Skip to content
Business logic Audit finding Intermediate

A malicious user can send tokens to the TribeRedeemer contract to make the redeem function work, and other users may lose assets as a result

The TribeRedeemer contract's redeem function only checks that reward token balances are non-zero, so a malicious user could send a tiny amount of reward tokens to the contract, making the balance non-zero and allowing early redemptions. A user who redeems early would receive far fewer reward tokens than if they had waited for the full reward tokens to be deposited.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz

In the TribeRedeemer contract, the user provides redeemedToken to redeem the tokens in the list. The transaction will revert when the balance of tokens in the list is 0. This prevents the user from losing their redeemedToken if they redeem when there are no tokens in the contract.

        for (uint256 i = 0; i < tokensReceived.length; i++) {
            uint256 balance = IERC20(tokensReceived[i]).balanceOf(address(this));
            require(balance != 0, "ZERO_BALANCE");
            // @dev, this assumes all of `tokensReceived` and `redeemedToken`
            // have the same number of decimals
            uint256 redeemedAmount = (amountIn * balance) / base;   // 10^6 * 10^18 / 10^8*10^6
            amountsOut[i] = redeemedAmount;
        }

However, a malicious user could send tokens in the list to the TribeRedeemer contract so that the token balance is not 0. This would allow the redeem function to work, and the user would suffer a loss when they redeem early by mistake.

Proof of Concept

TribeRedeemer.sol#L44-L61

Recommended Mitigation Steps

Consider making the TribeRedeemer contract inherit the Pausable contract and allow users to redeem when a sufficient number of tokens have been sent to the contract.

thomas-waite (FEI and TRIBE) disputed and commented:

Do not understand what the issue presented is. If the attacker sends funds to the contract so the balances are not 0, then the user would be able to redeem as normal. How do they suffer any loss if they ‘redeem early’?

The balances will only be 0 when all users have redeemed. Not an issue.

cccz (warden) commented:

@thomas-waite, consider the following scenario.

  1. there are no reward tokens in the TribeRedeemer contract now, (the administrator will transfer 100M reward tokens to the contract in exchange for the user’s redeemedToken only after some time).

  2. when the user provides redeemedToken to call the redeem function, the transaction reverts in the previewRedeem function because the reward token balance is 0 (this prevents the user from getting 0 reward tokens).

        for (uint256 i = 0; i < tokensReceived.length; i++) {
            uint256 balance = IERC20(tokensReceived[i]).balanceOf(address(this));
            require(balance != 0, "ZERO_BALANCE");
    
  3. a malicious user can send 100 reward tokens to the contract in advance.

  4. At this point, if the user calls the redeem function, the transaction will not revert and the contract will exchange the 100 reward tokens for the user’s redeemedToken. The user could have exchanged the redeemedToken for more reward tokens, but the user only got a small amount of reward tokens

hickuphh3 (judge) commented:

Redemptions can only begin when the contract has non-zero balances for all redeemed tokens, but the start redemption time isn’t explicitly stated.

Malicious users can break this assumption by sending paltry amounts to the contract as explained above. Naiive users might begin redemptions early, thus losing out on the tokens they would’ve otherwise received after the full redemption token amounts have been sent to the contract.

It is unclear if there is a time lag between the contract deployment and time at which redemption funds are sent, and if so, its duration.

While unlikely to happen, it would be a case of users losing out on rewards they should be entitled to. Hence, I’m siding with the warden in this instance.

thomas-waite (FEI and TRIBE) commented:

@hickuphh3 , the contract gets deployed ahead of time by necessity (the address is needed for the DAO vote). The DAO vote which funds the contract executes after deployment, there is a time lag of >= 3 days.

I do not agree that the situation described is a vulnerability in the contract and instead it would be down to user/deployer error. Clearly, no user was encouraged to redeem before funds were available and the contract address was not publicised. So no user attempted to redeem before funds were available.

hickuphh3 (judge) commented:

I respectfully disagree.

There is no doubt that there are a number of prerequisites to enable this attack, which makes the likelihood low:

  • Malicious actor has to know what the redeemer contract is
  • Malicious actor has to deposit some tokens into redeemer contract
  • Malicious actor must be able to trick users into redeeming early

From a game theory POV, small TRIBE holders could band together to target a few large TRIBE holders.

With these external requirements, it is only then that we will see what could be deemed as “protocol leaked value”.

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 scenario thankfully remained hypothetical.


The original report as published on Code4rena, by cccz. 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 contract uses a simple non-zero balance check instead of verifying that a sufficient amount of reward tokens has been deposited before allowing redemptions.

Impact

A user could lose value by redeeming early for a small amount of reward tokens instead of waiting for the full deposit, though the attack requires the attacker to know the contract, deposit tokens, and trick users into redeeming early.

What the attacker needed

Attacker knows the redeemer contract address; attacker can send tokens to the contract; attacker can trick users into redeeming early

The fix

The contract should inherit Pausable and only allow redemptions when a sufficient number of reward tokens have been sent.

How it was found

  1. The contract has no reward tokens yet, so redemptions revert.
  2. A malicious user sends a small amount of reward tokens to the contract.
  3. A user calls redeem and receives only the small amount of reward tokens in exchange for their redeemed tokens.

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.

This is a smart contract that lets users swap one token for another. The contract is supposed to wait until it has enough reward tokens before letting anyone swap, but it only checks that the reward token balance is not zero. An attacker can send a tiny amount of reward tokens to the contract, making the balance non-zero, so the contract lets users swap early and they get very few reward tokens in return.

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 cccz

View all

104 more disclosed reports, best first.

More from FEI and TRIBE Redemption contest

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.