Skip to content

Commit 6ee29c9

Browse files
Use exhaustive match statements for syscalls (#3720)
<!-- Reference any GitHub issues resolved by this PR --> Closes #3564 ## Introduced changes ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [ ] Updated relevant documentation - [ ] Added relevant tests - [x] Performed self-review of the code - [ ] Added changes to `CHANGELOG.md`
1 parent f413866 commit 6ee29c9

File tree

4 files changed

+101
-4
lines changed

4 files changed

+101
-4
lines changed

crates/cheatnet/src/runtime_extensions/call_to_blockifier_runtime_extension/mod.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ impl<'a> ExtensionLogic for CallToBlockifierExtension<'a> {
5050
vm: &mut VirtualMachine,
5151
extended_runtime: &mut Self::Runtime,
5252
) -> Result<SyscallHandlingResult, HintError> {
53+
// Warning: Do not add a default (`_`) arm here.
54+
// This match must remain exhaustive so that if a new syscall is introduced,
55+
// we will explicitly add support for it.
5356
match selector {
5457
// We execute contract calls and library calls with modified blockifier
5558
// This is redirected to drop ForgeRuntimeExtension
@@ -64,7 +67,39 @@ impl<'a> ExtensionLogic for CallToBlockifierExtension<'a> {
6467

6568
Ok(SyscallHandlingResult::Handled)
6669
}
67-
_ => Ok(SyscallHandlingResult::Forwarded),
70+
SyscallSelector::DelegateCall
71+
| SyscallSelector::DelegateL1Handler
72+
| SyscallSelector::Deploy
73+
| SyscallSelector::EmitEvent
74+
| SyscallSelector::GetBlockHash
75+
| SyscallSelector::GetBlockNumber
76+
| SyscallSelector::GetBlockTimestamp
77+
| SyscallSelector::GetCallerAddress
78+
| SyscallSelector::GetClassHashAt
79+
| SyscallSelector::GetContractAddress
80+
| SyscallSelector::GetExecutionInfo
81+
| SyscallSelector::GetSequencerAddress
82+
| SyscallSelector::GetTxInfo
83+
| SyscallSelector::GetTxSignature
84+
| SyscallSelector::Keccak
85+
| SyscallSelector::KeccakRound
86+
| SyscallSelector::Sha256ProcessBlock
87+
| SyscallSelector::LibraryCallL1Handler
88+
| SyscallSelector::MetaTxV0
89+
| SyscallSelector::ReplaceClass
90+
| SyscallSelector::Secp256k1Add
91+
| SyscallSelector::Secp256k1GetPointFromX
92+
| SyscallSelector::Secp256k1GetXy
93+
| SyscallSelector::Secp256k1Mul
94+
| SyscallSelector::Secp256k1New
95+
| SyscallSelector::Secp256r1Add
96+
| SyscallSelector::Secp256r1GetPointFromX
97+
| SyscallSelector::Secp256r1GetXy
98+
| SyscallSelector::Secp256r1Mul
99+
| SyscallSelector::Secp256r1New
100+
| SyscallSelector::SendMessageToL1
101+
| SyscallSelector::StorageRead
102+
| SyscallSelector::StorageWrite => Ok(SyscallHandlingResult::Forwarded),
68103
}
69104
}
70105
}

