Claiming alchemic-token rewards can fail for so
The claim function in RevenueHandler checks whether a user has deposits in AlchemistV2 rather than debt, and attempts to burn the alchemic-token. If the user has deposits but no debt, the burn call reverts, causing the claim transaction to fail.
Originally disclosed on Immunefi
- Disclosed after under an hour
31042 - [SC - High] Claiming alchemic-token rewards can fail for so...
Submitted on May 11th 2024 at 11:50:44 UTC by @infosec_us_team for Boost | Alchemix
Report ID: #31042
Report type: Smart Contract
Report severity: High
Target: https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/RevenueHandler.sol
Impacts:
- Temporary freezing of funds for 12 hours
Description
Description
When claiming an alchemic-token in RevenueHandler, the claim(...) function checks if a user has deposits in AlchemistV2 and attempts to pay his debt using the alchemic-token.
function claim(
uint256 tokenId,
address token,
address alchemist,
uint256 amount,
address recipient
) external override {
// ----------------------- Code above is omitted for brevity
// Get the deposits for the recipient
(, address[] memory deposits) = IAlchemistV2(alchemist).accounts(recipient);
IERC20(token).approve(alchemist, amount);
// Only burn if there are deposits <-- wrong check, we should only burn if there is "debt"
amountBurned = deposits.length > 0 ? IAlchemistV2(alchemist).burn(amount, recipient) : 0;
// ----------------------- Code below is omitted for brevity
}
Users can have deposits in AlchemistV2 with no debt. Attempting to burn debt from an AlchemistV2 account that has 0 debt reverts the transaction, therefore checking for deposits is wrong, we should be checking for debt instead.
(int256 debt, address[] memory deposits) = IAlchemistV2(alchemist).accounts(recipient);
Users with deposits but no debt in AlchemistV2, when calling RevenueHandler.claim(...) with an alchemist address and an alchemic-token will have their claim(...) transaction reverted.
Rewards are not permanently locked though. An advanced user can read the smart contract, detect the bug, and manually send a transaction to the revenueHandler smart contract with "address(0)" as the alchemist to bypass the bug and claim his reward.
Impact Details
Claiming alchemic-token rewards can fail for some users
Proof of Concept
Here's a test demonstrating the revenueHandler.claim(...) transaction reverting because the user has deposits but no debt.
function testClaimAlchemicRevenue() external {
revenueHandler.addAlchemicToken(address(alethAlchemist));
uint256 revAmt = 1000e18;
uint256 tokenId = _setupClaimableRevenue(revAmt);
uint256 claimable = revenueHandler.claimable(tokenId, alusd);
assertApproxEq(revAmt, claimable, revAmt / DELTA);
deal(dai, address(this), 3 * 5000e18);
IERC20(dai).approve(address(alusdAlchemist), 3 * 5000e18);
alusdAlchemist.depositUnderlying(ydai, 3 * 5000e18, address(this), 0);
revenueHandler.claim(tokenId, alusd, address(alusdAlchemist), claimable, address(this));
}
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 contract checks for deposits instead of debt before attempting to burn the alchemic-token.
Impact
Claiming alchemic-token rewards can fail for some users, temporarily freezing their funds for 12 hours.
What the attacker needed
User has deposits but no debt in AlchemistV2; user calls claim with an alchemist address
The fix
The contract should check for debt instead of deposits before attempting to burn the alchemic-token.
How it was found
- Add an alchemic token to the revenue handler.
- Set up a claimable revenue for a token ID.
- Deposit underlying into the alchemist contract.
- Call claim with the alchemist address and the claimable amount.
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 claim rewards, the contract tries to pay off any debt you have in another contract. But it mistakenly checks if you have any deposits at all, not just debt. If you have deposits but no debt, the payment fails and your claim is blocked.
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.