Skip to content

Add FastCommitManager for optimistic signed commit flow#56

Merged
sudo-owen merged 4 commits intomainfrom
claude/fast-commit-manager-22zgm
Feb 5, 2026
Merged

Add FastCommitManager for optimistic signed commit flow#56
sudo-owen merged 4 commits intomainfrom
claude/fast-commit-manager-22zgm

Conversation

@sudo-owen
Copy link
Collaborator

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

  • Changed ENGINE and playerData visibility from private to internal to allow subclass access
  • Added _getPlayerIndex() helper function to determine player index from address
  • Added _storeCommitment() helper function to store commitment data (used by FastCommitManager for signed commits)

New FastCommitManager Contract

  • Extends DefaultCommitManager with EIP-712 signature verification
  • Implements revealMoveWithOtherPlayerSignedCommit() to accept signed commitments from the committing player
  • Allows the revealing player to submit both players' moves in a single transaction
  • Falls back to normal reveal behavior if the committer has already made an on-chain commitment
  • Only works for two-player turns (validates playerSwitchForTurnFlag == 2)

New SignedCommitLib Library

  • Provides EIP-712 hashing utilities for SignedCommit struct
  • Defines the type hash for signed commitments: SignedCommit(bytes32 moveHash,bytes32 battleKey,uint64 turnId)
  • Includes hashSignedCommit() function for struct hashing

Implementation Details

  • The fast flow requires the committing player to sign their move hash off-chain
  • The revealing player can then call revealMoveWithOtherPlayerSignedCommit() with the signature
  • Signature verification uses ECDSA recovery against the EIP-712 digest
  • If the committer has already made an on-chain commitment, the signature is ignored and normal reveal proceeds
  • The revealer cannot trigger auto-execute since the committer hasn't revealed yet

https://claude.ai/code/session_012MZ9EeP4GD7GXEmu1S5xL1

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
@sudo-owen sudo-owen merged commit 3472314 into main Feb 5, 2026
1 check passed
@sudo-owen sudo-owen deleted the claude/fast-commit-manager-22zgm branch February 5, 2026 04:24
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.

2 participants