Add FastCommitManager for optimistic signed commit flow#56
Merged
Conversation
Implements a new commit-reveal flow that reduces transactions from 3 to 2: - Normal flow: commit -> reveal -> reveal (3 TX) - Fast flow: signedCommit+reveal -> reveal (2 TX) The revealing player can submit the committing player's EIP-712 signed commitment along with their own reveal in a single transaction. This removes the need for the committing player to make an on-chain commit. Changes: - DefaultCommitManager: expose internal storage and helpers for extension - SignedCommitLib: EIP-712 type hash library for signed commits - FastCommitManager: extends DefaultCommitManager with revealMoveWithOtherPlayerSignedCommit() - Comprehensive test suite including timeout compatibility and security tests - Gas benchmark tests for cold/warm storage access patterns Fallback: If the revealing player doesn't publish the signed commit, the committing player can still use the normal commitMove() flow. https://claude.ai/code/session_012MZ9EeP4GD7GXEmu1S5xL1
Turn 0 requires SWITCH_MOVE_INDEX to select the first mon, not NO_OP_MOVE_INDEX. Updated all turn 0 tests and gas benchmarks. https://claude.ai/code/session_012MZ9EeP4GD7GXEmu1S5xL1
- Add ValidationContext struct for batch validation data - Add getValidationContext() to Engine that returns all validation data in one call (reduces 5+ external calls to 1) - Update DefaultValidator.validatePlayerMove to use batch context - Fix Engine.getWinner to cache storage reference (saves 1 SLOAD) Gas savings: - ~3k gas per reveal operation - ~72k gas per full battle - ~120k gas overall in consecutive battle test https://claude.ai/code/session_012MZ9EeP4GD7GXEmu1S5xL1
Move FastCommitManagerGasBenchmarkTest to its own file, keeping FastCommitManagerTestBase as a shared abstract in the main test file. https://claude.ai/code/session_012MZ9EeP4GD7GXEmu1S5xL1
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
Introduces an optimistic commit flow that allows the revealing player to submit the committing player's signed commitment along with their own reveal in a single transaction, reducing the number of on-chain transactions needed from 3 to 2.
Changes
DefaultCommitManager
ENGINEandplayerDatavisibility fromprivatetointernalto allow subclass access_getPlayerIndex()helper function to determine player index from address_storeCommitment()helper function to store commitment data (used by FastCommitManager for signed commits)New FastCommitManager Contract
DefaultCommitManagerwith EIP-712 signature verificationrevealMoveWithOtherPlayerSignedCommit()to accept signed commitments from the committing playerplayerSwitchForTurnFlag == 2)New SignedCommitLib Library
SignedCommitstructSignedCommit(bytes32 moveHash,bytes32 battleKey,uint64 turnId)hashSignedCommit()function for struct hashingImplementation Details
revealMoveWithOtherPlayerSignedCommit()with the signaturehttps://claude.ai/code/session_012MZ9EeP4GD7GXEmu1S5xL1