Skip to content

Commit

Permalink
chore: upgrade blockifier version to v0.8.0-dev.0 (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 authored Jul 4, 2024
1 parent d77c357 commit b5fb285
Show file tree
Hide file tree
Showing 20 changed files with 420 additions and 362 deletions.
450 changes: 254 additions & 196 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 14 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ async-trait = "0.1.79"
axum = "0.6.12"
# TODO(YaelD, 28/5/2024): The special Blockifier version is needed in order to be aligned with the
# starknet-api version. This should be removed once we have a mono-repo.
blockifier = { git = "https://github.com/starkware-libs/blockifier.git", branch = "main-mempool" }
blockifier ="0.8.0-dev.0"
bincode = "1.3.3"
cairo-lang-sierra = "2.6.0"
cairo-lang-starknet-classes = "2.6.0"
cairo-lang-utils = "2.6.0"
cairo-vm = "0.9.2"
cairo-lang-sierra = "2.7.0-dev.0"
cairo-lang-starknet-classes = "2.7.0-dev.0"
cairo-lang-utils = "2.7.0-dev.0"
cairo-vm = "1.0.0-rc3"
clap = "4.3.10"
colored = "2.1.0"
const_format = "0.2.30"
Expand All @@ -50,23 +50,26 @@ futures = "0.3.30"
hyper = { version = "0.14", features = ["client", "server", "http1", "http2", "tcp"] }
indexmap = "2.1.0"
itertools = "0.13.0"
lazy_static = "1.4.0"
num-traits = "0.2"
num-bigint = { version = "0.4.5", default-features = false }
# TODO(YaelD, 28/5/2024): The special Papyrus version is needed in order to be aligned with the
# starknet-api version. This should be removed once we have a mono-repo.
papyrus_common = { git = "https://github.com/starkware-libs/papyrus.git", rev = "56c6fdc2" }
papyrus_config = { git = "https://github.com/starkware-libs/papyrus.git", rev = "56c6fdc2" }
papyrus_rpc = { git = "https://github.com/starkware-libs/papyrus.git", rev = "56c6fdc2" }
papyrus_storage = { git = "https://github.com/starkware-libs/papyrus.git", rev = "56c6fdc2" }
papyrus_common = { git = "https://github.com/starkware-libs/papyrus.git", rev = "22de602" }
papyrus_config = { git = "https://github.com/starkware-libs/papyrus.git", rev = "22de602" }
papyrus_rpc = { git = "https://github.com/starkware-libs/papyrus.git", rev = "22de602" }
papyrus_storage = { git = "https://github.com/starkware-libs/papyrus.git", rev = "22de602" }
pretty_assertions = "1.4.0"
reqwest = { version = "0.11", features = ["blocking", "json"] }
rstest = "0.17.0"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0"
# TODO(Arni, 1/5/2024): Use a fixed version once the StarkNet API is stable.
starknet_api = { git = "https://github.com/starkware-libs/starknet-api.git", branch = "main-mempool" }
starknet_api = "0.13.0-dev.9"
# TODO(YaelD, 28/5/2024): The special Papyrus version is needed in order to be aligned with the
# starknet-api version. This should be removed once we have a mono-repo.
starknet_client = { git = "https://github.com/starkware-libs/papyrus.git", rev = "56c6fdc2" }
starknet_client = { git = "https://github.com/starkware-libs/papyrus.git", rev = "22de602" }
starknet-types-core = { version = "0.1.5", features = ["std", "hash", "prime-bigint"] }
strum = "0.24.1"
tempfile = "3.3.0"
thiserror = "1.0"
Expand Down
3 changes: 3 additions & 0 deletions crates/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ blockifier= { workspace = true , features = ["testing"] }
cairo-lang-starknet-classes.workspace = true
cairo-vm.workspace = true
hyper.workspace = true
num-traits.workspace = true
papyrus_config.workspace = true
papyrus_rpc.workspace = true
reqwest.workspace = true
Expand All @@ -27,13 +28,15 @@ starknet_api.workspace = true
starknet_mempool_infra = { path = "../mempool_infra", version = "0.0" }
starknet_mempool_types = { path = "../mempool_types", version = "0.0" }
starknet_sierra_compile = { path = "../starknet_sierra_compile", version = "0.0" }
starknet-types-core.workspace = true
test_utils = { path = "../test_utils", version = "0.0"}
thiserror.workspace = true
tokio.workspace = true
validator.workspace = true

[dev-dependencies]
assert_matches.workspace = true
num-bigint.workspace = true
pretty_assertions.workspace = true
rstest.workspace = true
starknet_mempool = { path = "../mempool", version = "0.0" }
4 changes: 1 addition & 3 deletions crates/gateway/src/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::panic;
use std::sync::OnceLock;

use blockifier::execution::contract_class::{ClassInfo, ContractClass, ContractClassV1};
use blockifier::execution::execution_utils::felt_to_stark_felt;
use cairo_lang_starknet_classes::casm_contract_class::{
CasmContractClass, CasmContractEntryPoints,
};
Expand Down Expand Up @@ -40,8 +39,7 @@ pub fn compile_contract_class(declare_tx: &RPCDeclareTransaction) -> GatewayResu
};
validate_casm_class(&casm_contract_class)?;

