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

Bind ELF to ProofData #1647

Merged
merged 28 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
550de8d
Bind elf to ProofData and add tests
jfldde Dec 24, 2024
91a1a8d
Add missing import
jfldde Dec 24, 2024
b9b7bfa
With structs v1
jfldde Dec 24, 2024
cfcea45
fix pre fork1 batch proof guest serialization
eyusufatik Dec 25, 2024
e67099d
implement use_latest_elf for batch prover
eyusufatik Dec 26, 2024
aff6562
fix mock e2e tests
eyusufatik Dec 26, 2024
058e5fb
add todo
eyusufatik Dec 26, 2024
6de2754
add short prefix elf for genesis fork batch proof
eyusufatik Dec 26, 2024
bc9d694
add light client prover to fork elf switch test
eyusufatik Jan 2, 2025
9a58b5d
Merge branch 'nightly' into elf-switch
eyusufatik Jan 2, 2025
2c049dc
fix sys-getenv bug1
eyusufatik Jan 2, 2025
02b2abe
fix FromEnv test
eyusufatik Jan 2, 2025
862575b
Merge branch 'nightly' into elf-switch
jfldde Jan 2, 2025
f92b5fe
fix some tests
eyusufatik Jan 2, 2025
a69ebad
fix some more tests
eyusufatik Jan 2, 2025
798971b
fix forkmanager and some tests
eyusufatik Jan 2, 2025
814e8de
fix test_prover_transaction_chaining test
eyusufatik Jan 2, 2025
698eb70
get fork_from_block_number as an arg for evm query functions
eyusufatik Jan 3, 2025
6802fc0
Remove env debug
jfldde Jan 3, 2025
79c34cc
Fix native warning
jfldde Jan 3, 2025
406edc7
ProofData as struct and pub visibility
jfldde Jan 3, 2025
c79020c
Merge branch 'nightly' into elf-switch
jfldde Jan 3, 2025
1d12d48
update evm tests with always fork1
eyusufatik Jan 3, 2025
3841e9a
Fix ProofData struct in tests
jfldde Jan 3, 2025
4ca3f7e
Add missing import
jfldde Jan 3, 2025
552ceb8
Use expect directly
jfldde Jan 3, 2025
f1a6f94
Merge branch 'nightly' into elf-switch
jfldde Jan 3, 2025
f6659f6
Fix bind elf tests (#1663)
ercecan Jan 3, 2025
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
2 changes: 1 addition & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ alloy-eips = { version = "0.4.2", default-features = false }
alloy-consensus = { version = "0.4.2", default-features = false, features = ["serde", "serde-bincode-compat"] }
alloy-network = { version = "0.4.2", default-features = false }

citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "6a87ce3" }
citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "82c1cdb" }

[patch.crates-io]
bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "ca3cfa2" }
31 changes: 23 additions & 8 deletions bin/citrea/src/guests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ lazy_static! {
pub(crate) static ref BATCH_PROOF_LATEST_MOCK_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

m.insert(
SpecId::Genesis,
(
Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_MOCK_ID),
citrea_risc0_batch_proof::BATCH_PROOF_MOCK_ELF.to_vec(),
),
);

m.insert(
SpecId::Fork1,
(
Expand All @@ -42,20 +50,27 @@ lazy_static! {
};
/// The following 2 are used as latest guest builds for tests that use Bitcoin DA.
pub(crate) static ref BATCH_PROOF_LATEST_BITCOIN_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
HashMap::from(
[
// this is ELF of genesis fork except for da namespace [1, 1] -> [1] and [2,2] -> [2]
(SpecId::Genesis, guest!("../../../resources/guests/risc0/genesis-batch-proof-0-short-prefix")),
(SpecId::Fork1,
(Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID),
citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ELF.to_vec())
)
]
)
};
pub(crate) static ref LIGHT_CLIENT_LATEST_BITCOIN_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

m.insert(
SpecId::Fork1,
SpecId::Genesis,
(
Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID),
citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ELF.to_vec(),
Digest::new(citrea_risc0_light_client::LIGHT_CLIENT_PROOF_BITCOIN_ID),
citrea_risc0_light_client::LIGHT_CLIENT_PROOF_BITCOIN_ELF.to_vec(),
)
);
m
};
pub(crate) static ref LIGHT_CLIENT_LATEST_BITCOIN_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

m.insert(
SpecId::Fork1,
(
Expand Down
7 changes: 6 additions & 1 deletion bin/citrea/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use sov_modules_api::Spec;
use sov_modules_rollup_blueprint::RollupBlueprint;
use sov_rollup_interface::Network;
use sov_state::storage::NativeStorage;
use tracing::{debug, error, info, instrument};
use tracing::{debug, error, info, instrument, trace};

#[cfg(test)]
mod test_rpc;
Expand Down Expand Up @@ -155,6 +155,11 @@ async fn main() -> Result<(), anyhow::Error> {

info!("Starting node on {network}");

trace!("Running with env :");
for (key, value) in std::env::vars() {
trace!(" {}: {}", key, value);
}
jfldde marked this conversation as resolved.
Show resolved Hide resolved

match args.da_layer {
SupportedDaLayer::Mock => {
start_rollup::<MockDemoRollup, MockDaConfig>(
Expand Down
179 changes: 177 additions & 2 deletions bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ use bitcoin_da::service::{BitcoinService, BitcoinServiceConfig, FINALITY_DEPTH};
use bitcoin_da::spec::RollupParams;
use citrea_common::tasks::manager::TaskManager;
use citrea_e2e::config::{
BatchProverConfig, ProverGuestRunConfig, SequencerConfig, SequencerMempoolConfig,
TestCaseConfig, TestCaseEnv,
BatchProverConfig, LightClientProverConfig, ProverGuestRunConfig, SequencerConfig,
SequencerMempoolConfig, TestCaseConfig, TestCaseEnv,
};
use citrea_e2e::framework::TestFramework;
use citrea_e2e::full_node::FullNode;
use citrea_e2e::node::{Config, NodeKind};
use citrea_e2e::test_case::{TestCase, TestCaseRunner};
use citrea_e2e::traits::NodeT;
use citrea_e2e::Result;
use citrea_light_client_prover::rpc::LightClientProverRpcClient;
use citrea_primitives::forks::{fork_from_block_number, get_forks};
use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX};
use sov_ledger_rpc::LedgerRpcClient;
use sov_modules_api::fork::ForkManager;
use sov_modules_api::SpecId;
use sov_rollup_interface::da::{DaTxRequest, SequencerCommitment};
use sov_rollup_interface::rpc::VerifiedBatchProofResponse;
use tokio::time::sleep;
Expand Down Expand Up @@ -68,6 +72,13 @@ impl TestCase for BasicProverTest {
}
}

fn batch_prover_config() -> BatchProverConfig {
BatchProverConfig {
use_latest_elf: false,
..Default::default()
}
}

async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> {
let da = f.bitcoin_nodes.get(0).unwrap();
let sequencer = f.sequencer.as_ref().unwrap();
Expand Down Expand Up @@ -154,6 +165,13 @@ impl TestCase for SkipPreprovenCommitmentsTest {
}
}

fn batch_prover_config() -> BatchProverConfig {
BatchProverConfig {
use_latest_elf: false,
..Default::default()
}
}

async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> {
let da = f.bitcoin_nodes.get(0).unwrap();
let sequencer = f.sequencer.as_ref().unwrap();
Expand Down Expand Up @@ -523,3 +541,160 @@ async fn parallel_proving_test() -> Result<()> {
.run()
.await
}

struct ForkElfSwitchingTest;

#[async_trait]
impl TestCase for ForkElfSwitchingTest {
fn test_config() -> TestCaseConfig {
TestCaseConfig {
with_batch_prover: true,
with_full_node: true,
with_light_client_prover: true,
..Default::default()
}
}

fn sequencer_config() -> SequencerConfig {
let fork_1_height = ForkManager::new(get_forks(), 0)
.next_fork()
.unwrap()
.activation_height;

// Set just below fork1 height so we can generate first soft com txs in genesis
// and second batch above fork1
SequencerConfig {
min_soft_confirmations_per_commitment: fork_1_height - 5,
..Default::default()
}
}

fn batch_prover_config() -> BatchProverConfig {
BatchProverConfig {
use_latest_elf: false,
..Default::default()
}
}

fn light_client_prover_config() -> LightClientProverConfig {
LightClientProverConfig {
initial_da_height: 171,
enable_recovery: false,
..Default::default()
}
}

async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> {
let da = f.bitcoin_nodes.get(0).unwrap();
let sequencer = f.sequencer.as_ref().unwrap();
let batch_prover = f.batch_prover.as_ref().unwrap();
let full_node = f.full_node.as_ref().unwrap();
let light_client_prover = f.light_client_prover.as_ref().unwrap();

// send evm tx
let evm_client = make_test_client(SocketAddr::new(
sequencer.config().rpc_bind_host().parse()?,
sequencer.config().rpc_bind_port(),
))
.await?;

let pending_evm_tx = evm_client
.send_eth(Address::random(), None, None, None, 100)
.await
.unwrap();

let min_soft_confirmations = sequencer.min_soft_confirmations_per_commitment();

for _ in 0..min_soft_confirmations {
sequencer.client.send_publish_batch_request().await?;
}

// assert that evm tx is mined
let evm_tx = evm_client
.eth_get_transaction_by_hash(*pending_evm_tx.tx_hash(), None)
.await
.unwrap();

assert!(evm_tx.block_number.is_some());

let height = sequencer
.client
.ledger_get_head_soft_confirmation_height()
.await?;

assert_eq!(fork_from_block_number(height).spec_id, SpecId::Genesis);

// Generate softcom in fork1
for _ in 0..min_soft_confirmations {
sequencer.client.send_publish_batch_request().await?;
}

let height = sequencer
.client
.ledger_get_head_soft_confirmation_height()
.await?;
assert_eq!(fork_from_block_number(height).spec_id, SpecId::Fork1);

da.wait_mempool_len(4, None).await?;

da.generate(FINALITY_DEPTH).await?;

let finalized_height = da.get_finalized_height().await?;

batch_prover
.wait_for_l1_height(finalized_height, None)
.await?;

// Wait for batch proof tx to hit mempool
da.wait_mempool_len(4, None).await?;
da.generate(FINALITY_DEPTH).await?;

full_node
.wait_for_l1_height(finalized_height + FINALITY_DEPTH, None)
.await?;
let proofs = wait_for_zkproofs(full_node, finalized_height + FINALITY_DEPTH, None)
.await
.unwrap();

assert_eq!(proofs.len(), 2);
assert_eq!(
fork_from_block_number(proofs[0].proof_output.last_l2_height).spec_id,
SpecId::Genesis
);
assert_eq!(
fork_from_block_number(proofs[1].proof_output.last_l2_height).spec_id,
SpecId::Fork1
);

light_client_prover
.wait_for_l1_height(finalized_height + FINALITY_DEPTH, None)
.await?;
let lcp = light_client_prover
.client
.http_client()
.get_light_client_proof_by_l1_height(finalized_height + FINALITY_DEPTH)
.await
.unwrap()
.unwrap();

assert!(lcp
.light_client_proof_output
.unchained_batch_proofs_info
.is_empty());

assert_eq!(
lcp.light_client_proof_output.state_root.to_vec(),
proofs[1].proof_output.final_state_root
);

Ok(())
}
}

#[tokio::test]
async fn test_fork_elf_switching() -> Result<()> {
TestCaseRunner::new(ForkElfSwitchingTest)
.set_citrea_path(get_citrea_path())
.run()
.await
}
Loading
Loading