Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
af7e9e1
Fix how resources are handled
fmoletta Jun 8, 2023
f5d561a
Fix test values library_call test
fmoletta Jun 8, 2023
2866066
Fix test values
fmoletta Jun 8, 2023
498ab2a
Apply same fix for cairo 0
fmoletta Jun 8, 2023
cf2dbd8
Fix execution resources from inner calls not appearing in finall reso…
fmoletta Jun 9, 2023
aa26f96
Some fixes
fmoletta Jun 9, 2023
185ce49
Fix some tests
fmoletta Jun 9, 2023
115f31e
Fix some tests
fmoletta Jun 9, 2023
92701e2
Apply fix to cairo 0 execution
fmoletta Jun 9, 2023
1ee2962
Fix some tests
fmoletta Jun 9, 2023
1b33313
Fix some tests
fmoletta Jun 9, 2023
2721469
Fix some tests
fmoletta Jun 9, 2023
e688d03
Fix some tests
fmoletta Jun 9, 2023
96d9fea
Fix some tests
fmoletta Jun 9, 2023
db0b316
Fix some tests
fmoletta Jun 12, 2023
0088970
Fix some tests
fmoletta Jun 12, 2023
e88db05
clippy
fmoletta Jun 12, 2023
6dc51f6
Merge branch 'main' into fix-execution-resources-handling
fmoletta Jun 12, 2023
7ff0b00
fix
fmoletta Jun 12, 2023
fc7418f
Merge branch 'main' into fix-execution-resources-handling
fmoletta Jun 12, 2023
db59494
Merge branch 'main' into fix-execution-resources-handling
juanbono Jun 12, 2023
174b6a4
Merge branch 'main' into fix-execution-resources-handling
juanbono Jun 12, 2023
eba19d1
Use workspace version for cairo-vm
fmoletta Jun 12, 2023
b8a6556
Temporarily use github dependency for cairo vm
fmoletta Jun 12, 2023
1d2d5af
Disable trace
fmoletta Jun 12, 2023
a4cafec
Update cairo-vm version
fmoletta Jun 13, 2023
18b4536
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into f…
fmoletta Jun 13, 2023
e6d4b86
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into f…
fmoletta Jun 13, 2023
26ee656
fmt
fmoletta Jun 13, 2023
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
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ with_mimalloc = ["mimalloc"]
members = ["crates/starknet-contract-class", "fuzzer", "cli"]

[workspace.dependencies]
cairo-vm = { version = "0.5.1", features = ["cairo-1-hints"]}
cairo-vm = { version = "0.5.2", features = ["cairo-1-hints"]}