let hash_result =
CompiledClassHash(felt_to_stark_felt(&casm_contract_class.compiled_class_hash()));
let hash_result = CompiledClassHash(casm_contract_class.compiled_class_hash());
if hash_result != tx.compiled_class_hash {
return Err(GatewayError::CompiledClassHashMismatch {
supplied: tx.compiled_class_hash,
Expand Down
13 changes: 7 additions & 6 deletions crates/gateway/src/compiler_version.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::collections::BTreeMap;

use cairo_lang_starknet_classes::compiler_version::VersionId as CairoLangVersionId;
use num_traits::ToPrimitive;
use papyrus_config::dumping::{ser_param, SerializeConfig};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};
use starknet_api::hash::StarkFelt;
use starknet_types_core::felt::Felt;
use thiserror::Error;
use validator::Validate;

Expand Down Expand Up @@ -41,7 +42,7 @@ impl std::fmt::Display for VersionId {
}

impl VersionId {
pub fn from_sierra_program(sierra_program: &[StarkFelt]) -> Result<Self, VersionIdError> {
pub fn from_sierra_program(sierra_program: &[Felt]) -> Result<Self, VersionIdError> {
let sierra_program_length = sierra_program.len();

if sierra_program_length < 3 {
Expand All @@ -55,12 +56,12 @@ impl VersionId {
}

fn get_version_component(
sierra_program: &[StarkFelt],
sierra_program: &[Felt],
index: usize,
) -> Result<usize, VersionIdError> {
let felt = sierra_program[index];
felt.try_into().map_err(|_| VersionIdError::InvalidVersion {
message: format!("version contains a value that is out of range: {}", felt),
let felt = &sierra_program[index];
felt.to_usize().ok_or(VersionIdError::InvalidVersion {
message: format!("version contains a value that is out of range: {:?}", felt),
})
}

Expand Down
6 changes: 3 additions & 3 deletions crates/gateway/src/rpc_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use serde::Serialize;
use serde_json::{json, Value};
use starknet_api::block::BlockNumber;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::hash::StarkFelt;
use starknet_api::state::StorageKey;
use starknet_types_core::felt::Felt;

use crate::config::RpcStateReaderConfig;
use crate::errors::{serde_err_to_state_err, RPCStateReaderError, RPCStateReaderResult};
Expand Down Expand Up @@ -94,12 +94,12 @@ impl BlockifierStateReader for RpcStateReader {
&self,
contract_address: ContractAddress,
key: StorageKey,
) -> StateResult<StarkFelt> {
) -> StateResult<Felt> {
let get_storage_at_params =
GetStorageAtParams { block_id: self.block_id, contract_address, key };

let result = self.send_rpc_request("starknet_getStorageAt", get_storage_at_params)?;
let value: StarkFelt = serde_json::from_value(result).map_err(serde_err_to_state_err)?;
let value: Felt = serde_json::from_value(result).map_err(serde_err_to_state_err)?;
Ok(value)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/gateway/src/state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use blockifier::state::errors::StateError;
use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult};
use starknet_api::block::BlockNumber;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::hash::StarkFelt;
use starknet_api::state::StorageKey;
use starknet_types_core::felt::Felt;

pub trait MempoolStateReader: BlockifierStateReader + Send + Sync {
fn get_block_info(&self) -> Result<BlockInfo, StateError>;
Expand All @@ -30,7 +30,7 @@ impl BlockifierStateReader for Box<dyn MempoolStateReader> {
&self,
contract_address: ContractAddress,
key: StorageKey,
) -> StateResult<StarkFelt> {
) -> StateResult<Felt> {
self.as_ref().get_storage_at(contract_address, key)
}

Expand Down
10 changes: 5 additions & 5 deletions crates/gateway/src/state_reader_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use blockifier::state::errors::StateError;
use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult};
use blockifier::test_utils::contracts::FeatureContract;
use blockifier::test_utils::dict_state_reader::DictStateReader;
use blockifier::test_utils::initial_test_state::{fund_account, test_state_reader};
use blockifier::test_utils::initial_test_state::{fund_account, test_state};
use blockifier::test_utils::{CairoVersion, BALANCE};
use blockifier::versioned_constants::VersionedConstants;
use starknet_api::block::BlockNumber;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::hash::StarkFelt;
use starknet_api::rpc_transaction::RPCTransaction;
use starknet_api::state::StorageKey;
use starknet_types_core::felt::Felt;
use test_utils::starknet_api_test_utils::deployed_account_contract_address;

use crate::state_reader::{MempoolStateReader, StateReaderFactory};
Expand All @@ -34,7 +34,7 @@ impl BlockifierStateReader for TestStateReader {
&self,
contract_address: ContractAddress,
key: StorageKey,
) -> StateResult<StarkFelt> {
) -> StateResult<Felt> {
self.blockifier_state_reader.get_storage_at(contract_address, key)
}

Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn local_test_state_reader_factory(
let account_contract = FeatureContract::AccountWithoutValidations(cairo_version);
let test_contract = FeatureContract::TestContract(cairo_version);

let state_reader = test_state_reader(
let state_reader = test_state(
block_context.chain_info(),
account_balance,
&[(account_contract, 1), (test_contract, 1)],
Expand All @@ -91,7 +91,7 @@ pub fn local_test_state_reader_factory(
TestStateReaderFactory {
state_reader: TestStateReader {
block_info: block_context.block_info().clone(),
blockifier_state_reader: state_reader,
blockifier_state_reader: state_reader.state,
},
}
}
Expand Down
23 changes: 12 additions & 11 deletions crates/gateway/src/stateful_transaction_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use blockifier::context::BlockContext;
use blockifier::test_utils::CairoVersion;
use blockifier::transaction::errors::{TransactionFeeError, TransactionPreValidationError};
use rstest::rstest;
use starknet_api::hash::StarkFelt;
use starknet_api::felt;
use starknet_api::rpc_transaction::RPCTransaction;
use starknet_api::transaction::TransactionHash;
use starknet_types_core::felt::Felt;
use test_utils::starknet_api_test_utils::{
declare_tx, deploy_account_tx, invoke_tx, VALID_L1_GAS_MAX_AMOUNT,
VALID_L1_GAS_MAX_PRICE_PER_UNIT,
Expand All @@ -24,30 +25,30 @@ use crate::stateful_transaction_validator::StatefulTransactionValidator;
#[case::valid_invoke_tx_cairo1(
invoke_tx(CairoVersion::Cairo1),
local_test_state_reader_factory(CairoVersion::Cairo1, false),
Ok(TransactionHash(StarkFelt::try_from(
Ok(TransactionHash(felt!(
"0x007d70505b4487a4e1c1a4b4e4342cb5aa9e73b86d031891170c45a57ad8b4e6"
).unwrap()))
)))
)]
#[case::valid_invoke_tx_cairo0(
invoke_tx(CairoVersion::Cairo0),
local_test_state_reader_factory(CairoVersion::Cairo0, false),
Ok(TransactionHash(StarkFelt::try_from(
Ok(TransactionHash(felt!(
"0x032e3a969a64027f15ce2b526d8dff47d47524c58ff0363f93ce4cbe7c280861"
).unwrap()))
)))
)]
#[case::valid_deploy_account_tx(
deploy_account_tx(),
local_test_state_reader_factory_for_deploy_account(&external_tx),
Ok(TransactionHash(StarkFelt::try_from(
Ok(TransactionHash(felt!(
"0x013287740b37dc112391de4ef0f7cd7aeca323537ca2a78a1108c6aee5a55d70"
).unwrap()))
)))
)]
#[case::valid_declare_tx(
declare_tx(),
local_test_state_reader_factory(CairoVersion::Cairo1, false),
Ok(TransactionHash(StarkFelt::try_from(
Ok(TransactionHash(felt!(
"0x02da54b89e00d2e201f8e3ed2bcc715a69e89aefdce88aff2d2facb8dec55c0a"
).unwrap()))
)))
)]
#[case::invalid_tx(
invoke_tx(CairoVersion::Cairo1),
Expand All @@ -58,8 +59,8 @@ use crate::stateful_transaction_validator::StatefulTransactionValidator;
TransactionFeeError::L1GasBoundsExceedBalance {
max_amount: VALID_L1_GAS_MAX_AMOUNT,
max_price: VALID_L1_GAS_MAX_PRICE_PER_UNIT,
balance_low: StarkFelt::ZERO,
balance_high: StarkFelt::ZERO,
balance_low: Felt::ZERO,
balance_high: Felt::ZERO,
}
)
)
Expand Down
4 changes: 2 additions & 2 deletions crates/gateway/src/stateless_transaction_validator.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use starknet_api::hash::StarkFelt;
use starknet_api::rpc_transaction::{
RPCDeclareTransaction, RPCDeployAccountTransaction, RPCInvokeTransaction, RPCTransaction,
ResourceBoundsMapping,
};
use starknet_api::transaction::Resource;
use starknet_types_core::felt::Felt;

use crate::compiler_version::VersionId;
use crate::config::StatelessTransactionValidatorConfig;
Expand Down Expand Up @@ -111,7 +111,7 @@ impl StatelessTransactionValidator {

fn validate_sierra_version(
&self,
sierra_program: &[StarkFelt],
sierra_program: &[Felt],
) -> StatelessTransactionValidatorResult<()> {
// Any patch version is valid. (i.e. when check version for upper bound, we ignore the Z
// part in a version X.Y.Z).
Expand Down
Loading

0 comments on commit b5fb285

Please sign in to comment.