code-423n4 / 2023-02-ethos-findings

8 stars 6 forks source link

Vault is vulnerable to re-base exploit #635

Open code423n4 opened 1 year ago

code423n4 commented 1 year ago

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

        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

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)

c4-judge commented 1 year ago

trust1995 marked the issue as duplicate of #848

c4-judge commented 1 year ago

trust1995 changed the severity to 2 (Med Risk)

c4-judge commented 1 year ago

trust1995 marked the issue as satisfactory

c4-judge commented 1 year ago

trust1995 changed the severity to QA (Quality Assurance)