Skip to content

Commit

Permalink
Merge nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
yaziciahmet committed Dec 19, 2024
2 parents e0d7d56 + 8c812ba commit 090bd53
Show file tree
Hide file tree
Showing 44 changed files with 601 additions and 353 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly_build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Build Project
run: |
cargo build --features short-prefix
cargo build --features testing
- name: Copy binary to build-push/nightly
run: |
Expand Down
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ EF_TESTS_URL := https://github.com/chainwayxyz/ef-tests/archive/develop.tar.gz
EF_TESTS_DIR := crates/evm/ethereum-tests
CITREA_E2E_TEST_BINARY := $(CURDIR)/target/debug/citrea
PARALLEL_PROOF_LIMIT := 1
TEST_FEATURES := --features short-prefix
TEST_FEATURES := --features testing
BATCH_OUT_PATH := resources/guests/risc0/
LIGHT_OUT_PATH := resources/guests/risc0/

Expand Down
2 changes: 1 addition & 1 deletion bin/citrea/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ sp1-helper = { version = "3.0.0", default-features = false }

[features]
default = [] # Deviate from convention by making the "native" feature active by default. This aligns with how this package is meant to be used (as a binary first, library second).
bench = ["hex"]
testing = ["citrea-primitives/testing", "citrea-risc0/testing", "sov-rollup-interface/testing"]

[[bin]]
name = "citrea"
Expand Down
15 changes: 7 additions & 8 deletions bin/citrea/src/rollup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use jsonrpsee::RpcModule;
use sov_db::ledger_db::migrations::LedgerDBMigrator;
use sov_db::ledger_db::{LedgerDB, SharedLedgerOps};
use sov_db::rocks_db_config::RocksdbConfig;
use sov_db::schema::types::BatchNumber;
use sov_db::schema::types::SoftConfirmationNumber;
use sov_modules_api::Spec;
use sov_modules_rollup_blueprint::RollupBlueprint;
use sov_modules_stf_blueprint::{Runtime as RuntimeTrait, StfBlueprint};
Expand Down Expand Up @@ -123,7 +123,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
.get_head_soft_confirmation()
.map_err(|e| anyhow!("Failed to get head soft confirmation: {}", e))?
.map(|(l2_height, _)| l2_height)
.unwrap_or(BatchNumber(0));
.unwrap_or(SoftConfirmationNumber(0));

let mut fork_manager = ForkManager::new(get_forks(), current_l2_height.0);
fork_manager.register_handler(Box::new(ledger_db.clone()));
Expand Down Expand Up @@ -254,7 +254,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
.get_head_soft_confirmation()
.map_err(|e| anyhow!("Failed to get head soft confirmation: {}", e))?
.map(|(l2_height, _)| l2_height)
.unwrap_or(BatchNumber(0));
.unwrap_or(SoftConfirmationNumber(0));

let mut fork_manager = ForkManager::new(get_forks(), current_l2_height.0);
fork_manager.register_handler(Box::new(ledger_db.clone()));
Expand Down Expand Up @@ -382,12 +382,11 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
let elfs_by_spec = self.get_batch_proof_elfs();

let current_l2_height = ledger_db
.get_head_soft_confirmation()
.get_head_soft_confirmation_height()
.map_err(|e| anyhow!("Failed to get head soft confirmation: {}", e))?
.map(|(l2_height, _)| l2_height)
.unwrap_or(BatchNumber(0));
.unwrap_or(0);

let mut fork_manager = ForkManager::new(get_forks(), current_l2_height.0);
let mut fork_manager = ForkManager::new(get_forks(), current_l2_height);
fork_manager.register_handler(Box::new(ledger_db.clone()));

