Submitted by 0xsomeone, also found by carrotsmuggler, rvierdiiev, and said
The LendingLedger system will employ a distinct time system from the VotingEscrow and GaugeController implementations whereby rewards are denoted per block rather than based on time.
From an implementation perspective, there is no real reason to implement this distinction as the LendingLedger can be simply updated to utilize a reward-per-second system instead.
To work around this discrepancy, the LendingLedger implements an imprecise time measurement for evaluating the epochTime whenever a market update occurs through LendingLedger::update_market.
In detail, the following variables are configured and utilized:
The vulnerability lies in the fact that an overestimation of the time (i.e. a future time) will result in a IGaugeController::gauge_relative_weight_write result of 0, effectively nullifying the full reward of the epoch which may be up to 1 week worth of rewards.
Specifically, GaugeController::_gauge_relative_weight will yield 0 in the case the total weight of the epoch is 0 (points_total), a case that will occur 100% if the input time of the function exceeds the current block.timestamp to an extent that it would cause it to flow into the next WEEK.
This error does not need to necessarily be a full WEEK, as a timestamp at 5 weeks - 1 will fall in week 4 which can be calculated, while a timestamp at 5 weeks will fall in week 5 which would be in the future and thus not calculate-able.
It is impossible to programmatically approximate the number of blocks in a particular time period for any blockchain; meaning, that the vulnerability will manifest itself with a high possibility as either an overestimation or underestimation of time elapsed for the number of blocks will occur in the LendingLedger.
An overestimation of time elapsed by the LendingLedger::update_market function will lead to the rewards for a particular epoch being 0 even though the gauge may have had a non-zero relative weight due to the weight not having been tracked yet for the miscalculated future timestamp.
The non-zero rewards that should have been distributed for the latest epoch will not be processed correctly and would be considered 0.
I tried implementing a PoC in the forge toolkit; however, the test harness of LendingLedger.t.sol utilizes a mock GaugeController (DummyGaugeController) that yields a fixed value for the lookup and thus would require extensive time to re-build the test suite for just this PoC.
The actual vulnerabilitys validity can be observed in the GaugeController::gauge_relative_weight_write function, which also denotes that the _time should be a timestamp in the past or present.
If a future timestamp is provided (which the code permits), the GaugeController::_get_weight and GaugeController::_get_total functions would update the weights in the system up to the current block.timestamp, and the future week queried by the GaugeController::_gauge_relative_weight would yield 0.
Due to the blockchains by-design nature, it is impossible to precisely measure the time that has elapsed between two block numbers. As such, the likelihood at which this vulnerability would manifest is high.
A severity of Medium was assessed because even though rewards would be lost, they can be re-instated via administrative action through adjustment of the rewards per block to carry the rewards over to the next period.
A severity of High could be valid if we eliminate administrative intervention, and we consider that the secRewardDebt data point would become corrupted. Although meant for secondary rewards, it presently remains unused and would be corrupted in the aforementioned scenario as the accCantoPerShare value would be incremented by 0 while the secRewardsPerShare would be incremented by a non-zero value.
I would advise the LendingLedger implementation to be updated to a time-based reward mechanism instead, ensuring that it remains in sync with the GaugeController.
Math
OpenCoreCH (Neobase) confirmed
0xTheC0der (judge) commented:
