Skip to content

feat(completion_anchor): implement completion hash anchor contract with unit tests - #374

Open
maxx-GENIUS wants to merge 1 commit into
MindFlowInteractive:mainfrom
maxx-GENIUS:feat/completion-hash-anchor
Open

maxx-GENIUS wants to merge 1 commit into
MindFlowInteractive:mainfrom
maxx-GENIUS:feat/completion-hash-anchor

Conversation

@maxx-GENIUS

Copy link
Copy Markdown

Summary

This PR implements the completion_anchor Soroban smart contract module for the Quest protocol, resolving #371.

It allows authorized verifiers to anchor SHA-256 hashes of completed puzzle proofs alongside ledger sequence numbers and timestamps directly on-chain, enabling trustless completion verification without storing full puzzle/game state on the ledger.

Implementation Details

  • Anchor Record: Defined AnchorRecord contract type capturing player: Address, puzzle_id: u32, completion_hash: BytesN<32>, ledger_sequence: u32, and timestamp: u64.
  • Verifier Access Control: Implemented initialize(admin, verifier) and set_verifier(new_verifier) guarded by admin authentication. The anchor_completion invocation enforces verifier.require_auth().
  • Duplicate Prevention: Enforces idempotency and guarantees single-anchor invariant per (player, puzzle_id) pair, explicitly rejecting duplicates.
  • Lookup Methods: Added has_anchor, get_anchor, and get_completion_hash for fast, low-cost external queries by indexers and contracts.
  • Event Emission: Publishes (Symbol("anchor"), Symbol("completed")) event with player, puzzle ID, and ledger reference upon anchoring.

Test Suite

Comprehensive unit tests implemented in contracts/completion_anchor/src/lib.rs under mod test:

  • test_initialize_and_verifier_management: Validates admin authorization and verifier rotation.
  • test_anchor_completion_success: Validates anchor creation, ledger sequence/timestamp capture, and retrieval.
  • test_duplicate_anchor_rejected: Validates panic on duplicate submission for the same player and puzzle.
  • test_unauthorized_verifier_rejected: Validates strict rejection of unauthorized anchor callers.
  • test_nonexistent_anchor_returns_none: Validates graceful lookup fallbacks.

Closes #371

…th unit tests

- Define AnchorRecord storing player, puzzle, hash, ledger sequence, and timestamp
- Implement verifier-authenticated anchor_completion function
- Reject duplicate anchors for the same player and puzzle ID
- Add lookup methods has_anchor, get_anchor, and get_completion_hash
- Comprehensive unit test suite covering initialization, anchoring, duplicate rejection, and auth enforcement

Closes MindFlowInteractive#371
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.

Completion Hash Anchor

1 participant