Skip to content

Commit d24049e

Browse files
starknet_os: initial test, measure call contract resources
1 parent 6be6e6c commit d24049e

21 files changed

Lines changed: 358 additions & 52 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/constants.cairo

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_0 = (
7171
const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_1 = (
7272
0x06ecb73d21c7d98ddd4148f5bcd91cc2747c65364245fbf32a63b05cca1685c2
7373
);
74-
const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN = 2;
74+
const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_2 = (
75+
0x059a0052ae80a978ca71126c9774a17c67c19f79b14bb9d1ea96fb77dc6032d8
76+
);
77+
const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN = 3;
7578

7679
// Gas constants.
7780

@@ -104,7 +107,7 @@ const ENTRY_POINT_INITIAL_BUDGET = 10000;
104107
const SYSCALL_BASE_GAS_COST = 10000;
105108

106109
// Syscall gas costs.
107-
const CALL_CONTRACT_GAS_COST = 91560;
110+
const CALL_CONTRACT_GAS_COST = 91360;
108111
const DEPLOY_GAS_COST = 147120;
109112
const DEPLOY_CALLDATA_FACTOR_GAS_COST = 4850;
110113
const GET_BLOCK_HASH_GAS_COST = 10840;

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/execution/execution_constraints.cairo

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from starkware.cairo.common.math import assert_le, assert_nn_le, assert_not_zero
66
from starkware.starknet.core.os.constants import (
77
ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_0,
88
ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_1,
9+
ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_2,
910
ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN,
1011
STORED_BLOCK_HASH_BUFFER,
1112
)
@@ -25,9 +26,10 @@ func check_is_reverted(is_reverted: felt) {
2526

2627
// Returns TRUE if the given virtual OS program hash is allowed, FALSE otherwise.
2728
func is_program_hash_allowed(program_hash: felt) -> felt {
28-
static_assert ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN == 2;
29+
static_assert ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN == 3;
2930
if ((program_hash - ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_0) *
30-
(program_hash - ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_1) == 0) {
31+
(program_hash - ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_1) *
32+
(program_hash - ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_2) == 0) {
3133
return TRUE;
3234
}
3335
return FALSE;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"os": "0x783b9a9b8e6204534cd82ea7a594892bff6c44e0cc7cbbc09698e9c66ec9784",
3-
"virtual_os": "0x6ecb73d21c7d98ddd4148f5bcd91cc2747c65364245fbf32a63b05cca1685c2",
2+
"os": "0x47f5b47e73f1736037ea946704c57d9072f26d12beee01a55d947d87f779436",
3+
"virtual_os": "0x59a0052ae80a978ca71126c9774a17c67c19f79b14bb9d1ea96fb77dc6032d8",
44
"aggregator": "0x700786d51b3854af43d8e12180380bda3029be6c1767e007858de6ca2edac40",
55
"aggregator_with_prefix": "0xe08d300e3f5996e43d6d7cc5a20068e0e58cf1309089f2348317ac580f6c1f"
66
}

crates/apollo_starknet_os_program/src/virtual_os_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn test_virtual_os_swapped_files() {
1919
#[test]
2020
fn test_program_bytecode_lengths() {
2121
expect![[r#"
22-
16392
22+
16395
2323
"#]]
2424
.assert_debug_eq(&OS_PROGRAM.data_len());
2525
expect![[r#"

crates/blockifier/resources/blockifier_versioned_constants_0_14_4.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@
127127
"os_constants": {
128128
"allowed_virtual_os_program_hashes": [
129129
"0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473",
130-
"0x6ecb73d21c7d98ddd4148f5bcd91cc2747c65364245fbf32a63b05cca1685c2"
130+
"0x6ecb73d21c7d98ddd4148f5bcd91cc2747c65364245fbf32a63b05cca1685c2",
131+
"0x59a0052ae80a978ca71126c9774a17c67c19f79b14bb9d1ea96fb77dc6032d8"
131132
],
132133
"constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
133134
"default_entry_point_selector": "0x0",
@@ -224,7 +225,7 @@
224225
"os_resources": {
225226
"execute_syscalls": {
226227
"CallContract": {
227-
"n_steps": 903,
228+
"n_steps": 901,
228229
"n_memory_holes": 0,
229230
"builtin_instance_counter": {
230231
"range_check_builtin": 18
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
1+
+ /os_constants/allowed_virtual_os_program_hashes/2: "0x59a0052ae80a978ca71126c9774a17c67c19f79b14bb9d1ea96fb77dc6032d8"
2+
~ /os_resources/execute_syscalls/CallContract/n_steps: 901

crates/blockifier/src/blockifier_versioned_constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ pub struct RawVersionedConstants {
9898
pub os_resources: RawOsResources,
9999
}
100100

101-
#[cfg(test)]
101+
#[cfg(any(test, feature = "testing"))]
102102
impl RawVersionedConstants {
103-
fn to_string_pretty(&self) -> String {
103+
pub fn to_string_pretty(&self) -> String {
104104
let mut buffer = Vec::new();
105105
let formatter = serde_json::ser::PrettyFormatter::with_indent(b" ");
106106
let mut serializer = serde_json::Serializer::with_formatter(&mut buffer, formatter);

crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn test_call_contract(outer_contract: FeatureContract, inner_contract: FeatureCo
268268
l2_to_l1_messages: [],
269269
cairo_native: false,
270270
failed: false,
271-
gas_consumed: 191570,
271+
gas_consumed: 191370,
272272
}
273273
"#]]
274274
.assert_debug_eq(&execution);

crates/blockifier/src/transaction/transactions_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,15 +591,15 @@ fn add_kzg_da_resources_to_resources_mapping(
591591
resources: ExtendedExecutionResources::default(),
592592
validate_gas_consumed: 7820, // The gas consumption results from parsing the input
593593
// arguments.
594-
execute_gas_consumed: 113920,
594+
execute_gas_consumed: 113720,
595595
},
596596
CairoVersion::Cairo1(RunnableCairo1::Casm))]
597597
#[cfg_attr(feature = "cairo_native", case::with_cairo1_native_account(
598598
ExpectedResultTestInvokeTx{
599599
resources: ExtendedExecutionResources::default(),
600600
validate_gas_consumed: 7820, // The gas consumption results from parsing the input
601601
// arguments.
602-
execute_gas_consumed: 113920,
602+
execute_gas_consumed: 113720,
603603
},
604604
CairoVersion::Cairo1(RunnableCairo1::Native)))]
605605
// TODO(Tzahi): Add calls to cairo1 test contracts (where gas flows to and from the inner call).

0 commit comments

Comments
 (0)