Skip to content

Commit 2f0bb7a

Browse files
starknet_os: add proof virtual os output header
1 parent 36d3421 commit 2f0bb7a

File tree

10 files changed

+59
-16
lines changed

10 files changed

+59
-16
lines changed

crates/apollo_consensus_orchestrator/resources/central_invoke_tx_client_side_proving.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@
3535
"proof_facts": [
3636
"0x5649525455414c5f534e4f53",
3737
"0x4",
38+
"0x0",
3839
"0x7a0",
3940
"0x2fa80",
40-
"0x1"
41+
"0x1",
42+
"0x10",
43+
"0x0"
4144
],
4245
"type": "INVOKE_FUNCTION"
4346
},

crates/apollo_consensus_orchestrator/resources/central_preconfirmed_block.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@
6060
"proof_facts": [
6161
"0x5649525455414c5f534e4f53",
6262
"0x4",
63+
"0x0",
6364
"0x7a0",
6465
"0x2fa80",
65-
"0x1"
66+
"0x1",
67+
"0x10",
68+
"0x0"
6669
],
6770
"type":"INVOKE_FUNCTION"
6871
},

crates/apollo_http_server/resources/deprecated_gateway/invoke_tx_client_side_proving.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
"proof_facts": [
3030
"0x5649525455414c5f534e4f53",
3131
"0x4",
32+
"0x0",
3233
"0x7a0",
3334
"0x2fa80",
34-
"0x1"
35+
"0x1",
36+
"0x10",
37+
"0x0"
3538
],
3639
"proof": [
3740
1,

crates/apollo_starknet_client/resources/reader/invoke_v3_client_side_proving.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@
3535
"proof_facts": [
3636
"0x5649525455414c5f534e4f53",
3737
"0x4",
38+
"0x0",
3839
"0x7a0",
3940
"0x2fa80",
40-
"0x1"
41+
"0x1",
42+
"0x10",
43+
"0x0"
4144
]
4245
}

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ from starkware.cairo.common.bool import FALSE, TRUE
33
from starkware.cairo.common.cairo_builtins import EcOpBuiltin, PoseidonBuiltin
44
from starkware.cairo.common.dict_access import DictAccess
55
from starkware.cairo.common.memcpy import memcpy
6-
from starkware.cairo.common.serialize import serialize_word
76
from starkware.starknet.core.os.block_context import BlockContext, OsGlobalContext, VirtualOsConfig
87
from starkware.starknet.core.os.block_hash import get_block_hashes
98
from starkware.starknet.core.os.output import OsOutput, OsOutputHeader
109
from starkware.starknet.core.os.state.commitment import CommitmentUpdate
10+
from starkware.starknet.core.os.virtual_os_output import VirtualOsOutputHeader
1111

1212
const VIRTUAL_OS_OUTPUT_VERSION = 0;
1313

