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(pubdata): send call encoded pubdata #2360

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 1 addition & 1 deletion contracts
Submodule contracts updated 59 files
+0 −1 da-contracts/contracts/CalldataDA.sol
+4 −2 da-contracts/contracts/RollupL1DAValidator.sol
+4 −0 da-contracts/contracts/ValidiumL1DAValidator.sol
+ docs/Custom-da-contracts.png
+ docs/Custom-da-external.png
+ docs/Hyperchain-scheme.png
+ docs/PQ1.png
+ docs/PQ2.png
+ docs/PQ3.png
+0 −0 docs/SDK_compatibility.md
+62 −0 docs/contracts-review-cab.md
+48 −0 docs/contracts-review-gateway.md
+47 −0 docs/custom-da.md
+135 −0 docs/priority-merkle-tree.md
+0 −6 l1-contracts/contracts/bridgehub/Bridgehub.sol
+0 −4 l1-contracts/contracts/bridgehub/IBridgehub.sol
+1 −1 l1-contracts/contracts/bridgehub/STMDeploymentTracker.sol
+12 −4 l1-contracts/contracts/common/libraries/FullMerkle.sol
+4 −0 l1-contracts/contracts/dev-contracts/test/FullMerkleTest.sol
+9 −8 l1-contracts/contracts/state-transition/StateTransitionManager.sol
+0 −2 l1-contracts/contracts/state-transition/chain-deps/facets/Admin.sol
+1 −1 l1-contracts/contracts/state-transition/chain-deps/facets/Executor.sol
+1 −4 l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol
+0 −34 l1-contracts/contracts/state-transition/chain-interfaces/IExecutor.sol
+6 −1 l1-contracts/contracts/state-transition/chain-interfaces/IL1DAValidator.sol
+9 −5 l1-contracts/contracts/state-transition/data-availability/CalldataDA.sol
+1 −6 l1-contracts/contracts/state-transition/data-availability/RelayedSLDAValidator.sol
+1 −1 l1-contracts/lib/forge-std
+1 −1 l1-contracts/lib/murky
+2 −1 l1-contracts/package.json
+478 −492 l1-contracts/test/foundry/unit/concrete/Executor/Committing.t.sol
+44 −4 l1-contracts/test/foundry/unit/concrete/Executor/Executing.t.sol
+45 −3 l1-contracts/test/foundry/unit/concrete/Executor/Proving.t.sol
+45 −3 l1-contracts/test/foundry/unit/concrete/Executor/Reverting.t.sol
+13 −17 l1-contracts/test/foundry/unit/concrete/Executor/_Executor_Shared.t.sol
+53 −25 l1-contracts/test/foundry/unit/concrete/Utils/Utils.sol
+12 −31 l1-contracts/test/foundry/unit/concrete/Utils/Utils.t.sol
+0 −94 l1-contracts/test/foundry/unit/concrete/common/libraries/FullMerkle/FullMerkle.t.sol
+82 −0 l1-contracts/test/foundry/unit/concrete/common/libraries/FullMerkle/PushNewLeaf.t.sol
+56 −0 l1-contracts/test/foundry/unit/concrete/common/libraries/FullMerkle/Root.t.sol
+12 −0 l1-contracts/test/foundry/unit/concrete/common/libraries/FullMerkle/Setup.t.sol
+99 −0 l1-contracts/test/foundry/unit/concrete/common/libraries/FullMerkle/UpdateAllLeaves.t.sol
+82 −0 l1-contracts/test/foundry/unit/concrete/common/libraries/FullMerkle/UpdateAllNodesAtHeight.t.sol
+41 −0 l1-contracts/test/foundry/unit/concrete/common/libraries/FullMerkle/UpdateLeaf.t.sol
+23 −0 l1-contracts/test/foundry/unit/concrete/common/libraries/FullMerkle/_FullMerkle_Shared.t.sol
+2 −51 l1-contracts/test/unit_tests/utils.ts
+5 −2 l2-contracts/contracts/L2ContractHelper.sol
+2 −1 l2-contracts/contracts/data-availability/RollupL2DAValidator.sol
+4 −2 l2-contracts/contracts/data-availability/StateDiffL2DAValidator.sol
+1 −0 l2-contracts/package.json
+3 −1 l2-contracts/src/utils.ts
+0 −942 l2-contracts/test/systems-typechain/ContractDeployer.d.ts
+0 −534 l2-contracts/test/systems-typechain/ContractDeployerFactory.ts
+0 −5 l2-contracts/test/systems-typechain/index.ts
+27 −27 system-contracts/SystemContractsHashes.json
+1 −1 system-contracts/bootloader/bootloader.yul
+0 −6 system-contracts/contracts/Constants.sol
+63 −9 system-contracts/contracts/L1Messenger.sol
+6 −1 system-contracts/contracts/SystemContractErrors.sol
7 changes: 7 additions & 0 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ pub fn load_sys_contract(contract_name: &str) -> Contract {
))
}

