Repository navigation
feat(zkvm): state transition function proving using zkvm's #531
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
Open
Sahilgill24
wants to merge
20
commits into
lambdaclass:main
Choose a base branch
from
Sahilgill24:feat/zk-stf-proving
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6efa2b3
feat: adding state transition function input type
Sahilgill24 a1754ed
feat: scaffold sp1 guest program
Sahilgill24 4b61b80
refactor: update guest program workspace and add public values
Sahilgill24 da701e1
feat: setup the prover core for zkvm proving and verification
Sahilgill24 97b2ad4
feat: setup the prover backend for sp1
Sahilgill24 88ad3fb
feat: add zkVM target for guest program and its dependencies
Sahilgill24 f5b7ac6
refactor: separate no-op module targetting zkvm for metrics
Sahilgill24 cb54b4e
feat: add the execute path to the Prover trait and sp1 prover
Sahilgill24 84e65dc
test: test the execute path for the sp1 prover
Sahilgill24 3190c45
Merge upstream-main into feat/zk-stf-proving
Sahilgill24 fc625d4
feat: add mock chain driver for zkVM prover Backend
Sahilgill24 f4575b4
feat: add binary to run zkVM prover for the mock chain
Sahilgill24 6cb3b2b
Merge branch 'upstream/main' into feat/zk-stf-proving
Sahilgill24 e0ae4aa
Merge remote-tracking branch 'upstream/main' into feat/zk-stf-proving
Sahilgill24 fe526df
feat: add SSZ byte fetching route from rpc for zkVM proving
Sahilgill24 dd212c2
feat: add replay crate for actual zkVM proving on devnet
Sahilgill24 b69da2f
Merge remote-tracking branch 'upstream/main' into feat/zk-stf-proving
Sahilgill24 2088181
Merge remote-tracking branch 'upstream/main' into feat/zk-stf-proving
Sahilgill24 c3e3bc2
feat: adding timed prove verification and execution
Sahilgill24 3f04809
feat: adding proper proof gen/exec/verify timing
Sahilgill24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //! No-op metrics stub for the zkVM guest (`target_os = "zkvm"`), where | ||
| //! prometheus is unavailable. Compiled in place of `metrics.rs` | ||
| //! every function mirrors its host counterpart but records nothing. | ||
|
|
||
| /// Zero-sized stand-in for `ethlambda_metrics::TimingGuard`; records nothing. | ||
| pub struct TimingGuard; | ||
|
|
||
| pub fn inc_slots_processed(_count: u64) {} | ||
| pub fn inc_attestations_processed(_count: u64) {} | ||
| pub fn inc_finalizations(_result: &str) {} | ||
|
|
||
| pub fn time_state_transition() -> TimingGuard { | ||
| TimingGuard | ||
| } | ||
| pub fn time_slots_processing() -> TimingGuard { | ||
| TimingGuard | ||
| } | ||
| pub fn time_block_processing() -> TimingGuard { | ||
| TimingGuard | ||
| } | ||
| pub fn time_attestations_processing() -> TimingGuard { | ||
| TimingGuard | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| use libssz::{SszDecode, SszEncode}; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::{block::Block, primitives::H256, state::State}; | ||
|
|
||
| /// Input type for the zkVM's | ||
| /// | ||
| /// The inputs to the zkVM need to derive serde Serialize/deserialize | ||
| /// which is not derived for state (libssz traits) | ||
| /// wrapping pre-serialized SSZ bytes sidesteps that part. | ||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct StfInput { | ||
| state: Vec<u8>, | ||
| block: Vec<u8>, | ||
| } | ||
|
|
||
| /// Public values committed by the STF guest program. | ||
| /// | ||
| /// These bind a proof to one concrete transition: applying the block with | ||
| /// `block_root` to the state with `pre_state_root` yields the state with | ||
| /// `post_state_root`. A verifier reads these back from the proof without ever | ||
| /// seeing the full pre-state or block, and can chain proofs by matching one | ||
| /// transition's `post_state_root` to the next's `pre_state_root`. | ||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct StfPublicValues { | ||
| /// `hash_tree_root` of the pre-state. | ||
| pub pre_state_root: H256, | ||
| /// `hash_tree_root` of the block being applied. | ||
| pub block_root: H256, | ||
| /// `hash_tree_root` of the post-state (equals `block.state_root`). | ||
| pub post_state_root: H256, | ||
| } | ||
|
|
||
| impl StfInput { | ||
| pub fn new(state: State, block: Block) -> Self { | ||
| StfInput { | ||
| state: state.to_ssz(), | ||
| block: block.to_ssz(), | ||
| } | ||
| } | ||
|
|
||
| pub fn state(&self) -> State { | ||
| State::from_ssz_bytes(&self.state).expect("error decoding State") | ||
| } | ||
|
|
||
| pub fn block(&self) -> Block { | ||
| Block::from_ssz_bytes(&self.block).expect("error decoding block") | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Standalone workspace: this guest builds for a RISC-V zkVM target via | ||
| # `cargo prove build`, so it is excluded from the root workspace and cannot | ||
| # inherit its `[workspace.package]` / `[workspace.dependencies]` values. | ||
| [workspace] | ||
|
|
||
| [package] | ||
| name = "zkvm_guest_sp1" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| sp1-zkvm = "6.1.0" | ||
| ethlambda-types = { path = "../../common/types" } | ||
| ethlambda-state-transition = { path = "../../blockchain/state_transition" } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #![no_main] | ||
| sp1_zkvm::entrypoint!(main); | ||
|
|
||
| use ethlambda_state_transition::state_transition; | ||
| use ethlambda_types::{ | ||
| primitives::HashTreeRoot, | ||
| stf::{StfInput, StfPublicValues}, | ||
| }; | ||
|
|
||
| fn main() { | ||
| let input: StfInput = sp1_zkvm::io::read(); | ||
| let mut state = input.state(); | ||
| let block = input.block(); | ||
|
|
||
| // Capture the pre-state and block roots before mutating the state, so the | ||
| // committed public values bind the proof to this specific transition. | ||
| let pre_state_root = state.hash_tree_root(); | ||
| let block_root = block.hash_tree_root(); | ||
|
|
||
| state_transition(&mut state, &block).expect("state transition failed"); | ||
|
|
||
| let public_values = StfPublicValues { | ||
| pre_state_root, | ||
| block_root, | ||
| // state_transition already asserts this equals block.state_root. | ||
| post_state_root: state.hash_tree_root(), | ||
| }; | ||
| sp1_zkvm::io::commit(&public_values); | ||
| } |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [package] | ||
| name = "ethlambda-prover-core" | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| keywords.workspace = true | ||
| license.workspace = true | ||
| readme.workspace = true | ||
| repository.workspace = true | ||
| rust-version.workspace = true | ||
| version.workspace = true | ||
|
|
||
| [dependencies] | ||
| ethlambda-types.workspace = true | ||
| thiserror.workspace = true | ||
|
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing the SP1 prover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the sp1 prover, has a separate toolchain and is excluded from regular builds
exclude = ["crates/guest-program/sp1", "crates/prover/sp1"]because otherwise it would force other commands like cargo build to install the sp1 toolchain as well.