crates/cheatnet/src/runtime_extensions/cheatable_starknet_runtime_extension.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ impl<'a> ExtensionLogic for CheatableStarknetRuntimeExtension<'a> {
4242
) -> Result<SyscallHandlingResult, HintError> {
4343
let syscall_handler = &mut extended_runtime.hint_handler;
4444

45+
// Warning: Do not add a default (`_`) arm here.
46+
// This match must remain exhaustive so that if a new syscall is introduced,
47+
// we will explicitly add support for it.
4548
match selector {
4649
SyscallSelector::GetExecutionInfo => self
4750
.execute_syscall(
@@ -51,7 +54,6 @@ impl<'a> ExtensionLogic for CheatableStarknetRuntimeExtension<'a> {
5154
SyscallSelector::GetExecutionInfo,
5255
)
5356
.map(|()| SyscallHandlingResult::Handled),
54-
5557
SyscallSelector::CallContract => self
5658
.execute_syscall(
5759
syscall_handler,
@@ -108,7 +110,33 @@ impl<'a> ExtensionLogic for CheatableStarknetRuntimeExtension<'a> {
108110
SyscallSelector::MetaTxV0,
109111
)
110112
.map(|()| SyscallHandlingResult::Handled),
111-
_ => Ok(SyscallHandlingResult::Forwarded),
113+
SyscallSelector::DelegateCall
114+
| SyscallSelector::DelegateL1Handler
115+
| SyscallSelector::EmitEvent
116+
| SyscallSelector::GetBlockNumber
117+
| SyscallSelector::GetBlockTimestamp
118+
| SyscallSelector::GetCallerAddress
119+
| SyscallSelector::GetClassHashAt
120+
| SyscallSelector::GetContractAddress
121+
| SyscallSelector::GetSequencerAddress
122+
| SyscallSelector::GetTxInfo
123+
| SyscallSelector::GetTxSignature
124+
| SyscallSelector::Keccak
125+
| SyscallSelector::KeccakRound
126+
| SyscallSelector::Sha256ProcessBlock
127+
| SyscallSelector::LibraryCallL1Handler
128+
| SyscallSelector::ReplaceClass
129+
| SyscallSelector::Secp256k1Add
130+
| SyscallSelector::Secp256k1GetPointFromX
131+
| SyscallSelector::Secp256k1GetXy
132+
| SyscallSelector::Secp256k1Mul
133+
| SyscallSelector::Secp256k1New
134+
| SyscallSelector::Secp256r1Add
135+
| SyscallSelector::Secp256r1GetPointFromX
136+
| SyscallSelector::Secp256r1GetXy
137+
| SyscallSelector::Secp256r1Mul
138+
| SyscallSelector::Secp256r1New
139+
| SyscallSelector::SendMessageToL1 => Ok(SyscallHandlingResult::Forwarded),
112140
}
113141
}
114142

crates/cheatnet/src/runtime_extensions/deprecated_cheatable_starknet_extension/mod.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub type DeprecatedCheatableStarknetRuntime<'a> =
6363
impl<'a> DeprecatedExtensionLogic for DeprecatedCheatableStarknetRuntimeExtension<'a> {
6464
type Runtime = DeprecatedStarknetRuntime<'a>;
6565

66+
#[allow(clippy::too_many_lines)]
6667
fn override_system_call(
6768
&mut self,
6869
selector: SyscallSelector,
@@ -71,6 +72,10 @@ impl<'a> DeprecatedExtensionLogic for DeprecatedCheatableStarknetRuntimeExtensio
7172
) -> Result<SyscallHandlingResult, HintError> {
7273
let syscall_handler = &mut extended_runtime.hint_handler;
7374
let contract_address = syscall_handler.storage_address;
75+
76+
// Warning: Do not add a default (`_`) arm here.
77+
// This match must remain exhaustive so that if a new syscall is introduced,
78+
// we will explicitly add support for it.
7479
match selector {
7580
SyscallSelector::GetCallerAddress => {
7681
if let Some(caller_address) = self
@@ -176,7 +181,33 @@ impl<'a> DeprecatedExtensionLogic for DeprecatedCheatableStarknetRuntimeExtensio
176181
self.execute_syscall(vm, deploy, syscall_handler)?;
177182
Ok(SyscallHandlingResult::Handled)
178183
}
179-
_ => Ok(SyscallHandlingResult::Forwarded),
184+
SyscallSelector::DelegateL1Handler
185+
| SyscallSelector::EmitEvent
186+
| SyscallSelector::GetBlockHash
187+
| SyscallSelector::GetClassHashAt
188+
| SyscallSelector::GetContractAddress
189+
| SyscallSelector::GetExecutionInfo
190+
| SyscallSelector::GetTxInfo
191+
| SyscallSelector::GetTxSignature
192+
| SyscallSelector::Keccak
193+
| SyscallSelector::KeccakRound
194+
| SyscallSelector::Sha256ProcessBlock
195+
| SyscallSelector::LibraryCallL1Handler
196+
| SyscallSelector::MetaTxV0
197+
| SyscallSelector::ReplaceClass
198+
| SyscallSelector::Secp256k1Add
199+
| SyscallSelector::Secp256k1GetPointFromX
200+
| SyscallSelector::Secp256k1GetXy
201+
| SyscallSelector::Secp256k1Mul
202+
| SyscallSelector::Secp256k1New
203+
| SyscallSelector::Secp256r1Add
204+
| SyscallSelector::Secp256r1GetPointFromX
205+
| SyscallSelector::Secp256r1GetXy
206+
| SyscallSelector::Secp256r1Mul
207+
| SyscallSelector::Secp256r1New
208+
| SyscallSelector::SendMessageToL1
209+
| SyscallSelector::StorageRead
210+
| SyscallSelector::StorageWrite => Ok(SyscallHandlingResult::Forwarded),
180211
}
181212
}
182213

crates/forge-runner/src/build_trace_data.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ fn build_profiler_entry_point_type(value: EntryPointType) -> ProfilerEntryPointT
244244
fn build_profiler_deprecated_syscall_selector(
245245
value: SyscallSelector,
246246
) -> ProfilerDeprecatedSyscallSelector {
247+
// Warning: Do not add a default (`_`) arm here.
248+
// This match must remain exhaustive so that if a new syscall is introduced,
249+
// we will explicitly add support for it.
247250
match value {
248251
DeprecatedSyscallSelector::CallContract => ProfilerDeprecatedSyscallSelector::CallContract,
249252
DeprecatedSyscallSelector::DelegateCall => ProfilerDeprecatedSyscallSelector::DelegateCall,

0 commit comments

Comments
 (0)