Skip to content

[Security] Internal security audit of Soroban escrow contract #18

Open

Description

@Williams-1604

Overview

Developer-led security review before GrantFox application submission.

Audit checklist

Authorization

  • Every state-changing function calls `require_auth()` on the correct address
  • Admin functions gated to `owner` only
  • `approve_milestone` → `depositor` only
  • `start_work` → `beneficiary` only
  • `rate_freelancer` → post-`Released` state, `depositor` only

State machine

  • No state skipping possible
  • Completed/Refunded escrows are immutable

Arithmetic

  • All `i128` math uses checked operations
  • Platform fee calculation overflow-safe
  • Zero-amount edge cases handled

Token handling

  • Only whitelisted tokens accepted
  • No residual balance after all milestones settle
  • Native XLM and SAC paths both covered

DoS

  • Unbounded `Vec` inputs have max length
  • Ledger entry limits respected

Output

Post audit report as a comment: ✅ passes, ⚠️ findings with severity + fix.

Activity

  1. added
    contractSoroban / Rust smart contract work
    grant-criticalCompleting this directly unblocks the GrantFox application
    securitySecurity-sensitive work
    on May 18, 2026
  2. silentgeckoaudit3801 commented on Jul 13, 2026

    @silentgeckoaudit3801

    Security audit report

    Scope reviewed: contracts/secureflow/src on main at 5a52f4a. This was a static review; I did not run local tooling or deploy the contract.

    ✅ Passes

    • Core role authorization is present on the sensitive user paths I checked: create_escrow requires depositor auth, work submission/start requires beneficiary auth, milestone approval/rejection/refund/deadline extension require depositor auth, and arbiter resolution requires an authorized arbiter.
    • Milestone/arbiter vector sizes are bounded in create_escrow: mismatched milestone arrays, more than 20 milestones, more than 5 arbiters, and
      equired_confirmations > arbiters.len() are rejected.
    • Token whitelisting is enforced before escrow funding, and owner-only admin paths call
      equire_owner.

    ⚠� Findings

    High: native XLM emergency refunds mark funds released without transferring them

    emergency_refund_after_deadline updates the escrow status to Expired and decrements EscrowedAmount, but its native-XLM branch is empty:

    • contracts/secureflow/src/refund_system.rs:100 sets escrow.status = EscrowStatus::Expired.
    • contracts/secureflow/src/refund_system.rs:103-117 reduces escrow accounting by
      efund_amount.
    • contracts/secureflow/src/refund_system.rs:119-125 transfers only if escrow.token is Some; the None branch contains only // Native XLM refund.
    • contracts/secureflow/src/refund_system.rs:127 saves the escrow.

    Impact: for native-XLM escrows that reach the emergency path, the contract records the escrow as expired/released from escrow accounting, but the depositor receives no refund. The funds remain in the contract while the normal escrow state now says the amount is no longer escrowed, which can make user recovery and later accounting unsafe.

    Suggested fix: route this branch through the same native SAC transfer helper used by
    efund_escrow / do_transfer, and update accounting/state only after the transfer succeeds. Add a test for oken == None on emergency_refund_after_deadline that verifies both recipient balance and escrow accounting.

    Medium: escrow creation accepts inconsistent milestone accounting

    create_escrow bounds the milestone count but does not validate that the escrow economics are internally consistent:

    • It does not reject otal_amount <= 0 before using otal_amount for fee calculation, funding transfer, and escrowed accounting (escrow_management.rs:58, 74, 81-85, 98).
    • It allows zero milestones because only milestone_amounts.len() > 20 is checked (escrow_management.rs:40-42).
    • It does not reject zero/negative milestone amounts before saving each milestone (escrow_management.rs:124-142).
    • It does not require sum(milestone_amounts) == total_amount.

    Impact: an escrow can be created with no payable path, with milestone totals lower/higher than deposited funds, or with invalid milestone values. Later, �pprove_milestone trusts the saved milestone amount, increments paid_amount, decrements escrowed accounting, and transfers that amount (work_lifecycle.rs:139-183). This can lock residual funds when milestone totals are below otal_amount, prevent normal completion when totals exceed it, or make accounting depend on token behavior for invalid amounts.

    Suggested fix: in create_escrow, require otal_amount > 0, at least one milestone, every milestone amount > 0, and checked sum equality with otal_amount before any token transfer or escrow ID increment. Add negative/zero/empty/mismatched-sum tests.

    Medium: several required arithmetic operations are unchecked

    The issue asks to verify overflow/underflow protection, but many state-critical operations use direct +, -, or *:

    • escrow_core.rs:30: current_id + 1 for the next escrow ID.
    • escrow_core.rs:102: (amount * fee_bp as i128) / 10000 for platform fee calculation.
    • escrow_management.rs:62: current_ledger + duration / 5 for deadline calculation.
    • escrow_management.rs:98: current_escrowed + total_amount.
    • work_lifecycle.rs:50, 147, 163, 211: fee accumulation, paid amount, escrowed accounting, and completed-count updates.

    efund_system.rs:31, 52, 87, 95, 116, 151, 263, 323, 339, 347: refund amount, escrowed accounting, deadline delay, deadline extension, arbiter award accounting.

    atings.rs:86-87 and 194: rating totals/counts.

    Impact: with enough accumulated state, or with malformed values accepted at creation time, these operations can panic or wrap depending on build/runtime behavior, causing denial of service or incorrect escrow accounting. Even if Soroban traps on overflow in the current toolchain, this still means user actions can hard-fail instead of returning contract errors.

    Suggested fix: replace these with checked_add, checked_sub, and checked_mul, mapping failure to SecureFlowError::InvalidAmount or a dedicated overflow error. For escrowed-accounting subtraction, also require current_escrowed >= amount/refund_amount/available before writing storage.

    Notes

    I did not find missing
    equire_auth on the primary listed flows during this pass. The strongest issue is the emergency native refund path because the state/accounting mutation is present while the transfer is absent.

  3. guptakumarranjeet150 commented on Oct 2, 2026

    @guptakumarranjeet150

    Hello maintainers,

    I would like to take on and implement this issue: [Security] Internal security audit of Soroban escrow contract.

    Technical Implementation Roadmap:

    1. Formal Soroban Invariant Design: Audit storage layout (Instance, Persistent, Temporary) with strict TTL management and explicit require_auth guards.
    2. Core Rust WASM Implementation: Implement deterministic state transition handlers eliminating arithmetic overflow risks using checked/saturating math.
    3. Hermetic Testing Suite: Build comprehensive test cases in tests/ asserting authorized vs unauthorized invocations, mock auth environments, and edge value bounds.
    4. Gas & Footprint Optimization: Profile CPU/memory instruction budgets under Soroban host environment to ensure optimal runtime efficiency.

    I have worked extensively on similar architectures and can deliver this cleanly within 24 hours. Please assign to me!

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

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaigncontractSoroban / Rust smart contract workgrant-criticalCompleting this directly unblocks the GrantFox applicationsecuritySecurity-sensitive work

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions