# Reentrancy vulnerability in Basket contract's initialize() method.

Malicious ERC20 approve() callback reenters Basket.initialize() to overwrite auction and factory with attacker contracts, enabling later draining of user funds.

- Payout: Audit contest
- Severity: medium
- Program: Kuiper
- Found by: broccolirob
- Disclosed: 2022-05-02
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2021-12-defiprotocol-findings/issues/176
- Library page: https://bugbountylibrary.com/r/c4%3A2021-12-defiprotocol%3AM-04
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:access-control vuln:reentrancy

**Target:** Basket contract initialize() / ERC20 approve callback
**Root cause:** initialize() calls approveUnderlying(address(auction)) before the initializer guard is set, so a malicious underlying token's approve() can reenter initialize() and overwrite auction and factory.
**Steps:**
1. Publisher submits a basket proposal mixing real ERC20s with a malicious ERC20 whose approve() reenters.
2. Basket clone is created and initialize() is called.
3. initialize() invokes approveUnderlying(address(auction)) on the malicious token.
4. Malicious approve() reenters initialize(), passing attacker-controlled auction and factory addresses.
5. Reentrant call removes the malicious token from proposal.tokens and proposal.weights so it is hidden from users.
6. Attacker's Auction returns manipulated ibRatio to Basket, allowing burn of basket tokens and draining of underlying.
**How found:** Code review of initialize() ordering: noticed approveUnderlying() external call to a token-controlled approve() occurs before initialization state is finalized, hypothesizing a reentrant callback could re-run initialize().
**Exploitation:** Attacker publishes a basket with a malicious token; on initialize the reentrancy sets auction/factory to attacker contracts; the malicious Auction manipulates ibRatio so the publisher can burn basket tokens and drain all users' underlying tokens.
**Escalation:** Chained reentrancy with a malicious Auction implementation to convert control of basket parameters into full fund drain.
**Insight:** In clone/proxy patterns, any external call inside initialize() (including token approve/hooks) before the initializer flag is set is a reentrancy surface that lets an attacker rewrite trusted addresses like factory and auction.
