A medium severity vulnerability has been identified in the unstake
function of the FjordStaking contract. The current implementation lacks proper input validation for the _epoch
parameter, which could lead to an arithmetic underflow when calculating the difference between the current epoch and the input epoch. This could result in unexpected behavior, including bypassing the intended lock period for unstaking.
The vulnerability is present in the unstake
function:
The issue lies in the calculation currentEpoch - _epoch
. If _epoch
is greater than currentEpoch
, this subtraction will result in an arithmetic underflow, as these variables are of type uint16
. In Solidity 0.8.x, which this contract uses, arithmetic underflows cause the transaction to revert.
The impact of this vulnerability includes:
Unexpected Reverts: Transactions may revert due to arithmetic underflow rather than the intended UnstakeEarly
error, leading to confusion for users and developers.
Manual
To address this vulnerability and improve the robustness of the unstake
function, we recommend adding an explicit check to ensure that the input _epoch
is not greater than the currentEpoch
. Here's the suggested fix:
This modification ensures that:
The function reverts with a clear error message if a future epoch is provided.
It prevents any potential arithmetic underflow in the subsequent calculations.
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.