Skip to content
Smart contracts Audit finding Intermediate

AbstractRewardMine - Re-entrancy attack during withdrawal

The internal withdrawal function updated its accounting after transferring the reward token, so a token with transfer hooks could re-enter the withdrawal and drain the pool. An attacker using such a token could repeatedly withdraw before the recorded amount was updated.

ScopeLift Follow

Originally disclosed on Code4rena

Submitted by ScopeLift

The internal _withdraw method does not follow the checks-effects-interactions pattern. A malicious token, or one that implemented transfer hooks, could re-enter the public calling function (such as withdraw()) before proper internal accounting was completed. Because the earned function looks up the _userWithdrawn mapping, which is not yet updated when the transfer occurs, it would be possible for a malicious contract to re-enter _withdraw repeatedly and drain the pool.

Recommended Mitigation Steps

The internal accounting should be done before the transfer occurs:

function _withdraw(address account, uint256 amountReward, address to) internal {
    _userWithdrawn[account] += amountReward;
    _globalWithdrawn += amountReward;f

   rewardToken.safeTransfer(to, amountReward);

    emit Withdraw(account, amountReward, to);
  }

0xScotch (sponsor) confirmed

Alex the Entreprenerd (judge) commented:

The warden identified a re-entrancy vulnerability that, given the right token would allow to drain the entirety of the contract.

Tokens with hooks (ERC777 and ERC677) would allow to exploit the contract and drain it in it’s entirety.

This is a very serious vulnerability. However it can happen exclusively on a malicious or a token with hooks, as such (while I recommend the sponsor to mitigate by following recommendation by the warden), the attack can be completely prevented by using a token without hooks.

For that reason I’ll rate the finding of medium severity (as it requires external conditions)

The original report as published on Code4rena, by ScopeLift. 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 internal `_withdraw` method does not follow the checks-effects-interactions pattern, updating the withdrawn accounting only after the token transfer.

Impact

A malicious token or one with transfer hooks could re-enter the withdrawal and drain the entire pool; the judge rated it medium because it requires such a token, and using a token without hooks prevents the attack.

What the attacker needed

A malicious token or one with transfer hooks

The fix

The accounting should be updated before the token transfer occurs, as the report's mitigation shows.

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 re-entrancy attack happens when a contract calls out to another contract, and that other contract calls back into the first one before it has finished updating its records. Here the contract paid out the reward before noting that it had been paid, so the attacker could ask for the payout again and again. The fix is to update the records first, then send the money.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by ScopeLift

View all

1 more disclosed report, best first.

More from Malt Protocol - Versus contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.