Skip to content

Commit 6d69bf0

Browse files
starknet_os: os resources test - add send_message_to_l1
1 parent 8be4f98 commit 6d69bf0

6 files changed

Lines changed: 24 additions & 10 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_1 = (
7272
0x06ecb73d21c7d98ddd4148f5bcd91cc2747c65364245fbf32a63b05cca1685c2
7373
);
7474
const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_2 = (
75-
0x066a46bb88553c4dafd12959575033660780d689c99659ab3620e2f524f71701
75+
0x0471dd673f38125ba94e98145e3579d700ad13bd0e177687b67bab6221da4fa0
7676
);
7777
const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN = 3;
7878

@@ -119,7 +119,7 @@ const REPLACE_CLASS_GAS_COST = 10000;
119119
const STORAGE_READ_GAS_COST = 24070;
120120
const STORAGE_WRITE_GAS_COST = 59970;
121121
const EMIT_EVENT_GAS_COST = 10000;
122-
const SEND_MESSAGE_TO_L1_GAS_COST = 14470;
122+
const SEND_MESSAGE_TO_L1_GAS_COST = 12470;
123123
const META_TX_V0_GAS_COST = 187350;
124124
const META_TX_V0_CALLDATA_FACTOR_GAS_COST = 4850;
125125

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"os": "0x3ab760e55c8e6396b6b37f16076c9038ef6750bcebed93827b884194940fd53",
3-
"virtual_os": "0x66a46bb88553c4dafd12959575033660780d689c99659ab3620e2f524f71701",
2+
"os": "0x10e22135c2f216368f35ec35bdc6a9a6d2e448a1919147886ab0ddb2c0435c",
3+
"virtual_os": "0x471dd673f38125ba94e98145e3579d700ad13bd0e177687b67bab6221da4fa0",
44
"aggregator": "0x700786d51b3854af43d8e12180380bda3029be6c1767e007858de6ca2edac40",
55
"aggregator_with_prefix": "0xe08d300e3f5996e43d6d7cc5a20068e0e58cf1309089f2348317ac580f6c1f"
66
}

crates/blockifier/resources/blockifier_versioned_constants_0_14_4.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
"allowed_virtual_os_program_hashes": [
129129
"0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473",
130130
"0x6ecb73d21c7d98ddd4148f5bcd91cc2747c65364245fbf32a63b05cca1685c2",
131-
"0x66a46bb88553c4dafd12959575033660780d689c99659ab3620e2f524f71701"
131+
"0x471dd673f38125ba94e98145e3579d700ad13bd0e177687b67bab6221da4fa0"
132132
],
133133
"constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
134134
"default_entry_point_selector": "0x0",
@@ -454,7 +454,7 @@
454454
}
455455
},
456456
"SendMessageToL1": {
457-
"n_steps": 144,
457+
"n_steps": 124,
458458
"n_memory_holes": 0,
459459
"builtin_instance_counter": {
460460
"range_check_builtin": 1

crates/blockifier/resources/versioned_constants_diff_regression/0.14.3_0.14.4.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
+ /os_constants/allowed_virtual_os_program_hashes/2: "0x66a46bb88553c4dafd12959575033660780d689c99659ab3620e2f524f71701"
1+
+ /os_constants/allowed_virtual_os_program_hashes/2: "0x471dd673f38125ba94e98145e3579d700ad13bd0e177687b67bab6221da4fa0"
22
~ /os_resources/execute_syscalls/CallContract/n_steps: 901
33
~ /os_resources/execute_syscalls/Deploy/constant/builtin_instance_counter/pedersen_builtin: 8
44
~ /os_resources/execute_syscalls/Deploy/constant/n_steps: 1183

crates/blockifier_test_utils/resources/feature_contracts/cairo1/os_resources_test_contract.cairo

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ mod OsResourcesTestContract {
77
use starknet::info::SyscallResultTrait;
88
use starknet::syscalls::{
99
call_contract_syscall, deploy_syscall, emit_event_syscall, get_execution_info_v2_syscall,
10-
keccak_syscall, library_call_syscall, replace_class_syscall, sha256_process_block_syscall,
10+
keccak_syscall, library_call_syscall, replace_class_syscall, send_message_to_l1_syscall,
11+
sha256_process_block_syscall,
1112
};
1213
use starknet::{ClassHash, ContractAddress, get_block_hash_syscall, get_class_hash_at_syscall};
1314

@@ -121,6 +122,11 @@ mod OsResourcesTestContract {
121122

122123
// replace class syscall.
123124
replace_class_syscall(self_class_hash).unwrap_syscall();
125+
126+
// send message to l1 syscall.
127+
// TODO(Yoni, 1/6/2022): In this case the number of steps depends on the payload size -
128+
// consider counting it.
129+
send_message_to_l1_syscall(100, array![].span()).unwrap_syscall();
124130
}
125131

126132
// Target for call_contract and library_call — accepts no arguments.

crates/starknet_os_flow_tests/src/os_resources_test.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ use indexmap::IndexMap;
1919
use starknet_api::block::StarknetVersion;
2020
use starknet_api::contract_class::compiled_class_hash::{HashVersion, HashableCompiledClass};
2121
use starknet_api::contract_class::{ClassInfo, ContractClass, SierraVersion};
22+
use starknet_api::core::EthAddress;
2223
use starknet_api::executable_transaction::{DeclareTransaction, InvokeTransaction};
2324
use starknet_api::test_utils::declare::declare_tx;
2425
use starknet_api::test_utils::invoke::invoke_tx;
26+
use starknet_api::transaction::{L2ToL1Payload, MessageToL1};
2527
use starknet_api::versioned_constants_logic::VersionedConstantsTrait;
2628
use starknet_api::{calldata, declare_tx_args, invoke_tx_args};
2729
use starknet_os::hint_processor::constants::BUILTIN_INSTANCE_SIZES;
@@ -45,7 +47,7 @@ use crate::tests::NON_TRIVIAL_RESOURCE_BOUNDS;
4547
use crate::utils::get_class_hash_of_feature_contract;
4648

4749
// TODO(Dori): Delete this, or at least reduce it to a minimal set of unmeasurable syscalls.
48-
const UNMEASURABLE_SYSCALLS: [Selector; 24] = [
50+
const UNMEASURABLE_SYSCALLS: [Selector; 23] = [
4951
Selector::DelegateCall,
5052
Selector::DelegateL1Handler,
5153
Selector::GetBlockNumber,
@@ -67,7 +69,6 @@ const UNMEASURABLE_SYSCALLS: [Selector; 24] = [
6769
Selector::Secp256r1GetXy,
6870
Selector::Secp256r1Mul,
6971
Selector::Secp256r1New,
70-
Selector::SendMessageToL1,
7172
Selector::StorageRead,
7273
Selector::StorageWrite,
7374
];
@@ -285,6 +286,13 @@ async fn test_os_resources_regression() {
285286
}]),
286287
);
287288

289+
// Add the expected message to L1.
290+
test_builder.messages_to_l1.push(MessageToL1 {
291+
from_address: os_resources_contract_address,
292+
to_address: EthAddress::try_from(Felt::from(100)).unwrap(),
293+
payload: L2ToL1Payload(vec![]),
294+
});
295+
288296
// Run test. Grab the execution info from the runner (for later) before consuming it.
289297
let test_runner = test_builder.build().await;
290298
let inner_calls = test_runner

0 commit comments

Comments
 (0)