Skip to content

Add formal invariant assertion suite enforcing sum(investments) <= sum(invoice amounts) #1199

@Baskarayelu

Description

@Baskarayelu

Description

A protocol-wide solvency invariant is that the total of all active investments held in escrow must never exceed the sum of accepted invoice amounts denominated per currency. This issue introduces a stateful test that asserts this invariant after every public state transition driven by a randomized scenario, and exposes a runtime validate_solvency_invariant(env) admin helper that can be wired into a periodic off-chain check.

Requirements and context

  • Secure: helper is admin-gated and read-only.
  • Tested: invariant checked after every transition in the model.
  • Documented: docs/solvency-invariant.md.
  • Reference: src/lib.rs, src/investment.rs, src/payments.rs.

Suggested execution

git checkout -b feature/solvency-invariant

  • Add src/invariants.rs::validate_solvency_invariant.
  • Add src/test_solvency_invariant.rs driving randomized lifecycles.
  • Docs: docs/solvency-invariant.md.
  • Rust doc comments stating the invariant in plain language.
  • Validate that pause, default, and dispute paths preserve the invariant.

Test and commit

Run cargo test test_solvency_invariant -- --nocapture. Cover edge cases: default refunds, dispute resolutions, partial settlements. Include security note classifying any violation as a P0.

Example commit message

feat(invariants): add protocol-wide solvency invariant and stateful enforcement tests

Guidelines

  • Minimum 95% test coverage
  • Clear documentation in docs/solvency-invariant.md
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    securitySecurity hardening and auditssmart-contractSoroban/Rust smart contract worksorobanStellar Soroban specifictestingTests and coverage

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions