Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERC20Rewards.sol: Have a method to calculate the latest rewardsPerToken accumulated value #57

Open
code423n4 opened this issue Aug 14, 2021 · 1 comment

Comments

@code423n4
Copy link
Contributor

Handle

hickuphh3

Vulnerability details

Impact

This would be equivalent to Unipool's rewardPerToken() function. Note that rewardsPerToken.accumulated only reflects the latest stored accumulated value, but does not account for pending accumulation like Unipool, and is therefore not the same. It possibly might be mistaken to be so, hence the low risk classification.

Recommended Mitigation Steps

A possible implementation is given below.

function latestRewardPerToken() external view returns (uint256) {
	RewardsPerToken memory rewardsPerToken_ = rewardsPerToken;
	if (_totalSupply == 0) return rewardsPerToken_.accumulated;
	uint32 end = earliest(block.timestamp.u32(), rewardsPeriod.end);
	uint256 timeSinceLastUpdated = end - rewardsPerToken_.lastUpdated;
	return rewardsPerToken_.accumulated + 1e18 * timeSinceLastUpdated * rewardsPerToken_.rate / _totalSupply;
}
@code423n4 code423n4 added 1 (Low Risk) bug Something isn't working labels Aug 14, 2021
code423n4 added a commit that referenced this issue Aug 14, 2021
@alcueca
Copy link
Collaborator

alcueca commented Aug 15, 2021

Thanks for the suggestion. Even if there is no risk, it will be nice to have this on frontends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants