Skip to content

feat(contract): implement anti-frontrunning commit-reveal mechanism for competitive payroll bounties (#212) - #214

Open
markankamaransheogarat-sys wants to merge 2 commits into
Orbit-xyz:mainfrom
markankamaransheogarat-sys:feat/contract-commit-reveal-bounty-212
Open

markankamaransheogarat-sys wants to merge 2 commits into
Orbit-xyz:mainfrom
markankamaransheogarat-sys:feat/contract-commit-reveal-bounty-212

Conversation

@markankamaransheogarat-sys

Copy link
Copy Markdown

Summary

Resolves #212.

Implements a cryptographic two-phase commit-reveal claim scheme with an enforced challenge delay window for competitive payroll bounties on Stellar/Soroban. This mechanism prevents mempool frontrunning bots from observing valid bounty solutions/proofs, extracting preimages, and frontrunning legitimate contributors with higher gas fees.


Architectural Design & Threat Model

 Phase 1: COMMIT
 Contributor (Alice)           Mempool / Frontrunner (Bob)           Soroban Contract
       │                                   │                                │
       ├────── commit_bounty_claim ───────►│                                │
       │       (Alice, hash)               │                                ├─ Stores commitment
       │                                   │                                │  commit_ledger = seq
       │                                   ├─ Observes commitment           │
       │                                   ├─ Copies hash under Bob's addr  │
       │                                   ├─ commit_bounty_claim(Bob, hash)┼─ Bob commits
       │                                   │                                │
       ▼                                   ▼                                ▼
 ~~~~~ Enforce CHALLENGE DELAY WINDOW (>= 5 ledgers / ~25s) ~~~~~~~~~~~~~~~~~
       ▲                                   ▲                                ▲
 Phase 2: REVEAL                           │                                │
 Contributor (Alice)                       │                                │
       │                                   │                                │
       ├────── reveal_bounty_claim ───────►│                                │
       │       (Alice, proof, salt)        ├─ Intercepts proof/salt in tx   │
       │                                   ├─ Attempts reveal(Bob, proof)───┼─► REJECTED:
       │                                   │                                │   Preimage mismatch
       │                                   │                                │   SHA256(Bob||proof) !=
       │                                   │                                │   stored commitment
       │                                   │                                │
       ├───────────────────────────────────┴───────────────────────────────►├─► VERIFIED & PAID:
       │                                                                    │   1. delay >= 5 ledgers
       │◄──────── Transfer reward payout (50 USDC) ─────────────────────────┤   2. Preimage matches
       │                                                                    │   3. Target hash matches
       │                                                                    │   4. Marked claimed
  1. Commit Phase (commit_bounty_claim):

    • Contributor submits commitment_hash = SHA256(claimant || proof || secret_salt).
    • Contract records BountyCommitment { claimant, commitment_hash, commit_ledger } with state extension TTL.
    • Frontrunning bots inspecting mempool payloads only see an opaque hash preimage bound cryptographically to claimant. Even if a bot attempts to copy the commitment hash under the bot's address, the preimage check will fail upon reveal.
  2. Challenge Delay Window (BOUNTY_CHALLENGE_DELAY_LEDGERS = 5):

    • Requires current_ledger >= commitment.commit_ledger + 5 (~25 seconds).
    • Prevents same-block or immediate frontrunning when a solution is committed.
  3. Reveal Phase (reveal_bounty_claim):

    • Contributor submits proof and secret_salt.
    • Contract enforces:
      1. Commitment exists for claimant and commitment.claimant == claimant.
      2. Challenge delay window (5 ledgers) has elapsed.
      3. Preimage integrity: SHA256(claimant || proof || secret_salt) == commitment.commitment_hash.
      4. Solution verification: SHA256(proof) == bounty.solution_hash.
    • Dispatches token reward directly to claimant, marks bounty claimed, and emits bounty_claimed event.
  4. Lifecycle & Reclamation (reclaim_bounty, get_bounty, get_bounty_commitment):

    • Creator can reclaim funds from expired, unclaimed bounties after expiration_timestamp.
    • Transparent public getters and helper function compute_bounty_commitment_hash for off-chain and frontend dApp integration.

Acceptance Criteria Checklist

  • Two-phase commit-reveal process prevents mempool copy-paste frontrunning: Tested and verified (test_frontrunning_bot_mempool_copy_fails).
  • Reveal submissions before challenge delay window are rejected: Tested and verified (test_reveal_bounty_claim_before_challenge_delay_fails, test_bounty_reveal_challenge_delay_panics_with_message).
  • Invalid preimages or mismatched claimant addresses panic: Tested and verified (test_tampered_proof_or_salt_panics, test_invalid_solution_hash_fails, test_bounty_reveal_invalid_preimage_panics_with_message, test_bounty_reveal_without_commitment_panics).
  • Double-claim and expired reclaim safety: Tested and verified (test_bounty_cannot_be_claimed_twice, test_bounty_reclaim_after_expiration).
  • Comprehensive unit tests in contracts/soroban/src/test.rs: 8 dedicated tests covering full commit-reveal lifecycle, challenge delay, attack vectors, and edge cases.
  • cargo test passes cleanly: All 134 tests pass 100% green (134 passed; 0 failed; 0 ignored).

…or competitive payroll bounties (Orbit-xyz#212)

- Add BountyData and BountyCommitment contract types for competitive task escrows
- Add DataKey variants: NextBountyId, Bounty(u64), BountyCommitment(u64, Address)
- Implement create_bounty to escrow reward tokens against a target solution hash
- Implement commit_bounty_claim storing commitment hash binding claimant address, proof, and secret salt
- Enforce BOUNTY_CHALLENGE_DELAY_LEDGERS (5 ledgers) delay window to eliminate mempool copy-paste frontrunning
- Implement reveal_bounty_claim to verify preimage, validate solution hash, and dispatch payout to claimant
- Implement reclaim_bounty for creator recovery of expired unclaimed bounties
- Add public getters get_bounty, get_bounty_commitment, and pure helper compute_bounty_commitment_hash
- Implement comprehensive unit test suite in test.rs covering happy path, early reveal rejection, frontrunning resistance, tampered preimages, invalid solutions, double-claim protection, and expired reclaim
- Fix baseline test delimiters and lending pool client address call so all 134 soroban tests pass cleanly
@vercel

vercel Bot commented Oct 19, 2026

Copy link
Copy Markdown

@markankamaransheogarat-sys is attempting to deploy a commit to the Abdqoharr Olayiwola's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

contract: implement anti-frontrunning commit-reveal mechanism for competitive payroll bounty claims

1 participant