Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Optimistic ZK Game Contract #11

Closed
wants to merge 14 commits into from
Closed

Conversation

zobront
Copy link
Collaborator

@zobront zobront commented Jun 4, 2024

First draft of an Optimistic ZK Contract for the bridge:

  • Anyone can propose a root without any ZK proof, referencing a past confirmed block to anchor from
  • Anyone can challenge (in parallel) but once a challenger starts a challenge, only they can continue it
  • Challengers evenly bisect the range of blocks from the anchor block to the proposed block with their root
  • The proposer must agree or disagree with the bisections to pinpoint the block of disagreement
  • Once the block is confirmed, a ZK proof from the challenger settles the game (or it is settled by proposer when challenger runs out of time without a valid proof)
  • Challengers have up to MAX_GAME_DURATION to complete a challenge (expect 7 days)
  • Proposers must complete their turns within MAX_PROPOSER_DURATION (expect 3.5 days)

This contract attempts to model a lot of the patterns, types and interfaces of the existing game contracts, which can feel a little clunky in some areas, but works.

This is still a WIP. Sharing here for early feedback.


Note: Pausing work on this contract to focus on implementing the state transition function in the zkVM. After that's done, will come back to it to tackle:

  • Validate remaining public values going into the SP1 Verifier (blob kzg commitment & l1 block root)
  • Determine the correct bond amounts (considering ability for proposer to frontrun to steal some bonds)
  • Test suite (including updating bridge to use new game and validating the full flow with a proof)

Comment on lines 279 to 283
// Validate public values passed to the verifier: The real L1 block root matches the passed l1Root.
// @todo verify relevant L1 block root matches _publicValues.l1Root

// Validate public values passed to the verifier: The real commitment to the blob matches the passed blobKzgCommitment.
// @todo access correct kzg commitment to verify against _publicValues.blobKzgCommitment?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After building the STF, come back to finalize these commitments to ensure data is accurate.

Comment on lines +136 to +138
// Require that the gap between the reference block and the block being proven is less than MAX_BLOCK_GAP.
// This is used to avoid attacks where such a large gap is used that the game cannot be completed.
if (anchorStateRoot.l2BlockNumber + MAX_BLOCK_GAP < l2BlockNumber()) revert InvalidBlockNumber();
Copy link
Collaborator Author

@zobront zobront Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to think more about these limits to ensure that up to 7 days later, the necessary data will be available via the EVM to prove against.

@zobront zobront changed the title WIP: Optimistic ZK Contract WIP: Optimistic ZK Game Contract Jun 6, 2024
@zobront zobront closed this Jul 29, 2024
zobront pushed a commit that referenced this pull request Aug 14, 2024
* feat: introduce OptimismSuperchainERC20

* fix: contract fixes

* feat: add snapshots and semver

* test: add supports interface tests

* test: add invariant test

* feat: add parameters to the RelayERC20 event

* fix: typo

* fix: from param description

* fix: event signature and interface pragma

* feat: add initializer

* feat: use unstructured storage and OZ v5

* feat: update superchain erc20 interfaces

* fix: adapt storage to ERC7201

* test: add initializable OZ v5 test

* fix: invariant docs

* fix: ERC165 implementation

* test: improve superc20 invariant (#11)

* fix: gas snapshot

---------

Co-authored-by: 0xng <ng@defi.sucks>
Co-authored-by: Disco <131301107+0xDiscotech@users.noreply.github.com>
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