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

Bump blockifier #2866

Draft
wants to merge 45 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8840619
Update `Cargo.toml`
kkawula Jan 21, 2025
28c45de
Fix 0
kkawula Jan 21, 2025
3a300f1
Fix imports
kkawula Jan 21, 2025
4f00198
Undo unnecessary lock update
kkawula Jan 21, 2025
66f4b8e
Use `blockifier` and `starknet_api` from crates.io
kkawula Jan 23, 2025
afdc132
Fix 4
kkawula Jan 23, 2025
e37424a
Rename `get_compiled_contract_class` to `get_compiled_class`
kkawula Jan 27, 2025
9cdc581
Fix imports
kkawula Jan 27, 2025
69117b5
Update `verify_syscall_ptr` return type
kkawula Jan 27, 2025
a8a58a8
Specify int size for From triat
kkawula Jan 27, 2025
320be6b
Moc `From` impl for GasPrices and SerializableGasPrices
kkawula Jan 27, 2025
ec98539
Fix imports
kkawula Jan 27, 2025
a60a110
Update `get_compiled_class` return type
kkawula Jan 27, 2025
57af9ee
Revert changes in 'StarknetRuntime' struct
kkawula Jan 27, 2025
16eab87
Add `Mock` comment
kkawula Jan 27, 2025
3d469df
Revert `verify_syscall_ptr` type change
kkawula Jan 27, 2025
23e7b5d
Add `Mock` comment
kkawula Jan 27, 2025
ab1a722
Some fixes
kkawula Jan 30, 2025
c239c2c
Add mock comment
kkawula Jan 30, 2025
9bd480f
Some fixes
kkawula Jan 30, 2025
51bb4b6
Some fixes - update imports
kkawula Jan 30, 2025
dda8c59
Fix error match
kkawula Jan 30, 2025
c32f3bf
Fix
kkawula Jan 30, 2025
96e7854
Compiles
cptartur Jan 31, 2025
7ad3ed5
Make
cptartur Feb 4, 2025
f7d8b8f
Fix panic data extraction logic for string, disable for shortstrings …
cptartur Feb 5, 2025
00f48b2
Disable asserted gas values in non-gas tests
cptartur Feb 5, 2025
7371458
Move builtins test to separate file
cptartur Feb 5, 2025
eb4249f
Disable fuzzing tests
cptartur Feb 5, 2025
ac9d4f8
Try handling segment index offsets
cptartur Feb 5, 2025
d6e09bc
Add todo
cptartur Feb 5, 2025
34260c7
Remove todos from constants.rs
cptartur Feb 5, 2025
c6905bc
Add better comments on gas
cptartur Feb 5, 2025
fbff61a
Remove TODO in entry_code.rs
cptartur Feb 5, 2025
d758939
Add fixme
cptartur Feb 6, 2025
42f6b4b
gas.rs wip
cptartur Feb 6, 2025
e223c8d
Restore some resources related code
cptartur Feb 6, 2025
4592ca6
Some gas changes
cptartur Feb 6, 2025
9fe02fe
Add up gas from nested calls (some calculations are now correct)
cptartur Feb 7, 2025
94f655a
Update gas tests following price changes
cptartur Feb 7, 2025
6db75f2
Add fixme to l1 gas tests
cptartur Feb 7, 2025
2c8710a
Return total of l1 gas (maintain old behavior
cptartur Feb 7, 2025
a091e9c
Set class hash for mocked calls
cptartur Feb 7, 2025
f9c5de0
Restore passing used resources
cptartur Feb 7, 2025
e0db970
Partially fix regex
cptartur Feb 10, 2025
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
503 changes: 367 additions & 136 deletions Cargo.lock

Large diffs are not rendered by default.

35 changes: 18 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,26 @@ license = "MIT"
license-file = "LICENSE"

[workspace.dependencies]
blockifier = "0.8.0"
starknet_api = "0.13.0-dev.7"
cairo-lang-casm = { version = "2.7.0", features = ["serde"] }
cairo-lang-runner = "2.7.0"
cairo-lang-sierra-to-casm = "2.7.0"
cairo-lang-sierra = "2.7.0"
cairo-lang-utils = "2.7.0"
cairo-lang-starknet = "2.7.0"
cairo-lang-compiler = "2.7.0"
cairo-lang-filesystem = "2.7.0"
cairo-lang-diagnostics = "2.7.0"
cairo-lang-sierra-type-size = "2.7.0"
cairo-lang-syntax = "2.7.0"
cairo-lang-test-plugin = "2.7.0"
cairo-lang-starknet-classes = "2.7.0"
cairo-lang-parser = "2.7.0"
blockifier = "0.14.0-rc.0"
starknet_api = { version = "0.14.0-rc.0", features = ["testing"] }
cairo-lang-casm = { version = "2.10.0-rc.1", features = ["serde"] }
cairo-lang-runner = "2.10.0-rc.1"
cairo-lang-sierra-to-casm = "2.10.0-rc.1"
cairo-lang-sierra = "2.10.0-rc.1"
cairo-lang-utils = "2.10.0-rc.1"
cairo-lang-starknet = "2.10.0-rc.1"
cairo-lang-runnable-utils = "2.10.0-rc.1"
cairo-lang-compiler = "2.10.0-rc.1"
cairo-lang-filesystem = "2.10.0-rc.1"
cairo-lang-diagnostics = "2.10.0-rc.1"
cairo-lang-sierra-type-size = "2.10.0-rc.1"
cairo-lang-syntax = "2.10.0-rc.1"
cairo-lang-test-plugin = "2.10.0-rc.1"
cairo-lang-starknet-classes = "2.10.0-rc.1"
cairo-lang-parser = "2.10.0-rc.1"
cairo-lang-macro = "0.1.0"
cairo-vm = "1.0.0-rc3"
cairo-annotations = "0.1.0"
cairo-annotations = { git = "https://github.com/software-mansion/cairo-annotations.git", branch = "kkawula/2.10.0-rc.1" }
dirs = "5.0.1"
dialoguer = "0.11.0"
starknet-types-core = { version = "0.1.7", features = ["hash", "prime-bigint"] }
Expand Down
23 changes: 10 additions & 13 deletions crates/cheatnet/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
use starknet_api::contract_class::{ContractClass, SierraVersion};
use std::collections::HashMap;
use std::sync::Arc;

use blockifier::execution::contract_class::ContractClassV1;

use blockifier::execution::contract_class::ContractClass;

use blockifier::execution::entry_point::{CallEntryPoint, CallType};
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use conversions::string::TryFromHexStr;
use conversions::IntoConv;
use indoc::indoc;
use starknet::core::utils::get_selector_from_name;
use starknet_api::deprecated_contract_class::EntryPointType;

use conversions::string::TryFromHexStr;
use runtime::starknet::context::ERC20_CONTRACT_ADDRESS;
use runtime::starknet::state::DictStateReader;
use starknet_api::{core::ContractAddress, transaction::Calldata};
use starknet::core::utils::get_selector_from_name;
use starknet_api::contract_class::EntryPointType;
use starknet_api::{core::ContractAddress, transaction::fields::Calldata};

pub const MAX_FEE: u128 = 1_000_000 * 100_000_000_000; // 1000000 * min_gas_price.
pub const INITIAL_BALANCE: u128 = 10 * MAX_FEE;
Expand Down Expand Up @@ -46,10 +43,10 @@ fn contract_class_no_entrypoints() -> ContractClass {
}
}"#,
);
ContractClass::V1(
ContractClassV1::try_from_json_string(raw_contract_class)
.expect("Could not create dummy contract from raw"),
)
let casm_contract_class: CasmContractClass =
serde_json::from_str(raw_contract_class).expect("Could not casm_contract_class from raw");

