claimRewards() If a rewards is too small, it may block other epochs
The reward calculation in claimRewards() can round down to zero for small stakes, and if the payout token does not support zero-value transfers, the claim reverts and blocks subsequent epochs. An attacker could exploit this to prevent other users from claiming rewards or starting new epochs.
Source: https://github.com/sherlock-audit/2023-06-bond-judging/issues/110
Found by
TrungOre, bin2chen, pep7siup
Summary
When claimRewards(), if some rewards is too small after being round down to 0
If payoutToken does not support transferring 0, it will block the subsequent epochs
Vulnerability Detail
The current formula for calculating rewards per cycle is as follows.
function _claimEpochRewards(uint48 epoch_) internal returns (uint256) {
...
@> uint256 rewards = ((rewardsPerTokenEnd - userRewardsClaimed) * stakeBalance[msg.sender]) /
10 ** stakedTokenDecimals;
// Mint the option token on the teller
// This transfers the reward amount of payout tokens to the option teller in exchange for the amount of option tokens
payoutToken.approve(address(optionTeller), rewards);
optionTeller.create(optionToken, rewards);
Calculate rewards formula : uint256 rewards = ((rewardsPerTokenEnd - userRewardsClaimed) * stakeBalance[msg.sender]) /10 ** stakedTokenDecimals;
When rewardsPerTokenEnd is very close to userRewardsClaimed, rewards is likely to be round downs to 0
Some tokens do not support transfer(amount=0)
This will revert and lead to can't claims
Impact
Stuck claimRewards() when the rewards of an epoch is 0
Code Snippet
Tool used
Manual Review
Recommendation
function _claimEpochRewards(uint48 epoch_) internal returns (uint256) {
.....
uint256 rewards = ((rewardsPerTokenEnd - userRewardsClaimed) * stakeBalance[msg.sender]) /
10 ** stakedTokenDecimals;
+ if (rewards == 0 ) return 0;
// Mint the option token on the teller
// This transfers the reward amount of payout tokens to the option teller in exchange for the amount of option tokens
payoutToken.approve(address(optionTeller), rewards);
optionTeller.create(optionToken, rewards);
Discussion
Oighty
Agree with the proposed solution.
ctf-sec
Agree, while the revert in 0 transfer is an edge case, this does block reward distribution and new epoch from starting
Oighty
Fix implemented at https://github.com/Bond-Protocol/options/pull/4
ctf-sec
Hi Oighty, just one more than to highlight
/// @notice Modifier that tries to start a new epoch before a function is executed and rewards the caller for doing so
modifier tryNewEpoch() {
// If the epoch has ended, try to start a new one
if (uint48(block.timestamp) >= epochStart + epochDuration) {
_startNewEpoch();
// Issue reward to caller for starting the new epoch
payoutToken.approve(address(optionTeller), epochTransitionReward);
FixedStrikeOptionToken optionToken = epochOptionTokens[epoch];
optionTeller.create(optionToken, epochTransitionReward);
ERC20(address(optionToken)).safeTransfer(msg.sender, epochTransitionReward);
}
_;
}
if the owner set the epochTransitionReward to zero and the underlying payout token revert in zero amount transfer,
new epoch starting is blocked, the owner is not able to adjust epochTransitionReward in the current codebase
emm we can modify the code to
if (uint48(block.timestamp) >= epochStart + epochDuration) {
_startNewEpoch();
// Issue reward to caller for starting the new epoch
if(epochTransitionReward > 0) {
payoutToken.approve(address(optionTeller), epochTransitionReward);
FixedStrikeOptionToken optionToken = epochOptionTokens[epoch];
optionTeller.create(optionToken, epochTransitionReward);
ERC20(address(optionToken)).safeTransfer(msg.sender, epochTransitionReward);
}
}
that would resolve the issue
also in the constructor of OTLM, can validate the epochTransitionReward to make sure it is not 0
or add a seperate admin function so the owner can update the epochTransitionReward parameter.
ctf-sec
Other than the comments, fix looks good
Oighty
@ctf-sec I added the zero check for the epoch transition reward and also added a setter function so the owner can change it.
ctf-sec
Thanks Oighty, then all good!
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 reward calculation can produce zero due to integer division rounding, and the code does not check for zero before calling token transfer functions that may revert on zero-value transfers.
Impact
A user's claimRewards() call can revert when the calculated reward is zero, potentially blocking reward distribution and preventing new epochs from starting if the payout token does not support zero-value transfers.
What the attacker needed
Payout token does not support zero-value transfers; user has a very small stake or rewards are tiny
The fix
The fix adds a check to return early if the calculated reward is zero, and also adds a zero check and setter for the epoch transition reward.
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.
When you claim rewards, the system calculates how many tokens you earned. If that number is very small, it might round down to zero. Some tokens do not allow sending zero amounts, so the claim fails and can stop other people from claiming or starting new reward periods.
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.