diff --git a/src/block_hash/block_hash_calculator.rs b/src/block_hash/block_hash_calculator.rs index 2f5b268..41bccd5 100644 --- a/src/block_hash/block_hash_calculator.rs +++ b/src/block_hash/block_hash_calculator.rs @@ -11,7 +11,10 @@ use crate::core::{EventCommitment, ReceiptCommitment, StateDiffCommitment, Trans use crate::crypto::utils::HashChain; use crate::data_availability::L1DataAvailabilityMode; use crate::state::ThinStateDiff; -use crate::transaction::{TransactionHash, TransactionOutputCommon, TransactionSignature}; +use crate::transaction::{ + Event, Fee, GasVector, MessageToL1, TransactionExecutionStatus, TransactionHash, + TransactionSignature, +}; use crate::transaction_hash::ascii_as_felt; #[cfg(test)] @@ -22,9 +25,19 @@ static STARKNET_BLOCK_HASH0: Lazy = Lazy::new(|| { ascii_as_felt("STARKNET_BLOCK_HASH0").expect("ascii_as_felt failed for 'STARKNET_BLOCK_HASH0'") }); +/// The common fields of transaction output types. +#[derive(Clone)] +pub struct TransactionOutputForHash { + pub actual_fee: Fee, + pub events: Vec, + pub execution_status: TransactionExecutionStatus, + pub gas_consumed: GasVector, + pub messages_sent: Vec, +} + pub struct TransactionHashingData { pub transaction_signature: Option, - pub transaction_output: TransactionOutputCommon, + pub transaction_output: TransactionOutputForHash, pub transaction_hash: TransactionHash, } diff --git a/src/block_hash/receipt_commitment.rs b/src/block_hash/receipt_commitment.rs index 4c7ff43..8dfd104 100644 --- a/src/block_hash/receipt_commitment.rs +++ b/src/block_hash/receipt_commitment.rs @@ -1,15 +1,12 @@ use starknet_types_core::felt::Felt; use starknet_types_core::hash::StarkHash; -use super::block_hash_calculator::TransactionHashingData; +use super::block_hash_calculator::{TransactionHashingData, TransactionOutputForHash}; use crate::core::ReceiptCommitment; use crate::crypto::patricia_hash::calculate_root; use crate::crypto::utils::HashChain; use crate::hash::starknet_keccak_hash; -use crate::transaction::{ - ExecutionResources, MessageToL1, TransactionExecutionStatus, TransactionHash, - TransactionOutputCommon, -}; +use crate::transaction::{GasVector, MessageToL1, TransactionExecutionStatus, TransactionHash}; #[cfg(test)] #[path = "receipt_commitment_test.rs"] @@ -19,7 +16,7 @@ mod receipt_commitment_test; #[derive(Clone)] pub struct ReceiptElement { pub transaction_hash: TransactionHash, - pub transaction_output: TransactionOutputCommon, + pub transaction_output: TransactionOutputForHash, } impl From<&TransactionHashingData> for ReceiptElement { @@ -50,7 +47,7 @@ fn calculate_receipt_hash(receipt_element: &ReceiptElement) -> Felt { .chain(&receipt_element.transaction_output.actual_fee.0.into()) .chain(&calculate_messages_sent_hash(&receipt_element.transaction_output.messages_sent)) .chain(&get_revert_reason_hash(&receipt_element.transaction_output.execution_status)); - chain_execution_resources(hash_chain, &receipt_element.transaction_output.execution_resources) + chain_gas_consumed(hash_chain, &receipt_element.transaction_output.gas_consumed) .get_poseidon_hash() } @@ -85,12 +82,9 @@ fn get_revert_reason_hash(execution_status: &TransactionExecutionStatus) -> Felt // L1 gas consumed (In the current RPC: // L1 gas consumed for calldata + L1 gas consumed for steps and builtins. // L1 data gas consumed (In the current RPC: L1 data gas consumed for blob). -fn chain_execution_resources( - hash_chain: HashChain, - execution_resources: &ExecutionResources, -) -> HashChain { +fn chain_gas_consumed(hash_chain: HashChain, gas_consumed: &GasVector) -> HashChain { hash_chain .chain(&Felt::ZERO) // L2 gas consumed - .chain(&execution_resources.gas_consumed.l1_gas.into()) - .chain(&execution_resources.gas_consumed.l1_data_gas.into()) + .chain(&gas_consumed.l1_gas.into()) + .chain(&gas_consumed.l1_data_gas.into()) } diff --git a/src/block_hash/test_utils.rs b/src/block_hash/test_utils.rs index 748e802..cc3b24b 100644 --- a/src/block_hash/test_utils.rs +++ b/src/block_hash/test_utils.rs @@ -1,34 +1,26 @@ -use std::collections::HashMap; - use indexmap::indexmap; use primitive_types::H160; use starknet_types_core::felt::Felt; +use super::block_hash_calculator::TransactionOutputForHash; use crate::core::{ClassHash, CompiledClassHash, ContractAddress, EthAddress, Nonce}; use crate::state::ThinStateDiff; use crate::transaction::{ - Builtin, ExecutionResources, Fee, GasVector, L2ToL1Payload, MessageToL1, - RevertedTransactionExecutionStatus, TransactionExecutionStatus, TransactionOutputCommon, + Fee, GasVector, L2ToL1Payload, MessageToL1, RevertedTransactionExecutionStatus, + TransactionExecutionStatus, }; -pub(crate) fn get_transaction_output() -> TransactionOutputCommon { +pub(crate) fn get_transaction_output() -> TransactionOutputForHash { let execution_status = TransactionExecutionStatus::Reverted(RevertedTransactionExecutionStatus { revert_reason: "aborted".to_string(), }); - let execution_resources = ExecutionResources { - steps: 98, - builtin_instance_counter: HashMap::from([(Builtin::Bitwise, 11), (Builtin::EcOp, 22)]), - memory_holes: 76, - da_gas_consumed: GasVector { l1_gas: 54, l1_data_gas: 10 }, - gas_consumed: GasVector { l1_gas: 16580, l1_data_gas: 32 }, - }; - TransactionOutputCommon { + TransactionOutputForHash { actual_fee: Fee(99804), messages_sent: vec![generate_message_to_l1(34), generate_message_to_l1(56)], events: vec![], execution_status, - execution_resources, + gas_consumed: GasVector { l1_gas: 16580, l1_data_gas: 32 }, } } diff --git a/src/transaction.rs b/src/transaction.rs index 66d1eaa..ffc0d22 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -148,28 +148,6 @@ impl TransactionOutput { } } -/// The common fields of transaction output types. -#[derive(Clone)] -pub struct TransactionOutputCommon { - pub actual_fee: Fee, - pub events: Vec, - pub execution_status: TransactionExecutionStatus, - pub execution_resources: ExecutionResources, - pub messages_sent: Vec, -} - -impl From for TransactionOutputCommon { - fn from(transaction_output: TransactionOutput) -> Self { - Self { - actual_fee: transaction_output.actual_fee(), - events: transaction_output.events().to_vec(), - execution_status: transaction_output.execution_status().to_owned(), - execution_resources: transaction_output.execution_resources().to_owned(), - messages_sent: transaction_output.messages_sent().to_owned(), - } - } -} - /// A declare V0 or V1 transaction (same schema but different version). #[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] pub struct DeclareTransactionV0V1 {