Manipulate pair price by reentrancy attack while the base token is an ERC777 token #211
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-343
satisfactory
satisfies C4 submission criteria; eligible for awards
upgraded by judge
Original issue severity upgraded from QA/Gas by judge
Lines of code
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L172
Vulnerability details
Impact
The pair contract is susceptible to reentrancy attack while the base token is an ERC777 token such as imBTC. An attacker can exploit it to save significant cost for buying NFT or
fractionalToken
.Proof of Concept
The following test case is based on fork of Ethereum mainnet at height 16205002.
The pair consists of BAYC and imBTC, and the initial supply of the pool is 10 imBTC and 10 BAYC NFTs.
And the attacker want to buy 5 NFTs.
We can see, by reentrancy attack, the attacker can save about 25% cost than normal buy.
Full test script
Put it into a new
ReentrancyToManipulatePrice.t.sol
file of test directory and runRelated output
Tools Used
foundry
Recommended Mitigation Steps
Add reentrancy protection for
buy()
function.The text was updated successfully, but these errors were encountered: