Skip to content
Business logic Audit finding Intermediate

ERC20Rewards breaks when setting a different token

The setRewards function allows changing the reward token, but unclaimed rewards from previous periods are paid in the new token without adjusting for decimals or value. An attacker could wait for a token with fewer decimals and claim a vastly larger amount.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

The setRewards function allows setting a different token. Holders of a previous reward period cannot all be paid out and will receive their old reward amount in the new token.

This leads to issues when the new token is more (less) valuable, or uses different decimals.

Example: Assume the first reward period paid out in DAI which has 18 decimals. Someone would have received 1.0 DAI = 1e18 DAI if they called claim now. Instead, they wait until the new period starts with USDC (using only 6 decimals) and can claim their 1e18 reward amount in USDC which would equal 1e12 USDC, one trillion USD.

Changing the reward token only works if old and new tokens use the same decimals and have the exact same value. Otherwise, users that claim too late/early will lose out.

Recommend disallowing changing the reward token, or clearing user’s pending rewards of the old token. The second approach requires more code changes and keeping track of what token a user last claimed.

alcueca (Yield) confirmed:

Maybe I should have used stronger language: // If changed in a new rewards program, any unclaimed rewards from the last one will be served in the new token

The issue is known, but you are right in pointing it out. There are few situations in which changing the rewards token would make sense (such as replacing a faulty rewards token by a fixed one). I think it would be best to just disallow changing the token.

alcueca (Yield) patched:

Fix

The original report as published on Code4rena, by cmichel. 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 does not track which token a user's pending rewards were earned in, and pays out the raw amount in the new token without conversion.

Impact

If the new token has fewer decimals or is more valuable, users who claim late could receive an excessive amount, potentially draining the contract; the text notes this only works if decimals and value match.

What the attacker needed

Owner changes reward token; new token has different decimals or value; user delays claim until after change

The fix

The project patched the issue by disallowing changing the reward token.

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 lets you earn rewards in a token. The owner can change which token is used for rewards. If they change to a token with fewer decimals, your old reward amount (stored as a big number) becomes worth much more when paid in the new token. This means you could get far more than intended.

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 cmichel

View all

196 more disclosed reports, best first.

More from Yield Witch v2 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.