Flow

Sablier
FoundryDeFi
20,000 USDC
View results
Submission Details
Severity: high
Invalid

Analysis of ongoing debt miscalculation in SablierFlow contract

Summary

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.

Vulnerability Details

  1. 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.

  2. 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.

  3. 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.

Impact

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.

Tools Used

Tests

Recommendations

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Too generic

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.