Skip to content
Race condition Audit finding Intermediate

Possible token reentrancy in release() of BathBuddy.sol

The release() function in BathBuddy.sol lacks reentrancy protection, allowing a malicious beneficiary contract to repeatedly reenter and withdraw the vested amount before the vesting period ends. This is possible if the vested token has callback capabilities, such as ERC777.

kebabsec Follow

Originally disclosed on Code4rena

Submitted by kebabsec, also found by kenzo, cryptphi, and 0xsomeone

If a token with callback capabilities is used as a token to vested, then a malicious beneficiary may get the vested amount back without waiting for the vesting period.

Proof of Concept

In the function release, line, there’s no modifier to stop reentrancy, in the other contracts it would be the synchronized modifier. If a token could reenter with a hook in a malicious contract (an ERC777 token, for example, which is backwards compatible with ERC20), released token counter array wouldn’t be updated, enabling the withdrawal of the vested amount before the vesting period ends. A plausible scenario would be:

  1. A malicious beneficiary contract B calls the release() function with itself as the recipient, everything goes according to the function, and transfer and callback to the malicious beneficiary contract happens.
  2. Contract B contains tokensReceived(), a function in the ERC777 token that allows for callback to the victim contract as you can see here https://twitter.com/transmissions11/status/1496944873760428058/ (This function also can be any function that is analogous to a fallback function that might be implemented in a modified ERC20. As it can be seen, any token that would give the attacker control over the execution flow will suffice.)
  3. Inside the tokensReceived() function, a call is made back to the release function.
  4. This steps are repeated until vested amount is taken back.
  5. This allows for the malicious beneficiary contract to redeem the vested amount while bypassing the vesting period, due to the released token counter array (https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/peripheral_contracts/BathBuddy.sol#L116) which controls how many tokens are released (https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/peripheral_contracts/BathBuddy.sol#L101) being updated only after the transferring of all tokens occurs. As this is the case, malicious beneficiary can get the usual amount that they could withdraw at the time indefinite amount of times (as result of released in line 101 will be 0), thus approximately getting all of their vested amount back without waiting for the vesting period. (fees not included).

There’s also precedents of similar bugs that reported, as seen here

Recommended Mitigation Steps

  1. Consider adding a mutex such as nonReentrant, or the synchronized modifier used in the other contracts.
  2. Implement checks-effects-interactions pattern.

bghughes (Rubicon) confirmed, but disagreed with severity and commented:

This one should probably be a high priority, adding disagreement with severity.

HickupHH3 (judge) commented:

From what I gather, bonusTokens can be any ERC20 token (network incentives/governance tokens), which by extension, means ERC777 tokens are possible too.

Even if not, I suppose one could spin up a malicious bonus token to specifically target the BathBuddy contract.

Medium severity because there isn’t a loss nor stolen rewards from others, merely bypassing the vesting, which is an impact on protocol functionality. 2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.


The original report as published on Code4rena, by kebabsec. 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 release() function updates the released token counter after transferring tokens, allowing reentrancy through token callbacks.

Impact

A malicious beneficiary could bypass the vesting period and withdraw the full vested amount early, though this does not steal rewards from others.

What the attacker needed

Vested token supports callbacks (e.g., ERC777); attacker controls beneficiary contract

The fix

Add a reentrancy guard (such as nonReentrant or synchronized modifier) and follow the checks-effects-interactions pattern.

How it was found

  1. A malicious beneficiary contract calls release() with itself as recipient.
  2. The token transfer triggers a callback to the malicious contract.
  3. Inside the callback, the malicious contract calls release() again.
  4. Steps 2-3 are repeated until the vested amount is drained.

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 can call another contract during a token transfer, which is like a callback. If the receiving contract calls back into the release function before the first call finishes, it can withdraw the same vested tokens multiple times. This happens because the contract updates its record of how many tokens have been released only after the transfer completes.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More from Rubicon v2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.