Skip to content

Commit

Permalink
Check compressed sequencer commitments (#1349)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakanalh authored Oct 17, 2024
1 parent 8ea8350 commit 7c47f06
Show file tree
Hide file tree
Showing 19 changed files with 575 additions and 396 deletions.
3 changes: 1 addition & 2 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 bin/citrea/tests/bitcoin_e2e/prover_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl TestCase for BasicProverTest {
.sum();
let borshed_state_diff = borsh::to_vec(state_diff).unwrap();
let compressed_state_diff =
bitcoin_da::helpers::compression::compress_blob(&borshed_state_diff);
citrea_primitives::compression::compress_blob(&borshed_state_diff);
println!(
"StateDiff: size {}, compressed {}",
state_diff_size,
Expand Down
16 changes: 8 additions & 8 deletions bin/citrea/tests/e2e/sequencer_behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ async fn test_sequencer_commitment_threshold() {

seq_test_client.send_publish_batch_request().await;

for i in 1..17 {
for _ in 0..300 {
for i in 1..35 {
for _ in 0..600 {
let address = Address::random();
let _pending = seq_test_client
.send_eth(address, None, None, None, 1u128)
Expand All @@ -176,14 +176,14 @@ async fn test_sequencer_commitment_threshold() {
wait_for_l2_block(&seq_test_client, i, None).await;
}

wait_for_l2_block(&seq_test_client, 16, Some(Duration::from_secs(60))).await;
wait_for_l2_block(&seq_test_client, 35, Some(Duration::from_secs(60))).await;

// After block 9/10, the state diff should be large enough to trigger a commitment.
// After block 35, the state diff should be large enough to trigger a commitment.
let commitments = wait_for_commitment(&da_service, 2, Some(Duration::from_secs(60))).await;
assert_eq!(commitments.len(), 1);

for i in 17..30 {
for _ in 0..300 {
for i in 35..70 {
for _ in 0..600 {
let address = Address::random();
let _pending = seq_test_client
.send_eth(address, None, None, None, 1u128)
Expand All @@ -196,9 +196,9 @@ async fn test_sequencer_commitment_threshold() {
wait_for_l2_block(&seq_test_client, i, None).await;
}

wait_for_l2_block(&seq_test_client, 29, Some(Duration::from_secs(60))).await;
wait_for_l2_block(&seq_test_client, 70, Some(Duration::from_secs(60))).await;

// After block 17/18, the state diff should be large enough to trigger a commitment.
// After block 70, the state diff should be large enough to trigger a commitment.
// But the remaining blocks state diff should NOT trigger a third.
let commitments = wait_for_commitment(&da_service, 3, Some(Duration::from_secs(60))).await;
assert_eq!(commitments.len(), 1);
Expand Down
2 changes: 0 additions & 2 deletions crates/bitcoin-da/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ thiserror = { workspace = true }
tracing = { workspace = true, optional = true }

bitcoin = { workspace = true }
brotli = { workspace = true, optional = true }
futures.workspace = true
sha2 = { workspace = true }

Expand All @@ -41,7 +40,6 @@ bitcoincore-rpc = { workspace = true, optional = true }
default = []
native = [
"dep:backoff",
"dep:brotli",
"dep:tokio",
"dep:pin-project",
"dep:tracing",
Expand Down
2 changes: 1 addition & 1 deletion crates/bitcoin-da/src/helpers/builders/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use bitcoin::secp256k1::schnorr::Signature;
use bitcoin::secp256k1::SecretKey;
use bitcoin::taproot::ControlBlock;
use bitcoin::{Address, Amount, ScriptBuf, TxOut, Txid};
use citrea_primitives::compression::{compress_blob, decompress_blob};

use super::light_client_proof_namespace::LightClientTxs;
use crate::helpers::builders::sign_blob_with_private_key;
use crate::helpers::compression::{compress_blob, decompress_blob};
use crate::helpers::parsers::{parse_light_client_transaction, ParsedLightClientTransaction};
use crate::spec::utxo::UTXO;
use crate::REVEAL_OUTPUT_AMOUNT;
Expand Down
2 changes: 0 additions & 2 deletions crates/bitcoin-da/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use sha2::{Digest, Sha256};

#[cfg(feature = "native")]
pub mod builders;
#[cfg(feature = "native")]
pub mod compression;
pub mod merkle_tree;
pub mod parsers;
#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion crates/bitcoin-da/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use bitcoin::{Amount, BlockHash, CompactTarget, Transaction, Txid, Wtxid};
use bitcoincore_rpc::json::TestMempoolAcceptResult;
use bitcoincore_rpc::{Auth, Client, Error, RpcApi, RpcError};
use borsh::BorshDeserialize;
use citrea_primitives::compression::{compress_blob, decompress_blob};
use serde::{Deserialize, Serialize};
use sov_rollup_interface::da::{DaData, DaDataBatchProof, DaDataLightClient, DaSpec};
use sov_rollup_interface::services::da::{DaService, SenderWithNotifier};
Expand All @@ -35,7 +36,6 @@ use crate::helpers::builders::light_client_proof_namespace::{
create_zkproof_transactions, LightClientTxs,
};
use crate::helpers::builders::{TxListWithReveal, TxWithId};
use crate::helpers::compression::{compress_blob, decompress_blob};
use crate::helpers::merkle_tree;
use crate::helpers::merkle_tree::BitcoinMerkleTree;
use crate::helpers::parsers::{
Expand Down
1 change: 1 addition & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pub mod error;
pub mod rpc;
pub mod tasks;
pub mod utils;

pub use config::*;
2 changes: 2 additions & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface" }
# 3rd-party deps
alloy-eips = { workspace = true }
anyhow = { workspace = true }
brotli = { workspace = true, optional = true }
reth-primitives = { workspace = true }
serde = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
Expand All @@ -25,6 +26,7 @@ sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface", features =
[features]
native = [
"dep:serde",
"dep:brotli",
"dep:tokio",
"dep:tracing",
"sov-rollup-interface/native",
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions crates/primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ pub const REVEAL_LIGHT_CLIENT_PREFIX: &[u8] = get_reveal_light_client_prefix();
pub const TEST_PRIVATE_KEY: &str =
"1212121212121212121212121212121212121212121212121212121212121212";

pub const MAX_STATEDIFF_SIZE_COMMITMENT_THRESHOLD: u64 = 300 * 1024;

pub const MIN_BASE_FEE_PER_GAS: u128 = 10_000_000; // 0.01 gwei

/// Maximum size of a bitcoin transaction body in bytes
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod basefee;
#[cfg(feature = "native")]
pub mod compression;
mod constants;
pub mod forks;
pub mod types;
Expand Down
1 change: 0 additions & 1 deletion crates/prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ repository.workspace = true

[dependencies]
# Citrea Deps
bitcoin-da = { path = "../bitcoin-da" }
citrea-common = { path = "../common" }
citrea-primitives = { path = "../primitives", features = ["native"] }
citrea-stf = { path = "../citrea-stf" }
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/da_block_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use std::ops::RangeInclusive;
use std::sync::Arc;

use anyhow::anyhow;
use bitcoin_da::helpers::compression::compress_blob;
use borsh::{BorshDeserialize, BorshSerialize};
use citrea_common::cache::L1BlockCache;
use citrea_common::da::get_da_block_at_height;
use citrea_common::utils::merge_state_diffs;
use citrea_common::ProverConfig;
use citrea_primitives::compression::compress_blob;
use citrea_primitives::MAX_TXBODY_SIZE;
use rand::Rng;
use serde::de::DeserializeOwned;
Expand Down
Loading

0 comments on commit 7c47f06

Please sign in to comment.