Closed code423n4 closed 1 year ago
duplicate of #304 and #348, will work on it later.
hansfriese marked the issue as satisfactory
hansfriese marked the issue as duplicate of #304
hansfriese marked the issue as duplicate of #261
hansfriese marked the issue as not a duplicate
hansfriese marked the issue as duplicate of #304
hansfriese changed the severity to QA (Quality Assurance)
hansfriese marked the issue as grade-c
Lines of code
https://github.com/code-423n4/2023-03-neotokyo/blob/main/contracts/staking/NeoTokyoStaker.sol#L1124-L1174 https://github.com/code-423n4/2023-03-neotokyo/blob/main/contracts/staking/NeoTokyoStaker.sol#L1597-L1644
Vulnerability details
Impact
There is a precision loss in the amount of points accrued when staking LP tokens using the
_stakeLP()
function.Similarly, there is a precision loss in the amount of points subtracted when withdrawing LP tokens using the
_withdrawLP()
function.Proof of Concept
NeoTokyoStaker.sol#L1124-L1174
In line 1155:
The first division can greatly truncate the value of
amount * 100 / 1e18
. The result is then multiplied withtimelockMultiplier / _DIVISOR
. This can result in lower than expected rewards in the form of BYTES 2.0 tokens supplied to user due to lower than expected accrued points. When calculatingpoints
accrued,points
should be normalized and scaled by token precision._withdrawLP
NeoTokyoStaker.sol#L1597-L1644
In line 1623:
Similarly, there is a precision loss in the amount of points subtracted when withdrawing LP tokens using the
_withdrawLP()
function. The first division can greatly truncate the value ofamount * 100 / 1e18
. This can result in more than expected rewards in the form of BYTES 2.0 tokens supplied to user in the future due to more than expected points remaining based on staked LP tokens. When calculatingpoints
accrued,points
should be normalized and scaled by token precision.Tools Used
Manual Analysis
Recommended Mitigation Steps
The protocol should avoid divison before multiplication and always perform division operation last
Example: