Skip to content
Closed
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: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion crates/apollo_starknet_os_program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ serde_json.workspace = true

[dev-dependencies]
apollo_infra_utils = { workspace = true, features = ["testing"] }
blockifier.workspace = true
blockifier = { workspace = true, features = ["testing"] }
starknet-types-core.workspace = true
starknet_api.workspace = true
strum.workspace = true
strum_macros.workspace = true
39 changes: 39 additions & 0 deletions crates/apollo_starknet_os_program/src/constants_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use blockifier::blockifier_versioned_constants::{OsConstants, VersionedConstants
use blockifier::execution::syscalls::vm_syscall_utils::SyscallSelector;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
use starknet_types_core::felt::Felt;
use strum::IntoEnumIterator;

const CONSTANTS_CONTENTS: &str = include_str!("cairo/starkware/starknet/core/os/constants.cairo");

Expand Down Expand Up @@ -233,3 +234,41 @@ fn test_os_constants() {
);
}
}

/// Test that all syscalls have a gas cost, and syscalls with linear factors have both costs.
#[test]
fn test_all_syscall_have_gas_costs() {
let os_constants_template =
include_str!("cairo/starkware/starknet/core/os/constants_template.txt");
let syscall_costs = &VersionedConstants::latest_constants().os_constants.gas_costs.syscalls;
for selector in SyscallSelector::iter() {
let Ok(cost) = syscall_costs.get_syscall_gas_cost(&selector) else {
// We don't care about deprecated syscalls (without gas costs).
continue;
};

let selector_str: &str = match selector {
// Keccak round is a special case, since it has a different name in the template.
SyscallSelector::KeccakRound => "KECCAK_ROUND_COST",
_ => selector.as_ref(),
};
let gas_cost_str = format!("{selector_str}_GAS_COST = {{{selector_str}_GAS_COST}}");

// Base cost always exists.
assert!(
os_constants_template.contains(&gas_cost_str),
"Syscall {selector_str} should have a base gas cost."
);
// If the syscall has a linear factor check for it.
if cost.linear_syscall_cost() != 0 {
let linear_factor_str = format!(
"{selector_str}_CALLDATA_FACTOR_GAS_COST = \
{{{selector_str}_CALLDATA_FACTOR_GAS_COST}}"
);
assert!(
os_constants_template.contains(&linear_factor_str),
"Syscall {selector_str} should have a linear gas cost."
);
}
}
}
3 changes: 2 additions & 1 deletion crates/blockifier/src/execution/deprecated_syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ pub mod hint_processor;
pub type DeprecatedSyscallResult<T> = Result<T, DeprecatedSyscallExecutionError>;
pub type WriteResponseResult = DeprecatedSyscallExecutorBaseResult<()>;

#[cfg_attr(any(test, feature = "testing"), derive(serde::Serialize))]
#[cfg_attr(any(test, feature = "testing"), derive(serde::Serialize, strum_macros::AsRefStr))]
#[cfg_attr(any(test, feature = "testing"), strum(serialize_all = "SCREAMING_SNAKE_CASE"))]
#[derive(Clone, Copy, Debug, Deserialize, EnumIter, Eq, Hash, PartialEq)]
pub enum DeprecatedSyscallSelector {
CallContract,
Expand Down
Loading