@@ -66,20 +66,28 @@ func process_os_output{
6666
assert n_blocks = 1;
6767
let os_output = os_outputs[0];
6868

69-
// Serialize the header.
69+
// Serialize the header using memcpy to enforce struct field order.
7070
let header = os_output.header;
71-
serialize_word(VIRTUAL_OS_OUTPUT_VERSION);
72-
serialize_word(header.prev_block_number);
73-
serialize_word(header.prev_block_hash);
74-
serialize_word(header.starknet_os_config_hash);
75-
serialize_word(os_global_context.virtual_os_config.authorized_account_address);
7671

7772
// TODO(Yoni): output the hash of the messages instead.
7873
let messages_to_l1_segment_size = (
7974
os_output.final_carried_outputs.messages_to_l1 -
8075
os_output.initial_carried_outputs.messages_to_l1
8176
);
82-
serialize_word(messages_to_l1_segment_size);
77+
78+
// Create the virtual OS output header.
79+
tempvar virtual_os_output_header = new VirtualOsOutputHeader(
80+
version=VIRTUAL_OS_OUTPUT_VERSION,
81+
prev_block_number=header.prev_block_number,
82+
prev_block_hash=header.prev_block_hash,
83+
starknet_os_config_hash=os_global_context.starknet_os_config_hash,
84+
authorized_account_address=os_global_context.virtual_os_config.authorized_account_address,
85+
messages_to_l1_segment_size=messages_to_l1_segment_size,
86+
);
87+
88+
// Copy the header to the output.
89+
memcpy(dst=output_ptr, src=virtual_os_output_header, len=VirtualOsOutputHeader.SIZE);
90+
let output_ptr = &output_ptr[VirtualOsOutputHeader.SIZE];
8391

8492
// Copy 'messages_to_l1_segment' to the correct place in the output segment.
8593
memcpy(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
struct VirtualOsOutputHeader {
2+
version: felt,
3+
prev_block_number: felt,
4+
prev_block_hash: felt,
5+
starknet_os_config_hash: felt,
6+
authorized_account_address: felt,
7+
messages_to_l1_segment_size: felt,
8+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"os": "0x1d1dc21f9e82e8dc91f1703d8544ae0aa6814b557aa85a87068bb79ecc0c649",
3-
"virtual_os": "0x4d734178c8a8415d26bd4623ee06b630d718f88a03d714fac0f89674b1f9cf0",
3+
"virtual_os": "0x68097237de5c60d6a971c768006d147913f44c5e48061a6cf8fae1765572411",
44
"aggregator": "0x63868c8dbf389119d95bae88b80043f5d237d3ddec072fb8f2095fcfacb9b1c",
55
"aggregator_with_prefix": "0xd892fd2fd978d8c2749a6678457ca99161f3d1822e4c3b8c03914817c6de1a"
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
@@ -22,7 +22,7 @@ fn test_program_bytecode_lengths() {
2222
"#]]
2323
.assert_debug_eq(&OS_PROGRAM.data_len());
2424
expect![[r#"
25-
11615
25+
11604
2626
"#]]
2727
.assert_debug_eq(&VIRTUAL_OS_PROGRAM.data_len());
2828
}

crates/starknet_api/src/test_utils.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ impl ProofFacts {
375375
/// See [`crate::transaction::fields::ProofFacts`].
376376
pub fn snos_proof_facts_for_testing() -> Self {
377377
let program_hash = felt!("0x4");
378+
let version = felt!("0x0");
378379
let block_hash_history_start = CURRENT_BLOCK_NUMBER - BLOCK_HASH_HISTORY_RANGE;
379380
let block_number = felt!(block_hash_history_start + 2);
380381
let block_hash = block_number * felt!(100_u64);
@@ -385,7 +386,20 @@ impl ProofFacts {
385386
);
386387
// TODO(AvivG): Change to valid values when available.
387388
let config_hash = felt!("0x1");
388-
proof_facts![felt!(VIRTUAL_SNOS), program_hash, block_number, block_hash, config_hash]
389+
// This fields are verified only by the contract but assumed as part of the proof facts in
390+
// the OS.
391+
let authorized_account_address = felt!("0x10");
392+
let messages_to_l1_segment_size = felt!("0x0");
393+
proof_facts![
394+
felt!(VIRTUAL_SNOS),
395+
program_hash,
396+
version,
397+
block_number,
398+
block_hash,
399+
config_hash,
400+
authorized_account_address,
401+
messages_to_l1_segment_size
402+
]
389403
}
390404
}
391405

crates/starknet_api/src/transaction/fields.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ impl TryFrom<&ProofFacts> for ProofFactsVariant {
662662
)));
663663
}
664664

665-
let [program_hash, block_number_felt, block_hash, config_hash, ..] = snos_fields else {
665+
let [program_hash, _version, block_number_felt, block_hash, config_hash, ..] = snos_fields
666+
else {
666667
return Err(StarknetApiError::InvalidProofFacts(format!(
667668
"SNOS proof facts must have at least 5 fields, got {}",
668669
proof_facts.0.len()

0 commit comments

Comments
 (0)