Skip to content

fix(contracts): SafetyReserve.ratifyAppeal strands a fast-tracked appeal if maxAppealRestitution is lowered below its escrow #702

Closed

Description

@thiras

Problem

fastTrackAppeal escrows restitution at the then-current cap and records it on the appeal:

  • SafetyReserve.sol:444 uint256 escrow = maxAppealRestitution;
  • SafetyReserve.sol:446 totalEscrowLien += escrow;
  • SafetyReserve.sol:448 a.escrowAmount = escrow;

ratifyAppeal then refuses to pay out if the recorded escrow now exceeds the cap:

  • SafetyReserve.sol:476-478
    if (a.escrowAmount > maxAppealRestitution) {
        revert RestitutionExceedsCap(a.escrowAmount, maxAppealRestitution);
    }

But setMaxAppealRestitution has no floor and no guard against in-flight appeals:

  • SafetyReserve.sol:605-609

Consequence

If governance lowers maxAppealRestitution while an appeal is fast-tracked (escrowed at the old, higher cap), ratifyAppeal reverts permanently for that appeal. A validated, multisig-fast-tracked appellant can no longer be made whole. The escrow lien (totalEscrowLien) stays held against availableUsdc(), and the only exit is letting the window lapse and calling cleanupExpiredAppeal, which refunds the bond but pays zero restitution — denying recourse governance already approved and tying up reserve capacity in the meantime.

This is not a duplicate of #687 (TWAP-based MAX_APPEAL_RESTITUTION). In fact, making the cap track a TWAP would make this strictly more likely, since the cap would move on its own between fast-track and ratify.

Suggested direction

Either:

  • Clamp at ratify: uint256 restitution = a.escrowAmount < maxAppealRestitution ? a.escrowAmount : maxAppealRestitution; (and drop the revert), or
  • Treat the fast-track snapshot as binding: the escrow was already solvency-checked and lien-reserved, so honor a.escrowAmount regardless of later cap changes.

Test gap

test/SafetyReserve.t.sol exercises ratifyAppeal and setMaxAppealRestitution only in isolation; add a test that fast-tracks, lowers the cap, then ratifies.

Found during a repository audit.

Activity

  1. added
    kind:bug
    kind:security
    prio:medium
    on May 29, 2026
  2. github-actions commented on May 29, 2026

    @github-actions

    🎯 Triage report

    SafetyReserve.ratifyAppeal has a state-inconsistency bug: it permanently reverts for any appeal that was fast-tracked (escrowed) at a cap higher than the cap at ratify-time, because it compares the snapshot escrow amount against the current maxAppealRestitution and reverts instead of clamping. The only escape is cleanupExpiredAppeal, which refunds the bond but pays zero restitution — denying recourse that governance already approved and holding a totalEscrowLien against available reserve until the window expires. Making the cap TWAP-driven (#687) would make this strictly more likely.

    📊 Assessment

    Dimension Value Reasoning
    Type Bug Confirmed logic error with a permanent-revert consequence
    Labels bug, security, technical, medium (already applied) Correctness/security issue in a payment-path contract; medium severity (requires a governance tx to trigger, but consequence is fund lock + denial of approved restitution)
    Coding agent Suitable Root cause is well-scoped, two concrete fix options are provided, and a specific test gap is identified

    🔗 Similar issues

    💡 Notes and suggestions

    Root cause: ratifyAppeal checks a.escrowAmount > maxAppealRestitution and hard-reverts rather than clamping. The escrow was already solvency-checked and lien-reserved at fast-track time, so honoring the snapshot is both logically consistent and gas-safe.

    Preferred fix (binding snapshot):

    // SafetyReserve.sol ratifyAppeal — replace the revert block with:
    uint256 restitution = a.escrowAmount; // honor the governance-approved snapshot

    The lien already covers this amount, so no additional solvency check is needed.

    Alternative fix (clamp at ratify):

    uint256 restitution = a.escrowAmount < maxAppealRestitution
        ? a.escrowAmount
        : maxAppealRestitution;
    // drop the RestitutionExceedsCap revert

    This is simpler but silently reduces an appellant's payout after governance lowers the cap — arguably a policy choice that should be explicit.

    Recommended test to add in test/SafetyReserve.t.sol:

    1. Fast-track an appeal → escrow recorded at cap C1
    2. Call setMaxAppealRestitution(C1 / 2)
    3. Call ratifyAppeal → assert it succeeds and pays out correctly (not C1 / 2 depends on chosen fix)
    4. Assert totalEscrowLien returns to 0
    

    setMaxAppealRestitution hardening (optional follow-up): Consider adding a floor that prevents the cap from being set below the maximum currently-escrowed appeal amount (totalEscrowLien is insufficient — it aggregates; you need per-appeal tracking or a simpler "no in-flight appeals" guard).

    CLAUDE.md note: This is a Solidity contract fix; run (cd contracts && FOUNDRY_PROFILE=ci forge build --sizes --deny warnings && forge test) and both slither/aderyn checks before pushing. Watch for W5740 unreachable-code warnings if the revert RestitutionExceedsCap block is removed.

    Generated by Agentic Triage for issue #702 · sonnet46 395.9K · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  3. alpergundogdu commented on May 29, 2026

    @alpergundogdu
    Contributor

    Recommend closing as not-planned — the vulnerability is structurally eliminated by the SafetyReserve removal (#708, ADR 033 retired).

    The bug was specific to SafetyReserve.ratifyAppeal: a governance-lowered maxAppealRestitution USDC cap could strand a fast-tracked appeal escrowed at the old cap. That contract is gone, and the new SlashAppeal has none of the moving parts:

    • No ratifyAppeal, no maxAppealRestitution, no escrowAmount-vs-cap check — SlashAppeal never moves USDC (ADR 028: "No MAX_APPEAL_RESTITUTION cap exists").
    • Slashed TOKEN sits in CapacityBond escrow keyed by slashId; grantAppeal refunds it in full, upholdAppeal distributes 50/50 — neither reads a tunable cap. ADR 028 § Negative consequences calls this scenario "structurally impossible."

    I checked the surviving SlashAppeal setters (setAppealBond, setChallengerIncentivePool) for an analogous strand-on-lower bug — neither feeds appeal resolution, so the class doesn't transfer. No code change is warranted against the current surface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugkind:securityprio:medium

    Type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions