Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: starknet 0.13.1 (without RPC changes) #1766

Merged
merged 17 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
408 changes: 212 additions & 196 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ async-trait = "0.1.73"
axum = { version = "0.6.19", features = ["macros"] }
base64 = "0.13.1"
bitvec = "1.0.1"
blockifier = "=0.4.0"
blockifier = "=0.5.0-rc.1"
bytes = "1.4.0"
cached = "0.44.0"
# This one needs to match the version used by blockifier
cairo-vm = "=0.8.3"
cairo-vm = "=0.9.2"
clap = "4.1.13"
const_format = "0.2.31"
criterion = "0.5.1"
Expand All @@ -75,7 +75,7 @@ serde_json = "1.0.105"
serde_with = "3.0.0"
sha3 = "0.10"
# This one needs to match the version used by blockifier
starknet_api = "=0.6.0"
starknet_api = "=0.8.0"
test-log = { version = "0.2.12", default-features = false, features = [
"trace",
] }
Expand Down
16 changes: 16 additions & 0 deletions crates/common/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub struct BlockHeader {
pub timestamp: BlockTimestamp,
pub eth_l1_gas_price: GasPrice,
pub strk_l1_gas_price: GasPrice,
pub eth_l1_data_gas_price: GasPrice,
pub strk_l1_data_gas_price: GasPrice,
kkovaacs marked this conversation as resolved.
Show resolved Hide resolved
pub sequencer_address: SequencerAddress,
pub starknet_version: StarknetVersion,
pub class_commitment: ClassCommitment,
Expand All @@ -19,6 +21,15 @@ pub struct BlockHeader {
pub transaction_commitment: TransactionCommitment,
pub transaction_count: usize,
pub event_count: usize,
pub l1_da_mode: L1DataAvailabilityMode,
}

#[derive(Debug, Clone, PartialEq, Eq, Default, Dummy, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum L1DataAvailabilityMode {
#[default]
Calldata,
Blob,
}

#[derive(Debug, Clone, PartialEq, Default)]
Expand Down Expand Up @@ -148,6 +159,11 @@ impl BlockHeaderBuilder {
self
}

pub fn with_l1_da_mode(mut self, l1_da_mode: L1DataAvailabilityMode) -> Self {
self.0.l1_da_mode = l1_da_mode;
self
}

pub fn finalize_with_hash(mut self, hash: BlockHash) -> BlockHeader {
self.0.hash = hash;
self.0
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod trie;
pub use signature::BlockCommitmentSignature;
pub use state_update::StateUpdate;

pub use header::{BlockHeader, BlockHeaderBuilder, SignedBlockHeader};
pub use header::{BlockHeader, BlockHeaderBuilder, L1DataAvailabilityMode, SignedBlockHeader};

impl ContractAddress {
/// The contract at 0x1 is special. It was never deployed and therefore
Expand Down
7 changes: 7 additions & 0 deletions crates/common/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ pub struct ExecutionResources {
pub builtin_instance_counter: BuiltinCounters,
pub n_steps: u64,
pub n_memory_holes: u64,
pub data_availability: Option<ExecutionDataAvailability>,
}

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ExecutionDataAvailability {
pub l1_gas: u128,
pub l1_data_gas: u128,
}

#[derive(Clone, Debug, Default, PartialEq, Eq)]
Expand Down
3 changes: 2 additions & 1 deletion crates/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ rust-version = { workspace = true }

[dependencies]
anyhow = { workspace = true }
cairo-lang-starknet-classes = "=2.6.0-rc.0"
casm-compiler-v1_0_0-alpha6 = { package = "cairo-lang-starknet", git = "https://github.com/starkware-libs/cairo", tag = "v1.0.0-alpha.6" }
casm-compiler-v1_0_0-rc0 = { package = "cairo-lang-starknet", git = "https://github.com/starkware-libs/cairo", tag = "v1.0.0-rc0" }
casm-compiler-v1_1_1 = { package = "cairo-lang-starknet", version = "=1.1.1" }
casm-compiler-v2 = { package = "cairo-lang-starknet", version = "=2.4.0" }
casm-compiler-v2 = { package = "cairo-lang-starknet", version = "=2.6.0-rc.0" }
pathfinder-common = { path = "../common" }
semver = { workspace = true }
serde = { workspace = true, features = ["derive"] }
Expand Down
28 changes: 15 additions & 13 deletions crates/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ mod v1_1_1 {
// This compiler is backwards compatible with v1.1.
mod v2 {
use anyhow::Context;
use casm_compiler_v2::allowed_libfuncs::{validate_compatible_sierra_version, ListSelector};
use casm_compiler_v2::casm_contract_class::CasmContractClass;
use casm_compiler_v2::contract_class::ContractClass;
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_lang_starknet_classes::contract_class::ContractClass;

use super::FeederGatewayContractClass;

Expand All @@ -222,15 +221,17 @@ mod v2 {
.try_into()
.context("Converting to Sierra class")?;

validate_compatible_sierra_version(
&sierra_class,
ListSelector::ListName(
casm_compiler_v2::allowed_libfuncs::BUILTIN_ALL_LIBFUNCS_LIST.to_string(),
),
)
.context("Validating Sierra class")?;

let casm_class = CasmContractClass::from_contract_class(sierra_class, true)
sierra_class
.validate_version_compatible(
cairo_lang_starknet_classes::allowed_libfuncs::ListSelector::ListName(
cairo_lang_starknet_classes::allowed_libfuncs::BUILTIN_ALL_LIBFUNCS_LIST
.to_string(),
),
)
.context("Validating Sierra class")?;

// TODO: determine `max_bytecode_size`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to do this and I'm not sure if we want to do this at all. I will check this, but I have a feeling this API change is just a consequence of the cairo compiler wanting to add support for a new CLI flag or something like that to let users limit bytecode size. I might be completely wrong though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this new limit is just used by the gateway/sequencer to enforce some recently added limits.

I'm not sure it's terribly important for us to implement the same limit.

Copy link
Contributor

@Mirko-von-Leipzig Mirko-von-Leipzig Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be dangerous to impose any limit at all here. Starkware literally just changed the value for this on starknet without a starknet update. So any check here might cause problems in the future.

Since only "starknet valid" classes should arrive here, we ought to be safe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since only "starknet valid" classes should arrive here, we ought to be safe.

That's not entirely true though. DECLARE transactions submitted via starknet_estimateFee / starknet_simulateTransactions also contain a class that ends up being compiled here.

let casm_class = CasmContractClass::from_contract_class(sierra_class, true, usize::MAX)
.context("Compiling to CASM")?;
let casm_definition = serde_json::to_vec(&casm_class)?;

Expand Down Expand Up @@ -312,7 +313,8 @@ mod tests {
serde_json::from_slice::<FeederGatewayContractClass<'_>>(CAIRO_1_1_0_RC0_SIERRA)
.unwrap();

let _: casm_compiler_v2::contract_class::ContractClass = class.try_into().unwrap();
let _: cairo_lang_starknet_classes::contract_class::ContractClass =
class.try_into().unwrap();
}

#[test]
Expand Down
92 changes: 0 additions & 92 deletions crates/executor/src/block_context.rs

This file was deleted.

15 changes: 10 additions & 5 deletions crates/executor/src/call.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::sync::Arc;

use blockifier::{
execution::entry_point::{CallEntryPoint, EntryPointExecutionContext, ExecutionResources},
transaction::objects::{AccountTransactionContext, DeprecatedAccountTransactionContext},
context::TransactionContext,
execution::entry_point::{CallEntryPoint, EntryPointExecutionContext},
transaction::objects::{DeprecatedTransactionInfo, TransactionInfo},
versioned_constants::VersionedConstants,
};
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use pathfinder_common::{CallParam, CallResultValue, ContractAddress, EntryPoint};
use starknet_api::core::PatriciaKey;

Expand Down Expand Up @@ -36,15 +39,17 @@ pub fn call(
entry_point_type: starknet_api::deprecated_contract_class::EntryPointType::External,
entry_point_selector,
calldata: starknet_api::transaction::Calldata(Arc::new(calldata)),
initial_gas: blockifier::abi::constants::INITIAL_GAS_COST,
initial_gas: VersionedConstants::latest_constants().gas_cost("initial_gas_cost"),
Mirko-von-Leipzig marked this conversation as resolved.
Show resolved Hide resolved
call_type: blockifier::execution::entry_point::CallType::Call,
..Default::default()
};

let mut resources = ExecutionResources::default();
let mut context = EntryPointExecutionContext::new_invoke(
&block_context,
&AccountTransactionContext::Deprecated(DeprecatedAccountTransactionContext::default()),
Arc::new(TransactionContext {
block_context,
tx_info: TransactionInfo::Deprecated(DeprecatedTransactionInfo::default()),
}),
false,
)?;

Expand Down
20 changes: 4 additions & 16 deletions crates/executor/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ impl From<BlockifierTransactionExecutionError> for CallError {
use BlockifierTransactionExecutionError::*;
match value {
ContractConstructorExecutionFailed(e)
| EntryPointExecutionError(e)
| ExecutionError(e)
| ValidateTransactionError(e) => match e {
BlockifierEntryPointExecutionError::PreExecutionError(
Expand Down Expand Up @@ -106,18 +105,7 @@ impl TransactionExecutionError {
pub fn new(transaction_index: usize, error: BlockifierTransactionExecutionError) -> Self {
Self::ExecutionError {
transaction_index,
error: match &error {
// Some variants don't propagate their child's error so we do this manually until it is
// fixed in the blockifier. We have a test to ensure we don't miss fix.
BlockifierTransactionExecutionError::ContractConstructorExecutionFailed(x) => {
format!("{error} {x}")
}
BlockifierTransactionExecutionError::ExecutionError(x) => format!("{error} {x}"),
BlockifierTransactionExecutionError::ValidateTransactionError(x) => {
format!("{error} {x}")
}
other => other.to_string(),
},
error: error.to_string(),
}
}
}
Expand All @@ -135,7 +123,7 @@ mod tests {
#[test]
fn contract_constructor_execution_failed() {
let child = EntryPointExecutionError::RecursionDepthExceeded;
let expected = format!("Contract constructor execution has failed. {child}");
let expected = format!("Contract constructor execution has failed: {child}");

let err =
BlockifierTransactionExecutionError::ContractConstructorExecutionFailed(child);
Expand All @@ -151,7 +139,7 @@ mod tests {
#[test]
fn execution_error() {
let child = EntryPointExecutionError::RecursionDepthExceeded;
let expected = format!("Transaction execution has failed. {child}");
let expected = format!("Transaction execution has failed: {child}");

let err = BlockifierTransactionExecutionError::ExecutionError(child);
let err = TransactionExecutionError::new(0, err);
Expand All @@ -166,7 +154,7 @@ mod tests {
#[test]
fn validate_transaction_error() {
let child = EntryPointExecutionError::RecursionDepthExceeded;
let expected = format!("Transaction validation has failed. {child}");
let expected = format!("Transaction validation has failed: {child}");

let err = BlockifierTransactionExecutionError::ValidateTransactionError(child);
let err = TransactionExecutionError::new(0, err);
Expand Down
16 changes: 15 additions & 1 deletion crates/executor/src/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ pub fn estimate(
let _span = tracing::debug_span!("estimate", transaction_hash=%super::transaction::transaction_hash(&transaction), %block_number, %transaction_idx).entered();

let fee_type = &super::transaction::fee_type(&transaction);
let gas_price: U256 = block_context.gas_prices.get_by_fee_type(fee_type).into();

let gas_price: U256 = block_context
.block_info()
.gas_prices
.get_gas_price_by_fee_type(fee_type)
.get()
.into();
let data_gas_price: U256 = block_context
.block_info()
.gas_prices
.get_data_gas_price_by_fee_type(fee_type)
.get()
.into();
let unit = match fee_type {
blockifier::transaction::objects::FeeType::Strk => PriceUnit::Fri,
blockifier::transaction::objects::FeeType::Eth => PriceUnit::Wei,
Expand Down Expand Up @@ -60,6 +72,8 @@ pub fn estimate(
fees.push(FeeEstimate {
gas_consumed: U256::from(tx_info.actual_fee.0) / gas_price.max(1.into()),
gas_price,
data_gas_consumed: U256::from(tx_info.da_gas.l1_data_gas),
data_gas_price,
overall_fee: tx_info.actual_fee.0.into(),
unit,
});
Expand Down
Loading
Loading