BondVault.sol : Possibly unwithdrawable bondedLP funds in claimForMember() + claimRate never zeros after full withdrawals
In the claimForMember function, the claimable amount is subtracted from the member's bonded LP balance before the check that decides whether to zero the claim rate. This can either permanently lock half of a member's bonded LP funds or leave the claim rate non-zero after a full withdrawal.
Submitted by hickuphh3, also found by 0xRajeev
A host of problems arise from the L110-113 of the claimForMember() function, where _claimable is deducted from the bondedLP balance before the condition check, when it should be performed after (or the condition is changed to checking if the remaining bondedLP balance to zero).
mapBondAsset_memberDetails[asset].bondedLP[member] -= _claimable; // Remove the claim amount from the user's remainder
if(_claimable == mapBondAsset_memberDetails[asset].bondedLP[member]){
mapBondAsset_memberDetails[asset].claimRate[member] = 0; // If final claim; zero-out their claimRate
}
1. Permanently Locked Funds
If a user claims his bonded LP asset by calling dao.claimForMember(), or a malicious attacker helps a user to claim by calling dao.claimAllForMember(), either which is done such that _claimable is exactly half of his remaining bondedLP funds of an asset, then the other half would be permanently locked.
- Assume
mapBondAsset_memberDetails[asset].bondedLP[member] = 2 * _claimable - L110:
mapBondAsset_memberDetails[asset].bondedLP[member] = _claimable - L111: The if condition is satisfied
- L112: User’s claimRate is erroneously set to 0 ⇒
calcBondedLP()will return 0, ie. funds are locked permanently
2. Claim Rate Never Zeroes For Final Claim
On the flip side, should a user perform a claim that enables him to perform a full withdrawal (ie. _claimable = mapBondAsset_memberDetails[asset].bondedLP[member], we see the following effects:
- L110:
mapBondAsset_memberDetails[asset].bondedLP[member] = 0 - L111: The if condition is not satisfied, L112 does not execute, so the member’s claimRate for the asset remains non-zero (it is expected to have been set to zero).
Thankfully, subsequent behavior remains as expected since calcBondedLP returns zero as claimAmount is set to the member’s bondedLP balance (which is zero after a full withdrawal).
The _claimable deduction should occur after the condition check. Alternatively, change the condition check to if (mapBondAsset_memberDetails[asset].bondedLP[member] == 0).
verifyfirst (Spartan) confirmed:
Good find, suggested mitigation solves the potential to lock funds.
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 claimable amount is deducted from the bonded LP balance before the equality check that zeroes the claim rate, so the check compares against the already-reduced balance.
What the attacker needed
A member with bonded LP funds; claim amount equals half the balance
The fix
The deduction should happen after the condition check, or the check should test whether the remaining bonded LP balance is zero; the project confirmed the suggested mitigation solves the lock.
How it was found
- A member has a bonded LP balance equal to twice the claimable amount.
- The member or an attacker calls claimForMember or claimAllForMember so that the claimable amount is exactly half the balance.
- The balance is reduced to the claimable amount, so the equality check passes.
- The claim rate is set to zero, and calcBondedLP then returns zero, locking the remaining funds.
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.
A smart contract keeps track of how much a user has bonded and a rate used to calculate their share. The code reduces the user's balance first and then checks whether the balance is now equal to the amount just claimed, which is the wrong order. As a result, a claim of exactly half the balance makes the contract think the user is finished and wipes their rate, so the remaining half can no longer be calculated or withdrawn.
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.