Typo in PoolTemplate unlock function results in user being able to unlock multiple times
The unlock function in PoolTemplate uses a comparison instead of an assignment, so the insurance status is never set to false. An attacker can call unlock multiple times for the same id, reducing lockedAmount and allowing withdrawal of more underlying tokens than available.
Submitted by loop, also found by p4st13r4 and ye0lde
The function unlock() in PoolTemplate has a typo where it compares insurances[_id].status to false rather than setting it to false. If the conditions are met to unlock the funds for an id, the user should be able to call the unlock() function once for that id as insurances[_id].amount is subtracted from lockedAmount. However, since insurances[_id].status does not get set to false, a user can call unlock() multiple times for the same id, resulting in lockedAmount being way smaller than it should be since insurances[_id].amount is subtracted multiple times.
Impact
lockedAmount is used to calculate the amount of underlying tokens available for withdrawals. If lockedAmount is lower than it should be users are able to withdraw more underlying tokens than available for withdrawals.
Proof of Concept
Typo in unlock():
Calculation of underlying tokens available for withdrawal:
Recommended Mitigation Steps
Change insurances[_id].status == false; to insurances[_id].status = false;
oishun1112 (Insure) confirmed and resolved:
https://github.com/InsureDAO/pool-contracts/blob/audit/code4rena/contracts/PoolTemplate.sol#L375
upgrading to sev-3 based on assets being compromised.
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 a typo where the assignment operator was replaced by the equality operator, so the status field is compared rather than updated.
Impact
lockedAmount becomes lower than it should be, allowing users to withdraw more underlying tokens than are available for withdrawals.
What the attacker needed
Meet unlock conditions for an id
The fix
The typo was fixed by changing the comparison to an assignment, as confirmed by the project.
How it was found
- Meet the conditions to unlock funds for a specific id.
- Call the unlock function for that id.
- Call the unlock function again for the same id, since the status was not set to false.
- Repeat multiple times to reduce lockedAmount further.
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 has a function that is supposed to mark an insurance as unlocked by setting a true/false flag to false. But the code accidentally checks the flag instead of changing it, so the flag stays true. This lets someone call the unlock function over and over, each time reducing the total locked amount, which then lets them withdraw more money 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.