[Exchange] Smart-contract bounty escrow — trustless $5K–$960K challenge funding

← All Specs

Goal

CLAUDE.md cites $5K–$960K bounties live in the Exchange today, but
funds are bookkept off-chain in token_accounts with no trustless
release mechanism — a corrupt admin could re-route a payout. Build a
bounty-escrow contract: a sponsor locks tokens (USDC on Polygon) at
challenge creation; payout is gated on a Senate-multisig signature
plus a public verifier predicate (e.g. an oracle returning
"hypothesis confirmed by replication"). On expiry without a winner,
funds auto-return to sponsor.

Acceptance Criteria

☐ Contract contracts/BountyEscrow.sol: createBounty(bytes32 challengeId, address asset, uint256 amount, address verifier, uint256 expiresAt) external and claim(bytes32 challengeId, address winner, bytes calldata verifierProof) and refund(bytes32 challengeId).
☐ Verifier interface IBountyVerifier.isWinner(challengeId, winner, proof) -> bool so different challenge types plug in different verifiers (replication, market settlement, peer review threshold).
scidex/exchange/bounty_escrow.py::create_escrow(challenge_id) reads existing challenges table, locks the sponsor's tokens, returns tx_hash.
☐ DB mirror bounty_escrow_state(challenge_id PK, escrow_address, asset, amount, status, expires_at, claim_tx, refund_tx).
/exchange/{challenge_id} page shows escrow status, on-chain link, and live USDC balance from RPC.
☐ When a challenge is judged "won" by Senate, the existing settlement path now calls bounty_escrow.claim(...) with a multisig-signed proof.
☐ Test: create bounty for 100 USDC; advance time past expiry without claim; refund returns to sponsor; alternate scenario: sign winner proof → winner balance goes up by 100 USDC.

Approach

  • Read scidex/exchange/exchange.py and funding_allocators.py for current settlement flow.
  • Use OpenZeppelin's SafeERC20 wrapper — never raw transfer.
  • Verifier proof = ABI-encoded (senate_multisig_signature, replication_artifact_id) so Senate's role is auditable on chain.
  • Test against testnet USDC (LINK faucet substitute on Amoy).
  • Add a paused admin escape-hatch for emergencies (multisig-only).
  • Dependencies

    • q-cw-multisig-funding-decisions (multisig used as the claim authoriser).
    • q-cw-polygon-testnet-provenance (chain client).

    Work Log

    Tasks using this spec (1)
    [Exchange] Smart-contract bounty escrow - trustless challeng
    Crypto Wallets running P90
    File: q-cw-bounty-escrow-contract_spec.md
    Modified: 2026-04-27 03:19
    Size: 2.4 KB