Skip to content

Commit b4dc505

Browse files
starknet_os: os resources test - add send_message_to_l1
1 parent ed548b5 commit b4dc505

5 files changed

Lines changed: 21 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const REPLACE_CLASS_GAS_COST = 10000;
116116
const STORAGE_READ_GAS_COST = 18070;
117117
const STORAGE_WRITE_GAS_COST = 44970;
118118
const EMIT_EVENT_GAS_COST = 10000;
119-
const SEND_MESSAGE_TO_L1_GAS_COST = 14470;
119+
const SEND_MESSAGE_TO_L1_GAS_COST = 12270;
120120
const META_TX_V0_GAS_COST = 186850;
121121
const META_TX_V0_CALLDATA_FACTOR_GAS_COST = 4850;
122122

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

crates/blockifier/resources/blockifier_versioned_constants_0_14_3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@
453453
}
454454
},
455455
"SendMessageToL1": {
456-
"n_steps": 144,
456+
"n_steps": 122,
457457
"n_memory_holes": 0,
458458
"builtin_instance_counter": {
459459
"range_check_builtin": 1

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; 23] = [
50+
const UNMEASURABLE_SYSCALLS: [Selector; 22] = [
4951
Selector::DelegateCall,
5052
Selector::DelegateL1Handler,
5153
Selector::GetBlockNumber,
@@ -66,7 +68,6 @@ const UNMEASURABLE_SYSCALLS: [Selector; 23] = [
6668
Selector::Secp256r1GetXy,
6769
Selector::Secp256r1Mul,
6870
Selector::Secp256r1New,
69-
Selector::SendMessageToL1,
7071
Selector::StorageRead,
7172
Selector::StorageWrite,
7273
];
@@ -259,6 +260,13 @@ async fn test_os_resources_regression() {
259260
}]),
260261
);
261262

263+
// Add the expected message to L1.
264+
test_builder.messages_to_l1.push(MessageToL1 {
265+
from_address: os_resources_contract_address,
266+
to_address: EthAddress::try_from(Felt::from(100)).unwrap(),
267+
payload: L2ToL1Payload(vec![]),
268+
});
269+
262270
// Run test. Grab the execution info from the runner (for later) before consuming it.
263271
let test_runner = test_builder.build().await;
264272
let inner_calls = test_runner

0 commit comments

Comments
 (0)