Skip to content
Business logic Audit finding Intermediate

Deactivate function can be bypassed

The activate function could be called repeatedly, resetting the timestamp used to enforce a grace period. A malicious client could then deactivate a token after the deadline and transfer all contract funds to itself.

Anurag Jain Follow

Originally disclosed on Code4rena

Submitted by csanuragjain, also found by gzeon

onlyClient can deactivate a token even after deadline is passed and transfer all token balance to itself.

Proof of Concept

  1. Navigate to contract Shelter.sol
  2. Observe that token can only be deactivated if activated[_token] + GRACE_PERIOD > block.timestamp. We will bypass this
  3. onlyClient activates a token X using the activate function
  4. Assume Grace period is crossed such that activated[_token] + GRACE_PERIOD < block.timestamp
  5. Now if onlyClient calls deactivate function, it fails with “too late”
  6. But onlyClient can bypass this by calling activate function again on token X which will reset the timestamp to latest in activated[_token] and hence onlyClient can now call deactivate function to disable the token and retrieve all funds present in the contract to his own address

Recommended Mitigation Steps

Add below condition to activate function:

function activate(IERC20 _token) external override onlyClient {
require(activated[_token]==0, "Already activated");
        activated[_token] = block.timestamp;
        savedTokens[_token] = _token.balanceOf(address(this));
        emit ShelterActivated(_token);
    }

leekt (Concur) confirmed

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

The warden has identified a way for the client to trick the shelter into sending all tokens to the client, effectively rugging all other users.

Because this is contingent on a malicious client, I believe Medium Severity to be more appropriate.


The original report as published on Code4rena, by csanuragjain. 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

The activate function did not check if the token was already activated, allowing the timestamp to be reset and the grace period to be bypassed.

Impact

A malicious client could transfer all tokens held by the contract to itself, effectively rugging all other users.

What the attacker needed

The attacker is the client (onlyClient); the token has been activated; the grace period has passed

How it was found

  1. The client activates a token using the activate function.
  2. The grace period passes so that the activation timestamp plus the grace period is before the current block timestamp.
  3. The client calls deactivate, which fails with 'too late'.
  4. The client calls activate again on the same token, resetting the activation timestamp to the current time.
  5. The client calls deactivate again, which now succeeds and transfers all contract funds to the client.

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 had a function to start a timer for a token. The timer was supposed to stop the owner from taking funds after a certain time. But the owner could restart the timer by calling the start function again, so they could always take the funds. This means the owner could steal all tokens held by the contract.

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 Anurag Jain

View all

63 more disclosed reports, best first.

More from Concur Finance 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.