From 87dfc812bd2d7eedd1d0723cdafabc444b6caa21 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Tue, 28 Nov 2023 14:11:38 +0100 Subject: [PATCH] fix blockifier API changes --- .../ef-testing/src/evm_sequencer/account.rs | 7 ++-- .../ef-testing/src/evm_sequencer/evm_state.rs | 42 +++++++++---------- crates/ef-testing/src/evm_sequencer/utils.rs | 2 +- crates/sequencer/src/sequencer.rs | 1 + crates/sequencer/src/transaction.rs | 1 + 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/crates/ef-testing/src/evm_sequencer/account.rs b/crates/ef-testing/src/evm_sequencer/account.rs index 0ab30292..56d383c7 100644 --- a/crates/ef-testing/src/evm_sequencer/account.rs +++ b/crates/ef-testing/src/evm_sequencer/account.rs @@ -1,4 +1,4 @@ -use blockifier::abi::abi_utils::{get_storage_var_address, get_uint256_storage_var_addresses}; +use blockifier::abi::{abi_utils::get_storage_var_address, sierra_types::next_storage_key}; use reth_primitives::{Address, Bytes}; use revm_primitives::U256; use starknet_api::{ @@ -109,8 +109,9 @@ impl KakarotAccount { .flat_map(|(k, v)| { let keys = split_u256(*k).map(Into::into); let values = split_u256(*v).map(Into::::into); - let keys = get_uint256_storage_var_addresses("storage_", &keys).unwrap(); // safe unwrap: all vars are ASCII - vec![(keys.0, values[0]), (keys.1, values[1])] + let low_key = get_storage_var_address("storage_", &keys); + let high_key = next_storage_key(&low_key).unwrap(); // can fail only if low is the max key + vec![(low_key, values[0]), (high_key, values[1])] }) .collect(); storage.append(&mut evm_storage_storage); diff --git a/crates/ef-testing/src/evm_sequencer/evm_state.rs b/crates/ef-testing/src/evm_sequencer/evm_state.rs index cb8a868b..bb557d54 100644 --- a/crates/ef-testing/src/evm_sequencer/evm_state.rs +++ b/crates/ef-testing/src/evm_sequencer/evm_state.rs @@ -1,12 +1,10 @@ -use blockifier::abi::abi_utils::{ - get_erc20_balance_var_addresses, get_storage_var_address, get_uint256_storage_var_addresses, -}; +use blockifier::abi::abi_utils::{get_fee_token_var_address, get_storage_var_address}; +use blockifier::abi::sierra_types::next_storage_key; use blockifier::state::state_api::{State, StateReader, StateResult}; use reth_primitives::{Address, Bytes}; use revm_primitives::U256; use starknet::core::types::FieldElement; use starknet_api::hash::StarkFelt; -use starknet_api::state::StorageKey; use super::account::{AccountType, KakarotAccount}; use super::constants::{ @@ -80,26 +78,23 @@ impl EvmState for KakarotSequencer { let mut storage = vec![]; // Initialize the balance storage var. - let balance_keys = get_erc20_balance_var_addresses(&starknet_address.try_into()?)?; - let balance_keys: [StorageKey; 2] = balance_keys.into(); - let balance_storage = &mut balance_keys - .into_iter() - .zip(balance_values) - .map(|(k, v)| (k, StarkFelt::from(v))) - .collect(); - storage.append(balance_storage); + let balance_low_key = get_fee_token_var_address(&starknet_address.try_into()?); + let balance_high_key = next_storage_key(&balance_low_key)?; + storage.append(&mut vec![ + (balance_low_key, StarkFelt::from(balance_values[0])), + (balance_high_key, StarkFelt::from(balance_values[1])), + ]); // Initialize the allowance storage var. - let allowance_keys = get_uint256_storage_var_addresses( + let allowance_key_low = get_storage_var_address( "ERC20_allowances", &[starknet_address.into(), *KAKAROT_ADDRESS.0.key()], - )?; - let allowance_keys: [StorageKey; 2] = allowance_keys.into(); - let allowance_storage = &mut allowance_keys - .into_iter() - .map(|k| (k, StarkFelt::from(u128::MAX))) - .collect(); - storage.append(allowance_storage); + ); + let allowance_key_high = next_storage_key(&allowance_key_low)?; + storage.append(&mut vec![ + (allowance_key_low, StarkFelt::from(u128::MAX)), + (allowance_key_high, StarkFelt::from(u128::MAX)), + ]); // Write all the storage vars to the sequencer state. for (k, v) in storage { @@ -111,12 +106,13 @@ impl EvmState for KakarotSequencer { /// Returns the storage value at the given key evm storage key. fn get_storage_at(&mut self, evm_address: &Address, key: U256) -> StateResult { let keys = split_u256(key).map(Into::into); - let keys = get_uint256_storage_var_addresses("storage_", &keys).unwrap(); // safe unwrap: all vars are ASCII + let key_low = get_storage_var_address("storage_", &keys); + let key_high = next_storage_key(&key_low)?; let starknet_address = compute_starknet_address(evm_address); - let low = (&mut self.0.state).get_storage_at(starknet_address.try_into()?, keys.0)?; - let high = (&mut self.0.state).get_storage_at(starknet_address.try_into()?, keys.1)?; + let low = (&mut self.0.state).get_storage_at(starknet_address.try_into()?, key_low)?; + let high = (&mut self.0.state).get_storage_at(starknet_address.try_into()?, key_high)?; let low = U256::from_be_bytes(Into::::into(low).to_bytes_be()); let high = U256::from_be_bytes(Into::::into(high).to_bytes_be()); diff --git a/crates/ef-testing/src/evm_sequencer/utils.rs b/crates/ef-testing/src/evm_sequencer/utils.rs index b4edd891..8fd660ea 100644 --- a/crates/ef-testing/src/evm_sequencer/utils.rs +++ b/crates/ef-testing/src/evm_sequencer/utils.rs @@ -42,7 +42,7 @@ pub(crate) fn split_bytecode_to_starkfelt(bytecode: &Bytes) -> Vec { pub(crate) fn split_u256(value: U256) -> [u128; 2] { [ (value & U256::from(u128::MAX)).try_into().unwrap(), // safe unwrap <= U128::MAX. - (value >> 128).try_into().unwrap(), // safe unwrap <= U128::MAX. + (value >> U256::from(128)).try_into().unwrap(), // safe unwrap <= U128::MAX. ] } diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index 02f4945a..ac95a0bb 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -225,6 +225,7 @@ mod tests { signature: TransactionSignature(vec![]), nonce: Nonce(*ZERO_FELT), }), + only_query: false, tx_hash: TransactionHash(*ZERO_FELT), })) } diff --git a/crates/sequencer/src/transaction.rs b/crates/sequencer/src/transaction.rs index 65d9377b..26311afc 100644 --- a/crates/sequencer/src/transaction.rs +++ b/crates/sequencer/src/transaction.rs @@ -58,6 +58,7 @@ impl BroadcastedTransactionWrapper { .collect(), )), }), + only_query: false, tx_hash: TransactionHash(Into::::into(Into::::into( compute_transaction_hash( invoke.sender_address,