ContractClass::V1((casm_contract_class, SierraVersion::LATEST))
}

// Creates a state with predeployed account and erc20 used to send transactions during tests.
Expand Down
3 changes: 1 addition & 2 deletions crates/cheatnet/src/forking/cache.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use anyhow::{Context, Result};
use blockifier::blockifier::block::BlockInfo;
use camino::{Utf8Path, Utf8PathBuf};
use fs2::FileExt;
use regex::Regex;
use runtime::starknet::context::SerializableBlockInfo;
use serde::{Deserialize, Serialize};
use starknet::core::types::ContractClass;
use starknet_api::block::BlockNumber;
use starknet_api::block::{BlockInfo, BlockNumber};
use starknet_api::core::{ClassHash, ContractAddress, Nonce};
use starknet_api::state::StorageKey;
use starknet_types_core::felt::Felt;
Expand Down
59 changes: 24 additions & 35 deletions crates/cheatnet/src/forking/state.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::forking::cache::ForkCache;
use crate::state::BlockInfoReader;
use anyhow::{Context, Result};
use blockifier::blockifier::block::BlockInfo;
use blockifier::execution::contract_class::{
ContractClass as ContractClassBlockifier, ContractClassV0, ContractClassV1,
CompiledClassV0, CompiledClassV0Inner, CompiledClassV1, RunnableCompiledClass,
};
use blockifier::state::errors::StateError::{self, StateReadError, UndeclaredClassHash};
use blockifier::state::state_api::{StateReader, StateResult};
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_lang_utils::bigint::BigUintAsHex;
use cairo_vm::types::program::Program;
use camino::Utf8Path;
use conversions::{FromConv, IntoConv};
use flate2::read::GzDecoder;
Expand All @@ -20,17 +19,15 @@ use starknet::core::types::{
use starknet::core::utils::parse_cairo_short_string;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::{JsonRpcClient, Provider, ProviderError};
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::block::{BlockInfo, BlockNumber, BlockTimestamp};
use starknet_api::contract_class::SierraVersion;
use starknet_api::core::{ChainId, ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::deprecated_contract_class::{
ContractClass as DeprecatedContractClass, EntryPoint, EntryPointType,
};
use starknet_api::state::StorageKey;
use starknet_types_core::felt::Felt;
use std::cell::RefCell;
use std::collections::HashMap;
use std::future::Future;
use std::io::Read;
use std::sync::Arc;
use tokio::runtime::Handle;
use tokio::task;
use universal_sierra_compiler_api::{compile_sierra, SierraType};
Expand Down Expand Up @@ -141,7 +138,7 @@ impl StateReader for ForkStateReader {
Felt::default(),
);
Ok(Felt::default())
},
}
Err(x) => Err(StateReadError(format!(
"Unable to get storage at address: {contract_address:?} and key: {key:?} from fork ({x})"
))),
Expand Down Expand Up @@ -206,10 +203,7 @@ impl StateReader for ForkStateReader {
}
}

