Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReaperVaultV2 inflation attack #848

Open
code423n4 opened this issue Mar 7, 2023 · 7 comments
Open

ReaperVaultV2 inflation attack #848

code423n4 opened this issue Mar 7, 2023 · 7 comments
Labels
bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) downgraded by judge Judge downgraded the risk level of this issue grade-b primary issue Highest quality submission among a set of duplicates Q-02 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-02-ethos/blob/73687f32b934c9d697b97745356cdf8a1f264955/Ethos-Vault/contracts/ReaperVaultV2.sol#L334

Vulnerability details

Impact

A hacker can drain new deposits into the pool by causing a rounding error in a share-issuing function:

shares = (_amount * totalSupply()) / freeFunds;

The ReaperVaultV2._deposit() method issues zero shares for the victim if the freeFunds (which is proportional to token.balanceOf(address(vault))) is greater than _amount * totalSupply() (which may be the case if the totalSupply() is low).

The impact is not high because a hacker can only deposit into the pool via contracts that have the DEPOSITOR role (e.g. ActivePool).

Proof of Concept

Let's consider a scenario where there are two contracts that have the DEPOSITOR role. We will refer to the first contract as the HACKER and the second as the VICTIM.

  1. The HACKER creates a small number of shares. For example, they may issue a single share by calling vault.deposit(1 wei).
  2. The VICTIM intends to deposit a significant amount of funds into the vault, such as 20_000e18 wei.
  3. The HACKER anticipates the VICTIM's transaction and front-runs it with a direct donation to the pool by calling token.transfer(vault, 20_000e18).
  4. The VICTIM's transaction is processed. However, the VICTIM does not receive any shares:
shares == (_amount * totalSupply()) / freeFunds 
       == (20_000e18 * 1) / (20_000e18 + 1)
       == 0

This happens because the freeFunds are proportional to the vault's balance and hacker can manipulate it by direct donations:

function _freeFunds() internal view returns (uint256) {
    return balance() - _calculateLockedProfit();
}

https://github.com/code-423n4/2023-02-ethos/blob/73687f32b934c9d697b97745356cdf8a1f264955/Ethos-Vault/contracts/ReaperVaultV2.sol#L288

function balance() public view returns (uint256) {
    return token.balanceOf(address(this)) + totalAllocated;
}

https://github.com/code-423n4/2023-02-ethos/blob/73687f32b934c9d697b97745356cdf8a1f264955/Ethos-Vault/contracts/ReaperVaultV2.sol#L279

Tools Used

Manual

Recommended Mitigation Steps

To prevent errors, it is recommended to add a requirement that shares cannot be equal to zero.

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Mar 7, 2023
code423n4 added a commit that referenced this issue Mar 7, 2023
@c4-judge c4-judge added the primary issue Highest quality submission among a set of duplicates label Mar 8, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Mar 8, 2023

trust1995 marked the issue as primary issue

@c4-judge
Copy link
Contributor

c4-judge commented Mar 8, 2023

trust1995 marked the issue as satisfactory

@tess3rac7
Copy link

We have received this report over and over through the last year or so across different platforms. DEPOSITOR role is trusted and will only be granted to ActivePool.

In the more general case (outside of Ethos), Reaper's vaults always undergo manual testing whereby funds are deposited before we invite the public to utilize the vault.

I will not dispute the validity since this is a valid scenario, but it will never occur in the case of Ethos (since only one DEPOSITOR being ActivePool), and never really occur otherwise outside of ethos. Recommend low severity.

@c4-sponsor
Copy link

tess3rac7 marked the issue as disagree with severity

@c4-sponsor c4-sponsor added the disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) label Mar 13, 2023
@trust1995
Copy link

I agree with sponsor that the finding severity is low, given the centralized nature of the DEPOSITOR role.

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Mar 20, 2023
@c4-judge
Copy link
Contributor

trust1995 changed the severity to QA (Quality Assurance)

@c4-judge
Copy link
Contributor

trust1995 marked the issue as grade-b

@C4-Staff C4-Staff added the Q-02 label Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) downgraded by judge Judge downgraded the risk level of this issue grade-b primary issue Highest quality submission among a set of duplicates Q-02 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

6 participants