Skip to content

Commit 7651a81

Browse files
starknet_os_runner: allow fee token address overide
1 parent 812a29f commit 7651a81

File tree

9 files changed

+78
-18
lines changed

9 files changed

+78
-18
lines changed

crates/blockifier_reexecution/src/state_reader/offline_state_reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl From<SerializableOfflineReexecutionData> for OfflineReexecutionData {
118118
offline_state_reader_prev_block,
119119
block_context_next_block: BlockContext::new(
120120
block_info_next_block,
121-
get_chain_info(&chain_id),
121+
get_chain_info(&chain_id, None),
122122
versioned_constants,
123123
BouncerConfig::max(),
124124
),

crates/blockifier_reexecution/src/state_reader/rpc_state_reader.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub struct RpcStateReader {
120120
pub block_id: BlockId,
121121
pub(crate) retry_config: RetryConfig,
122122
pub chain_id: ChainId,
123+
/// Optional override for the STRK fee token address.
124+
pub strk_fee_token_address: Option<ContractAddress>,
123125
#[allow(dead_code)]
124126
pub(crate) contract_class_mapping_dumper: Arc<Mutex<Option<StarknetContractClassMapping>>>,
125127
}
@@ -132,6 +134,7 @@ impl Default for RpcStateReader {
132134
block_id: BlockId::Latest,
133135
retry_config: RetryConfig::default(),
134136
chain_id: ChainId::Mainnet,
137+
strk_fee_token_address: None,
135138
contract_class_mapping_dumper: Arc::new(Mutex::new(None)),
136139
}
137140
}
@@ -153,15 +156,18 @@ impl RpcStateReader {
153156
block_id: BlockId::Number(block_number),
154157
retry_config: RetryConfig::default(),
155158
chain_id,
159+
strk_fee_token_address: None,
156160
contract_class_mapping_dumper,
157161
}
158162
}
159163

