-
Notifications
You must be signed in to change notification settings - Fork 29
refactor: Simplify batch metadata and related types #1170
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
kostia244
wants to merge
11
commits into
main
Choose a base branch
from
kos/batch-metadata
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 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a27fbcc
Don't use BatchInfo in Batch Verification
6056d37
comments
cb54251
move chain address out of BatchInfo
75726ff
Move blob sidecar
e5357cd
Move protocol version to BatchInfo
9883f27
remove unused and redundant filed execution_version from BatchMetadata
3a0701a
merge batchinfo and committedbatch
7e2d04e
fmt
9610597
fix ci
3d1645c
delete unused function
9bdea28
I had to fix imports manually
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| use alloy::consensus::{BlobTransactionSidecar, SidecarBuilder, SimpleCoder}; | ||
| use alloy::primitives::{Address, B256, BlockNumber, U256, keccak256}; | ||
| use alloy::primitives::{B256, BlockNumber, U256, keccak256}; | ||
| use alloy::sol_types::SolValue; | ||
| use blake2::{Blake2s256, Digest}; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
@@ -14,38 +14,36 @@ use zksync_os_types::{ | |
|
|
||
| const PUBDATA_SOURCE_CALLDATA: u8 = 0; | ||
|
|
||
| /// Commitment information about a batch. | ||
| /// Contains enough data to restore `StoredBatchInfo` that got applied on-chain. | ||
| /// Contains enough data to construct public input hash. | ||
| /// todo: these fields should be a part of `CommitBatchInfo` but needs to be changed on L1 contracts' side first | ||
| #[derive(Clone, Serialize, Deserialize, Debug)] | ||
| pub struct BatchInfo { | ||
| pub struct CommitBatchInfoExt { | ||
| #[serde(flatten)] | ||
| pub commit_info: CommitBatchInfo, | ||
| /// Chain's diamond proxy address on L1. | ||
| // todo: this should not be a part of this struct as this is static information for the entire chain | ||
| // but we cannot remove it without breaking backwards compatibility | ||
| pub chain_address: Address, | ||
| /// L1 protocol upgrade transaction that was finalized in this batch. Missing for the vast | ||
| /// majority of batches. | ||
| pub upgrade_tx_hash: Option<B256>, | ||
| /// Blobs sidecar that should be sent with commit operation. | ||
| pub blob_sidecar: Option<BlobTransactionSidecar>, | ||
| pub protocol_version: ProtocolSemanticVersion, | ||
| } | ||
|
|
||
| impl BatchInfo { | ||
| impl CommitBatchInfoExt { | ||
| #[allow(clippy::too_many_arguments)] | ||
| pub fn new( | ||
| pub fn build( | ||
| blocks: Vec<( | ||
| &BlockOutput, | ||
| &BlockContext, | ||
| &[ZkTransaction], | ||
| &zksync_os_merkle_tree::TreeBatchOutput, | ||
| )>, | ||
|
Comment on lines
34
to
39
Contributor
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. Not sure whether this is in the scope of the PR, but this looks like too much data supplied, since |
||
| chain_id: u64, | ||
| chain_address: Address, | ||
| batch_number: u64, | ||
| pubdata_mode: PubdataMode, | ||
| sl_chain_id: u64, | ||
| multichain_root: B256, | ||
| protocol_version: &ProtocolSemanticVersion, | ||
| ) -> Self { | ||
| ) -> (Self, Option<BlobTransactionSidecar>) { | ||
| let mut priority_operations_hash = keccak256([]); | ||
| let mut number_of_layer1_txs = 0; | ||
| let mut number_of_layer2_txs = 0; | ||
|
|
@@ -178,19 +176,21 @@ impl BatchInfo { | |
| operator_da_input: da_fields.operator_da_input, | ||
| sl_chain_id, | ||
| }; | ||
| Self { | ||
| commit_info, | ||
| chain_address, | ||
| upgrade_tx_hash, | ||
| blob_sidecar: da_fields.blob_sidecar, | ||
| } | ||
| ( | ||
| Self { | ||
| commit_info, | ||
| protocol_version: protocol_version.clone(), | ||
| upgrade_tx_hash, | ||
| }, | ||
| da_fields.blob_sidecar, | ||
| ) | ||
| } | ||
|
|
||
| /// Calculate keccak256 hash of BatchOutput part of public input | ||
| pub fn public_input_hash(&self, protocol_version: &ProtocolSemanticVersion) -> B256 { | ||
| pub fn public_input_hash(&self) -> B256 { | ||
| let commit_info = &self.commit_info; | ||
| let upgrade_tx_hash = self.upgrade_tx_hash.unwrap_or(B256::ZERO); | ||
| match protocol_version.minor { | ||
| match self.protocol_version.minor { | ||
| // v30 and v31 use different packed layouts for batch output hash: | ||
| // v31 inserts number_of_layer2_txs between L1 tx count and priority_operations_hash. | ||
| 30 => B256::from(keccak256( | ||
|
|
@@ -225,12 +225,12 @@ impl BatchInfo { | |
| ) | ||
| .abi_encode_packed(), | ||
| )), | ||
| _ => panic!("Unsupported protocol version: {protocol_version}"), | ||
| _ => panic!("Unsupported protocol version: {}", self.protocol_version), | ||
| } | ||
| } | ||
|
|
||
| pub fn into_stored(self, protocol_version: &ProtocolSemanticVersion) -> StoredBatchInfo { | ||
| let commitment = self.public_input_hash(protocol_version); | ||
| pub fn into_stored(self) -> StoredBatchInfo { | ||
| let commitment = self.public_input_hash(); | ||
| let commit_info = self.commit_info; | ||
| StoredBatchInfo { | ||
| batch_number: commit_info.batch_number, | ||
|
|
@@ -246,15 +246,15 @@ impl BatchInfo { | |
| } | ||
| } | ||
|
|
||
| impl Deref for BatchInfo { | ||
| impl Deref for CommitBatchInfoExt { | ||
| type Target = CommitBatchInfo; | ||
|
|
||
| fn deref(&self) -> &Self::Target { | ||
| &self.commit_info | ||
| } | ||
| } | ||
|
|
||
| impl DerefMut for BatchInfo { | ||
| impl DerefMut for CommitBatchInfoExt { | ||
| fn deref_mut(&mut self) -> &mut Self::Target { | ||
| &mut self.commit_info | ||
| } | ||
|
|
||
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
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.
Bikeshedding:
_Extsuffix makes it look this is an extension trait. Maybe, useExtendedCommitBatchInfo?