Skip to content

Commit

Permalink
Merge branch 'main' into vbar/return-compilation-error
Browse files Browse the repository at this point in the history
  • Loading branch information
vbar committed Jan 10, 2025
2 parents 26b2395 + 7cbefab commit c061079
Show file tree
Hide file tree
Showing 102 changed files with 3,133 additions and 2,052 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Use aggregate Bloom filters for `starknet_getEvents` to improve performance.
- Cairo 0 class definition size is now capped at 4 MiB.

## [0.15.2] - 2024-12-04

Expand Down
2 changes: 2 additions & 0 deletions crates/common/src/class_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use serde_with::serde_as;

use crate::{ByteCodeOffset, EntryPoint};

pub const CLASS_DEFINITION_MAX_ALLOWED_SIZE: u64 = 4 * 1024 * 1024;

#[derive(Debug, Deserialize, Dummy)]
pub enum ClassDefinition<'a> {
Sierra(Sierra<'a>),
Expand Down
21 changes: 20 additions & 1 deletion crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ impl ContractAddress {
/// It is used by starknet to store values for smart contracts to access
/// using syscalls. For example the block hash.
pub const ONE: ContractAddress = contract_address!("0x1");
/// The contract at 0x2 was introduced in Starknet version 0.13.4. It is
/// used for stateful compression:
/// - storage key 0 points to the global counter, which is the base for
/// index values in the next block,
/// - other storage k-v pairs store the mapping of key to index,
/// - the global counter starts at value 0x80 in the first block from
/// 0.13.4,
/// - keys of value lower than 0x80 are not indexed.
pub const TWO: ContractAddress = contract_address!("0x2");
/// Useful for iteration over the system contracts
pub const SYSTEM: [ContractAddress; 2] = [ContractAddress::ONE, ContractAddress::TWO];
}

// Bytecode and entry point list of a class
Expand Down Expand Up @@ -169,6 +180,10 @@ macros::i64_backed_u64::serdes!(TransactionIndex);
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, Default, Dummy)]
pub struct GasPrice(pub u128);

/// A hex representation of a [GasPrice].
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, Default, Dummy)]
pub struct GasPriceHex(pub GasPrice);

/// Starknet resource bound: amount.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, Default, Dummy)]
pub struct ResourceAmount(pub u64);
Expand All @@ -178,6 +193,10 @@ pub struct ResourceAmount(pub u64);
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, Default, Dummy)]
pub struct Tip(pub u64);

// A hex representation of a [Tip].
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default, Dummy)]
pub struct TipHex(pub Tip);

/// Starknet resource bound: price per unit.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, Default, Dummy)]
pub struct ResourcePricePerUnit(pub u128);
Expand Down Expand Up @@ -595,7 +614,7 @@ impl ContractAddress {
}

pub fn is_system_contract(&self) -> bool {
*self == ContractAddress::ONE
(*self == ContractAddress::ONE) || (*self == ContractAddress::TWO)
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ macro_rules! felt {
($hex:expr) => {{
// This forces const evaluation of the macro call. Without this the invocation
// will only be evaluated at runtime.
use ::pathfinder_crypto;
const CONST_FELT: pathfinder_crypto::Felt =
match pathfinder_crypto::Felt::from_hex_str($hex) {
Ok(f) => f,
Expand Down
2 changes: 2 additions & 0 deletions crates/crypto/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/src/algebra/curve/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 13 additions & 9 deletions crates/executor/src/execution_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -103,6 +96,8 @@ pub struct ExecutionState<'tx> {
pending_state: Option<Arc<StateUpdate>>,
allow_use_kzg_data: bool,
custom_versioned_constants: Option<VersionedConstants>,
eth_fee_address: ContractAddress,
strk_fee_address: ContractAddress,
}

impl<'tx> ExecutionState<'tx> {
Expand Down Expand Up @@ -174,11 +169,11 @@ impl<'tx> ExecutionState<'tx> {

fn chain_info(&self) -> anyhow::Result<ChainInfo> {
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"),
);

Expand Down Expand Up @@ -259,6 +254,8 @@ impl<'tx> ExecutionState<'tx> {
header: BlockHeader,
pending_state: Option<Arc<StateUpdate>>,
custom_versioned_constants: Option<VersionedConstants>,
eth_fee_address: ContractAddress,
strk_fee_address: ContractAddress,
) -> Self {
Self {
transaction,
Expand All @@ -268,16 +265,21 @@ 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,
header: BlockHeader,
pending_state: Option<Arc<StateUpdate>>,
l1_blob_data_availability: L1BlobDataAvailability,
custom_versioned_constants: Option<VersionedConstants>,
eth_fee_address: ContractAddress,
strk_fee_address: ContractAddress,
) -> Self {
Self {
transaction,
Expand All @@ -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,
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions crates/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions crates/executor/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use pathfinder_crypto::Felt;

use super::felt::IntoFelt;

#[derive(Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct FeeEstimate {
pub l1_gas_consumed: primitive_types::U256,
pub l1_gas_price: primitive_types::U256,
Expand Down Expand Up @@ -85,7 +85,7 @@ impl FeeEstimate {
}
}

#[derive(Debug, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum PriceUnit {
Wei,
Fri,
Expand Down
2 changes: 1 addition & 1 deletion crates/gateway-client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(self) -> Result<T, SequencerError>
Expand Down
10 changes: 9 additions & 1 deletion crates/gateway-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
)]);
Expand Down
Loading

0 comments on commit c061079

Please sign in to comment.