Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
refactor: add strk fee contract address into config (#1750)
Browse files Browse the repository at this point in the history
* refactor: add strk fee contract address into config

* test: check execution configs are loaded correctly
  • Loading branch information
eitanm-starkware authored Mar 17, 2024
1 parent 88f2623 commit ff26f50
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 50 deletions.
8 changes: 5 additions & 3 deletions config/execution/goerli_integration.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"execution_config_segments": {
"0": {
"fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strk_fee_contract_address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"eth_fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"invoke_tx_max_n_steps": 3000000,
"validate_tx_max_n_steps": 1000000,
"max_recursion_depth": 50,
Expand All @@ -20,7 +21,8 @@
}
},
"322171": {
"fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strk_fee_contract_address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"eth_fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"invoke_tx_max_n_steps": 3000000,
"validate_tx_max_n_steps": 1000000,
"max_recursion_depth": 50,
Expand All @@ -39,4 +41,4 @@
}
}
}
}
}
6 changes: 4 additions & 2 deletions config/execution/goerli_testnet.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"execution_config_segments": {
"0": {
"fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strk_fee_contract_address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"eth_fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"invoke_tx_max_n_steps": 3000000,
"validate_tx_max_n_steps": 1000000,
"max_recursion_depth": 50,
Expand All @@ -20,7 +21,8 @@
}
},
"916914": {
"fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strk_fee_contract_address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"eth_fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"invoke_tx_max_n_steps": 3000000,
"validate_tx_max_n_steps": 1000000,
"max_recursion_depth": 50,
Expand Down
5 changes: 3 additions & 2 deletions config/execution/mainnet.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"execution_config_segments": {
"0": {
"fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strk_fee_contract_address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"eth_fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"invoke_tx_max_n_steps": 3000000,
"validate_tx_max_n_steps": 1000000,
"max_recursion_depth": 50,
Expand All @@ -20,4 +21,4 @@
}
}
}
}
}
8 changes: 5 additions & 3 deletions config/execution/sepolia_integration.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"execution_config_segments": {
"0": {
"fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strk_fee_contract_address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"eth_fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"invoke_tx_max_n_steps": 3000000,
"validate_tx_max_n_steps": 1000000,
"max_recursion_depth": 50,
Expand All @@ -20,7 +21,8 @@
}
},
"1746": {
"fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strk_fee_contract_address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"eth_fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"invoke_tx_max_n_steps": 3000000,
"validate_tx_max_n_steps": 1000000,
"max_recursion_depth": 50,
Expand All @@ -39,4 +41,4 @@
}
}
}
}
}
8 changes: 5 additions & 3 deletions config/execution/sepolia_testnet.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"execution_config_segments": {
"0": {
"fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strk_fee_contract_address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"eth_fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"invoke_tx_max_n_steps": 3000000,
"validate_tx_max_n_steps": 1000000,
"max_recursion_depth": 50,
Expand All @@ -20,7 +21,8 @@
}
},
"6329": {
"fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strk_fee_contract_address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"eth_fee_contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"invoke_tx_max_n_steps": 3000000,
"validate_tx_max_n_steps": 1000000,
"max_recursion_depth": 50,
Expand All @@ -39,4 +41,4 @@
}
}
}
}
}
94 changes: 72 additions & 22 deletions crates/papyrus_execution/src/execution_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// TODO(shahak): Add a test for executing when there's a missing casm that's not required and when
// there's a missing casm that is required.
use std::collections::{BTreeMap, HashMap};
use std::path::PathBuf;
use std::sync::Arc;

use assert_matches::assert_matches;
Expand Down Expand Up @@ -63,6 +64,8 @@ use crate::{
RevertedTransaction,
};

const NUM_OF_PRESET_EXECUTION_CONFIGS: usize = 5;