fn get_compiled_contract_class(
&self,
class_hash: ClassHash,
) -> StateResult<ContractClassBlockifier> {
fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult<RunnableCompiledClass> {
let mut cache = self.cache.borrow_mut();

let contract_class = {
Expand Down Expand Up @@ -251,38 +245,33 @@ impl StateReader for ForkStateReader {
});

match compile_sierra::<String>(&sierra_contract_class, &SierraType::Contract) {
Ok(casm_contract_class_raw) => {
let casm_contract_class: CasmContractClass =
serde_json::from_str(&casm_contract_class_raw)
.expect("Unable to deserialize CasmContractClass");

Ok(ContractClassBlockifier::V1(
ContractClassV1::try_from(casm_contract_class)
.expect("Unable to create ContractClassV1 from CasmContractClass"),
))
}
Ok(casm_contract_class_raw) => Ok(RunnableCompiledClass::V1(
CompiledClassV1::try_from_json_string(
&casm_contract_class_raw,
SierraVersion::LATEST,
)
.expect("Unable to create RunnableCompiledClass::V1"),
)),
Err(err) => Err(StateReadError(err.to_string())),
}
}
ContractClassStarknet::Legacy(legacy_class) => {
let converted_entry_points: HashMap<EntryPointType, Vec<EntryPoint>> =
serde_json::from_str(
&serde_json::to_string(&legacy_class.entry_points_by_type).unwrap(),
)
.unwrap();
let converted_entry_points = serde_json::from_str(
&serde_json::to_string(&legacy_class.entry_points_by_type).unwrap(),
)
.unwrap();

let mut decoder = GzDecoder::new(&legacy_class.program[..]);
let mut converted_program = String::new();
decoder.read_to_string(&mut converted_program).unwrap();

Ok(ContractClassBlockifier::V0(
ContractClassV0::try_from(DeprecatedContractClass {
abi: None,
program: serde_json::from_str(&converted_program).unwrap(),
Ok(RunnableCompiledClass::V0(CompiledClassV0(Arc::new(
CompiledClassV0Inner {
program: Program::from_bytes(converted_program.as_ref(), None)
.expect("Unable to load program from converted_program"),
entry_points_by_type: converted_entry_points,
})
.unwrap(),
))
},
))))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ use crate::runtime_extensions::call_to_blockifier_runtime_extension::execution::
use crate::runtime_extensions::call_to_blockifier_runtime_extension::CheatnetState;
use crate::runtime_extensions::cheatable_starknet_runtime_extension::CheatableStarknetRuntimeExtension;
use crate::runtime_extensions::common::get_relocated_vm_trace;
use blockifier::execution::contract_class::CompiledClassV1;
use blockifier::execution::entry_point_execution::{
finalize_execution, initialize_execution_context, prepare_call_arguments, VmExecutionContext,
};
use blockifier::execution::stack_trace::{
extract_trailing_cairo1_revert_trace, Cairo1RevertHeader,
};
use blockifier::{
execution::{
contract_class::{ContractClassV1, EntryPointV1},
contract_class::EntryPointV1,
entry_point::{CallEntryPoint, EntryPointExecutionContext},
errors::EntryPointExecutionError,
execution_utils::Args,
Expand All @@ -19,45 +23,54 @@ use blockifier::{
use cairo_vm::vm::errors::cairo_run_errors::CairoRunError;
use cairo_vm::{
hint_processor::hint_processor_definition::HintProcessor,
vm::runners::cairo_runner::{CairoArg, CairoRunner, ExecutionResources},
vm::runners::cairo_runner::{CairoArg, CairoRunner},
};
use runtime::{ExtendedRuntime, StarknetRuntime};

// blockifier/src/execution/cairo1_execution.rs:48 (execute_entry_point_call)
pub fn execute_entry_point_call_cairo1(
call: CallEntryPoint,
contract_class: &ContractClassV1,
compiled_class_v1: CompiledClassV1,
state: &mut dyn State,
cheatnet_state: &mut CheatnetState, // Added parameter
resources: &mut ExecutionResources,
// resources: &mut ExecutionResources,
context: &mut EntryPointExecutionContext,
) -> ContractClassEntryPointExecutionResult {
let tracked_resource = *context
.tracked_resource_stack
.last()
.expect("Unexpected empty tracked resource.");
let entry_point_initial_budget = context.gas_costs().base.entry_point_initial_budget;

let VmExecutionContext {
mut runner,
mut syscall_handler,
initial_syscall_ptr,
entry_point,
program_extra_data_length,
} = initialize_execution_context(call, contract_class, state, resources, context)?;
} = initialize_execution_context(call, &compiled_class_v1, state, context)?;

let args = prepare_call_arguments(
&syscall_handler.call,
&syscall_handler.base.call,
&mut runner,
initial_syscall_ptr,
&mut syscall_handler.read_only_segments,
&entry_point,
entry_point_initial_budget,
)?;
let n_total_args = args.len();

// Snapshot the VM resources, in order to calculate the usage of this run at the end.
let previous_vm_resources = syscall_handler.resources.clone();
// // Snapshot the VM resources, in order to calculate the usage of this run at the end.
// let previous_vm_resources = syscall_handler.resources.clone();

// region: Modified blockifier code

let mut cheatable_runtime = ExtendedRuntime {
extension: CheatableStarknetRuntimeExtension { cheatnet_state },
extended_runtime: StarknetRuntime {
hint_handler: syscall_handler,
// FIXME use correct value
user_args: vec![],
},
};

Expand All @@ -82,14 +95,17 @@ pub fn execute_entry_point_call_cairo1(
let call_info = finalize_execution(
runner,
cheatable_runtime.extended_runtime.hint_handler,
previous_vm_resources,
n_total_args,
program_extra_data_length,
tracked_resource,
)?;
if call_info.execution.failed {
return Err(EntryPointExecutionErrorWithTrace {
source: EntryPointExecutionError::ExecutionFailed {
error_data: call_info.execution.retdata.0,
error_trace: extract_trailing_cairo1_revert_trace(
&call_info,
Cairo1RevertHeader::Execution,
),
},
trace,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use blockifier::{
execution::execution_utils::update_remaining_gas,
execution::{
entry_point::{CallEntryPoint, CallType},
execution_utils::ReadOnlySegment,
syscalls::{
hint_processor::{create_retdata_segment, SyscallExecutionError, SyscallHintProcessor},
SyscallResult,
syscall_base::SyscallResult,
},
},
transaction::transaction_utils::update_remaining_gas,
};
use cairo_vm::vm::vm_core::VirtualMachine;
use starknet_api::{
contract_class::EntryPointType,
core::{ClassHash, EntryPointSelector},
deprecated_contract_class::EntryPointType,
transaction::Calldata,
transaction::fields::Calldata,
};

use crate::runtime_extensions::call_to_blockifier_runtime_extension::CheatnetState;
Expand All @@ -31,27 +31,26 @@ pub fn execute_inner_call(
// region: Modified blockifier code
let call_info = execute_call_entry_point(
call,
syscall_handler.state,
syscall_handler.base.state,
cheatnet_state,
syscall_handler.resources,
syscall_handler.context,
// syscall_handler.resources,
syscall_handler.base.context,
)?;
// endregion

let raw_retdata = &call_info.execution.retdata.0;

if call_info.execution.failed {
// TODO(spapini): Append an error word according to starknet spec if needed.
// Something like "EXECUTION_ERROR".
return Err(SyscallExecutionError::SyscallError {
// TODO verify error type
return Err(SyscallExecutionError::Revert {
error_data: raw_retdata.clone(),
});
}

let retdata_segment = create_retdata_segment(vm, syscall_handler, raw_retdata)?;
update_remaining_gas(remaining_gas, &call_info);

syscall_handler.inner_calls.push(call_info);
syscall_handler.base.inner_calls.push(call_info);

Ok(retdata_segment)
}
Expand Down
Loading