The SablierFlow
contract facilitates streaming payments over time using a debt accrual system. A critical aspect of this system is the ongoing debt calculation, which depends on the difference between block.timestamp
and snapshotTime
. Mismanagement of these parameters can lead to overestimation or underestimation of the ongoing debt, causing financial inconsistencies. This report outlines the vulnerability, its impact, and recommendations for mitigation.
Overestimation of Debt:
Occurs when the ongoing debt is calculated as higher than it should be.
Primary Cause: Failure to update snapshotTime
after modifying stream parameters like ratePerSecond
. If the timestamp remains unchanged, the accrued debt will account for an extended period, leading to inflated debt values.
Underestimation of Debt:
Occurs when the ongoing debt is calculated as lower than expected.
Primary Cause: Incorrect or delayed updates to snapshotTime
, or failing to reset it when resuming a paused stream. As a result, the debt accrual period becomes shorter, resulting in an understated debt amount.
Debt Resetting Logic Flaws:
If the reset logic does not properly recalculate debt and update the timestamp, it may introduce discrepancies that accumulate over time, exacerbating the problem.
Financial Discrepancies:
Overestimation Impact:
Stream recipients may withdraw more tokens than they should, depleting the contract’s reserves faster than intended.
Risk of insolvency if excessive withdrawals reduce the available funds for other streams.
Underestimation Impact:
Recipients receive less than their entitled amount, causing unfair distribution and potential reputational damage to the contract's owner or service provider.
Accumulation of unpaid liabilities, which could become problematic if a significant payout is required.
Contract Solvency Risks:
Overestimation may lead to premature depletion of funds, making the contract unable to fulfill future obligations.
Underestimation could create large future liabilities that are difficult to manage if suddenly claimed.
Potential for Exploitation:
Malicious actors could attempt to exploit timing vulnerabilities to withdraw more funds than permitted.
Tests
Accurate Timestamp Management:
Always update snapshotTime
to block.timestamp
whenever debt-related parameters are modified (e.g., when pausing, resuming, or adjusting the rate).
Ensure that the snapshotTime
is correctly reset during operations like stream restarts and voiding.
Thorough Testing and Simulation:
Implement extensive unit tests covering all possible scenarios, including frequent rate adjustments and edge cases where the stream is paused or modified.
Use fuzz testing to simulate random changes in contract state and identify vulnerabilities.
Debt Calculation Audits:
Conduct regular audits to review debt calculation logic, especially when changes are made to the contract.
Periodically review and optimize the debt logic to ensure it remains robust and secure.
Event-Based Monitoring:
Emit detailed events whenever significant changes are made to the stream, such as debt resets, pauses, and rate adjustments. This will help in auditing and troubleshooting.
Static and Dynamic Analysis:
Use static analysis tools to automatically detect potential logical errors and inefficiencies.
Regularly deploy dynamic analysis tools to test the contract in a simulated blockchain environment.
Consider a Safety Mechanism:
Implement safety checks or limits on the maximum amount that can be withdrawn within a given time frame to prevent excessive withdrawals.
Consider adding a buffer or grace period for debt recalculations to minimize timing discrepancies.
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.