Skip to content

Commit

Permalink
store pubdata in global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
toni-calvin committed Jan 8, 2024
1 parent c5fe842 commit af1274e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/lib/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ thiserror = "1.0"
num_enum = "0.6"
hex = "0.4"
prost = "0.12.1"
lazy_static = "1.4.0"

# Crypto stuff
# TODO (PLA-440): remove parity-crypto
Expand Down
42 changes: 41 additions & 1 deletion core/lib/types/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

use std::{collections::HashMap, convert::TryFrom};

use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::sync::{Arc, Mutex};
use zksync_mini_merkle_tree::MiniMerkleTree;
use zksync_system_constants::{
L2_TO_L1_LOGS_TREE_ROOT_KEY, STATE_DIFF_HASH_KEY, ZKPORTER_IS_AVAILABLE,
Expand All @@ -27,6 +29,18 @@ use crate::{
H256, KNOWN_CODES_STORAGE_ADDRESS, U256,
};

#[derive(Debug, Default)]
struct L2Pubdata {
l2_to_l1_messages: Vec<u8>,
factory_deps: Vec<u8>,
state_diffs_compressed: Vec<u8>,
}

// Create a global instance of the data using Mutex
lazy_static! {
static ref L2_PUBDATA: Mutex<L2Pubdata> = Mutex::new(L2Pubdata::default());
}

/// Type that can be serialized for commitment.
pub trait SerializeCommitment {
/// Size of the structure in bytes.
Expand Down Expand Up @@ -248,8 +262,34 @@ impl L1BatchWithMetadata {

// Extend with Compressed StateDiffs
res.extend(&self.metadata.state_diffs_compressed);
}
} else {
let mut l2_pubdata = L2_PUBDATA.lock().unwrap();
l2_pubdata
.l2_to_l1_messages
.extend((self.header.l2_to_l1_messages.len() as u32).to_be_bytes());
for msg in &self.header.l2_to_l1_messages {
l2_pubdata
.l2_to_l1_messages
.extend((msg.len() as u32).to_be_bytes());
l2_pubdata.l2_to_l1_messages.extend(msg);
}

// Process and Pack Bytecodes
l2_pubdata
.factory_deps
.extend((self.factory_deps.len() as u32).to_be_bytes());
for bytecode in &self.factory_deps {
l2_pubdata
.factory_deps
.extend((bytecode.len() as u32).to_be_bytes());
l2_pubdata.factory_deps.extend(bytecode);
}

// Extend with Compressed StateDiffs
l2_pubdata
.state_diffs_compressed
.extend(&self.metadata.state_diffs_compressed);
}
res
}
}
Expand Down
1 change: 1 addition & 0 deletions era-contracts-lambda
Submodule era-contracts-lambda added at 7fe797

0 comments on commit af1274e

Please sign in to comment.