diff --git a/crates/crypto/benches/bench.rs b/crates/crypto/benches/bench.rs index eee5057344..20081050ba 100644 --- a/crates/crypto/benches/bench.rs +++ b/crates/crypto/benches/bench.rs @@ -1,3 +1,5 @@ +#![allow(unexpected_cfgs)] + use ::pathfinder_crypto::hash::poseidon::poseidon_hash; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use pathfinder_crypto::algebra::curve::{ProjectivePoint, CURVE_G}; diff --git a/crates/crypto/src/algebra/curve/consts.rs b/crates/crypto/src/algebra/curve/consts.rs index 35b4d1c90b..660d9ab642 100644 --- a/crates/crypto/src/algebra/curve/consts.rs +++ b/crates/crypto/src/algebra/curve/consts.rs @@ -3,7 +3,7 @@ use crate::algebra::curve::AffinePoint; pub const G_CONSTS_BITS: usize = 4; #[rustfmt::skip] -pub const G_CONSTS: [AffinePoint; 945] = [ +pub static G_CONSTS: [AffinePoint; 945] = [ AffinePoint::from_raw( [14484022957141291997,5884444832209845738,299981207024966779,232005955912912577], [6241159653446987914,664812301889158119,18147424675297964973,405578048423154473] diff --git a/crates/executor/src/execution_state.rs b/crates/executor/src/execution_state.rs index 739fb46dbc..ba4bf328d4 100644 --- a/crates/executor/src/execution_state.rs +++ b/crates/executor/src/execution_state.rs @@ -7,7 +7,6 @@ use blockifier::context::{BlockContext, ChainInfo}; use blockifier::state::cached_state::CachedState; use blockifier::versioned_constants::VersionedConstants; use pathfinder_common::{ - contract_address, BlockHeader, ChainId, ContractAddress, @@ -20,12 +19,6 @@ use super::pending::PendingStateReader; use super::state_reader::PathfinderStateReader; use crate::IntoStarkFelt; -// NOTE: these are the same for _all_ networks -pub const ETH_FEE_TOKEN_ADDRESS: ContractAddress = - contract_address!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"); -pub const STRK_FEE_TOKEN_ADDRESS: ContractAddress = - contract_address!("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"); - mod versioned_constants { use std::borrow::Cow; use std::sync::LazyLock; @@ -103,6 +96,8 @@ pub struct ExecutionState<'tx> { pending_state: Option>, allow_use_kzg_data: bool, custom_versioned_constants: Option, + eth_fee_address: ContractAddress, + strk_fee_address: ContractAddress, } impl<'tx> ExecutionState<'tx> { @@ -174,11 +169,11 @@ impl<'tx> ExecutionState<'tx> { fn chain_info(&self) -> anyhow::Result { let eth_fee_token_address = starknet_api::core::ContractAddress( - PatriciaKey::try_from(ETH_FEE_TOKEN_ADDRESS.0.into_starkfelt()) + PatriciaKey::try_from(self.eth_fee_address.0.into_starkfelt()) .expect("ETH fee token address overflow"), ); let strk_fee_token_address = starknet_api::core::ContractAddress( - PatriciaKey::try_from(STRK_FEE_TOKEN_ADDRESS.0.into_starkfelt()) + PatriciaKey::try_from(self.strk_fee_address.0.into_starkfelt()) .expect("STRK fee token address overflow"), ); @@ -259,6 +254,8 @@ impl<'tx> ExecutionState<'tx> { header: BlockHeader, pending_state: Option>, custom_versioned_constants: Option, + eth_fee_address: ContractAddress, + strk_fee_address: ContractAddress, ) -> Self { Self { transaction, @@ -268,9 +265,12 @@ impl<'tx> ExecutionState<'tx> { execute_on_parent_state: true, allow_use_kzg_data: true, custom_versioned_constants, + eth_fee_address, + strk_fee_address, } } + #[allow(clippy::too_many_arguments)] pub fn simulation( transaction: &'tx pathfinder_storage::Transaction<'tx>, chain_id: ChainId, @@ -278,6 +278,8 @@ impl<'tx> ExecutionState<'tx> { pending_state: Option>, l1_blob_data_availability: L1BlobDataAvailability, custom_versioned_constants: Option, + eth_fee_address: ContractAddress, + strk_fee_address: ContractAddress, ) -> Self { Self { transaction, @@ -287,6 +289,8 @@ impl<'tx> ExecutionState<'tx> { execute_on_parent_state: false, allow_use_kzg_data: l1_blob_data_availability == L1BlobDataAvailability::Enabled, custom_versioned_constants, + eth_fee_address, + strk_fee_address, } } } diff --git a/crates/executor/src/lib.rs b/crates/executor/src/lib.rs index a73edd1e2f..32f73d4b98 100644 --- a/crates/executor/src/lib.rs +++ b/crates/executor/src/lib.rs @@ -22,12 +22,7 @@ pub use class::{parse_casm_definition, parse_deprecated_class_definition}; pub use error::{CallError, TransactionExecutionError}; pub use error_stack::{CallFrame, ErrorStack, Frame}; pub use estimate::estimate; -pub use execution_state::{ - ExecutionState, - L1BlobDataAvailability, - ETH_FEE_TOKEN_ADDRESS, - STRK_FEE_TOKEN_ADDRESS, -}; +pub use execution_state::{ExecutionState, L1BlobDataAvailability}; pub use felt::{IntoFelt, IntoStarkFelt}; pub use simulate::{simulate, trace, TraceCache}; pub use transaction::transaction_hash; diff --git a/crates/gateway-client/src/builder.rs b/crates/gateway-client/src/builder.rs index e343a9619e..743db8a227 100644 --- a/crates/gateway-client/src/builder.rs +++ b/crates/gateway-client/src/builder.rs @@ -228,7 +228,7 @@ impl<'a> Request<'a, stage::Params> { } } -impl<'a> Request<'a, stage::Final> { +impl Request<'_, stage::Final> { /// Sends the Sequencer request as a REST `GET` operation and parses the /// response into `T`. pub async fn get(self) -> Result diff --git a/crates/gateway-client/src/lib.rs b/crates/gateway-client/src/lib.rs index abf73d8f1b..8232d8fd00 100644 --- a/crates/gateway-client/src/lib.rs +++ b/crates/gateway-client/src/lib.rs @@ -630,7 +630,15 @@ mod tests { let (_jh, url) = setup([( "/feeder_gateway/get_contract_addresses", ( - r#"{"Starknet":"0xde29d060d45901fb19ed6c6e959eb22d8626708e","GpsStatementVerifier":"0xab43ba48c9edf4c2c4bb01237348d1d7b28ef168"}"#, + r#"{ + "FriStatementContract": "0x55d049b4C82807808E76e61a08C6764bbf2ffB55", + "GpsStatementVerifier": "0x2046B966994Adcb88D83f467a41b75d64C2a619F", + "MemoryPageFactRegistry": "0x5628E75245Cc69eCA0994F0449F4dDA9FbB5Ec6a", + "MerkleStatementContract": "0xd414f8f535D4a96cB00fFC8E85160b353cb7809c", + "Starknet": "0x4737c0c1B4D5b1A687B42610DdabEE781152359c", + "strk_l2_token_address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", + "eth_l2_token_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" + }"#, 200, ), )]); diff --git a/crates/gateway-types/src/reply.rs b/crates/gateway-types/src/reply.rs index 34914148af..f44f647f03 100644 --- a/crates/gateway-types/src/reply.rs +++ b/crates/gateway-types/src/reply.rs @@ -16,7 +16,8 @@ use pathfinder_common::{ StateDiffCommitment, TransactionCommitment, }; -use pathfinder_serde::{EthereumAddressAsHexStr, GasPriceAsHexStr}; +use pathfinder_serde::{EthereumAddressAsHexStr, GasPriceAsHexStr, H256AsNoLeadingZerosHexStr}; +use primitive_types::H256; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; pub use transaction::DataAvailabilityMode; @@ -2184,6 +2185,12 @@ pub struct EthContractAddresses { #[serde(rename = "Starknet")] #[serde_as(as = "EthereumAddressAsHexStr")] pub starknet: EthereumAddress, + + #[serde_as(as = "H256AsNoLeadingZerosHexStr")] + pub strk_l2_token_address: H256, + + #[serde_as(as = "H256AsNoLeadingZerosHexStr")] + pub eth_l2_token_address: H256, } pub mod add_transaction { @@ -2401,12 +2408,16 @@ mod tests { #[test] fn eth_contract_addresses_ignores_extra_fields() { - // Some gateway mocks include extra addresses, check that we can still parse - // these. + // Sepolia integration gateway includes extra fields, check + // that we can still parse these. let json = serde_json::json!({ - "Starknet": "0x12345abcd", - "GpsStatementVerifier": "0xaabdde", - "MemoryPageFactRegistry": "0xdeadbeef" + "FriStatementContract": "0x55d049b4C82807808E76e61a08C6764bbf2ffB55", + "GpsStatementVerifier": "0x2046B966994Adcb88D83f467a41b75d64C2a619F", + "MemoryPageFactRegistry": "0x5628E75245Cc69eCA0994F0449F4dDA9FbB5Ec6a", + "MerkleStatementContract": "0xd414f8f535D4a96cB00fFC8E85160b353cb7809c", + "Starknet": "0x4737c0c1B4D5b1A687B42610DdabEE781152359c", + "strk_l2_token_address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", + "eth_l2_token_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" }); serde_json::from_value::(json).unwrap(); diff --git a/crates/p2p/src/behaviour.rs b/crates/p2p/src/behaviour.rs index 3e69cc1d13..1bd3ceb256 100644 --- a/crates/p2p/src/behaviour.rs +++ b/crates/p2p/src/behaviour.rs @@ -494,7 +494,7 @@ impl Behaviour { if self .peers .get(peer_id) - .map_or(false, |peer| peer.is_connected()) + .is_some_and(|peer| peer.is_connected()) { tracing::debug!(%peer_id, "Peer already connected, closing"); return Err(ConnectionDenied::new("duplicate connection")); diff --git a/crates/p2p/src/peers.rs b/crates/p2p/src/peers.rs index dfcabaa2f3..42964a00bf 100644 --- a/crates/p2p/src/peers.rs +++ b/crates/p2p/src/peers.rs @@ -39,7 +39,7 @@ impl Peer { pub fn is_relayed(&self) -> bool { self.addr .as_ref() - .map_or(false, |addr| addr.iter().any(|p| p == Protocol::P2pCircuit)) + .is_some_and(|addr| addr.iter().any(|p| p == Protocol::P2pCircuit)) } pub fn ip_addr(&self) -> Option { diff --git a/crates/pathfinder/examples/re_execute.rs b/crates/pathfinder/examples/re_execute.rs index 93f2e66cec..371964f342 100644 --- a/crates/pathfinder/examples/re_execute.rs +++ b/crates/pathfinder/examples/re_execute.rs @@ -5,6 +5,7 @@ use pathfinder_common::receipt::Receipt; use pathfinder_common::transaction::Transaction; use pathfinder_common::{BlockHeader, BlockNumber, ChainId}; use pathfinder_executor::ExecutionState; +use pathfinder_rpc::context::{ETH_FEE_TOKEN_ADDRESS, STRK_FEE_TOKEN_ADDRESS}; use pathfinder_storage::{BlockId, Storage}; use rayon::prelude::*; @@ -132,7 +133,15 @@ fn execute(storage: &mut Storage, chain_id: ChainId, work: Work) { let db_tx = connection.transaction().expect("Create transaction"); - let execution_state = ExecutionState::trace(&db_tx, chain_id, work.header.clone(), None, None); + let execution_state = ExecutionState::trace( + &db_tx, + chain_id, + work.header.clone(), + None, + None, + ETH_FEE_TOKEN_ADDRESS, + STRK_FEE_TOKEN_ADDRESS, + ); let transactions = work .transactions diff --git a/crates/pathfinder/src/bin/pathfinder/main.rs b/crates/pathfinder/src/bin/pathfinder/main.rs index 23298e9be2..ffcc1fb861 100644 --- a/crates/pathfinder/src/bin/pathfinder/main.rs +++ b/crates/pathfinder/src/bin/pathfinder/main.rs @@ -15,10 +15,9 @@ use pathfinder_ethereum::{EthereumApi, EthereumClient}; use pathfinder_lib::monitoring::{self}; use pathfinder_lib::state; use pathfinder_lib::state::SyncContext; -use pathfinder_rpc::context::WebsocketContext; +use pathfinder_rpc::context::{EthContractAddresses, WebsocketContext}; use pathfinder_rpc::{Notifications, SyncState}; use pathfinder_storage::Storage; -use primitive_types::H160; use starknet_gateway_client::GatewayApi; use tokio::signal::unix::{signal, SignalKind}; use tokio::task::JoinError; @@ -228,7 +227,7 @@ Hint: This is usually caused by exceeding the file descriptor limit of your syst execution_storage, sync_state.clone(), pathfinder_context.network_id, - pathfinder_context.l1_core_address, + pathfinder_context.contract_addresses, pathfinder_context.gateway.clone(), rx_pending.clone(), notifications.clone(), @@ -628,7 +627,7 @@ fn start_feeder_gateway_sync( ethereum: ethereum_client, chain: pathfinder_context.network, chain_id: pathfinder_context.network_id, - core_address: pathfinder_context.l1_core_address, + core_address: pathfinder_context.contract_addresses.l1_contract_address, sequencer: pathfinder_context.gateway, state: sync_state.clone(), head_poll_interval: config.poll_interval, @@ -665,7 +664,7 @@ fn start_p2p_sync( storage, p2p: p2p_client, eth_client: ethereum_client, - eth_address: pathfinder_context.l1_core_address, + eth_address: pathfinder_context.contract_addresses.l1_contract_address, fgw_client: pathfinder_context.gateway, chain_id: pathfinder_context.network_id, public_key: gateway_public_key, @@ -759,7 +758,7 @@ struct PathfinderContext { network_id: ChainId, gateway: starknet_gateway_client::Client, database: PathBuf, - l1_core_address: H160, + contract_addresses: EthContractAddresses, } /// Used to hide private fn's for [PathfinderContext]. @@ -770,7 +769,7 @@ mod pathfinder_context { use anyhow::Context; use pathfinder_common::{Chain, ChainId}; use pathfinder_ethereum::core_addr; - use primitive_types::H160; + use pathfinder_rpc::context::EthContractAddresses; use reqwest::Url; use starknet_gateway_client::Client as GatewayClient; @@ -790,14 +789,14 @@ mod pathfinder_context { network_id: ChainId::MAINNET, gateway: GatewayClient::mainnet(gateway_timeout).with_api_key(api_key), database: data_directory.join("mainnet.sqlite"), - l1_core_address: H160::from(core_addr::MAINNET), + contract_addresses: EthContractAddresses::new_known(core_addr::MAINNET), }, NetworkConfig::SepoliaTestnet => Self { network: Chain::SepoliaTestnet, network_id: ChainId::SEPOLIA_TESTNET, gateway: GatewayClient::sepolia_testnet(gateway_timeout).with_api_key(api_key), database: data_directory.join("testnet-sepolia.sqlite"), - l1_core_address: H160::from(core_addr::SEPOLIA_TESTNET), + contract_addresses: EthContractAddresses::new_known(core_addr::SEPOLIA_TESTNET), }, NetworkConfig::SepoliaIntegration => Self { network: Chain::SepoliaIntegration, @@ -805,7 +804,9 @@ mod pathfinder_context { gateway: GatewayClient::sepolia_integration(gateway_timeout) .with_api_key(api_key), database: data_directory.join("integration-sepolia.sqlite"), - l1_core_address: H160::from(core_addr::SEPOLIA_INTEGRATION), + contract_addresses: EthContractAddresses::new_known( + core_addr::SEPOLIA_INTEGRATION, + ), }, NetworkConfig::Custom { gateway, @@ -848,12 +849,16 @@ mod pathfinder_context { let network_id = ChainId(Felt::from_be_slice(chain_id.as_bytes()).context("Parsing chain ID")?); - let l1_core_address = gateway + let reply_contract_addresses = gateway .eth_contract_addresses() .await - .context("Downloading starknet L1 address from gateway for proxy check")? - .starknet - .0; + .context("Downloading starknet L1 address from gateway for proxy check")?; + let l1_core_address = reply_contract_addresses.starknet.0; + let contract_addresses = EthContractAddresses::new_custom( + l1_core_address, + reply_contract_addresses.eth_l2_token_address, + reply_contract_addresses.strk_l2_token_address, + )?; // Check for proxies by comparing the core address against those of the known // networks. @@ -873,7 +878,7 @@ mod pathfinder_context { network_id, gateway, database: data_directory.join("custom.sqlite"), - l1_core_address, + contract_addresses, }; Ok(context) diff --git a/crates/rpc/src/context.rs b/crates/rpc/src/context.rs index ab3306d364..96c180c2fe 100644 --- a/crates/rpc/src/context.rs +++ b/crates/rpc/src/context.rs @@ -1,11 +1,11 @@ use std::num::NonZeroUsize; use std::sync::Arc; -use pathfinder_common::ChainId; +use pathfinder_common::{contract_address, ChainId, ContractAddress}; use pathfinder_ethereum::EthereumClient; use pathfinder_executor::{TraceCache, VersionedConstants}; use pathfinder_storage::Storage; -use primitive_types::H160; +use primitive_types::{H160, H256}; pub use crate::jsonrpc::websocket::WebsocketContext; use crate::jsonrpc::Notifications; @@ -15,6 +15,54 @@ use crate::SyncState; type SequencerClient = starknet_gateway_client::Client; use tokio::sync::watch as tokio_watch; +// NOTE: these are the same for all _non-custom_ networks +pub const ETH_FEE_TOKEN_ADDRESS: ContractAddress = + contract_address!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"); +pub const STRK_FEE_TOKEN_ADDRESS: ContractAddress = + contract_address!("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"); + +/// Addresses from get_contract_addresses. +#[derive(Debug, Copy, Clone)] +pub struct EthContractAddresses { + pub l1_contract_address: H160, + + pub eth_l2_token_address: ContractAddress, + + pub strk_l2_token_address: ContractAddress, +} + +impl EthContractAddresses { + pub fn new_known(contract_address: [u8; 20]) -> Self { + Self { + l1_contract_address: H160::from(contract_address), + eth_l2_token_address: ETH_FEE_TOKEN_ADDRESS, + strk_l2_token_address: STRK_FEE_TOKEN_ADDRESS, + } + } + + pub fn new_custom( + contract_address: H160, + eth_l2_token_address: H256, + strk_l2_token_address: H256, + ) -> anyhow::Result { + let addresses = Self { + l1_contract_address: contract_address, + eth_l2_token_address: Self::from_token_addr(eth_l2_token_address)?, + strk_l2_token_address: Self::from_token_addr(strk_l2_token_address)?, + }; + Ok(addresses) + } + + fn from_token_addr(addr: H256) -> anyhow::Result { + use pathfinder_crypto::Felt; + + let felt = Felt::from_be_slice(addr.as_bytes())?; + let contract_addr = ContractAddress::new(felt) + .ok_or_else(|| anyhow::anyhow!("Cannot parse {} as token address", felt))?; + Ok(contract_addr) + } +} + #[derive(Clone)] pub struct RpcConfig { pub batch_concurrency_limit: NonZeroUsize, @@ -31,7 +79,7 @@ pub struct RpcContext { pub pending_data: PendingWatcher, pub sync_status: Arc, pub chain_id: ChainId, - pub core_contract_address: H160, + pub contract_addresses: EthContractAddresses, pub sequencer: SequencerClient, pub websocket: Option, pub notifications: Notifications, @@ -46,7 +94,7 @@ impl RpcContext { execution_storage: Storage, sync_status: Arc, chain_id: ChainId, - core_contract_address: H160, + contract_addresses: EthContractAddresses, sequencer: SequencerClient, pending_data: tokio_watch::Receiver, notifications: Notifications, @@ -60,7 +108,7 @@ impl RpcContext { execution_storage, sync_status, chain_id, - core_contract_address, + contract_addresses, pending_data, sequencer, websocket: None, @@ -97,17 +145,17 @@ impl RpcContext { let (chain_id, core_contract_address, sequencer) = match chain { Chain::Mainnet => ( ChainId::MAINNET, - H160::from(core_addr::MAINNET), + core_addr::MAINNET, SequencerClient::mainnet(GATEWAY_TIMEOUT), ), Chain::SepoliaTestnet => ( ChainId::SEPOLIA_TESTNET, - H160::from(core_addr::SEPOLIA_TESTNET), + core_addr::SEPOLIA_TESTNET, SequencerClient::sepolia_testnet(GATEWAY_TIMEOUT), ), Chain::SepoliaIntegration => ( ChainId::SEPOLIA_INTEGRATION, - H160::from(core_addr::SEPOLIA_INTEGRATION), + core_addr::SEPOLIA_INTEGRATION, SequencerClient::sepolia_integration(GATEWAY_TIMEOUT), ), Chain::Custom => unreachable!("Should not be testing with custom chain"), @@ -132,7 +180,7 @@ impl RpcContext { storage, sync_state, chain_id, - core_contract_address, + EthContractAddresses::new_known(core_contract_address), sequencer.disable_retry_for_tests(), rx, Notifications::default(), diff --git a/crates/rpc/src/dto/primitives.rs b/crates/rpc/src/dto/primitives.rs index 90867d372b..13509b8699 100644 --- a/crates/rpc/src/dto/primitives.rs +++ b/crates/rpc/src/dto/primitives.rs @@ -98,10 +98,7 @@ pub mod hex_str { // Handle a possible odd nibble remaining nibble. if len % 2 == 1 { let idx = len / 2; - buf[N - 1 - idx] = match parse_hex_digit(bytes[start]) { - Ok(b) => b, - Err(e) => return Err(e), - }; + buf[N - 1 - idx] = parse_hex_digit(bytes[start])?; } } else if len != 2 * N { return Err(anyhow!( @@ -114,14 +111,8 @@ pub mod hex_str { let mut chunk = 0; while chunk < chunks { - let lower = match parse_hex_digit(bytes[bytes.len() - chunk * 2 - 1]) { - Ok(b) => b, - Err(e) => return Err(e), - }; - let upper = match parse_hex_digit(bytes[bytes.len() - chunk * 2 - 2]) { - Ok(b) => b, - Err(e) => return Err(e), - }; + let lower = parse_hex_digit(bytes[bytes.len() - chunk * 2 - 1])?; + let upper = parse_hex_digit(bytes[bytes.len() - chunk * 2 - 2])?; buf[N - 1 - chunk] = upper << 4 | lower; chunk += 1; } diff --git a/crates/rpc/src/jsonrpc/router.rs b/crates/rpc/src/jsonrpc/router.rs index 0710848e92..3439230faf 100644 --- a/crates/rpc/src/jsonrpc/router.rs +++ b/crates/rpc/src/jsonrpc/router.rs @@ -173,7 +173,7 @@ fn is_utf8_encoded_json(headers: http::HeaderMap) -> bool { // `application/json` or `XXX+json` are allowed. let is_json = (mime.type_() == "application" && mime.subtype() == "json") - || mime.suffix().map_or(false, |name| name == "json"); + || mime.suffix().is_some_and(|name| name == "json"); is_json && valid_charset } diff --git a/crates/rpc/src/jsonrpc/router/subscription.rs b/crates/rpc/src/jsonrpc/router/subscription.rs index 0c96d937b2..0729f15d47 100644 --- a/crates/rpc/src/jsonrpc/router/subscription.rs +++ b/crates/rpc/src/jsonrpc/router/subscription.rs @@ -804,12 +804,11 @@ mod tests { use pathfinder_crypto::Felt; use pathfinder_ethereum::EthereumClient; use pathfinder_storage::StorageBuilder; - use primitive_types::H160; use starknet_gateway_client::Client; use tokio::sync::mpsc; use super::RpcSubscriptionEndpoint; - use crate::context::{RpcConfig, RpcContext}; + use crate::context::{EthContractAddresses, RpcConfig, RpcContext}; use crate::dto::DeserializeForVersion; use crate::jsonrpc::{ handle_json_rpc_socket, @@ -1018,7 +1017,9 @@ mod tests { } .into(), chain_id: ChainId::MAINNET, - core_contract_address: H160::from(pathfinder_ethereum::core_addr::MAINNET), + contract_addresses: EthContractAddresses::new_known( + pathfinder_ethereum::core_addr::MAINNET, + ), sequencer: Client::mainnet(Duration::from_secs(10)), websocket: None, notifications, diff --git a/crates/rpc/src/method/call.rs b/crates/rpc/src/method/call.rs index add563bf3b..c690e5ceeb 100644 --- a/crates/rpc/src/method/call.rs +++ b/crates/rpc/src/method/call.rs @@ -145,6 +145,8 @@ pub async fn call(context: RpcContext, input: Input) -> Result Result Result Vec { vec![StorageDiff { - address: pathfinder_executor::ETH_FEE_TOKEN_ADDRESS, + address: ETH_FEE_TOKEN_ADDRESS, storage_entries: vec![ StorageEntry { key: storage_address!("0x032a4edd4e4cffa71ee6d0971c54ac9e62009526cd78af7404aa968c3dc3408e"), @@ -921,7 +923,7 @@ pub(crate) mod tests { Felt::from_u64(DECLARE_OVERALL_FEE), felt!("0x0"), ], - contract_address: pathfinder_executor::ETH_FEE_TOKEN_ADDRESS, + contract_address: ETH_FEE_TOKEN_ADDRESS, selector: EntryPoint::hashed(b"transfer").0, internal_calls: vec![], messages: vec![], @@ -1182,7 +1184,7 @@ pub(crate) mod tests { fn universal_deployer_fee_transfer_storage_diffs() -> Vec { vec![StorageDiff { - address: pathfinder_executor::ETH_FEE_TOKEN_ADDRESS, + address: ETH_FEE_TOKEN_ADDRESS, storage_entries: vec![ StorageEntry { key: storage_address!("0x032a4edd4e4cffa71ee6d0971c54ac9e62009526cd78af7404aa968c3dc3408e"), @@ -1358,7 +1360,7 @@ pub(crate) mod tests { // calldata_len call_param!("0x0").0, ], - contract_address: pathfinder_executor::ETH_FEE_TOKEN_ADDRESS, + contract_address: ETH_FEE_TOKEN_ADDRESS, selector: EntryPoint::hashed(b"transfer").0, messages: vec![], result: vec![felt!("0x1")], @@ -1580,7 +1582,7 @@ pub(crate) mod tests { fn invoke_fee_transfer_storage_diffs() -> Vec { vec![StorageDiff { - address: pathfinder_executor::ETH_FEE_TOKEN_ADDRESS, + address: ETH_FEE_TOKEN_ADDRESS, storage_entries: vec![ StorageEntry { key: storage_address!("0x032a4edd4e4cffa71ee6d0971c54ac9e62009526cd78af7404aa968c3dc3408e"), @@ -1693,7 +1695,7 @@ pub(crate) mod tests { Felt::from_u64(INVOKE_OVERALL_FEE), call_param!("0x0").0, ], - contract_address: pathfinder_executor::ETH_FEE_TOKEN_ADDRESS, + contract_address: ETH_FEE_TOKEN_ADDRESS, selector: EntryPoint::hashed(b"transfer").0, messages: vec![], result: vec![felt!("0x1")], @@ -1881,7 +1883,7 @@ pub(crate) mod tests { Felt::from_u64(INVOKE_V3_OVERALL_FEE), felt!("0x0"), ], - contract_address: pathfinder_executor::STRK_FEE_TOKEN_ADDRESS, + contract_address: STRK_FEE_TOKEN_ADDRESS, selector: EntryPoint::hashed(b"transfer").0, messages: vec![], result: vec![felt!("0x1")], @@ -1923,7 +1925,7 @@ pub(crate) mod tests { fn invoke_v3_fee_transfer_storage_diffs() -> Vec { vec![StorageDiff { - address: pathfinder_executor::STRK_FEE_TOKEN_ADDRESS, + address: STRK_FEE_TOKEN_ADDRESS, storage_entries: vec![ StorageEntry { key: storage_address!("0x032a4edd4e4cffa71ee6d0971c54ac9e62009526cd78af7404aa968c3dc3408e"), diff --git a/crates/rpc/src/method/subscribe_events.rs b/crates/rpc/src/method/subscribe_events.rs index 5979c6cb5d..8008bfec4c 100644 --- a/crates/rpc/src/method/subscribe_events.rs +++ b/crates/rpc/src/method/subscribe_events.rs @@ -251,12 +251,11 @@ mod tests { use pathfinder_crypto::Felt; use pathfinder_ethereum::EthereumClient; use pathfinder_storage::StorageBuilder; - use primitive_types::H160; use starknet_gateway_client::Client; use starknet_gateway_types::reply::Block; use tokio::sync::mpsc; - use crate::context::{RpcConfig, RpcContext}; + use crate::context::{EthContractAddresses, RpcConfig, RpcContext}; use crate::jsonrpc::{handle_json_rpc_socket, RpcRouter, RpcSubscriptionFlow}; use crate::method::subscribe_events::SubscribeEvents; use crate::pending::PendingWatcher; @@ -731,7 +730,9 @@ mod tests { } .into(), chain_id: ChainId::MAINNET, - core_contract_address: H160::from(pathfinder_ethereum::core_addr::MAINNET), + contract_addresses: EthContractAddresses::new_known( + pathfinder_ethereum::core_addr::MAINNET, + ), sequencer: Client::mainnet(Duration::from_secs(10)), websocket: None, notifications, diff --git a/crates/rpc/src/method/subscribe_new_heads.rs b/crates/rpc/src/method/subscribe_new_heads.rs index 6f2c2e0e85..327041d586 100644 --- a/crates/rpc/src/method/subscribe_new_heads.rs +++ b/crates/rpc/src/method/subscribe_new_heads.rs @@ -172,12 +172,11 @@ mod tests { use pathfinder_crypto::Felt; use pathfinder_ethereum::EthereumClient; use pathfinder_storage::StorageBuilder; - use primitive_types::H160; use starknet_gateway_client::Client; use tokio::sync::mpsc; use super::*; - use crate::context::{RpcConfig, RpcContext}; + use crate::context::{EthContractAddresses, RpcConfig, RpcContext}; use crate::jsonrpc::{handle_json_rpc_socket, RpcResponse, RpcRouter}; use crate::pending::PendingWatcher; use crate::types::syncing::Syncing; @@ -539,7 +538,9 @@ mod tests { } .into(), chain_id: ChainId::MAINNET, - core_contract_address: H160::from(pathfinder_ethereum::core_addr::MAINNET), + contract_addresses: EthContractAddresses::new_known( + pathfinder_ethereum::core_addr::MAINNET, + ), sequencer: Client::mainnet(Duration::from_secs(10)), websocket: None, notifications, diff --git a/crates/rpc/src/method/subscribe_pending_transactions.rs b/crates/rpc/src/method/subscribe_pending_transactions.rs index f9bc488b7f..28a0833d14 100644 --- a/crates/rpc/src/method/subscribe_pending_transactions.rs +++ b/crates/rpc/src/method/subscribe_pending_transactions.rs @@ -150,12 +150,11 @@ mod tests { }; use pathfinder_ethereum::EthereumClient; use pathfinder_storage::StorageBuilder; - use primitive_types::H160; use starknet_gateway_client::Client; use starknet_gateway_types::reply::PendingBlock; use tokio::sync::{mpsc, watch}; - use crate::context::{RpcConfig, RpcContext}; + use crate::context::{EthContractAddresses, RpcConfig, RpcContext}; use crate::jsonrpc::{handle_json_rpc_socket, RpcResponse}; use crate::pending::PendingWatcher; use crate::types::syncing::Syncing; @@ -483,7 +482,9 @@ mod tests { } .into(), chain_id: ChainId::MAINNET, - core_contract_address: H160::from(pathfinder_ethereum::core_addr::MAINNET), + contract_addresses: EthContractAddresses::new_known( + pathfinder_ethereum::core_addr::MAINNET, + ), sequencer: Client::mainnet(Duration::from_secs(10)), websocket: None, notifications, diff --git a/crates/rpc/src/method/subscribe_transaction_status.rs b/crates/rpc/src/method/subscribe_transaction_status.rs index 5593bc6b52..48b5f08a53 100644 --- a/crates/rpc/src/method/subscribe_transaction_status.rs +++ b/crates/rpc/src/method/subscribe_transaction_status.rs @@ -449,12 +449,11 @@ mod tests { use pathfinder_ethereum::{EthereumClient, EthereumStateUpdate}; use pathfinder_storage::StorageBuilder; use pretty_assertions_sorted::assert_eq; - use primitive_types::H160; use starknet_gateway_client::Client; use starknet_gateway_types::reply::{Block, PendingBlock}; use tokio::sync::mpsc; - use crate::context::{RpcConfig, RpcContext}; + use crate::context::{EthContractAddresses, RpcConfig, RpcContext}; use crate::dto::{SerializeForVersion, Serializer}; use crate::jsonrpc::{handle_json_rpc_socket, RpcResponse, RpcRouter}; use crate::pending::PendingWatcher; @@ -1162,7 +1161,9 @@ mod tests { } .into(), chain_id: ChainId::MAINNET, - core_contract_address: H160::from(pathfinder_ethereum::core_addr::MAINNET), + contract_addresses: EthContractAddresses::new_known( + pathfinder_ethereum::core_addr::MAINNET, + ), sequencer: Client::mainnet(Duration::from_secs(10)), websocket: None, notifications, diff --git a/crates/rpc/src/method/trace_block_transactions.rs b/crates/rpc/src/method/trace_block_transactions.rs index 99a38a32f4..7ebdb67e07 100644 --- a/crates/rpc/src/method/trace_block_transactions.rs +++ b/crates/rpc/src/method/trace_block_transactions.rs @@ -115,6 +115,8 @@ pub async fn trace_block_transactions( header, None, context.config.custom_versioned_constants, + context.contract_addresses.eth_l2_token_address, + context.contract_addresses.strk_l2_token_address, ); let traces = match pathfinder_executor::trace(state, cache, hash, executor_transactions) { Ok(traces) => traces, @@ -834,7 +836,7 @@ pub(crate) mod tests { Ok(()) } - pub(crate) async fn setup_multi_tx_trace_pending_test<'a>( + pub(crate) async fn setup_multi_tx_trace_pending_test( ) -> anyhow::Result<(RpcContext, Vec)> { use super::super::simulate_transactions::tests::{ fixtures, diff --git a/crates/rpc/src/method/trace_transaction.rs b/crates/rpc/src/method/trace_transaction.rs index c1e9a2483a..ed34062393 100644 --- a/crates/rpc/src/method/trace_transaction.rs +++ b/crates/rpc/src/method/trace_transaction.rs @@ -40,7 +40,7 @@ impl crate::dto::SerializeForVersion for Output { } } -pub async fn trace_transaction<'a>( +pub async fn trace_transaction( context: RpcContext, input: Input, ) -> Result { @@ -126,6 +126,8 @@ pub async fn trace_transaction<'a>( header, None, context.config.custom_versioned_constants, + context.contract_addresses.eth_l2_token_address, + context.contract_addresses.strk_l2_token_address, ); let executor_transactions = transactions diff --git a/crates/rpc/src/test_setup.rs b/crates/rpc/src/test_setup.rs index ee73a2ac76..85d790cc9a 100644 --- a/crates/rpc/src/test_setup.rs +++ b/crates/rpc/src/test_setup.rs @@ -14,7 +14,7 @@ use pathfinder_common::{ use pathfinder_storage::Storage; use starknet_gateway_test_fixtures::class_definitions::{DUMMY_ACCOUNT, DUMMY_ACCOUNT_CLASS_HASH}; -use crate::context::RpcContext; +use crate::context::{RpcContext, ETH_FEE_TOKEN_ADDRESS, STRK_FEE_TOKEN_ADDRESS}; pub async fn test_storage StateUpdate>( version: StarknetVersion, @@ -88,18 +88,15 @@ pub async fn test_storage StateUpdate>( .with_declared_cairo_class(erc20_class_hash) .with_deployed_contract(account_contract_address, DUMMY_ACCOUNT_CLASS_HASH) .with_deployed_contract(universal_deployer_address, universal_deployer_class_hash) - .with_deployed_contract(pathfinder_executor::ETH_FEE_TOKEN_ADDRESS, erc20_class_hash) - .with_deployed_contract( - pathfinder_executor::STRK_FEE_TOKEN_ADDRESS, - erc20_class_hash, - ) + .with_deployed_contract(ETH_FEE_TOKEN_ADDRESS, erc20_class_hash) + .with_deployed_contract(STRK_FEE_TOKEN_ADDRESS, erc20_class_hash) .with_storage_update( - pathfinder_executor::ETH_FEE_TOKEN_ADDRESS, + ETH_FEE_TOKEN_ADDRESS, account_balance_key, storage_value!("0x10000000000000000000000000000"), ) .with_storage_update( - pathfinder_executor::STRK_FEE_TOKEN_ADDRESS, + STRK_FEE_TOKEN_ADDRESS, account_balance_key, storage_value!("0x10000000000000000000000000000"), ); diff --git a/crates/serde/src/lib.rs b/crates/serde/src/lib.rs index 1d8aeae2b8..ed4cf77c77 100644 --- a/crates/serde/src/lib.rs +++ b/crates/serde/src/lib.rs @@ -100,7 +100,6 @@ impl<'de> DeserializeAs<'de, EthereumAddress> for EthereumAddressAsHexStr { } } -// TODO: This can be removed once we yank RPC V06 pub struct H256AsNoLeadingZerosHexStr; impl SerializeAs for H256AsNoLeadingZerosHexStr {