From cdcc80f0815c736b46ba88bac29e4a08e089796b Mon Sep 17 00:00:00 2001 From: Yonatan Iluz Date: Tue, 26 Nov 2024 18:37:26 +0200 Subject: [PATCH] chore(cairo_native): update to v0.2.4 --- Cargo.lock | 8 ++--- Cargo.toml | 2 +- crates/bin/starknet-native-compile/Cargo.toml | 4 +-- .../execution/native/entry_point_execution.rs | 31 ++++++------------- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e476f0c134..cfc4fa7913 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2225,9 +2225,9 @@ dependencies = [ [[package]] name = "cairo-native" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "833170f422b08eec0e5ab116573bbb73c73f1601987d4b151cf71760836bd142" +checksum = "9bdebc70c3d563bc30078985ae3e975aa7dc4fa233631b5e0462a924c26c0dd9" dependencies = [ "anyhow", "aquamarine", @@ -2279,9 +2279,9 @@ dependencies = [ [[package]] name = "cairo-native-runtime" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fa4ec78d0a6df2988b71838c330a5113f65a4db6ccff53d8d71465f6619a427" +checksum = "5bf997252c402d6844f41357660cde3c11825ac5b3feafd0fb99b9dcdfb58aa3" dependencies = [ "cairo-lang-sierra-gas", "itertools 0.13.0", diff --git a/Cargo.toml b/Cargo.toml index 730c9a1e8b..a0f6d5c0da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -103,7 +103,7 @@ cairo-lang-sierra-to-casm = "2.9.0-dev.0" cairo-lang-starknet-classes = "2.9.0-dev.0" cairo-lang-utils = "2.9.0-dev.0" # Important: when updated, make sure to update the cairo-native submodule as well. -cairo-native = "0.2.3" +cairo-native = "0.2.4" cairo-vm = "=1.0.1" camelpaste = "0.1.0" chrono = "0.4.26" diff --git a/crates/bin/starknet-native-compile/Cargo.toml b/crates/bin/starknet-native-compile/Cargo.toml index 477e8e429f..2894bcc5f9 100644 --- a/crates/bin/starknet-native-compile/Cargo.toml +++ b/crates/bin/starknet-native-compile/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "starknet-native-compile" # The version of this crate should equal the version of cairo-native. -version = "0.2.1-alpha.0" +version = "0.2.4" edition = "2021" repository = "https://github.com/starkware-libs/sequencer/" license = "Apache-2.0" @@ -10,6 +10,6 @@ license = "Apache-2.0" # TODO(Avi, 01/02/2025): Check consistency with the blockifier. cairo-lang-sierra = "2.9.0-dev.0" cairo-lang-starknet-classes = "2.9.0-dev.0" -cairo-native = "0.2.3" +cairo-native = "0.2.4" clap = { version = "4.5.4", features = ["derive"] } serde_json = "1.0.116" diff --git a/crates/blockifier/src/execution/native/entry_point_execution.rs b/crates/blockifier/src/execution/native/entry_point_execution.rs index 9a338d593b..34b3460c67 100644 --- a/crates/blockifier/src/execution/native/entry_point_execution.rs +++ b/crates/blockifier/src/execution/native/entry_point_execution.rs @@ -27,9 +27,9 @@ pub fn execute_entry_point_call( let mut syscall_handler: NativeSyscallHandler<'_> = NativeSyscallHandler::new(call, state, context); - let gas_costs = &syscall_handler.base.context.versioned_constants().os_constants.gas_costs; + let gas_costs = &syscall_handler.base.context.gas_costs(); let builtin_costs = BuiltinCosts { - // todo(rodrigo): Unsure of what value `const` means, but 1 is the right value + // todo(rodrigo): Unsure of what value `const` means, but 1 is the right value. r#const: 1, pedersen: gas_costs.pedersen_gas_cost, bitwise: gas_costs.bitwise_builtin_gas_cost, @@ -39,13 +39,10 @@ pub fn execute_entry_point_call( mul_mod: gas_costs.mul_mod_gas_cost, }; - // Fund the initial budget since the native executor charges it before the run. - // TODO(Yoni): revert once the VM is aligned with this. - let gas = syscall_handler.base.call.initial_gas + gas_costs.entry_point_initial_budget; let execution_result = contract_class.executor.run( entry_point.selector.0, &syscall_handler.base.call.calldata.0.clone(), - Some(gas), + syscall_handler.base.call.initial_gas, Some(builtin_costs), &mut syscall_handler, ); @@ -64,24 +61,16 @@ fn create_callinfo( call_result: ContractExecutionResult, syscall_handler: NativeSyscallHandler<'_>, ) -> Result { - let mut remaining_gas = call_result.remaining_gas; + let remaining_gas = call_result.remaining_gas; if remaining_gas > syscall_handler.base.call.initial_gas { - if remaining_gas - syscall_handler.base.call.initial_gas - <= syscall_handler.base.context.gas_costs().entry_point_initial_budget - { - // Revert the refund. - // TODO(Yoni): temporary hack - this is probably a bug. Investigate and fix native. - remaining_gas = syscall_handler.base.call.initial_gas; - } else { - return Err(PostExecutionError::MalformedReturnData { - error_message: format!( - "Unexpected remaining gas. Used gas is greater than initial gas: {} > {}", - remaining_gas, syscall_handler.base.call.initial_gas - ), - } - .into()); + return Err(PostExecutionError::MalformedReturnData { + error_message: format!( + "Unexpected remaining gas. Used gas is greater than initial gas: {} > {}", + remaining_gas, syscall_handler.base.call.initial_gas + ), } + .into()); } let gas_consumed = syscall_handler.base.call.initial_gas - remaining_gas;