160164
/// Creates an RpcStateReader from a node URL, chain ID, and block ID.
165+
/// Optionally accepts a STRK fee token address override for custom environments.
161166
pub fn new_with_config_from_url(
162167
node_url: String,
163168
chain_id: ChainId,
164169
block_id: BlockId,
170+
strk_fee_token_address: Option<ContractAddress>,
165171
) -> Self {
166172
let config = RpcStateReaderConfig::from_url(node_url);
167173
let contract_class_mapping_dumper = Arc::new(Mutex::new(None));
@@ -170,6 +176,7 @@ impl RpcStateReader {
170176
block_id,
171177
retry_config: RetryConfig::default(),
172178
chain_id,
179+
strk_fee_token_address,
173180
contract_class_mapping_dumper,
174181
}
175182
}
@@ -301,7 +308,7 @@ impl RpcStateReader {
301308
pub fn get_block_context(&self) -> ReexecutionResult<BlockContext> {
302309
Ok(BlockContext::new(
303310
self.get_block_info()?,
304-
get_chain_info(&self.chain_id),
311+
get_chain_info(&self.chain_id, self.strk_fee_token_address),
305312
self.get_versioned_constants()?,
306313
BouncerConfig::max(),
307314
))

crates/blockifier_reexecution/src/utils.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ pub fn contract_class_to_compiled_classes(
4646
}
4747
}
4848

49-
/// Returns the fee token addresses of mainnet.
50-
pub fn get_fee_token_addresses(chain_id: &ChainId) -> FeeTokenAddresses {
49+
/// Returns the fee token addresses for the given chain.
50+
/// If `strk_fee_token_address_override` is provided, it overrides the default STRK fee token
51+
/// address.
52+
pub fn get_fee_token_addresses(
53+
chain_id: &ChainId,
54+
strk_fee_token_address_override: Option<ContractAddress>,
55+
) -> FeeTokenAddresses {
5156
match chain_id {
5257
// Mainnet, testnet and integration systems have the same fee token addresses.
5358
ChainId::Mainnet | ChainId::Sepolia | ChainId::IntegrationSepolia => FeeTokenAddresses {
54-
strk_fee_token_address: *STRK_FEE_CONTRACT_ADDRESS,
59+
strk_fee_token_address: strk_fee_token_address_override
60+
.unwrap_or(*STRK_FEE_CONTRACT_ADDRESS),
5561
eth_fee_token_address: *ETH_FEE_CONTRACT_ADDRESS,
5662
},
5763
unknown_chain => unimplemented!("Unknown chain ID {unknown_chain}."),
@@ -63,11 +69,16 @@ pub fn get_rpc_state_reader_config() -> RpcStateReaderConfig {
6369
RpcStateReaderConfig::from_url(RPC_NODE_URL.clone())
6470
}
6571

66-
/// Returns the chain info of mainnet.
67-
pub fn get_chain_info(chain_id: &ChainId) -> ChainInfo {
72+
/// Returns the chain info for the given chain.
73+
/// If `strk_fee_token_address_override` is provided, it overrides the default STRK fee token
74+
/// address.
75+
pub fn get_chain_info(
76+
chain_id: &ChainId,
77+
strk_fee_token_address_override: Option<ContractAddress>,
78+
) -> ChainInfo {
6879
ChainInfo {
6980
chain_id: chain_id.clone(),
70-
fee_token_addresses: get_fee_token_addresses(chain_id),
81+
fee_token_addresses: get_fee_token_addresses(chain_id, strk_fee_token_address_override),
7182
is_l3: false,
7283
}
7384
}

crates/starknet_os_runner/src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use blockifier::blockifier::config::ContractClassManagerConfig;
44
use serde::{Deserialize, Serialize};
5-
use starknet_api::core::ChainId;
5+
use starknet_api::core::{ChainId, ContractAddress};
66

77
use crate::runner::RunnerConfig;
88

@@ -18,6 +18,8 @@ pub struct ProverConfig {
1818
pub rpc_node_url: String,
1919
/// Configuration for the runner.
2020
pub runner_config: RunnerConfig,
21+
/// Optional override for the STRK fee token address (e.g., for custom environments).
22+
pub strk_fee_token_address: Option<ContractAddress>,
2123
}
2224

2325
impl Default for ProverConfig {
@@ -27,6 +29,7 @@ impl Default for ProverConfig {
2729
chain_id: ChainId::Mainnet,
2830
rpc_node_url: String::new(),
2931
runner_config: RunnerConfig::default(),
32+
strk_fee_token_address: None,
3033
}
3134
}
3235
}

crates/starknet_os_runner/src/runner.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ pub(crate) struct RpcRunnerFactory {
384384
contract_class_manager: ContractClassManager,
385385
/// Configuration for the runner.
386386
runner_config: RunnerConfig,
387+
/// Optional override for the STRK fee token address (e.g., for custom environments).
388+
strk_fee_token_address: Option<ContractAddress>,
387389
}
388390

389391
impl RpcRunnerFactory {
@@ -393,8 +395,9 @@ impl RpcRunnerFactory {
393395
chain_id: ChainId,
394396
contract_class_manager: ContractClassManager,
395397
runner_config: RunnerConfig,
398+
strk_fee_token_address: Option<ContractAddress>,
396399
) -> Self {
397-
Self { node_url, chain_id, contract_class_manager, runner_config }
400+
Self { node_url, chain_id, contract_class_manager, runner_config, strk_fee_token_address }
398401
}
399402

400403
/// Creates a runner configured for the given block ID.
@@ -404,6 +407,7 @@ impl RpcRunnerFactory {
404407
self.node_url.to_string(),
405408
self.chain_id.clone(),
406409
block_id,
410+
self.strk_fee_token_address,
407411
);
408412

409413
// Create the storage proofs provider.
@@ -414,6 +418,7 @@ impl RpcRunnerFactory {
414418
self.node_url.to_string(),
415419
self.chain_id.clone(),
416420
block_id,
421+
self.strk_fee_token_address,
417422
);
418423

419424
// Wrap in StateReaderAndContractManager for class resolution.

crates/starknet_os_runner/src/server/config.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
33
use std::net::{IpAddr, Ipv4Addr};
44
use std::path::PathBuf;
5+
use std::str::FromStr;
56

67
use clap::Parser;
78
use serde::{Deserialize, Serialize};
8-
use starknet_api::core::ChainId;
9+
use starknet_api::core::{ChainId, ContractAddress};
910
use tracing::info;
1011

1112
use crate::config::ProverConfig;
@@ -117,6 +118,19 @@ impl ServiceConfig {
117118
}
118119
}
119120

121+
if let Some(hex_str) = args.strk_fee_token_address {
122+
let strk_fee_token_address = ContractAddress::from_str(&hex_str).map_err(|e| {
123+
ConfigError::InvalidArgument(format!("Invalid strk_fee_token_address: {}", e))
124+
})?;
125+
if Some(strk_fee_token_address) != config.prover_config.strk_fee_token_address {
126+
info!(
127+
"CLI override: strk_fee_token_address: {:?} -> {:?}",
128+
config.prover_config.strk_fee_token_address, strk_fee_token_address
129+
);
130+
config.prover_config.strk_fee_token_address = Some(strk_fee_token_address);
131+
}
132+
}
133+
120134
// Validate required fields.
121135
if config.prover_config.rpc_node_url.is_empty() {
122136
return Err(ConfigError::MissingRequiredField(
@@ -170,6 +184,10 @@ pub struct CliArgs {
170184
/// Maximum number of simultaneous JSON-RPC connections (default: 10).
171185
#[arg(long, value_name = "N")]
172186
pub max_connections: Option<u32>,
187+
188+
/// Override STRK fee token address (hex, e.g. for custom environments that share a chain ID).
189+
#[arg(long, value_name = "ADDRESS")]
190+
pub strk_fee_token_address: Option<String>,
173191
}
174192

175193
/// Errors that can occur during configuration.

crates/starknet_os_runner/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub fn rpc_state_reader() -> RpcStateReader {
3535
node_url,
3636
ChainId::Mainnet,
3737
BlockId::Number(BlockNumber(TEST_BLOCK_NUMBER)),
38+
None,
3839
)
3940
}
4041

crates/starknet_os_runner/src/virtual_block_executor.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use blockifier_reexecution::utils::get_chain_info;
2222
use starknet_api::block::{BlockHash, BlockInfo};
2323
use starknet_api::block_hash::block_hash_calculator::{concat_counts, BlockHeaderCommitments};
2424
use starknet_api::contract_class::SierraVersion;
25-
use starknet_api::core::{ChainId, ClassHash};
25+
use starknet_api::core::{ChainId, ClassHash, ContractAddress};
2626
use starknet_api::transaction::fields::Fee;
2727
use starknet_api::transaction::{InvokeTransaction, MessageToL1, Transaction, TransactionHash};
2828
use starknet_api::versioned_constants_logic::VersionedConstantsTrait;
@@ -46,10 +46,12 @@ pub(crate) struct BaseBlockInfo {
4646
pub(crate) prev_base_block_hash: BlockHash,
4747
}
4848

49-
impl TryFrom<(BlockHeader, ChainId)> for BaseBlockInfo {
49+
impl TryFrom<(BlockHeader, ChainId, Option<ContractAddress>)> for BaseBlockInfo {
5050
type Error = VirtualBlockExecutorError;
5151

52-
fn try_from((header, chain_id): (BlockHeader, ChainId)) -> Result<Self, Self::Error> {
52+
fn try_from(
53+
(header, chain_id, strk_fee_token_address): (BlockHeader, ChainId, Option<ContractAddress>),
54+
) -> Result<Self, Self::Error> {
5355
let base_block_hash = header.block_hash;
5456
let prev_base_block_hash = header.parent_hash;
5557
let base_block_header_commitments = BlockHeaderCommitments {
@@ -70,7 +72,7 @@ impl TryFrom<(BlockHeader, ChainId)> for BaseBlockInfo {
7072
"Failed to convert block header to block info: {e}"
7173
))
7274
})?;
73-
let chain_info = get_chain_info(&chain_id);
75+
let chain_info = get_chain_info(&chain_id, strk_fee_token_address);
7476
let mut versioned_constants = VersionedConstants::get(&block_info.starknet_version)
7577
.map_err(|e| {
7678
VirtualBlockExecutorError::TransactionExecutionError(format!(
@@ -316,10 +318,18 @@ pub(crate) struct RpcVirtualBlockExecutor {
316318

317319
#[allow(dead_code)]
318320
impl RpcVirtualBlockExecutor {
319-
pub(crate) fn new(node_url: String, chain_id: ChainId, block_id: BlockId) -> Self {
321+
pub(crate) fn new(
322+
node_url: String,
323+
chain_id: ChainId,
324+
block_id: BlockId,
325+
strk_fee_token_address: Option<ContractAddress>,
326+
) -> Self {
320327
Self {
321328
rpc_state_reader: RpcStateReader::new_with_config_from_url(
322-
node_url, chain_id, block_id,
329+
node_url,
330+
chain_id,
331+
block_id,
332+
strk_fee_token_address,
323333
),
324334
validate_txs: true,
325335
}
@@ -340,7 +350,11 @@ impl VirtualBlockExecutor for RpcVirtualBlockExecutor {
340350
.rpc_state_reader
341351
.get_block_header()
342352
.map_err(|e| VirtualBlockExecutorError::ReexecutionError(Box::new(e)))?;
343-
BaseBlockInfo::try_from((block_header, self.rpc_state_reader.chain_id.clone()))
353+
BaseBlockInfo::try_from((
354+
block_header,
355+
self.rpc_state_reader.chain_id.clone(),
356+
self.rpc_state_reader.strk_fee_token_address,
357+
))
344358
}
345359

346360
fn state_reader(

crates/starknet_os_runner/src/virtual_snos_prover.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ impl VirtualSnosProver<RpcRunnerFactory> {
9797
prover_config.chain_id.clone(),
9898
contract_class_manager,
9999
prover_config.runner_config.clone(),
100+
prover_config.strk_fee_token_address,
100101
);
101102
Self { runner }
102103
}

0 commit comments

Comments
 (0)