Skip to content

Commit 00a30cb

Browse files
starknet_os: os resources test - add emit event
1 parent f7fd3a3 commit 00a30cb

5 files changed

Lines changed: 40 additions & 12 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
@@ -105,8 +105,8 @@ const SYSCALL_BASE_GAS_COST = 10000;
105105

106106
// Syscall gas costs.
107107
const CALL_CONTRACT_GAS_COST = 91160;
108-
const DEPLOY_GAS_COST = 151870;
109-
const DEPLOY_CALLDATA_FACTOR_GAS_COST = 4650;
108+
const DEPLOY_GAS_COST = 151670;
109+
const DEPLOY_CALLDATA_FACTOR_GAS_COST = 5050;
110110
const GET_BLOCK_HASH_GAS_COST = 10840;
111111
const GET_CLASS_HASH_AT_GAS_COST = 10000;
112112
const GET_EXECUTION_INFO_GAS_COST = 12640;

crates/apollo_starknet_os_program/src/program_hash.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"os": "0x62240ee2187ddc8c215c5b258f754c847961b5e4f376586457cbb0a6707d3d",
2+
"os": "0x5b8231cecc8a39079e941218abfc486097369f888638f9675b1f04bb24af57",
33
"virtual_os": "0x1689e4a3bb32dd81c66ee660a9ca05aad72309b38ba5cbac0ffec782e5b8154",
44
"aggregator": "0x700786d51b3854af43d8e12180380bda3029be6c1767e007858de6ca2edac40",
55
"aggregator_with_prefix": "0xe08d300e3f5996e43d6d7cc5a20068e0e58cf1309089f2348317ac580f6c1f"

crates/blockifier/resources/blockifier_versioned_constants_0_14_3.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,23 +247,23 @@
247247
},
248248
"Deploy": {
249249
"constant": {
250-
"n_steps": 1180,
250+
"n_steps": 1178,
251251
"n_memory_holes": 0,
252252
"builtin_instance_counter": {
253253
"range_check_builtin": 21,
254254
"pedersen_builtin": 8
255255
}
256256
},
257257
"calldata_factor": {
258-
"n_steps": 6,
258+
"n_steps": 10,
259259
"n_memory_holes": 0,
260260
"builtin_instance_counter": {
261261
"pedersen_builtin": 1
262262
}
263263
}
264264
},
265265
"EmitEvent": {
266-
"n_steps": 61,
266+
"n_steps": 47,
267267
"n_memory_holes": 0,
268268
"builtin_instance_counter": {
269269
"range_check_builtin": 1

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
mod OsResourcesTestContract {
44
use starknet::class_hash::ClassHashZero;
55
use starknet::info::SyscallResultTrait;
6-
use starknet::syscalls::{call_contract_syscall, deploy_syscall, library_call_syscall};
6+
use starknet::syscalls::{
7+
call_contract_syscall, deploy_syscall, emit_event_syscall, library_call_syscall
8+
};
79
use starknet::{ClassHash, ContractAddress};
810

911
const EMPTY_FUNCTION_SELECTOR: felt252 = selector!("empty_function");
@@ -81,6 +83,9 @@ mod OsResourcesTestContract {
8183
deploy_syscall(self_class_hash, 0, array![0].span(), false).unwrap_syscall();
8284
// deploy syscall: linear factor (calldata len = 1).
8385
deploy_syscall(self_class_hash, 0, array![1, 0].span(), false).unwrap_syscall();
86+
87+
// emit event syscall.
88+
emit_event_syscall(array![5].span(), array![7].span()).unwrap_syscall();
8489
}
8590

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

crates/starknet_os_flow_tests/src/os_resources_test.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ use starknet_types_core::felt::Felt;
2626
use strum::IntoEnumIterator;
2727

2828
use crate::initial_state::create_default_initial_state_data;
29-
use crate::test_manager::{TestBuilder, TestBuilderConfig};
29+
use crate::test_manager::{EventPredicateExpectation, TestBuilder, TestBuilderConfig};
3030
use crate::tests::NON_TRIVIAL_RESOURCE_BOUNDS;
3131
use crate::utils::get_class_hash_of_feature_contract;
3232

3333
// TODO(Dori): Delete this, or at least reduce it to a minimal set of unmeasurable syscalls.
34-
const UNMEASURABLE_SYSCALLS: [Selector; 31] = [
34+
const UNMEASURABLE_SYSCALLS: [Selector; 30] = [
3535
Selector::DelegateCall,
3636
Selector::DelegateL1Handler,
37-
Selector::EmitEvent,
3837
Selector::GetBlockHash,
3938
Selector::GetBlockNumber,
4039
Selector::GetBlockTimestamp,
@@ -116,7 +115,19 @@ async fn test_os_resources_regression() {
116115
&test_builder.chain_id(),
117116
)
118117
.unwrap();
119-
test_builder.add_invoke_tx(tx, None, None);
118+
test_builder.add_invoke_tx(
119+
tx,
120+
None,
121+
// Expect one event from the emit-event syscall measurement.
122+
Some(vec![EventPredicateExpectation {
123+
description: "emit event syscall".to_string(),
124+
predicate: Box::new(move |event| {
125+
event.from_address == os_resources_contract_address
126+
&& event.content.keys[0].0 == Felt::from(5)
127+
&& event.content.data.0[0] == Felt::from(7)
128+
}),
129+
}]),
130+
);
120131

121132
// Run test. Grab the execution info from the runner (for later) before consuming it.
122133
let test_runner = test_builder.build().await;
@@ -138,7 +149,19 @@ async fn test_os_resources_regression() {
138149
test_output.perform_default_validations();
139150

140151
// Extract syscall resources consumed, per (measurable) syscall.
141-
let syscall_traces = test_output.runner_output.txs_trace.last().unwrap().get_syscalls();
152+
// There should be two events emitted: the first is the syscall we are measuring, and the second
153+
// is the last syscall in the tx, emitted from the fee transfer. Pop the second event.
154+
let mut syscall_traces =
155+
test_output.runner_output.txs_trace.last().unwrap().get_syscalls().clone();
156+
assert!(!UNMEASURABLE_SYSCALLS.contains(&Selector::EmitEvent));
157+
assert_eq!(
158+
syscall_traces
159+
.iter()
160+
.filter(|syscall_trace| syscall_trace.get_selector() == Selector::EmitEvent)
161+
.count(),
162+
2
163+
);
164+
assert_eq!(syscall_traces.pop().unwrap().get_selector(), Selector::EmitEvent);
142165

143166
// Measure each syscall overhead. If the syscall incurs an inner call, subtract the inner call
144167
// overhead.

0 commit comments

Comments
 (0)