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

Incorrect computation allows cheaper mints in periodic sale #266

Closed
c4-submissions opened this issue Nov 4, 2023 · 5 comments
Closed

Incorrect computation allows cheaper mints in periodic sale #266

c4-submissions opened this issue Nov 4, 2023 · 5 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-641 sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-submissions
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/MinterContract.sol#L536

Vulnerability details

Impact

The idea behind the third sale model, periodic sale, is that for each new minted NFT, the price increases with a given % of the initial price. This % is the _rate parameter in the MinterContract.setCollectionCosts() function. MinterContract.getPrice() calculates the price incorrectly. Let's have a look:

return collectionPhases[_collectionId].collectionMintCost + ((collectionPhases[_collectionId].collectionMintCost / collectionPhases[_collectionId].rate) * gencore.viewCirSupply(_collectionId));

It divides the initial mint cost by the rate. So if the rate is 20%, the new price will become initialPrice / 20, which is actually 5% increase and not 20%. This lets users mint NFTs for significantly less money.

Proof of Concept

Let's look at the following case:

mintCost 1 ETH
rate 20%
mints 5
Expected mint price Actual mint price
1 ETH 1 ETH
1.2 ETH 1.05 ETH
1.4 ETH 1.1 ETH
1.6 ETH 1.15 ETH
1.8 ETH 1.20 ETH

As a result we have minted 5 NFTs for 5.5 ETH, not for 7 ETH. Here is a PoC in Foundry:

Proof of Concept

  1. Create foundry folder and install Foundry inside of it.
  2. Add remappings to map smart-contracts to contracts relative to the needed path.
  3. Add the following PoC.
  4. Run
forge test --lib-paths ../smart-contracts

Tools Used

Foundry

Recommended Mitigation Steps

Instead of dividing the mint cost by rate, multiply it by rate and then divide by 100.

Assessed type

Math

@c4-submissions c4-submissions added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Nov 4, 2023
c4-submissions added a commit that referenced this issue Nov 4, 2023
@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Nov 15, 2023
@c4-pre-sort
Copy link

141345 marked the issue as sufficient quality report

@c4-pre-sort
Copy link

141345 marked the issue as duplicate of #643

@c4-pre-sort
Copy link

141345 marked the issue as not a duplicate

@c4-pre-sort
Copy link

141345 marked the issue as duplicate of #641

@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Dec 6, 2023
@c4-judge
Copy link

c4-judge commented Dec 6, 2023

alex-ppg marked the issue as unsatisfactory:
Overinflated severity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-641 sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants