Repository navigation
feat(completion_anchor): implement completion hash anchor contract with unit tests - #374
Open
maxx-GENIUS wants to merge 1 commit into
Open
maxx-GENIUS wants to merge 1 commit into
maxx-GENIUS wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements the
completion_anchorSoroban 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
AnchorRecordcontract type capturingplayer: Address,puzzle_id: u32,completion_hash: BytesN<32>,ledger_sequence: u32, andtimestamp: u64.initialize(admin, verifier)andset_verifier(new_verifier)guarded by admin authentication. Theanchor_completioninvocation enforcesverifier.require_auth().(player, puzzle_id)pair, explicitly rejecting duplicates.has_anchor,get_anchor, andget_completion_hashfor fast, low-cost external queries by indexers and contracts.(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.rsundermod 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