User can alter amount returned by redeem function due to control transfer
The redeem function calculates the amount of assets to return by comparing the receiver's balance before and after burning shares. Because the underlying token is an ERC777, burning shares transfers control to the receiver, who can move tokens out during that callback, making the balance difference smaller and reducing the assets returned.
Submitted by 0xDjango
Control is transferred to the receiver when receiving the ERC777. They are able to transfer the ERC777 to another account, at which time the before and after balance calculation will be incorrect.
uint256 balanceBefore = IERC20(asset()).balanceOf(receiver);
if (msg.sender != owner) {
_spendAllowance(owner, msg.sender, shares);
}
_redeemInternal(shares, receiver, owner);
/////////////
Control is transferred to user. They can alter their balance here.
///////////
uint256 balanceAfter = IERC20(asset()).balanceOf(receiver);
uint256 assets = balanceAfter - balanceBefore;
//////////
Assets can be as low as 0 if they have transferred the same amount out as received.
//////////
emit Withdraw(msg.sender, receiver, owner, assets, shares);
return assets;
jeffywu (Notional) disputed and commented:
Control of the contract is not transferred to anyone during a
balanceOfcall which is read only. No state can be modified.
fatherGoose1 (warden) commented:
The control is transferred in
_redeemInternal()which calls_burn()on the ERC777 which transfers control.
_burn()function logic here: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/109778c17c7020618ea4e035efb9f0f9b82d43ca/contracts/token/ERC777/ERC777.sol#L390-L400
jeffywu (Notional) confirmed and commented:
Understood, will change to confirmed.
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 redeem function uses a balance difference to determine assets returned, but the ERC777 token's burn operation transfers control to the receiver, allowing them to alter their balance before the after-balance is read.
Impact
The receiver could receive as few as zero assets when redeeming, effectively losing their shares without receiving the corresponding assets.
What the attacker needed
Receiver is an ERC777 token holder; receiver can execute code during token transfer
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 you redeem shares, the contract checks how many tokens the receiver has before and after burning the shares, and returns the difference. But the token used here (ERC777) lets the receiver run code during the burn, and that code can move tokens away. So the difference becomes smaller, and the receiver gets fewer assets than they should.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.