Skip to content

Contracts: Add security audit preparation — natspec, invariants, and threat model doc #316

@CelestinaBeing

Description

@CelestinaBeing

Summary

Before deploying to mainnet with real value at stake, the contracts need to be prepared for a formal external security audit. This means: complete NatSpec/doc comments, documented invariants, and a threat model doc that auditors can use to scope their work efficiently.

Problem

  • Inline doc comments are present but inconsistent — some functions have no docs
  • No formal statement of contract invariants (what must always be true)
  • No threat model documenting trusted roles, attack surfaces, and known limitations
  • Without these, an external audit will be slower, more expensive, and may miss context-specific issues

Acceptance Criteria

NatSpec / Rust doc comments

  • All public functions in contracts/rewards/src/lib.rs and contracts/campaign/src/lib.rs have complete /// doc comments with: @param, @returns, @emits, @errors sections
  • All error variants in the Error enums are documented with when they're returned

Invariants document

  • Create contracts/INVARIANTS.md documenting:
    • Rewards: sum(all balances) + total_claimed == sum(all credits ever)
    • Rewards: balance(user) >= 0 always (enforced by u64 semantics)
    • Campaign: participant_count <= max_cap when max_cap > 0
    • Campaign: participant_count only increments, never decrements
    • Both: only admin can call admin-only functions

Threat model

  • Create docs/THREAT_MODEL.md covering:
    • Trusted roles (admin key holder)
    • Attack vectors: admin key compromise, Soroban RPC manipulation, replay attacks, TTL expiry
    • Known limitations and accepted risks
    • Out-of-scope (Stellar network-level attacks)

References

  • contracts/rewards/src/lib.rs
  • contracts/campaign/src/lib.rs
  • docs/

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions