-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(stateless): make witness generation conform to the draft specs #22289
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
Merged
mattsse
merged 9 commits into
paradigmxyz:main
from
jsign:jsign/witness-generation-testing
Apr 13, 2026
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8094653
feat(trie): introduce ExecutionWitnessMode and update witness methods…
jsign 163f656
feat(witness): add ExecutionWitnessMode support for state recording a…
jsign 9734e23
feat(trie): implement ExecutionWitnessMode for configurable witness g…
jsign 6eb8948
test(witness): enhance tests for ExecutionWitnessMode with legacy and…
jsign 6dac697
fix
jsign 5d56622
feedback
jsign 6848c13
typo
jsign 81c4d69
lint
jsign 484d480
Update crates/trie/common/src/execution_witness.rs
mattsse 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
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
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| use alloc::vec::Vec; | ||
| use alloy_primitives::{keccak256, Bytes, B256}; | ||
| use reth_trie::{HashedPostState, HashedStorage}; | ||
| use alloy_primitives::{keccak256, map::B256Map, Bytes, B256}; | ||
| use reth_trie::{ExecutionWitnessMode, HashedPostState, HashedStorage}; | ||
| use revm::database::State; | ||
|
|
||
| /// Tracks state changes during execution. | ||
|
|
@@ -30,21 +30,36 @@ pub struct ExecutionWitnessRecord { | |
| } | ||
|
|
||
| impl ExecutionWitnessRecord { | ||
| /// Records the state after execution. | ||
| pub fn record_executed_state<DB>(&mut self, statedb: &State<DB>) { | ||
| self.codes = statedb | ||
| .cache | ||
| .contracts | ||
| .values() | ||
| .map(|code| code.original_bytes()) | ||
| .chain( | ||
| // cache state does not have all the contracts, especially when | ||
| // a contract is created within the block | ||
| // the contract only exists in bundle state, therefore we need | ||
| // to include them as well | ||
| statedb.bundle_state.contracts.values().map(|code| code.original_bytes()), | ||
|
jsign marked this conversation as resolved.
|
||
| ) | ||
| .collect(); | ||
| /// Records the state after execution using the given witness generation mode. | ||
| pub fn record_executed_state<DB>(&mut self, statedb: &State<DB>, mode: ExecutionWitnessMode) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we have both. |
||
| self.codes = match mode { | ||
| ExecutionWitnessMode::Legacy => statedb | ||
| .cache | ||
| .contracts | ||
| .values() | ||
| .map(|code| code.original_bytes()) | ||
| .chain( | ||
| // cache state does not have all the contracts, especially when | ||
| // a contract is created within the block | ||
| // the contract only exists in bundle state, therefore we need | ||
| // to include them as well | ||
| statedb.bundle_state.contracts.values().map(|code| code.original_bytes()), | ||
| ) | ||
| .collect(), | ||
| ExecutionWitnessMode::Canonical => { | ||
| let mut accessed_codes = B256Map::default(); | ||
| for code in statedb.cache.contracts.values() { | ||
| let code = code.original_bytes(); | ||
| if code.is_empty() { | ||
| continue; | ||
| } | ||
| accessed_codes.entry(keccak256(&code)).or_insert(code); | ||
| } | ||
| let mut codes: Vec<_> = accessed_codes.into_values().collect(); | ||
| codes.sort_unstable(); | ||
| codes | ||
|
mediocregopher marked this conversation as resolved.
Outdated
|
||
| } | ||
| }; | ||
|
|
||
| for (address, account) in &statedb.cache.accounts { | ||
| let hashed_address = keccak256(address); | ||
|
|
@@ -75,9 +90,9 @@ impl ExecutionWitnessRecord { | |
| } | ||
|
|
||
| /// Creates the record from the state after execution. | ||
| pub fn from_executed_state<DB>(state: &State<DB>) -> Self { | ||
| pub fn from_executed_state<DB>(state: &State<DB>, mode: ExecutionWitnessMode) -> Self { | ||
| let mut record = Self::default(); | ||
| record.record_executed_state(state); | ||
| record.record_executed_state(state, mode); | ||
| record | ||
| } | ||
|
|
||
|
|
@@ -93,6 +108,7 @@ impl ExecutionWitnessRecord { | |
| state_provider: &SP, | ||
| headers_provider: &HP, | ||
| block_number: u64, | ||
| mode: ExecutionWitnessMode, | ||
| ) -> reth_storage_errors::provider::ProviderResult<alloy_rpc_types_debug::ExecutionWitness> | ||
| where | ||
| SP: reth_storage_api::StateProofProvider + ?Sized, | ||
|
|
@@ -101,7 +117,7 @@ impl ExecutionWitnessRecord { | |
| { | ||
| let Self { hashed_state, codes, keys, lowest_block_number } = self; | ||
|
|
||
| let state = state_provider.witness(Default::default(), hashed_state)?; | ||
| let state = state_provider.witness(Default::default(), hashed_state, mode)?; | ||
| let mut exec_witness = | ||
| alloy_rpc_types_debug::ExecutionWitness { state, codes, keys, ..Default::default() }; | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
ExecutionWitnessModeis a new enum to allow generating/using both witness types:Legacy(current), andCanonical(new).At the
debug_executionWitnesslevel there is a new parameter that allows to select this. It is anOptionso not providing it defaults toLegacyfor backwards compat.