diff --git a/contracts/src/deploy-config/holesky.ts b/contracts/src/deploy-config/holesky.ts index adf4b11b2..f5a5a090f 100644 --- a/contracts/src/deploy-config/holesky.ts +++ b/contracts/src/deploy-config/holesky.ts @@ -14,7 +14,7 @@ const config = { l2BaseFee: 0.1, // Gwei // verify contract config - programVkey: '0x00da5ade7ec0ec902618c53b616ac96f47de1cb79b450f815a7c6cbebd6ffaef', + programVkey: '0x001fe18a35489f0e7ae203bc2b1f26b7696f00bafa8000518c94a479d29c4076', // rollup contract config // initialize config finalizationPeriodSeconds: 600, diff --git a/contracts/src/deploy-config/hoodi.ts b/contracts/src/deploy-config/hoodi.ts index aef1e7295..15f50dda4 100644 --- a/contracts/src/deploy-config/hoodi.ts +++ b/contracts/src/deploy-config/hoodi.ts @@ -17,7 +17,7 @@ const config = { l2BaseFee: 0.1, // Gwei // verify contract config - programVkey: '0x00da5ade7ec0ec902618c53b616ac96f47de1cb79b450f815a7c6cbebd6ffaef', + programVkey: '0x001fe18a35489f0e7ae203bc2b1f26b7696f00bafa8000518c94a479d29c4076', // rollup contract config // initialize config finalizationPeriodSeconds: 600, diff --git a/contracts/src/deploy-config/l1.ts b/contracts/src/deploy-config/l1.ts index 979010c87..680b89db7 100644 --- a/contracts/src/deploy-config/l1.ts +++ b/contracts/src/deploy-config/l1.ts @@ -17,7 +17,7 @@ const config = { l2BaseFee: 0.1, // Gwei // verify contract config - programVkey: '0x00da5ade7ec0ec902618c53b616ac96f47de1cb79b450f815a7c6cbebd6ffaef', + programVkey: '0x001fe18a35489f0e7ae203bc2b1f26b7696f00bafa8000518c94a479d29c4076', // rollup contract config // initialize config finalizationPeriodSeconds: 10, diff --git a/contracts/src/deploy-config/qanetl1.ts b/contracts/src/deploy-config/qanetl1.ts index 278c2aa3b..c21ea93b6 100644 --- a/contracts/src/deploy-config/qanetl1.ts +++ b/contracts/src/deploy-config/qanetl1.ts @@ -14,7 +14,7 @@ const config = { l2BaseFee: 0.1, // Gwei // verify contract config - programVkey: '0x00da5ade7ec0ec902618c53b616ac96f47de1cb79b450f815a7c6cbebd6ffaef', + programVkey: '0x001fe18a35489f0e7ae203bc2b1f26b7696f00bafa8000518c94a479d29c4076', // rollup contract config // initialize config finalizationPeriodSeconds: 600, diff --git a/contracts/src/deploy-config/sepolia.ts b/contracts/src/deploy-config/sepolia.ts index 14117dac6..0facf9f99 100644 --- a/contracts/src/deploy-config/sepolia.ts +++ b/contracts/src/deploy-config/sepolia.ts @@ -18,7 +18,7 @@ const config = { /** * ---to---legacy property */ - programVkey: '0x00da5ade7ec0ec902618c53b616ac96f47de1cb79b450f815a7c6cbebd6ffaef', + programVkey: '0x001fe18a35489f0e7ae203bc2b1f26b7696f00bafa8000518c94a479d29c4076', rollupMinDeposit: 0.0001, rollupProofWindow: 86400, rollupGenesisBlockNumber: 0, diff --git a/contracts/src/deploy-config/testnetl1.ts b/contracts/src/deploy-config/testnetl1.ts index 0d0659ef8..501bb7b7f 100644 --- a/contracts/src/deploy-config/testnetl1.ts +++ b/contracts/src/deploy-config/testnetl1.ts @@ -13,7 +13,7 @@ const config = { sequencerWindowSize: 200, channelTimeout: 120, - programVkey: '0x00da5ade7ec0ec902618c53b616ac96f47de1cb79b450f815a7c6cbebd6ffaef', + programVkey: '0x001fe18a35489f0e7ae203bc2b1f26b7696f00bafa8000518c94a479d29c4076', rollupMinDeposit: 1, rollupProofWindow: 100, rollupGenesisBlockNumber: 0, diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 9651be8bc..48b49e1b7 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -4364,6 +4364,22 @@ dependencies = [ "serde_json", ] +[[package]] +name = "morph-da-decoder-core" +version = "0.1.0" +source = "git+https://github.com/morph-l2/morph-da-codec.git?rev=681727561e38d07c3ca7ad3017bea7f165b68783#681727561e38d07c3ca7ad3017bea7f165b68783" +dependencies = [ + "ruzstd", +] + +[[package]] +name = "morph-da-encoder-core" +version = "0.1.0" +source = "git+https://github.com/morph-l2/morph-da-codec.git?rev=681727561e38d07c3ca7ad3017bea7f165b68783#681727561e38d07c3ca7ad3017bea7f165b68783" +dependencies = [ + "zstd", +] + [[package]] name = "morph-primitives" version = "0.2.0" @@ -4673,7 +4689,7 @@ dependencies = [ "hashbrown 0.15.5", "indexmap 2.12.1", "memchr", - "ruzstd 0.8.3", + "ruzstd", ] [[package]] @@ -5735,6 +5751,7 @@ dependencies = [ "anyhow", "kzg-rs", "log", + "morph-da-decoder-core", "morph-revm", "prover-executor-core", "prover-mpt", @@ -5742,7 +5759,6 @@ dependencies = [ "prover-storage-witness", "reth-trie", "revm", - "ruzstd 0.7.2", "serde", "serde_json", "serde_with", @@ -5776,6 +5792,7 @@ dependencies = [ "anyhow", "c-kzg", "log", + "morph-da-encoder-core", "prover-executor-client", "prover-executor-core", "prover-mpt", @@ -5786,7 +5803,6 @@ dependencies = [ "serde", "serde_json", "tokio", - "zstd", ] [[package]] @@ -7123,21 +7139,13 @@ dependencies = [ "wait-timeout", ] -[[package]] -name = "ruzstd" -version = "0.7.2" -source = "git+https://github.com/KillingSpark/zstd-rs.git?branch=master#603ee2dfa5f0abe3a8bfc5fad6cb9782cdf37a68" -dependencies = [ - "twox-hash 1.6.3", -] - [[package]] name = "ruzstd" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7c1c839d570d835527c9a5e4db7cb2198683a988cb9d7293fc8674e6bd58fc8" dependencies = [ - "twox-hash 2.1.2", + "twox-hash", ] [[package]] @@ -9543,16 +9551,6 @@ dependencies = [ "url", ] -[[package]] -name = "twox-hash" -version = "1.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" -dependencies = [ - "cfg-if 0.1.10", - "static_assertions", -] - [[package]] name = "twox-hash" version = "2.1.2" diff --git a/prover/Cargo.toml b/prover/Cargo.toml index 5795ea7fd..d9ddac7a3 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -58,13 +58,9 @@ tokio = { version = "1.21", default-features = false, features = [ prometheus = { version = "0.9", features = ["process"] } prometheus-client = "0.22" -# Compression -# zstd decompression, the pure Rust implementation used in riscv client. -ruzstd = { git = "https://github.com/KillingSpark/zstd-rs.git", branch = "master" } -# zstd compression, the C implementation used in host. -zstd = { git = "https://github.com/morph-l2/zstd-rs.git", branch = "zstd-dev", features = [ - "experimental", -] } +# DA Codec +morph-da-encoder-core = { git = "https://github.com/morph-l2/morph-da-codec.git", rev = "681727561e38d07c3ca7ad3017bea7f165b68783" } +morph-da-decoder-core = { git = "https://github.com/morph-l2/morph-da-codec.git", rev = "681727561e38d07c3ca7ad3017bea7f165b68783" } # Crypto diff --git a/prover/bin/client/elf/verifier-client b/prover/bin/client/elf/verifier-client index 04703b958..754175072 100755 Binary files a/prover/bin/client/elf/verifier-client and b/prover/bin/client/elf/verifier-client differ diff --git a/prover/bin/shadow-prove/contracts/README.md b/prover/bin/shadow-prove/contracts/README.md index 556c70247..2c03d9401 100644 --- a/prover/bin/shadow-prove/contracts/README.md +++ b/prover/bin/shadow-prove/contracts/README.md @@ -16,7 +16,7 @@ forge build EvmVerifier: ``` -forge create --broadcast --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545 src/libs/EvmVerifier.sol:EvmVerifier --constructor-args 0x00da5ade7ec0ec902618c53b616ac96f47de1cb79b450f815a7c6cbebd6ffaef +forge create --broadcast --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545 src/libs/EvmVerifier.sol:EvmVerifier --constructor-args 0x001fe18a35489f0e7ae203bc2b1f26b7696f00bafa8000518c94a479d29c4076 ``` ShadowRollup diff --git a/prover/contracts/README.md b/prover/contracts/README.md index 4cb10d7f3..f745f97e3 100644 --- a/prover/contracts/README.md +++ b/prover/contracts/README.md @@ -17,5 +17,5 @@ $ forge test ### Deploy ``` -forge create --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545 prover/contracts/src/EvmVerifier.sol:EvmVerifier --constructor-args 0x00da5ade7ec0ec902618c53b616ac96f47de1cb79b450f815a7c6cbebd6ffaef +forge create --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545 prover/contracts/src/EvmVerifier.sol:EvmVerifier --constructor-args 0x001fe18a35489f0e7ae203bc2b1f26b7696f00bafa8000518c94a479d29c4076 ``` \ No newline at end of file diff --git a/prover/crates/executor/client/Cargo.toml b/prover/crates/executor/client/Cargo.toml index 3d9e51c36..96fa4fefd 100644 --- a/prover/crates/executor/client/Cargo.toml +++ b/prover/crates/executor/client/Cargo.toml @@ -9,7 +9,7 @@ anyhow = { workspace = true } sha2 = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_with.workspace = true -ruzstd = { workspace = true } +morph-da-decoder-core = { workspace = true } kzg-rs = { workspace = true } thiserror = { workspace = true } alloy-eips = { workspace = true } diff --git a/prover/crates/executor/client/src/types/blob.rs b/prover/crates/executor/client/src/types/blob.rs index 31ab48d1b..83fddb4bc 100644 --- a/prover/crates/executor/client/src/types/blob.rs +++ b/prover/crates/executor/client/src/types/blob.rs @@ -1,9 +1,5 @@ -use anyhow::{anyhow, Context}; -use ruzstd::StreamingDecoder; -use std::io::Read; - -/// This magic number is included at the start of a single Zstandard frame -pub const MAGIC_NUM: u32 = 0xFD2F_B528; +use anyhow::anyhow; +use morph_da_decoder_core::decompress_morph_da_zstd; /// The number of coefficients (BLS12-381 scalars) to represent the blob polynomial in /// evaluationform. @@ -48,19 +44,8 @@ pub fn get_origin_batch(blob_data: &[u8]) -> Result, anyhow::Error> { } pub fn decompress_batch(compressed_batch: &[u8]) -> Result, anyhow::Error> { - if compressed_batch.iter().all(|&x| x == 0) { - // empty batch - return Ok(Vec::new()); - } - - let mut content = MAGIC_NUM.to_le_bytes().to_vec(); - content.append(&mut compressed_batch.to_vec()); - let mut x = content.as_slice(); - - let mut decoder = StreamingDecoder::new(&mut x)?; - let mut result = Vec::new(); - decoder.read_to_end(&mut result).context("Failed to decompress batch")?; + let decoded = decompress_morph_da_zstd(compressed_batch)?; #[cfg(not(target_os = "zkvm"))] - log::info!("decompressed_batch: {:?}", result.len()); - Ok(result) + log::info!("decompressed_batch: {:?}", decoded.len()); + Ok(decoded) } diff --git a/prover/crates/executor/host/Cargo.toml b/prover/crates/executor/host/Cargo.toml index 4aaa110e4..1e9103ef2 100644 --- a/prover/crates/executor/host/Cargo.toml +++ b/prover/crates/executor/host/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" edition = "2021" [dependencies] -zstd = { workspace = true } +morph-da-encoder-core = { workspace = true } anyhow = { workspace = true } c-kzg = { workspace = true } prover-primitives = { workspace = true } diff --git a/prover/crates/executor/host/src/blob.rs b/prover/crates/executor/host/src/blob.rs index a7bb38a94..43168e4ad 100644 --- a/prover/crates/executor/host/src/blob.rs +++ b/prover/crates/executor/host/src/blob.rs @@ -1,10 +1,10 @@ -use crate::zstd_util::{init_zstd_encoder, N_BLOCK_SIZE_TARGET}; use anyhow::{ensure, Context, Result}; +use morph_da_encoder_core::compress_morph_da_zstd; use prover_executor_client::types::input::BlobInfo; use prover_primitives::types::blob::{get_blob_data_from_blocks, get_blob_data_from_traces}; use prover_primitives::types::block::L2Block; use prover_primitives::types::BlockTrace; -use std::{io::Write, sync::Arc}; +use std::sync::Arc; /// The number of bytes to represent an unsigned 256 bit number. const N_BYTES_U256: usize = 32; @@ -152,10 +152,6 @@ pub fn populate_kzg(blob_bytes: &[u8]) -> Result { /// zstd compress batch data pub fn compresse_batch(batch: &[u8]) -> Result> { - let mut encoder = init_zstd_encoder(N_BLOCK_SIZE_TARGET); - encoder.set_pledged_src_size(Some(batch.len() as u64)).context("zstd set_pledged")?; - encoder.write_all(batch).context("zstd write_all")?; - - let encoded_bytes: Vec = encoder.finish().context("zstd finish")?; + let encoded_bytes: Vec = compress_morph_da_zstd(batch).context("compress batch failed")?; Ok(encoded_bytes) } diff --git a/prover/crates/executor/host/src/lib.rs b/prover/crates/executor/host/src/lib.rs index 36ed6809e..e5b290f84 100644 --- a/prover/crates/executor/host/src/lib.rs +++ b/prover/crates/executor/host/src/lib.rs @@ -4,4 +4,3 @@ pub mod blob; pub mod execute; pub mod trace; pub mod utils; -mod zstd_util; diff --git a/prover/crates/executor/host/src/zstd_util.rs b/prover/crates/executor/host/src/zstd_util.rs deleted file mode 100644 index b66a3bedf..000000000 --- a/prover/crates/executor/host/src/zstd_util.rs +++ /dev/null @@ -1,43 +0,0 @@ -use zstd::{ - stream::Encoder, - zstd_safe::{CParameter, ParamSwitch}, -}; - -// we use offset window no more than = 17 -#[allow(dead_code)] -pub const CL_WINDOW_LIMIT: usize = 17; - -#[allow(dead_code)] -/// zstd block size target. -pub const N_BLOCK_SIZE_TARGET: u32 = 124 * 1024; - -#[allow(dead_code)] -/// Maximum number of blocks that we can expect in the encoded data. -pub const N_MAX_BLOCKS: u64 = 10; - -#[allow(dead_code)] -/// Zstd encoder configuration -pub(crate) fn init_zstd_encoder(target_block_size: u32) -> Encoder<'static, Vec> { - let mut encoder = Encoder::new(Vec::new(), 0).expect("infallible"); - - // disable compression of literals, i.e. literals will be raw bytes. - encoder - .set_parameter(CParameter::LiteralCompressionMode(ParamSwitch::Disable)) - .expect("infallible"); - // with a hack in zstd we can set window log <= 17 with single segment kept - encoder.set_parameter(CParameter::WindowLog(17)).expect("infallible"); - // set target block size to fit within a single block. - encoder.set_parameter(CParameter::TargetCBlockSize(target_block_size)).expect("infallible"); - // do not include the checksum at the end of the encoded data. - encoder.include_checksum(false).expect("infallible"); - // do not include magic bytes at the start of the frame since we will have a single - // frame. - encoder.include_magicbytes(false).expect("infallible"); - // do not include dictionary id so we have more simple content - encoder.include_dictid(false).expect("infallible"); - // include the content size to know at decode time the expected size of decoded - // data. - encoder.include_contentsize(true).expect("infallible"); - - encoder -}