Skip to content

Commit d72bed0

Browse files
apollo_starknet_os_program,starknet_os: support PROOF_VERSION_V1 in check_proof_facts
1 parent 90c0ffc commit d72bed0

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
@@ -10,7 +10,8 @@ from starkware.starknet.core.os.constants import (
1010
)
1111
from starkware.starknet.core.os.execution.syscall_impls import read_block_hash_from_storage
1212
from starkware.starknet.core.os.virtual_os_output import (
13-
PROOF_VERSION,
13+
PROOF_VERSION_V0,
14+
PROOF_VERSION_V1,
1415
VIRTUAL_OS_OUTPUT_VERSION,
1516
VIRTUAL_SNOS,
1617
ProofHeader,
@@ -44,14 +45,15 @@ func check_proof_facts{range_check_ptr, contract_state_changes: DictAccess*}(
4445
assert_le(ProofHeader.SIZE + VirtualOsOutputHeader.SIZE, proof_facts_size);
4546

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

5658
// Validate the virtual OS output header.
5759
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": "0xb0134eed363da4094afca019a74939b4c17f238a4f7411798813f55905cd7",
2+
"os": "0x4f1294d5ec8c98bfb01a26af215a8d15f5f3530bb7bac8342ee72334ebcec6d",
33
"virtual_os": "0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473",
44
"aggregator": "0x43666b81f964bcdedf0098d2791b061d61f3098ff1429a754d0b97eeeae9489",
55
"aggregator_with_prefix": "0x68072c8f5ff5ae133060e12cfad3a38362dbb6d667abd4f7e1fac6f37febe46"

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-
15610
22+
15613
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)