This document outlines the security posture, trust assumptions, and threat model of the PadiPay Soroban smart contracts. It is intended for contributors, auditors, and users to understand the guarantees and limitations of the system.
PadiPay operates as a trust-minimized escrow service. The core assumptions are:
- Soroban Environment: We assume the underlying Stellar network and the Soroban runtime execute instructions correctly, enforce authorization via
require_auth(), and handle integer overflow/underflow safely (Rust panics on overflow by default in debug, but we rely on Soroban's safe math environment). - Mediator Neutrality: When a mediator is assigned to an escrow, they are trusted to act impartially in the event of a dispute. The contract does not mathematically constrain the mediator's decision; it only enforces that only the authorized mediator can route funds during a dispute.
- Ledger Time: We assume
env.ledger().timestamp()is a reliable source of truth for enforcing time-locks and expirations.
The contract strictly enforces authorization for state-changing operations using Soroban's native require_auth().
- Buyer:
- Authorized to
create_escrow. - Authorized to
lock_funds(requires the buyer to sign the token transfer). - Authorized to trigger
execute_timeout(refunds the buyer if the deadline has passed).
- Authorized to
- Seller:
- Cannot initiate or lock funds.
- No direct authorization required in the happy path (the buyer releases funds to them).
- Mediator:
- Authorized to
resolve_dispute. Only the explicitly assigned mediator for a specificEscrowIdcan force a state transition toReleasedorRefunded.
- Authorized to
The escrow lifecycle is governed by a strict state machine defined in EscrowStatus.
- Invariant 1 (Creation): An escrow must begin in the
Createdstate. - Invariant 2 (Funding): Funds can only be locked if the state is exactly
Created. - Invariant 3 (Terminal States):
ReleasedandRefundedare terminal. No further state transitions are permitted once an escrow reaches these states. - Invariant 4 (Time-Locks): A timeout (
execute_timeout) can only be executed if the ledger timestamp strictly exceeds thedeadlinespecified at creation, and the escrow is currentlyLocked.
- Escrow ID Uniqueness: Each escrow is assigned a unique
EscrowIdderived from a globally incrementing nonce (DataKey::EscrowNonce). ID collisions are impossible as long as the nonce does not overflowu64. - Data Integrity: The
EscrowStateis written to persistent storage. It contains immutable parameters (buyer,seller,token,amount,deadline) and a mutablestatus. The immutable parameters cannot be modified after creation.
- Vector: A malicious token contract could attempt to reenter the
lock_fundsorrelease_fundsfunctions during atransfercall. - Mitigation: Soroban natively prevents reentrancy at the host level. Furthermore, the contract updates its state before invoking external token transfers (Checks-Effects-Interactions pattern), rendering reentrancy attacks ineffective.
- Vector: A seller refuses to deliver goods, and the buyer refuses to release funds. Without intervention, funds remain locked indefinitely.
- Mitigation: The
deadlineparameter introduces a time-lock. If the deadline passes, theexecute_timeoutfunction can be called to recover the funds, preventing indefinite locking.
- Vector: An attacker attempts to release funds from an escrow they do not own.
- Mitigation: Every state transition function enforces either
require_auth()from the appropriate party or strict role validation against the persistedEscrowState.
- Vector: An attacker predicts the next
EscrowIdand attempts to pre-calculate or front-run creation. - Mitigation: While the nonce is predictable,
EscrowIdis purely an internal identifier. Knowing it in advance provides no economic advantage or exploit vector, as all sensitive operations require cryptographic authorization from the buyer/seller.
- Single Point of Failure (Mediator): Currently, if the designated mediator loses their private key, disputes cannot be resolved. Future iterations will introduce a decentralized mediator registry and multi-mediator voting.
- Emergency Circuit Breaker: The contract currently lacks a global
pausefunctionality. Adding an admin-controlled circuit breaker is a high-priority future enhancement to freeze new escrows in the event of a zero-day exploit. - Formal Verification: The state machine has been tested extensively via integration tests, but mathematical formal verification of the transitions has not yet been performed.