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(config): Added blobs to commit batches and made da source part of config #1243

Merged
merged 39 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d584101
add tokenizations for blobs and calldata
koloz193 Feb 24, 2024
9298d45
add config for da slots and da source
koloz193 Feb 24, 2024
6fd4f6a
lint fixes
koloz193 Feb 24, 2024
d8c6ad0
lint and revert snark vk hash
koloz193 Feb 24, 2024
712dd48
rename fn
koloz193 Feb 24, 2024
cf255d5
changed pubdata sending to not optional, num blobs to u8, and kzg inf…
koloz193 Feb 25, 2024
0ba9385
remove da slots from state keeper config
koloz193 Feb 25, 2024
36874a4
Merge branch 'main' into zk-4844-batch-commitment
koloz193 Feb 26, 2024
ef792be
adding DA to commit batches
koloz193 Feb 27, 2024
40667a1
move da to types
koloz193 Feb 27, 2024
1e5c520
Merge remote-tracking branch 'origin/main' into zk-4844-batch-commitment
montekki Feb 27, 2024
725b61a
make it build
montekki Feb 27, 2024
e5a2c09
a bit of clippy fixes
montekki Feb 27, 2024
5cfc3b7
more fixes
montekki Feb 27, 2024
944a962
and more fixes
montekki Feb 27, 2024
973ca9a
and more fixes 2
montekki Feb 27, 2024
4e99eae
Merge remote-tracking branch 'origin/main' into zk-4844-batch-commitment
montekki Feb 27, 2024
7485da7
should be a tuple
montekki Feb 27, 2024
9447ac9
spelling and consistency checker tests
montekki Feb 27, 2024
53b32f2
fix integrations
montekki Feb 28, 2024
e2bb95c
Remove DB column; check all variants in consistency checker
perekopskiy Feb 28, 2024
fffd91c
Fix tests
perekopskiy Feb 28, 2024
69be0bd
remove todo and unused var
montekki Feb 28, 2024
5d7c7d2
named fields in commitbatchinfo
montekki Feb 28, 2024
e6d1fc5
wire together transaction sending and sidecar storing with this pr
montekki Feb 28, 2024
6c2f3fb
format sql queries
montekki Feb 28, 2024
2da3bbd
Merge remote-tracking branch 'origin/main' into zk-4844-batch-commitment
montekki Feb 28, 2024
af1509a
remove allow unused
montekki Feb 28, 2024
bb8cf84
wire in blob tx resending
montekki Feb 28, 2024
e2443b0
remove nonsense hacks and correctly double price for blob txs
montekki Feb 28, 2024
8cab538
removed option for pubdata da
koloz193 Feb 28, 2024
973f68a
spellcheck
koloz193 Feb 28, 2024
6863792
lint and streamline
koloz193 Feb 28, 2024
af5a8cf
add unwrap or else to protocol version
koloz193 Feb 28, 2024
62b55bb
lint
koloz193 Feb 28, 2024
8e6dc4c
also check pubdata da mode in aggregator
montekki Feb 28, 2024
bfcaafa
Merge branch 'main' into zk-4844-batch-commitment
montekki Feb 28, 2024
e45f065
Make upgrade test pass
perekopskiy Feb 28, 2024
3796856
Merge branch 'main' into zk-4844-batch-commitment
perekopskiy Feb 28, 2024
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
50 changes: 47 additions & 3 deletions Cargo.lock

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

15 changes: 14 additions & 1 deletion core/lib/config/src/configs/eth_sender.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use serde::Deserialize;
use serde::{Deserialize, Serialize};
use zksync_basic_types::H256;

