feat: implement v2 reveal phase and commitment verification - #84
Merged
Conversation
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
Implements #67: the reveal phase, where third-party positions disclose the side they committed to during registration.
reveal(voter, id, choice, salt): looks up the voter'sPosition, verifies(choice, salt)against its stored commitment, and adds the position's weight toResolution.agree_weightordisagree_weight.VoteCommitmentPreimagestruct hashed viaToXdr, the same canonical-encoding approachpolicy_hashalready uses (see [Feature] V2: implement PolicySnapshot and versioned assertion state #64), rather than a hand-rolled byte concatenation. Matches V2_RESOLUTION.md'sH(canonical_encode("THOLOS_V2_VOTE", network_id, contract_address, policy_hash, assertion_id, round, voter, choice, salt))spec exactly, withroundfixed at 0 (this design has exactly one weighted round).revealcall afterregistration_deadlinetriggers it, matching V2_RESOLUTION.md's "a caller may advance an expired phase permissionlessly" principle rather than adding a separate entrypoint. That same transition auto-counts and auto-marks-revealed the asserter's and disputer's fixed positions, since their sides are already public and they never callrevealthemselves; aFixedvoter callingrevealis naturally rejected withAlreadyRevealedsince their position is already marked revealed at that point, no separate error variant needed.register's existing phase check already refuses new deposits once phase leavesRegistration, soWfreezes as a side effect of the transition with no extra code.RevealOpenedevent for the phase transition itself, alongsideRevealedper reveal.One ordering fix worth calling out:
revealchecks the assertion's phase before fetching itsResolution, not after. An uncontested assertion that reachedResolvedviafinalizenever has aResolutionat all (onlydisputecreates one), so fetching it first would've surfaced a misleadingAssertionNotFoundinstead ofNotRevealfor that case.Closes #67
Test plan
cargo fmt --check,cargo clippy --workspace --all-targets --locked -- -D warnings,cargo test --workspace --lockedall pass (67 v1 + 60 v2 + 2 integration-example tests)cargo build -p tholos-v2 --target wasm32v1-none --release --lockedsucceedsmdbook buildsucceedsErrorvariant has a dedicated test triggering it