Skip to content
Smart contracts Audit finding Advanced

[ConcurRewardPool] Possible reentrancy when claiming rewards

The reward pool contract transferred reward tokens to the caller before resetting the caller's recorded balance to zero. If the reward token supports a sender callback (such as an ERC777 token), an attacker could re-enter the claim function during the transfer and drain the pool's rewards.

ShadowyNoobDev Follow

Originally disclosed on Code4rena

Submitted by ShadowyNoobDev, also found by 0xw4rd3n, CertoraInc, ckksec, Czar102, defsec, Alex the Entreprenerd, Heartless, IllIllI, Jujic, kirk-baird, leastwood, pauliax, peritoflores, Randyyy, reassor, Rhynorater, Sleepy, SolidityScan, and wuwe1

ConcurRewardPool.sol#L34

Since the reward tokens are transferred before the balances are set to 0, it is possible to perform a reentrancy attack if the reward token has some kind of call back functionality e.g. ERC777. pBTC is an ERC777 token that is currently available on Convex. A similar attack occurred with imBTC on uniswap v1.

Proof of Concept

  • Preparation

    1. Assume that pBTC is used as extra rewards for this victim convex pool.
    2. A malicious user interacts with Concur through a smart contract. He follows the standard flow and has some rewards to be claimed.
    3. The malicious user interacts with this smart contract to register a bad tokensToSend() callback function through the ERC-1820 contract.
    4. In this tokensToSend() function, he calls ConcurRewardPool.claimRewards() n-1 more times to drain contract.
  • Attack

    1. When he calls ConcurRewardPool.claimRewards() for the first time, the pBTC reward tokens are transferred.
    2. You can see from the pBTC contract on line 871 that _callTokensToSend(from, from, recipient, amount, "", ""); is called inside the transfer() function.
    3. If you trace to the _callTokensToSend function definition to line 1147, you will notice that it calls IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData); on line 1159.
    4. Since the malicious user already registered a bad tokensToSend() function, this function will be called thus draining majority of the pBTC rewards available on the ConcurRewardPool contract.

You can also find a walkthrough replicating a similar attack here.

Recommended Mitigation Steps

  • Use a nonReentrant modifier
  • set balances to 0 first before disbursing the rewards

ryuheimat (Concur) confirmed

Alex the Entreprenerd (judge) commented:

The warden has shown how using a specific reward token can lead to reentrancy for the function claimRewards.

Because the finding is contingent on a specific token that enables the exploit, I believe Medium Severity to be appropriate.


The original report as published on Code4rena, by ShadowyNoobDev. 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 the claim function sends reward tokens before zeroing the claimant's stored balance, so a token with a transfer callback allows re-entry into the same claim.

Impact

An attacker could drain most of the reward tokens held by the pool, but only if the reward token is one that invokes a sender callback during transfers.

What the attacker needed

Reward token has a transfer callback (e.g. ERC777); attacker uses a contract with a registered callback; attacker has claimable rewards

The fix

The contract should set the claimant's balance to zero before sending rewards and should use a nonReentrant modifier.

How it was found

  1. Assume an ERC777-style token such as pBTC is used as extra rewards for the pool.
  2. The attacker interacts through a smart contract and registers a malicious tokensToSend callback via ERC-1820.
  3. The attacker calls claimRewards, which transfers the reward tokens.
  4. The token's transfer calls the attacker's tokensToSend callback, which calls claimRewards again to drain the contract.

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 reentrancy attack is 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 pool pays out rewards before marking them as paid, so a malicious recipient can ask for the payout again and again while the first payment is still in progress. This only works if the reward token itself lets the recipient run code during a transfer.

What is Smart contracts?

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

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.

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.