Skip to content
Business logic Audit finding Intermediate

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.

loop Follow

Originally disclosed on Code4rena

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

0xean (judge) commented:

upgrading to sev-3 based on assets being compromised.

The original report as published on Code4rena, by loop. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Meet the conditions to unlock funds for a specific id.
  2. Call the unlock function for that id.
  3. Call the unlock function again for the same id, since the status was not set to false.
  4. 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.

More by loop

View all

1 more disclosed report, best first.

More from InsureDAO contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.