let runner = CitreaBatchProver::new(
Expand Down Expand Up @@ -475,7 +474,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
.get_head_soft_confirmation()
.map_err(|e| anyhow!("Failed to get head soft confirmation: {}", e))?
.map(|(l2_height, _)| l2_height)
.unwrap_or(BatchNumber(0));
.unwrap_or(SoftConfirmationNumber(0));

let mut fork_manager = ForkManager::new(get_forks(), current_l2_height.0);
fork_manager.register_handler(Box::new(ledger_db.clone()));
Expand Down
2 changes: 1 addition & 1 deletion bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl TestCase for SkipPreprovenCommitmentsTest {

// Wait for the full node to see all process verify and store all batch proofs
full_node.wait_for_l1_height(finalized_height, None).await?;
let proofs = wait_for_zkproofs(full_node, finalized_height, None)
let proofs = wait_for_zkproofs(full_node, finalized_height, Some(Duration::from_secs(600)))
.await
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion bin/citrea/tests/e2e/sequencer_behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ async fn test_gas_limit_too_high() {
assert_eq!(block_from_sequencer.header.hash, block.header.hash);

seq_test_client.send_publish_batch_request().await;
wait_for_l2_block(&full_node_test_client, 2, None).await;
wait_for_l2_block(&full_node_test_client, 2, Some(Duration::from_secs(60))).await;

let block = full_node_test_client
.eth_get_block_by_number(Some(BlockNumberOrTag::Latest))
Expand Down
23 changes: 11 additions & 12 deletions crates/batch-prover/src/da_block_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rand::Rng;
use serde::de::DeserializeOwned;
use serde::Serialize;
use sov_db::ledger_db::BatchProverLedgerOps;
use sov_db::schema::types::{BatchNumber, SlotNumber};
use sov_db::schema::types::{SlotNumber, SoftConfirmationNumber};
use sov_modules_api::{DaSpec, StateDiff, Zkvm};
use sov_rollup_interface::da::{BlockHeaderTrait, SequencerCommitment};
use sov_rollup_interface::services::da::{DaService, SlotData};
Expand Down Expand Up @@ -365,9 +365,9 @@ pub(crate) async fn get_batch_proof_circuit_input_from_commitments<
let mut witnesses = vec![];
let start_l2 = sequencer_commitment.l2_start_block_number;
let end_l2 = sequencer_commitment.l2_end_block_number;
let soft_confirmations_in_commitment = match ledger_db
.get_soft_confirmation_range(&(BatchNumber(start_l2)..=BatchNumber(end_l2)))
{
let soft_confirmations_in_commitment = match ledger_db.get_soft_confirmation_range(
&(SoftConfirmationNumber(start_l2)..=SoftConfirmationNumber(end_l2)),
) {
Ok(soft_confirmations) => soft_confirmations,
Err(e) => {
return Err(anyhow!(
Expand Down Expand Up @@ -450,14 +450,13 @@ pub(crate) fn break_sequencer_commitments_into_groups<DB: BatchProverLedgerOps>(
for l2_height in
sequencer_commitment.l2_start_block_number..=sequencer_commitment.l2_end_block_number
{
let state_diff =
ledger_db
.get_l2_state_diff(BatchNumber(l2_height))?
.ok_or(anyhow!(
"Could not find state diff for L2 range {}-{}",
sequencer_commitment.l2_start_block_number,
sequencer_commitment.l2_end_block_number
))?;
let state_diff = ledger_db
.get_l2_state_diff(SoftConfirmationNumber(l2_height))?
.ok_or(anyhow!(
"Could not find state diff for L2 range {}-{}",
sequencer_commitment.l2_start_block_number,
sequencer_commitment.l2_end_block_number
))?;
sequencer_commitment_state_diff =
merge_state_diffs(sequencer_commitment_state_diff, state_diff);
}
Expand Down
9 changes: 6 additions & 3 deletions crates/batch-prover/src/proving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use citrea_primitives::forks::fork_from_block_number;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use sov_db::ledger_db::BatchProverLedgerOps;
use sov_db::schema::types::{BatchNumber, StoredBatchProof, StoredBatchProofOutput};
use sov_db::schema::types::{SoftConfirmationNumber, StoredBatchProof, StoredBatchProofOutput};
use sov_modules_api::{BatchProofCircuitOutput, BlobReaderTrait, SlotData, SpecId, Zkvm};
use sov_rollup_interface::da::{BlockHeaderTrait, DaNamespace, DaSpec, SequencerCommitment};
use sov_rollup_interface::rpc::SoftConfirmationStatus;
Expand Down Expand Up @@ -164,7 +164,7 @@ where
.expect("There should be a state root");

let initial_batch_hash = ledger
.get_soft_confirmation_by_number(&BatchNumber(first_l2_height_of_l1))
.get_soft_confirmation_by_number(&SoftConfirmationNumber(first_l2_height_of_l1))
.map_err(|e| {
L1ProcessingError::Other(format!("Error getting initial batch hash: {:?}", e))
})?
Expand Down Expand Up @@ -388,7 +388,10 @@ pub(crate) fn save_commitments<DB>(
let l2_end_height = sequencer_commitment.l2_end_block_number;
for i in l2_start_height..=l2_end_height {
ledger_db
.put_soft_confirmation_status(BatchNumber(i), SoftConfirmationStatus::Proven)
.put_soft_confirmation_status(
SoftConfirmationNumber(i),
SoftConfirmationStatus::Proven,
)
.unwrap_or_else(|_| {
panic!(
"Failed to put soft confirmation status in the ledger db {}",
Expand Down
16 changes: 7 additions & 9 deletions crates/batch-prover/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use jsonrpsee::http_client::{HttpClient, HttpClientBuilder};
use jsonrpsee::server::{BatchRequestConfig, ServerBuilder};
use jsonrpsee::RpcModule;
use sov_db::ledger_db::BatchProverLedgerOps;
use sov_db::schema::types::{BatchNumber, SlotNumber};
use sov_db::schema::types::{SlotNumber, SoftConfirmationNumber};
use sov_ledger_rpc::LedgerRpcClient;
use sov_modules_api::{Context, SignedSoftConfirmation, SlotData, Spec};
use sov_modules_stf_blueprint::{Runtime, StfBlueprint};
Expand Down Expand Up @@ -130,12 +130,8 @@ where
}
};

// Start the main rollup loop
let item_numbers = ledger_db.get_next_items_numbers();
let last_soft_confirmation_processed_before_shutdown =
item_numbers.soft_confirmation_number;
// Last L1/L2 height before shutdown.
let start_l2_height = last_soft_confirmation_processed_before_shutdown;
let start_l2_height = ledger_db.get_head_soft_confirmation_height()?.unwrap_or(0) + 1;

Ok(Self {
start_l2_height,
Expand Down Expand Up @@ -446,8 +442,10 @@ where
}

// Save state diff to ledger DB
self.ledger_db
.set_l2_state_diff(BatchNumber(l2_height), soft_confirmation_result.state_diff)?;
self.ledger_db.set_l2_state_diff(
SoftConfirmationNumber(l2_height),
soft_confirmation_result.state_diff,
)?;

// Save witnesses data to ledger db
self.ledger_db.set_l2_witness(
Expand All @@ -472,7 +470,7 @@ where

self.ledger_db.extend_l2_range_of_l1_slot(
SlotNumber(current_l1_block.header().height()),
BatchNumber(l2_height),
SoftConfirmationNumber(l2_height),
)?;

// Register this new block with the fork manager to active
Expand Down
9 changes: 5 additions & 4 deletions crates/common/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use jsonrpsee::types::error::{INTERNAL_ERROR_CODE, INTERNAL_ERROR_MSG};
use jsonrpsee::types::{ErrorObjectOwned, Request};
use jsonrpsee::{MethodResponse, RpcModule};
use sov_db::ledger_db::{LedgerDB, SharedLedgerOps};
use sov_db::schema::types::BatchNumber;
use sov_db::schema::types::SoftConfirmationNumber;
use tower_http::cors::{Any, CorsLayer};

// Exit early if head_batch_num is below this threshold
Expand All @@ -33,7 +33,7 @@ pub fn register_healthcheck_rpc<T: Send + Sync + 'static>(
)
};

let Some((BatchNumber(head_batch_num), _)) = ledger_db
let Some((SoftConfirmationNumber(head_batch_num), _)) = ledger_db
.get_head_soft_confirmation()
.map_err(|err| error(&format!("Failed to get head soft batch: {}", err)))?
else {
Expand All @@ -47,7 +47,8 @@ pub fn register_healthcheck_rpc<T: Send + Sync + 'static>(

let soft_batches = ledger_db
.get_soft_confirmation_range(
&(BatchNumber(head_batch_num - 1)..=BatchNumber(head_batch_num)),
&(SoftConfirmationNumber(head_batch_num - 1)
..=SoftConfirmationNumber(head_batch_num)),
)
.map_err(|err| error(&format!("Failed to get soft batch range: {}", err)))?;

Expand All @@ -58,7 +59,7 @@ pub fn register_healthcheck_rpc<T: Send + Sync + 'static>(
.get_head_soft_confirmation()
.map_err(|err| error(&format!("Failed to get head soft batch: {}", err)))?
.unwrap();
if new_head_batch_num > BatchNumber(head_batch_num) {
if new_head_batch_num > SoftConfirmationNumber(head_batch_num) {
Ok::<(), ErrorObjectOwned>(())
} else {
Err(error("Block number is not increasing"))
Expand Down
10 changes: 6 additions & 4 deletions crates/common/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet};

use sov_db::ledger_db::SharedLedgerOps;
use sov_db::schema::types::BatchNumber;
use sov_db::schema::types::SoftConfirmationNumber;
use sov_modules_api::{Context, Spec};
use sov_rollup_interface::da::{DaSpec, SequencerCommitment};
use sov_rollup_interface::digest::Digest;
Expand Down Expand Up @@ -53,8 +53,9 @@ fn filter_out_commitments_by_status<DB: SharedLedgerOps>(
visited_l2_ranges.insert(current_range);

// Check if the commitment was previously finalized.
let Some(status) = ledger_db
.get_soft_confirmation_status(BatchNumber(sequencer_commitment.l2_end_block_number))?
let Some(status) = ledger_db.get_soft_confirmation_status(SoftConfirmationNumber(
sequencer_commitment.l2_end_block_number,
))?
else {
filtered.push(sequencer_commitment.clone());
continue;
Expand All @@ -76,7 +77,8 @@ pub fn check_l2_range_exists<DB: SharedLedgerOps>(
last_l2_height_of_l1: u64,
) -> bool {
if let Ok(range) = ledger_db.get_soft_confirmation_range(
&(BatchNumber(first_l2_height_of_l1)..=BatchNumber(last_l2_height_of_l1)),
&(SoftConfirmationNumber(first_l2_height_of_l1)
..=SoftConfirmationNumber(last_l2_height_of_l1)),
) {
if (range.len() as u64) >= (last_l2_height_of_l1 - first_l2_height_of_l1 + 1) {
return true;
Expand Down
6 changes: 4 additions & 2 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ reth-rpc-eth-types = { workspace = true, optional = true }
reth-rpc-server-types = { workspace = true, optional = true }
reth-rpc-types-compat = { workspace = true, optional = true }
reth-transaction-pool = { workspace = true, optional = true }
revm = { workspace = true, features = ["secp256k1"] }
revm = { workspace = true, default-features = false, features = ["secp256k1"] }
revm-inspectors = { workspace = true, optional = true }
secp256k1 = { workspace = true, optional = true }

Expand All @@ -64,7 +64,8 @@ rayon = { workspace = true }
reth-chainspec = { workspace = true }
reth-db = { workspace = true }
reth-errors = { workspace = true }
revm = { workspace = true, features = ["optional_block_gas_limit", "optional_eip3607", "optional_no_base_fee", "secp256k1"] }
revm = { workspace = true, default-features = false, features = ["optional_block_gas_limit", "optional_eip3607", "optional_no_base_fee", "secp256k1"] }
sha2 = { workspace = true }
sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", features = ["macros"] }
sov-prover-storage-manager = { path = "../sovereign-sdk/full-node/sov-prover-storage-manager", features = ["test-utils"] }
sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface", features = ["testing"] }
Expand All @@ -84,6 +85,7 @@ native = [
"reth-rpc-eth-api",
"reth-rpc-server-types",
"reth-rpc-types-compat",
"revm/serde",
"reth-transaction-pool",
"revm-inspectors",
"reth-provider",
Expand Down
10 changes: 4 additions & 6 deletions crates/evm/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId};
use sov_modules_api::prelude::*;
use sov_modules_api::{native_error, CallResponse, SoftConfirmationModuleCallError, WorkingSet};

use crate::conversions::ConversionError;
use crate::evm::db::EvmDb;
use crate::evm::executor::{self};
use crate::evm::handler::{CitreaExternal, CitreaExternalExt};
Expand Down Expand Up @@ -131,14 +132,11 @@ impl<C: sov_modules_api::Context> Evm<C> {
) -> Result<CallResponse, SoftConfirmationModuleCallError> {
// use of `self.block_env` is allowed here

// TODO: should not include non deserilizable transactions
let users_txs: Vec<TransactionSignedEcRecovered> = txs
.into_iter()
.filter_map(|tx| match tx.try_into() {
Ok(tx) => Some(tx),
Err(_) => None,
})
.collect();
.map(|tx| tx.try_into())
.collect::<Result<Vec<_>, ConversionError>>()
.map_err(|_| SoftConfirmationModuleCallError::EvmTxNotSerializable)?;

let cfg = self.cfg.get(working_set).expect("Evm config must be set");
let active_evm_spec = citrea_spec_id_to_evm_spec_id(context.active_spec());
Expand Down
21 changes: 19 additions & 2 deletions crates/evm/src/evm/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use revm::handler::register::{EvmHandler, HandleRegisters};
#[cfg(feature = "native")]
use revm::interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter};
use revm::interpreter::{Gas, InstructionResult};
use revm::precompile::u64_to_address;
#[cfg(feature = "native")]
use revm::primitives::Log;
use revm::primitives::{
spec_to_generic, Address, EVMError, Env, HandlerCfg, InvalidTransaction, ResultAndState, Spec,
SpecId, B256, U256,
};
use revm::{Context, Database, FrameResult, InnerEvmContext, JournalEntry};
use revm::{Context, ContextPrecompiles, Database, FrameResult, InnerEvmContext, JournalEntry};
#[cfg(feature = "native")]
use revm::{EvmContext, Inspector};
use sov_modules_api::{native_debug, native_error, native_warn};
Expand Down Expand Up @@ -290,7 +291,7 @@ where
// validation.env =
validation.tx_against_state =
Arc::new(CitreaHandler::<SPEC, EXT, DB>::validate_tx_against_state);
// pre_execution.load_accounts =
pre_execution.load_precompiles = Arc::new(CitreaHandler::<SPEC, EXT, DB>::load_precompiles);
// pre_execution.load_accounts =
pre_execution.deduct_caller = Arc::new(CitreaHandler::<SPEC, EXT, DB>::deduct_caller);
// execution.last_frame_return =
Expand All @@ -314,6 +315,22 @@ struct CitreaHandler<SPEC, EXT, DB> {
}

impl<SPEC: Spec, EXT: CitreaExternalExt, DB: Database> CitreaHandler<SPEC, EXT, DB> {
fn load_precompiles() -> ContextPrecompiles<DB> {
fn our_precompiles<SPEC: Spec, DB: Database>() -> ContextPrecompiles<DB> {
let mut precompiles = revm::handler::mainnet::load_precompiles::<SPEC, DB>();

if SPEC::enabled(SpecId::CANCUN) {
precompiles
.to_mut()
.remove(&u64_to_address(0x0A))
.expect("after cancun point eval should be removed");
}

precompiles
}

our_precompiles::<SPEC, DB>()
}
fn validate_tx_against_state(
context: &mut Context<EXT, DB>,
) -> Result<(), EVMError<DB::Error>> {
Expand Down
1 change: 1 addition & 0 deletions crates/evm/src/evm/test_data/KZGPointEvaluationCaller.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"bytes","name":"input","type":"bytes"}],"name":"verifyPointEvaluation","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
Loading

0 comments on commit 090bd53

Please sign in to comment.