[dependencies]
cairo-lang-starknet = "1.1.0"
cairo-lang-casm = "1.1.0"
cairo-vm = { version = "0.5.1", features = ["cairo-1-hints"]}
cairo-vm = { workspace=true, features = ["cairo-1-hints"]}
getset = "0.1.2"
lazy_static = "1.4.0"
num-bigint = { version = "0.4", features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ with_mimalloc = ["mimalloc"]
[dependencies]
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", tag = "v1.1.0"}
cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", tag = "v1.1.0"}
cairo-vm = { version = "0.5.1", features = ["cairo-1-hints"]}
cairo-vm = { workspace=true, features = ["cairo-1-hints"]}
getset = "0.1.2"
lazy_static = "1.4.0"
num-bigint = { version = "0.4", features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-contract-class/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
serde = "1.0.156"
serde_json = "1.0.94"
getset = "0.1.2"
cairo-vm = { version = "0.5.1", features = ["cairo-1-hints"]}
cairo-vm = { workspace=true, features = ["cairo-1-hints"]}

[dependencies.starknet_api]
git = "https://github.com/starkware-libs/starknet-api"
Expand Down
2 changes: 1 addition & 1 deletion fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ starknet_api = { git = "https://github.com/starkware-libs/starknet-api", rev="a8
] }
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
tempfile = "3.2.0"
cairo-vm = { version = "0.5.1", features = ["cairo-1-hints"]}
cairo-vm = { workspace=true, features = ["cairo-1-hints"]}
starknet-contract-class = { path = "../crates/starknet-contract-class/" }
27 changes: 19 additions & 8 deletions src/business_logic/execution/execution_entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl ExecutionEntryPoint {
fn build_call_info_deprecated<S>(
&self,
previous_cairo_usage: ExecutionResources,
resources_manager: ExecutionResourcesManager,
resources_manager: &ExecutionResourcesManager,
starknet_storage_state: ContractStorageState<S>,
events: Vec<OrderedEvent>,
l2_to_l1_messages: Vec<OrderedL2ToL1Message>,
Expand Down Expand Up @@ -225,7 +225,7 @@ impl ExecutionEntryPoint {
fn build_call_info<S>(
&self,
previous_cairo_usage: ExecutionResources,
resources_manager: ExecutionResourcesManager,
resources_manager: &ExecutionResourcesManager,
starknet_storage_state: ContractStorageState<S>,
events: Vec<OrderedEvent>,
l2_to_l1_messages: Vec<OrderedL2ToL1Message>,
Expand Down Expand Up @@ -367,15 +367,20 @@ impl ExecutionEntryPoint {
.vm
.mark_address_range_as_accessed(args_ptr, entry_point_args.len())?;

*resources_manager = runner
.hint_processor
.syscall_handler
.resources_manager
.clone();

// Update resources usage (for bouncer).
resources_manager.cairo_usage =
&resources_manager.cairo_usage + &runner.get_execution_resources()?;
resources_manager.cairo_usage += &runner.get_execution_resources()?;

let retdata = runner.get_return_values()?;

self.build_call_info_deprecated::<T>(
previous_cairo_usage,
runner.hint_processor.syscall_handler.resources_manager,
resources_manager,
runner.hint_processor.syscall_handler.starknet_storage_state,
runner.hint_processor.syscall_handler.events,
runner.hint_processor.syscall_handler.l2_to_l1_messages,
Expand All @@ -398,6 +403,7 @@ impl ExecutionEntryPoint {
T: State + StateReader,
{
let previous_cairo_usage = resources_manager.cairo_usage.clone();

// fetch selected entry point
let entry_point = self.get_selected_entry_point(&contract_class, class_hash)?;

Expand Down Expand Up @@ -501,14 +507,19 @@ impl ExecutionEntryPoint {
.vm
.mark_address_range_as_accessed(args_ptr.unwrap(), entrypoint_args.len())?;

*resources_manager = runner
.hint_processor
.syscall_handler
.resources_manager
.clone();

// Update resources usage (for bouncer).
resources_manager.cairo_usage =
&resources_manager.cairo_usage + &runner.get_execution_resources()?;
resources_manager.cairo_usage += &runner.get_execution_resources()?;

let call_result = runner.get_call_result(self.initial_gas)?;
self.build_call_info::<T>(
previous_cairo_usage,
runner.hint_processor.syscall_handler.resources_manager,
resources_manager,
runner.hint_processor.syscall_handler.starknet_storage_state,
runner.hint_processor.syscall_handler.events,
runner.hint_processor.syscall_handler.l2_to_l1_messages,
Expand Down
9 changes: 8 additions & 1 deletion src/business_logic/transaction/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ impl Declare {
#[cfg(test)]
mod tests {
use super::*;
use cairo_vm::felt::{felt_str, Felt252};
use cairo_vm::{
felt::{felt_str, Felt252},
vm::runners::cairo_runner::ExecutionResources,
};
use num_traits::{One, Zero};
use std::{collections::HashMap, path::PathBuf};

Expand Down Expand Up @@ -392,6 +395,10 @@ mod tests {
entry_point_type: Some(EntryPointType::External),
calldata,
class_hash: Some(expected_class_hash),
execution_resources: ExecutionResources {
n_steps: 12,
..Default::default()
},
..Default::default()
});

Expand Down
7 changes: 6 additions & 1 deletion src/testing/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl StarknetState {
mod tests {
use std::path::PathBuf;

use cairo_vm::felt::felt_str;
use cairo_vm::{felt::felt_str, vm::runners::cairo_runner::ExecutionResources};
use num_traits::Num;

use super::*;
Expand Down Expand Up @@ -546,6 +546,11 @@ mod tests {
entry_point_type: Some(EntryPointType::External),
calldata: vec![1.into(), 1.into(), 10.into()],
retdata: vec![144.into()],
execution_resources: ExecutionResources {
n_steps: 94,
n_memory_holes: 0,
builtin_instance_counter: HashMap::default(),
},
..Default::default()
}),
actual_resources,
Expand Down
31 changes: 25 additions & 6 deletions tests/cairo_1_syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,16 @@ fn library_call() {
TRANSACTION_VERSION,
);
let mut resources_manager = ExecutionResourcesManager::default();
let mut expected_execution_resources = ExecutionResources::default();
expected_execution_resources
.builtin_instance_counter
.insert(RANGE_CHECK_BUILTIN_NAME.to_string(), 7);
expected_execution_resources.n_memory_holes = 6;
let expected_execution_resources = ExecutionResources {
n_steps: 259,
n_memory_holes: 10,
builtin_instance_counter: HashMap::from([(RANGE_CHECK_BUILTIN_NAME.to_string(), 12)]),
};
let expected_execution_resources_internal_call = ExecutionResources {
n_steps: 85,
n_memory_holes: 6,
builtin_instance_counter: HashMap::from([(RANGE_CHECK_BUILTIN_NAME.to_string(), 7)]),
};

// expected results
let expected_call_info = CallInfo {
Expand All @@ -272,7 +277,7 @@ fn library_call() {
entry_point_type: Some(EntryPointType::External),
calldata: vec![25.into()],
retdata: [5.into()].to_vec(),
execution_resources: ExecutionResources::default(),
execution_resources: expected_execution_resources_internal_call,
class_hash: Some(lib_class_hash),
gas_consumed: 0,
..Default::default()
Expand Down Expand Up @@ -1073,6 +1078,12 @@ fn test_send_message_to_l1_syscall() {
payload: vec![555.into(), 666.into()],
}];

let expected_execution_resources = ExecutionResources {
n_steps: 50,
n_memory_holes: 1,
builtin_instance_counter: HashMap::from([(RANGE_CHECK_BUILTIN_NAME.to_string(), 2)]),
};

let expected_call_info = CallInfo {
caller_address: Address(0.into()),
call_type: Some(CallType::Delegate),
Expand All @@ -1081,6 +1092,7 @@ fn test_send_message_to_l1_syscall() {
entry_point_selector: Some(external_entrypoint_selector.into()),
entry_point_type: Some(EntryPointType::External),
l2_to_l1_messages,
execution_resources: expected_execution_resources,
gas_consumed: 10040,
..Default::default()
};
Expand Down Expand Up @@ -1170,6 +1182,12 @@ fn test_get_execution_info() {
address.0.clone(),
];

let expected_execution_resources = ExecutionResources {
n_steps: 355,
n_memory_holes: 14,
builtin_instance_counter: HashMap::from([(RANGE_CHECK_BUILTIN_NAME.to_string(), 4)]),
};

let expected_call_info = CallInfo {
caller_address: Address(0.into()),
call_type: Some(CallType::Delegate),
Expand All @@ -1178,6 +1196,7 @@ fn test_get_execution_info() {
entry_point_selector: Some(external_entrypoint_selector.into()),
entry_point_type: Some(EntryPointType::External),
retdata: expected_ret_data,
execution_resources: expected_execution_resources,
gas_consumed: 38180,
..Default::default()
};
Expand Down
50 changes: 43 additions & 7 deletions tests/complex_contracts/amm_contracts/amm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};

use cairo_vm::felt::Felt252;
use cairo_vm::vm::runners::builtin_runner::HASH_BUILTIN_NAME;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use cairo_vm::{felt::Felt252, vm::runners::builtin_runner::RANGE_CHECK_BUILTIN_NAME};
use num_traits::Zero;
use starknet_contract_class::EntryPointType;
use starknet_rs::{
Expand Down Expand Up @@ -91,7 +92,14 @@ fn amm_init_pool_test() {
entry_point_type: Some(EntryPointType::External),
calldata: calldata.clone(),
retdata: [].to_vec(),
execution_resources: ExecutionResources::default(),
execution_resources: ExecutionResources {
n_steps: 232,
n_memory_holes: 20,
builtin_instance_counter: HashMap::from([
(RANGE_CHECK_BUILTIN_NAME.to_string(), 14),
(HASH_BUILTIN_NAME.to_string(), 2),
]),
},
class_hash: Some(class_hash),
accessed_storage_keys,
..Default::default()
Expand Down Expand Up @@ -173,7 +181,14 @@ fn amm_add_demo_tokens_test() {
entry_point_selector: Some(add_demo_token_selector),
entry_point_type: Some(EntryPointType::External),
calldata: calldata_add_demo_token.clone(),
execution_resources: ExecutionResources::default(),
execution_resources: ExecutionResources {
n_steps: 393,
n_memory_holes: 44,
builtin_instance_counter: HashMap::from([
(RANGE_CHECK_BUILTIN_NAME.to_string(), 20),
(HASH_BUILTIN_NAME.to_string(), 8),
]),
},
class_hash: Some(class_hash),
accessed_storage_keys: accessed_storage_keys_add_demo_token,
storage_read_values: vec![Felt252::zero(), Felt252::zero()],
Expand Down Expand Up @@ -241,7 +256,14 @@ fn amm_get_pool_token_balance() {
entry_point_selector: Some(get_pool_balance_selector),
entry_point_type: Some(EntryPointType::External),
calldata: calldata_get_pool_token_balance.clone(),
execution_resources: ExecutionResources::default(),
execution_resources: ExecutionResources {
n_steps: 84,
n_memory_holes: 10,
builtin_instance_counter: HashMap::from([
(RANGE_CHECK_BUILTIN_NAME.to_string(), 3),
(HASH_BUILTIN_NAME.to_string(), 1),
]),
},
class_hash: Some(class_hash),
accessed_storage_keys: accessed_storage_keys_get_pool_token_balance,
storage_read_values: vec![10000.into()],
Expand Down Expand Up @@ -330,7 +352,14 @@ fn amm_swap_test() {
entry_point_type: Some(EntryPointType::External),
calldata: calldata_swap.clone(),
retdata: expected_return,
execution_resources: ExecutionResources::default(),
execution_resources: ExecutionResources {
n_steps: 820,
n_memory_holes: 95,
builtin_instance_counter: HashMap::from([
(RANGE_CHECK_BUILTIN_NAME.to_string(), 41),
(HASH_BUILTIN_NAME.to_string(), 14),
]),
},
class_hash: Some(class_hash),
accessed_storage_keys,
storage_read_values: [
Expand Down Expand Up @@ -574,7 +603,14 @@ fn amm_get_account_token_balance_test() {
entry_point_type: Some(EntryPointType::External),
calldata: calldata_get_balance,
retdata: expected_return,
execution_resources: ExecutionResources::default(),
execution_resources: ExecutionResources {
n_steps: 92,
n_memory_holes: 11,
builtin_instance_counter: HashMap::from([
(RANGE_CHECK_BUILTIN_NAME.to_string(), 3),
(HASH_BUILTIN_NAME.to_string(), 2),
]),
},
class_hash: Some(class_hash),
accessed_storage_keys,
storage_read_values: [10.into()].to_vec(),
Expand Down
Loading