// Test calling entry points of a deprecated class.
#[test]
fn execute_call_cairo0() {
Expand Down Expand Up @@ -656,20 +659,42 @@ fn simulate_invoke_from_new_account_validate_and_charge() {
/// Test that the execution config is loaded correctly. Compare the loaded config to the expected.
#[test]
fn test_default_execution_config() {
let mut vm_resource_fee_cost = HashMap::new();
vm_resource_fee_cost.insert("n_steps".to_owned(), 0.01);
vm_resource_fee_cost.insert("pedersen_builtin".to_owned(), 0.32);
vm_resource_fee_cost.insert("range_check_builtin".to_owned(), 0.16);
vm_resource_fee_cost.insert("ecdsa_builtin".to_owned(), 20.48);
vm_resource_fee_cost.insert("bitwise_builtin".to_owned(), 0.64);
vm_resource_fee_cost.insert("poseidon_builtin".to_owned(), 0.32);
vm_resource_fee_cost.insert("output_builtin".to_owned(), 1.0);
vm_resource_fee_cost.insert("ec_op_builtin".to_owned(), 10.24);
vm_resource_fee_cost.insert("keccak_builtin".to_owned(), 20.48);
let mut execution_config_segments = BTreeMap::new();
execution_config_segments.insert(BlockNumber(0), get_default_block_execution_config());
let expected_config = ExecutionConfigByBlock { execution_config_segments };
let config_from_file = test_get_default_execution_config();
assert_eq!(expected_config, config_from_file);
}

let vm_resource_fee_cost = Arc::new(vm_resource_fee_cost);
let block_execution_config = BlockExecutionConfig {
fee_contract_address: contract_address!(
/// Test that the execution configs are loaded correctly. Compare the loaded configs to the
/// expected.
#[test]
fn test_preset_execution_configs() {
let mut execution_configs: Vec<ExecutionConfigByBlock> = Vec::new();
let preset_files_dir = "../../config/execution";
for path in preset_files_dir.parse::<PathBuf>().unwrap().read_dir().unwrap() {
let path = path.unwrap().path();
let execution_config_file = path.try_into().unwrap();
execution_configs.push(execution_config_file);
}
assert_eq!(execution_configs.len(), NUM_OF_PRESET_EXECUTION_CONFIGS);
for config in execution_configs {
for (block_number, segment) in config.execution_config_segments {
if block_number == BlockNumber(0) {
assert_eq!(segment.vm_resource_fee_cost, get_vm_resource_fee_cost_first_segment());
} else {
assert_eq!(segment.vm_resource_fee_cost, get_vm_resource_fee_cost_second_segment());
}
}
}
}

fn get_default_block_execution_config() -> BlockExecutionConfig {
BlockExecutionConfig {
strk_fee_contract_address: contract_address!(
"0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
),
eth_fee_contract_address: contract_address!(
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
),
invoke_tx_max_n_steps: 3_000_000,
Expand All @@ -678,20 +703,15 @@ fn test_default_execution_config() {
step_gas_cost: VersionedConstants::latest_constants().gas_cost("step_gas_cost"),
initial_gas_cost: 10_u64.pow(8)
* VersionedConstants::latest_constants().gas_cost("step_gas_cost"),
vm_resource_fee_cost,
};
let mut execution_config_segments = BTreeMap::new();
execution_config_segments.insert(BlockNumber(0), block_execution_config);
let expected_config = ExecutionConfigByBlock { execution_config_segments };
let config_from_file = test_get_default_execution_config();
assert_eq!(expected_config, config_from_file);
vm_resource_fee_cost: get_vm_resource_fee_cost_first_segment(),
}
}

fn fill_up_block_execution_config_segment_with_value(value: usize) -> BlockExecutionConfig {
let vm_resource_fee_cost = HashMap::new();
let vm_resource_fee_cost = Arc::new(vm_resource_fee_cost);
BlockExecutionConfig {
fee_contract_address: contract_address!(format!("{:x}", value).as_str()),
strk_fee_contract_address: contract_address!(format!("{:x}", value).as_str()),
eth_fee_contract_address: contract_address!(format!("{:x}", value).as_str()),
invoke_tx_max_n_steps: value as u32,
validate_tx_max_n_steps: value as u32,
max_recursion_depth: value,
Expand Down Expand Up @@ -900,3 +920,33 @@ fn blockifier_error_mapping() {
assert_eq!(execution_error, expected);
assert_eq!(transaction_index, 0);
}

fn get_vm_resource_fee_cost_first_segment() -> Arc<HashMap<String, f64>> {
let mut vm_resource_fee_cost = HashMap::new();
vm_resource_fee_cost.insert("n_steps".to_owned(), 0.01);
vm_resource_fee_cost.insert("pedersen_builtin".to_owned(), 0.32);
vm_resource_fee_cost.insert("range_check_builtin".to_owned(), 0.16);
vm_resource_fee_cost.insert("ecdsa_builtin".to_owned(), 20.48);
vm_resource_fee_cost.insert("bitwise_builtin".to_owned(), 0.64);
vm_resource_fee_cost.insert("poseidon_builtin".to_owned(), 0.32);
vm_resource_fee_cost.insert("output_builtin".to_owned(), 1.0);
vm_resource_fee_cost.insert("ec_op_builtin".to_owned(), 10.24);
vm_resource_fee_cost.insert("keccak_builtin".to_owned(), 20.48);

Arc::new(vm_resource_fee_cost)
}

fn get_vm_resource_fee_cost_second_segment() -> Arc<HashMap<String, f64>> {
let mut vm_resource_fee_cost = HashMap::new();
vm_resource_fee_cost.insert("n_steps".to_owned(), 0.005);
vm_resource_fee_cost.insert("pedersen_builtin".to_owned(), 0.16);
vm_resource_fee_cost.insert("range_check_builtin".to_owned(), 0.08);
vm_resource_fee_cost.insert("ecdsa_builtin".to_owned(), 10.24);
vm_resource_fee_cost.insert("bitwise_builtin".to_owned(), 0.32);
vm_resource_fee_cost.insert("poseidon_builtin".to_owned(), 0.16);
vm_resource_fee_cost.insert("output_builtin".to_owned(), 0.5);
vm_resource_fee_cost.insert("ec_op_builtin".to_owned(), 5.12);
vm_resource_fee_cost.insert("keccak_builtin".to_owned(), 10.24);

Arc::new(vm_resource_fee_cost)
}
20 changes: 8 additions & 12 deletions crates/papyrus_execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ use papyrus_storage::header::HeaderStorageReader;
use papyrus_storage::{StorageError, StorageReader};
use serde::{Deserialize, Serialize};
use starknet_api::block::BlockNumber;
use starknet_api::core::{ChainId, ClassHash, ContractAddress, EntryPointSelector, PatriciaKey};
use starknet_api::core::{ChainId, ClassHash, ContractAddress, EntryPointSelector};
use starknet_api::data_availability::L1DataAvailabilityMode;
// TODO: merge multiple EntryPointType structs in SN_API into one.
use starknet_api::deprecated_contract_class::{
ContractClass as DeprecatedContractClass,
EntryPointType,
};
use starknet_api::hash::StarkHash;
use starknet_api::state::{StateNumber, ThinStateDiff};
use starknet_api::transaction::{
Calldata,
Expand All @@ -75,7 +74,7 @@ use starknet_api::transaction::{
TransactionHash,
TransactionVersion,
};
use starknet_api::{contract_address, patricia_key, StarknetApiError};
use starknet_api::StarknetApiError;
use state_reader::ExecutionStateReader;
use tracing::trace;

Expand All @@ -90,19 +89,17 @@ use crate::objects::{
// TODO(yair): understand what it is and whether the use of this constant should change.
const GLOBAL_CONTRACT_CACHE_SIZE: usize = 100;

// TODO(Eitan): get from config.
const STRK_FEE_TOKEN_ADDRESS: &str =
"0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";

/// Result type for execution functions.
pub type ExecutionResult<T> = Result<T, ExecutionError>;

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
/// Parameters that are needed for execution.
// TODO(yair): Find a way to get them from the Starknet general config.
pub struct BlockExecutionConfig {
/// The adress to receive fees
pub fee_contract_address: ContractAddress,
/// The strk address to receive fees
pub strk_fee_contract_address: ContractAddress,
/// The address to receive fees
pub eth_fee_contract_address: ContractAddress,
/// The maximum number of steps for an invoke transaction
pub invoke_tx_max_n_steps: u32,
/// The maximum number of steps for a validate transaction
Expand Down Expand Up @@ -366,10 +363,9 @@ fn create_block_context(
};
let chain_info = ChainInfo {
chain_id,
// TODO(Eitan): add the correct fee token addresses to the execution config.
fee_token_addresses: FeeTokenAddresses {
strk_fee_token_address: contract_address!(STRK_FEE_TOKEN_ADDRESS),
eth_fee_token_address: execution_config.fee_contract_address,
strk_fee_token_address: execution_config.strk_fee_contract_address,
eth_fee_token_address: execution_config.eth_fee_contract_address,
},
};

Expand Down
3 changes: 2 additions & 1 deletion crates/papyrus_execution/src/testing_instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ pub fn test_block_execution_config() -> BlockExecutionConfig {
let execution_config = test_get_default_execution_config();
let mut block_execution_config =
execution_config.execution_config_segments.get(&BlockNumber(0)).unwrap().clone();
block_execution_config.fee_contract_address = contract_address!("0x1001");
block_execution_config.eth_fee_contract_address = contract_address!("0x1001");
block_execution_config.strk_fee_contract_address = contract_address!("0x1001");
block_execution_config
}

Expand Down
5 changes: 3 additions & 2 deletions crates/papyrus_rpc/resources/test_config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"execution_config_segments": {
"0": {
"fee_contract_address": "0x1001",
"strk_fee_contract_address": "0x1001",
"eth_fee_contract_address": "0x1001",
"invoke_tx_max_n_steps": 1000000,
"validate_tx_max_n_steps": 1000000,
"max_recursion_depth": 50,
Expand All @@ -20,4 +21,4 @@
}
}
}
}
}

0 comments on commit ff26f50

Please sign in to comment.