Slashing during `LSTCalculatorBase.sol` deployment can show bad apr for months
The APR calculation for a liquid staking token uses a function that floors negative changes at zero, so a slashing event during the initial 9-day observation period sets the initial APR to zero. Because subsequent updates only apply a 10% weight to new values, it can take up to 84 days for the APR to recover to the correct level, causing suboptimal fund allocation.
carrotsmuggler Follow with saidam017 and xiaoming90
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-tokemak-judging/issues/824
Found by
carrotsmuggler, saidam017, xiaoming90
Slashing during LSTCalculatorBase.sol deployment can show bad apr for months
Vulnerability Detail
The contract LSTCalculatorBase.sol has some functions to calculate the rough APR expected from a liquid staking token. The contract is first deployed, and the first snapshot is taken after APR_FILTER_INIT_INTERVAL_IN_SEC, which is 9 days. It then calculates the APR between the deployment and this first snapshot, and uses that to initialize the APR value. It uses the function calculateAnnualizedChangeMinZero to do this calculation.
The issue is that the function calculateAnnualizedChangeMinZero has a floor of 0. So if the backing of the LST decreases over that 9 days due to a slashing event in that interval, this function will return 0, and the initial APR and baseApr will be set to 0.
The calculator is designed to update the APR at regular intervals of 3 days. However, the new apr is given a weight of 10% and the older apr is given a weight of 90% as seen below.
return ((priorValue * (1e18 - alpha)) + (currentValue * alpha)) / 1e18;
And alpha is hardcoded to 0.1. So if the initial APR starts at 0 due to a slashing event in the initial 9 day period, a large number of updates will be required to bring the APR up to the correct value.
Assuming the correct APR of 6%, and an initial APR of 0%, we can calculate that it takes upto 28 updates to reflect close the correct APR. This transaltes to 84 days. So the wrong APR cann be shown for upto 3 months. Tha protocol uses these APR values to justify the allocation to the various protocols. Thus a wrong APR for months would mean the protocol would sub optimally allocate funds for months, losing potential yield.
Impact
The protocol can underperform for months due to slashing events messing up APR calculations close to deployment date.
Code Snippet
Tool used
Manual Review
Recommendation
It is recommended to initialize the APR with a specified value, rather than calculate it over the initial 9 days. 9 day window is not good enough to get an accurate APR, and can be easily manipulated by a slashing event.
Discussion
codenutt
This behavior is acceptable. If we happen to see a slash > 12 bps over the initial 9 days, yes, we set it to 0. It increases the ramp time for that LST so pools with that LST will be set aside for a while until some APR (incentive, etc) comes up. For larger slashes that are more material (> 25bps), we have a 90 day penalty anyway.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the use of a function that floors negative changes at zero for initial APR calculation, combined with a slow exponential moving average update, means a slashing event during the initial period permanently biases the APR downward for an extended time.
Impact
The protocol could underperform for months due to misallocated funds caused by an artificially low APR after a slashing event near deployment.
What the attacker needed
Slashing event during initial 9 days; deployment of LSTCalculatorBase
The fix
The APR should be initialized with a specified value rather than calculated over the initial 9-day window, which is too short and susceptible to slashing events.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A liquid staking token (LST) represents staked cryptocurrency and earns rewards, but its value can drop if the validator misbehaves (a 'slashing' event). The protocol calculates an annual percentage rate (APR) to decide where to invest funds. If a slashing happens right after the calculator is deployed, the APR is set to zero and then updated very slowly, so the protocol may make poor investment choices for months.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.