_coveredDebtOf
function in the SablierFlow
contract uses a strict equality check balance == 0
to determine if the balance is zero. However, this check does not consider the case where the balance is a very small value (e.g., 1) that is effectively zero.Vulnerable Functionality: The _coveredDebtOf
function is used to calculate the amount of covered debt by the stream balance.
Attack Vector: An attacker can exploit this vulnerability by creating a stream with a very small balance (e.g., 1) that is effectively zero.
Exploitation: To exploit this vulnerability, an attacker would need to create a stream with a very small balance and then call the _coveredDebtOf
function to calculate the amount of covered debt.
Incorrect Calculation: The _coveredDebtOf
function is used to calculate the amount of covered debt by the stream balance. If the function returns an incorrect result, it could lead to incorrect calculations in other parts of the code that rely on this value.
Financial Losses: In the context of the SablierFlow contract, the covered debt represents the amount of debt that has been paid off by the stream balance. If the function returns an incorrect result, it could lead to incorrect calculations of the covered debt, which could result in financial losses for the users of the contract.
Attack Vector: An attacker can exploit this vulnerability by creating a stream with a very small balance (e.g., 1) that is effectively zero. By doing so, the attacker can manipulate the _coveredDebtOf
function to return an incorrect result, which could then be used to perform further attacks or exploit other parts of the code.
_coveredDebtOf
function..This proof of concept code creates a contract called SablierFlow
that has a function called _coveredDebtOf
that is vulnerable to the attack. The contract also has a function called createStream
that allows the attacker to create a stream with a very small balance.
The Attacker
contract is used to demonstrate the attack. It creates a stream with a very small balance and then gets the covered debt of the stream using the getCoveredDebt
function. If the covered debt is not zero, then the attack was successful.
Recommendation 1: Use a More Robust Comparison Method
Instead of using a strict equality check (balance == 0
), use a comparison that considers the balance as effectively zero if it is less than or equal to a small threshold value (e.g., 1).
This will ensure that the _coveredDebtOf
function returns the correct result, even when the balance is a very small value.
Recommendation 2: Update the _coveredDebtOf
Function
Update the _coveredDebtOf
function to use the more robust comparison method:
Recommendation 3: Review and Test the Updated Code
Review the updated code to ensure that it is correct and does not introduce any new vulnerabilities.
Test the updated code thoroughly to ensure that it works as expected and does not produce any incorrect results.
Recommendation 4: Consider Using a Library for Safe Arithmetic Operations
Consider using a library like OpenZeppelin's SafeMath to perform safe arithmetic operations.
This will help prevent overflow and underflow errors, and ensure that the code is more secure.
Recommendation 5: Review and Update Other Parts of the Code
Review other parts of the code that rely on the _coveredDebtOf
function to ensure that they are correct and do not introduce any new vulnerabilities.
Update other parts of the code as necessary to ensure that they work correctly with the updated _coveredDebtOf
function.
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.