From bfb9e87d490d314e6de7281d7bd91d8fc0431718 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Wed, 28 Aug 2024 17:43:39 +0300 Subject: [PATCH 01/17] rename SignedSoftConfirmationBatch to SignedSoftConfirmation --- crates/fullnode/tests/hash_stf.rs | 10 +++++----- crates/prover/src/runner.rs | 8 ++++---- crates/sequencer-client/src/lib.rs | 6 +++--- crates/sequencer/src/sequencer.rs | 12 ++++++------ .../src/tests/hooks_tests.rs | 12 ++++++------ .../src/tests/query_tests.rs | 10 +++++----- .../examples/demo-simple-stf/src/lib.rs | 6 +++--- .../full-node/db/sov-db/src/schema/types.rs | 6 +++--- .../full-node/sov-stf-runner/src/mock/mod.rs | 4 ++-- .../module-system/sov-modules-api/src/hooks.rs | 8 ++++---- .../module-system/sov-modules-api/src/lib.rs | 2 +- .../sov-modules-stf-blueprint/src/lib.rs | 18 +++++++++--------- .../src/stf_blueprint.rs | 8 ++++---- .../src/state_machine/soft_confirmation.rs | 8 ++++---- .../rollup-interface/src/state_machine/stf.rs | 6 +++--- .../src/state_machine/zk/mod.rs | 4 ++-- 16 files changed, 64 insertions(+), 64 deletions(-) diff --git a/crates/fullnode/tests/hash_stf.rs b/crates/fullnode/tests/hash_stf.rs index 3b3cfd778..7eb3e4091 100644 --- a/crates/fullnode/tests/hash_stf.rs +++ b/crates/fullnode/tests/hash_stf.rs @@ -81,7 +81,7 @@ impl StfBlueprintTrai _pre_state: Self::PreState, _witness: <::Storage as Storage>::Witness, _slot_header: &::BlockHeader, - _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmationBatch, + _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmation, ) -> ( Result<(), SoftConfirmationError>, sov_modules_api::WorkingSet, @@ -105,7 +105,7 @@ impl StfBlueprintTrai &self, _current_spec: SpecId, _sequencer_public_key: &[u8], - _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmationBatch, + _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmation, _tx_receipts: Vec< sov_modules_stf_blueprint::TransactionReceipt, >, @@ -126,7 +126,7 @@ impl StfBlueprintTrai _sc_receipt: SoftConfirmationReceipt, _checkpoint: sov_modules_api::StateCheckpoint, _pre_state: Self::PreState, - _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmationBatch, + _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmation, ) -> SoftConfirmationResult< Self::StateRoot, Self::ChangeSet, @@ -222,7 +222,7 @@ impl StateTransitionFunction::BlockHeader, _validity_condition: &::ValidityCondition, - _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmationBatch, + _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmation, ) -> Result< SoftConfirmationResult< Self::StateRoot, @@ -249,7 +249,7 @@ impl StateTransitionFunction::BlockHeader>>, _validity_condition: &::ValidityCondition, _soft_confirmations: std::collections::VecDeque< - Vec, + Vec, >, _preproven_commitment_indicies: Vec, _forks: Vec, diff --git a/crates/prover/src/runner.rs b/crates/prover/src/runner.rs index db56fe3a8..e3d4c6374 100644 --- a/crates/prover/src/runner.rs +++ b/crates/prover/src/runner.rs @@ -20,7 +20,7 @@ use sequencer_client::{GetSoftConfirmationResponse, SequencerClient}; use sov_db::ledger_db::ProverLedgerOps; use sov_db::schema::types::{BatchNumber, SlotNumber, StoredStateTransition}; use sov_modules_api::storage::HierarchicalStorageManager; -use sov_modules_api::{BlobReaderTrait, Context, SignedSoftConfirmationBatch, SlotData, StateDiff}; +use sov_modules_api::{BlobReaderTrait, Context, SignedSoftConfirmation, SlotData, StateDiff}; use sov_modules_stf_blueprint::StfBlueprintTrait; use sov_rollup_interface::da::{BlockHeaderTrait, DaData, DaSpec, SequencerCommitment}; use sov_rollup_interface::rpc::SoftConfirmationStatus; @@ -40,7 +40,7 @@ type StateRoot = >::StateRoot; type CommitmentStateTransitionData = ( VecDeque::Spec>>::Witness>>, - VecDeque>, + VecDeque>, VecDeque::Spec as DaSpec>::BlockHeader>>, ); @@ -648,7 +648,7 @@ where let mut state_transition_witnesses: VecDeque< Vec<::Spec>>::Witness>, > = VecDeque::new(); - let mut soft_confirmations: VecDeque> = VecDeque::new(); + let mut soft_confirmations: VecDeque> = VecDeque::new(); let mut da_block_headers_of_soft_confirmations: VecDeque< Vec<<::Spec as DaSpec>::BlockHeader>, > = VecDeque::new(); @@ -695,7 +695,7 @@ where }; da_block_headers_to_push.push(filtered_block.header().clone()); } - let signed_soft_confirmation: SignedSoftConfirmationBatch = + let signed_soft_confirmation: SignedSoftConfirmation = soft_confirmation.clone().into(); commitment_soft_confirmations.push(signed_soft_confirmation.clone()); } diff --git a/crates/sequencer-client/src/lib.rs b/crates/sequencer-client/src/lib.rs index e2e20edee..3a1e198d1 100644 --- a/crates/sequencer-client/src/lib.rs +++ b/crates/sequencer-client/src/lib.rs @@ -7,7 +7,7 @@ use jsonrpsee::rpc_params; use reth_primitives::{Bytes, B256}; use serde::Deserialize; use sov_rollup_interface::rpc::HexTx; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmationBatch; +use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use tracing::instrument; /// Configuration for SequencerClient. @@ -126,9 +126,9 @@ pub struct GetSoftConfirmationResponse { pub timestamp: u64, } -impl From for SignedSoftConfirmationBatch { +impl From for SignedSoftConfirmation { fn from(val: GetSoftConfirmationResponse) -> Self { - SignedSoftConfirmationBatch::new( + SignedSoftConfirmation::new( val.hash, val.prev_hash, val.da_slot_height, diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index dee3fd4ca..bddb024ce 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -35,8 +35,8 @@ use sov_db::schema::types::{BatchNumber, SlotNumber}; use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::transaction::Transaction; use sov_modules_api::{ - BlobReaderTrait, Context, EncodeCall, PrivateKey, SignedSoftConfirmationBatch, SlotData, - StateDiff, UnsignedSoftConfirmationBatch, WorkingSet, + BlobReaderTrait, Context, EncodeCall, PrivateKey, SignedSoftConfirmation, SlotData, StateDiff, + UnsignedSoftConfirmationBatch, WorkingSet, }; use sov_modules_stf_blueprint::StfBlueprintTrait; use sov_rollup_interface::da::{BlockHeaderTrait, DaData, DaSpec, SequencerCommitment}; @@ -267,7 +267,7 @@ where pub_key: &[u8], prestate: ::Spec>>::NativeStorage, da_block_header: <::Spec as DaSpec>::BlockHeader, - mut signed_batch: SignedSoftConfirmationBatch, + mut signed_batch: SignedSoftConfirmation, l2_block_mode: L2BlockMode, ) -> anyhow::Result<(Vec, Vec)> { let active_fork_spec = self.fork_manager.active_fork().spec_id; @@ -400,7 +400,7 @@ where timestamp, }; // initially create sc info and call begin soft confirmation hook with it - let mut signed_batch: SignedSoftConfirmationBatch = batch_info.clone().into(); + let mut signed_batch: SignedSoftConfirmation = batch_info.clone().into(); let prestate = self .storage_manager @@ -1070,14 +1070,14 @@ where &mut self, soft_confirmation: UnsignedSoftConfirmationBatch, prev_soft_confirmation_hash: [u8; 32], - ) -> anyhow::Result { + ) -> anyhow::Result { let raw = borsh::to_vec(&soft_confirmation).map_err(|e| anyhow!(e))?; let hash = ::Hasher::digest(raw.as_slice()).into(); let signature = self.sov_tx_signer_priv_key.sign(&raw); let pub_key = self.sov_tx_signer_priv_key.pub_key(); - Ok(SignedSoftConfirmationBatch::new( + Ok(SignedSoftConfirmation::new( hash, prev_soft_confirmation_hash, soft_confirmation.da_slot_height(), diff --git a/crates/soft-confirmation-rule-enforcer/src/tests/hooks_tests.rs b/crates/soft-confirmation-rule-enforcer/src/tests/hooks_tests.rs index f4c85f841..b3dfb9985 100644 --- a/crates/soft-confirmation-rule-enforcer/src/tests/hooks_tests.rs +++ b/crates/soft-confirmation-rule-enforcer/src/tests/hooks_tests.rs @@ -5,7 +5,7 @@ use sov_modules_api::default_context::DefaultContext; use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::utils::generate_address; use sov_modules_api::{Context, Module, Spec}; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmationBatch; +use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::spec::SpecId; use crate::call::CallMessage; @@ -34,7 +34,7 @@ fn begin_soft_confirmation_hook_checks_max_l2_blocks_per_l1() { .call(call_message, &context, &mut working_set) .unwrap(); - let signed_soft_confirmation_batch = SignedSoftConfirmationBatch::new( + let signed_soft_confirmation_batch = SignedSoftConfirmation::new( [0; 32], [0; 32], 0, @@ -72,7 +72,7 @@ fn begin_soft_confirmation_hook_checks_l1_fee_rate() { let (soft_confirmation_rule_enforcer, mut working_set) = get_soft_confirmation_rule_enforcer::(&TEST_CONFIG); - let mut signed_soft_confirmation_batch = SignedSoftConfirmationBatch::new( + let mut signed_soft_confirmation_batch = SignedSoftConfirmation::new( [0; 32], [0; 32], 0, @@ -240,7 +240,7 @@ fn begin_soft_confirmation_hook_checks_timestamp() { let original_timestamp = chrono::Local::now().timestamp() as u64; - let signed_soft_confirmation_batch = SignedSoftConfirmationBatch::new( + let signed_soft_confirmation_batch = SignedSoftConfirmation::new( [0; 32], [0; 32], 0, @@ -268,7 +268,7 @@ fn begin_soft_confirmation_hook_checks_timestamp() { // now call with a timestamp before the original one. // should fail - let signed_soft_confirmation_batch = SignedSoftConfirmationBatch::new( + let signed_soft_confirmation_batch = SignedSoftConfirmation::new( [0; 32], [0; 32], 0, @@ -300,7 +300,7 @@ fn begin_soft_confirmation_hook_checks_timestamp() { // now call with a timestamp after the original one. // should fail - let signed_soft_confirmation_batch = SignedSoftConfirmationBatch::new( + let signed_soft_confirmation_batch = SignedSoftConfirmation::new( [0; 32], [0; 32], 0, diff --git a/crates/soft-confirmation-rule-enforcer/src/tests/query_tests.rs b/crates/soft-confirmation-rule-enforcer/src/tests/query_tests.rs index dabb8e64a..e5e557a50 100644 --- a/crates/soft-confirmation-rule-enforcer/src/tests/query_tests.rs +++ b/crates/soft-confirmation-rule-enforcer/src/tests/query_tests.rs @@ -1,7 +1,7 @@ use sov_mock_da::MockDaSpec; use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::StateMapAccessor; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmationBatch; +use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::spec::SpecId; use crate::tests::genesis_tests::{get_soft_confirmation_rule_enforcer, TEST_CONFIG}; @@ -11,7 +11,7 @@ fn block_count_per_da_hash_must_be_correct() { let (soft_confirmation_rule_enforcer, mut working_set) = get_soft_confirmation_rule_enforcer::(&TEST_CONFIG); - let mut signed_soft_confirmation_batch = SignedSoftConfirmationBatch::new( + let mut signed_soft_confirmation_batch = SignedSoftConfirmation::new( [0; 32], [0; 32], 0, @@ -81,7 +81,7 @@ fn get_max_l1_fee_rate_change_percentage_must_be_correct() { 10 ); - let signed_soft_confirmation_batch = SignedSoftConfirmationBatch::new( + let signed_soft_confirmation_batch = SignedSoftConfirmation::new( [0; 32], [0; 32], 0, @@ -127,7 +127,7 @@ fn get_last_l1_fee_rate_must_be_correct() { 0 ); - let signed_soft_confirmation_batch = SignedSoftConfirmationBatch::new( + let signed_soft_confirmation_batch = SignedSoftConfirmation::new( [0; 32], [0; 32], 0, @@ -173,7 +173,7 @@ fn get_last_timestamp_must_be_correct() { ); let timestamp = chrono::Local::now().timestamp() as u64; - let signed_soft_confirmation_batch = SignedSoftConfirmationBatch::new( + let signed_soft_confirmation_batch = SignedSoftConfirmation::new( [0; 32], [0; 32], 0, diff --git a/crates/sovereign-sdk/examples/demo-simple-stf/src/lib.rs b/crates/sovereign-sdk/examples/demo-simple-stf/src/lib.rs index b27ea0f1e..c52950dad 100644 --- a/crates/sovereign-sdk/examples/demo-simple-stf/src/lib.rs +++ b/crates/sovereign-sdk/examples/demo-simple-stf/src/lib.rs @@ -5,7 +5,7 @@ use std::marker::PhantomData; use sha2::Digest; use sov_rollup_interface::da::{BlobReaderTrait, DaSpec}; use sov_rollup_interface::fork::Fork; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmationBatch; +use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::spec::SpecId; use sov_rollup_interface::stf::{ BatchReceipt, SlotResult, SoftConfirmationError, SoftConfirmationResult, @@ -125,7 +125,7 @@ impl StateTransitionFunction::BlockHeader, _validity_condition: &::ValidityCondition, - _soft_confirmation: &mut SignedSoftConfirmationBatch, + _soft_confirmation: &mut SignedSoftConfirmation, ) -> Result< SoftConfirmationResult< Self::StateRoot, @@ -151,7 +151,7 @@ impl StateTransitionFunction>, _slot_headers: std::collections::VecDeque::BlockHeader>>, _validity_condition: &::ValidityCondition, - _soft_confirmation: std::collections::VecDeque>, + _soft_confirmation: std::collections::VecDeque>, _preproven_commitment_indicies: Vec, _forks: Vec, ) -> (Self::StateRoot, CumulativeStateDiff, SpecId) { diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs index 28aa93095..b9ffc40e1 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs @@ -8,7 +8,7 @@ use sov_rollup_interface::rpc::{ HexTx, ProofResponse, ProofRpcResponse, SoftConfirmationResponse, StateTransitionRpcResponse, TxIdentifier, TxResponse, VerifiedProofResponse, }; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmationBatch; +use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::stf::{Event, EventKey, TransactionReceipt}; use sov_rollup_interface::zk::{CumulativeStateDiff, Proof}; @@ -194,9 +194,9 @@ pub struct StoredSoftConfirmation { pub timestamp: u64, } -impl From for SignedSoftConfirmationBatch { +impl From for SignedSoftConfirmation { fn from(value: StoredSoftConfirmation) -> Self { - SignedSoftConfirmationBatch::new( + SignedSoftConfirmation::new( value.hash, value.prev_hash, value.da_slot_height, diff --git a/crates/sovereign-sdk/full-node/sov-stf-runner/src/mock/mod.rs b/crates/sovereign-sdk/full-node/sov-stf-runner/src/mock/mod.rs index 26d5dd8cc..c5b90bebb 100644 --- a/crates/sovereign-sdk/full-node/sov-stf-runner/src/mock/mod.rs +++ b/crates/sovereign-sdk/full-node/sov-stf-runner/src/mock/mod.rs @@ -78,7 +78,7 @@ impl StateTransitionFunction::BlockHeader, _validity_condition: &::ValidityCondition, - _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmationBatch, + _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmation, ) -> Result< SoftConfirmationResult< Self::StateRoot, @@ -105,7 +105,7 @@ impl StateTransitionFunction::BlockHeader>>, _validity_condition: &::ValidityCondition, _soft_confirmations: std::collections::VecDeque< - Vec, + Vec, >, _preproven_commitment_indicies: Vec, _forks: Vec, diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs index cff6dc38d..862dd0a3a 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs @@ -2,7 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use sov_modules_core::{AccessoryWorkingSet, Context, Spec, Storage, WorkingSet}; use sov_rollup_interface::da::{BlobReaderTrait, DaSpec}; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmationBatch; +use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::spec::SpecId; pub use sov_rollup_interface::stf::SoftConfirmationError; @@ -103,7 +103,7 @@ pub struct HookSoftConfirmationInfo { impl HookSoftConfirmationInfo { pub fn new( - signed_soft_confirmation: SignedSoftConfirmationBatch, + signed_soft_confirmation: SignedSoftConfirmation, pre_state_root: Vec, current_spec: SpecId, ) -> Self { @@ -121,9 +121,9 @@ impl HookSoftConfirmationInfo { } } -impl From for SignedSoftConfirmationBatch { +impl From for SignedSoftConfirmation { fn from(val: HookSoftConfirmationInfo) -> Self { - SignedSoftConfirmationBatch::new( + SignedSoftConfirmation::new( [0u8; 32], [0u8; 32], val.da_slot_height, diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs index d934b5974..b954a63ff 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs @@ -190,7 +190,7 @@ pub use sov_modules_core::{ pub use sov_rollup_interface::da::{BlobReaderTrait, DaSpec}; pub use sov_rollup_interface::services::da::SlotData; pub use sov_rollup_interface::soft_confirmation::{ - SignedSoftConfirmationBatch, UnsignedSoftConfirmationBatch, + SignedSoftConfirmation, UnsignedSoftConfirmationBatch, }; pub use sov_rollup_interface::stf::{Event, StateDiff}; pub use sov_rollup_interface::zk::{ diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs index 5d16549ee..a2a27767f 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs @@ -17,7 +17,7 @@ use sov_modules_api::{ use sov_rollup_interface::da::{DaData, SequencerCommitment}; use sov_rollup_interface::digest::Digest; use sov_rollup_interface::fork::Fork; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmationBatch; +use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::spec::SpecId; pub use sov_rollup_interface::stf::{BatchReceipt, TransactionReceipt}; use sov_rollup_interface::stf::{ @@ -144,7 +144,7 @@ pub trait StfBlueprintTrait: pre_state: Self::PreState, witness: <::Storage as Storage>::Witness, slot_header: &::BlockHeader, - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, ) -> (Result<(), SoftConfirmationError>, WorkingSet); /// Apply soft confirmation transactions @@ -160,7 +160,7 @@ pub trait StfBlueprintTrait: &self, current_spec: SpecId, sequencer_public_key: &[u8], - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, tx_receipts: Vec>, batch_workspace: WorkingSet, ) -> ( @@ -175,7 +175,7 @@ pub trait StfBlueprintTrait: sc_receipt: SoftConfirmationReceipt, checkpoint: StateCheckpoint, pre_state: Self::PreState, - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, ) -> SoftConfirmationResult< Self::StateRoot, Self::ChangeSet, @@ -200,7 +200,7 @@ where pre_state: ::Storage, witness: <::Storage as Storage>::Witness, slot_header: &::BlockHeader, - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, ) -> (Result<(), SoftConfirmationError>, WorkingSet) { native_debug!("Applying soft confirmation in STF Blueprint"); @@ -249,7 +249,7 @@ where &self, _current_spec: SpecId, sequencer_public_key: &[u8], - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, tx_receipts: Vec>, batch_workspace: WorkingSet, ) -> ( @@ -301,7 +301,7 @@ where sc_receipt: SoftConfirmationReceipt, checkpoint: StateCheckpoint, pre_state: Self::PreState, - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, ) -> SoftConfirmationResult< ::Root, C::Storage, @@ -445,7 +445,7 @@ where witness: Self::Witness, slot_header: &::BlockHeader, _validity_condition: &::ValidityCondition, - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, ) -> Result< SoftConfirmationResult< Self::StateRoot, @@ -518,7 +518,7 @@ where witnesses: std::collections::VecDeque>, slot_headers: std::collections::VecDeque::BlockHeader>>, validity_condition: &::ValidityCondition, - soft_confirmations: std::collections::VecDeque>, + soft_confirmations: std::collections::VecDeque>, mut preproven_commitment_indicies: Vec, forks: Vec, ) -> (Self::StateRoot, CumulativeStateDiff, SpecId) { diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index 7248c6c2f..613f6656f 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -4,7 +4,7 @@ use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::{ native_debug, native_error, Context, DaSpec, DispatchCall, StateCheckpoint, WorkingSet, }; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmationBatch; +use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::spec::SpecId; use sov_rollup_interface::stf::{ SoftConfirmationError, SoftConfirmationReceipt, TransactionReceipt, @@ -164,7 +164,7 @@ where pub fn begin_soft_confirmation_inner( &self, mut batch_workspace: WorkingSet, - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, pre_state_root: &::Root, current_spec: SpecId, ) -> (Result<(), SoftConfirmationError>, WorkingSet) { @@ -206,7 +206,7 @@ where #[cfg_attr(feature = "native", instrument(level = "trace", skip_all))] pub fn end_soft_confirmation_inner( &self, - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, tx_receipts: Vec>, mut batch_workspace: WorkingSet, ) -> (ApplySoftConfirmationResult, StateCheckpoint) { @@ -242,7 +242,7 @@ where pub(crate) fn _apply_soft_confirmation_inner( &self, checkpoint: StateCheckpoint, - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, pre_state_root: &::Root, current_spec: SpecId, ) -> (ApplySoftConfirmationResult, StateCheckpoint) { diff --git a/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs b/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs index 6d43dd93b..f4372d769 100644 --- a/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs +++ b/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs @@ -73,10 +73,10 @@ impl UnsignedSoftConfirmationBatch { } } -/// Signed version of the `UnsignedSoftConfirmationBatch` +/// Signed version of the `UnsignedSoftConfirmation` /// Contains the signature and public key of the sequencer #[derive(Debug, PartialEq, Clone, BorshDeserialize, BorshSerialize, Serialize, Deserialize, Eq)] -pub struct SignedSoftConfirmationBatch { +pub struct SignedSoftConfirmation { hash: [u8; 32], prev_hash: [u8; 32], da_slot_height: u64, @@ -90,7 +90,7 @@ pub struct SignedSoftConfirmationBatch { timestamp: u64, } -impl SignedSoftConfirmationBatch { +impl SignedSoftConfirmation { /// Creates a signed soft confirmation batch #[allow(clippy::too_many_arguments)] pub fn new( @@ -105,7 +105,7 @@ impl SignedSoftConfirmationBatch { signature: Vec, pub_key: Vec, timestamp: u64, - ) -> SignedSoftConfirmationBatch { + ) -> SignedSoftConfirmation { Self { hash, prev_hash, diff --git a/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs b/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs index 15c2f6058..568708144 100644 --- a/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs +++ b/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs @@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize}; use crate::da::DaSpec; use crate::fork::Fork; -use crate::soft_confirmation::SignedSoftConfirmationBatch; +use crate::soft_confirmation::SignedSoftConfirmation; use crate::spec::SpecId; use crate::zk::{CumulativeStateDiff, ValidityCondition, Zkvm}; @@ -259,7 +259,7 @@ pub trait StateTransitionFunction { witness: Self::Witness, slot_header: &Da::BlockHeader, validity_condition: &Da::ValidityCondition, - soft_confirmation: &mut SignedSoftConfirmationBatch, + soft_confirmation: &mut SignedSoftConfirmation, ) -> Result< SoftConfirmationResult< Self::StateRoot, @@ -288,7 +288,7 @@ pub trait StateTransitionFunction { witnesses: VecDeque>, slot_headers: VecDeque>, validity_condition: &Da::ValidityCondition, - soft_confirmations: VecDeque>, + soft_confirmations: VecDeque>, preproven_commitment_indicies: Vec, forks: Vec, ) -> (Self::StateRoot, CumulativeStateDiff, SpecId); diff --git a/crates/sovereign-sdk/rollup-interface/src/state_machine/zk/mod.rs b/crates/sovereign-sdk/rollup-interface/src/state_machine/zk/mod.rs index e495fd944..58c5c0bb7 100644 --- a/crates/sovereign-sdk/rollup-interface/src/state_machine/zk/mod.rs +++ b/crates/sovereign-sdk/rollup-interface/src/state_machine/zk/mod.rs @@ -20,7 +20,7 @@ use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use crate::da::DaSpec; -use crate::soft_confirmation::SignedSoftConfirmationBatch; +use crate::soft_confirmation::SignedSoftConfirmation; use crate::spec::SpecId; /// The ZK proof generated by the [`ZkvmHost::run`] method. @@ -190,7 +190,7 @@ pub struct StateTransitionData { /// Pre-proven commitments L2 ranges which also exist in the current L1 `da_data`. pub preproven_commitments: Vec, /// The soft confirmations that are inside the sequencer commitments. - pub soft_confirmations: VecDeque>, + pub soft_confirmations: VecDeque>, /// Corresponding witness for the soft confirmations. pub state_transition_witnesses: VecDeque>, /// DA block headers the soft confirmations was constructed on. From b49d49799a350537d014c52910e66ab1902fb0a4 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Wed, 28 Aug 2024 17:44:45 +0300 Subject: [PATCH 02/17] rename UnignedSoftConfirmationBatch to UnsignedSoftConfirmation --- crates/sequencer/src/sequencer.rs | 6 +++--- .../sovereign-sdk/module-system/sov-modules-api/src/lib.rs | 2 +- .../module-system/sov-modules-stf-blueprint/src/lib.rs | 6 +++--- .../rollup-interface/src/state_machine/soft_confirmation.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index bddb024ce..12acfb470 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -36,7 +36,7 @@ use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::transaction::Transaction; use sov_modules_api::{ BlobReaderTrait, Context, EncodeCall, PrivateKey, SignedSoftConfirmation, SlotData, StateDiff, - UnsignedSoftConfirmationBatch, WorkingSet, + UnsignedSoftConfirmation, WorkingSet, }; use sov_modules_stf_blueprint::StfBlueprintTrait; use sov_rollup_interface::da::{BlockHeaderTrait, DaData, DaSpec, SequencerCommitment}; @@ -466,7 +466,7 @@ where } // create the unsigned batch with the txs then sign th sc - let unsigned_batch = UnsignedSoftConfirmationBatch::new( + let unsigned_batch = UnsignedSoftConfirmation::new( da_block.header().height(), da_block.header().hash().into(), da_block.header().txs_commitment().into(), @@ -1068,7 +1068,7 @@ where /// Signs necessary info and returns a BlockTemplate fn sign_soft_confirmation_batch( &mut self, - soft_confirmation: UnsignedSoftConfirmationBatch, + soft_confirmation: UnsignedSoftConfirmation, prev_soft_confirmation_hash: [u8; 32], ) -> anyhow::Result { let raw = borsh::to_vec(&soft_confirmation).map_err(|e| anyhow!(e))?; diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs index b954a63ff..5a3bcbd36 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs @@ -190,7 +190,7 @@ pub use sov_modules_core::{ pub use sov_rollup_interface::da::{BlobReaderTrait, DaSpec}; pub use sov_rollup_interface::services::da::SlotData; pub use sov_rollup_interface::soft_confirmation::{ - SignedSoftConfirmation, UnsignedSoftConfirmationBatch, + SignedSoftConfirmation, UnsignedSoftConfirmation, }; pub use sov_rollup_interface::stf::{Event, StateDiff}; pub use sov_rollup_interface::zk::{ diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs index a2a27767f..ce83fbc24 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs @@ -12,7 +12,7 @@ use sov_modules_api::hooks::{ }; use sov_modules_api::{ native_debug, native_warn, BasicAddress, BlobReaderTrait, Context, DaSpec, DispatchCall, - Genesis, Signature, Spec, StateCheckpoint, UnsignedSoftConfirmationBatch, WorkingSet, Zkvm, + Genesis, Signature, Spec, StateCheckpoint, UnsignedSoftConfirmation, WorkingSet, Zkvm, }; use sov_rollup_interface::da::{DaData, SequencerCommitment}; use sov_rollup_interface::digest::Digest; @@ -256,7 +256,7 @@ where Result, SoftConfirmationError>, StateCheckpoint, ) { - let unsigned = UnsignedSoftConfirmationBatch::new( + let unsigned = UnsignedSoftConfirmation::new( soft_confirmation.da_slot_height(), soft_confirmation.da_slot_hash(), soft_confirmation.da_slot_txs_commitment(), @@ -754,7 +754,7 @@ where } fn verify_soft_confirmation_signature( - unsigned_soft_confirmation: UnsignedSoftConfirmationBatch, + unsigned_soft_confirmation: UnsignedSoftConfirmation, signature: &[u8], sequencer_public_key: &[u8], ) -> Result<(), anyhow::Error> { diff --git a/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs b/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs index f4372d769..4571b3871 100644 --- a/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs +++ b/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize}; /// Contains raw transactions and information about the soft confirmation block #[derive(Debug, PartialEq, Clone, BorshDeserialize, BorshSerialize, Serialize, Deserialize)] -pub struct UnsignedSoftConfirmationBatch { +pub struct UnsignedSoftConfirmation { da_slot_height: u64, da_slot_hash: [u8; 32], da_slot_txs_commitment: [u8; 32], @@ -21,7 +21,7 @@ pub struct UnsignedSoftConfirmationBatch { timestamp: u64, } -impl UnsignedSoftConfirmationBatch { +impl UnsignedSoftConfirmation { #[allow(clippy::too_many_arguments)] /// Creates a new unsigned soft confirmation batch pub fn new( From d445bbabadf5a03a21fc877c1860a9348a374b1e Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Wed, 28 Aug 2024 17:57:19 +0300 Subject: [PATCH 03/17] add l2 height to soft confirmations --- bin/citrea/src/test_rpc.rs | 2 ++ crates/sequencer-client/src/lib.rs | 2 ++ crates/sequencer/src/sequencer.rs | 5 ++++- .../full-node/db/sov-db/src/schema/types.rs | 5 +++-- .../module-system/sov-modules-api/src/hooks.rs | 9 +++++++++ .../sov-modules-stf-blueprint/src/lib.rs | 1 + .../src/stf_blueprint.rs | 1 + .../rollup-interface/src/node/rpc/mod.rs | 4 ++-- .../src/state_machine/soft_confirmation.rs | 15 +++++++++++++++ .../rollup-interface/src/state_machine/stf.rs | 2 ++ 10 files changed, 41 insertions(+), 5 deletions(-) diff --git a/bin/citrea/src/test_rpc.rs b/bin/citrea/src/test_rpc.rs index 83e7c6837..6d4cac11c 100644 --- a/bin/citrea/src/test_rpc.rs +++ b/bin/citrea/src/test_rpc.rs @@ -105,6 +105,7 @@ fn batch2_tx_receipts() -> Vec> { fn regular_test_helper(payload: serde_json::Value, expected: &serde_json::Value) { let soft_confirmation_receipts = vec![ SoftConfirmationReceipt { + l2_height: 1, da_slot_height: 0, da_slot_hash: ::SlotHash::from([0u8; 32]), da_slot_txs_commitment: ::SlotHash::from([1u8; 32]), @@ -137,6 +138,7 @@ fn regular_test_helper(payload: serde_json::Value, expected: &serde_json::Value) timestamp: 0, }, SoftConfirmationReceipt { + l2_height: 2, da_slot_height: 1, da_slot_hash: ::SlotHash::from([2; 32]), da_slot_txs_commitment: ::SlotHash::from([3; 32]), diff --git a/crates/sequencer-client/src/lib.rs b/crates/sequencer-client/src/lib.rs index 3a1e198d1..45e43452e 100644 --- a/crates/sequencer-client/src/lib.rs +++ b/crates/sequencer-client/src/lib.rs @@ -104,6 +104,7 @@ impl SequencerClient { #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct GetSoftConfirmationResponse { + l2_height: u64, #[serde(with = "hex::serde")] pub hash: SoftConfirmationHash, #[serde(with = "hex::serde")] @@ -129,6 +130,7 @@ pub struct GetSoftConfirmationResponse { impl From for SignedSoftConfirmation { fn from(val: GetSoftConfirmationResponse) -> Self { SignedSoftConfirmation::new( + val.l2_height, val.hash, val.prev_hash, val.da_slot_height, diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index 12acfb470..a53ab9099 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -370,7 +370,7 @@ where .map_err(|e| anyhow!("Failed to get head soft confirmation: {}", e))? { Some((l2_height, sb)) => (l2_height.0 + 1, sb.da_slot_height), - None => (0, da_height), + None => (1, da_height), }; anyhow::ensure!( l1_height == da_height || l1_height + 1 == da_height, @@ -389,6 +389,7 @@ where let active_fork_spec = self.fork_manager.active_fork().spec_id; let batch_info = HookSoftConfirmationInfo { + l2_height, da_slot_height: da_block.header().height(), da_slot_hash: da_block.header().hash().into(), da_slot_txs_commitment: da_block.header().txs_commitment().into(), @@ -467,6 +468,7 @@ where // create the unsigned batch with the txs then sign th sc let unsigned_batch = UnsignedSoftConfirmation::new( + l2_height, da_block.header().height(), da_block.header().hash().into(), da_block.header().txs_commitment().into(), @@ -1078,6 +1080,7 @@ where let signature = self.sov_tx_signer_priv_key.sign(&raw); let pub_key = self.sov_tx_signer_priv_key.pub_key(); Ok(SignedSoftConfirmation::new( + soft_confirmation.l2_height(), hash, prev_soft_confirmation_hash, soft_confirmation.da_slot_height(), diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs index b9ffc40e1..c10307441 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs @@ -164,10 +164,10 @@ pub fn convert_to_rpc_proof(stored_proof: Proof) -> ProofRpcResponse { /// included in the batch. #[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize)] pub struct StoredSoftConfirmation { - /// The number of the batch - pub da_slot_height: u64, /// The l2 height of the soft confirmation pub l2_height: u64, + /// The number of the batch + pub da_slot_height: u64, /// The da hash of the batch pub da_slot_hash: [u8; 32], /// The da transactions commitment of the batch @@ -197,6 +197,7 @@ pub struct StoredSoftConfirmation { impl From for SignedSoftConfirmation { fn from(value: StoredSoftConfirmation) -> Self { SignedSoftConfirmation::new( + value.l2_height, value.hash, value.prev_hash, value.da_slot_height, diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs index 862dd0a3a..8b2a505a5 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs @@ -81,6 +81,8 @@ pub trait ApplySoftConfirmationHooks { /// Does not include txs because txs can be appended by the sequencer #[derive(Debug, PartialEq, Clone, BorshDeserialize, BorshSerialize, Serialize, Deserialize, Eq)] pub struct HookSoftConfirmationInfo { + /// L2 block height + pub l2_height: u64, /// DA block this soft confirmation was given for pub da_slot_height: u64, /// DA block hash @@ -108,6 +110,7 @@ impl HookSoftConfirmationInfo { current_spec: SpecId, ) -> Self { HookSoftConfirmationInfo { + l2_height: signed_soft_confirmation.l2_height(), da_slot_height: signed_soft_confirmation.da_slot_height(), da_slot_hash: signed_soft_confirmation.da_slot_hash(), da_slot_txs_commitment: signed_soft_confirmation.da_slot_txs_commitment(), @@ -124,6 +127,7 @@ impl HookSoftConfirmationInfo { impl From for SignedSoftConfirmation { fn from(val: HookSoftConfirmationInfo) -> Self { SignedSoftConfirmation::new( + val.l2_height, [0u8; 32], [0u8; 32], val.da_slot_height, @@ -140,6 +144,11 @@ impl From for SignedSoftConfirmation { } impl HookSoftConfirmationInfo { + /// L2 block height + pub fn l2_height(&self) -> u64 { + self.l2_height + } + /// DA block to build on pub fn da_slot_hash(&self) -> [u8; 32] { self.da_slot_hash diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs index ce83fbc24..52f355392 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs @@ -257,6 +257,7 @@ where StateCheckpoint, ) { let unsigned = UnsignedSoftConfirmation::new( + soft_confirmation.l2_height(), soft_confirmation.da_slot_height(), soft_confirmation.da_slot_hash(), soft_confirmation.da_slot_txs_commitment(), diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index 613f6656f..866641e02 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -222,6 +222,7 @@ where ( Ok(SoftConfirmationReceipt { + l2_height: soft_confirmation.l2_height(), hash: soft_confirmation.hash(), prev_hash: soft_confirmation.prev_hash(), tx_receipts, diff --git a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs index 87718d06f..3077933d9 100644 --- a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs +++ b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs @@ -153,10 +153,10 @@ impl From> for HexTx { #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct SoftConfirmationResponse { - /// The DA height of the soft confirmation. - pub da_slot_height: u64, /// The L2 height of the soft confirmation. pub l2_height: u64, + /// The DA height of the soft confirmation. + pub da_slot_height: u64, /// The DA slothash of the soft confirmation. // TODO: find a way to hex serialize this and then // deserialize in `SequencerClient` diff --git a/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs b/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs index 4571b3871..ac27a6176 100644 --- a/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs +++ b/crates/sovereign-sdk/rollup-interface/src/state_machine/soft_confirmation.rs @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize}; /// Contains raw transactions and information about the soft confirmation block #[derive(Debug, PartialEq, Clone, BorshDeserialize, BorshSerialize, Serialize, Deserialize)] pub struct UnsignedSoftConfirmation { + l2_height: u64, da_slot_height: u64, da_slot_hash: [u8; 32], da_slot_txs_commitment: [u8; 32], @@ -25,6 +26,7 @@ impl UnsignedSoftConfirmation { #[allow(clippy::too_many_arguments)] /// Creates a new unsigned soft confirmation batch pub fn new( + l2_height: u64, da_slot_height: u64, da_slot_hash: [u8; 32], da_slot_txs_commitment: [u8; 32], @@ -34,6 +36,7 @@ impl UnsignedSoftConfirmation { timestamp: u64, ) -> Self { Self { + l2_height, da_slot_height, da_slot_hash, da_slot_txs_commitment, @@ -43,6 +46,10 @@ impl UnsignedSoftConfirmation { timestamp, } } + /// L2 block height + pub fn l2_height(&self) -> u64 { + self.l2_height + } /// DA block to build on pub fn da_slot_height(&self) -> u64 { self.da_slot_height @@ -77,6 +84,7 @@ impl UnsignedSoftConfirmation { /// Contains the signature and public key of the sequencer #[derive(Debug, PartialEq, Clone, BorshDeserialize, BorshSerialize, Serialize, Deserialize, Eq)] pub struct SignedSoftConfirmation { + l2_height: u64, hash: [u8; 32], prev_hash: [u8; 32], da_slot_height: u64, @@ -94,6 +102,7 @@ impl SignedSoftConfirmation { /// Creates a signed soft confirmation batch #[allow(clippy::too_many_arguments)] pub fn new( + l2_height: u64, hash: [u8; 32], prev_hash: [u8; 32], da_slot_height: u64, @@ -107,6 +116,7 @@ impl SignedSoftConfirmation { timestamp: u64, ) -> SignedSoftConfirmation { Self { + l2_height, hash, prev_hash, da_slot_height, @@ -121,6 +131,11 @@ impl SignedSoftConfirmation { } } + /// L2 block height + pub fn l2_height(&self) -> u64 { + self.l2_height + } + /// Hash of the signed batch pub fn hash(&self) -> [u8; 32] { self.hash diff --git a/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs b/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs index 568708144..f726f6342 100644 --- a/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs +++ b/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs @@ -88,6 +88,8 @@ pub struct BatchReceipt { /// A receipt for a soft confirmation of transactions. These receipts are stored in the rollup's database #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SoftConfirmationReceipt { + /// L2 block height + pub l2_height: u64, /// DA layer block number pub da_slot_height: u64, /// DA layer block hash From 0de1971a764d4c9c50e6f7c6d30338adef1cdabf Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Wed, 28 Aug 2024 18:07:53 +0300 Subject: [PATCH 04/17] add l1 fee rate and active spec to context --- Cargo.lock | 1 + .../module-system/sov-modules-api/Cargo.toml | 1 + .../sov-modules-api/src/default_context.rs | 58 +++++++++++++++---- .../sov-modules-core/src/module/spec.rs | 21 +++++-- .../sovereign-sdk/rollup-interface/Cargo.toml | 2 + .../rollup-interface/src/spec.rs | 8 +++ 6 files changed, 76 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 728246074..d7332f39a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7568,6 +7568,7 @@ name = "sov-rollup-interface" version = "0.4.0-rc.3" dependencies = [ "anyhow", + "arbitrary", "async-trait", "borsh", "bytes", diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/Cargo.toml b/crates/sovereign-sdk/module-system/sov-modules-api/Cargo.toml index 335a397b5..7805721c8 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/Cargo.toml +++ b/crates/sovereign-sdk/module-system/sov-modules-api/Cargo.toml @@ -55,6 +55,7 @@ arbitrary = [ "dep:proptest", "dep:proptest-derive", "native", + "sov-rollup-interface/arbitrary", "proptest/default", "sov-state/arbitrary", ] diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs index 38b0f717a..76ecfe961 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs @@ -5,6 +5,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use sha2::Digest; use sov_modules_core::{Address, Context, PublicKey, Spec}; +use sov_rollup_interface::spec::SpecId; use sov_rollup_interface::RollupAddress; #[cfg(feature = "native")] use sov_state::ProverStorage; @@ -20,6 +21,8 @@ use crate::default_signature::{DefaultPublicKey, DefaultSignature}; pub struct DefaultContext { pub sender: Address, pub sequencer: Address, + pub l1_fee_rate: u128, + pub active_spec: SpecId, /// The height to report. This is set by the kernel when the context is created visible_height: u64, } @@ -41,21 +44,37 @@ impl Context for DefaultContext { &self.sender } - fn sequencer(&self) -> &Self::Address { - &self.sequencer - } - - fn new(sender: Self::Address, sequencer: Self::Address, height: u64) -> Self { + fn new( + sender: Self::Address, + sequencer: Self::Address, + height: u64, + active_spec: SpecId, + l1_fee_rate: u128, + ) -> Self { Self { sender, sequencer, + l1_fee_rate, + active_spec, visible_height: height, } } + fn sequencer(&self) -> &Self::Address { + &self.sequencer + } + fn slot_height(&self) -> u64 { self.visible_height } + + fn active_spec(&self) -> SpecId { + self.active_spec + } + + fn l1_fee_rate(&self) -> u128 { + self.l1_fee_rate + } } #[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize)] @@ -63,6 +82,8 @@ impl Context for DefaultContext { pub struct ZkDefaultContext { pub sender: Address, pub sequencer: Address, + pub l1_fee_rate: u128, + pub active_spec: SpecId, /// The height to report. This is set by the kernel when the context is created visible_height: u64, } @@ -82,22 +103,37 @@ impl Context for ZkDefaultContext { fn sender(&self) -> &Self::Address { &self.sender } - - fn sequencer(&self) -> &Self::Address { - &self.sequencer - } - - fn new(sender: Self::Address, sequencer: Self::Address, height: u64) -> Self { + fn new( + sender: Self::Address, + sequencer: Self::Address, + height: u64, + active_spec: SpecId, + l1_fee_rate: u128, + ) -> Self { Self { sender, sequencer, + active_spec, + l1_fee_rate, visible_height: height, } } + fn sequencer(&self) -> &Self::Address { + &self.sequencer + } + fn slot_height(&self) -> u64 { self.visible_height } + + fn active_spec(&self) -> SpecId { + self.active_spec + } + + fn l1_fee_rate(&self) -> u128 { + self.l1_fee_rate + } } impl PublicKey for DefaultPublicKey { diff --git a/crates/sovereign-sdk/module-system/sov-modules-core/src/module/spec.rs b/crates/sovereign-sdk/module-system/sov-modules-core/src/module/spec.rs index 402a256a0..3b8f3ea87 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-core/src/module/spec.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-core/src/module/spec.rs @@ -5,6 +5,7 @@ use core::fmt::Debug; use borsh::{BorshDeserialize, BorshSerialize}; use digest::typenum::U32; use digest::Digest; +use sov_rollup_interface::spec::SpecId; use sov_rollup_interface::RollupAddress; use crate::common::{PublicKey, Signature, Witness}; @@ -101,14 +102,26 @@ pub trait Context: Spec + Clone + Debug + PartialEq + 'static { /// Sender of the transaction. fn sender(&self) -> &Self::Address; - /// Sequencer of the runtime. - fn sequencer(&self) -> &Self::Address; - /// Constructor for the Context. - fn new(sender: Self::Address, sequencer: Self::Address, height: u64) -> Self; + fn new( + sender: Self::Address, + sequencer: Self::Address, + height: u64, + active_spec: SpecId, + l1_fee_rate: u128, + ) -> Self; + + /// TODO: remove + fn sequencer(&self) -> &Self::Address; /// Returns the height of the current slot as reported by the kernel. This value is /// non-decreasing and is guaranteed to be less than or equal to the actual "objective" height of the rollup. /// Kernels should ensure that the reported height never falls too far behind the actual height. fn slot_height(&self) -> u64; + + /// The current active spec + fn active_spec(&self) -> SpecId; + + /// The L1 fee rate applied to the soft confirmation + fn l1_fee_rate(&self) -> u128; } diff --git a/crates/sovereign-sdk/rollup-interface/Cargo.toml b/crates/sovereign-sdk/rollup-interface/Cargo.toml index 81ee847db..bc68a0f19 100644 --- a/crates/sovereign-sdk/rollup-interface/Cargo.toml +++ b/crates/sovereign-sdk/rollup-interface/Cargo.toml @@ -15,6 +15,7 @@ exclude = [ ] [dependencies] +arbitrary = { workspace = true, optional = true } anyhow = { workspace = true } async-trait = { workspace = true } borsh = { workspace = true } @@ -43,6 +44,7 @@ default = ["std"] native = ["std", "tokio", "futures"] fuzzing = ["proptest", "proptest-derive", "sha2", "std"] testing = ["native"] +arbitrary = ["dep:arbitrary"] std = [ "anyhow/default", "borsh/default", diff --git a/crates/sovereign-sdk/rollup-interface/src/spec.rs b/crates/sovereign-sdk/rollup-interface/src/spec.rs index 11dfde63f..223a37ae3 100644 --- a/crates/sovereign-sdk/rollup-interface/src/spec.rs +++ b/crates/sovereign-sdk/rollup-interface/src/spec.rs @@ -23,6 +23,10 @@ mod spec { Hash, )] #[borsh(use_discriminant = true)] + #[cfg_attr( + feature = "arbitrary", + derive(arbitrary::Arbitrary, proptest_derive::Arbitrary) + )] pub enum SpecId { /// Genesis spec #[default] @@ -48,6 +52,10 @@ mod spec { Hash, )] #[borsh(use_discriminant = true)] + #[cfg_attr( + feature = "arbitrary", + derive(arbitrary::Arbitrary, proptest_derive::Arbitrary) + )] pub enum SpecId { /// Genesis spec #[default] From 6544cc51cc788d8a17aed99938434b8d3e9bf068 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Thu, 29 Aug 2024 11:29:42 +0300 Subject: [PATCH 05/17] fixes for the last commit --- crates/citrea-stf/src/hooks_impl.rs | 11 +++++++++-- .../examples/demo-stf/src/hooks_impl.rs | 11 +++++++++-- .../sov-modules-stf-blueprint/src/lib.rs | 10 ++++++---- .../sov-modules-stf-blueprint/src/stf_blueprint.rs | 14 ++++++-------- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/crates/citrea-stf/src/hooks_impl.rs b/crates/citrea-stf/src/hooks_impl.rs index 6dab1ebbf..0b05d4acc 100644 --- a/crates/citrea-stf/src/hooks_impl.rs +++ b/crates/citrea-stf/src/hooks_impl.rs @@ -28,13 +28,20 @@ impl TxHooks for Runtime { let RuntimeTxHook { height, sequencer, - current_spec: _current_spec, + current_spec, + l1_fee_rate, } = arg; let AccountsTxHook { sender, sequencer } = self.accounts .pre_dispatch_tx_hook(tx, working_set, sequencer)?; - Ok(C::new(sender, sequencer, *height)) + Ok(C::new( + sender, + sequencer, + *height, + *current_spec, + *l1_fee_rate, + )) } #[cfg_attr(feature = "native", instrument(level = "trace", skip_all, ret))] diff --git a/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs b/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs index 42b40c84b..86eed17e5 100644 --- a/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs +++ b/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs @@ -26,7 +26,8 @@ impl TxHooks for Runtime { let RuntimeTxHook { height, sequencer, - current_spec: _current_spec, + current_spec, + l1_fee_rate, } = arg; let AccountsTxHook { sender, sequencer } = self.accounts @@ -35,7 +36,13 @@ impl TxHooks for Runtime { let hook = BankTxHook { sender, sequencer }; self.bank.pre_dispatch_tx_hook(tx, working_set, &hook)?; - Ok(C::new(hook.sender, hook.sequencer, *height)) + Ok(C::new( + hook.sender, + hook.sequencer, + *height, + *current_spec, + *l1_fee_rate, + )) } fn post_dispatch_tx_hook( diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs index 52f355392..a8721e10b 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs @@ -43,6 +43,8 @@ pub struct RuntimeTxHook { pub sequencer: C::PublicKey, /// Current spec pub current_spec: SpecId, + /// L1 fee rate + pub l1_fee_rate: u128, } /// This trait has to be implemented by a runtime in order to be used in `StfBlueprint`. @@ -151,7 +153,7 @@ pub trait StfBlueprintTrait: fn apply_soft_confirmation_txs( &self, current_spec: SpecId, - txs: Vec>, + soft_confirmation: &SignedSoftConfirmation, batch_workspace: WorkingSet, ) -> (WorkingSet, Vec>); @@ -239,10 +241,10 @@ where fn apply_soft_confirmation_txs( &self, current_spec: SpecId, - txs: Vec>, + soft_confirmation: &SignedSoftConfirmation, batch_workspace: WorkingSet, ) -> (WorkingSet, Vec>) { - self.apply_sov_txs_inner(txs, current_spec, batch_workspace) + self.apply_sov_txs_inner(soft_confirmation, current_spec, batch_workspace) } fn end_soft_confirmation( @@ -469,7 +471,7 @@ where (Ok(()), batch_workspace) => { let (batch_workspace, tx_receipts) = self.apply_soft_confirmation_txs( current_spec, - soft_confirmation.txs(), + &soft_confirmation, batch_workspace, ); diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index 866641e02..e879cfc7e 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -64,11 +64,11 @@ where #[cfg_attr(feature = "native", instrument(level = "trace", skip_all))] pub fn apply_sov_txs_inner( &self, - txs: Vec>, + soft_confirmation: &SignedSoftConfirmation, current_spec: SpecId, mut sc_workspace: WorkingSet, ) -> (WorkingSet, Vec>) { - let txs = self.verify_txs_stateless_soft(&txs); + let txs = self.verify_txs_stateless_soft(&soft_confirmation.txs()); let messages = self .decode_txs(&txs) @@ -88,9 +88,10 @@ where // Pre dispatch hook // TODO set the sequencer pubkey let hook = RuntimeTxHook { - height: 1, + height: soft_confirmation.l2_height(), sequencer: tx.pub_key().clone(), current_spec, + l1_fee_rate: soft_confirmation.l1_fee_rate(), }; let ctx = match self .runtime @@ -257,11 +258,8 @@ where ) { (Ok(()), batch_workspace) => { // TODO: wait for txs here, apply_sov_txs can be called multiple times - let (batch_workspace, tx_receipts) = self.apply_sov_txs_inner( - soft_confirmation.txs(), - current_spec, - batch_workspace, - ); + let (batch_workspace, tx_receipts) = + self.apply_sov_txs_inner(soft_confirmation, current_spec, batch_workspace); self.end_soft_confirmation_inner(soft_confirmation, tx_receipts, batch_workspace) } From 4d0fb4ba3288095cc2dcddb108d94941b86e4c39 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Thu, 29 Aug 2024 11:44:28 +0300 Subject: [PATCH 06/17] modify ApplySoftConfirmationHooks and StfBluePrint function so that types make more sense --- crates/citrea-stf/src/hooks_impl.rs | 6 ++-- .../src/hooks.rs | 8 ++--- .../examples/demo-stf/src/hooks_impl.rs | 2 +- .../sov-modules-api/src/hooks.rs | 21 +----------- .../sov-modules-stf-blueprint/src/lib.rs | 34 ++++++++----------- .../src/stf_blueprint.rs | 33 ++++++++---------- 6 files changed, 38 insertions(+), 66 deletions(-) diff --git a/crates/citrea-stf/src/hooks_impl.rs b/crates/citrea-stf/src/hooks_impl.rs index 0b05d4acc..ed21aff5d 100644 --- a/crates/citrea-stf/src/hooks_impl.rs +++ b/crates/citrea-stf/src/hooks_impl.rs @@ -86,14 +86,14 @@ impl ApplySoftConfirmationHooks for Runtime { )] fn begin_soft_confirmation_hook( &self, - soft_confirmation: &mut HookSoftConfirmationInfo, + soft_confirmation_info: HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { self.soft_confirmation_rule_enforcer - .begin_soft_confirmation_hook(soft_confirmation, working_set)?; + .begin_soft_confirmation_hook(&soft_confirmation_info, working_set)?; self.evm - .begin_soft_confirmation_hook(soft_confirmation, working_set); + .begin_soft_confirmation_hook(&soft_confirmation_info, working_set); Ok(()) } diff --git a/crates/soft-confirmation-rule-enforcer/src/hooks.rs b/crates/soft-confirmation-rule-enforcer/src/hooks.rs index 44335cc7f..3a2e905ab 100644 --- a/crates/soft-confirmation-rule-enforcer/src/hooks.rs +++ b/crates/soft-confirmation-rule-enforcer/src/hooks.rs @@ -18,7 +18,7 @@ where #[cfg_attr(feature = "native", instrument(level = "trace", skip_all, err, ret))] fn apply_block_count_rule( &self, - soft_confirmation_info: &mut HookSoftConfirmationInfo, + soft_confirmation_info: &HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { let da_root_hash = soft_confirmation_info.da_slot_hash(); @@ -55,7 +55,7 @@ where #[cfg_attr(feature = "native", instrument(level = "trace", skip_all, err, ret))] fn apply_fee_rate_rule( &self, - soft_confirmation: &mut HookSoftConfirmationInfo, + soft_confirmation: &HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { let l1_fee_rate = soft_confirmation.l1_fee_rate(); @@ -95,7 +95,7 @@ where #[cfg_attr(feature = "native", instrument(level = "trace", skip_all, err, ret))] fn apply_timestamp_rule( &self, - soft_confirmation: &mut HookSoftConfirmationInfo, + soft_confirmation: &HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { let current_timestamp = soft_confirmation.timestamp(); @@ -120,7 +120,7 @@ where )] pub fn begin_soft_confirmation_hook( &self, - soft_confirmation: &mut HookSoftConfirmationInfo, + soft_confirmation: &HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { self.apply_block_count_rule(soft_confirmation, working_set)?; diff --git a/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs b/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs index 86eed17e5..b8e9c21cf 100644 --- a/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs +++ b/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs @@ -83,7 +83,7 @@ impl ApplySoftConfirmationHooks for Runtime { fn begin_soft_confirmation_hook( &self, - _soft_confirmation: &mut HookSoftConfirmationInfo, + _soft_confirmation: HookSoftConfirmationInfo, _working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { // Before executing each batch, check that the sender is registered as a sequencer diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs index 8b2a505a5..01d185b5d 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs @@ -65,7 +65,7 @@ pub trait ApplySoftConfirmationHooks { /// If this hook returns Err, batch is not applied fn begin_soft_confirmation_hook( &self, - soft_confirmation: &mut HookSoftConfirmationInfo, + soft_confirmation_info: HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError>; @@ -124,25 +124,6 @@ impl HookSoftConfirmationInfo { } } -impl From for SignedSoftConfirmation { - fn from(val: HookSoftConfirmationInfo) -> Self { - SignedSoftConfirmation::new( - val.l2_height, - [0u8; 32], - [0u8; 32], - val.da_slot_height, - val.da_slot_hash(), - val.da_slot_txs_commitment(), - val.l1_fee_rate, - vec![], - val.deposit_data, - vec![], - val.pub_key.clone(), - val.timestamp, - ) - } -} - impl HookSoftConfirmationInfo { /// L2 block height pub fn l2_height(&self) -> u64 { diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs index a8721e10b..be2c2ea39 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs @@ -8,7 +8,8 @@ use rs_merkle::algorithms::Sha256; use rs_merkle::MerkleTree; use sov_modules_api::da::BlockHeaderTrait; use sov_modules_api::hooks::{ - ApplyBlobHooks, ApplySoftConfirmationHooks, FinalizeHook, SlotHooks, TxHooks, + ApplyBlobHooks, ApplySoftConfirmationHooks, FinalizeHook, HookSoftConfirmationInfo, SlotHooks, + TxHooks, }; use sov_modules_api::{ native_debug, native_warn, BasicAddress, BlobReaderTrait, Context, DaSpec, DispatchCall, @@ -140,13 +141,11 @@ pub trait StfBlueprintTrait: #[allow(clippy::too_many_arguments)] fn begin_soft_confirmation( &self, - current_spec: SpecId, sequencer_public_key: &[u8], - pre_state_root: &Self::StateRoot, pre_state: Self::PreState, witness: <::Storage as Storage>::Witness, slot_header: &::BlockHeader, - soft_confirmation: &mut SignedSoftConfirmation, + soft_confirmation: HookSoftConfirmationInfo, ) -> (Result<(), SoftConfirmationError>, WorkingSet); /// Apply soft confirmation transactions @@ -196,13 +195,11 @@ where { fn begin_soft_confirmation( &self, - current_spec: SpecId, sequencer_public_key: &[u8], - pre_state_root: &Self::StateRoot, pre_state: ::Storage, witness: <::Storage as Storage>::Witness, slot_header: &::BlockHeader, - soft_confirmation: &mut SignedSoftConfirmation, + soft_confirmation_info: HookSoftConfirmationInfo, ) -> (Result<(), SoftConfirmationError>, WorkingSet) { native_debug!("Applying soft confirmation in STF Blueprint"); @@ -210,7 +207,7 @@ where let batch_workspace = checkpoint.to_revertable(); // check if soft confirmation is coming from our sequencer - if soft_confirmation.sequencer_pub_key() != sequencer_public_key { + if soft_confirmation_info.sequencer_pub_key() != sequencer_public_key { return ( Err(SoftConfirmationError::SequencerPublicKeyMismatch), batch_workspace, @@ -218,24 +215,19 @@ where }; // then verify da hashes match - if soft_confirmation.da_slot_hash() != slot_header.hash().into() { + if soft_confirmation_info.da_slot_hash() != slot_header.hash().into() { return (Err(SoftConfirmationError::InvalidDaHash), batch_workspace); } // then verify da transactions commitment match - if soft_confirmation.da_slot_txs_commitment() != slot_header.txs_commitment().into() { + if soft_confirmation_info.da_slot_txs_commitment() != slot_header.txs_commitment().into() { return ( Err(SoftConfirmationError::InvalidDaTxsCommitment), batch_workspace, ); } - self.begin_soft_confirmation_inner( - batch_workspace, - soft_confirmation, - pre_state_root, - current_spec, - ) + self.begin_soft_confirmation_inner(batch_workspace, soft_confirmation_info) } fn apply_soft_confirmation_txs( @@ -459,14 +451,18 @@ where >, SoftConfirmationError, > { - match self.begin_soft_confirmation( + let soft_confirmation_info = HookSoftConfirmationInfo::new( + soft_confirmation.clone(), + pre_state_root.as_ref().to_vec(), current_spec, + ); + + match self.begin_soft_confirmation( sequencer_public_key, - pre_state_root, pre_state.clone(), witness, slot_header, - soft_confirmation, + soft_confirmation_info, ) { (Ok(()), batch_workspace) => { let (batch_workspace, tx_receipts) = self.apply_soft_confirmation_txs( diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index e879cfc7e..6b4db420a 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -165,25 +165,19 @@ where pub fn begin_soft_confirmation_inner( &self, mut batch_workspace: WorkingSet, - soft_confirmation: &mut SignedSoftConfirmation, - pre_state_root: &::Root, - current_spec: SpecId, + soft_confirmation_info: HookSoftConfirmationInfo, ) -> (Result<(), SoftConfirmationError>, WorkingSet) { native_debug!( - "Beginning soft confirmation 0x{} from sequencer: 0x{}", - hex::encode(soft_confirmation.hash()), - hex::encode(soft_confirmation.sequencer_pub_key()) + "Beginning soft confirmation #{} from sequencer: 0x{}", + soft_confirmation_info.l2_height(), + hex::encode(soft_confirmation_info.sequencer_pub_key()) ); // ApplySoftConfirmationHook: begin - if let Err(e) = self.runtime.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - soft_confirmation.clone(), - pre_state_root.as_ref().to_vec(), - current_spec, - ), - &mut batch_workspace, - ) { + if let Err(e) = self + .runtime + .begin_soft_confirmation_hook(soft_confirmation_info, &mut batch_workspace) + { native_error!( "Error: The batch was rejected by the 'begin_soft_confirmation_hook'. Skipping batch with error: {:?}", e @@ -250,12 +244,13 @@ where ) -> (ApplySoftConfirmationResult, StateCheckpoint) { let batch_workspace = checkpoint.to_revertable(); - match self.begin_soft_confirmation_inner( - batch_workspace, - soft_confirmation, - pre_state_root, + let soft_confirmation_info = HookSoftConfirmationInfo::new( + soft_confirmation.clone(), + pre_state_root.as_ref().to_vec(), current_spec, - ) { + ); + + match self.begin_soft_confirmation_inner(batch_workspace, soft_confirmation_info) { (Ok(()), batch_workspace) => { // TODO: wait for txs here, apply_sov_txs can be called multiple times let (batch_workspace, tx_receipts) = From 11a9685893740e17086beef5bcacea77a5a2daf2 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Thu, 29 Aug 2024 12:12:48 +0300 Subject: [PATCH 07/17] make new changes work in the sequencer --- crates/citrea-stf/src/hooks_impl.rs | 6 +-- crates/sequencer/src/sequencer.rs | 25 +++------ .../examples/demo-stf/src/hooks_impl.rs | 2 +- .../sov-modules-api/src/hooks.rs | 9 +++- .../sov-modules-core/src/module/dispatch.rs | 1 - .../src/dispatch/dispatch_call.rs | 1 - .../sov-modules-stf-blueprint/src/lib.rs | 20 +++---- .../src/stf_blueprint.rs | 52 ++++--------------- 8 files changed, 40 insertions(+), 76 deletions(-) diff --git a/crates/citrea-stf/src/hooks_impl.rs b/crates/citrea-stf/src/hooks_impl.rs index ed21aff5d..363606f6e 100644 --- a/crates/citrea-stf/src/hooks_impl.rs +++ b/crates/citrea-stf/src/hooks_impl.rs @@ -86,14 +86,14 @@ impl ApplySoftConfirmationHooks for Runtime { )] fn begin_soft_confirmation_hook( &self, - soft_confirmation_info: HookSoftConfirmationInfo, + soft_confirmation_info: &HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { self.soft_confirmation_rule_enforcer - .begin_soft_confirmation_hook(&soft_confirmation_info, working_set)?; + .begin_soft_confirmation_hook(soft_confirmation_info, working_set)?; self.evm - .begin_soft_confirmation_hook(&soft_confirmation_info, working_set); + .begin_soft_confirmation_hook(soft_confirmation_info, working_set); Ok(()) } diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index a53ab9099..ec22700b6 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -267,18 +267,15 @@ where pub_key: &[u8], prestate: ::Spec>>::NativeStorage, da_block_header: <::Spec as DaSpec>::BlockHeader, - mut signed_batch: SignedSoftConfirmation, + soft_confirmation_info: HookSoftConfirmationInfo, l2_block_mode: L2BlockMode, ) -> anyhow::Result<(Vec, Vec)> { - let active_fork_spec = self.fork_manager.active_fork().spec_id; match self.stf.begin_soft_confirmation( - active_fork_spec, pub_key, - &self.state_root, prestate.clone(), Default::default(), &da_block_header, - &mut signed_batch, + &soft_confirmation_info, ) { (Ok(()), mut working_set_to_discard) => { let block_gas_limit = self.db_provider.cfg().block_gas_limit; @@ -310,7 +307,7 @@ where let txs = vec![signed_blob.clone()]; let (sc_workspace, _) = self.stf.apply_soft_confirmation_txs( - active_fork_spec, + soft_confirmation_info.clone(), txs.clone(), working_set_to_discard, ); @@ -388,7 +385,7 @@ where let active_fork_spec = self.fork_manager.active_fork().spec_id; - let batch_info = HookSoftConfirmationInfo { + let soft_confirmation_info = HookSoftConfirmationInfo { l2_height, da_slot_height: da_block.header().height(), da_slot_hash: da_block.header().hash().into(), @@ -396,12 +393,10 @@ where pre_state_root: self.state_root.clone().as_ref().to_vec(), deposit_data: deposit_data.clone(), current_spec: active_fork_spec, - pub_key, + pub_key: pub_key.clone(), l1_fee_rate, timestamp, }; - // initially create sc info and call begin soft confirmation hook with it - let mut signed_batch: SignedSoftConfirmation = batch_info.clone().into(); let prestate = self .storage_manager @@ -412,8 +407,6 @@ where hex::encode(da_block.header().hash().into()) ); - let pub_key = signed_batch.pub_key().clone(); - let evm_txs = self.get_best_transactions()?; // Dry running transactions would basically allow for figuring out a list of @@ -425,7 +418,7 @@ where &pub_key, prestate.clone(), da_block.header().clone(), - signed_batch.clone(), + soft_confirmation_info.clone(), l2_block_mode, ) .await?; @@ -437,13 +430,11 @@ where // Execute the selected transactions match self.stf.begin_soft_confirmation( - active_fork_spec, &pub_key, - &self.state_root, prestate.clone(), Default::default(), da_block.header(), - &mut signed_batch, + &soft_confirmation_info, ) { (Ok(()), mut batch_workspace) => { let mut txs = vec![]; @@ -460,7 +451,7 @@ where txs.push(signed_blob); (batch_workspace, tx_receipts) = self.stf.apply_soft_confirmation_txs( - active_fork_spec, + soft_confirmation_info, txs.clone(), batch_workspace, ); diff --git a/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs b/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs index b8e9c21cf..f253163de 100644 --- a/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs +++ b/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs @@ -83,7 +83,7 @@ impl ApplySoftConfirmationHooks for Runtime { fn begin_soft_confirmation_hook( &self, - _soft_confirmation: HookSoftConfirmationInfo, + _soft_confirmation: &HookSoftConfirmationInfo, _working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { // Before executing each batch, check that the sender is registered as a sequencer diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs index 01d185b5d..ce8130db7 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs @@ -65,7 +65,7 @@ pub trait ApplySoftConfirmationHooks { /// If this hook returns Err, batch is not applied fn begin_soft_confirmation_hook( &self, - soft_confirmation_info: HookSoftConfirmationInfo, + soft_confirmation_info: &HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError>; @@ -93,7 +93,7 @@ pub struct HookSoftConfirmationInfo { pub pre_state_root: Vec, /// The current spec pub current_spec: SpecId, - /// Public key of signer + /// Public key of the sequencer pub pub_key: Vec, /// Deposit data from the L1 chain pub deposit_data: Vec>, @@ -145,6 +145,11 @@ impl HookSoftConfirmationInfo { self.pre_state_root.clone() } + /// Active spec + pub fn current_spec(&self) -> SpecId { + self.current_spec + } + /// Public key of signer pub fn sequencer_pub_key(&self) -> &[u8] { self.pub_key.as_ref() diff --git a/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs b/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs index d0bb4b115..7e628afaf 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs @@ -23,7 +23,6 @@ pub trait DispatchCall: Send + Sync { &self, message: Self::Decodable, working_set: &mut WorkingSet, - current_spec: SpecId, context: &Self::Context, ) -> Result; diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/src/dispatch/dispatch_call.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/src/dispatch/dispatch_call.rs index 35c8a8042..3dc8ac75d 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/src/dispatch/dispatch_call.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/src/dispatch/dispatch_call.rs @@ -67,7 +67,6 @@ impl<'a> StructDef<'a> { &self, decodable: Self::Decodable, working_set: &mut ::sov_modules_api::WorkingSet, - current_spec: ::sov_rollup_interface::spec::SpecId, context: &Self::Context, ) -> ::core::result::Result<::sov_modules_api::CallResponse, ::sov_modules_api::Error> { diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs index be2c2ea39..208e24117 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs @@ -145,14 +145,14 @@ pub trait StfBlueprintTrait: pre_state: Self::PreState, witness: <::Storage as Storage>::Witness, slot_header: &::BlockHeader, - soft_confirmation: HookSoftConfirmationInfo, + soft_confirmation_info: &HookSoftConfirmationInfo, ) -> (Result<(), SoftConfirmationError>, WorkingSet); /// Apply soft confirmation transactions fn apply_soft_confirmation_txs( &self, - current_spec: SpecId, - soft_confirmation: &SignedSoftConfirmation, + soft_confirmation: HookSoftConfirmationInfo, + txs: Vec>, batch_workspace: WorkingSet, ) -> (WorkingSet, Vec>); @@ -199,7 +199,7 @@ where pre_state: ::Storage, witness: <::Storage as Storage>::Witness, slot_header: &::BlockHeader, - soft_confirmation_info: HookSoftConfirmationInfo, + soft_confirmation_info: &HookSoftConfirmationInfo, ) -> (Result<(), SoftConfirmationError>, WorkingSet) { native_debug!("Applying soft confirmation in STF Blueprint"); @@ -232,11 +232,11 @@ where fn apply_soft_confirmation_txs( &self, - current_spec: SpecId, - soft_confirmation: &SignedSoftConfirmation, + soft_confirmation_info: HookSoftConfirmationInfo, + txs: Vec>, batch_workspace: WorkingSet, ) -> (WorkingSet, Vec>) { - self.apply_sov_txs_inner(soft_confirmation, current_spec, batch_workspace) + self.apply_sov_txs_inner(soft_confirmation_info, txs, batch_workspace) } fn end_soft_confirmation( @@ -462,12 +462,12 @@ where pre_state.clone(), witness, slot_header, - soft_confirmation_info, + &soft_confirmation_info, ) { (Ok(()), batch_workspace) => { let (batch_workspace, tx_receipts) = self.apply_soft_confirmation_txs( - current_spec, - &soft_confirmation, + soft_confirmation_info, + soft_confirmation.txs(), batch_workspace, ); diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index 6b4db420a..f577d85da 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -64,11 +64,11 @@ where #[cfg_attr(feature = "native", instrument(level = "trace", skip_all))] pub fn apply_sov_txs_inner( &self, - soft_confirmation: &SignedSoftConfirmation, - current_spec: SpecId, + soft_confirmation_info: HookSoftConfirmationInfo, + txs: Vec>, mut sc_workspace: WorkingSet, ) -> (WorkingSet, Vec>) { - let txs = self.verify_txs_stateless_soft(&soft_confirmation.txs()); + let txs = self.verify_txs_stateless_soft(txs); let messages = self .decode_txs(&txs) @@ -88,10 +88,10 @@ where // Pre dispatch hook // TODO set the sequencer pubkey let hook = RuntimeTxHook { - height: soft_confirmation.l2_height(), + height: soft_confirmation_info.l2_height(), sequencer: tx.pub_key().clone(), - current_spec, - l1_fee_rate: soft_confirmation.l1_fee_rate(), + current_spec: soft_confirmation_info.current_spec(), + l1_fee_rate: soft_confirmation_info.l1_fee_rate(), }; let ctx = match self .runtime @@ -116,9 +116,7 @@ where // Commit changes after pre_dispatch_tx_hook sc_workspace = sc_workspace.checkpoint().to_revertable(); - let tx_result = self - .runtime - .dispatch_call(msg, &mut sc_workspace, current_spec, &ctx); + let tx_result = self.runtime.dispatch_call(msg, &mut sc_workspace, &ctx); let events = sc_workspace.take_events(); let tx_effect = match tx_result { @@ -165,7 +163,7 @@ where pub fn begin_soft_confirmation_inner( &self, mut batch_workspace: WorkingSet, - soft_confirmation_info: HookSoftConfirmationInfo, + soft_confirmation_info: &HookSoftConfirmationInfo, ) -> (Result<(), SoftConfirmationError>, WorkingSet) { native_debug!( "Beginning soft confirmation #{} from sequencer: 0x{}", @@ -234,40 +232,12 @@ where ) } - #[cfg_attr(all(target_os = "zkvm", feature = "bench"), cycle_tracker)] - pub(crate) fn _apply_soft_confirmation_inner( - &self, - checkpoint: StateCheckpoint, - soft_confirmation: &mut SignedSoftConfirmation, - pre_state_root: &::Root, - current_spec: SpecId, - ) -> (ApplySoftConfirmationResult, StateCheckpoint) { - let batch_workspace = checkpoint.to_revertable(); - - let soft_confirmation_info = HookSoftConfirmationInfo::new( - soft_confirmation.clone(), - pre_state_root.as_ref().to_vec(), - current_spec, - ); - - match self.begin_soft_confirmation_inner(batch_workspace, soft_confirmation_info) { - (Ok(()), batch_workspace) => { - // TODO: wait for txs here, apply_sov_txs can be called multiple times - let (batch_workspace, tx_receipts) = - self.apply_sov_txs_inner(soft_confirmation, current_spec, batch_workspace); - - self.end_soft_confirmation_inner(soft_confirmation, tx_receipts, batch_workspace) - } - (Err(err), batch_workspace) => (Err(err), batch_workspace.revert()), - } - } - // Stateless verification of transaction, such as signature check // Single malformed transaction results in sequencer slashing. - fn verify_txs_stateless_soft(&self, txs: &[Vec]) -> Vec> { + fn verify_txs_stateless_soft(&self, txs: Vec>) -> Vec> { verify_txs_stateless( - txs.iter() - .map(|tx| RawTx { data: tx.clone() }) + txs.into_iter() + .map(|tx| RawTx { data: tx }) .collect::>(), ) .expect("Sequencer must not include non-deserializable transaction.") From ec5662b3644ae26e9c06a12d3ee88e3e7b26ae53 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Thu, 29 Aug 2024 14:59:51 +0300 Subject: [PATCH 08/17] test and lint fixes --- crates/evm/src/tests/call_tests.rs | 109 ++++++- .../tests/ef_tests/cases/blockchain_test.rs | 26 +- crates/evm/src/tests/hooks_tests.rs | 19 ++ crates/evm/src/tests/queries/basic_queries.rs | 16 +- .../src/tests/queries/estimate_gas_tests.rs | 4 +- .../evm/src/tests/queries/evm_call_tests.rs | 15 +- crates/evm/src/tests/queries/log_tests.rs | 64 +++- crates/evm/src/tests/queries/mod.rs | 87 +++++- crates/evm/src/tests/sys_tx_tests.rs | 76 ++++- crates/evm/src/tests/utils.rs | 1 + crates/fullnode/tests/hash_stf.rs | 8 +- .../src/hooks.rs | 8 +- .../src/tests/call_tests.rs | 6 +- .../src/tests/hooks_tests.rs | 276 +++++------------- .../src/tests/mod.rs | 18 ++ .../src/tests/query_tests.rs | 110 +------ crates/sovereign-sdk/fuzz/Cargo.lock | 2 + .../fuzz/fuzz_targets/bank_call.rs | 4 +- .../sov-accessory-state/tests/test.rs | 4 +- .../examples/sov-value-setter/src/tests.rs | 11 +- .../examples/sov-vec-setter/tests/tests.rs | 3 +- .../module-template/tests/value_setter.rs | 6 +- .../sov-bank/tests/archival_query_test.rs | 4 +- .../sov-bank/tests/burn_test.rs | 8 +- .../sov-bank/tests/create_token_test.rs | 4 +- .../sov-bank/tests/freeze_test.rs | 12 +- .../sov-bank/tests/gas_test.rs | 10 +- .../sov-bank/tests/mint_test.rs | 28 +- .../sov-bank/tests/transfer_test.rs | 8 +- .../sov-prover-incentives/src/tests.rs | 10 +- .../tests/sequencer_registry_test.rs | 16 +- .../src/containers/versioned_value.rs | 46 ++- .../module-system/sov-modules-api/src/lib.rs | 2 + .../sov-modules-core/src/module/dispatch.rs | 1 - .../tests/working_set_tests.rs | 9 +- .../tests/dispatch/derive_dispatch.rs | 4 +- .../src/stf_blueprint.rs | 6 +- .../sovereign-sdk/rollup-interface/Cargo.toml | 9 +- 38 files changed, 606 insertions(+), 444 deletions(-) diff --git a/crates/evm/src/tests/call_tests.rs b/crates/evm/src/tests/call_tests.rs index e787d8de1..a728389e5 100644 --- a/crates/evm/src/tests/call_tests.rs +++ b/crates/evm/src/tests/call_tests.rs @@ -49,9 +49,11 @@ fn call_multiple_test() { let contract_addr = address!("819c5497b157177315e1204f52e588b393771719"); let l1_fee_rate = 0; + let l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -70,7 +72,13 @@ fn call_multiple_test() { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let transactions: Vec = vec![ create_contract_transaction(&dev_signer1, 0, SimpleStorageContract::default()), @@ -164,9 +172,11 @@ fn call_test() { let (evm, mut working_set) = get_evm(&config); let l1_fee_rate = 0; + let l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -184,7 +194,13 @@ fn call_test() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let rlp_transactions = vec![ create_contract_message(&dev_signer, 0, SimpleStorageContract::default()), @@ -244,9 +260,11 @@ fn failed_transaction_test() { let (evm, mut working_set) = get_evm(&EvmConfig::default()); let working_set = &mut working_set; let l1_fee_rate = 0; + let l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -262,7 +280,13 @@ fn failed_transaction_test() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let rlp_transactions = vec![create_contract_message( &dev_signer, 0, @@ -302,9 +326,11 @@ fn self_destruct_test() { get_evm_config(U256::from_str("100000000000000000000").unwrap(), None); let (evm, mut working_set) = get_evm(&config); let l1_fee_rate = 0; + let mut l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -320,7 +346,13 @@ fn self_destruct_test() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); // deploy selfdestruct contract // send some money to the selfdestruct contract @@ -343,6 +375,8 @@ fn self_destruct_test() { evm.end_soft_confirmation_hook(&mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); + l2_height += 1; + let db_contract = evm .accounts .get(&contract_addr, &mut working_set) @@ -366,6 +400,7 @@ fn self_destruct_test() { evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 2, da_slot_txs_commitment: [42u8; 32], @@ -381,7 +416,13 @@ fn self_destruct_test() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); // selfdestruct evm.call( CallMessage { @@ -398,6 +439,7 @@ fn self_destruct_test() { .unwrap(); } evm.end_soft_confirmation_hook(&mut working_set); + let db_contract = evm .accounts .get(&contract_addr, &mut working_set) @@ -445,9 +487,11 @@ fn test_block_hash_in_evm() { let (evm, mut working_set) = get_evm(&config); let l1_fee_rate = 0; + let mut l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -463,7 +507,13 @@ fn test_block_hash_in_evm() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let deploy_message = create_contract_message(&dev_signer, 0, BlockHashContract::default()); @@ -479,11 +529,14 @@ fn test_block_hash_in_evm() { evm.end_soft_confirmation_hook(&mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); + l2_height += 1; + for _i in 0..514 { // generate 514 more blocks let l1_fee_rate = 0; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -498,6 +551,8 @@ fn test_block_hash_in_evm() { ); evm.end_soft_confirmation_hook(&mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); + + l2_height += 1; } let _last_block_number = evm @@ -558,9 +613,11 @@ fn test_block_gas_limit() { let (evm, mut working_set) = get_evm(&config); let l1_fee_rate = 0; + let l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -576,7 +633,13 @@ fn test_block_gas_limit() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); // deploy logs contract let mut rlp_transactions = vec![create_contract_message( @@ -841,6 +904,7 @@ fn test_l1_fee_success() { evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height: 2, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -856,7 +920,13 @@ fn test_l1_fee_success() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + 2, + SovSpecId::Genesis, + l1_fee_rate, + ); let deploy_message = create_contract_message_with_priority_fee( &dev_signer, @@ -943,8 +1013,11 @@ fn test_l1_fee_not_enough_funds() { let l1_fee_rate = 10000; let (evm, mut working_set) = get_evm(&config); + let l2_height = 2; + evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -960,7 +1033,13 @@ fn test_l1_fee_not_enough_funds() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let deploy_message = create_contract_message_with_fee(&dev_signer, 0, BlockHashContract::default(), 1); @@ -1001,11 +1080,13 @@ fn test_l1_fee_halt() { let (config, dev_signer, _) = get_evm_config_starting_base_fee(U256::from_str("20000000000000").unwrap(), None, 1); - let (evm, mut working_set) = get_evm(&config); + let (evm, mut working_set) = get_evm(&config); // l2 height 1 let l1_fee_rate = 1; + let l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -1021,7 +1102,13 @@ fn test_l1_fee_halt() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let deploy_message = create_contract_message_with_fee( &dev_signer, diff --git a/crates/evm/src/tests/ef_tests/cases/blockchain_test.rs b/crates/evm/src/tests/ef_tests/cases/blockchain_test.rs index 849552c81..1d89a5038 100644 --- a/crates/evm/src/tests/ef_tests/cases/blockchain_test.rs +++ b/crates/evm/src/tests/ef_tests/cases/blockchain_test.rs @@ -59,13 +59,16 @@ impl BlockchainTestCase { mut working_set: WorkingSet, storage: ProverStorage, root: &[u8; 32], + l2_height: u64, ) -> ( WorkingSet, ProverStorage, ) { + let l1_fee_rate = 0; // Call begin_soft_confirmation_hook evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [0u8; 32], da_slot_height: 0, da_slot_txs_commitment: [0u8; 32], @@ -73,7 +76,7 @@ impl BlockchainTestCase { current_spec: SovSpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 0, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -81,7 +84,13 @@ impl BlockchainTestCase { let dummy_address = generate_address::("dummy"); let sequencer_address = generate_address::("sequencer"); - let context = DefaultContext::new(dummy_address, sequencer_address, 1); + let context = DefaultContext::new( + dummy_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let _ = evm.execute_call(txs, &context, &mut working_set); evm.end_soft_confirmation_hook(&mut working_set); @@ -176,6 +185,7 @@ impl Case for BlockchainTestCase { } let (mut evm, _, mut storage) = get_evm_with_storage(&evm_config); + let mut l2_height = 2; let mut working_set = WorkingSet::new(storage.clone()); evm.cfg.set( @@ -217,8 +227,16 @@ impl Case for BlockchainTestCase { }) .collect(); - (working_set, storage) = - self.execute_transactions(&mut evm, txs, working_set, storage, &root); + (working_set, storage) = self.execute_transactions( + &mut evm, + txs, + working_set, + storage, + &root, + l2_height, + ); + + l2_height += 1; } // Validate the post-state for the test case. diff --git a/crates/evm/src/tests/hooks_tests.rs b/crates/evm/src/tests/hooks_tests.rs index e7b6c0edc..e0b70a3b2 100644 --- a/crates/evm/src/tests/hooks_tests.rs +++ b/crates/evm/src/tests/hooks_tests.rs @@ -26,8 +26,10 @@ lazy_static! { fn begin_soft_confirmation_hook_creates_pending_block() { let (evm, mut working_set) = get_evm(&TEST_CONFIG); let l1_fee_rate = 0; + let l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: DA_ROOT_HASH.0, da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -61,9 +63,11 @@ fn end_soft_confirmation_hook_sets_head() { pre_state_root.copy_from_slice(GENESIS_STATE_ROOT.as_ref()); let txs_commitment = *GENESIS_DA_TXS_COMMITMENT; let l1_fee_rate = 0; + let l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: DA_ROOT_HASH.0, da_slot_height: 1, da_slot_txs_commitment: txs_commitment.into(), @@ -139,8 +143,10 @@ fn end_soft_confirmation_hook_sets_head() { fn end_soft_confirmation_hook_moves_transactions_and_receipts() { let (evm, mut working_set) = get_evm(&TEST_CONFIG); let l1_fee_rate = 0; + let l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: DA_ROOT_HASH.0, da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -244,9 +250,11 @@ fn finalize_hook_creates_final_block() { let txs_commitment = *GENESIS_DA_TXS_COMMITMENT; let l1_fee_rate = 0; + let mut l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: txs_commitment.into(), @@ -276,8 +284,11 @@ fn finalize_hook_creates_final_block() { evm.finalize_hook(&root_hash.into(), &mut accessory_state); assert_eq!(evm.blocks.len(&mut accessory_state), 3); + l2_height += 1; + evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: DA_ROOT_HASH.0, da_slot_height: 1, da_slot_txs_commitment: txs_commitment.into(), @@ -363,9 +374,11 @@ fn begin_soft_confirmation_hook_appends_last_block_hashes() { let txs_commitment = *GENESIS_DA_TXS_COMMITMENT; let l1_fee_rate = 0; + let mut l2_height = 2; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: DA_ROOT_HASH.0, da_slot_height: 1, da_slot_txs_commitment: txs_commitment.into(), @@ -403,11 +416,14 @@ fn begin_soft_confirmation_hook_appends_last_block_hashes() { let mut random_32_bytes: [u8; 32] = rand::thread_rng().gen::<[u8; 32]>(); evm.finalize_hook(&random_32_bytes.into(), &mut working_set.accessory_state()); + l2_height += 1; + // finalize blocks 2-257 with random state root hashes for _ in 2..257 { let l1_fee_rate = 0; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: DA_ROOT_HASH.0, da_slot_height: 1, da_slot_txs_commitment: random_32_bytes, @@ -425,12 +441,15 @@ fn begin_soft_confirmation_hook_appends_last_block_hashes() { random_32_bytes = rand::thread_rng().gen::<[u8; 32]>(); evm.finalize_hook(&random_32_bytes.into(), &mut working_set.accessory_state()); + + l2_height += 1; } // start environment for block 258 let l1_fee_rate = 0; evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: DA_ROOT_HASH.0, da_slot_height: 1, da_slot_txs_commitment: random_32_bytes, diff --git a/crates/evm/src/tests/queries/basic_queries.rs b/crates/evm/src/tests/queries/basic_queries.rs index 8d6b2645b..572f50f4f 100644 --- a/crates/evm/src/tests/queries/basic_queries.rs +++ b/crates/evm/src/tests/queries/basic_queries.rs @@ -13,7 +13,7 @@ use crate::tests::queries::init_evm; #[test] fn get_block_by_hash_test() { // make a block - let (evm, mut working_set, _) = init_evm(); + let (evm, mut working_set, _, _) = init_evm(); let result = evm.get_block_by_hash([5u8; 32].into(), Some(false), &mut working_set); @@ -34,7 +34,7 @@ fn get_block_by_hash_test() { #[test] fn get_block_by_number_test() { // make a block - let (evm, mut working_set, _) = init_evm(); + let (evm, mut working_set, _, _) = init_evm(); let result = evm.get_block_by_number( Some(BlockNumberOrTag::Number(1000)), @@ -60,7 +60,7 @@ fn get_block_by_number_test() { #[test] fn get_block_receipts_test() { // make a block - let (evm, mut working_set, _) = init_evm(); + let (evm, mut working_set, _, _) = init_evm(); let result = evm.get_block_receipts( BlockId::Number(BlockNumberOrTag::Number(1000)), @@ -91,7 +91,7 @@ fn get_block_receipts_test() { #[test] fn get_transaction_by_block_hash_and_index_test() { - let (evm, mut working_set, _) = init_evm(); + let (evm, mut working_set, _, _) = init_evm(); let result = evm.get_transaction_by_block_hash_and_index( [0u8; 32].into(), @@ -135,7 +135,7 @@ fn get_transaction_by_block_hash_and_index_test() { #[test] fn get_transaction_by_block_number_and_index_test() { - let (evm, mut working_set, _) = init_evm(); + let (evm, mut working_set, _, _) = init_evm(); let result = evm.get_transaction_by_block_number_and_index( BlockNumberOrTag::Number(100), @@ -184,7 +184,7 @@ fn get_transaction_by_block_number_and_index_test() { #[test] fn get_block_transaction_count_by_hash_test() { - let (evm, mut working_set, _) = init_evm(); + let (evm, mut working_set, _, _) = init_evm(); let result = evm.eth_get_block_transaction_count_by_hash(B256::from([0u8; 32]), &mut working_set); @@ -230,7 +230,7 @@ fn get_block_transaction_count_by_hash_test() { #[test] fn get_block_transaction_count_by_number_test() { - let (evm, mut working_set, _) = init_evm(); + let (evm, mut working_set, _, _) = init_evm(); let result = evm .eth_get_block_transaction_count_by_number(BlockNumberOrTag::Number(5), &mut working_set); @@ -252,7 +252,7 @@ fn get_block_transaction_count_by_number_test() { #[test] fn call_test() { - let (evm, mut working_set, signer) = init_evm(); + let (evm, mut working_set, signer, _) = init_evm(); let fail_result = evm.get_call( TransactionRequest { diff --git a/crates/evm/src/tests/queries/estimate_gas_tests.rs b/crates/evm/src/tests/queries/estimate_gas_tests.rs index 4058e3b3a..67ec3819c 100644 --- a/crates/evm/src/tests/queries/estimate_gas_tests.rs +++ b/crates/evm/src/tests/queries/estimate_gas_tests.rs @@ -276,7 +276,7 @@ fn test_access_list() { // 0x819c5497b157177315e1204f52e588b393771719 -- Storage contract // 0x5ccda3e6d071a059f00d4f3f25a1adc244eb5c93 -- Caller contract - let (evm, mut working_set, signer) = init_evm_with_caller_contract(); + let (evm, mut working_set, signer, _) = init_evm_with_caller_contract(); let caller = CallerContract::default(); let input_data = caller.call_set_call_data( @@ -339,7 +339,7 @@ fn test_access_list() { #[test] fn estimate_gas_with_varied_inputs_test() { - let (evm, mut working_set, signer) = init_evm(); + let (evm, mut working_set, signer, _) = init_evm(); let simple_call_data = 0; let simple_result = diff --git a/crates/evm/src/tests/queries/evm_call_tests.rs b/crates/evm/src/tests/queries/evm_call_tests.rs index 7c548a93a..17fdd9b80 100644 --- a/crates/evm/src/tests/queries/evm_call_tests.rs +++ b/crates/evm/src/tests/queries/evm_call_tests.rs @@ -17,7 +17,7 @@ use crate::Evm; #[test] fn call_contract_without_value() { - let (evm, mut working_set, signer) = init_evm(); + let (evm, mut working_set, signer, _) = init_evm(); let contract = SimpleStorageContract::default(); let contract_address = Address::from_str("0xeeb03d20dae810f52111b853b31c8be6f30f4cd3").unwrap(); @@ -65,7 +65,7 @@ fn call_contract_without_value() { #[test] fn test_state_change() { - let (evm, mut working_set, signer) = init_evm(); + let (evm, mut working_set, signer, l2_height) = init_evm(); let balance_1 = evm.get_balance(signer.address(), None, &mut working_set); @@ -73,6 +73,7 @@ fn test_state_change() { evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -112,7 +113,7 @@ fn test_state_change() { #[test] fn call_contract_with_value_transfer() { - let (evm, mut working_set, signer) = init_evm(); + let (evm, mut working_set, signer, _) = init_evm(); let contract = SimpleStorageContract::default(); let contract_address = Address::from_str("0xeeb03d20dae810f52111b853b31c8be6f30f4cd3").unwrap(); @@ -138,7 +139,7 @@ fn call_contract_with_value_transfer() { #[test] fn call_contract_with_invalid_nonce() { - let (evm, mut working_set, signer) = init_evm(); + let (evm, mut working_set, signer, _) = init_evm(); let contract = SimpleStorageContract::default(); let contract_address = Address::from_str("0xeeb03d20dae810f52111b853b31c8be6f30f4cd3").unwrap(); @@ -188,7 +189,7 @@ fn call_contract_with_invalid_nonce() { #[test] fn call_to_nonexistent_contract() { - let (evm, mut working_set, signer) = init_evm(); + let (evm, mut working_set, signer, _) = init_evm(); let nonexistent_contract_address = Address::from_str("0x000000000000000000000000000000000000dead").unwrap(); @@ -216,7 +217,7 @@ fn call_to_nonexistent_contract() { #[test] fn call_with_high_gas_price() { - let (evm, mut working_set, signer) = init_evm(); + let (evm, mut working_set, signer, _) = init_evm(); let contract = SimpleStorageContract::default(); let contract_address = Address::from_str("0xeeb03d20dae810f52111b853b31c8be6f30f4cd3").unwrap(); @@ -246,7 +247,7 @@ fn call_with_high_gas_price() { #[test] fn test_eip1559_fields_call() { - let (evm, mut working_set, signer) = init_evm(); + let (evm, mut working_set, signer, _) = init_evm(); let default_result = eth_call_eip1559( &evm, diff --git a/crates/evm/src/tests/queries/log_tests.rs b/crates/evm/src/tests/queries/log_tests.rs index 5b4f215fa..b76a07591 100644 --- a/crates/evm/src/tests/queries/log_tests.rs +++ b/crates/evm/src/tests/queries/log_tests.rs @@ -21,7 +21,7 @@ type C = DefaultContext; #[test] fn logs_for_filter_test() { - let (evm, mut working_set, _) = init_evm(); + let (evm, mut working_set, _, _) = init_evm(); let result = evm.eth_get_logs( Filter { @@ -66,8 +66,12 @@ fn log_filter_test_at_block_hash() { let (evm, mut working_set) = get_evm(&config); + let l1_fee_rate = 1; + let l2_height = 2; + evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -75,7 +79,7 @@ fn log_filter_test_at_block_hash() { current_spec: SpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -83,7 +87,13 @@ fn log_filter_test_at_block_hash() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SpecId::Genesis, + l1_fee_rate, + ); // deploy logs contract // call the contract function @@ -273,8 +283,12 @@ fn log_filter_test_with_range() { let (evm, mut working_set) = get_evm(&config); + let l1_fee_rate = 1; + let mut l2_height = 2; + evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -282,7 +296,7 @@ fn log_filter_test_with_range() { current_spec: SpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -290,7 +304,13 @@ fn log_filter_test_with_range() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SpecId::Genesis, + l1_fee_rate, + ); // deploy selfdestruct contract // call the contract function @@ -315,6 +335,8 @@ fn log_filter_test_with_range() { evm.end_soft_confirmation_hook(&mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); + l2_height += 1; + // Test with block range from start to finish, should get all logs let empty_topics = [ FilterSet::default(), @@ -337,6 +359,7 @@ fn log_filter_test_with_range() { evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -344,7 +367,7 @@ fn log_filter_test_with_range() { current_spec: SpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -352,7 +375,13 @@ fn log_filter_test_with_range() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SpecId::Genesis, + l1_fee_rate, + ); // call the contract function evm.call( CallMessage { @@ -397,8 +426,12 @@ fn test_log_limits() { let (evm, mut working_set) = get_evm(&config); + let l1_fee_rate = 1; + let mut l2_height = 2; + evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -406,7 +439,7 @@ fn test_log_limits() { current_spec: SpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -414,7 +447,13 @@ fn test_log_limits() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SpecId::Genesis, + l1_fee_rate, + ); // deploy logs contract let mut rlp_transactions = vec![create_contract_message( @@ -462,6 +501,8 @@ fn test_log_limits() { evm.end_soft_confirmation_hook(&mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); + l2_height += 1; + // Test with block range from start to finish, should get all logs let empty_topics = [ FilterSet::default(), @@ -500,6 +541,7 @@ fn test_log_limits() { // generate 100_000 blocks to test the max block range limit evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -507,13 +549,15 @@ fn test_log_limits() { current_spec: SpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, ); evm.end_soft_confirmation_hook(&mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); + + l2_height += 1; } let filter = Filter { diff --git a/crates/evm/src/tests/queries/mod.rs b/crates/evm/src/tests/queries/mod.rs index e8b8e402d..84513bfe8 100644 --- a/crates/evm/src/tests/queries/mod.rs +++ b/crates/evm/src/tests/queries/mod.rs @@ -30,7 +30,7 @@ type C = DefaultContext; /// Block 1 has 3 transactions /// Block 2 has 4 transactions /// Block 3 has 2 transactions -fn init_evm() -> (Evm, WorkingSet, TestSigner) { +fn init_evm() -> (Evm, WorkingSet, TestSigner, u64) { let dev_signer: TestSigner = TestSigner::new_random(); let config = EvmConfig { @@ -50,6 +50,9 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { let (evm, mut working_set, prover_storage) = get_evm_with_storage(&config); + let l1_fee_rate = 1; + let mut l2_height = 1; + let contract_addr: Address = Address::from_slice( hex::decode("819c5497b157177315e1204f52e588b393771719") .unwrap() @@ -64,6 +67,7 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -71,7 +75,7 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { current_spec: SovSpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 24, }, &mut working_set, @@ -80,7 +84,13 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let transactions: Vec = vec![ create_contract_transaction(&dev_signer, 0, LogsContract::default()), @@ -100,11 +110,13 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); + l2_height += 1; let mut working_set: WorkingSet = WorkingSet::new(prover_storage.clone()); evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [8u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -112,7 +124,7 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { current_spec: SovSpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 24, }, &mut working_set, @@ -121,7 +133,13 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let transactions: Vec = vec![ publish_event_message(contract_addr, &dev_signer, 3, "hello2".to_string()), @@ -142,11 +160,13 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { evm.finalize_hook(&[100u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); + l2_height += 1; let mut working_set: WorkingSet = WorkingSet::new(prover_storage.clone()); evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [10u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -154,7 +174,7 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { current_spec: SovSpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 24, }, &mut working_set, @@ -163,7 +183,13 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let transactions: Vec = vec![ create_contract_transaction(&dev_signer, 7, SimpleStorageContract::default()), @@ -182,10 +208,11 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner) { evm.finalize_hook(&[101u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); + l2_height += 1; let working_set: WorkingSet = WorkingSet::new(prover_storage.clone()); - (evm, working_set, dev_signer) + (evm, working_set, dev_signer, l2_height) } pub fn init_evm_single_block() -> (Evm, WorkingSet, TestSigner) { @@ -222,8 +249,11 @@ pub fn init_evm_single_block() -> (Evm, WorkingSet, TestSigner) { // .as_slice(), // ); + let l1_fee_rate = 1; + evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height: 1, da_slot_hash: [1u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -231,7 +261,7 @@ pub fn init_evm_single_block() -> (Evm, WorkingSet, TestSigner) { current_spec: SovSpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -242,7 +272,13 @@ pub fn init_evm_single_block() -> (Evm, WorkingSet, TestSigner) { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + 1, + SovSpecId::Genesis, + l1_fee_rate, + ); evm.call( CallMessage { @@ -263,7 +299,7 @@ pub fn init_evm_single_block() -> (Evm, WorkingSet, TestSigner) { (evm, working_set, dev_signer) } -pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner) { +pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner, u64) { let dev_signer: TestSigner = TestSigner::new_random(); let config = EvmConfig { @@ -294,8 +330,12 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner) { // .as_slice(), // ); + let l1_fee_rate = 1; + let mut l2_height = 1; + evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [1u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -303,7 +343,7 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner) { current_spec: SovSpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -312,7 +352,13 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner) { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let transactions: Vec = vec![ create_contract_transaction(&dev_signer, 0, SimpleStorageContract::default()), @@ -331,11 +377,13 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner) { evm.finalize_hook(&[2u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); + l2_height += 1; let mut working_set: WorkingSet = WorkingSet::new(prover_storage.clone()); evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [2u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -343,7 +391,7 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner) { current_spec: SovSpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -352,7 +400,13 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner) { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SovSpecId::Genesis, + l1_fee_rate, + ); let transactions: Vec = vec![create_contract_transaction( &dev_signer, @@ -372,8 +426,9 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner) { evm.finalize_hook(&[3u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); + l2_height += 1; let working_set: WorkingSet = WorkingSet::new(prover_storage); - (evm, working_set, dev_signer) + (evm, working_set, dev_signer, l2_height) } diff --git a/crates/evm/src/tests/sys_tx_tests.rs b/crates/evm/src/tests/sys_tx_tests.rs index 3e3ff762f..6ae28e9de 100644 --- a/crates/evm/src/tests/sys_tx_tests.rs +++ b/crates/evm/src/tests/sys_tx_tests.rs @@ -101,6 +101,7 @@ fn test_sys_bitcoin_light_client() { ); let l1_fee_rate = 1; + let l2_height = 2; let system_account = evm.accounts.get(&SYSTEM_SIGNER, &mut working_set).unwrap(); // The system caller balance is unchanged(if exists)/or should be 0 @@ -141,6 +142,7 @@ fn test_sys_bitcoin_light_client() { // New L1 block â„–2 evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [2u8; 32], da_slot_height: 2, da_slot_txs_commitment: [3u8; 32], @@ -156,7 +158,13 @@ fn test_sys_bitcoin_light_client() { { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SpecId::Genesis, + l1_fee_rate, + ); let deploy_message = create_contract_message_with_fee( &dev_signer, @@ -278,13 +286,21 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { let (evm, mut working_set) = get_evm(&config); let l1_fee_rate = 0; + let mut l2_height = 2; let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SpecId::Genesis, + l1_fee_rate, + ); evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -315,8 +331,11 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { evm.end_soft_confirmation_hook(&mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); + l2_height += 1; + evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [10u8; 32], da_slot_height: 2, da_slot_txs_commitment: [43u8; 32], @@ -330,7 +349,13 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { &mut working_set, ); { - let context = C::new(sender_address, sequencer_address, 2); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SpecId::Genesis, + l1_fee_rate, + ); let sys_tx_gas_usage = evm.get_pending_txs_cumulative_gas_used(&mut working_set); assert_eq!(sys_tx_gas_usage, 80720); @@ -389,8 +414,12 @@ fn test_bridge() { let (evm, mut working_set) = get_evm(&config); + let l1_fee_rate = 1; + let l2_height = 2; + evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_height: 2, da_slot_hash: [2u8; 32], da_slot_txs_commitment: [ @@ -462,7 +491,7 @@ fn test_bridge() { 0, 0, 0, ] .to_vec()], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -523,12 +552,22 @@ fn test_upgrade_light_client() { let (evm, mut working_set) = get_evm(&config); + let l1_fee_rate = 1; + let l2_height = 2; + let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SpecId::Genesis, + l1_fee_rate, + ); evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -536,7 +575,7 @@ fn test_upgrade_light_client() { current_spec: SpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -648,12 +687,21 @@ fn test_change_upgrade_owner() { let (evm, mut working_set) = get_evm(&config); + let l1_fee_rate = 1; + let mut l2_height = 2; let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SpecId::Genesis, + l1_fee_rate, + ); evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -661,7 +709,7 @@ fn test_change_upgrade_owner() { current_spec: SpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, @@ -688,8 +736,18 @@ fn test_change_upgrade_owner() { evm.end_soft_confirmation_hook(&mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); + l2_height += 1; + let context = C::new( + sender_address, + sequencer_address, + l2_height, + SpecId::Genesis, + l1_fee_rate, + ); + evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height, da_slot_hash: [5u8; 32], da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], @@ -697,7 +755,7 @@ fn test_change_upgrade_owner() { current_spec: SpecId::Genesis, pub_key: vec![], deposit_data: vec![], - l1_fee_rate: 1, + l1_fee_rate, timestamp: 0, }, &mut working_set, diff --git a/crates/evm/src/tests/utils.rs b/crates/evm/src/tests/utils.rs index 0c3cd2a5d..9bd93ace8 100644 --- a/crates/evm/src/tests/utils.rs +++ b/crates/evm/src/tests/utils.rs @@ -58,6 +58,7 @@ pub(crate) fn get_evm(config: &EvmConfig) -> (Evm, WorkingSet) { evm.begin_soft_confirmation_hook( &HookSoftConfirmationInfo { + l2_height: 1, da_slot_hash: [1u8; 32], da_slot_height: 1, da_slot_txs_commitment: [2u8; 32], diff --git a/crates/fullnode/tests/hash_stf.rs b/crates/fullnode/tests/hash_stf.rs index 7eb3e4091..a6bfccd32 100644 --- a/crates/fullnode/tests/hash_stf.rs +++ b/crates/fullnode/tests/hash_stf.rs @@ -3,7 +3,7 @@ use sov_mock_da::{ MockAddress, MockBlob, MockBlock, MockBlockHeader, MockDaSpec, MockValidityCond, }; use sov_mock_zkvm::MockZkvm; -use sov_modules_api::hooks::SoftConfirmationError; +use sov_modules_api::hooks::{HookSoftConfirmationInfo, SoftConfirmationError}; use sov_modules_api::Context; use sov_modules_stf_blueprint::StfBlueprintTrait; use sov_prover_storage_manager::{new_orphan_storage, SnapshotManager}; @@ -75,13 +75,11 @@ impl StfBlueprintTrai { fn begin_soft_confirmation( &self, - _current_spec: SpecId, _sequencer_public_key: &[u8], - _pre_state_root: &Self::StateRoot, _pre_state: Self::PreState, _witness: <::Storage as Storage>::Witness, _slot_header: &::BlockHeader, - _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmation, + _soft_confirmation_info: &HookSoftConfirmationInfo, ) -> ( Result<(), SoftConfirmationError>, sov_modules_api::WorkingSet, @@ -91,7 +89,7 @@ impl StfBlueprintTrai fn apply_soft_confirmation_txs( &self, - _current_spec: SpecId, + _soft_confirmation_info: HookSoftConfirmationInfo, _txs: Vec>, _batch_workspace: sov_modules_api::WorkingSet, ) -> ( diff --git a/crates/soft-confirmation-rule-enforcer/src/hooks.rs b/crates/soft-confirmation-rule-enforcer/src/hooks.rs index 3a2e905ab..a6b995c91 100644 --- a/crates/soft-confirmation-rule-enforcer/src/hooks.rs +++ b/crates/soft-confirmation-rule-enforcer/src/hooks.rs @@ -120,14 +120,14 @@ where )] pub fn begin_soft_confirmation_hook( &self, - soft_confirmation: &HookSoftConfirmationInfo, + soft_confirmation_info: &HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { - self.apply_block_count_rule(soft_confirmation, working_set)?; + self.apply_block_count_rule(soft_confirmation_info, working_set)?; - self.apply_fee_rate_rule(soft_confirmation, working_set)?; + self.apply_fee_rate_rule(soft_confirmation_info, working_set)?; - self.apply_timestamp_rule(soft_confirmation, working_set)?; + self.apply_timestamp_rule(soft_confirmation_info, working_set)?; Ok(()) } diff --git a/crates/soft-confirmation-rule-enforcer/src/tests/call_tests.rs b/crates/soft-confirmation-rule-enforcer/src/tests/call_tests.rs index 48847f1d6..a37393933 100644 --- a/crates/soft-confirmation-rule-enforcer/src/tests/call_tests.rs +++ b/crates/soft-confirmation-rule-enforcer/src/tests/call_tests.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use sov_mock_da::MockDaSpec; use sov_modules_api::default_context::DefaultContext; use sov_modules_api::utils::generate_address; -use sov_modules_api::{Context, Module, Spec, StateValueAccessor}; +use sov_modules_api::{Context, Module, Spec, SpecId, StateValueAccessor}; use crate::call::CallMessage; use crate::tests::genesis_tests::{get_soft_confirmation_rule_enforcer, TEST_CONFIG}; @@ -25,7 +25,7 @@ fn change_max_l2_blocks_per_l1_and_authority() { .unwrap(); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new(sender_address, sequencer_address, 1, SpecId::Genesis, 0); let _ = soft_confirmation_rule_enforcer .call(call_message, &context, &mut working_set) @@ -90,7 +90,7 @@ fn change_max_l2_blocks_per_l1_and_authority() { ); // create a new context with the new authority - let context = C::new(new_authority, sequencer_address, 1); + let context = C::new(new_authority, sequencer_address, 1, SpecId::Genesis, 0); let _ = soft_confirmation_rule_enforcer .call( modify_max_l2_blocks_per_l1_message, diff --git a/crates/soft-confirmation-rule-enforcer/src/tests/hooks_tests.rs b/crates/soft-confirmation-rule-enforcer/src/tests/hooks_tests.rs index b3dfb9985..a2657d66c 100644 --- a/crates/soft-confirmation-rule-enforcer/src/tests/hooks_tests.rs +++ b/crates/soft-confirmation-rule-enforcer/src/tests/hooks_tests.rs @@ -2,12 +2,11 @@ use std::str::FromStr; use sov_mock_da::MockDaSpec; use sov_modules_api::default_context::DefaultContext; -use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::utils::generate_address; use sov_modules_api::{Context, Module, Spec}; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::spec::SpecId; +use super::sc_info_helper; use crate::call::CallMessage; use crate::tests::genesis_tests::{get_soft_confirmation_rule_enforcer, TEST_CONFIG}; @@ -28,37 +27,18 @@ fn begin_soft_confirmation_hook_checks_max_l2_blocks_per_l1() { .unwrap(); let sequencer_address = generate_address::("sequencer"); - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new(sender_address, sequencer_address, 1, SpecId::Genesis, 0); let _ = soft_confirmation_rule_enforcer .call(call_message, &context, &mut working_set) .unwrap(); - let signed_soft_confirmation_batch = SignedSoftConfirmation::new( - [0; 32], - [0; 32], - 0, - [0; 32], - [0; 32], - 1, - vec![], - vec![], - vec![], - vec![], - 10, - ); + let hook_soft_confirmation_info = sc_info_helper(); // call begin_slot_hook 11 times for i in 0..11 { if soft_confirmation_rule_enforcer - .begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ) + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set) .is_err() { assert_eq!(i, 10); @@ -72,44 +52,24 @@ fn begin_soft_confirmation_hook_checks_l1_fee_rate() { let (soft_confirmation_rule_enforcer, mut working_set) = get_soft_confirmation_rule_enforcer::(&TEST_CONFIG); - let mut signed_soft_confirmation_batch = SignedSoftConfirmation::new( - [0; 32], - [0; 32], - 0, - [0; 32], - [0; 32], - 100, - vec![], - vec![], - vec![], - vec![], - 1, - ); + let mut hook_soft_confirmation_info = sc_info_helper(); // call first with 100 fee rate to set last_l1_fee_rate - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + hook_soft_confirmation_info.l1_fee_rate = 100; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_ok()); // now call with 111 fee rate // should fail - signed_soft_confirmation_batch.set_l1_fee_rate(111); - - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + let mut hook_soft_confirmation_info = sc_info_helper(); + + hook_soft_confirmation_info.l1_fee_rate = 111; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_err()); assert_eq!( @@ -119,83 +79,60 @@ fn begin_soft_confirmation_hook_checks_l1_fee_rate() { // now call with 110 fee rate // should not fail - signed_soft_confirmation_batch.set_l1_fee_rate(110); - - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + let mut hook_soft_confirmation_info = sc_info_helper(); + + hook_soft_confirmation_info.l1_fee_rate = 110; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_ok()); // now 122 should'nt pass but 121 should - signed_soft_confirmation_batch.set_l1_fee_rate(122); - - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + let mut hook_soft_confirmation_info = sc_info_helper(); + + hook_soft_confirmation_info.l1_fee_rate = 122; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_err()); - signed_soft_confirmation_batch.set_l1_fee_rate(121); + let mut hook_soft_confirmation_info = sc_info_helper(); - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + hook_soft_confirmation_info.l1_fee_rate = 121; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_ok()); // reset back to 100 so calculations are easier - signed_soft_confirmation_batch.set_l1_fee_rate(109); - - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + let mut hook_soft_confirmation_info = sc_info_helper(); + + hook_soft_confirmation_info.l1_fee_rate = 109; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_ok()); - signed_soft_confirmation_batch.set_l1_fee_rate(100); - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + + let mut hook_soft_confirmation_info = sc_info_helper(); + + hook_soft_confirmation_info.l1_fee_rate = 100; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_ok()); - // change da root hash so it doesnt fail - signed_soft_confirmation_batch.set_da_slot_hash([1; 32]); + let mut hook_soft_confirmation_info = sc_info_helper(); + // change da root hash so it doesnt fail + hook_soft_confirmation_info.da_slot_hash = [1; 32]; // now 89 should'nt pass but 90 should - signed_soft_confirmation_batch.set_l1_fee_rate(89); - - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + hook_soft_confirmation_info.l1_fee_rate = 89; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_err()); @@ -204,31 +141,23 @@ fn begin_soft_confirmation_hook_checks_l1_fee_rate() { format!("{}", res.unwrap_err()) ); - signed_soft_confirmation_batch.set_l1_fee_rate(90); + let mut hook_soft_confirmation_info = sc_info_helper(); - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + hook_soft_confirmation_info.l1_fee_rate = 90; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_ok()); // since 90 passed now e.g. 89 should pass - signed_soft_confirmation_batch.set_l1_fee_rate(89); + let mut hook_soft_confirmation_info = sc_info_helper(); - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + hook_soft_confirmation_info.l1_fee_rate = 89; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_ok()); } @@ -240,56 +169,25 @@ fn begin_soft_confirmation_hook_checks_timestamp() { let original_timestamp = chrono::Local::now().timestamp() as u64; - let signed_soft_confirmation_batch = SignedSoftConfirmation::new( - [0; 32], - [0; 32], - 0, - [0; 32], - [0; 32], - 100, - vec![], - vec![], - vec![], - vec![], - original_timestamp, - ); + let mut hook_soft_confirmation_info = sc_info_helper(); + + hook_soft_confirmation_info.timestamp = original_timestamp; // call first with `original_timestamp` - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_ok()); // now call with a timestamp before the original one. // should fail - let signed_soft_confirmation_batch = SignedSoftConfirmation::new( - [0; 32], - [0; 32], - 0, - [0; 32], - [0; 32], - 100, - vec![], - vec![], - vec![], - vec![], - original_timestamp - 1000, - ); - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + let mut hook_soft_confirmation_info = sc_info_helper(); + + hook_soft_confirmation_info.timestamp = original_timestamp - 1000; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_err()); @@ -299,29 +197,13 @@ fn begin_soft_confirmation_hook_checks_timestamp() { ); // now call with a timestamp after the original one. - // should fail - let signed_soft_confirmation_batch = SignedSoftConfirmation::new( - [0; 32], - [0; 32], - 0, - [0; 32], - [0; 32], - 100, - vec![], - vec![], - vec![], - vec![], - original_timestamp + 1000, - ); + // should not fail + let mut hook_soft_confirmation_info = sc_info_helper(); - let res = soft_confirmation_rule_enforcer.begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ); + hook_soft_confirmation_info.timestamp = original_timestamp + 1000; + + let res = soft_confirmation_rule_enforcer + .begin_soft_confirmation_hook(&hook_soft_confirmation_info, &mut working_set); assert!(res.is_ok()); } diff --git a/crates/soft-confirmation-rule-enforcer/src/tests/mod.rs b/crates/soft-confirmation-rule-enforcer/src/tests/mod.rs index 40f631d83..03e86d8f0 100644 --- a/crates/soft-confirmation-rule-enforcer/src/tests/mod.rs +++ b/crates/soft-confirmation-rule-enforcer/src/tests/mod.rs @@ -6,3 +6,21 @@ mod genesis_tests; mod hooks_tests; #[cfg(test)] mod query_tests; + +use sov_modules_api::hooks::HookSoftConfirmationInfo; +use sov_modules_api::SpecId; + +fn sc_info_helper() -> HookSoftConfirmationInfo { + HookSoftConfirmationInfo { + l2_height: 1, + da_slot_height: 1, + da_slot_hash: [0; 32], + da_slot_txs_commitment: [0; 32], + pre_state_root: vec![0; 32], + current_spec: SpecId::Genesis, + pub_key: vec![0; 32], + deposit_data: vec![], + l1_fee_rate: 1, + timestamp: 10, + } +} diff --git a/crates/soft-confirmation-rule-enforcer/src/tests/query_tests.rs b/crates/soft-confirmation-rule-enforcer/src/tests/query_tests.rs index e5e557a50..7719ee395 100644 --- a/crates/soft-confirmation-rule-enforcer/src/tests/query_tests.rs +++ b/crates/soft-confirmation-rule-enforcer/src/tests/query_tests.rs @@ -1,40 +1,20 @@ use sov_mock_da::MockDaSpec; -use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::StateMapAccessor; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; -use sov_rollup_interface::spec::SpecId; use crate::tests::genesis_tests::{get_soft_confirmation_rule_enforcer, TEST_CONFIG}; +use crate::tests::sc_info_helper; #[test] fn block_count_per_da_hash_must_be_correct() { let (soft_confirmation_rule_enforcer, mut working_set) = get_soft_confirmation_rule_enforcer::(&TEST_CONFIG); - let mut signed_soft_confirmation_batch = SignedSoftConfirmation::new( - [0; 32], - [0; 32], - 0, - [0; 32], - [0; 32], - 1, - vec![], - vec![], - vec![], - vec![], - 0, - ); + let mut soft_confirmation_info = sc_info_helper(); + // call begin_slot_hook a couple times for da hash 0 for _ in 0..3 { soft_confirmation_rule_enforcer - .begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ) + .begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set) .unwrap(); } // the block count for da hash 0 should be 3 @@ -46,19 +26,13 @@ fn block_count_per_da_hash_must_be_correct() { 3 ); - signed_soft_confirmation_batch.set_da_slot_hash([1; 32]); + soft_confirmation_info.da_slot_hash = [1; 32]; // call with a different da hash soft_confirmation_rule_enforcer - .begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ) + .begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set) .unwrap(); + // the block count for da hash 1 should be 1 assert_eq!( soft_confirmation_rule_enforcer @@ -81,29 +55,8 @@ fn get_max_l1_fee_rate_change_percentage_must_be_correct() { 10 ); - let signed_soft_confirmation_batch = SignedSoftConfirmation::new( - [0; 32], - [0; 32], - 0, - [0; 32], - [0; 32], - 1, - vec![], - vec![], - vec![], - vec![], - 0, - ); - soft_confirmation_rule_enforcer - .begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ) + .begin_soft_confirmation_hook(&sc_info_helper(), &mut working_set) .unwrap(); // didn't change @@ -127,28 +80,8 @@ fn get_last_l1_fee_rate_must_be_correct() { 0 ); - let signed_soft_confirmation_batch = SignedSoftConfirmation::new( - [0; 32], - [0; 32], - 0, - [0; 32], - [0; 32], - 1, - vec![], - vec![], - vec![], - vec![], - 0, - ); soft_confirmation_rule_enforcer - .begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ) + .begin_soft_confirmation_hook(&sc_info_helper(), &mut working_set) .unwrap(); // now set to 1 @@ -173,28 +106,11 @@ fn get_last_timestamp_must_be_correct() { ); let timestamp = chrono::Local::now().timestamp() as u64; - let signed_soft_confirmation_batch = SignedSoftConfirmation::new( - [0; 32], - [0; 32], - 0, - [0; 32], - [0; 32], - 1, - vec![], - vec![], - vec![], - vec![], - timestamp, - ); + let mut soft_confirmation_info = sc_info_helper(); + soft_confirmation_info.timestamp = timestamp; + soft_confirmation_rule_enforcer - .begin_soft_confirmation_hook( - &mut HookSoftConfirmationInfo::new( - signed_soft_confirmation_batch.clone(), - vec![0; 32], - SpecId::Genesis, - ), - &mut working_set, - ) + .begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set) .unwrap(); assert_ne!( diff --git a/crates/sovereign-sdk/fuzz/Cargo.lock b/crates/sovereign-sdk/fuzz/Cargo.lock index 628369a09..b409a985f 100644 --- a/crates/sovereign-sdk/fuzz/Cargo.lock +++ b/crates/sovereign-sdk/fuzz/Cargo.lock @@ -3265,6 +3265,7 @@ name = "sov-rollup-interface" version = "0.4.0-rc.3" dependencies = [ "anyhow", + "arbitrary", "async-trait", "borsh", "bytes", @@ -3272,6 +3273,7 @@ dependencies = [ "futures", "hex", "proptest", + "proptest-derive", "serde", "sha2", "thiserror", diff --git a/crates/sovereign-sdk/fuzz/fuzz_targets/bank_call.rs b/crates/sovereign-sdk/fuzz/fuzz_targets/bank_call.rs index 6ad74849e..86d9dc9da 100644 --- a/crates/sovereign-sdk/fuzz/fuzz_targets/bank_call.rs +++ b/crates/sovereign-sdk/fuzz/fuzz_targets/bank_call.rs @@ -3,7 +3,7 @@ use libfuzzer_sys::fuzz_target; use sov_bank::{Bank, CallMessage}; use sov_modules_api::default_context::DefaultContext; -use sov_modules_api::{Context, Module, WorkingSet}; +use sov_modules_api::{Context, Module, SpecId, WorkingSet}; use sov_prover_storage_manager::new_orphan_storage; type C = DefaultContext; @@ -13,7 +13,7 @@ fuzz_target!(|input: (&[u8], [u8; 32], [u8; 32])| { if let Ok(msgs) = serde_json::from_slice::>>(data) { let tmpdir = tempfile::tempdir().unwrap(); let mut working_set = WorkingSet::new(new_orphan_storage(tmpdir.path()).unwrap()); - let ctx = C::new(sender.into(), sequencer.into(), 1); + let ctx = C::new(sender.into(), sequencer.into(), 1, SpecId::Genesis, 0); let bank = Bank::default(); for msg in msgs { bank.call(msg, &ctx, &mut working_set).ok(); diff --git a/crates/sovereign-sdk/module-system/module-implementations/examples/sov-accessory-state/tests/test.rs b/crates/sovereign-sdk/module-system/module-implementations/examples/sov-accessory-state/tests/test.rs index 36f7c57e8..22d3dd70e 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/examples/sov-accessory-state/tests/test.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/examples/sov-accessory-state/tests/test.rs @@ -3,7 +3,7 @@ use sov_accessory_state::{AccessorySetter, CallMessage}; use sov_modules_api::default_context::DefaultContext; use sov_modules_api::prelude::*; -use sov_modules_api::{Address, Context, Module, WorkingSet}; +use sov_modules_api::{Address, Context, Module, SpecId, WorkingSet}; use sov_prover_storage_manager::new_orphan_storage; use sov_state::Storage; @@ -20,7 +20,7 @@ fn test_accessory_value_setter() { let admin = Address::from([1; 32]); let sequencer = Address::from([2; 32]); - let context = DefaultContext::new(admin, sequencer, 1); + let context = DefaultContext::new(admin, sequencer, 1, SpecId::Genesis, 0); let module = AccessorySetter::::default(); diff --git a/crates/sovereign-sdk/module-system/module-implementations/examples/sov-value-setter/src/tests.rs b/crates/sovereign-sdk/module-system/module-implementations/examples/sov-value-setter/src/tests.rs index b1a70a4e6..5244cf309 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/examples/sov-value-setter/src/tests.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/examples/sov-value-setter/src/tests.rs @@ -16,7 +16,7 @@ fn test_value_setter() { #[cfg(feature = "native")] { let config = ValueSetterConfig { admin }; - let context = DefaultContext::new(admin, sequencer, 1); + let context = DefaultContext::new(admin, sequencer, 1, sov_modules_api::SpecId::Genesis, 0); test_value_setter_helper(context, &config, &mut working_set); } @@ -25,7 +25,8 @@ fn test_value_setter() { // Test Zk-Context { let config = ValueSetterConfig { admin }; - let zk_context = ZkDefaultContext::new(admin, sequencer, 1); + let zk_context = + ZkDefaultContext::new(admin, sequencer, 1, sov_modules_api::SpecId::Genesis, 0); let mut zk_working_set = WorkingSet::with_witness(ZkStorage::new(), witness); test_value_setter_helper(zk_context, &config, &mut zk_working_set); } @@ -77,7 +78,8 @@ fn test_err_on_sender_is_not_admin() { let config = ValueSetterConfig { admin: sender_not_admin, }; - let context = DefaultContext::new(sender, sequencer, 1); + let context = + DefaultContext::new(sender, sequencer, 1, sov_modules_api::SpecId::Genesis, 0); test_err_on_sender_is_not_admin_helper(context, &config, &mut prover_working_set); } let (_, witness) = prover_working_set.checkpoint().freeze(); @@ -88,7 +90,8 @@ fn test_err_on_sender_is_not_admin() { admin: sender_not_admin, }; let zk_backing_store = ZkStorage::new(); - let zk_context = ZkDefaultContext::new(sender, sequencer, 1); + let zk_context = + ZkDefaultContext::new(sender, sequencer, 1, sov_modules_api::SpecId::Genesis, 0); let zk_working_set = &mut WorkingSet::with_witness(zk_backing_store, witness); test_err_on_sender_is_not_admin_helper(zk_context, &config, zk_working_set); } diff --git a/crates/sovereign-sdk/module-system/module-implementations/examples/sov-vec-setter/tests/tests.rs b/crates/sovereign-sdk/module-system/module-implementations/examples/sov-vec-setter/tests/tests.rs index 9883727ca..6408e8f1b 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/examples/sov-vec-setter/tests/tests.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/examples/sov-vec-setter/tests/tests.rs @@ -41,7 +41,8 @@ fn test_vec_setter_calls() { vec_setter.genesis(&config, &mut working_set).unwrap(); for (sender, sequencer, call, expected_contents) in test_cases().iter().cloned() { - let context = DefaultContext::new(sender, sequencer, 1); + let context = + DefaultContext::new(sender, sequencer, 1, sov_modules_api::SpecId::Genesis, 0); let call_result = vec_setter.call(call, &context, &mut working_set); diff --git a/crates/sovereign-sdk/module-system/module-implementations/module-template/tests/value_setter.rs b/crates/sovereign-sdk/module-system/module-implementations/module-template/tests/value_setter.rs index 550205960..cc5e7fc3b 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/module-template/tests/value_setter.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/module-template/tests/value_setter.rs @@ -1,6 +1,6 @@ use module_template::{CallMessage, ExampleModule, ExampleModuleConfig, Response}; use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; -use sov_modules_api::{Address, Context, Event, Module, WorkingSet}; +use sov_modules_api::{Address, Context, Event, Module, SpecId, WorkingSet}; use sov_prover_storage_manager::new_orphan_storage; use sov_state::{DefaultStorageSpec, ZkStorage}; @@ -17,7 +17,7 @@ fn test_value_setter() { // Test Native-Context { let config = ExampleModuleConfig {}; - let context = DefaultContext::new(admin, sequencer, 1); + let context = DefaultContext::new(admin, sequencer, 1, SpecId::Genesis, 0); test_value_setter_helper(context, &config, &mut working_set); } @@ -26,7 +26,7 @@ fn test_value_setter() { // Test Zk-Context { let config = ExampleModuleConfig {}; - let zk_context = ZkDefaultContext::new(admin, sequencer, 1); + let zk_context = ZkDefaultContext::new(admin, sequencer, 1, SpecId::Genesis, 0); let mut zk_working_set = WorkingSet::with_witness(ZkStorage::new(), witness); test_value_setter_helper(zk_context, &config, &mut zk_working_set); } diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/archival_query_test.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/archival_query_test.rs index e19d47a56..5536d4eac 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/archival_query_test.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/archival_query_test.rs @@ -3,7 +3,7 @@ mod helpers; use helpers::*; use sov_bank::{get_genesis_token_address, Amount, Bank, CallMessage, Coins}; use sov_modules_api::default_context::DefaultContext; -use sov_modules_api::{Address, Context, Module, StateReaderAndWriter, WorkingSet}; +use sov_modules_api::{Address, Context, Module, SpecId, StateReaderAndWriter, WorkingSet}; use sov_prover_storage_manager::{new_orphan_storage, SnapshotManager}; use sov_state::storage::{StorageKey, StorageValue}; use sov_state::{DefaultStorageSpec, ProverStorage, Storage}; @@ -264,7 +264,7 @@ fn transfer( }, }; - let sender_context = C::new(sender_address, sequencer_address, 1); + let sender_context = C::new(sender_address, sequencer_address, 1, SpecId::Genesis, 0); bank.call(transfer_message, &sender_context, working_set) .expect("Transfer call failed"); diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/burn_test.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/burn_test.rs index 29a153ab4..8cfb4f71d 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/burn_test.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/burn_test.rs @@ -4,7 +4,7 @@ use sov_bank::{ TotalSupplyResponse, }; use sov_modules_api::default_context::DefaultContext; -use sov_modules_api::{Address, Context, Error, Module, WorkingSet}; +use sov_modules_api::{Address, Context, Error, Module, SpecId, WorkingSet}; use sov_prover_storage_manager::{new_orphan_storage, SnapshotManager}; use sov_state::{DefaultStorageSpec, ProverStorage}; @@ -24,9 +24,9 @@ fn burn_deployed_tokens() { let sender_address = generate_address("just_sender"); let sequencer_address = generate_address("sequencer"); - let sender_context = C::new(sender_address, sequencer_address, 1); + let sender_context = C::new(sender_address, sequencer_address, 1, SpecId::Genesis, 0); let minter_address = generate_address("minter"); - let minter_context = C::new(minter_address, sequencer_address, 1); + let minter_context = C::new(minter_address, sequencer_address, 1, SpecId::Genesis, 0); let salt = 0; let token_name = "Token1".to_owned(); @@ -214,7 +214,7 @@ fn burn_initial_tokens() { }, }; - let context = C::new(sender_address, sequencer_address, 1); + let context = C::new(sender_address, sequencer_address, 1, SpecId::Genesis, 0); bank.call(burn_message, &context, &mut working_set) .expect("Failed to burn token"); assert!(working_set.events().is_empty()); diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/create_token_test.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/create_token_test.rs index 09e315d4a..35f47a355 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/create_token_test.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/create_token_test.rs @@ -1,7 +1,7 @@ use helpers::*; use sov_bank::{get_token_address, Bank, CallMessage}; use sov_modules_api::utils::generate_address; -use sov_modules_api::{Context, Module, WorkingSet}; +use sov_modules_api::{Context, Module, SpecId, WorkingSet}; use sov_prover_storage_manager::new_orphan_storage; mod helpers; @@ -16,7 +16,7 @@ fn initial_and_deployed_token() { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); - let sender_context = C::new(sender_address, sequencer_address, 1); + let sender_context = C::new(sender_address, sequencer_address, 1, SpecId::Genesis, 0); let minter_address = generate_address::("minter"); let initial_balance = 500; let token_name = "Token1".to_owned(); diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/freeze_test.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/freeze_test.rs index a1e6441ec..3efa22c92 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/freeze_test.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/freeze_test.rs @@ -2,7 +2,7 @@ use helpers::C; use sov_bank::{get_token_address, Bank, BankConfig, CallMessage, Coins, TotalSupplyResponse}; use sov_modules_api::default_context::DefaultContext; use sov_modules_api::utils::generate_address; -use sov_modules_api::{Address, Context, Error, Module, WorkingSet}; +use sov_modules_api::{Address, Context, Error, Module, SpecId, WorkingSet}; use sov_prover_storage_manager::{new_orphan_storage, SnapshotManager}; use sov_state::{DefaultStorageSpec, ProverStorage}; @@ -20,7 +20,7 @@ fn freeze_token() { let minter_address = generate_address::("minter"); let sequencer_address = generate_address::("sequencer"); - let minter_context = C::new(minter_address, sequencer_address, 1); + let minter_context = C::new(minter_address, sequencer_address, 1, SpecId::Genesis, 0); let salt = 0; let token_name = "Token1".to_owned(); @@ -94,7 +94,13 @@ fn freeze_token() { // Try to freeze with a non authorized minter let unauthorized_address = generate_address::("unauthorized_address"); let sequencer_address = generate_address::("sequencer"); - let unauthorized_context = C::new(unauthorized_address, sequencer_address, 1); + let unauthorized_context = C::new( + unauthorized_address, + sequencer_address, + 1, + SpecId::Genesis, + 0, + ); let freeze_message = CallMessage::Freeze { token_address: token_address_2, }; diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/gas_test.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/gas_test.rs index 8c7dd36ee..5f422cfb4 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/gas_test.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/gas_test.rs @@ -2,7 +2,7 @@ use helpers::*; use sov_bank::{get_genesis_token_address, Bank, BankConfig, CallMessage, TokenConfig}; use sov_modules_api::macros::config_constant; use sov_modules_api::utils::generate_address; -use sov_modules_api::{Context, Module, WorkingSet}; +use sov_modules_api::{Context, Module, SpecId, WorkingSet}; use sov_prover_storage_manager::new_orphan_storage; use tempfile::TempDir; @@ -51,7 +51,13 @@ impl BankGasTestCase { let height = 1; let minter_address = generate_address::("minter"); let sequencer_address = generate_address::("sequencer"); - let ctx = C::new(sender_address, sequencer_address, height); + let ctx = C::new( + sender_address, + sequencer_address, + height, + SpecId::Genesis, + 0, + ); // create a bank instance let bank = Bank::default(); diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/mint_test.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/mint_test.rs index 0708ba926..97d4a5852 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/mint_test.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/mint_test.rs @@ -2,7 +2,7 @@ use helpers::C; use sov_bank::{get_token_address, Bank, BankConfig, CallMessage, Coins, TotalSupplyResponse}; use sov_modules_api::default_context::DefaultContext; use sov_modules_api::utils::generate_address; -use sov_modules_api::{Address, Context, Error, Module, WorkingSet}; +use sov_modules_api::{Address, Context, Error, Module, SpecId, WorkingSet}; use sov_prover_storage_manager::{new_orphan_storage, SnapshotManager}; use sov_state::{DefaultStorageSpec, ProverStorage}; @@ -20,7 +20,7 @@ fn mint_token() { let minter_address = generate_address::("minter"); let sequencer_address = generate_address::("sequencer"); - let minter_context = C::new(minter_address, sequencer_address, 1); + let minter_context = C::new(minter_address, sequencer_address, 1, SpecId::Genesis, 0); let salt = 0; let token_name = "Token1".to_owned(); @@ -88,7 +88,13 @@ fn mint_token() { // Mint with an un-authorized user let unauthorized_address = generate_address::("unauthorized_address"); let sequencer_address = generate_address::("sequencer"); - let unauthorized_context = C::new(unauthorized_address, sequencer_address, 1); + let unauthorized_context = C::new( + unauthorized_address, + sequencer_address, + 1, + SpecId::Genesis, + 0, + ); let unauthorized_mint = bank.call(mint_message, &unauthorized_context, &mut working_set); assert!(unauthorized_mint.is_err()); @@ -172,7 +178,13 @@ fn mint_token() { message_2 ); // Try to mint new token with authorized sender 2 - let authorized_minter_2_context = C::new(authorized_minter_address_2, sequencer_address, 1); + let authorized_minter_2_context = C::new( + authorized_minter_address_2, + sequencer_address, + 1, + SpecId::Genesis, + 0, + ); let mint_message = CallMessage::Mint { coins: Coins { amount: mint_amount, @@ -189,7 +201,13 @@ fn mint_token() { assert_eq!(Some(110), supply); // Try to mint new token with authorized sender 1 - let authorized_minter_1_context = C::new(authorized_minter_address_1, sequencer_address, 1); + let authorized_minter_1_context = C::new( + authorized_minter_address_1, + sequencer_address, + 1, + SpecId::Genesis, + 0, + ); let mint_message = CallMessage::Mint { coins: Coins { amount: mint_amount, diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/transfer_test.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/transfer_test.rs index 6af81b538..b9437b7a4 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/transfer_test.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-bank/tests/transfer_test.rs @@ -7,7 +7,7 @@ use sov_bank::{ }; use sov_modules_api::default_context::DefaultContext; use sov_modules_api::utils::generate_address; -use sov_modules_api::{Address, Context, Error, Module, WorkingSet}; +use sov_modules_api::{Address, Context, Error, Module, SpecId, WorkingSet}; use sov_prover_storage_manager::{new_orphan_storage, SnapshotManager}; use sov_state::{DefaultStorageSpec, ProverStorage}; @@ -51,7 +51,7 @@ fn transfer_initial_token() { assert_eq!(Some(initial_balance), sender_balance_before); assert_eq!(sender_balance_before, receiver_balance_before); - let sender_context = C::new(sender_address, sequencer_address, 1); + let sender_context = C::new(sender_address, sequencer_address, 1, SpecId::Genesis, 0); // Transfer happy test { @@ -159,7 +159,7 @@ fn transfer_initial_token() { { let unknown_sender = generate_address::("non_existing_sender"); let sequencer = generate_address::("sequencer"); - let unknown_sender_context = C::new(unknown_sender, sequencer, 1); + let unknown_sender_context = C::new(unknown_sender, sequencer, 1, SpecId::Genesis, 0); let sender_balance = query_user_balance(unknown_sender, &mut working_set); assert!(sender_balance.is_none()); @@ -293,7 +293,7 @@ fn transfer_deployed_token() { assert!(sender_balance_before.is_none()); assert!(receiver_balance_before.is_none()); - let sender_context = C::new(sender_address, sequencer_address, 1); + let sender_context = C::new(sender_address, sequencer_address, 1, SpecId::Genesis, 0); let mint_message = CallMessage::CreateToken { salt, diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-prover-incentives/src/tests.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-prover-incentives/src/tests.rs index 7d59d08ea..3ae427280 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-prover-incentives/src/tests.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-prover-incentives/src/tests.rs @@ -3,7 +3,7 @@ use sov_mock_zkvm::{MockCodeCommitment, MockProof, MockZkvm}; use sov_modules_api::default_context::DefaultContext; use sov_modules_api::digest::Digest; use sov_modules_api::prelude::*; -use sov_modules_api::{Address, Context, Module, Spec, WorkingSet}; +use sov_modules_api::{Address, Context, Module, Spec, SpecId, WorkingSet}; use sov_prover_storage_manager::new_orphan_storage; use crate::ProverIncentives; @@ -92,7 +92,7 @@ fn test_burn_on_invalid_proof() { // Process an invalid proof { - let context = DefaultContext::new(prover_address, sequencer, 1); + let context = DefaultContext::new(prover_address, sequencer, 1, SpecId::Genesis, 0); let proof = MockProof { program_id: MOCK_CODE_COMMITMENT, is_valid: false, @@ -128,7 +128,7 @@ fn test_valid_proof() { // Process a valid proof { - let context = DefaultContext::new(prover_address, sequencer, 1); + let context = DefaultContext::new(prover_address, sequencer, 1, SpecId::Genesis, 0); let proof = MockProof { program_id: MOCK_CODE_COMMITMENT, is_valid: true, @@ -153,7 +153,7 @@ fn test_unbonding() { let tmpdir = tempfile::tempdir().unwrap(); let mut working_set = WorkingSet::new(new_orphan_storage(tmpdir.path()).unwrap()); let (module, prover_address, sequencer) = setup(&mut working_set); - let context = DefaultContext::new(prover_address, sequencer, 1); + let context = DefaultContext::new(prover_address, sequencer, 1, SpecId::Genesis, 0); let token_address = module .bonding_token_address .get(&mut working_set) @@ -204,7 +204,7 @@ fn test_prover_not_bonded() { let tmpdir = tempfile::tempdir().unwrap(); let mut working_set = WorkingSet::new(new_orphan_storage(tmpdir.path()).unwrap()); let (module, prover_address, sequencer) = setup(&mut working_set); - let context = DefaultContext::new(prover_address, sequencer, 1); + let context = DefaultContext::new(prover_address, sequencer, 1, SpecId::Genesis, 0); // Unbond the prover module diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-sequencer-registry/tests/sequencer_registry_test.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-sequencer-registry/tests/sequencer_registry_test.rs index a830bac6c..7d12ffbaf 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-sequencer-registry/tests/sequencer_registry_test.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-sequencer-registry/tests/sequencer_registry_test.rs @@ -1,6 +1,6 @@ use helpers::*; use sov_mock_da::MockAddress; -use sov_modules_api::{Context, Error, Module, ModuleInfo, WorkingSet}; +use sov_modules_api::{Context, Error, Module, ModuleInfo, SpecId, WorkingSet}; use sov_prover_storage_manager::new_orphan_storage; use sov_sequencer_registry::{CallMessage, SequencerRegistry}; @@ -34,7 +34,7 @@ fn test_registration_lifecycle() { let sequencer_address = generate_address(ANOTHER_SEQUENCER_KEY); let reward_address = generate_address(REWARD_SEQUENCER_KEY); - let sender_context = C::new(sequencer_address, reward_address, 1); + let sender_context = C::new(sequencer_address, reward_address, 1, SpecId::Genesis, 0); let balance_before = test_sequencer .query_balance(sequencer_address, working_set) @@ -105,7 +105,7 @@ fn test_registration_not_enough_funds() { let sequencer_address = generate_address(LOW_FUND_KEY); let reward_address = generate_address(REWARD_SEQUENCER_KEY); - let sender_context = C::new(sequencer_address, reward_address, 1); + let sender_context = C::new(sequencer_address, reward_address, 1, SpecId::Genesis, 0); let register_message = CallMessage::Register { da_address: da_address.as_ref().to_vec(), @@ -159,7 +159,7 @@ fn test_registration_second_time() { let sequencer_address = generate_address(GENESIS_SEQUENCER_KEY); let reward_address = generate_address(REWARD_SEQUENCER_KEY); - let sender_context = C::new(sequencer_address, reward_address, 1); + let sender_context = C::new(sequencer_address, reward_address, 1, SpecId::Genesis, 0); let register_message = CallMessage::Register { da_address: da_address.as_ref().to_vec(), @@ -184,9 +184,9 @@ fn test_exit_different_sender() { let sequencer_address = generate_address(ANOTHER_SEQUENCER_KEY); let reward_address = generate_address(REWARD_SEQUENCER_KEY); - let sender_context = C::new(sequencer_address, reward_address, 1); + let sender_context = C::new(sequencer_address, reward_address, 1, SpecId::Genesis, 0); let attacker_address = generate_address("some_random_key"); - let attacker_context = C::new(attacker_address, reward_address, 1); + let attacker_context = C::new(attacker_address, reward_address, 1, SpecId::Genesis, 0); let register_message = CallMessage::Register { da_address: ANOTHER_SEQUENCER_DA_ADDRESS.to_vec(), @@ -221,7 +221,7 @@ fn test_allow_exit_last_sequencer() { let sequencer_address = generate_address(GENESIS_SEQUENCER_KEY); let rewards_address = generate_address(REWARD_SEQUENCER_KEY); - let sender_context = C::new(sequencer_address, rewards_address, 1); + let sender_context = C::new(sequencer_address, rewards_address, 1, SpecId::Genesis, 0); let exit_message = CallMessage::Exit { da_address: GENESIS_SEQUENCER_DA_ADDRESS.to_vec(), }; @@ -264,7 +264,7 @@ fn test_preferred_sequencer_returned_and_removed() { let sequencer_address = generate_address(GENESIS_SEQUENCER_KEY); let reward_address = generate_address(REWARD_SEQUENCER_KEY); - let sender_context = C::new(sequencer_address, reward_address, 1); + let sender_context = C::new(sequencer_address, reward_address, 1, SpecId::Genesis, 0); let exit_message = CallMessage::Exit { da_address: GENESIS_SEQUENCER_DA_ADDRESS.to_vec(), }; diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/versioned_value.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/versioned_value.rs index 08e2088a1..fabf9f79c 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/versioned_value.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/versioned_value.rs @@ -287,6 +287,7 @@ mod tests { use sov_modules_core::capabilities::mocks::MockKernel; use sov_modules_core::{Address, Context, KernelWorkingSet, Prefix, WorkingSet}; use sov_prover_storage_manager::new_orphan_storage; + use sov_rollup_interface::spec::SpecId; use crate::default_context::DefaultContext; use crate::VersionedStateValue; @@ -313,14 +314,24 @@ mod tests { { { - let mut versioned_state = - working_set.versioned_state(&DefaultContext::new(signer, sequencer, 1)); + let mut versioned_state = working_set.versioned_state(&DefaultContext::new( + signer, + sequencer, + 1, + sov_rollup_interface::spec::SpecId::Genesis, + 0, + )); // Try to read the value from user space with the slot number set to 1. Should fail. assert_eq!(value.get_current(&mut versioned_state), None); } // Try to read the value from user space with the slot number set to 4. Should succeed. - let mut versioned_state = - working_set.versioned_state(&DefaultContext::new(signer, sequencer, 4)); + let mut versioned_state = working_set.versioned_state(&DefaultContext::new( + signer, + sequencer, + 4, + sov_rollup_interface::spec::SpecId::Genesis, + 0, + )); // Try to read the value from user space with the slot number set to 1. Should fail. assert_eq!(value.get_current(&mut versioned_state), Some(100)); } @@ -350,22 +361,37 @@ mod tests { { { - let mut versioned_state = - working_set.versioned_state(&DefaultContext::new(signer, sequencer, 1)); + let mut versioned_state = working_set.versioned_state(&DefaultContext::new( + signer, + sequencer, + 1, + SpecId::Genesis, + 0, + )); // Try to read the value from user space with the slot number set to 1. Should fail. assert_eq!(value.get_current(&mut versioned_state), None); } { // Try to read the value from user space with the slot number set to 2. Should succeed. - let mut versioned_state = - working_set.versioned_state(&DefaultContext::new(signer, sequencer, 2)); + let mut versioned_state = working_set.versioned_state(&DefaultContext::new( + signer, + sequencer, + 2, + SpecId::Genesis, + 0, + )); assert_eq!(value.get_current(&mut versioned_state), Some(100)); } // Try to read the value from user space with the slot number set to 4. Should succeed. - let mut versioned_state = - working_set.versioned_state(&DefaultContext::new(signer, sequencer, 4)); + let mut versioned_state = working_set.versioned_state(&DefaultContext::new( + signer, + sequencer, + 4, + SpecId::Genesis, + 0, + )); assert_eq!(value.get_current(&mut versioned_state), Some(17)); } } diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs index 5a3bcbd36..f4f14f154 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs @@ -8,6 +8,8 @@ pub mod default_signature; pub mod hooks; mod pub_key_hex; +pub use sov_rollup_interface::spec::SpecId; + #[cfg(feature = "macros")] mod reexport_macros; #[cfg(feature = "macros")] diff --git a/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs b/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs index 7e628afaf..6abfd8834 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs @@ -1,7 +1,6 @@ //! Runtime call message definitions. use borsh::io; -use sov_rollup_interface::spec::SpecId; use crate::common::ModuleError; use crate::module::{CallResponse, Context, Spec}; diff --git a/crates/sovereign-sdk/module-system/sov-modules-core/tests/working_set_tests.rs b/crates/sovereign-sdk/module-system/sov-modules-core/tests/working_set_tests.rs index 3784479ea..2f44af5af 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-core/tests/working_set_tests.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-core/tests/working_set_tests.rs @@ -1,5 +1,6 @@ use sov_mock_da::MockDaSpec; use sov_modules_api::default_context::DefaultContext; +use sov_modules_api::SpecId; use sov_modules_core::capabilities::mocks::MockKernel; use sov_modules_core::{ Address, Context, KernelWorkingSet, StateReaderAndWriter, StorageKey, StorageValue, WorkingSet, @@ -36,7 +37,13 @@ fn test_versioned_workingset_get() { let sender = Address::from([1; 32]); let sequencer = Address::from([2; 32]); let mut working_set = WorkingSet::::new(storage.clone()); - let mut working_set = working_set.versioned_state(&DefaultContext::new(sender, sequencer, 1)); + let mut working_set = working_set.versioned_state(&DefaultContext::new( + sender, + sequencer, + 1, + SpecId::Genesis, + 0, + )); working_set.set(&storage_key, storage_value.clone()); assert_eq!(Some(storage_value), working_set.get(&storage_key)); diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs index 7a942bbfb..b2ce13e2f 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs @@ -4,7 +4,7 @@ use modules::{first_test_module, second_test_module}; use sov_modules_api::default_context::ZkDefaultContext; use sov_modules_api::macros::DefaultRuntime; use sov_modules_api::{ - Address, Context, DispatchCall, EncodeCall, Genesis, MessageCodec, ModuleInfo, + Address, Context, DispatchCall, EncodeCall, Genesis, MessageCodec, ModuleInfo, SpecId, }; use sov_rollup_interface::spec::SpecId; use sov_state::ZkStorage; @@ -31,7 +31,7 @@ fn main() { runtime.genesis(&config, working_set).unwrap(); let sender = Address::try_from([0; 32].as_ref()).unwrap(); let sequencer = Address::try_from([1; 32].as_ref()).unwrap(); - let context = ZkDefaultContext::new(sender, sequencer, 1); + let context = ZkDefaultContext::new(sender, sequencer, 1, SpecId::Genesis, 0); let value = 11; { diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index f577d85da..b3f7d4dd2 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -5,13 +5,11 @@ use sov_modules_api::{ native_debug, native_error, Context, DaSpec, DispatchCall, StateCheckpoint, WorkingSet, }; use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; -use sov_rollup_interface::spec::SpecId; use sov_rollup_interface::stf::{ SoftConfirmationError, SoftConfirmationReceipt, TransactionReceipt, }; -use sov_state::Storage; -#[cfg(all(target_os = "zkvm", feature = "bench"))] -use sov_zk_cycle_macros::cycle_tracker; +// #[cfg(all(target_os = "zkvm", feature = "bench"))] +// use sov_zk_cycle_macros::cycle_tracker; #[cfg(feature = "native")] use tracing::instrument; diff --git a/crates/sovereign-sdk/rollup-interface/Cargo.toml b/crates/sovereign-sdk/rollup-interface/Cargo.toml index bc68a0f19..5fbadaab1 100644 --- a/crates/sovereign-sdk/rollup-interface/Cargo.toml +++ b/crates/sovereign-sdk/rollup-interface/Cargo.toml @@ -33,18 +33,15 @@ tokio = { workspace = true, optional = true } proptest = { workspace = true, optional = true } proptest-derive = { workspace = true, optional = true } - [dev-dependencies] serde_json = { workspace = true } -proptest = { workspace = true } -proptest-derive = { workspace = true } [features] default = ["std"] native = ["std", "tokio", "futures"] -fuzzing = ["proptest", "proptest-derive", "sha2", "std"] -testing = ["native"] -arbitrary = ["dep:arbitrary"] +fuzzing = ["dep:proptest", "dep:proptest-derive", "dep:sha2", "std"] +testing = ["native", "dep:proptest", "dep:proptest-derive"] +arbitrary = ["dep:arbitrary", "dep:proptest", "dep:proptest-derive"] std = [ "anyhow/default", "borsh/default", From 5f6b66be09b172aab26cc99a9ce09b0149c1b031 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Thu, 29 Aug 2024 16:17:57 +0300 Subject: [PATCH 09/17] remove l1 fee rate from evm state --- crates/citrea-stf/src/hooks_impl.rs | 4 +- crates/evm/src/call.rs | 13 +- crates/evm/src/hooks.rs | 28 +- crates/evm/src/lib.rs | 4 - crates/evm/src/query.rs | 84 ++--- crates/evm/src/tests/call_tests.rs | 340 +++++++++--------- .../tests/ef_tests/cases/blockchain_test.rs | 30 +- crates/evm/src/tests/hooks_tests.rs | 276 +++++++------- .../evm/src/tests/queries/evm_call_tests.rs | 30 +- crates/evm/src/tests/queries/log_tests.rs | 150 ++++---- crates/evm/src/tests/queries/mod.rs | 180 +++++----- crates/evm/src/tests/sys_tx_tests.rs | 340 +++++++++--------- crates/evm/src/tests/utils.rs | 33 +- crates/fullnode/tests/hash_stf.rs | 1 + crates/sequencer/src/sequencer.rs | 1 + .../examples/demo-stf/src/hooks_impl.rs | 1 + .../sov-modules-api/src/hooks.rs | 1 + .../sov-modules-stf-blueprint/src/lib.rs | 13 +- .../src/stf_blueprint.rs | 9 +- 19 files changed, 725 insertions(+), 813 deletions(-) diff --git a/crates/citrea-stf/src/hooks_impl.rs b/crates/citrea-stf/src/hooks_impl.rs index 363606f6e..d40693951 100644 --- a/crates/citrea-stf/src/hooks_impl.rs +++ b/crates/citrea-stf/src/hooks_impl.rs @@ -101,9 +101,11 @@ impl ApplySoftConfirmationHooks for Runtime { #[cfg_attr(feature = "native", instrument(level = "trace", skip_all, err, ret))] fn end_soft_confirmation_hook( &self, + soft_confirmation_info: &HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { - self.evm.end_soft_confirmation_hook(working_set); + self.evm + .end_soft_confirmation_hook(soft_confirmation_info, working_set); Ok(()) } } diff --git a/crates/evm/src/call.rs b/crates/evm/src/call.rs index 312ae9191..6c2274604 100644 --- a/crates/evm/src/call.rs +++ b/crates/evm/src/call.rs @@ -33,6 +33,7 @@ impl Evm { pub(crate) fn execute_system_events( &self, system_events: Vec, + l1_fee_rate: u128, working_set: &mut WorkingSet, ) { let block_env = self @@ -43,11 +44,6 @@ impl Evm { let cfg = self.cfg.get(working_set).expect("Evm config must be set"); let cfg_env: CfgEnvWithHandlerCfg = get_cfg_env(&block_env, cfg); - let l1_fee_rate = self - .l1_fee_rate - .get(working_set) - .expect("L1 fee rate must be set"); - let l1_block_hash_exists = self .accounts .get(&BitcoinLightClient::address(), working_set) @@ -128,7 +124,7 @@ impl Evm { pub(crate) fn execute_call( &self, txs: Vec, - _context: &C, + context: &C, working_set: &mut WorkingSet, ) -> Result { let users_txs: Vec = txs @@ -147,10 +143,7 @@ impl Evm { let cfg = self.cfg.get(working_set).expect("Evm config must be set"); let cfg_env: CfgEnvWithHandlerCfg = get_cfg_env(&block_env, cfg); - let l1_fee_rate = self - .l1_fee_rate - .get(working_set) - .expect("L1 fee rate must be set"); + let l1_fee_rate = context.l1_fee_rate(); let mut citrea_handler_ext = CitreaExternal::new(l1_fee_rate); let block_number = block_env.number; diff --git a/crates/evm/src/hooks.rs b/crates/evm/src/hooks.rs index 0b7dbc2cb..b3b5e3d03 100644 --- a/crates/evm/src/hooks.rs +++ b/crates/evm/src/hooks.rs @@ -95,11 +95,13 @@ where }; self.block_env.set(&new_pending_env, working_set); - self.l1_fee_rate - .set(&soft_confirmation_info.l1_fee_rate, working_set); if !system_events.is_empty() { - self.execute_system_events(system_events, working_set); + self.execute_system_events( + system_events, + soft_confirmation_info.l1_fee_rate(), + working_set, + ); } // if height > 256, start removing the oldest block @@ -119,7 +121,11 @@ where /// Logic executed at the end of the slot. Here, we generate an authenticated block and set it as the new head of the chain. /// It's important to note that the state root hash is not known at this moment, so we postpone setting this field until the begin_slot_hook of the next slot. #[cfg_attr(feature = "native", instrument(level = "trace", skip_all, ret))] - pub fn end_soft_confirmation_hook(&self, working_set: &mut WorkingSet) { + pub fn end_soft_confirmation_hook( + &self, + soft_confirmation_info: &HookSoftConfirmationInfo, + working_set: &mut WorkingSet, + ) { let cfg = self .cfg .get(working_set) @@ -130,15 +136,7 @@ where .get(working_set) .expect("Pending block should always be set"); - let l1_fee_rate = self - .l1_fee_rate - .get(working_set) - .expect("L1 fee rate must be set"); - - let l1_hash = self - .last_l1_hash - .get(working_set) - .expect("Last L1 hash must be set"); + let l1_hash = soft_confirmation_info.da_slot_hash; let parent_block = self .head @@ -216,8 +214,8 @@ where let block = Block { header, - l1_fee_rate, - l1_hash, + l1_fee_rate: soft_confirmation_info.l1_fee_rate(), + l1_hash: l1_hash.into(), transactions: start_tx_index..start_tx_index + pending_transactions.len() as u64, }; diff --git a/crates/evm/src/lib.rs b/crates/evm/src/lib.rs index d2b235347..4aa86eb52 100644 --- a/crates/evm/src/lib.rs +++ b/crates/evm/src/lib.rs @@ -109,10 +109,6 @@ pub struct Evm { #[state] pub(crate) latest_block_hashes: sov_modules_api::StateMap, - /// L1 fee rate. - #[state] - pub(crate) l1_fee_rate: sov_modules_api::StateValue, - /// Transaction's hash that failed to pay the L1 fee. /// Used to prevent DOS attacks. /// The vector is cleared in `finalize_hook`. diff --git a/crates/evm/src/query.rs b/crates/evm/src/query.rs index 003c249ce..a2a821009 100644 --- a/crates/evm/src/query.rs +++ b/crates/evm/src/query.rs @@ -723,35 +723,21 @@ impl Evm { let mut request = request.clone(); - let (l1_fee_rate, mut block_env) = match block_number { - None | Some(BlockNumberOrTag::Pending | BlockNumberOrTag::Latest) => { - // so we don't unnecessarily set archival version - // if no block was produced yet, the l1 fee rate can unwrap to 0, we don't care, else just return the latest - let l1_fee_rate = self.l1_fee_rate.get(working_set).unwrap_or_default(); - // if no block is produced yet, should default to genesis block env, else just return the lates - let block_env = self.block_env.get(working_set).unwrap_or_else(|| { - BlockEnv::from( - &self - .get_sealed_block_by_number( - Some(BlockNumberOrTag::Earliest), - working_set, - ) - .unwrap() - .expect("Genesis block must be set"), - ) - }); - (l1_fee_rate, block_env) - } - _ => { - let block = match self.get_sealed_block_by_number(block_number, working_set)? { - Some(block) => block, - None => return Err(EthApiError::UnknownBlockNumber.into()), - }; + let (l1_fee_rate, mut block_env, block_num) = { + let block = match self.get_sealed_block_by_number(block_number, working_set)? { + Some(block) => block, + None => return Err(EthApiError::UnknownBlockNumber.into()), + }; + let l1_fee_rate = block.l1_fee_rate; + let block_env = BlockEnv::from(&block); - set_state_to_end_of_evm_block(block.header.number, working_set); - let l1_fee_rate = block.l1_fee_rate; - let block_env = BlockEnv::from(&block); - (l1_fee_rate, block_env) + (l1_fee_rate, block_env, block.header.number) + }; + + match block_number { + None | Some(BlockNumberOrTag::Pending | BlockNumberOrTag::Latest) => {} + _ => { + set_state_to_end_of_evm_block(block_num, working_set); } }; @@ -846,35 +832,21 @@ impl Evm { block_number: Option, working_set: &mut WorkingSet, ) -> RpcResult { - let (l1_fee_rate, block_env) = match block_number { - None | Some(BlockNumberOrTag::Pending | BlockNumberOrTag::Latest) => { - // so we don't unnecessarily set archival version - // if no block was produced yet, the l1 fee rate can unwrap to 0, we don't care, else just return the latest - let l1_fee_rate = self.l1_fee_rate.get(working_set).unwrap_or_default(); - // if no block is produced yet, should default to genesis block env, else just return the lates - let block_env = self.block_env.get(working_set).unwrap_or_else(|| { - BlockEnv::from( - &self - .get_sealed_block_by_number( - Some(BlockNumberOrTag::Earliest), - working_set, - ) - .unwrap() - .expect("Genesis block must be set"), - ) - }); - (l1_fee_rate, block_env) - } - _ => { - let block = match self.get_sealed_block_by_number(block_number, working_set)? { - Some(block) => block, - None => return Err(EthApiError::UnknownBlockNumber.into()), - }; + let (l1_fee_rate, block_env, block_num) = { + let block = match self.get_sealed_block_by_number(block_number, working_set)? { + Some(block) => block, + None => return Err(EthApiError::UnknownBlockNumber.into()), + }; + let l1_fee_rate = block.l1_fee_rate; + let block_env = BlockEnv::from(&block); - set_state_to_end_of_evm_block(block.header.number, working_set); - let l1_fee_rate = block.l1_fee_rate; - let block_env = BlockEnv::from(&block); - (l1_fee_rate, block_env) + (l1_fee_rate, block_env, block.header.number) + }; + + match block_number { + None | Some(BlockNumberOrTag::Pending | BlockNumberOrTag::Latest) => {} + _ => { + set_state_to_end_of_evm_block(block_num, working_set); } }; diff --git a/crates/evm/src/tests/call_tests.rs b/crates/evm/src/tests/call_tests.rs index a728389e5..694946abb 100644 --- a/crates/evm/src/tests/call_tests.rs +++ b/crates/evm/src/tests/call_tests.rs @@ -51,21 +51,20 @@ fn call_multiple_test() { let l1_fee_rate = 0; let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let set_arg = 999; { @@ -95,7 +94,7 @@ fn call_multiple_test() { .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let db_account = evm.accounts.get(&contract_addr, &mut working_set).unwrap(); @@ -174,21 +173,20 @@ fn call_test() { let l1_fee_rate = 0; let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let set_arg = 999; { @@ -213,7 +211,7 @@ fn call_test() { evm.call(call_message, &context, &mut working_set).unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let db_account = evm.accounts.get(&contract_addr, &mut working_set).unwrap(); @@ -262,21 +260,20 @@ fn failed_transaction_test() { let l1_fee_rate = 0; let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -303,7 +300,7 @@ fn failed_transaction_test() { let pending_txs = evm.pending_transactions.iter(working_set); assert_eq!(pending_txs.len(), 0); - evm.end_soft_confirmation_hook(working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, working_set); // assert no pending transaction let pending_txs = evm.pending_transactions.iter(working_set); @@ -328,21 +325,20 @@ fn self_destruct_test() { let l1_fee_rate = 0; let mut l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -372,7 +368,7 @@ fn self_destruct_test() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); l2_height += 1; @@ -398,21 +394,20 @@ fn self_destruct_test() { assert_eq!(db_contract.keys.len(&mut working_set), 1); let l1_fee_rate = 0; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 2, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [99u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 2, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [99u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -438,7 +433,7 @@ fn self_destruct_test() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let db_contract = evm .accounts @@ -489,21 +484,20 @@ fn test_block_hash_in_evm() { let l1_fee_rate = 0; let mut l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -526,7 +520,7 @@ fn test_block_hash_in_evm() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); l2_height += 1; @@ -534,22 +528,20 @@ fn test_block_hash_in_evm() { for _i in 0..514 { // generate 514 more blocks let l1_fee_rate = 0; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [99u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); - evm.end_soft_confirmation_hook(&mut working_set); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [99u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); l2_height += 1; @@ -615,21 +607,20 @@ fn test_block_gas_limit() { let l1_fee_rate = 0; let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -666,7 +657,7 @@ fn test_block_gas_limit() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let block = evm @@ -902,21 +893,20 @@ fn test_l1_fee_success() { let (evm, mut working_set) = get_evm(&config); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height: 2, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height: 2, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -945,7 +935,7 @@ fn test_l1_fee_success() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let db_account = evm @@ -1015,21 +1005,20 @@ fn test_l1_fee_not_enough_funds() { let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -1058,7 +1047,7 @@ fn test_l1_fee_not_enough_funds() { assert!(block.transactions.is_empty()); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let db_account = evm @@ -1084,21 +1073,20 @@ fn test_l1_fee_halt() { let l1_fee_rate = 1; let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -1139,7 +1127,7 @@ fn test_l1_fee_halt() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); assert_eq!( diff --git a/crates/evm/src/tests/ef_tests/cases/blockchain_test.rs b/crates/evm/src/tests/ef_tests/cases/blockchain_test.rs index 1d89a5038..a460d9e44 100644 --- a/crates/evm/src/tests/ef_tests/cases/blockchain_test.rs +++ b/crates/evm/src/tests/ef_tests/cases/blockchain_test.rs @@ -66,21 +66,19 @@ impl BlockchainTestCase { ) { let l1_fee_rate = 0; // Call begin_soft_confirmation_hook - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [0u8; 32], - da_slot_height: 0, - da_slot_txs_commitment: [0u8; 32], - pre_state_root: root.to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [0u8; 32], + da_slot_height: 0, + da_slot_txs_commitment: [0u8; 32], + pre_state_root: root.to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let dummy_address = generate_address::("dummy"); let sequencer_address = generate_address::("sequencer"); @@ -93,7 +91,7 @@ impl BlockchainTestCase { ); let _ = evm.execute_call(txs, &context, &mut working_set); - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let root = commit(working_set, storage.clone()); let mut working_set: WorkingSet = WorkingSet::new(storage.clone()); evm.finalize_hook(&root.into(), &mut working_set.accessory_state()); diff --git a/crates/evm/src/tests/hooks_tests.rs b/crates/evm/src/tests/hooks_tests.rs index e0b70a3b2..0e11ce57e 100644 --- a/crates/evm/src/tests/hooks_tests.rs +++ b/crates/evm/src/tests/hooks_tests.rs @@ -2,8 +2,8 @@ use lazy_static::lazy_static; use rand::Rng; use reth_primitives::hex_literal::hex; use reth_primitives::{ - Address, Bloom, Bytes, Header, SealedHeader, Signature, TransactionSigned, B256, - EMPTY_OMMER_ROOT_HASH, KECCAK_EMPTY, U256, + Address, Bloom, Bytes, Header, Signature, TransactionSigned, B256, EMPTY_OMMER_ROOT_HASH, + KECCAK_EMPTY, U256, }; use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::{StateMapAccessor, StateValueAccessor, StateVecAccessor}; @@ -27,21 +27,19 @@ fn begin_soft_confirmation_hook_creates_pending_block() { let (evm, mut working_set) = get_evm(&TEST_CONFIG); let l1_fee_rate = 0; let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: DA_ROOT_HASH.0, - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 54, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: DA_ROOT_HASH.0, + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 54, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let pending_block = evm.block_env.get(&mut working_set).unwrap(); assert_eq!( pending_block, @@ -65,21 +63,20 @@ fn end_soft_confirmation_hook_sets_head() { let l1_fee_rate = 0; let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: DA_ROOT_HASH.0, - da_slot_height: 1, - da_slot_txs_commitment: txs_commitment.into(), - pre_state_root: pre_state_root.to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 54, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: DA_ROOT_HASH.0, + da_slot_height: 1, + da_slot_txs_commitment: txs_commitment.into(), + pre_state_root: pre_state_root.to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 54, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.pending_transactions.push( &create_pending_transaction(B256::from([1u8; 32]), 1), @@ -91,7 +88,7 @@ fn end_soft_confirmation_hook_sets_head() { &mut working_set, ); - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let head = evm.head.get(&mut working_set).unwrap(); let pending_head = evm .pending_head @@ -144,21 +141,20 @@ fn end_soft_confirmation_hook_moves_transactions_and_receipts() { let (evm, mut working_set) = get_evm(&TEST_CONFIG); let l1_fee_rate = 0; let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: DA_ROOT_HASH.0, - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: DA_ROOT_HASH.0, + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let tx1 = create_pending_transaction(B256::from([1u8; 32]), 1); evm.pending_transactions.push(&tx1, &mut working_set); @@ -166,7 +162,7 @@ fn end_soft_confirmation_hook_moves_transactions_and_receipts() { let tx2 = create_pending_transaction(B256::from([2u8; 32]), 2); evm.pending_transactions.push(&tx2, &mut working_set); - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let tx1_hash = tx1.transaction.signed_transaction.hash; let tx2_hash = tx2.transaction.signed_transaction.hash; @@ -252,21 +248,19 @@ fn finalize_hook_creates_final_block() { let l1_fee_rate = 0; let mut l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: txs_commitment.into(), - pre_state_root: root.to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 54, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: txs_commitment.into(), + pre_state_root: root.to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 54, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.pending_transactions.push( &create_pending_transaction(B256::from([1u8; 32]), 1), @@ -276,7 +270,7 @@ fn finalize_hook_creates_final_block() { &create_pending_transaction(B256::from([2u8; 32]), 2), &mut working_set, ); - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let root_hash = [99u8; 32]; @@ -308,43 +302,39 @@ fn finalize_hook_creates_final_block() { let parent_hash = parent_block.header.hash(); let block = evm.blocks.get(2usize, &mut accessory_state).unwrap(); + let header = Header { + parent_hash, + ommers_hash: EMPTY_OMMER_ROOT_HASH, + beneficiary: TEST_CONFIG.coinbase, + state_root: B256::from(root_hash), + transactions_root: B256::from(hex!( + "30eb5f6050df7ea18ca34cf3503f4713119315a2d3c11f892c5c8920acf816f4" + )), + receipts_root: B256::from(hex!( + "27036187b3f5e87d4306b396cf06c806da2cc9a0fef9b07c042e3b4304e01c64" + )), + withdrawals_root: None, + logs_bloom: Bloom::default(), + difficulty: U256::ZERO, + number: 2, + gas_limit: 30000000, + gas_used: 200, + timestamp: 54, + mix_hash: B256::from(hex!( + "0505050505050505050505050505050505050505050505050505050505050505" + )), + nonce: 0, + base_fee_per_gas: Some(765625000), + extra_data: Bytes::default(), + blob_gas_used: None, + excess_blob_gas: None, + parent_beacon_block_root: None, + requests_root: None, + }; assert_eq!( block, SealedBlock { - header: SealedHeader::new( - Header { - parent_hash, - ommers_hash: EMPTY_OMMER_ROOT_HASH, - beneficiary: TEST_CONFIG.coinbase, - state_root: B256::from(root_hash), - transactions_root: B256::from(hex!( - "30eb5f6050df7ea18ca34cf3503f4713119315a2d3c11f892c5c8920acf816f4" - )), - receipts_root: B256::from(hex!( - "27036187b3f5e87d4306b396cf06c806da2cc9a0fef9b07c042e3b4304e01c64" - )), - withdrawals_root: None, - logs_bloom: Bloom::default(), - difficulty: U256::ZERO, - number: 2, - gas_limit: 30000000, - gas_used: 200, - timestamp: 54, - mix_hash: B256::from(hex!( - "0505050505050505050505050505050505050505050505050505050505050505" - )), - nonce: 0, - base_fee_per_gas: Some(765625000), - extra_data: Bytes::default(), - blob_gas_used: None, - excess_blob_gas: None, - parent_beacon_block_root: None, - requests_root: None, - }, - B256::from(hex!( - "34a41cc49fb5f0bbf3192596d87c6a0cc813e3f33c22af6951efdf57d02c175a" - )) - ), + header: header.seal_slow(), l1_fee_rate: 0, l1_hash: B256::from(DA_ROOT_HASH.0), transactions: 0..2 @@ -376,21 +366,19 @@ fn begin_soft_confirmation_hook_appends_last_block_hashes() { let l1_fee_rate = 0; let mut l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: DA_ROOT_HASH.0, - da_slot_height: 1, - da_slot_txs_commitment: txs_commitment.into(), - pre_state_root: root.to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: DA_ROOT_HASH.0, + da_slot_height: 1, + da_slot_txs_commitment: txs_commitment.into(), + pre_state_root: root.to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); // on block 2, only block 0 and 1 exists for i in 0..2 { @@ -411,7 +399,7 @@ fn begin_soft_confirmation_hook_appends_last_block_hashes() { .get(&U256::from(2), &mut working_set) .is_none()); - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let mut random_32_bytes: [u8; 32] = rand::thread_rng().gen::<[u8; 32]>(); evm.finalize_hook(&random_32_bytes.into(), &mut working_set.accessory_state()); @@ -421,34 +409,7 @@ fn begin_soft_confirmation_hook_appends_last_block_hashes() { // finalize blocks 2-257 with random state root hashes for _ in 2..257 { let l1_fee_rate = 0; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: DA_ROOT_HASH.0, - da_slot_height: 1, - da_slot_txs_commitment: random_32_bytes, - pre_state_root: random_32_bytes.to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); - - evm.end_soft_confirmation_hook(&mut working_set); - - random_32_bytes = rand::thread_rng().gen::<[u8; 32]>(); - evm.finalize_hook(&random_32_bytes.into(), &mut working_set.accessory_state()); - - l2_height += 1; - } - - // start environment for block 258 - let l1_fee_rate = 0; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { + let soft_confirmation_info = HookSoftConfirmationInfo { l2_height, da_slot_hash: DA_ROOT_HASH.0, da_slot_height: 1, @@ -459,9 +420,32 @@ fn begin_soft_confirmation_hook_appends_last_block_hashes() { deposit_data: vec![], l1_fee_rate, timestamp: 0, - }, - &mut working_set, - ); + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); + + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); + + random_32_bytes = rand::thread_rng().gen::<[u8; 32]>(); + evm.finalize_hook(&random_32_bytes.into(), &mut working_set.accessory_state()); + + l2_height += 1; + } + + // start environment for block 258 + let l1_fee_rate = 0; + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: DA_ROOT_HASH.0, + da_slot_height: 1, + da_slot_txs_commitment: random_32_bytes, + pre_state_root: random_32_bytes.to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); // only the last 256 blocks should exist on block 258 // which is [2, 257] diff --git a/crates/evm/src/tests/queries/evm_call_tests.rs b/crates/evm/src/tests/queries/evm_call_tests.rs index 17fdd9b80..4830dbf85 100644 --- a/crates/evm/src/tests/queries/evm_call_tests.rs +++ b/crates/evm/src/tests/queries/evm_call_tests.rs @@ -71,21 +71,19 @@ fn test_state_change() { let random_address = Address::from_str("0x000000000000000000000000000000000000dead").unwrap(); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate: 1, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate: 1, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let call_result = evm.get_call( TransactionRequest { @@ -104,7 +102,7 @@ fn test_state_change() { assert_eq!(call_result.unwrap(), Bytes::from_str("0x").unwrap()); - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let balance_2 = evm.get_balance(signer.address(), None, &mut working_set); diff --git a/crates/evm/src/tests/queries/log_tests.rs b/crates/evm/src/tests/queries/log_tests.rs index b76a07591..99609022a 100644 --- a/crates/evm/src/tests/queries/log_tests.rs +++ b/crates/evm/src/tests/queries/log_tests.rs @@ -69,21 +69,19 @@ fn log_filter_test_at_block_hash() { let l1_fee_rate = 1; let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -115,7 +113,7 @@ fn log_filter_test_at_block_hash() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); // `AnotherLog` topics @@ -286,21 +284,19 @@ fn log_filter_test_with_range() { let l1_fee_rate = 1; let mut l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -332,7 +328,7 @@ fn log_filter_test_with_range() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); l2_height += 1; @@ -357,21 +353,19 @@ fn log_filter_test_with_range() { assert_eq!(rpc_logs.len(), 4); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [99u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [99u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -398,7 +392,7 @@ fn log_filter_test_with_range() { .unwrap(); // the last topic will be Keccak256("message") } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[100u8; 32].into(), &mut working_set.accessory_state()); let filter = Filter { block_option: crate::FilterBlockOption::Range { @@ -429,21 +423,19 @@ fn test_log_limits() { let l1_fee_rate = 1; let mut l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -498,7 +490,7 @@ fn test_log_limits() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); l2_height += 1; @@ -538,23 +530,21 @@ fn test_log_limits() { ]; for _ in 1..100_001 { + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [99u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; // generate 100_000 blocks to test the max block range limit - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [99u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); - evm.end_soft_confirmation_hook(&mut working_set); + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); l2_height += 1; diff --git a/crates/evm/src/tests/queries/mod.rs b/crates/evm/src/tests/queries/mod.rs index 84513bfe8..22e0de79d 100644 --- a/crates/evm/src/tests/queries/mod.rs +++ b/crates/evm/src/tests/queries/mod.rs @@ -65,21 +65,19 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner, u64) { .as_slice(), ); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 24, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 24, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); @@ -106,7 +104,7 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner, u64) { .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); @@ -114,21 +112,19 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner, u64) { let mut working_set: WorkingSet = WorkingSet::new(prover_storage.clone()); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [8u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [99u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 24, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [8u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [99u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 24, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); @@ -156,7 +152,7 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner, u64) { .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[100u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); @@ -164,21 +160,19 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner, u64) { let mut working_set: WorkingSet = WorkingSet::new(prover_storage.clone()); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [10u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [100u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 24, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [10u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [100u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 24, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); @@ -204,7 +198,7 @@ fn init_evm() -> (Evm, WorkingSet, TestSigner, u64) { .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[101u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); @@ -251,21 +245,19 @@ pub fn init_evm_single_block() -> (Evm, WorkingSet, TestSigner) { let l1_fee_rate = 1; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height: 1, - da_slot_hash: [1u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [0u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height: 1, + da_slot_hash: [1u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [0u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let simple_payable_contract_tx = create_contract_transaction(&dev_signer, 0, SimplePayableContract::default()); @@ -289,7 +281,7 @@ pub fn init_evm_single_block() -> (Evm, WorkingSet, TestSigner) { ) .unwrap(); - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[2u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); @@ -333,21 +325,19 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner, u6 let l1_fee_rate = 1; let mut l2_height = 1; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [1u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [0u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [1u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [0u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); @@ -373,7 +363,7 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner, u6 .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[2u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); @@ -381,21 +371,19 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner, u6 let mut working_set: WorkingSet = WorkingSet::new(prover_storage.clone()); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [2u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [2u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [2u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [2u8; 32].to_vec(), + current_spec: SovSpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); @@ -422,7 +410,7 @@ pub fn init_evm_with_caller_contract() -> (Evm, WorkingSet, TestSigner, u6 .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[3u8; 32].into(), &mut working_set.accessory_state()); commit(working_set, prover_storage.clone()); diff --git a/crates/evm/src/tests/sys_tx_tests.rs b/crates/evm/src/tests/sys_tx_tests.rs index 6ae28e9de..51434d0e8 100644 --- a/crates/evm/src/tests/sys_tx_tests.rs +++ b/crates/evm/src/tests/sys_tx_tests.rs @@ -139,22 +139,21 @@ fn test_sys_bitcoin_light_client() { assert_eq!(hash.as_ref(), &[1u8; 32]); assert_eq!(merkle_root.as_ref(), &[2u8; 32]); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [2u8; 32], + da_slot_height: 2, + da_slot_txs_commitment: [3u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 42, + }; + // New L1 block â„–2 - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [2u8; 32], - da_slot_height: 2, - da_slot_txs_commitment: [3u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 42, - }, - &mut working_set, - ); + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); let sequencer_address = generate_address::("sequencer"); @@ -182,7 +181,7 @@ fn test_sys_bitcoin_light_client() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let system_account = evm.accounts.get(&SYSTEM_SIGNER, &mut working_set).unwrap(); @@ -298,21 +297,20 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { l1_fee_rate, ); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate: 1, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate: 1, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { // deploy logs contract evm.call( @@ -328,26 +326,24 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); l2_height += 1; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [10u8; 32], - da_slot_height: 2, - da_slot_txs_commitment: [43u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [10u8; 32], + da_slot_height: 2, + da_slot_txs_commitment: [43u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let context = C::new( sender_address, @@ -387,7 +383,7 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { ) .unwrap(); } - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let block = evm @@ -417,86 +413,82 @@ fn test_bridge() { let l1_fee_rate = 1; let l2_height = 2; - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_height: 2, - da_slot_hash: [2u8; 32], - da_slot_txs_commitment: [ - 136, 147, 225, 201, 35, 145, 64, 167, 182, 140, 185, 55, 22, 224, 150, 42, 51, 86, - 214, 251, 181, 122, 169, 246, 188, 29, 186, 32, 227, 33, 199, 38, - ], - pre_state_root: [1u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![[ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 128, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 4, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 1, 196, 196, 205, 156, - 93, 62, 54, 134, 133, 188, 6, 17, 153, 42, 62, 155, 138, 8, 111, 222, 48, 192, 86, - 41, 210, 202, 111, 100, 49, 6, 36, 123, 0, 0, 0, 0, 0, 253, 255, 255, 255, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, 2, 197, 63, - 15, 0, 0, 0, 0, 0, 34, 81, 32, 225, 85, 228, 181, 8, 114, 26, 130, 4, 159, 125, - 249, 18, 119, 121, 134, 147, 142, 99, 173, 85, 230, 58, 42, 39, 210, 102, 158, 156, - 54, 47, 183, 74, 1, 0, 0, 0, 0, 0, 0, 34, 0, 32, 74, 232, 21, 114, 240, 110, 27, - 136, 253, 92, 237, 122, 26, 0, 9, 69, 67, 46, 131, 225, 85, 30, 111, 114, 30, 233, - 192, 11, 140, 195, 50, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 91, 7, 64, 85, 100, - 226, 121, 160, 231, 130, 160, 201, 56, 39, 35, 161, 143, 216, 21, 211, 206, 127, - 229, 78, 29, 6, 86, 241, 85, 191, 62, 174, 148, 71, 7, 97, 25, 170, 78, 173, 238, - 251, 184, 7, 3, 139, 103, 184, 9, 84, 28, 37, 39, 39, 91, 248, 166, 240, 149, 245, - 51, 48, 45, 10, 151, 90, 134, 64, 58, 4, 251, 18, 243, 51, 241, 78, 218, 137, 248, - 84, 193, 73, 6, 249, 29, 144, 62, 120, 43, 235, 170, 173, 3, 241, 236, 171, 253, - 71, 17, 237, 81, 214, 38, 47, 206, 119, 2, 116, 56, 203, 107, 84, 255, 102, 133, - 42, 245, 35, 173, 250, 41, 110, 193, 18, 121, 214, 157, 81, 81, 115, 91, 237, 64, - 21, 17, 223, 104, 155, 182, 45, 200, 209, 237, 114, 78, 88, 157, 251, 106, 70, 76, - 150, 27, 223, 254, 87, 62, 121, 250, 18, 141, 166, 53, 181, 63, 41, 28, 81, 51, 20, - 84, 115, 122, 154, 139, 187, 182, 208, 212, 16, 122, 183, 103, 149, 223, 86, 216, - 191, 246, 117, 102, 59, 111, 120, 22, 223, 62, 64, 253, 145, 239, 196, 249, 255, - 135, 5, 208, 64, 144, 150, 213, 166, 66, 98, 4, 23, 151, 165, 220, 201, 209, 179, - 201, 162, 185, 98, 0, 228, 44, 29, 230, 117, 232, 11, 123, 162, 71, 201, 73, 125, - 209, 236, 189, 139, 56, 160, 205, 48, 238, 29, 185, 43, 229, 103, 117, 247, 252, - 85, 166, 29, 59, 232, 64, 189, 1, 191, 87, 25, 32, 77, 193, 98, 33, 84, 159, 168, - 209, 181, 157, 80, 130, 164, 59, 101, 196, 190, 247, 124, 131, 53, 156, 111, 105, - 196, 18, 8, 177, 1, 118, 217, 178, 150, 165, 172, 205, 126, 106, 54, 246, 54, 95, - 47, 16, 155, 156, 123, 135, 135, 4, 44, 241, 144, 188, 76, 181, 157, 173, 210, 32, - 93, 175, 87, 112, 72, 197, 229, 169, 167, 93, 10, 146, 78, 208, 62, 34, 108, 51, 4, - 244, 162, 240, 28, 101, 202, 29, 171, 115, 82, 46, 107, 139, 173, 32, 98, 40, 235, - 166, 83, 207, 24, 25, 188, 252, 27, 200, 88, 99, 14, 90, 227, 115, 238, 193, 169, - 146, 67, 34, 165, 254, 132, 69, 197, 231, 96, 39, 173, 32, 21, 33, 214, 95, 100, - 190, 63, 113, 183, 28, 164, 98, 34, 15, 19, 199, 123, 37, 16, 39, 246, 202, 68, 58, - 72, 51, 83, 169, 111, 188, 226, 34, 173, 32, 15, 171, 238, 210, 105, 105, 78, 232, - 61, 155, 51, 67, 165, 113, 32, 46, 104, 175, 101, 208, 95, 237, 166, 29, 190, 208, - 196, 189, 178, 86, 166, 234, 173, 32, 0, 50, 109, 111, 114, 28, 3, 220, 95, 29, - 136, 23, 216, 248, 238, 137, 10, 149, 162, 238, 218, 13, 77, 154, 1, 177, 204, 155, - 123, 27, 114, 77, 172, 0, 99, 6, 99, 105, 116, 114, 101, 97, 20, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 0, 0, 0, 0, 0, 15, 66, 64, 104, 65, - 193, 147, 199, 55, 141, 150, 81, 138, 117, 68, 136, 33, 196, 247, 200, 244, 186, - 231, 206, 96, 248, 4, 208, 61, 31, 6, 40, 221, 93, 208, 245, 222, 81, 15, 41, 81, - 255, 251, 84, 130, 89, 213, 171, 185, 243, 81, 190, 143, 148, 3, 28, 156, 232, 140, - 232, 56, 180, 13, 124, 236, 124, 96, 110, 12, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, - ] - .to_vec()], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); - evm.end_soft_confirmation_hook(&mut working_set); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_height: 2, + da_slot_hash: [2u8; 32], + da_slot_txs_commitment: [ + 136, 147, 225, 201, 35, 145, 64, 167, 182, 140, 185, 55, 22, 224, 150, 42, 51, 86, 214, + 251, 181, 122, 169, 246, 188, 29, 186, 32, 227, 33, 199, 38, + ], + pre_state_root: [1u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![[ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 128, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 42, 1, 196, 196, 205, 156, 93, 62, 54, 134, 133, 188, 6, 17, 153, 42, + 62, 155, 138, 8, 111, 222, 48, 192, 86, 41, 210, 202, 111, 100, 49, 6, 36, 123, 0, 0, + 0, 0, 0, 253, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 87, 2, 197, 63, 15, 0, 0, 0, 0, 0, 34, 81, 32, 225, 85, 228, 181, 8, + 114, 26, 130, 4, 159, 125, 249, 18, 119, 121, 134, 147, 142, 99, 173, 85, 230, 58, 42, + 39, 210, 102, 158, 156, 54, 47, 183, 74, 1, 0, 0, 0, 0, 0, 0, 34, 0, 32, 74, 232, 21, + 114, 240, 110, 27, 136, 253, 92, 237, 122, 26, 0, 9, 69, 67, 46, 131, 225, 85, 30, 111, + 114, 30, 233, 192, 11, 140, 195, 50, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 91, 7, 64, + 85, 100, 226, 121, 160, 231, 130, 160, 201, 56, 39, 35, 161, 143, 216, 21, 211, 206, + 127, 229, 78, 29, 6, 86, 241, 85, 191, 62, 174, 148, 71, 7, 97, 25, 170, 78, 173, 238, + 251, 184, 7, 3, 139, 103, 184, 9, 84, 28, 37, 39, 39, 91, 248, 166, 240, 149, 245, 51, + 48, 45, 10, 151, 90, 134, 64, 58, 4, 251, 18, 243, 51, 241, 78, 218, 137, 248, 84, 193, + 73, 6, 249, 29, 144, 62, 120, 43, 235, 170, 173, 3, 241, 236, 171, 253, 71, 17, 237, + 81, 214, 38, 47, 206, 119, 2, 116, 56, 203, 107, 84, 255, 102, 133, 42, 245, 35, 173, + 250, 41, 110, 193, 18, 121, 214, 157, 81, 81, 115, 91, 237, 64, 21, 17, 223, 104, 155, + 182, 45, 200, 209, 237, 114, 78, 88, 157, 251, 106, 70, 76, 150, 27, 223, 254, 87, 62, + 121, 250, 18, 141, 166, 53, 181, 63, 41, 28, 81, 51, 20, 84, 115, 122, 154, 139, 187, + 182, 208, 212, 16, 122, 183, 103, 149, 223, 86, 216, 191, 246, 117, 102, 59, 111, 120, + 22, 223, 62, 64, 253, 145, 239, 196, 249, 255, 135, 5, 208, 64, 144, 150, 213, 166, 66, + 98, 4, 23, 151, 165, 220, 201, 209, 179, 201, 162, 185, 98, 0, 228, 44, 29, 230, 117, + 232, 11, 123, 162, 71, 201, 73, 125, 209, 236, 189, 139, 56, 160, 205, 48, 238, 29, + 185, 43, 229, 103, 117, 247, 252, 85, 166, 29, 59, 232, 64, 189, 1, 191, 87, 25, 32, + 77, 193, 98, 33, 84, 159, 168, 209, 181, 157, 80, 130, 164, 59, 101, 196, 190, 247, + 124, 131, 53, 156, 111, 105, 196, 18, 8, 177, 1, 118, 217, 178, 150, 165, 172, 205, + 126, 106, 54, 246, 54, 95, 47, 16, 155, 156, 123, 135, 135, 4, 44, 241, 144, 188, 76, + 181, 157, 173, 210, 32, 93, 175, 87, 112, 72, 197, 229, 169, 167, 93, 10, 146, 78, 208, + 62, 34, 108, 51, 4, 244, 162, 240, 28, 101, 202, 29, 171, 115, 82, 46, 107, 139, 173, + 32, 98, 40, 235, 166, 83, 207, 24, 25, 188, 252, 27, 200, 88, 99, 14, 90, 227, 115, + 238, 193, 169, 146, 67, 34, 165, 254, 132, 69, 197, 231, 96, 39, 173, 32, 21, 33, 214, + 95, 100, 190, 63, 113, 183, 28, 164, 98, 34, 15, 19, 199, 123, 37, 16, 39, 246, 202, + 68, 58, 72, 51, 83, 169, 111, 188, 226, 34, 173, 32, 15, 171, 238, 210, 105, 105, 78, + 232, 61, 155, 51, 67, 165, 113, 32, 46, 104, 175, 101, 208, 95, 237, 166, 29, 190, 208, + 196, 189, 178, 86, 166, 234, 173, 32, 0, 50, 109, 111, 114, 28, 3, 220, 95, 29, 136, + 23, 216, 248, 238, 137, 10, 149, 162, 238, 218, 13, 77, 154, 1, 177, 204, 155, 123, 27, + 114, 77, 172, 0, 99, 6, 99, 105, 116, 114, 101, 97, 20, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 0, 0, 0, 0, 0, 15, 66, 64, 104, 65, 193, 147, 199, 55, + 141, 150, 81, 138, 117, 68, 136, 33, 196, 247, 200, 244, 186, 231, 206, 96, 248, 4, + 208, 61, 31, 6, 40, 221, 93, 208, 245, 222, 81, 15, 41, 81, 255, 251, 84, 130, 89, 213, + 171, 185, 243, 81, 190, 143, 148, 3, 28, 156, 232, 140, 232, 56, 180, 13, 124, 236, + 124, 96, 110, 12, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ] + .to_vec()], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let recipient_address = address!("0101010101010101010101010101010101010101"); @@ -565,21 +557,20 @@ fn test_upgrade_light_client() { l1_fee_rate, ); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let upgrade_tx = contract_owner .sign_default_transaction( @@ -602,7 +593,7 @@ fn test_upgrade_light_client() { ) .unwrap(); - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let hash = evm @@ -699,21 +690,20 @@ fn test_change_upgrade_owner() { l1_fee_rate, ); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); let change_owner_tx = contract_owner .sign_default_transaction( @@ -733,7 +723,7 @@ fn test_change_upgrade_owner() { ) .unwrap(); - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); l2_height += 1; @@ -745,21 +735,19 @@ fn test_change_upgrade_owner() { l1_fee_rate, ); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height, - da_slot_hash: [5u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [42u8; 32], - pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate, - timestamp: 0, - }, - &mut working_set, - ); + let soft_confirmation_info = HookSoftConfirmationInfo { + l2_height, + da_slot_hash: [5u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [42u8; 32], + pre_state_root: [10u8; 32].to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate, + timestamp: 0, + }; + evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); // New owner should be able to upgrade the contract @@ -785,7 +773,7 @@ fn test_change_upgrade_owner() { ) .unwrap(); - evm.end_soft_confirmation_hook(&mut working_set); + evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); let provided_new_owner = evm diff --git a/crates/evm/src/tests/utils.rs b/crates/evm/src/tests/utils.rs index 9bd93ace8..2c34287b4 100644 --- a/crates/evm/src/tests/utils.rs +++ b/crates/evm/src/tests/utils.rs @@ -43,7 +43,6 @@ pub(crate) fn get_evm_with_storage( ); (evm, working_set, prover_storage) } - pub(crate) fn get_evm(config: &EvmConfig) -> (Evm, WorkingSet) { let tmpdir = tempfile::tempdir().unwrap(); let storage = new_orphan_storage(tmpdir.path()).unwrap(); @@ -56,22 +55,22 @@ pub(crate) fn get_evm(config: &EvmConfig) -> (Evm, WorkingSet) { let mut working_set: WorkingSet = WorkingSet::new(storage.clone()); evm.finalize_hook(&root.into(), &mut working_set.accessory_state()); - evm.begin_soft_confirmation_hook( - &HookSoftConfirmationInfo { - l2_height: 1, - da_slot_hash: [1u8; 32], - da_slot_height: 1, - da_slot_txs_commitment: [2u8; 32], - pre_state_root: root.to_vec(), - current_spec: SpecId::Genesis, - pub_key: vec![], - deposit_data: vec![], - l1_fee_rate: 0, - timestamp: 0, - }, - &mut working_set, - ); - evm.end_soft_confirmation_hook(&mut working_set); + let hook_info = HookSoftConfirmationInfo { + l2_height: 1, + da_slot_hash: [1u8; 32], + da_slot_height: 1, + da_slot_txs_commitment: [2u8; 32], + pre_state_root: root.to_vec(), + current_spec: SpecId::Genesis, + pub_key: vec![], + deposit_data: vec![], + l1_fee_rate: 0, + timestamp: 0, + }; + + // Pass the same struct to both hooks + evm.begin_soft_confirmation_hook(&hook_info, &mut working_set); + evm.end_soft_confirmation_hook(&hook_info, &mut working_set); let root = commit(working_set, storage.clone()); let mut working_set: WorkingSet = WorkingSet::new(storage.clone()); diff --git a/crates/fullnode/tests/hash_stf.rs b/crates/fullnode/tests/hash_stf.rs index a6bfccd32..dae60e974 100644 --- a/crates/fullnode/tests/hash_stf.rs +++ b/crates/fullnode/tests/hash_stf.rs @@ -102,6 +102,7 @@ impl StfBlueprintTrai fn end_soft_confirmation( &self, _current_spec: SpecId, + _pre_state_root: Vec, _sequencer_public_key: &[u8], _soft_confirmation: &mut sov_modules_api::SignedSoftConfirmation, _tx_receipts: Vec< diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index ec22700b6..87b327b90 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -474,6 +474,7 @@ where let (soft_confirmation_receipt, checkpoint) = self.stf.end_soft_confirmation( active_fork_spec, + self.state_root.clone().as_ref().to_vec(), self.sequencer_pub_key.as_ref(), &mut signed_soft_confirmation, tx_receipts, diff --git a/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs b/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs index f253163de..f0e9c04d5 100644 --- a/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs +++ b/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs @@ -92,6 +92,7 @@ impl ApplySoftConfirmationHooks for Runtime { fn end_soft_confirmation_hook( &self, + _soft_confirmation: &HookSoftConfirmationInfo, _working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { Ok(()) diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs index ce8130db7..e8a6b8b90 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs @@ -73,6 +73,7 @@ pub trait ApplySoftConfirmationHooks { /// If this hook returns Err rollup panics fn end_soft_confirmation_hook( &self, + soft_confirmation_info: &HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError>; } diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs index 208e24117..615afba55 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs @@ -160,6 +160,7 @@ pub trait StfBlueprintTrait: fn end_soft_confirmation( &self, current_spec: SpecId, + pre_state_root: Vec, sequencer_public_key: &[u8], soft_confirmation: &mut SignedSoftConfirmation, tx_receipts: Vec>, @@ -241,7 +242,8 @@ where fn end_soft_confirmation( &self, - _current_spec: SpecId, + current_spec: SpecId, + pre_state_root: Vec, sequencer_public_key: &[u8], soft_confirmation: &mut SignedSoftConfirmation, tx_receipts: Vec>, @@ -287,7 +289,13 @@ where ); } - self.end_soft_confirmation_inner(soft_confirmation, tx_receipts, batch_workspace) + self.end_soft_confirmation_inner( + current_spec, + pre_state_root, + soft_confirmation, + tx_receipts, + batch_workspace, + ) } fn finalize_soft_confirmation( @@ -473,6 +481,7 @@ where match self.end_soft_confirmation( current_spec, + pre_state_root.as_ref().to_vec(), sequencer_public_key, soft_confirmation, tx_receipts, diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index b3f7d4dd2..453abf7aa 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::{ - native_debug, native_error, Context, DaSpec, DispatchCall, StateCheckpoint, WorkingSet, + native_debug, native_error, Context, DaSpec, DispatchCall, SpecId, StateCheckpoint, WorkingSet, }; use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::stf::{ @@ -197,13 +197,18 @@ where #[cfg_attr(feature = "native", instrument(level = "trace", skip_all))] pub fn end_soft_confirmation_inner( &self, + current_spec: SpecId, + pre_state_root: Vec, soft_confirmation: &mut SignedSoftConfirmation, tx_receipts: Vec>, mut batch_workspace: WorkingSet, ) -> (ApplySoftConfirmationResult, StateCheckpoint) { + let hook_soft_confirmation_info = + HookSoftConfirmationInfo::new(soft_confirmation.clone(), pre_state_root, current_spec); + if let Err(e) = self .runtime - .end_soft_confirmation_hook(&mut batch_workspace) + .end_soft_confirmation_hook(&hook_soft_confirmation_info, &mut batch_workspace) { // TODO: will be covered in https://github.com/Sovereign-Labs/sovereign-sdk/issues/421 native_error!("Failed on `end_soft_confirmation_hook`: {:?}", e); From b3a36ff12fe0990d1b3fb850ee3f7da1da1f0ef4 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Thu, 29 Aug 2024 16:58:04 +0300 Subject: [PATCH 10/17] fix ci --- crates/sovereign-sdk/fuzz/Cargo.lock | 1 - .../tests/dispatch/derive_dispatch.rs | 1 - .../tests/rpc/expose_rpc_associated_types.rs | 7 ++++--- crates/sovereign-sdk/rollup-interface/Cargo.toml | 6 +++--- crates/sovereign-sdk/rollup-interface/Makefile | 2 +- crates/sovereign-sdk/rollup-interface/src/spec.rs | 10 ++-------- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/crates/sovereign-sdk/fuzz/Cargo.lock b/crates/sovereign-sdk/fuzz/Cargo.lock index b409a985f..026974b71 100644 --- a/crates/sovereign-sdk/fuzz/Cargo.lock +++ b/crates/sovereign-sdk/fuzz/Cargo.lock @@ -3273,7 +3273,6 @@ dependencies = [ "futures", "hex", "proptest", - "proptest-derive", "serde", "sha2", "thiserror", diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs index b2ce13e2f..61e8e1b18 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs @@ -6,7 +6,6 @@ use sov_modules_api::macros::DefaultRuntime; use sov_modules_api::{ Address, Context, DispatchCall, EncodeCall, Genesis, MessageCodec, ModuleInfo, SpecId, }; -use sov_rollup_interface::spec::SpecId; use sov_state::ZkStorage; #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs index 72242687f..76d5ac71c 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs @@ -1,9 +1,10 @@ use jsonrpsee::core::RpcResult; use sov_modules_api::default_context::ZkDefaultContext; use sov_modules_api::macros::{expose_rpc, rpc_gen, DefaultRuntime}; +use sov_modules_api::prelude::*; use sov_modules_api::{ - prelude::*, Address, CallResponse, Context, DispatchCall, EncodeCall, Error, Genesis, - MessageCodec, Module, ModuleInfo, StateValue, WorkingSet, + Address, CallResponse, Context, DispatchCall, EncodeCall, Error, Genesis, MessageCodec, Module, + ModuleInfo, SpecId, StateValue, WorkingSet, }; use sov_state::ZkStorage; @@ -124,7 +125,7 @@ fn main() { let module = RT::decode_call(&serialized_message).unwrap(); let sender = Address::try_from([11; 32].as_ref()).unwrap(); let sequencer = Address::try_from([12; 32].as_ref()).unwrap(); - let context = C::new(sender, sequencer, 1); + let context = C::new(sender, sequencer, 1, SpecId::Genesis, 0); let _ = runtime .dispatch_call(module, working_set, SpecId::Genesis, &context) diff --git a/crates/sovereign-sdk/rollup-interface/Cargo.toml b/crates/sovereign-sdk/rollup-interface/Cargo.toml index 5fbadaab1..f5cf45faf 100644 --- a/crates/sovereign-sdk/rollup-interface/Cargo.toml +++ b/crates/sovereign-sdk/rollup-interface/Cargo.toml @@ -39,9 +39,9 @@ serde_json = { workspace = true } [features] default = ["std"] native = ["std", "tokio", "futures"] -fuzzing = ["dep:proptest", "dep:proptest-derive", "dep:sha2", "std"] -testing = ["native", "dep:proptest", "dep:proptest-derive"] -arbitrary = ["dep:arbitrary", "dep:proptest", "dep:proptest-derive"] +fuzzing = ["proptest", "proptest-derive", "sha2", "std"] +testing = ["native"] +arbitrary = ["dep:arbitrary"] std = [ "anyhow/default", "borsh/default", diff --git a/crates/sovereign-sdk/rollup-interface/Makefile b/crates/sovereign-sdk/rollup-interface/Makefile index cce3522d5..5411c1dc3 100644 --- a/crates/sovereign-sdk/rollup-interface/Makefile +++ b/crates/sovereign-sdk/rollup-interface/Makefile @@ -6,5 +6,5 @@ help: ## Display this help message check-no-std: ## Checks that project compiles without std # check bare metal cargo hack check --feature-powerset \ - --exclude-features default,fuzzing,std,native,testing \ + --exclude-features default,fuzzing,std,native,testing,arbitrary \ --target thumbv6m-none-eabi diff --git a/crates/sovereign-sdk/rollup-interface/src/spec.rs b/crates/sovereign-sdk/rollup-interface/src/spec.rs index 223a37ae3..3663c7329 100644 --- a/crates/sovereign-sdk/rollup-interface/src/spec.rs +++ b/crates/sovereign-sdk/rollup-interface/src/spec.rs @@ -23,10 +23,7 @@ mod spec { Hash, )] #[borsh(use_discriminant = true)] - #[cfg_attr( - feature = "arbitrary", - derive(arbitrary::Arbitrary, proptest_derive::Arbitrary) - )] + #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub enum SpecId { /// Genesis spec #[default] @@ -52,10 +49,7 @@ mod spec { Hash, )] #[borsh(use_discriminant = true)] - #[cfg_attr( - feature = "arbitrary", - derive(arbitrary::Arbitrary, proptest_derive::Arbitrary) - )] + #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub enum SpecId { /// Genesis spec #[default] From 5382648ecc014b1e60d9deb93eb83f6590629375 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Thu, 29 Aug 2024 17:06:51 +0300 Subject: [PATCH 11/17] remove comment and unnecessary clone --- crates/sequencer/src/sequencer.rs | 2 +- .../sov-modules-stf-blueprint/src/stf_blueprint.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index 87b327b90..a16ef4ee2 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -474,7 +474,7 @@ where let (soft_confirmation_receipt, checkpoint) = self.stf.end_soft_confirmation( active_fork_spec, - self.state_root.clone().as_ref().to_vec(), + self.state_root.as_ref().to_vec(), self.sequencer_pub_key.as_ref(), &mut signed_soft_confirmation, tx_receipts, diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index 453abf7aa..a0554eff0 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -8,8 +8,6 @@ use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::stf::{ SoftConfirmationError, SoftConfirmationReceipt, TransactionReceipt, }; -// #[cfg(all(target_os = "zkvm", feature = "bench"))] -// use sov_zk_cycle_macros::cycle_tracker; #[cfg(feature = "native")] use tracing::instrument; From 2d0176a5536c9dcd5376a7037f662d1c3894a339 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Thu, 29 Aug 2024 17:52:49 +0300 Subject: [PATCH 12/17] fix ci again --- .../sov-modules-macros/tests/dispatch/derive_dispatch.rs | 4 ++-- .../tests/rpc/expose_rpc_associated_type_not_static.rs | 7 ++++--- .../tests/rpc/expose_rpc_associated_types_nested.rs | 7 ++++--- .../tests/rpc/expose_rpc_first_generic_not_context.rs | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs index 61e8e1b18..eeee8f5f8 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs @@ -42,7 +42,7 @@ fn main() { assert_eq!(runtime.module_address(&module), runtime.first.address()); let _ = runtime - .dispatch_call(module, working_set, SpecId::Genesis, &context) + .dispatch_call(module, working_set, 2, SpecId::Genesis, &context) .unwrap(); } @@ -62,7 +62,7 @@ fn main() { assert_eq!(runtime.module_address(&module), runtime.second.address()); let _ = runtime - .dispatch_call(module, working_set, SpecId::Genesis, &context) + .dispatch_call(module, working_set, 3, SpecId::Genesis, &context) .unwrap(); } diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs index 811c20a9d..705978bb2 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs @@ -1,9 +1,10 @@ use jsonrpsee::core::RpcResult; use sov_modules_api::default_context::ZkDefaultContext; use sov_modules_api::macros::{expose_rpc, rpc_gen, DefaultRuntime}; +use sov_modules_api::prelude::*; use sov_modules_api::{ - prelude::*, Address, CallResponse, Context, DispatchCall, EncodeCall, Error, Genesis, - MessageCodec, Module, ModuleInfo, StateValue, WorkingSet, + Address, CallResponse, Context, DispatchCall, EncodeCall, Error, Genesis, MessageCodec, Module, + ModuleInfo, SpecId, StateValue, WorkingSet, }; use sov_state::ZkStorage; @@ -124,7 +125,7 @@ fn main() { let module = RT::decode_call(&serialized_message).unwrap(); let sender = Address::try_from([11; 32].as_ref()).unwrap(); let sequencer = Address::try_from([11; 32].as_ref()).unwrap(); - let context = C::new(sender, sequencer, 1); + let context = C::new(sender, sequencer, 1, SpecId::Genesis, 0); let _ = runtime .dispatch_call(module, working_set, SpecId::Genesis, &context) diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs index a07f77338..dc7389b7e 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs @@ -2,9 +2,10 @@ use borsh::{BorshDeserialize, BorshSerialize}; use jsonrpsee::core::RpcResult; use sov_modules_api::default_context::ZkDefaultContext; use sov_modules_api::macros::{expose_rpc, rpc_gen, DefaultRuntime}; +use sov_modules_api::prelude::*; use sov_modules_api::{ - prelude::*, Address, CallResponse, Context, DispatchCall, EncodeCall, Error, Genesis, - MessageCodec, Module, ModuleInfo, StateValue, WorkingSet, + Address, CallResponse, Context, DispatchCall, EncodeCall, Error, Genesis, MessageCodec, Module, + ModuleInfo, SpecId, StateValue, WorkingSet, }; use sov_state::ZkStorage; @@ -137,7 +138,7 @@ fn main() { let module = RT::decode_call(&serialized_message).unwrap(); let sender = Address::try_from([11; 32].as_ref()).unwrap(); let sequencer = Address::try_from([12; 32].as_ref()).unwrap(); - let context = C::new(sender, sequencer, 1); + let context = C::new(sender, sequencer, 1, SpecId::Genesis, 0); let _ = runtime .dispatch_call(module, working_set, SpecId::Genesis, &context) diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs index 4cacc47b7..cb6661b38 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs @@ -3,7 +3,7 @@ use sov_modules_api::default_context::ZkDefaultContext; use sov_modules_api::macros::{expose_rpc, rpc_gen, DefaultRuntime}; use sov_modules_api::{ Address, CallResponse, Context, DispatchCall, EncodeCall, Error, Genesis, MessageCodec, Module, - ModuleInfo, StateValue, WorkingSet, + ModuleInfo, SpecId, StateValue, WorkingSet, }; use sov_state::ZkStorage; @@ -122,7 +122,7 @@ fn main() { let module = RT::decode_call(&serialized_message).unwrap(); let sender = Address::try_from([11; 32].as_ref()).unwrap(); let sequencer = Address::try_from([11; 32].as_ref()).unwrap(); - let context = C::new(sender, sequencer, 1); + let context = C::new(sender, sequencer, 1, SpecId::Genesis, 0); let _ = runtime .dispatch_call(module, working_set, SpecId::Genesis, &context) From ad2ec14583d5fc6c52aa6e6c60a6267925e0e60c Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Fri, 30 Aug 2024 10:52:58 +0300 Subject: [PATCH 13/17] fix ci again --- .../sov-modules-macros/tests/dispatch/derive_dispatch.rs | 4 ++-- .../tests/rpc/expose_rpc_associated_type_not_static.rs | 3 +-- .../tests/rpc/expose_rpc_associated_types.rs | 3 +-- .../tests/rpc/expose_rpc_associated_types_nested.rs | 3 +-- .../tests/rpc/expose_rpc_first_generic_not_context.rs | 3 +-- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs index eeee8f5f8..3fbd6307f 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/derive_dispatch.rs @@ -42,7 +42,7 @@ fn main() { assert_eq!(runtime.module_address(&module), runtime.first.address()); let _ = runtime - .dispatch_call(module, working_set, 2, SpecId::Genesis, &context) + .dispatch_call(module, working_set, &context) .unwrap(); } @@ -62,7 +62,7 @@ fn main() { assert_eq!(runtime.module_address(&module), runtime.second.address()); let _ = runtime - .dispatch_call(module, working_set, 3, SpecId::Genesis, &context) + .dispatch_call(module, working_set, &context) .unwrap(); } diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs index 705978bb2..db2fade28 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs @@ -95,7 +95,6 @@ pub mod my_module { } use my_module::query::{QueryModuleRpcImpl, QueryModuleRpcServer}; -use sov_rollup_interface::spec::SpecId; #[expose_rpc] #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] @@ -128,6 +127,6 @@ fn main() { let context = C::new(sender, sequencer, 1, SpecId::Genesis, 0); let _ = runtime - .dispatch_call(module, working_set, SpecId::Genesis, &context) + .dispatch_call(module, working_set, &context) .unwrap(); } diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs index 76d5ac71c..6c63c9dee 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs @@ -95,7 +95,6 @@ pub mod my_module { } use my_module::query::{QueryModuleRpcImpl, QueryModuleRpcServer}; -use sov_rollup_interface::spec::SpecId; #[expose_rpc] #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] @@ -128,6 +127,6 @@ fn main() { let context = C::new(sender, sequencer, 1, SpecId::Genesis, 0); let _ = runtime - .dispatch_call(module, working_set, SpecId::Genesis, &context) + .dispatch_call(module, working_set, &context) .unwrap(); } diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs index dc7389b7e..aedde5c9a 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs @@ -100,7 +100,6 @@ pub mod my_module { } use my_module::query::{QueryModuleRpcImpl, QueryModuleRpcServer}; -use sov_rollup_interface::spec::SpecId; #[expose_rpc] #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] @@ -141,6 +140,6 @@ fn main() { let context = C::new(sender, sequencer, 1, SpecId::Genesis, 0); let _ = runtime - .dispatch_call(module, working_set, SpecId::Genesis, &context) + .dispatch_call(module, working_set, &context) .unwrap(); } diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs index cb6661b38..536224249 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs @@ -92,7 +92,6 @@ pub mod my_module { } use my_module::query::{QueryModuleRpcImpl, QueryModuleRpcServer}; -use sov_rollup_interface::spec::SpecId; #[expose_rpc] #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] @@ -125,6 +124,6 @@ fn main() { let context = C::new(sender, sequencer, 1, SpecId::Genesis, 0); let _ = runtime - .dispatch_call(module, working_set, SpecId::Genesis, &context) + .dispatch_call(module, working_set, &context) .unwrap(); } From 3ff188c6d7b09f345e64a4f2de747e96d3953fa4 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Fri, 30 Aug 2024 10:59:37 +0300 Subject: [PATCH 14/17] change function signature of ApplySoftConfirmationHooks --- crates/citrea-stf/src/hooks_impl.rs | 4 ++-- crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs | 2 +- .../sovereign-sdk/module-system/sov-modules-api/src/hooks.rs | 2 +- .../sov-modules-stf-blueprint/src/stf_blueprint.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/citrea-stf/src/hooks_impl.rs b/crates/citrea-stf/src/hooks_impl.rs index d40693951..778afef18 100644 --- a/crates/citrea-stf/src/hooks_impl.rs +++ b/crates/citrea-stf/src/hooks_impl.rs @@ -101,11 +101,11 @@ impl ApplySoftConfirmationHooks for Runtime { #[cfg_attr(feature = "native", instrument(level = "trace", skip_all, err, ret))] fn end_soft_confirmation_hook( &self, - soft_confirmation_info: &HookSoftConfirmationInfo, + soft_confirmation_info: HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { self.evm - .end_soft_confirmation_hook(soft_confirmation_info, working_set); + .end_soft_confirmation_hook(&soft_confirmation_info, working_set); Ok(()) } } diff --git a/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs b/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs index f0e9c04d5..36069d75d 100644 --- a/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs +++ b/crates/sovereign-sdk/examples/demo-stf/src/hooks_impl.rs @@ -92,7 +92,7 @@ impl ApplySoftConfirmationHooks for Runtime { fn end_soft_confirmation_hook( &self, - _soft_confirmation: &HookSoftConfirmationInfo, + _soft_confirmation: HookSoftConfirmationInfo, _working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError> { Ok(()) diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs index e8a6b8b90..7240bd26f 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/hooks.rs @@ -73,7 +73,7 @@ pub trait ApplySoftConfirmationHooks { /// If this hook returns Err rollup panics fn end_soft_confirmation_hook( &self, - soft_confirmation_info: &HookSoftConfirmationInfo, + soft_confirmation_info: HookSoftConfirmationInfo, working_set: &mut WorkingSet, ) -> Result<(), SoftConfirmationError>; } diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index a0554eff0..ce24b3979 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -206,7 +206,7 @@ where if let Err(e) = self .runtime - .end_soft_confirmation_hook(&hook_soft_confirmation_info, &mut batch_workspace) + .end_soft_confirmation_hook(hook_soft_confirmation_info, &mut batch_workspace) { // TODO: will be covered in https://github.com/Sovereign-Labs/sovereign-sdk/issues/421 native_error!("Failed on `end_soft_confirmation_hook`: {:?}", e); From b7f38a9ea2b8f26b71a2758fe630ee8bd1e6d3e3 Mon Sep 17 00:00:00 2001 From: Roman Proskuryakoff Date: Fri, 30 Aug 2024 12:46:11 +0400 Subject: [PATCH 15/17] Inline verify_txs_stateless and decode_txs to reduce .collect() --- .../src/stf_blueprint.rs | 74 +++++++------------ .../src/tx_verifier.rs | 36 --------- 2 files changed, 25 insertions(+), 85 deletions(-) diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index ce24b3979..ceca7a705 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -1,9 +1,12 @@ use std::marker::PhantomData; +use borsh::BorshDeserialize; use sov_modules_api::hooks::HookSoftConfirmationInfo; +use sov_modules_api::transaction::Transaction; use sov_modules_api::{ - native_debug, native_error, Context, DaSpec, DispatchCall, SpecId, StateCheckpoint, WorkingSet, + native_debug, native_error, Context, DaSpec, Spec, SpecId, StateCheckpoint, WorkingSet, }; +use sov_rollup_interface::digest::Digest; use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::stf::{ SoftConfirmationError, SoftConfirmationReceipt, TransactionReceipt, @@ -11,8 +14,7 @@ use sov_rollup_interface::stf::{ #[cfg(feature = "native")] use tracing::instrument; -use crate::tx_verifier::{verify_txs_stateless, TransactionAndRawHash}; -use crate::{RawTx, Runtime, RuntimeTxHook, SlashingReason, TxEffect}; +use crate::{Runtime, RuntimeTxHook, TxEffect}; /// An implementation of the /// [`StateTransitionFunction`](sov_rollup_interface::stf::StateTransitionFunction) @@ -64,23 +66,27 @@ where txs: Vec>, mut sc_workspace: WorkingSet, ) -> (WorkingSet, Vec>) { - let txs = self.verify_txs_stateless_soft(txs); + let mut tx_receipts = Vec::with_capacity(txs.len()); + for raw_tx in txs { + let raw_tx_hash = ::Hasher::digest(&raw_tx).into(); + // Stateless verification of transaction, such as signature check + // Single malformed transaction results in sequencer slashing. + let tx = Transaction::::deserialize_reader(&mut &*raw_tx) + .expect("Sequencer must not include non-deserializable transaction."); + tx.verify() + .expect("Sequencer must include correctly signed transaction."); + // Checks that runtime message can be decoded from transaction. + // If a single message cannot be decoded, sequencer is slashed + let msg = match RT::decode_call(tx.runtime_msg()) { + Ok(msg) => msg, + Err(e) => { + native_error!("Tx 0x{} decoding error: {}", hex::encode(raw_tx_hash), e); + panic!("Decoding transactions from the sequencer failed"); + } + }; - let messages = self - .decode_txs(&txs) - .expect("Decoding transactions from the sequencer failed"); + // Dispatching transactions - // Sanity check after pre processing - assert_eq!( - txs.len(), - messages.len(), - "Error in preprocessing batch, there should be same number of txs and messages" - ); - // Dispatching transactions - let mut tx_receipts = Vec::with_capacity(txs.len()); - for (TransactionAndRawHash { tx, raw_tx_hash }, msg) in - txs.into_iter().zip(messages.into_iter()) - { // Pre dispatch hook // TODO set the sequencer pubkey let hook = RuntimeTxHook { @@ -223,7 +229,7 @@ where da_slot_height: soft_confirmation.da_slot_height(), da_slot_hash: soft_confirmation.da_slot_hash().into(), da_slot_txs_commitment: soft_confirmation.da_slot_txs_commitment().into(), - soft_confirmation_signature: soft_confirmation.signature().to_vec(), + soft_confirmation_signature: soft_confirmation.signature(), pub_key: soft_confirmation.sequencer_pub_key().to_vec(), deposit_data: soft_confirmation.deposit_data().clone(), l1_fee_rate: soft_confirmation.l1_fee_rate(), @@ -232,34 +238,4 @@ where batch_workspace.checkpoint(), ) } - - // Stateless verification of transaction, such as signature check - // Single malformed transaction results in sequencer slashing. - fn verify_txs_stateless_soft(&self, txs: Vec>) -> Vec> { - verify_txs_stateless( - txs.into_iter() - .map(|tx| RawTx { data: tx }) - .collect::>(), - ) - .expect("Sequencer must not include non-deserializable transaction.") - } - - // Checks that runtime message can be decoded from transaction. - // If a single message cannot be decoded, sequencer is slashed - fn decode_txs( - &self, - txs: &[TransactionAndRawHash], - ) -> Result::Decodable>, SlashingReason> { - let mut decoded_messages = Vec::with_capacity(txs.len()); - for TransactionAndRawHash { tx, raw_tx_hash } in txs { - match RT::decode_call(tx.runtime_msg()) { - Ok(msg) => decoded_messages.push(msg), - Err(e) => { - native_error!("Tx 0x{} decoding error: {}", hex::encode(raw_tx_hash), e); - return Err(SlashingReason::InvalidTransactionEncoding); - } - } - } - Ok(decoded_messages) - } } diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/tx_verifier.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/tx_verifier.rs index 82621ad92..85eeee836 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/tx_verifier.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/tx_verifier.rs @@ -1,19 +1,5 @@ -use std::io::Cursor; - use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; -use sov_modules_api::transaction::Transaction; -use sov_modules_api::{native_debug, Context, Spec}; -use sov_rollup_interface::digest::Digest; -#[cfg(feature = "native")] -use tracing::instrument; - -type RawTxHash = [u8; 32]; - -pub(crate) struct TransactionAndRawHash { - pub(crate) tx: Transaction, - pub(crate) raw_tx_hash: RawTxHash, -} /// RawTx represents a serialized rollup transaction received from the DA. #[derive(Debug, PartialEq, Clone, BorshDeserialize, BorshSerialize, Serialize, Deserialize, Eq)] @@ -21,25 +7,3 @@ pub struct RawTx { /// Serialized transaction. pub data: Vec, } - -impl RawTx { - fn hash(&self) -> [u8; 32] { - ::Hasher::digest(&self.data).into() - } -} - -#[cfg_attr(feature = "native", instrument(level = "trace", skip_all, err))] -pub(crate) fn verify_txs_stateless( - raw_txs: Vec, -) -> anyhow::Result>> { - let mut txs = Vec::with_capacity(raw_txs.len()); - native_debug!("Verifying {} transactions", raw_txs.len()); - for raw_tx in raw_txs { - let raw_tx_hash = raw_tx.hash::(); - let mut data = Cursor::new(&raw_tx.data); - let tx = Transaction::::deserialize_reader(&mut data)?; - tx.verify()?; - txs.push(TransactionAndRawHash { tx, raw_tx_hash }); - } - Ok(txs) -} From 12e00f4929d5d004d93433dd8737621d97e9dd60 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Fri, 30 Aug 2024 12:15:00 +0300 Subject: [PATCH 16/17] fix rpc tests, add issue urls to TODOs --- .../sov-modules-core/src/module/spec.rs | 1 + ...xpose_rpc_first_generic_not_context.stderr | 578 +++++++++--------- .../src/stf_blueprint.rs | 2 +- 3 files changed, 291 insertions(+), 290 deletions(-) diff --git a/crates/sovereign-sdk/module-system/sov-modules-core/src/module/spec.rs b/crates/sovereign-sdk/module-system/sov-modules-core/src/module/spec.rs index 3b8f3ea87..76f4b296c 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-core/src/module/spec.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-core/src/module/spec.rs @@ -112,6 +112,7 @@ pub trait Context: Spec + Clone + Debug + PartialEq + 'static { ) -> Self; /// TODO: remove + /// https://github.com/chainwayxyz/citrea/issues/1060 fn sequencer(&self) -> &Self::Address; /// Returns the height of the current slot as reported by the kernel. This value is diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr index 790a9dead..7e20c1987 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr @@ -1,128 +1,128 @@ error[E0220]: associated type `Storage` not found for `S` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:1 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:1 | -97 | #[expose_rpc] +96 | #[expose_rpc] | ^^^^^^^^^^^^^ associated type `Storage` not found | = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:16 - | -100 | struct Runtime { - | ^ the trait `sov_modules_api::Context` is not implemented for `S` - | + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:16 + | +99 | struct Runtime { + | ^ the trait `sov_modules_api::Context` is not implemented for `S` + | note: required by a bound in `sov_modules_api::Genesis::Context` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/mod.rs - | - | type Context: Context; - | ^^^^^^^ required by this bound in `Genesis::Context` + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/mod.rs + | + | type Context: Context; + | ^^^^^^^ required by this bound in `Genesis::Context` help: consider further restricting this bound - | -100 | struct Runtime { - | ++++++++++++++++++++++++++ + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ error[E0277]: `::Data` cannot be shared between threads safely - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:8 - | -100 | struct Runtime { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Data` cannot be shared between threads safely - | - = help: within `Runtime`, the trait `std::marker::Sync` is not implemented for `::Data`, which is required by `Runtime: std::marker::Sync` + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:8 + | +99 | struct Runtime { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Data` cannot be shared between threads safely + | + = help: within `Runtime`, the trait `std::marker::Sync` is not implemented for `::Data`, which is required by `Runtime: std::marker::Sync` note: required because it appears within the type `PhantomData<::Data>` - --> $RUST/core/src/marker.rs - | - | pub struct PhantomData; - | ^^^^^^^^^^^ + --> $RUST/core/src/marker.rs + | + | pub struct PhantomData; + | ^^^^^^^^^^^ note: required because it appears within the type `sov_modules_api::StateValue<::Data>` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/value.rs - | - | pub struct StateValue { - | ^^^^^^^^^^ + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/value.rs + | + | pub struct StateValue { + | ^^^^^^^^^^ note: required because it appears within the type `QueryModule::Data>` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:33:16 - | -33 | pub struct QueryModule { - | ^^^^^^^^^^^ + --> tests/rpc/expose_rpc_first_generic_not_context.rs:33:16 + | +33 | pub struct QueryModule { + | ^^^^^^^^^^^ note: required because it appears within the type `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:8 - | -100 | struct Runtime { - | ^^^^^^^ + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:8 + | +99 | struct Runtime { + | ^^^^^^^ note: required by a bound in `sov_modules_api::DispatchCall` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs - | - | pub trait DispatchCall: Send + Sync { - | ^^^^ required by this bound in `DispatchCall` + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs + | + | pub trait DispatchCall: Send + Sync { + | ^^^^ required by this bound in `DispatchCall` help: consider further restricting the associated type - | -100 | struct Runtime where ::Data: std::marker::Sync { - | ++++++++++++++++++++++++++++++++++++++++++++++ + | +99 | struct Runtime where ::Data: std::marker::Sync { + | ++++++++++++++++++++++++++++++++++++++++++++++ error[E0277]: `::Data` cannot be sent between threads safely - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:8 - | -100 | struct Runtime { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Data` cannot be sent between threads safely - | - = help: within `Runtime`, the trait `Send` is not implemented for `::Data`, which is required by `Runtime: Send` + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:8 + | +99 | struct Runtime { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Data` cannot be sent between threads safely + | + = help: within `Runtime`, the trait `Send` is not implemented for `::Data`, which is required by `Runtime: Send` note: required because it appears within the type `PhantomData<::Data>` - --> $RUST/core/src/marker.rs - | - | pub struct PhantomData; - | ^^^^^^^^^^^ + --> $RUST/core/src/marker.rs + | + | pub struct PhantomData; + | ^^^^^^^^^^^ note: required because it appears within the type `sov_modules_api::StateValue<::Data>` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/value.rs - | - | pub struct StateValue { - | ^^^^^^^^^^ + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/value.rs + | + | pub struct StateValue { + | ^^^^^^^^^^ note: required because it appears within the type `QueryModule::Data>` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:33:16 - | -33 | pub struct QueryModule { - | ^^^^^^^^^^^ + --> tests/rpc/expose_rpc_first_generic_not_context.rs:33:16 + | +33 | pub struct QueryModule { + | ^^^^^^^^^^^ note: required because it appears within the type `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:8 - | -100 | struct Runtime { - | ^^^^^^^ + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:8 + | +99 | struct Runtime { + | ^^^^^^^ note: required by a bound in `sov_modules_api::DispatchCall` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs - | - | pub trait DispatchCall: Send + Sync { - | ^^^^ required by this bound in `DispatchCall` + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs + | + | pub trait DispatchCall: Send + Sync { + | ^^^^ required by this bound in `DispatchCall` help: consider further restricting the associated type - | -100 | struct Runtime where ::Data: Send { - | +++++++++++++++++++++++++++++++++ + | +99 | struct Runtime where ::Data: Send { + | +++++++++++++++++++++++++++++++++ error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:16 - | -100 | struct Runtime { - | ^ the trait `sov_modules_api::Context` is not implemented for `S` - | + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:16 + | +99 | struct Runtime { + | ^ the trait `sov_modules_api::Context` is not implemented for `S` + | note: required by a bound in `sov_modules_api::DispatchCall::Context` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs - | - | type Context: Context; - | ^^^^^^^ required by this bound in `DispatchCall::Context` + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs + | + | type Context: Context; + | ^^^^^^^ required by this bound in `DispatchCall::Context` help: consider further restricting this bound - | -100 | struct Runtime { - | ++++++++++++++++++++++++++ + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ error[E0277]: `::Data` cannot be shared between threads safely - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ `::Data` cannot be shared between threads safely | = help: within `RuntimeCall`, the trait `std::marker::Sync` is not implemented for `::Data`, which is required by `RuntimeCall: std::marker::Sync` note: required because it appears within the type `RuntimeCall` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ note: required by a bound in `sov_modules_api::DispatchCall::Decodable` --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs @@ -132,20 +132,20 @@ note: required by a bound in `sov_modules_api::DispatchCall::Decodable` = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting the associated type | -100| struct Runtime where ::Data: std::marker::Sync { +99 | struct Runtime where ::Data: std::marker::Sync { | ++++++++++++++++++++++++++++++++++++++++++++++ error[E0277]: `::Data` cannot be sent between threads safely - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ `::Data` cannot be sent between threads safely | = help: within `RuntimeCall`, the trait `Send` is not implemented for `::Data`, which is required by `RuntimeCall: Send` note: required because it appears within the type `RuntimeCall` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ note: required by a bound in `sov_modules_api::DispatchCall::Decodable` --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs @@ -155,108 +155,108 @@ note: required by a bound in `sov_modules_api::DispatchCall::Decodable` = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting the associated type | -100| struct Runtime where ::Data: Send { +99 | struct Runtime where ::Data: Send { | +++++++++++++++++++++++++++++++++ error[E0277]: the trait bound `S: Spec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ the trait `Spec` is not implemented for `S` | = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound | -100| struct Runtime { +99 | struct Runtime { | +++++++++++++++++++++++ error[E0277]: the trait bound `S: Spec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:1 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:1 | -97 | #[expose_rpc] +96 | #[expose_rpc] | ^^^^^^^^^^^^^ the trait `Spec` is not implemented for `S` | = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound | -100| struct Runtime { +99 | struct Runtime { | +++++++++++++++++++++++ error[E0053]: method `get_working_set` has an incompatible type for trait - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:1 - | -97 | #[expose_rpc] - | ^^^^^^^^^^^^^ - | | - | expected type parameter `C`, found type parameter `S` - | help: change the output type to match the trait: `sov_modules_api::WorkingSet` + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:1 + | +96 | #[expose_rpc] + | ^^^^^^^^^^^^^ + | | + | expected type parameter `C`, found type parameter `S` + | help: change the output type to match the trait: `sov_modules_api::WorkingSet` ... -100 | struct Runtime { - | - - expected type parameter - | | - | found type parameter - | +99 | struct Runtime { + | - - expected type parameter + | | + | found type parameter + | note: type in trait - --> tests/rpc/expose_rpc_first_generic_not_context.rs:86:57 - | -86 | pub fn query_value(&self, working_set: &mut WorkingSet) -> RpcResult { - | ^^^^^^^^^^^^^ - = note: expected signature `fn(&RpcStorage<_, _>) -> sov_modules_api::WorkingSet` - found signature `fn(&RpcStorage<_, _>) -> sov_modules_api::WorkingSet` - = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound - = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters - = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) + --> tests/rpc/expose_rpc_first_generic_not_context.rs:86:57 + | +86 | pub fn query_value(&self, working_set: &mut WorkingSet) -> RpcResult { + | ^^^^^^^^^^^^^ + = note: expected signature `fn(&RpcStorage) -> sov_modules_api::WorkingSet` + found signature `fn(&RpcStorage) -> sov_modules_api::WorkingSet` + = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound + = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters + = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:10 - | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] - | ^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` - | + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:10 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` + | note: required by a bound in `sov_modules_api::WorkingSet` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs - | - | pub struct WorkingSet { - | ^^^^^^^ required by this bound in `WorkingSet` - = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs + | + | pub struct WorkingSet { + | ^^^^^^^ required by this bound in `WorkingSet` + = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound - | -100 | struct Runtime { - | ++++++++++++++++++++++++++ + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:19 - | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] - | ^^^^^^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` - | + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` + | note: required by a bound in `sov_modules_api::WorkingSet` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs - | - | pub struct WorkingSet { - | ^^^^^^^ required by this bound in `WorkingSet` - = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs + | + | pub struct WorkingSet { + | ^^^^^^^ required by this bound in `WorkingSet` + = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound - | -100 | struct Runtime { - | ++++++++++++++++++++++++++ + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:1 - | -97 | #[expose_rpc] - | ^^^^^^^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` - | + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:1 + | +96 | #[expose_rpc] + | ^^^^^^^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` + | note: required by a bound in `sov_modules_api::WorkingSet` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs - | - | pub struct WorkingSet { - | ^^^^^^^ required by this bound in `WorkingSet` - = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs + | + | pub struct WorkingSet { + | ^^^^^^^ required by this bound in `WorkingSet` + = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound - | -100 | struct Runtime { - | ++++++++++++++++++++++++++ + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ error[E0599]: no method named `set` found for struct `sov_modules_api::StateValue` in the current scope --> tests/rpc/expose_rpc_first_generic_not_context.rs:55:23 @@ -325,127 +325,127 @@ help: trait `StateValueAccessor` which provides `get` is implemented but not in | error[E0271]: type mismatch resolving `::Data> as ModuleInfo>::Context == S` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:10 - | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] - | ^^^^^^^ expected type parameter `S`, found type parameter `C` -99 | #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] -100 | struct Runtime { - | - - found type parameter - | | - | expected type parameter - | - = note: expected type parameter `S` - found type parameter `C` - = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound - = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters - = note: required for the cast from `&QueryModule::Data>` to `&dyn sov_modules_api::ModuleInfo` - = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:10 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^ expected type parameter `S`, found type parameter `C` +98 | #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] +99 | struct Runtime { + | - - found type parameter + | | + | expected type parameter + | + = note: expected type parameter `S` + found type parameter `C` + = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound + = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters + = note: required for the cast from `&QueryModule::Data>` to `&dyn sov_modules_api::ModuleInfo` + = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:10 - | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] - | ^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` - | + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:10 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` + | note: required by a bound in `sort_values_by_modules_dependencies` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs - | - | pub fn sort_values_by_modules_dependencies( - | ^^^^^^^ required by this bound in `sort_values_by_modules_dependencies` - = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs + | + | pub fn sort_values_by_modules_dependencies( + | ^^^^^^^ required by this bound in `sort_values_by_modules_dependencies` + = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound - | -100 | struct Runtime { - | ++++++++++++++++++++++++++ + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ error[E0308]: mismatched types - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:10 - | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] - | ^^^^^^^ - | | - | expected `&mut WorkingSet`, found `&mut WorkingSet` - | arguments to this function are incorrect -99 | #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] -100 | struct Runtime { - | - - expected type parameter - | | - | found type parameter - | - = note: expected mutable reference `&mut sov_modules_api::WorkingSet` - found mutable reference `&mut sov_modules_api::WorkingSet` - = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound - = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:10 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^ + | | + | expected `&mut WorkingSet`, found `&mut WorkingSet` + | arguments to this function are incorrect +98 | #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] +99 | struct Runtime { + | - - expected type parameter + | | + | found type parameter + | + = note: expected mutable reference `&mut sov_modules_api::WorkingSet` + found mutable reference `&mut sov_modules_api::WorkingSet` + = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound + = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters note: method defined here - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/mod.rs - | - | fn genesis( - | ^^^^^^^ - = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/mod.rs + | + | fn genesis( + | ^^^^^^^ + = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: arguments to this function are incorrect - --> tests/rpc/expose_rpc_first_generic_not_context.rs:98:19 - | -98 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] - | ^^^^^^^^^^^^ - | | - | expected `&C`, found `&S` - | expected `&mut WorkingSet`, found `&mut WorkingSet` -99 | #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] -100 | struct Runtime { - | - - - | | | - | | expected type parameter - | | expected type parameter - | found type parameter - | found type parameter - | - = note: expected reference `&C` - found reference `&S` - = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound - = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters - = note: expected mutable reference `&mut sov_modules_api::WorkingSet` - found mutable reference `&mut sov_modules_api::WorkingSet` - = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound - = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^^^^^^ + | | + | expected `&C`, found `&S` + | expected `&mut WorkingSet`, found `&mut WorkingSet` +98 | #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] +99 | struct Runtime { + | - - + | | | + | | expected type parameter + | | expected type parameter + | found type parameter + | found type parameter + | + = note: expected reference `&C` + found reference `&S` + = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound + = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters + = note: expected mutable reference `&mut sov_modules_api::WorkingSet` + found mutable reference `&mut sov_modules_api::WorkingSet` + = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound + = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters note: method defined here - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/mod.rs - | - | fn call( - | ^^^^ - = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/mod.rs + | + | fn call( + | ^^^^ + = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:1 - | -97 | #[expose_rpc] - | ^^^^^^^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` - | + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:1 + | +96 | #[expose_rpc] + | ^^^^^^^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` + | note: required by a bound in `sov_modules_api::WorkingSet::::new` - --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs - | - | impl WorkingSet { - | ^^^^^^^ required by this bound in `WorkingSet::::new` + --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs + | + | impl WorkingSet { + | ^^^^^^^ required by this bound in `WorkingSet::::new` ... - | pub fn new(inner: ::Storage) -> Self { - | --- required by a bound in this associated function - = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) + | pub fn new(inner: ::Storage) -> Self { + | --- required by a bound in this associated function + = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound - | -100 | struct Runtime { - | ++++++++++++++++++++++++++ + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ error[E0599]: the function or associated item `default` exists for struct `Runtime`, but its trait bounds were not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:115:50 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:114:50 | -100 | struct Runtime { +99 | struct Runtime { | --------------------------------------- function or associated item `default` not found for this struct because it doesn't satisfy `_: Default` ... -104 | struct ActualSpec; +103 | struct ActualSpec; | ----------------- doesn't satisfy `ActualSpec: sov_modules_api::Context` ... -115 | let runtime = &mut Runtime::::default(); +114 | let runtime = &mut Runtime::::default(); | ^^^^^^^ function or associated item cannot be called on `Runtime` due to unsatisfied trait bounds | ::: $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs @@ -466,79 +466,79 @@ note: the trait `sov_modules_api::Context` must be implemented candidate #1: `std::default::Default` error[E0277]: the trait bound `ZkDefaultContext: TestSpec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:115:24 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:114:24 | -115 | let runtime = &mut Runtime::::default(); +114 | let runtime = &mut Runtime::::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TestSpec` is not implemented for `ZkDefaultContext` | = help: the trait `TestSpec` is implemented for `ActualSpec` note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:19 | -100 | struct Runtime { +99 | struct Runtime { | ^^^^^^^^ required by this bound in `Runtime` error[E0277]: the trait bound `ActualSpec: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:115:24 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:114:24 | -115 | let runtime = &mut Runtime::::default(); +114 | let runtime = &mut Runtime::::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `ActualSpec` | = help: the following other types implement trait `sov_modules_api::Context`: DefaultContext ZkDefaultContext note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:32 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:32 | -100 | struct Runtime { +99 | struct Runtime { | ^^^^^^^ required by this bound in `Runtime` error[E0277]: the trait bound `Runtime: EncodeCall>` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:121:10 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:120:10 | -121 | >>::encode_call(message); +120 | >>::encode_call(message); | ^^ the trait `EncodeCall>` is not implemented for `Runtime` | = help: the trait `EncodeCall::Data>>` is implemented for `Runtime` error[E0277]: the trait bound `ZkDefaultContext: TestSpec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:121:10 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:120:10 | -121 | >>::encode_call(message); +120 | >>::encode_call(message); | ^^ the trait `TestSpec` is not implemented for `ZkDefaultContext` | = help: the trait `TestSpec` is implemented for `ActualSpec` note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:19 | -100 | struct Runtime { +99 | struct Runtime { | ^^^^^^^^ required by this bound in `Runtime` error[E0277]: the trait bound `ActualSpec: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:121:10 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:120:10 | -121 | >>::encode_call(message); +120 | >>::encode_call(message); | ^^ the trait `sov_modules_api::Context` is not implemented for `ActualSpec` | = help: the following other types implement trait `sov_modules_api::Context`: DefaultContext ZkDefaultContext note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:32 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:32 | -100 | struct Runtime { +99 | struct Runtime { | ^^^^^^^ required by this bound in `Runtime` error[E0599]: the function or associated item `decode_call` exists for struct `Runtime`, but its trait bounds were not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:122:22 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:121:22 | -100 | struct Runtime { +99 | struct Runtime { | --------------------------------------- function or associated item `decode_call` not found for this struct because it doesn't satisfy `_: DispatchCall` ... -104 | struct ActualSpec; +103 | struct ActualSpec; | ----------------- doesn't satisfy `ActualSpec: sov_modules_api::Context` ... -122 | let module = RT::decode_call(&serialized_message).unwrap(); +121 | let module = RT::decode_call(&serialized_message).unwrap(); | ^^^^^^^^^^^ function or associated item cannot be called on `Runtime` due to unsatisfied trait bounds | ::: $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs @@ -559,29 +559,29 @@ note: the trait `sov_modules_api::Context` must be implemented candidate #1: `sov_modules_api::DispatchCall` error[E0277]: the trait bound `ZkDefaultContext: TestSpec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:122:18 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:121:18 | -122 | let module = RT::decode_call(&serialized_message).unwrap(); +121 | let module = RT::decode_call(&serialized_message).unwrap(); | ^^ the trait `TestSpec` is not implemented for `ZkDefaultContext` | = help: the trait `TestSpec` is implemented for `ActualSpec` note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:19 | -100 | struct Runtime { +99 | struct Runtime { | ^^^^^^^^ required by this bound in `Runtime` error[E0277]: the trait bound `ActualSpec: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:122:18 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:121:18 | -122 | let module = RT::decode_call(&serialized_message).unwrap(); +121 | let module = RT::decode_call(&serialized_message).unwrap(); | ^^ the trait `sov_modules_api::Context` is not implemented for `ActualSpec` | = help: the following other types implement trait `sov_modules_api::Context`: DefaultContext ZkDefaultContext note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:100:32 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:32 | -100 | struct Runtime { +99 | struct Runtime { | ^^^^^^^ required by this bound in `Runtime` diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs index ceca7a705..c7f3b8491 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/stf_blueprint.rs @@ -70,7 +70,7 @@ where for raw_tx in txs { let raw_tx_hash = ::Hasher::digest(&raw_tx).into(); // Stateless verification of transaction, such as signature check - // Single malformed transaction results in sequencer slashing. + // TODO: https://github.com/chainwayxyz/citrea/issues/1061 let tx = Transaction::::deserialize_reader(&mut &*raw_tx) .expect("Sequencer must not include non-deserializable transaction."); tx.verify() From 49e883b855d78307358ff426a04fa980998a6f60 Mon Sep 17 00:00:00 2001 From: Roman Proskuryakoff Date: Fri, 30 Aug 2024 13:36:26 +0400 Subject: [PATCH 17/17] trybuild=overwrite --- .../tests/rpc/expose_rpc_first_generic_not_context.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr index 7e20c1987..cb99bf2ba 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr @@ -201,8 +201,8 @@ note: type in trait | 86 | pub fn query_value(&self, working_set: &mut WorkingSet) -> RpcResult { | ^^^^^^^^^^^^^ - = note: expected signature `fn(&RpcStorage) -> sov_modules_api::WorkingSet` - found signature `fn(&RpcStorage) -> sov_modules_api::WorkingSet` + = note: expected signature `fn(&RpcStorage<_, _>) -> sov_modules_api::WorkingSet` + found signature `fn(&RpcStorage<_, _>) -> sov_modules_api::WorkingSet` = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info)