Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/apollo_starknet_os_program/src/program_hash.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"os": "0xad3b2efb91d0a035ca3acde2c0428869e997a1cf9631d6d947433aa91f71ec",
"os": "0x3b4efc0b4f281f2d80cd0d8104288e6cff9f960f4be1465d43ea64e6f983dd7",
"virtual_os": "0x4fb8c0cb28349d61091f3fc633493c01385f77cd0d4ebfd577251b3941d49b9",
"aggregator": "0x700786d51b3854af43d8e12180380bda3029be6c1767e007858de6ca2edac40",
"aggregator_with_prefix": "0xe08d300e3f5996e43d6d7cc5a20068e0e58cf1309089f2348317ac580f6c1f"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
}
},
"EmitEvent": {
"n_steps": 61,
"n_steps": 47,
"n_memory_holes": 0,
"builtin_instance_counter": {
"range_check_builtin": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
mod OsResourcesTestContract {
use starknet::class_hash::ClassHashZero;
use starknet::info::SyscallResultTrait;
use starknet::syscalls::{call_contract_syscall, deploy_syscall, library_call_syscall};
use starknet::syscalls::{
call_contract_syscall, deploy_syscall, emit_event_syscall, library_call_syscall,
};
use starknet::{ClassHash, ContractAddress};

const EMPTY_FUNCTION_SELECTOR: felt252 = selector!("empty_function");
Expand Down Expand Up @@ -87,6 +89,9 @@ mod OsResourcesTestContract {
deploy_syscall(deployable_class_hash, 2, array![0].span(), true).unwrap_syscall();
// linear factor (calldata len = 1):
deploy_syscall(deployable_class_hash, 2, array![1, 0].span(), true).unwrap_syscall();

// emit event syscall.
emit_event_syscall(array![5].span(), array![7].span()).unwrap_syscall();
}

// Target for call_contract and library_call — accepts no arguments.
Expand Down
38 changes: 33 additions & 5 deletions crates/starknet_os_flow_tests/src/os_resources_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ use crate::special_contracts::{
DEPLOYABLE_FOR_RESOURCE_MEASUREMENT_CONTRACT_CASM,
DEPLOYABLE_FOR_RESOURCE_MEASUREMENT_CONTRACT_SIERRA,
};
use crate::test_manager::{TestBuilder, TestBuilderConfig, FUNDED_ACCOUNT_ADDRESS};
use crate::test_manager::{
EventPredicateExpectation,
TestBuilder,
TestBuilderConfig,
FUNDED_ACCOUNT_ADDRESS,
};
use crate::tests::NON_TRIVIAL_RESOURCE_BOUNDS;
use crate::utils::get_class_hash_of_feature_contract;

// TODO(Dori): Delete this, or at least reduce it to a minimal set of unmeasurable syscalls.
const UNMEASURABLE_SYSCALLS: [Selector; 31] = [
const UNMEASURABLE_SYSCALLS: [Selector; 30] = [
Selector::DelegateCall,
Selector::DelegateL1Handler,
Selector::EmitEvent,
Selector::GetBlockHash,
Selector::GetBlockNumber,
Selector::GetBlockTimestamp,
Expand Down Expand Up @@ -178,7 +182,19 @@ async fn test_os_resources_regression() {
&test_builder.chain_id(),
)
.unwrap();
test_builder.add_invoke_tx(tx, None, None);
test_builder.add_invoke_tx(
tx,
None,
// Expect one event from the emit-event syscall measurement.
Some(vec![EventPredicateExpectation {
description: "emit event syscall".to_string(),
predicate: Box::new(move |event| {
event.from_address == os_resources_contract_address
&& event.content.keys[0].0 == Felt::from(5)
&& event.content.data.0[0] == Felt::from(7)
}),
}]),
);

// Run test. Grab the execution info from the runner (for later) before consuming it.
let test_runner = test_builder.build().await;
Expand All @@ -200,7 +216,19 @@ async fn test_os_resources_regression() {
test_output.perform_default_validations();

// Extract syscall resources consumed, per (measurable) syscall.
let syscall_traces = test_output.runner_output.txs_trace.last().unwrap().get_syscalls();
// There should be two events emitted: the first is the syscall we are measuring, and the second
// is the last syscall in the tx, emitted from the fee transfer. Pop the second event.
let mut syscall_traces =
test_output.runner_output.txs_trace.last().unwrap().get_syscalls().clone();
assert!(!UNMEASURABLE_SYSCALLS.contains(&Selector::EmitEvent));
assert_eq!(
syscall_traces
.iter()
.filter(|syscall_trace| syscall_trace.get_selector() == Selector::EmitEvent)
.count(),
2
);
assert_eq!(syscall_traces.pop().unwrap().get_selector(), Selector::EmitEvent);

// Measure each syscall overhead. If the syscall incurs an inner call, subtract the inner call
// overhead.
Expand Down
Loading