if (totalSupply() == 0) {
shares = _amount;
} else {
shares = (_amount * totalSupply()) / freeFunds; // use "freeFunds" instead of "pool"
}
The idea behind this is that shares will be worth 10 ** DECIMALS if totalSupply is non-zero
However, that's not the case if we perform a small deposit and we force an upwards rebase via a donation
Considerations in context of the codebase
The attack is possible, however, in the in-scope codebase the only depositor will be the Active Pool
A rebase will still be possible, but due to the accounting, it will not cause loss
This will change if there's more than one depositor at which point the risk is brought back as one of the depositors can steal assets from the others, as well as break their accounting
Lines of code
https://github.com/code-423n4/2023-02-ethos/blob/73687f32b934c9d697b97745356cdf8a1f264955/Ethos-Vault/contracts/ReaperVaultV2.sol#L331-L335
Vulnerability details
Impact
Because there's no minimum deposit size, all vaults are vulnerable to an attack by the first depositor.
At this point, the attack is very well documented.
The idea is the following:
Any new deposit will be divided by this new value, and due to rounding may return 0 shares minted.
This allows to steal the entirety of the original deposit.
The exploit is very well documented, hence am pointing to other resources
POC
The root cause of the issue is the incorrect assumption here:
https://github.com/code-423n4/2023-02-ethos/blob/73687f32b934c9d697b97745356cdf8a1f264955/Ethos-Vault/contracts/ReaperVaultV2.sol#L331-L335
The idea behind this is that shares will be worth 10 ** DECIMALS if totalSupply is non-zero
However, that's not the case if we perform a small deposit and we force an upwards rebase via a donation
Considerations in context of the codebase
The attack is possible, however, in the in-scope codebase the only depositor will be the Active Pool
A rebase will still be possible, but due to the accounting, it will not cause loss
This will change if there's more than one depositor at which point the risk is brought back as one of the depositors can steal assets from the others, as well as break their accounting
Resources
https://mixbytes.io/blog/overview-of-the-inflation-attack
https://youtu.be/_pO2jDgL0XE?t=112
Mitigation Steps
The simplest mitigation is to perform the first deposit yourself
Alternatively, you can set a minimum threshold for the first deposit which will reduce risk (as Harley recommended)