Skip to content

Commit 2e1f541

Browse files
apollo_starknet_os_program,starknet_os: support PROOF_VERSION_V1 in check_proof_facts (#14014)
1 parent aeed81a commit 2e1f541

6 files changed

Lines changed: 22 additions & 13 deletions

File tree

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ from starkware.starknet.core.os.constants import (
1111
)
1212
from starkware.starknet.core.os.execution.syscall_impls import read_block_hash_from_storage
1313
from starkware.starknet.core.os.virtual_os_output import (
14-
PROOF_VERSION,
14+
PROOF_VERSION_V0,
15+
PROOF_VERSION_V1,
1516
VIRTUAL_OS_OUTPUT_VERSION,
1617
VIRTUAL_SNOS,
1718
ProofHeader,
@@ -46,14 +47,15 @@ func check_proof_facts{range_check_ptr, contract_state_changes: DictAccess*}(
4647
assert_le(ProofHeader.SIZE + VirtualOsOutputHeader.SIZE, proof_facts_size);
4748

4849
// Validate the proof header.
50+
static_assert ProofHeader.SIZE == 3;
4951
let proof_header = cast(proof_facts, ProofHeader*);
52+
assert proof_header.proof_variant = VIRTUAL_SNOS;
5053
assert is_program_hash_allowed(proof_header.program_hash) = TRUE;
51-
// Proof version and variant are for future compatibility.
52-
assert [proof_header] = ProofHeader(
53-
proof_version=PROOF_VERSION,
54-
proof_variant=VIRTUAL_SNOS,
55-
program_hash=proof_header.program_hash,
56-
);
54+
// Proof version may be V0 (legacy) or V1 (current).
55+
with_attr error_message("Unsupported proof version") {
56+
tempvar proof_version = proof_header.proof_version;
57+
assert (proof_version - PROOF_VERSION_V0) * (proof_version - PROOF_VERSION_V1) = 0;
58+
}
5759

5860
// Validate the virtual OS output header.
5961
let os_output_header = cast(&proof_facts[ProofHeader.SIZE], VirtualOsOutputHeader*);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
const VIRTUAL_SNOS = 'VIRTUAL_SNOS';
33

44
// Marker indicating proof facts format version 0.
5-
const PROOF_VERSION = 'PROOF0';
5+
const PROOF_VERSION_V0 = 'PROOF0';
6+
7+
// Marker indicating proof facts format version 1.
8+
const PROOF_VERSION_V1 = 'PROOF1';
69

710
// The version of the virtual OS output.
811
//

crates/apollo_starknet_os_program/src/program_hash.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"os": "0x10e4d1fd519f4675b021671fb866ec60fc0522f65273f587255414d0e5d5b23",
2+
"os": "0x2a4b5650b64c1a13a4d2754353ddd85d4b970766063220253a4f96643ba23f6",
33
"virtual_os": "0x39f55918423cade9e95a6a52286b56bed1c5c9b6fe39aa00301361457a3c604",
44
"aggregator": "0x700786d51b3854af43d8e12180380bda3029be6c1767e007858de6ca2edac40",
55
"aggregator_with_prefix": "0xe08d300e3f5996e43d6d7cc5a20068e0e58cf1309089f2348317ac580f6c1f"

crates/apollo_starknet_os_program/src/virtual_os_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn test_virtual_os_swapped_files() {
1919
#[test]
2020
fn test_program_bytecode_lengths() {
2121
expect![[r#"
22-
15660
22+
15663
2323
"#]]
2424
.assert_debug_eq(&OS_PROGRAM.data_len());
2525
expect![[r#"

crates/starknet_os/src/constants_test.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use starknet_api::core::{
1010
};
1111
use starknet_api::transaction::fields::{
1212
PROOF_VERSION_V0,
13+
PROOF_VERSION_V1,
1314
VIRTUAL_OS_OUTPUT_VERSION,
1415
VIRTUAL_SNOS,
1516
};
@@ -82,10 +83,12 @@ fn test_virtual_snos() {
8283
assert_eq!(Const::VirtualSnos.fetch_from_os_program().unwrap(), VIRTUAL_SNOS);
8384
}
8485

85-
/// Asserts that the Rust PROOF_VERSION_V0 constant matches the Cairo constant.
86+
/// Asserts that the Rust PROOF_VERSION_V0 and PROOF_VERSION_V1 constants match their Cairo
87+
/// counterparts.
8688
#[test]
8789
fn test_proof_version() {
88-
assert_eq!(Const::ProofVersion.fetch_from_os_program().unwrap(), PROOF_VERSION_V0);
90+
assert_eq!(Const::ProofVersionV0.fetch_from_os_program().unwrap(), PROOF_VERSION_V0);
91+
assert_eq!(Const::ProofVersionV1.fetch_from_os_program().unwrap(), PROOF_VERSION_V1);
8992
}
9093

9194
/// Asserts that the Rust STARKNET_OS_CONFIG_HASH_VERSION constant matches the Cairo constant.

crates/starknet_os/src/hints/vars.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ define_string_enum! {
369369
"starkware.starknet.core.os.virtual_os_output.VIRTUAL_OS_OUTPUT_VERSION"
370370
),
371371
(VirtualSnos, "starkware.starknet.core.os.virtual_os_output.VIRTUAL_SNOS"),
372-
(ProofVersion, "starkware.starknet.core.os.virtual_os_output.PROOF_VERSION"),
372+
(ProofVersionV0, "starkware.starknet.core.os.virtual_os_output.PROOF_VERSION_V0"),
373+
(ProofVersionV1, "starkware.starknet.core.os.virtual_os_output.PROOF_VERSION_V1"),
373374
}
374375
}
375376

0 commit comments

Comments
 (0)