Updating the vault's yield rate in the LibVault.updateYield
function can lead to a loss of yield if the newly received ETH yield is small due to rounding errors.
The updateYield
function in the LibVault
library is called by the permissionless YieldFacet.updateYield
function and used to update the vault's yield rate from staking rewards earned by bridge contracts holding LSD.
The newly accumulated yield, i.e., ETH received since the last update, is calculated by subtracting the current zethTotalNew
from the previously stored yield zethTotal
, as seen in line 75 of the updateYield
function.
contracts/libraries/LibVault.sol#L92
After determining the new yield (ETH), a fraction of the yield is assigned to the TAPP (treasury). Thereafter, the remaining yield is realized by adding it to the vault's yield rate (zethYieldRate
), which is calculated by dividing the yield
by the vault's short collateral, zethCollateral
.
[!NOTE]
Both theyield
andzethCollateral
values are in 18 decimal precision due to tracking ETH balances.
By using the divU80
function, the zethYieldRate
is calculated as
However, if the numerator is smaller than the denominator, i.e., the received ETH yield is very small and the vault's collateral large enough, the result of the division will be rounded down to 0, leading to a loss of the remaining yield.
As anyone is able to call the public YieldFacet.updateYield
function, this can be used to maliciously cause a loss of yield for all users if the newly received yield is small.
The following test case demonstrates the described rounding error:
How to run this test case:
Save git diff to a file named test.patch
and run with
Result:
Loss of LSD ETH yield for users of the same vault.
Manual Review
Consider storing the rounding error and applying the correcting factor (error stored) the next time, or alternatively, prevent (skip) updating the yield if the resulting yield is 0.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.