Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

yixxas - Rewards are updated wrongly if collateral is not 18 decimals #23

Closed
sherlock-admin opened this issue Mar 13, 2023 · 0 comments
Closed
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Mar 13, 2023

yixxas

high

Rewards are updated wrongly if collateral is not 18 decimals

Summary

The calculation of tauEarned in updateReward is incorrect when collateral used is not 18 decimals. This can critically break the protocol.

Vulnerability Detail

This is how _tauEarned is calculated in updateReward

uint256 _rewardDiff = cumulativeTauRewardPerCollateral - userDetails[_account].lastUpdatedRewardPerCollateral
uint256 _tauEarned = (_rewardDiff * _userCollateral) / Constants.PRECISION

_rewardDiff is calculated based on the cumulativeTauRewardPerCollateral. Since TAU is 18 decimals, _rewardDiff is 18 decimals. Constants.PRECISION is 18 decimals as well, and hence the resulting computation of _tauEarned will be based on the number of decimals of _userCollateral.

However, correct decimals for _tauEarned should be 18 as TAU token is 18 decimals. Subsequent computations based on either an inflated or deflated value of _tauEarned will break the protocol.

Impact

Protocol cannot function correctly if collateral used is not 18 decimals.

Code Snippet

https://github.com/sherlock-audit/2023-03-taurus/blob/main/taurus-contracts/contracts/Vault/BaseVault.sol#L90

Tool used

Manual Review

Recommendation

Consider dividing by number of decimals of collateral instead of Constants.PRECISION

- uint256 _tauEarned = (_rewardDiff * _userCollateral) / Constants.PRECISION
+ uint256 _tauEarned = (_rewardDiff * _userCollateral) / 10 ** decimals()

Duplicate of #35

@github-actions github-actions bot added High A valid High severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Mar 21, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant