Skip to content

Commit d7be89f

Browse files
starknet_os: add proof virtual os output header
1 parent abacec2 commit d7be89f

File tree

11 files changed

+56
-17
lines changed

11 files changed

+56
-17
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
"0x130206a40921880628605041292e995870334451179c63090221210893986a2",
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
"0x130206a40921880628605041292e995870334451179c63090221210893986a2",
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
"0x130206a40921880628605041292e995870334451179c63090221210893986a2",
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
"0x130206a40921880628605041292e995870334451179c63090221210893986a2",
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+
base_block_number=header.prev_block_number,
82+
base_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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// The header of the virtual OS output.
2+
struct VirtualOsOutputHeader {
3+
version: felt,
4+
// The block number and hash that this run is based on.
5+
base_block_number: felt,
6+
base_block_hash: felt,
7+
starknet_os_config_hash: felt,
8+
// The account address that is authorized to run transactions.
9+
authorized_account_address: felt,
10+
messages_to_l1_segment_size: felt,
11+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"os": "0x24a4dbf1caa00186a70b56470ae920f7ce49fbd5b57263a279ebdb7a355f0ed",
3-
"virtual_os": "0x40693cd3a5ac9ba9ed620892170da34bb22ba9dbc5cc203ab1cc758de782495",
3+
"virtual_os": "0x7433ebe51a1de5b09532d2efa53b7a33658567ba7eef3a4743292a28e5a2ab2",
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-
11621
25+
11610
2626
"#]]
2727
.assert_debug_eq(&VIRTUAL_OS_PROGRAM.data_len());
2828
}

crates/starknet_api/src/rpc_transaction_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn test_invoke_tx_size_of() {
146146
// + tx_v3.proof.dynamic_size();
147147

148148
// Check the size of the V3 invoke transaction.
149-
assert_eq!(tx_v3.size_bytes(), 696);
149+
assert_eq!(tx_v3.size_bytes(), 792);
150150
} else {
151151
panic!("Expected RpcTransaction::Invoke");
152152
}

crates/starknet_api/src/test_utils.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ impl ProofFacts {
381381
///
382382
/// See [`crate::transaction::fields::ProofFacts`].
383383
pub fn snos_proof_facts_for_testing() -> Self {
384+
let version = Felt::ZERO;
384385
let block_hash_history_start = CURRENT_BLOCK_NUMBER - BLOCK_HASH_HISTORY_RANGE;
385386
let block_number = felt!(block_hash_history_start + 2);
386387
let block_hash = block_number * felt!(100_u64);
@@ -391,12 +392,18 @@ impl ProofFacts {
391392
);
392393
// TODO(AvivG): Change to valid values when available.
393394
let config_hash = felt!("0x1");
395+
// These fields are not verified by the OS (they are application-related).
396+
let authorized_account_address = felt!("0x10");
397+
let messages_to_l1_segment_size = Felt::ZERO;
394398
proof_facts![
395399
felt!(VIRTUAL_SNOS),
396400
VIRTUAL_OS_PROGRAM_HASH,
401+
version,
397402
block_number,
398403
block_hash,
399-
config_hash
404+
config_hash,
405+
authorized_account_address,
406+
messages_to_l1_segment_size
400407
]
401408
}
402409
}

0 commit comments

Comments
 (0)