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.
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
- Navigate to contract Shelter.sol
- Observe that token can only be deactivated if activated[_token] + GRACE_PERIOD > block.timestamp. We will bypass this
- onlyClient activates a token X using the activate function
- Assume Grace period is crossed such that activated[_token] + GRACE_PERIOD < block.timestamp
- Now if onlyClient calls deactivate function, it fails with “too late”
- 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);
}
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.
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
- The client activates a token using the activate function.
- The grace period passes so that the activation timestamp plus the grace period is before the current block timestamp.
- The client calls deactivate, which fails with 'too late'.
- The client calls activate again on the same token, resetting the activation timestamp to the current time.
- 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.