Skip to content

Commit 44e99e0

Browse files
apollo_starknet_os_program: restore keccak syscall in virtual OS
Re-adds the keccak syscall to the virtual OS (reverts the removal from #12355) and bumps allowed_virtual_os_program_hashes to the new virtual_os program hash. Cleans up the now-redundant 'Keccak' arm in test_contract's test_forbidden_syscall_in_virtual_mode and drops the corresponding case in test_forbidden_syscall. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3210a0e commit 44e99e0

9 files changed

Lines changed: 21 additions & 16 deletions

File tree

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/constants.cairo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_0 = (
6969
0x03e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473
7070
);
7171
const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_1 = (
72-
0x039f55918423cade9e95a6a52286b56bed1c5c9b6fe39aa00301361457a3c604
72+
0x0542f701524219b8333d8a74a7eee00724673d53d1c78915e8f6d241e4ad81b9
7373
);
7474
const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN = 2;
7575

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/execution/execute_syscalls__virtual.cairo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from starkware.starknet.common.new_syscalls import (
99
EMIT_EVENT_SELECTOR,
1010
GET_CLASS_HASH_AT_SELECTOR,
1111
GET_EXECUTION_INFO_SELECTOR,
12+
KECCAK_SELECTOR,
1213
LIBRARY_CALL_SELECTOR,
1314
SECP256K1_ADD_SELECTOR,
1415
SECP256K1_GET_POINT_FROM_X_SELECTOR,
@@ -39,6 +40,7 @@ from starkware.starknet.core.os.execution.syscall_impls import (
3940
execute_call_contract,
4041
execute_get_class_hash_at,
4142
execute_get_execution_info,
43+
execute_keccak,
4244
execute_library_call,
4345
execute_secp256k1_add,
4446
execute_secp256k1_get_point_from_x,
@@ -157,6 +159,16 @@ func execute_syscalls{
157159
);
158160
}
159161

162+
if (selector == KECCAK_SELECTOR) {
163+
execute_keccak();
164+
%{ OsLoggerExitSyscall %}
165+
return execute_syscalls(
166+
block_context=block_context,
167+
execution_context=execution_context,
168+
syscall_ptr_end=syscall_ptr_end,
169+
);
170+
}
171+
160172
if (selector == SHA256_PROCESS_BLOCK_SELECTOR) {
161173
execute_sha256_process_block();
162174
%{ OsLoggerExitSyscall %}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"os": "0x2a4b5650b64c1a13a4d2754353ddd85d4b970766063220253a4f96643ba23f6",
3-
"virtual_os": "0x39f55918423cade9e95a6a52286b56bed1c5c9b6fe39aa00301361457a3c604",
2+
"os": "0x3bd43ee8e972acc8afd825f8254a6e842884591bff817c3e2a7795577054da",
3+
"virtual_os": "0x542f701524219b8333d8a74a7eee00724673d53d1c78915e8f6d241e4ad81b9",
44
"aggregator": "0x700786d51b3854af43d8e12180380bda3029be6c1767e007858de6ca2edac40",
55
"aggregator_with_prefix": "0xe08d300e3f5996e43d6d7cc5a20068e0e58cf1309089f2348317ac580f6c1f"
66
}

crates/apollo_starknet_os_program/src/virtual_os_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn test_program_bytecode_lengths() {
2323
"#]]
2424
.assert_debug_eq(&OS_PROGRAM.data_len());
2525
expect![[r#"
26-
10261
26+
10717
2727
"#]]
2828
.assert_debug_eq(&VIRTUAL_OS_PROGRAM.data_len());
2929
}

crates/blockifier/resources/blockifier_versioned_constants_0_14_3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"os_constants": {
6969
"allowed_virtual_os_program_hashes": [
7070
"0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473",
71-
"0x39f55918423cade9e95a6a52286b56bed1c5c9b6fe39aa00301361457a3c604"
71+
"0x542f701524219b8333d8a74a7eee00724673d53d1c78915e8f6d241e4ad81b9"
7272
],
7373
"constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
7474
"default_entry_point_selector": "0x0",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
~ /enable_casm_hash_migration: true
2-
+ /os_constants/allowed_virtual_os_program_hashes/1: "0x39f55918423cade9e95a6a52286b56bed1c5c9b6fe39aa00301361457a3c604"
2+
+ /os_constants/allowed_virtual_os_program_hashes/1: "0x542f701524219b8333d8a74a7eee00724673d53d1c78915e8f6d241e4ad81b9"

crates/blockifier/src/bouncer_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,11 @@ fn class_hash_migration_data_from_state(
804804

805805
if should_migrate {
806806
expect![[r#"
807-
108608775
807+
108525874
808808
"#]]
809809
.assert_debug_eq(&migration_sierra_gas.0);
810810
expect![[r#"
811-
266780662
811+
266554526
812812
"#]]
813813
.assert_debug_eq(&migration_proving_gas.0);
814814
} else {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,8 +1411,7 @@ mod TestContract {
14111411

14121412
// Tests forbidden syscalls in virtual OS mode.
14131413
// Gets valid class_hash and contract_address from the current contract.
1414-
// syscall_selector should be one of: 'Deploy', 'GetBlockHash', 'Keccak', 'ReplaceClass',
1415-
// 'MetaTxV0'.
1414+
// syscall_selector should be one of: 'Deploy', 'GetBlockHash', 'ReplaceClass', 'MetaTxV0'.
14161415
#[external(v0)]
14171416
fn test_forbidden_syscall_in_virtual_mode(self: @ContractState, syscall_selector: felt252) {
14181417
let execution_info = get_execution_info().unbox();
@@ -1421,11 +1420,6 @@ mod TestContract {
14211420

14221421
if syscall_selector == 'GetBlockHash' {
14231422
syscalls::get_block_hash_syscall(0).unwrap_syscall();
1424-
} else if syscall_selector == 'Keccak' {
1425-
// Use the high-level keccak function which internally calls the keccak syscall.
1426-
let mut input: Array<u256> = Default::default();
1427-
input.append(u256 { low: 1, high: 0 });
1428-
keccak::keccak_u256s_le_inputs(input.span());
14291423
} else if syscall_selector == 'ReplaceClass' {
14301424
syscalls::replace_class_syscall(class_hash).unwrap_syscall();
14311425
} else if syscall_selector == 'Deploy' {

crates/starknet_os_flow_tests/src/virtual_os_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ async fn test_cairo0_contract_os_error() {
145145
#[rstest]
146146
#[case::deploy("Deploy")]
147147
#[case::get_block_hash("GetBlockHash")]
148-
#[case::keccak("Keccak")]
149148
#[case::replace_class("ReplaceClass")]
150149
#[case::meta_tx_v0("MetaTxV0")]
151150
#[tokio::test]

0 commit comments

Comments
 (0)