pub fn load_sys_contract_interface(contract_name: &str) -> Contract {
load_contract(format!(
"contracts/system-contracts/artifacts-zk/contracts-preprocessed/interfaces/{0}.sol/{0}.json",
contract_name
))
}

pub fn read_contract_abi(path: impl AsRef<Path> + std::fmt::Debug) -> String {
read_file_to_json_value(path)["abi"]
.as_str()
Expand Down
2 changes: 2 additions & 0 deletions core/lib/multivm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ zksync_contracts.workspace = true
zksync_utils.workspace = true
zksync_system_constants.workspace = true

zksync_mini_merkle_tree.workspace = true


anyhow.workspace = true
hex.workspace = true
Expand Down
9 changes: 3 additions & 6 deletions core/lib/multivm/src/versions/vm_latest/tests/block_tip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,7 @@ fn test_dry_run_upper_bound() {
.max()
.unwrap();
assert!(
// FIXME: use the 1.5 factor after optimizations
max_used_gas.0 <= BOOTLOADER_BATCH_TIP_OVERHEAD,
max_used_gas.0 * 3 / 2 <= BOOTLOADER_BATCH_TIP_OVERHEAD,
"BOOTLOADER_BATCH_TIP_OVERHEAD is too low for {} with result {}, BOOTLOADER_BATCH_TIP_OVERHEAD = {}",
max_used_gas.1,
max_used_gas.0,
Expand All @@ -407,8 +406,7 @@ fn test_dry_run_upper_bound() {
.max()
.unwrap();
assert!(
// FIXME: use the 1.5 factor after optimizations
circuit_statistics.0 <= BOOTLOADER_BATCH_TIP_CIRCUIT_STATISTICS_OVERHEAD as u64,
circuit_statistics.0 * 3 / 2 <= BOOTLOADER_BATCH_TIP_CIRCUIT_STATISTICS_OVERHEAD as u64,
"BOOTLOADER_BATCH_TIP_CIRCUIT_STATISTICS_OVERHEAD is too low for {} with result {}, BOOTLOADER_BATCH_TIP_CIRCUIT_STATISTICS_OVERHEAD = {}",
circuit_statistics.1,
circuit_statistics.0,
Expand All @@ -421,8 +419,7 @@ fn test_dry_run_upper_bound() {
.max()
.unwrap();
assert!(
// FIXME: use the 1.5 factor after optimizations
execution_metrics_size.0 <= BOOTLOADER_BATCH_TIP_METRICS_SIZE_OVERHEAD as u64,
execution_metrics_size.0 * 3 / 2 <= BOOTLOADER_BATCH_TIP_METRICS_SIZE_OVERHEAD as u64,
"BOOTLOADER_BATCH_TIP_METRICS_SIZE_OVERHEAD is too low for {} with result {}, BOOTLOADER_BATCH_TIP_METRICS_SIZE_OVERHEAD = {}",
execution_metrics_size.1,
execution_metrics_size.0,
Expand Down
4 changes: 2 additions & 2 deletions core/lib/multivm/src/versions/vm_latest/tests/l1_messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::{
},
};

pub(crate) const L2_DA_VALIDATOR_OUTPUT_HASH_KEY: usize = 13;
pub(crate) const USED_L2_DA_VALIDATOR_ADDRESS_KEY: usize = 14;
pub(crate) const L2_DA_VALIDATOR_OUTPUT_HASH_KEY: usize = 7;
pub(crate) const USED_L2_DA_VALIDATOR_ADDRESS_KEY: usize = 8;

pub(crate) fn encoded_uncompressed_state_diffs(input: &PubdataInput) -> Vec<u8> {
let mut result = vec![];
Expand Down
87 changes: 87 additions & 0 deletions core/lib/multivm/src/versions/vm_latest/types/internals/pubdata.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
use ethabi::Token;
use zksync_contracts::load_sys_contract_interface;
use zksync_mini_merkle_tree::MiniMerkleTree;
use zksync_types::{
ethabi,
event::L1MessengerL2ToL1Log,
l2_to_l1_log::l2_to_l1_logs_tree_size,
web3::keccak256,
writes::{compress_state_diffs, StateDiffRecord},
ProtocolVersionId,
};
use zksync_utils::bytecode::hash_bytecode;

/// Struct based on which the pubdata blob is formed
#[derive(Debug, Clone, Default)]
Expand Down Expand Up @@ -44,6 +52,7 @@ fn encode_user_logs(user_logs: Vec<L1MessengerL2ToL1Log>) -> Vec<u8> {
impl PubdataBuilder for RollupPubdataBuilder {
fn build_pubdata(&self, input: PubdataInput, l2_version: bool) -> Vec<u8> {
let mut l1_messenger_pubdata = vec![];
let mut l2_da_header = vec![];

let PubdataInput {
user_logs,
Expand All @@ -52,6 +61,18 @@ impl PubdataBuilder for RollupPubdataBuilder {
state_diffs,
} = input;

if l2_version {
let chained_log_hash = build_chained_log_hash(user_logs.clone());
let log_root_hash = build_logs_root(user_logs.clone());
let chained_msg_hash = build_chained_message_hash(l2_to_l1_messages.clone());
let chained_bytecodes_hash = build_chained_bytecode_hash(published_bytecodes.clone());

l2_da_header.push(Token::FixedBytes(chained_log_hash));
l2_da_header.push(Token::FixedBytes(log_root_hash));
l2_da_header.push(Token::FixedBytes(chained_msg_hash));
l2_da_header.push(Token::FixedBytes(chained_bytecodes_hash));
}

l1_messenger_pubdata.extend(encode_user_logs(user_logs));

// Encoding L2->L1 messages
Expand Down Expand Up @@ -80,6 +101,18 @@ impl PubdataBuilder for RollupPubdataBuilder {
for state_diff in state_diffs {
l1_messenger_pubdata.extend(state_diff.encode_padded());
}

let func_selector = load_sys_contract_interface("IL2DAValidator")
.function("validatePubdata")
.expect("validatePubdata Function does not exist on IL2DAValidator")
.short_signature()
.to_vec();

l2_da_header.push(ethabi::Token::Bytes(l1_messenger_pubdata));

l1_messenger_pubdata = [func_selector, ethabi::encode(&l2_da_header)]
.concat()
.to_vec();
}

l1_messenger_pubdata
Expand All @@ -100,6 +133,60 @@ impl PubdataBuilder for ValidiumPubdataBuilder {
}
}

fn build_chained_log_hash(user_logs: Vec<L1MessengerL2ToL1Log>) -> Vec<u8> {
let mut chained_log_hash = vec![0u8; 32];

for log in user_logs {
let log_bytes = log.packed_encoding();
let hash = keccak256(&log_bytes);

chained_log_hash = keccak256(&[chained_log_hash, hash.to_vec()].concat()).to_vec();
}

chained_log_hash
}

fn build_logs_root(user_logs: Vec<L1MessengerL2ToL1Log>) -> Vec<u8> {
let logs = user_logs.iter().map(|log| {
let encoded = log.packed_encoding();
let mut slice = [0u8; 88];
slice.copy_from_slice(&encoded);
slice
});
MiniMerkleTree::new(
logs,
Some(l2_to_l1_logs_tree_size(ProtocolVersionId::latest())),
)
.merkle_root()
.as_bytes()
.to_vec()
}

fn build_chained_message_hash(l2_to_l1_messages: Vec<Vec<u8>>) -> Vec<u8> {
let mut chained_msg_hash = vec![0u8; 32];

for msg in l2_to_l1_messages {
let hash = keccak256(&msg);

chained_msg_hash = keccak256(&[chained_msg_hash, hash.to_vec()].concat()).to_vec();
}

chained_msg_hash
}

fn build_chained_bytecode_hash(published_bytecodes: Vec<Vec<u8>>) -> Vec<u8> {
let mut chained_bytecode_hash = vec![0u8; 32];

for bytecode in published_bytecodes {
let hash = hash_bytecode(&bytecode).to_fixed_bytes();

chained_bytecode_hash =
keccak256(&[chained_bytecode_hash, hash.to_vec()].concat()).to_vec();
}

chained_bytecode_hash
}

#[cfg(test)]
mod tests {

Expand Down
4 changes: 2 additions & 2 deletions etc/env/base/chain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ fee_model_version = "V1"
validation_computational_gas_limit = 300000
save_call_traces = true

bootloader_hash = "0x010008ebe92cafb31d44d1855fe97af98550f0f58bced18f29a7d74efd863b3f"
default_aa_hash = "0x0100055df3908fa6efcfa0bdfce813d4224f4657b696bcfdea0c1dbac659ecf4"
bootloader_hash = "0x010008eba3fb775aa81ef7cc2dbfe6cb84559f4a4f594522357ddd843cb87841"
default_aa_hash = "0x0100055d16f15378f8338471eef7af52def45925e83f98affc0ee7883e34c494"

[chain.operations_manager]
# Sleep time when there is no new input data
Expand Down
4 changes: 2 additions & 2 deletions etc/env/base/contracts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ RECURSION_NODE_LEVEL_VK_HASH = "0x1186ec268d49f1905f8d9c1e9d39fc33e98c74f91d91a2
RECURSION_LEAF_LEVEL_VK_HASH = "0x101e08b00193e529145ee09823378ef51a3bc8966504064f1f6ba3f1ba863210"
RECURSION_CIRCUITS_SET_VKS_HASH = "0x18c1639094f58177409186e8c48d9f577c9410901d2f1d486b3e7d6cf553ae4c"
GENESIS_TX_HASH = "0xb99ebfea46cbe05a21cd80fe5597d97b204befc52a16303f579c607dc1ac2e2e"
GENESIS_ROOT = "0x5e597aa72d5f475debf6d334e591a8fe17e06117b538cf1e42e524540f1826f9"
GENESIS_BATCH_COMMITMENT = "0x327d772f5b3d06e56da8dcc9eb34dfa35ecbc82b231a50c02b626815dbce2e2b"
GENESIS_ROOT = "0x38231d1956c379d89392ef85dd92256c76e48f32ba9fb6a0a96a7c97512f6321"
GENESIS_BATCH_COMMITMENT = "0xde5b29f5278bcd72ca559852409b99fd9cbf2f801a92444f1a7dec2fb638097e"
PRIORITY_TX_MAX_GAS_LIMIT = 72000000
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT = 10000000
GENESIS_ROLLUP_LEAF_INDEX = "64"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions prover/Cargo.lock

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

Loading