Closed captainmangoC4 closed 6 months ago
Issue created on behalf of judge in order to split into 2 findings
alex-ppg marked the issue as duplicate of #572
alex-ppg marked the issue as partial-25
The Warden does denote that the periodic-sale related variable is updated after a re-entrant call, however, the main focus of their submission is #1517 rendering this submission to be of 25% credit.
alex-ppg changed the severity to 3 (High Risk)
alex-ppg marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2023-10-nextgen/blob/08a56bacd286ee52433670f3bb73a0e4a4525dd4/smart-contracts/NextGenCore.sol#L189-L200
Vulnerability details
Impact
The
mint
function in NextGenCore.sol doesn't follow the checks-effects-interactions pattern and can be reentered through theonERC721Received
function, if the receiver is a contract.The state variables written after the call are
tokensMintedAllowlistAddress
(during allowlist phase) ortokensMintedPerAddress
(during public mint).NextGenCore 189-200
As a result, it is possible to bypass the following checks and mint more tokens than allowed per address, during the public mint phase:
MinterContract 213
and during the allowlist phase:
MinterContract 224
Proof of Concept
This test shows that on a collection where the total supply is 50 and the maximum allowed per address during the public mint phase is 3, a single buyer could buy up all the supply.
Tools Used
Foundry
Recommended Mitigation Steps
The
mintProcessing
function, which makes the external call toonERC721Received
during_safeMint
, should be called at the very end of themint
function, after all the state variables are written.NextGenCore 189-200
Similarly in
airDropTokens
andburnToMint
,_mintProcessing
should be called after making all state changes.NextGenCore 178-185
NextGenCore 213-223
Other state variables in
MinterContract
are written after the call to the recipient contract:collectionTotalAmount
MinterContract 238 MinterContract 272 MinterContract 366
lastMintDate
MinterContract 252 MinterContract 2296
mintToAuctionData
andmintToAuctionStatus
MinterContract 297-298
This could potentially be used to bypass checks related to the time difference that is enforced between mints.
Assessed type
Reentrancy