Gareth Larkan
Welcome to the fascinating world of ERC-4626! You may have heard about ERC standards, which help structure smart contracts for decentralized applications. Well, ERC-4626 is one of those standards, and today we'll explore what it's all about.
ERC standards are guidelines for developing smart contracts that work well with decentralized applications. Some common ERC standards include ERC20 and ERC721. Today, we'll focus on ERC-4626.
ERC-4626 was created as an Ethereum Improvement Proposal (EIP) by multiple authors, including Joey Santoro and transmissions 11, on December 22nd, 2021.
The reason ERC-4626 was developed is that there was a lack of standardization in how vaults were being created. This made it difficult for protocols to follow standards and integrate with different vaults. So, ERC-4626 was introduced to solve this problem.
The ERC-4626 vault combines two different ERC20 tokens: the underlying asset and the vault token. When users deposit the underlying asset, they receive a proportionate amount of vault tokens. These tokens represent their share of the total assets in the vault.
When a user wants to withdraw from the vault, they burn their vault tokens and receive an equivalent amount of the underlying asset. The amount they receive depends on the proportion of shares they hold compared to the total shares and assets in the vault.
The benefit of the share/vault token is that it eliminates the need to update user balances every time assets enter the vault.
Let's look at an example to understand better how a vault works:
Bob made a profit of 2 ETH, while Alice would have made 8 ETH if she had withdrawn. On a larger scale, this process becomes more complex.
One common attack on vaults is the inflation attack, which is particularly dangerous in the early stages of a vault. This attack involves an attacker front-running the first deposit in a contract. By manipulating the exchange rate, the attacker can steal funds from other depositors.
Let's take a practical example to better understand the vulnerability. We'll use the same scenario as mentioned earlier.
Here's what happens step by step:
To mitigate this vulnerability, several solutions can be implemented. One approach is to mint a certain amount of shares to a burnable address during the first deposit, making the attack much riskier and costlier. Other solutions include adding a decimal offset to the share token, setting minimum deposit amounts, or, for simpler contracts using ETH, tracking the ETH inside the contract separately.
In conclusion, ERC-4626 enables decentralized protocols to integrate with yield-bearing vaults more efficiently. It operates based on two tokens that are proportionate to each other. While there is a vulnerability to be aware of, with proper knowledge, vaults can be built in a safe and secure manner.
Ready to Secure
Your Protocol?