Reentrancy vulnerability in Basket contract’s initialize() method.
The Basket contract's initialize() method calls approve() on underlying tokens, which can trigger a reentrancy callback in a malicious token. An attacker could re-enter initialize() to overwrite the auction and factory addresses, potentially manipulating the basket's ibRatio to burn tokens and drain user funds.
Originally disclosed on Code4rena
Submitted by broccolirob
A malicious “publisher” can create a basket proposal that mixes real ERC20 tokens with a malicious ERC20 token containing a reentrancy callback in it’s approve() method. When the initialize() method is called on the newly cloned Basket contract, a method called approveUnderlying(address(auction)) is called, which would trigger the reentrancy, call initialize() again, passing in altered critical values such as auction and factory, and then removes its self from proposal.tokens and proposal.weights so it doesn’t appear in the token list to basket users.
Impact
Auction and Factory can be set to custom implementations that do malicious things. Since all baskets and auctions are clones with their own addresses, this fact would be difficult for users to detect. Auction controls ibRatio, which a malicious version could send back a manipulated value to Basket, allowing the malicious “publisher” to burn basket tokens till all users underlying tokens are drained.
Tools Used
Manual review and Hardhat.
Recommended Mitigation Steps
Since Basket inherits from ERC20Upgradeable the initializer modifier should be available and therefore used here. It has an inititializing variable that would prevent this kind of reentrancy attack.
frank-beard (Kuiper) confirmed
0xleastwood (judge) decreased severity to Medium and commented:
While the warden is correct, a malicious publisher could re-enter the
Basket.initialize()function and overwritefactoryandauctionwith their own addresses, this does not lead to a direct loss of funds for users. It would require that users interact with their malicious contracts which is entirely possible if baskets created via the factory are deemed as trusted. I think this fits the criteria of amediumseverity issue.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The initialize() function lacks a reentrancy guard and calls an external token's approve() method, allowing a malicious token to re-enter and overwrite critical state variables.
Impact
A malicious publisher could set Auction and Factory to custom implementations that manipulate ibRatio, potentially allowing them to burn basket tokens and drain users' underlying tokens, though this requires users to interact with the malicious contracts.
What the attacker needed
Attacker can create a basket proposal; malicious ERC20 token with callback; users interact with malicious contracts
How it was found
- Create a basket proposal that includes a malicious ERC20 token with a reentrancy callback in its approve() method.
- When initialize() is called on the cloned Basket contract, it calls approveUnderlying(address(auction)), triggering the malicious token's callback.
- The callback re-enters initialize() and passes altered values for auction and factory.
- The malicious token removes itself from proposal.tokens and proposal.weights so it does not appear in the token list.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A reentrancy attack happens when a contract calls another contract, and that other contract calls back into the first one before the first call finishes. Here, a malicious token could call back into the basket setup function and change important settings like the auction and factory addresses. This could let the attacker manipulate the basket and potentially steal users' tokens.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.