Skip to content

Commit c2939e8

Browse files
starknet_os: os resources test - add send_message_to_l1
1 parent 8e6b4a4 commit c2939e8

9 files changed

Lines changed: 32 additions & 17 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-
0x04373ade67a35a6ae0466730e5807b828a5db813010d6070bb1db85f99682dcb
75+
0x0397efd2933dd48595331d4a61ca1cdf4ae1b4ff1999933cd419625a67fc7b04
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 = 168550;
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": "0x2f2a3b9083c0d74ac187befa00a61033e46f5b4782c03b87869592babcbe3e9",
3-
"virtual_os": "0x4373ade67a35a6ae0466730e5807b828a5db813010d6070bb1db85f99682dcb",
2+
"os": "0x72a1e11937375845bdbfcb0c13ecc41f98f9439aac233eef668ac0f8272240c",
3+
"virtual_os": "0x397efd2933dd48595331d4a61ca1cdf4ae1b4ff1999933cd419625a67fc7b04",
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
@@ -129,7 +129,7 @@
129129
"allowed_virtual_os_program_hashes": [
130130
"0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473",
131131
"0x6ecb73d21c7d98ddd4148f5bcd91cc2747c65364245fbf32a63b05cca1685c2",
132-
"0x4373ade67a35a6ae0466730e5807b828a5db813010d6070bb1db85f99682dcb"
132+
"0x397efd2933dd48595331d4a61ca1cdf4ae1b4ff1999933cd419625a67fc7b04"
133133
],
134134
"constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
135135
"default_entry_point_selector": "0x0",
@@ -455,7 +455,7 @@
455455
}
456456
},
457457
"SendMessageToL1": {
458-
"n_steps": 144,
458+
"n_steps": 124,
459459
"n_memory_holes": 0,
460460
"builtin_instance_counter": {
461461
"range_check_builtin": 1

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
+ /os_constants/allowed_virtual_os_program_hashes/2: "0x4373ade67a35a6ae0466730e5807b828a5db813010d6070bb1db85f99682dcb"
1+
+ /os_constants/allowed_virtual_os_program_hashes/2: "0x397efd2933dd48595331d4a61ca1cdf4ae1b4ff1999933cd419625a67fc7b04"
22
~ /os_resources/execute_syscalls/CallContract/n_steps: 901
33
~ /os_resources/execute_syscalls/EmitEvent/n_steps: 47
44
~ /os_resources/execute_syscalls/GetBlockHash/builtin_instance_counter/range_check_builtin: 3
@@ -10,4 +10,5 @@
1010
~ /os_resources/execute_syscalls/LibraryCall/n_steps: 874
1111
~ /os_resources/execute_syscalls/MetaTxV0/constant/n_steps: 1307
1212
~ /os_resources/execute_syscalls/ReplaceClass/n_steps: 92
13+
~ /os_resources/execute_syscalls/SendMessageToL1/n_steps: 124
1314
~ /os_resources/execute_syscalls/Sha256ProcessBlock/n_steps: 1854

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn test_send_message_to_l1(runnable_version: RunnableCairo1) {
7575
],
7676
cairo_native: false,
7777
failed: false,
78-
gas_consumed: 25220,
78+
gas_consumed: 23220,
7979
}
8080
"#]]
8181
.assert_debug_eq(&execution);

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
@@ -6,7 +6,8 @@ mod OsResourcesTestContract {
66
use starknet::info::SyscallResultTrait;
77
use starknet::syscalls::{
88
call_contract_syscall, deploy_syscall, emit_event_syscall, get_execution_info_v3_syscall,
9-
keccak_syscall, library_call_syscall, replace_class_syscall, sha256_process_block_syscall,
9+
keccak_syscall, library_call_syscall, replace_class_syscall, send_message_to_l1_syscall,
10+
sha256_process_block_syscall,
1011
};
1112
use starknet::{ClassHash, ContractAddress, get_block_hash_syscall, get_class_hash_at_syscall};
1213

@@ -125,5 +126,10 @@ mod OsResourcesTestContract {
125126

126127
// replace class syscall.
127128
replace_class_syscall(stable_class_hash).unwrap_syscall();
129+
130+
// send message to l1 syscall.
131+
// TODO(Yoni, 1/6/2022): In this case the number of steps depends on the payload size -
132+
// consider counting it.
133+
send_message_to_l1_syscall(100, array![].span()).unwrap_syscall();
128134
}
129135
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
31
1+
32

crates/central_systest_blobs/resources/preconfirmed_block.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
"timestamp": 1013,
2121
"transaction_receipts": [
2222
{
23-
"actual_fee": "0x1076e9",
23+
"actual_fee": "0x106f19",
2424
"events": [
2525
{
2626
"data": [
2727
"0x3d3759cf036b96f8105f40dcf3fe0c209be3419154aa458d03336ad0443ce81",
2828
"0x1000",
29-
"0x1076e9",
29+
"0x106f19",
3030
"0x0"
3131
],
3232
"from_address": "0x6c6a50ee425e9ff35846be376051b8cdbdc1aadc6c954209fe3fd247a571b33",
@@ -51,7 +51,7 @@
5151
"total_gas_consumed": {
5252
"l1_data_gas": 0,
5353
"l1_gas": 1652,
54-
"l2_gas": 1077365
54+
"l2_gas": 1075365
5555
}
5656
},
5757
"execution_status": "SUCCEEDED",
@@ -74,11 +74,11 @@
7474
"0x6c6a50ee425e9ff35846be376051b8cdbdc1aadc6c954209fe3fd247a571b33": [
7575
{
7676
"key": "0x2cbac7495ce24b399327e9282b09d029b1dd772b24b7e8dcd0467fedab5af58",
77-
"value": "0xfffffffffffffffffffffffff98c1fb3"
77+
"value": "0xfffffffffffffffffffffffff98c2f53"
7878
},
7979
{
8080
"key": "0x723973208639b7839ce298f7ffea61e3f9533872defd7abdb91023db4658812",
81-
"value": "0x673e04c"
81+
"value": "0x673d0ac"
8282
}
8383
]
8484
}

crates/starknet_os_flow_tests/src/os_resources_test.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ use expect_test::expect_file;
2020
use indexmap::IndexMap;
2121
use starknet_api::block::StarknetVersion;
2222
use starknet_api::contract_class::SierraVersion;
23+
use starknet_api::core::EthAddress;
2324
use starknet_api::executable_transaction::InvokeTransaction;
2425
use starknet_api::test_utils::invoke::invoke_tx;
2526
use starknet_api::transaction::fields::ContractAddressSalt;
27+
use starknet_api::transaction::{L2ToL1Payload, MessageToL1};
2628
use starknet_api::versioned_constants_logic::VersionedConstantsTrait;
2729
use starknet_api::{calldata, declare_tx_args, invoke_tx_args};
2830
use starknet_os::hint_processor::os_logger::ResourceFinalizer;
@@ -47,7 +49,7 @@ use crate::test_manager::{
4749
use crate::tests::NON_TRIVIAL_RESOURCE_BOUNDS;
4850

4951
// TODO(Dori): Delete this, or at least reduce it to a minimal set of unmeasurable syscalls.
50-
const UNMEASURABLE_SYSCALLS: [Selector; 24] = [
52+
const UNMEASURABLE_SYSCALLS: [Selector; 23] = [
5153
Selector::DelegateCall,
5254
Selector::DelegateL1Handler,
5355
Selector::GetBlockNumber,
@@ -69,7 +71,6 @@ const UNMEASURABLE_SYSCALLS: [Selector; 24] = [
6971
Selector::Secp256r1GetXy,
7072
Selector::Secp256r1Mul,
7173
Selector::Secp256r1New,
72-
Selector::SendMessageToL1,
7374
Selector::StorageRead,
7475
Selector::StorageWrite,
7576
];
@@ -288,6 +289,13 @@ async fn test_os_resources_regression() {
288289
}]),
289290
);
290291

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

0 commit comments

Comments
 (0)