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

feat: Optimism Derivation Proof Composition #69

Merged
merged 130 commits into from
Feb 12, 2024
Merged

Conversation

hashcashier
Copy link
Contributor

@hashcashier hashcashier commented Dec 20, 2023

OP Composition

This PR introduces the proof composition program for optimism block derivation. The goal of this composition is to stitch together sequential optimism block derivation proofs into a single composed proofs about the contiguous chain of optimism blocks.

Input

pub struct ComposeInput {
    pub derive_image_id: [u32; 8],
    pub compose_image_id: [u32; 8],
    pub operation: ComposeInputOperation,
    pub eth_chain_root: [u8; 32],
}

The input given to the composition predicate consists of:

  1. The image id used for op block derivation
  2. The image id of the composition guest itself
  3. The “operation” which this invocation of the guest should perform (prep/lift/join/finish)
  4. The Merkle-tree root of the Ethereum blockchain using which all derivation should be performed.

Operations

pub enum ComposeInputOperation {
    PREP {
        eth_blocks: Vec<Header>,
        prior_prep: Option<(ComposeOutput, MerkleMountainRange)>,
    },
    LIFT {
        derivation: DeriveOutput,
        eth_tail_proof: MerkleProof,
    },
    JOIN {
        left: ComposeOutput,
        right: ComposeOutput,
    },
    FINISH {
        prep: ComposeOutput,
        aggregate: ComposeOutput,
    },
}

The composer can be asked to perform any one of four possible operations, described below.

Join

The join operation is where the stitching logic happens. Joining can only succeed if:

  1. The optimism “tail” of the left proof is equal to the optimism “head” of the right proof (i.e. the optimism blocks in the right proof’s chain start off where the left proof chain ends).
  2. The ethereum blocks used for derivation in both proofs are on the same chain. (security)

The first condition is checked during the join operation, while the second condition is already validated during the pre-requisite “lift” operation using the eth_chain_root.

Lift

Lifting converts a block derivation proof into an equivalent proof, only after verifying that the last ethereum block read during derivation belongs to the continuous chain committed to under eth_chain_root. This is done using a merkle inclusion proof.

Preparation

This operation takes as input a chain of ethereum blocks and inserts them into a Merkle-tree, resulting in a composition statement about an eth_chain_root value. This operation can also be performed incrementally when given a Merkle mountain range (and corresponding proof) as input if the ethereum chain is too large for one session.

Finish

Finalization takes as input a composition “preparation” proof about the merkle root eth_chain_root, asserting its commitment to a continuous chain of ethereum blocks, and a composition “aggregation” proof about the derivation of a series of op-blocks from the ethereum blocks under eth_chain_root.

@hashcashier hashcashier requested a review from Wollac February 2, 2024 15:32
Copy link
Contributor

@Wollac Wollac left a comment

Choose a reason for hiding this comment

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

Will look at it one last time when all the sub-PRs are merged.

* feat: Provably build derived op blocks (#78)

* feat: Composition via Bonsai (#79)

* feat: Deterministic builds with receipt cache (+misc) (#80)
@hashcashier hashcashier requested a review from Wollac February 5, 2024 16:00
guests/Cargo.toml Show resolved Hide resolved
README.md Show resolved Hide resolved
host/src/lib.rs Show resolved Hide resolved
host/src/operations/mod.rs Show resolved Hide resolved
lib/src/builder/execute/ethereum.rs Outdated Show resolved Hide resolved
lib/src/optimism/composition.rs Show resolved Hide resolved
lib/src/optimism/composition.rs Show resolved Hide resolved
lib/src/optimism/mod.rs Outdated Show resolved Hide resolved
lib/src/optimism/mod.rs Show resolved Hide resolved
lib/src/output.rs Outdated Show resolved Hide resolved
host/src/cli.rs Outdated Show resolved Hide resolved
@hashcashier hashcashier requested a review from Wollac February 12, 2024 13:28
Copy link
Contributor

@Wollac Wollac left a comment

Choose a reason for hiding this comment

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

Let's create the issues we discussed, but other than that, let's finally merge this beast!

@hashcashier hashcashier merged commit ee9d6e0 into main Feb 12, 2024
4 checks passed
@hashcashier hashcashier deleted the rkhalil/op-compose branch February 12, 2024 16:28
johntaiko pushed a commit to johntaiko/zeth that referenced this pull request Apr 10, 2024
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.

3 participants