diff --git a/crates/ef-testing/src/evm_sequencer/account/mod.rs b/crates/ef-testing/src/evm_sequencer/account/mod.rs index dea89133..5b261953 100644 --- a/crates/ef-testing/src/evm_sequencer/account/mod.rs +++ b/crates/ef-testing/src/evm_sequencer/account/mod.rs @@ -82,9 +82,9 @@ pub mod kkrt_account { } /// Splits a byte array into 31-byte chunks and converts each chunk to a StarkFelt. -pub fn split_bytecode_to_starkfelt(bytecode: &[u8]) -> impl Iterator + '_ { - bytecode.chunks(31).filter_map(|bytes| { - let f = FieldElement::from_byte_slice_be(bytes); +pub fn pack_byte_array_to_starkfelt_array(bytes: &[u8]) -> impl Iterator + '_ { + bytes.chunks(31).filter_map(|chunk_bytes| { + let f = FieldElement::from_byte_slice_be(chunk_bytes); f.map(StarkFelt::from).ok() }) } @@ -121,12 +121,12 @@ mod tests { use reth_primitives::Bytes; #[test] - fn test_split_bytecode_to_starkfelt() { + fn test_pack_byte_array_to_starkfelt_array() { // Given let bytes = Bytes::from([0x01, 0x02, 0x03, 0x04, 0x05]); // When - let result: Vec<_> = split_bytecode_to_starkfelt(&bytes).collect(); + let result: Vec<_> = pack_byte_array_to_starkfelt_array(&bytes).collect(); // Then assert_eq!(result, vec![StarkFelt::from(0x0102030405u64)]); diff --git a/crates/ef-testing/src/evm_sequencer/account/v0.rs b/crates/ef-testing/src/evm_sequencer/account/v0.rs index 1d092cda..b7e57b45 100644 --- a/crates/ef-testing/src/evm_sequencer/account/v0.rs +++ b/crates/ef-testing/src/evm_sequencer/account/v0.rs @@ -6,7 +6,7 @@ use starknet_api::core::PatriciaKey; use starknet_api::{core::Nonce, hash::StarkFelt, state::StorageKey, StarknetApiError}; use starknet_crypto::FieldElement; -use super::{split_bytecode_to_starkfelt, KakarotAccount}; +use super::{pack_byte_array_to_starkfelt_array, KakarotAccount}; use crate::evm_sequencer::constants::storage_variables::{ ACCOUNT_BYTECODE_LEN, ACCOUNT_EVM_ADDRESS, ACCOUNT_IS_INITIALIZED, ACCOUNT_JUMPDESTS_INITIALIZED, ACCOUNT_NONCE, ACCOUNT_STORAGE, ACCOUNT_VALID_JUMPDESTS, @@ -42,7 +42,7 @@ impl KakarotAccount { storage.append(&mut vec![starknet_storage!(ACCOUNT_NONCE, nonce)]); // Initialize the bytecode storage var. - let mut bytecode_storage = split_bytecode_to_starkfelt(code) + let mut bytecode_storage = pack_byte_array_to_starkfelt_array(code) .enumerate() .map(|(i, bytes)| (StorageKey::from(i as u32), bytes)) .collect(); diff --git a/crates/ef-testing/src/evm_sequencer/account/v1.rs b/crates/ef-testing/src/evm_sequencer/account/v1.rs index 80af89ef..90d3f9ad 100644 --- a/crates/ef-testing/src/evm_sequencer/account/v1.rs +++ b/crates/ef-testing/src/evm_sequencer/account/v1.rs @@ -8,7 +8,7 @@ use starknet_api::{ }; use super::KakarotAccount; -use super::{inner_byte_array_pointer, split_bytecode_to_starkfelt}; +use super::{inner_byte_array_pointer, pack_byte_array_to_starkfelt_array}; use crate::evm_sequencer::constants::storage_variables::{ ACCOUNT_EVM_ADDRESS, ACCOUNT_IS_INITIALIZED, ACCOUNT_NONCE, ACCOUNT_STORAGE, }; @@ -32,7 +32,7 @@ fn prepare_bytearray_storage(code: &Bytes) -> Vec<(StorageKey, StarkFelt)> { let bytecode_base_address = get_storage_var_address(ACCOUNT_BYTECODE, &[]); let mut bytearray = vec![(bytecode_base_address, StarkFelt::from(code.len() as u128))]; - let bytecode_storage: Vec<_> = split_bytecode_to_starkfelt(code) + let bytecode_storage: Vec<_> = pack_byte_array_to_starkfelt_array(code) .enumerate() .map(|(index, b)| { let offset = index % 256; diff --git a/crates/ef-testing/src/evm_sequencer/evm_state/v1.rs b/crates/ef-testing/src/evm_sequencer/evm_state/v1.rs index 43dce18d..58c71254 100644 --- a/crates/ef-testing/src/evm_sequencer/evm_state/v1.rs +++ b/crates/ef-testing/src/evm_sequencer/evm_state/v1.rs @@ -458,7 +458,7 @@ mod tests { transaction: reth_primitives::Transaction::Legacy(TxLegacy { chain_id: Some(CHAIN_ID), gas_limit: 1_000_000, - to: reth_primitives::TransactionKind::Call(*TEST_CONTRACT_ADDRESS), + to: reth_primitives::TxKind::Call(*TEST_CONTRACT_ADDRESS), ..Default::default() }), }; diff --git a/crates/ef-testing/src/evm_sequencer/utils.rs b/crates/ef-testing/src/evm_sequencer/utils.rs index 3e7b3ef8..aab9269c 100644 --- a/crates/ef-testing/src/evm_sequencer/utils.rs +++ b/crates/ef-testing/src/evm_sequencer/utils.rs @@ -47,7 +47,25 @@ pub fn to_broadcasted_starknet_transaction( let mut bytes = BytesMut::new(); transaction.transaction.encode_without_signature(&mut bytes); - let mut calldata: Vec<_> = bytes.into_iter().map(FieldElement::from).collect(); + let mut calldata: Vec = { + // Pack the calldata in 31-byte chunks. + #[cfg(feature = "v0")] + { + use crate::evm_sequencer::account::pack_byte_array_to_starkfelt_array; + let bytes_u8: Vec = bytes.into_iter().collect(); + let bytes_len = bytes_u8.len(); + let packed_data: Vec<_> = pack_byte_array_to_starkfelt_array(bytes_u8.as_slice()) + .map(FieldElement::from) + .collect(); + std::iter::once(FieldElement::from(bytes_len)) + .chain(packed_data) + .collect() + } + #[cfg(not(feature = "v0"))] + { + bytes.into_iter().map(FieldElement::from).collect() + } + }; let mut execute_calldata = { #[cfg(feature = "v0")]