/// Configuration for the Ethereum sender crate.
Expand Down Expand Up @@ -35,6 +35,7 @@ impl ETHSenderConfig {
l1_batch_min_age_before_execute_seconds: None,
max_acceptable_priority_fee_in_gwei: 100000000000,
proof_loading_mode: ProofLoadingMode::OldProofFromDb,
pubdata_sending_mode: PubdataSendingMode::Calldata,
},
gas_adjuster: GasAdjusterConfig {
default_priority_fee_per_gas: 1000000000,
Expand Down Expand Up @@ -63,6 +64,14 @@ pub enum ProofLoadingMode {
FriProofFromGcs,
}

#[derive(Debug, Deserialize, Clone, Copy, PartialEq, Serialize, Default)]
pub enum PubdataSendingMode {
#[default]
Calldata,
OneBlob,
koloz193 marked this conversation as resolved.
Show resolved Hide resolved
TwoBlobs,
}

#[derive(Debug, Deserialize, Clone, PartialEq)]
pub struct SenderConfig {
pub aggregated_proof_sizes: Vec<usize>,
Expand Down Expand Up @@ -96,6 +105,10 @@ pub struct SenderConfig {

/// The mode in which proofs are loaded, either from DB/GCS for FRI/Old proof.
pub proof_loading_mode: ProofLoadingMode,

/// The mode in which we send pubdata, either Calldata, 1 Blob, or 2 Blobs/
/// If not specified, Calldata will be used
pub pubdata_sending_mode: PubdataSendingMode,
montekki marked this conversation as resolved.
Show resolved Hide resolved
}

impl SenderConfig {
Expand Down
13 changes: 12 additions & 1 deletion core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use zksync_basic_types::{
basic_fri_types::CircuitIdRoundTuple, network::Network, Address, L2ChainId, H256,
};

use crate::configs;
use crate::configs::{self, eth_sender::PubdataSendingMode};

/// Generator of random configs.
pub struct Gen<'a, R: Rng> {
Expand Down Expand Up @@ -457,6 +457,16 @@ impl RandomConfig for configs::eth_sender::ProofLoadingMode {
}
}

impl RandomConfig for configs::eth_sender::PubdataSendingMode {
fn sample(g: &mut Gen<impl Rng>) -> Self {
match g.rng.gen_range(0..3) {
0 => Self::Calldata,
1 => Self::OneBlob,
_ => Self::TwoBlobs,
}
}
}

impl RandomConfig for configs::eth_sender::SenderConfig {
fn sample(g: &mut Gen<impl Rng>) -> Self {
Self {
Expand All @@ -477,6 +487,7 @@ impl RandomConfig for configs::eth_sender::SenderConfig {
l1_batch_min_age_before_execute_seconds: g.gen(),
max_acceptable_priority_fee_in_gwei: g.gen(),
proof_loading_mode: g.gen(),
pubdata_sending_mode: PubdataSendingMode::Calldata,
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions core/lib/constants/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ pub const PRIORITY_EXPIRATION: u64 = 50000;
pub const MAX_L1_TRANSACTION_GAS_LIMIT: u64 = 300000;
pub const ETHEREUM_ADDRESS: Address = Address::zero();

/// The maximum number of pubdata per L1 batch. This limit is due to the fact that the Ethereum
/// nodes do not accept transactions that have more than 128kb of pubdata.
/// The 18kb margin is left in case of any impreciseness of the pubdata calculation.
pub const MAX_PUBDATA_PER_L1_BATCH: u64 = 110000;

// TODO: import from `zkevm_opcode_defs` once `VM1.3` is supported
pub const MAX_L2_TX_GAS_LIMIT: u64 = 80000000;

Expand Down
6 changes: 5 additions & 1 deletion core/lib/env_config/src/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ impl FromEnv for GasAdjusterConfig {

#[cfg(test)]
mod tests {
use zksync_config::configs::eth_sender::{ProofLoadingMode, ProofSendingMode};
use zksync_config::configs::eth_sender::{
ProofLoadingMode, ProofSendingMode, PubdataSendingMode,
};

use super::*;
use crate::test_utils::{hash, EnvMutex};
Expand Down Expand Up @@ -54,6 +56,7 @@ mod tests {
l1_batch_min_age_before_execute_seconds: Some(1000),
max_acceptable_priority_fee_in_gwei: 100_000_000_000,
proof_loading_mode: ProofLoadingMode::OldProofFromDb,
pubdata_sending_mode: PubdataSendingMode::Calldata,
},
gas_adjuster: GasAdjusterConfig {
default_priority_fee_per_gas: 20000000000,
Expand Down Expand Up @@ -98,6 +101,7 @@ mod tests {
ETH_SENDER_SENDER_L1_BATCH_MIN_AGE_BEFORE_EXECUTE_SECONDS="1000"
ETH_SENDER_SENDER_MAX_ACCEPTABLE_PRIORITY_FEE_IN_GWEI="100000000000"
ETH_SENDER_SENDER_PROOF_LOADING_MODE="OldProofFromDb"
ETH_SENDER_SENDER_PUBDATA_SENDING_MODE="Calldata"
"#;
lock.set_env(config);

Expand Down
4 changes: 3 additions & 1 deletion core/lib/l1_contract_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ codegen = { git = "https://github.com/matter-labs/solidity_plonk_verifier.git",
zkevm_test_harness_1_3_3 = { package = "zkevm_test_harness", git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.3.3" }

# Used to calculate the kzg commitment and proofs
zkevm_test_harness_1_4_1 = { package = "zkevm_test_harness", git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.1" }
zkevm_test_harness_1_4_2 = { package = "zkevm_test_harness", git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.2" }
sha2 = "0.10.8"
sha3 = "0.10.8"

once_cell = "1.19"
montekki marked this conversation as resolved.
Show resolved Hide resolved

montekki marked this conversation as resolved.
Show resolved Hide resolved
[dev-dependencies]
hex = "0.4"
serde = "1.0.90"
Expand Down
30 changes: 23 additions & 7 deletions core/lib/l1_contract_interface/src/i_executor/commit/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::convert::TryInto;
use sha2::Sha256;
use sha3::{Digest, Keccak256};
use zkevm_test_harness_1_3_3::ff::{PrimeField, PrimeFieldRepr};
use zkevm_test_harness_1_4_1::{
use zkevm_test_harness_1_4_2::{
kzg::{compute_commitment, compute_proof, compute_proof_poly, KzgSettings},
zkevm_circuits::{
boojum::pairing::{
Expand All @@ -21,7 +21,7 @@ use zkevm_test_harness_1_4_1::{
},
};

const ZK_SYNC_BYTES_PER_BLOB: usize = BLOB_CHUNK_SIZE * ELEMENTS_PER_4844_BLOCK;
pub const ZK_SYNC_BYTES_PER_BLOB: usize = BLOB_CHUNK_SIZE * ELEMENTS_PER_4844_BLOCK;
const EIP_4844_BYTES_PER_BLOB: usize = 32 * ELEMENTS_PER_4844_BLOCK;

/// Packed pubdata commitments.
Expand Down Expand Up @@ -89,7 +89,7 @@ impl KzgInfo {

/// Returns the bytes necessary for pubdata commitment part of batch commitments when blobs are used.
/// Return format: opening point (16 bytes) || claimed value (32 bytes) || commitment (48 bytes)
/// || opening proof (48 bytes))
/// || opening proof (48 bytes)
pub fn to_pubdata_commitment(&self) -> [u8; BYTES_PER_PUBDATA_COMMITMENT] {
let mut res = [0u8; BYTES_PER_PUBDATA_COMMITMENT];
// The crypto team/batch commitment expects the opening point to be 16 bytes
Expand All @@ -102,6 +102,22 @@ impl KzgInfo {
res
}

/// Computes the commitment to the blob needed as part of the batch commitment through the aux output
/// Format is: Keccak(versioned hash || opening point || opening value)
pub fn to_blob_commitment(&self) -> [u8; 32] {
let mut commitment = [0u8; 32];
let hash = &Keccak256::digest(
[
self.versioned_hash.as_slice(),
&self.opening_point[16..],
self.opening_value.as_slice(),
]
.concat(),
);
commitment.copy_from_slice(hash);
commitment
}

/// Deserializes `Self::SERIALIZED_SIZE` bytes into `KzgInfo` struct
pub fn from_slice(data: &[u8]) -> Self {
assert_eq!(data.len(), Self::SERIALIZED_SIZE);
Expand Down Expand Up @@ -183,7 +199,7 @@ impl KzgInfo {
/// 7. opening point <- keccak(linear hash || versioned hash)[16..]
/// 8. opening value, opening proof <- `compute_kzg_proof`(4844)
/// 9. blob proof <- `compute_proof_poly`(blob, 4844 `kzg` commitment)
pub fn new(kzg_settings: &KzgSettings, pubdata: Vec<u8>) -> Self {
pub fn new(kzg_settings: &KzgSettings, pubdata: &Vec<u8>) -> Self {
montekki marked this conversation as resolved.
Show resolved Hide resolved
assert!(pubdata.len() <= ZK_SYNC_BYTES_PER_BLOB);

let mut zksync_blob = [0u8; ZK_SYNC_BYTES_PER_BLOB];
Expand Down Expand Up @@ -250,7 +266,7 @@ impl KzgInfo {
mod tests {
use serde::{Deserialize, Serialize};
use serde_with::{self, serde_as};
use zkevm_test_harness_1_4_1::{
use zkevm_test_harness_1_4_2::{
boojum::pairing::{
bls12_381::{Fr, FrRepr, G1Affine, G1Compressed},
EncodedPoint,
Expand Down Expand Up @@ -322,7 +338,7 @@ mod tests {
let path = std::path::Path::new(&zksync_home).join("trusted_setup.json");
let kzg_settings = KzgSettings::new(path.to_str().unwrap());

let kzg_info = KzgInfo::new(&kzg_settings, kzg_test.pubdata);
let kzg_info = KzgInfo::new(&kzg_settings, &kzg_test.pubdata);

// Verify all the fields were correctly computed
assert_eq!(
Expand Down Expand Up @@ -392,7 +408,7 @@ mod tests {
let path = std::path::Path::new(&zksync_home).join("trusted_setup.json");
let kzg_settings = KzgSettings::new(path.to_str().unwrap());

let kzg_info = KzgInfo::new(&kzg_settings, kzg_test.pubdata);
let kzg_info = KzgInfo::new(&kzg_settings, &kzg_test.pubdata);

let encoded_info = kzg_info.to_bytes();
assert_eq!(KzgInfo::SERIALIZED_SIZE, encoded_info.len());
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod kzg;
pub mod kzg;
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// TODO: Remove once integrated into batch commit
#![allow(dead_code)]

use zksync_types::{commitment::L1BatchWithMetadata, ethabi::Token};

use crate::{
Expand All @@ -24,3 +27,27 @@ impl Tokenize for CommitBatches {
vec![stored_batch_info, Token::Array(l1_batches_to_commit)]
}
}

impl CommitBatches {
fn into_tokens_blobs(self, number_of_blobs: usize) -> Vec<Token> {
koloz193 marked this conversation as resolved.
Show resolved Hide resolved
let stored_batch_info = StoredBatchInfo(&self.last_committed_l1_batch).into_token();
let l1_batches_to_commit = self
.l1_batches
.iter()
.map(|batch| CommitBatchInfo(batch).into_tokens_blobs(number_of_blobs))
.collect();

vec![stored_batch_info, Token::Array(l1_batches_to_commit)]
}

fn into_tokens_calldata(self) -> Vec<Token> {
let stored_batch_info = StoredBatchInfo(&self.last_committed_l1_batch).into_token();
let l1_batches_to_commit = self
.l1_batches
.iter()
.map(|batch| CommitBatchInfo(batch).into_tokens_calldata())
.collect();

vec![stored_batch_info, Token::Array(l1_batches_to_commit)]
}
}
Loading
Loading