Skip to content
Business logic Audit finding Intermediate

Early funds withdrawers can get bonus in multiples of vested bonus tokens (e.g. 2-times, 3-times, etc.)

The setBonusToken function allowed the same bonus token to be added multiple times to an array. When bonus rewards were distributed during a withdrawal, the duplicate entries caused the same token to be released more than once, letting early withdrawers receive multiples of their entitled bonus while later withdrawers might get none.

hubble Follow

Originally disclosed on Code4rena

Submitted by hubble, also found by Ruhum

https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L270

https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L629

https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/peripheral_contracts/BathBuddy.sol#L98-L101

Vulnerability details

The function setBonusToken allows the same BonusToken to be added more than once to the array bonusTokens.

  function setBonusToken(address newBonusERC20) external onlyBathHouse {
    bonusTokens.push(newBonusERC20);
  }

Impact

If that happens, early withdrawers can get Bonus in multiples of what they actually have the right to. Late withdrawers, might not get any Bonus due to shortage.

Proof of Concept

BathToken.sol, function setBonusToken

https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L270-L272

  1. function setBonusToken allows the same BonusToken to be added more than once to the array.

    BathToken.sol, function

    distributeBonusTokenRewards

    https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L629

  2. a. As and when distributeBonusTokenRewards is triggered during a withdraw call, the same bonusToken will be released more than once.

    BathBuddy.sol, function release

    https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/peripheral_contracts/BathBuddy.sol#L98-L101

  3. b. The release function is called.

Recommended Mitigation Steps

Add the required validations to avoid duplicate additions of bonus tokens.

  function setBonusToken(address newBonusERC20) external onlyBathHouse {
    require(newBonusERC20 != address(0), "invalid_addr");
    if (bonusTokens.length > 0) {
      for (uint256 index = 0; index < bonusTokens.length; index++) {
        require (token != newBonusERC20, "token already exists")
      }
    }
    bonusTokens.push(newBonusERC20);
  }

bghughes (Rubicon) confirmed

HickupHH3 (judge) commented:

Similar, but different to unbounded tokens case because it’s about duplicates.


The original report as published on Code4rena, by hubble. 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 setBonusToken function lacked a check to prevent adding the same token address more than once to the bonusTokens array.

Impact

Early withdrawers could receive bonus tokens in multiples of their entitlement, potentially leaving later withdrawers with no bonus due to a shortage.

What the attacker needed

The ability to call setBonusToken (onlyBathHouse); a bonus token already added or being added

The fix

The setBonusToken function should be fixed to reject duplicate token addresses by checking the existing array before pushing a new entry.

How it was found

  1. Call setBonusToken with the same bonus token address more than once, adding duplicates to the array.
  2. Trigger a withdrawal that calls distributeBonusTokenRewards.
  3. The release function is called for each duplicate entry, releasing the same bonus token multiple times.

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 stored a list of bonus tokens but did not check for duplicates. If the same token was added twice, the payout logic would send that bonus twice to whoever withdrew first, using up funds meant for others.

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 hubble

View all

11 more disclosed reports, best first.

More from Rubicon v2

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.