You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The private method _updateBaseRewardHistory updates the list containing the base rewards based on the active rewardConfig. If currentTotalStake is within the active rewardConfig lower and upper bounds, a new baseRewardHistory is not added to the list.
This functionality is implemented in _updateBaseRewardHistory:
The user's expectation is that if they stake enough tokens to hit the higher bound, it should push the reward into the nextrewardConfig.
Recommendation
To make sure that the higher bound is not included in the comparison the condition should be changed to:
// Do nothing if currentTotalStake is in the current base reward boundsif (currentBaseReward.lowerBound <= currentTotalStake && currentTotalStake < currentBaseReward.upperBound) {
return;
}
The higher bound check was changed from a lower than or equal to a strictly lower comparison.
Because this change affects how the upper bound is handled, the findUpperBound method has to be updated to reflect the current logic (the upper bound should be strictly lower).
The Arrays library is no longer needed, but a new method needs to be implemented.
This means that _computeCurrentBaseReward has to be changed to use the new findUpperBound method:
function _computeCurrentBaseReward()
privateviewreturns (uint256)
{
uint256 index =findIntervalIndex(rewardConfig.upperBounds, currentTotalStake);
require(index < rewardConfig.upperBounds.length, "[NotFound] The current total staked is out of bounds");
return index;
}
And a new method findIntervalIndex has to be implemented:
function findIntervalIndex(uint[] storagearray, uintelement) internalviewreturns(uint) {
if (array.length==0|| element < array[0]) {
return0;
}
for (uint i = array.length-1; i >=0; i--) {
if (element >= array[i]) {
return i +1;
}
}
return0;
}
The text was updated successfully, but these errors were encountered:
Description
The private method
_updateBaseRewardHistory
updates the list containing the base rewards based on the activerewardConfig
. IfcurrentTotalStake
is within the activerewardConfig
lower and upper bounds, a newbaseRewardHistory
is not added to the list.This functionality is implemented in
_updateBaseRewardHistory
:https://github.com/ElrondNetwork/pre-staking/blob/a305562874ee0537c7277d78ed16be5178b9e8a1/contracts/StakingContract.sol#L453-L469
The interval check is done in this comparison and it verifies if the
currentTotalStake
is within the bounds or equal to the lower or the higher bound:https://github.com/ElrondNetwork/pre-staking/blob/a305562874ee0537c7277d78ed16be5178b9e8a1/contracts/StakingContract.sol#L463
The user's expectation is that if they stake enough tokens to hit the higher bound, it should push the reward into the next
rewardConfig
.Recommendation
To make sure that the higher bound is not included in the comparison the condition should be changed to:
The higher bound check was changed from a lower than or equal to a strictly lower comparison.
Because this change affects how the upper bound is handled, the
findUpperBound
method has to be updated to reflect the current logic (the upper bound should be strictly lower).The
Arrays
library is no longer needed, but a new method needs to be implemented.This means that
_computeCurrentBaseReward
has to be changed to use the newfindUpperBound
method:And a new method
findIntervalIndex
has to be implemented:The text was updated successfully, but these errors were encountered: