Skip to content

Commit

Permalink
dev: remove steps limit (#596)
Browse files Browse the repository at this point in the history
* remove patches

* update block resources limit

* fix blockifier API changes

* rebase

* change steps limit to 20M
  • Loading branch information
greged93 authored Dec 4, 2023
1 parent 3e7c5f2 commit 8e96e9a
Show file tree
Hide file tree
Showing 9 changed files with 1,798 additions and 999 deletions.
2,676 changes: 1,744 additions & 932 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 9 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ incremental = true

[workspace.dependencies]
# Eth deps
ef-tests = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.1.0-alpha.7", features = [
ef-tests = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.1.0-alpha.10", features = [
"ef-tests",
] }
ethers-signers = { git = "https://github.com/gakonst/ethers-rs.git", tag = "v2.0" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.1.0-alpha.7" }
revm-primitives = "1.1"
reth-rlp = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.1.0-alpha.7" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.1.0-alpha.10" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "516f62cc" }
reth-rlp = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.1.0-alpha.10" }

# Starknet deps
cairo-lang-casm = "2.1.0"
cairo-lang-starknet = "2.1.0"
cairo-lang-utils = "2.1.0"
cairo-lang-casm = "2.4.0-rc2"
cairo-lang-starknet = "2.4.0-rc2"
cairo-lang-utils = "2.4.0-rc2"
cairo-vm = "=0.8.2"
blockifier = { package = "blockifier", git = "https://github.com/starkware-libs/blockifier.git", tag = "v0.3.0-rc0" }
blockifier = { package = "blockifier", git = "https://github.com/kkrt-labs/blockifier.git", branch = "v0.4.0-rc9.1" }
starknet = "0.6.0"
starknet-crypto = "0.6.0"
starknet_api = "0.5.0-rc1"
starknet_api = "0.6.0-rc2"

# Other
async-trait = "0.1.58"
Expand Down Expand Up @@ -76,15 +76,6 @@ serde_yaml = "0.9.25"
# Log
log = "0.4.20"

[patch."https://github.com/ethereum/c-kzg-4844"]
c-kzg = { git = "https://github.com/rjected/c-kzg-4844", branch = "dan/add-serde-feature" }

[patch."https://github.com/starkware-libs/blockifier.git"]
blockifier = { package = "blockifier", git = "https://github.com/kkrt-labs/blockifier.git", branch = "v0.3.0-rc0" }


[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }
revm-primitives = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }
cairo-felt = { git = "https://github.com/kkrt-labs/cairo-vm.git", branch = "v0.8.2" }
cairo-vm = { git = "https://github.com/kkrt-labs/cairo-vm.git", branch = "v0.8.2" }
7 changes: 4 additions & 3 deletions crates/ef-testing/src/evm_sequencer/account/v0.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -97,8 +97,9 @@ impl KakarotAccount {
.flat_map(|(k, v)| {
let keys = split_u256(*k).map(Into::into);
let values = split_u256(*v).map(Into::<StarkFelt>::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);
Expand Down
6 changes: 3 additions & 3 deletions crates/ef-testing/src/evm_sequencer/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ lazy_static! {
fee_token_addresses: FeeTokenAddresses{eth_fee_token_address: *ETH_FEE_TOKEN_ADDRESS, strk_fee_token_address: *STRK_FEE_TOKEN_ADDRESS},
vm_resource_fee_cost: Arc::new(VM_RESOURCES.clone()),
gas_prices: GasPrices{eth_l1_gas_price: 1, strk_l1_gas_price: 1},
invoke_tx_max_n_steps: 2_u32.pow(24),
validate_max_n_steps: 2_u32.pow(24),
max_recursion_depth: 1024,
invoke_tx_max_n_steps: 20_000_000,
validate_max_n_steps: 20_000_000,
max_recursion_depth: 2048,
};

// Main addresses
Expand Down
42 changes: 19 additions & 23 deletions crates/ef-testing/src/evm_sequencer/evm_state/v0.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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::execution::errors::EntryPointExecutionError;
use blockifier::state::state_api::{State, StateReader, StateResult};
use blockifier::transaction::errors::TransactionExecutionError;
Expand All @@ -11,7 +10,6 @@ use sequencer::execution::Execution as _;
use sequencer::transaction::BroadcastedTransactionWrapper;
use starknet::core::types::{BroadcastedTransaction, FieldElement};
use starknet_api::hash::StarkFelt;
use starknet_api::state::StorageKey;

use super::Evm;
use crate::evm_sequencer::account::{AccountType, KakarotAccount};
Expand Down Expand Up @@ -57,26 +55,23 @@ impl Evm 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 {
Expand All @@ -88,12 +83,13 @@ impl Evm 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<U256> {
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.state).get_storage_at(starknet_address.try_into()?, keys.0)?;
let high = (&mut self.state).get_storage_at(starknet_address.try_into()?, keys.1)?;
let low = (&mut self.state).get_storage_at(starknet_address.try_into()?, key_low)?;
let high = (&mut self.state).get_storage_at(starknet_address.try_into()?, key_high)?;

let low = U256::from_be_bytes(Into::<FieldElement>::into(low).to_bytes_be());
let high = U256::from_be_bytes(Into::<FieldElement>::into(high).to_bytes_be());
Expand Down
35 changes: 16 additions & 19 deletions crates/ef-testing/src/evm_sequencer/evm_state/v1.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use blockifier::{
abi::abi_utils::{
get_erc20_balance_var_addresses, get_storage_var_address,
get_uint256_storage_var_addresses, starknet_keccak,
abi::{
abi_utils::{get_fee_token_var_address, get_storage_var_address, starknet_keccak},
sierra_types::next_storage_key,
},
execution::{
errors::EntryPointExecutionError,
Expand Down Expand Up @@ -79,26 +79,23 @@ impl Evm 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_key_low = get_fee_token_var_address(&starknet_address.try_into()?);
let balance_key_high = next_storage_key(&balance_key_low)?;
storage.append(&mut vec![
(balance_key_low, StarkFelt::from(balance_values[0])),
(balance_key_high, 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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/ef-testing/src/evm_sequencer/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn account_constructor_args(_evm_address: FieldElement) -> Vec<FieldElement> {
pub 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.
]
}

Expand Down
1 change: 1 addition & 0 deletions crates/sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ mod tests {
signature: TransactionSignature(vec![]),
nonce: Nonce(*ZERO_FELT),
}),
only_query: false,
tx_hash: TransactionHash(*ZERO_FELT),
}))
}
Expand Down
1 change: 1 addition & 0 deletions crates/sequencer/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl BroadcastedTransactionWrapper {
.collect(),
)),
}),
only_query: false,
tx_hash: TransactionHash(Into::<StarkHash>::into(Into::<StarkFelt>::into(
compute_transaction_hash(
invoke.sender_address,
Expand Down

0 comments on commit 8e96e9a

Please sign in to comment.