DoS in wrap and unwrap
The wrap and unwrap functions in the Fuse token adapter incorrectly compare the return value of mint and redeem against a zero error code, but those functions return the amount minted or redeemed. This causes the functions to revert even when the operation succeeds, making the adapter unusable.
Originally disclosed on Code4rena
Submitted by CertoraInc
FuseTokenAdapterV1.sol#L76 FuseTokenAdapterV1.sol#L98
The code is doing wrong check, so when things will work it will revert.
Proof of Concept
In the function wrap() there is this lines:
if ((error = ICERC20(token).mint(amount)) != NO_ERROR) {
revert FuseError(error);
}
but mint returns the amount that minted, so when error = amount the check will fail even though it worked good.
Same in unwrap:
if ((error = ICERC20(token).redeem(amount)) != NO_ERROR) {
revert FuseError(error);
}
the redeem returns the amount.
Recommended Mitigation Steps
I recommend to change the lines like this: in wrap: if ((error = ICERC20(token).mint(amount)) != amount) { revert FuseError(error); } and in unwrap: if ((error = ICERC20(token).redeem(amount)) != amount) { revert FuseError(error); }
0xfoobar (Alchemix) confirmed, disagreed with severity and commented:
This would not cause any loss of user funds because the deposit function would revert, but it is a needed fix in the Fuse Adapter. So recommend a lower severity.
0xleastwood (judge) decreased severity to Medium and commented:
As no assets are at risk, medium risk seems correct because only the availability of the protocol is impacted.
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 code assumes the mint and redeem functions return an error code, but they actually return the amount, so the comparison to NO_ERROR is wrong.
Impact
The wrap and unwrap functions always revert when the amount is non-zero, causing a denial of service for the adapter; no user funds are lost because the transaction reverts.
What the attacker needed
None
The fix
The check should compare the return value to the amount instead of NO_ERROR, as recommended in the report.
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.
Smart contracts often call other contracts to perform actions. Here, the code expected a success code of zero, but the called function actually returns the number of tokens involved. So the check always fails when the amount is not zero, blocking the operation.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.