Buyout Module: redeem ing before the update of totalSupply will make buyout’s current state success
The mint function updates totalSupply after an external call to the recipient, allowing a malicious contract to call redeem during the callback and set the buyout state to SUCCESS before totalSupply is updated. The attacker can then sell fractions and withdraw assets from the vault at any time.
Submitted by zzzitron, also found by unforgiven
MED - a hypothetical attack path with stated assumptions, but external requirements.
Attacker can create a vault with successful buyout status and non zero supply. The attacker can sell the fractions and then simply withdraw the assets.
Proof of Concept
- Proof of Concept
- Evil redeemer
- Deploy
evil_redeemer: it will deployVault and calls redeem when the minted FERC1155 token is received - Calling
startwill start the process :baseVault.deployVault - The baseVault will deploy vault and eventually mint the FERC1155 token to the
evil_redeemer - When the FERC1155 is received, the
evil_redeemercallsredeemand set the state toSUCCESS - After the redeem, the tatalSupply of the FERC1155 is set.
Now, the attacker can send in some assets to the vault and sell the fractions. Then, the attacker can withdraw any asset at any time from the vault using the buyout module, because the state is already SUCCESS.
Note: An attacker can achieve the similar result with plugins. However, users might just refuse to buy tokens associated with such vaults and plugins. With the current issue, the user who is only looking at the vault will not notice this possibility unless they also check the status in the buyout module for the vault.
// FERC1155.sol::mint
// totalSupply is updated after _mint
// _mint contains out going call if the `_to` address's codesize is non zero
// Mitigation idea: update totalSupply before _mint
79 function mint(
80 address _to,
81 uint256 _id,
82 uint256 _amount,
83 bytes memory _data
84 ) external onlyRegistry {
85 _mint(_to, _id, _amount, _data);
86 totalSupply[_id] += _amount;
87 }
Tools Used
Foundry
Recommended Mitigation Steps
Update totalSupply before _mint.
stevennevins (Fractional) disagreed with severity
HardlyDifficult (judge) commented:
Since totalSupply is updated after an external call, a vault can be created with an incorrect buyout status. Agree that this is Medium risk.
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
Likely the totalSupply is updated after an external call in mint, allowing reentrancy to set the buyout state before the supply is recorded.
Impact
The attacker could create a vault with a successful buyout status and non-zero supply, then sell fractions and withdraw assets at any time.
What the attacker needed
Attacker can deploy a malicious contract; attacker can create a vault
The fix
Update totalSupply before calling _mint.
How it was found
- Deploy a malicious redeemer contract that deploys a vault and calls redeem when it receives the minted token.
- Call start to begin the process, which deploys the vault and mints the token to the redeemer.
- When the token is received, the redeemer calls redeem and sets the state to SUCCESS.
- After the redeem, the totalSupply of the token is set.
- The attacker sends assets to the vault and sells the fractions.
- The attacker withdraws any asset from the vault using the buyout module because the state is already SUCCESS.
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.
When a vault mints tokens to a contract, that contract can run code immediately. The bug is that the vault updates its total supply only after that code runs, so the contract can call another function that marks the buyout as successful. This lets the attacker later take assets out of the vault.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.