A low severity vulnerability has been identified in the stakeVested
function of the FjordStaking contract. The current implementation could potentially lead to an arithmetic underflow when calculating the remaining amount of a Sablier stream, which could result in transaction reverts.
The vulnerability is present in the stakeVested
function:
The issue lies in the calculation depositedAmount - (withdrawnAmount + refundedAmount)
. If the sum of withdrawnAmount
and refundedAmount
exceeds depositedAmount
, this subtraction will result in an arithmetic underflow, as these variables are of type uint128
.
In Solidity 0.8.x, which this contract uses, arithmetic underflows cause the transaction to revert. However, this revert occurs before the InvalidAmount
error is thrown, potentially leading to confusion about the cause of the failure.
The impact of this vulnerability includes:
Unexpected Reverts: Transactions may revert due to arithmetic underflow rather than the intended InvalidAmount
error, leading to confusion for users and developers.
Potential for Misinterpretation: The arithmetic underflow could be misinterpreted as a different issue, complicating debugging and maintenance.
While the occurrence of this condition (where withdrawn and refunded amounts exceed the deposited amount) should be rare in a properly functioning Sablier stream, it's important to handle all edge cases correctly to ensure robust contract behavior.
Manual
To address this vulnerability and improve the robustness of the stakeVested
function, we recommend modifying the condition to avoid the potential underflow. Here's the suggested fix:
This modification ensures that:
The condition checks if there's any remaining amount in the stream without performing subtraction.
It avoids the potential for arithmetic underflow entirely.
The InvalidAmount
error is thrown as intended when the stream has been fully withdrawn or refunded.
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.