Skip to content

Commit 61946a6

Browse files
test(starknet_os): deprecated syscall hint consistency test (#6988)
1 parent 5b21dc6 commit 61946a6

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

crates/starknet_os/src/hints/enum_definition_test.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::HashSet;
22
use std::sync::LazyLock;
33

44
use apollo_starknet_os_program::{AGGREGATOR_PROGRAM, OS_PROGRAM};
5+
use blockifier::execution::deprecated_syscalls::DeprecatedSyscallSelector;
56
use blockifier::execution::hint_code::SYSCALL_HINTS;
67
use cairo_vm::hint_processor::builtin_hint_processor::hint_code::HINT_CODES;
78
use cairo_vm::hint_processor::builtin_hint_processor::kzg_da::WRITE_DIVMOD_SEGMENT;
@@ -19,6 +20,35 @@ static VM_HINTS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
1920
vm_hints
2021
});
2122

23+
/// This conversion is only required for testing consistency.
24+
impl TryFrom<DeprecatedSyscallSelector> for DeprecatedSyscallHint {
25+
type Error = String;
26+
27+
fn try_from(selector: DeprecatedSyscallSelector) -> Result<Self, Self::Error> {
28+
match selector {
29+
DeprecatedSyscallSelector::CallContract => Ok(Self::CallContract),
30+
DeprecatedSyscallSelector::DelegateCall => Ok(Self::DelegateCall),
31+
DeprecatedSyscallSelector::DelegateL1Handler => Ok(Self::DelegateL1Handler),
32+
DeprecatedSyscallSelector::Deploy => Ok(Self::Deploy),
33+
DeprecatedSyscallSelector::EmitEvent => Ok(Self::EmitEvent),
34+
DeprecatedSyscallSelector::GetBlockNumber => Ok(Self::GetBlockNumber),
35+
DeprecatedSyscallSelector::GetBlockTimestamp => Ok(Self::GetBlockTimestamp),
36+
DeprecatedSyscallSelector::GetCallerAddress => Ok(Self::GetCallerAddress),
37+
DeprecatedSyscallSelector::GetContractAddress => Ok(Self::GetContractAddress),
38+
DeprecatedSyscallSelector::GetSequencerAddress => Ok(Self::GetSequencerAddress),
39+
DeprecatedSyscallSelector::GetTxInfo => Ok(Self::GetTxInfo),
40+
DeprecatedSyscallSelector::GetTxSignature => Ok(Self::GetTxSignature),
41+
DeprecatedSyscallSelector::LibraryCall => Ok(Self::LibraryCall),
42+
DeprecatedSyscallSelector::LibraryCallL1Handler => Ok(Self::LibraryCallL1Handler),
43+
DeprecatedSyscallSelector::ReplaceClass => Ok(Self::ReplaceClass),
44+
DeprecatedSyscallSelector::SendMessageToL1 => Ok(Self::SendMessageToL1),
45+
DeprecatedSyscallSelector::StorageRead => Ok(Self::StorageRead),
46+
DeprecatedSyscallSelector::StorageWrite => Ok(Self::StorageWrite),
47+
_ => Err(format!("Non-deprecated syscall selector: {selector:?}.")),
48+
}
49+
}
50+
}
51+
2252
fn program_hints(program: &Program) -> HashSet<String> {
2353
program
2454
.shared_program_data
@@ -95,3 +125,58 @@ fn test_all_hints_are_used() {
95125
Please remove them from the enum definition."
96126
);
97127
}
128+
129+
/// Tests that the set of deprecated syscall hints is consistent with the enum of deprecated
130+
/// syscalls.
131+
#[test]
132+
fn test_deprecated_syscall_hint_consistency() {
133+
let deprecated_syscall_hints: Vec<DeprecatedSyscallHint> =
134+
DeprecatedSyscallHint::iter().collect();
135+
let deprecated_syscall_selectors: Vec<DeprecatedSyscallSelector> =
136+
DeprecatedSyscallSelector::iter()
137+
.filter(|selector| {
138+
!matches!(
139+
selector,
140+
// As the new and deprecated syscall selector enums are the same enum,
141+
// explicitly filter out all "new" syscalls that are not supported in Cairo0.
142+
DeprecatedSyscallSelector::GetBlockHash
143+
| DeprecatedSyscallSelector::GetClassHashAt
144+
| DeprecatedSyscallSelector::GetExecutionInfo
145+
| DeprecatedSyscallSelector::Keccak
146+
| DeprecatedSyscallSelector::KeccakRound
147+
| DeprecatedSyscallSelector::Sha256ProcessBlock
148+
| DeprecatedSyscallSelector::MetaTxV0
149+
| DeprecatedSyscallSelector::Secp256k1Add
150+
| DeprecatedSyscallSelector::Secp256k1GetPointFromX
151+
| DeprecatedSyscallSelector::Secp256k1GetXy
152+
| DeprecatedSyscallSelector::Secp256k1Mul
153+
| DeprecatedSyscallSelector::Secp256k1New
154+
| DeprecatedSyscallSelector::Secp256r1Add
155+
| DeprecatedSyscallSelector::Secp256r1GetPointFromX
156+
| DeprecatedSyscallSelector::Secp256r1GetXy
157+
| DeprecatedSyscallSelector::Secp256r1Mul
158+
| DeprecatedSyscallSelector::Secp256r1New
159+
)
160+
})
161+
.collect();
162+
163+
assert_eq!(
164+
deprecated_syscall_selectors.len(),
165+
deprecated_syscall_hints.len(),
166+
"The number of deprecated syscall selectors does not match the number of deprecated \
167+
syscall hints. Selectors: {deprecated_syscall_selectors:#?}, hints: \
168+
{deprecated_syscall_hints:#?}",
169+
);
170+
171+
let converted_selectors: HashSet<DeprecatedSyscallHint> = deprecated_syscall_selectors
172+
.iter()
173+
.map(|selector| DeprecatedSyscallHint::try_from(*selector).unwrap())
174+
.collect();
175+
assert_eq!(
176+
converted_selectors,
177+
deprecated_syscall_hints.iter().cloned().collect(),
178+
"The deprecated syscall selectors, converted to hints, do not match the deprecated \
179+
syscall hints. Converted selectors: {converted_selectors:#?}, hints: \
180+
{deprecated_syscall_hints:#?}"
181+
);
182+
}

0 commit comments

Comments
 (0)