Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func combine_blocks{range_check_ptr}(
starknet_os_config_hash=first.header.starknet_os_config_hash,
use_kzg_da=use_kzg_da,
full_output=full_output,
processed_proof_output_low=0,
processed_proof_output_high=0,
n_proof_facts_transactions=0,
),
squashed_os_state_update=first.squashed_os_state_update,
initial_carried_outputs=initial_carried_outputs,
Expand All @@ -98,6 +101,13 @@ func combine_blocks{range_check_ptr}(
let res = combine_blocks_inner(aggregated=aggregated, n=n - 1, os_outputs=&os_outputs[1]);
local res_state_update: SquashedOsStateUpdate = [res.squashed_os_state_update];

let (
local n_proof_facts_transactions,
local processed_proof_output_low,
local processed_proof_output_high,
) = combine_proof_facts_folds(n=n, os_outputs=os_outputs);
local res_header: OsOutputHeader* = res.header;

%{ SetStateUpdatePointersToNone %}

// Squash the contract state diff dict.
Expand All @@ -117,7 +127,20 @@ func combine_blocks{range_check_ptr}(
);

tempvar squashed_res = new OsOutput(
header=res.header,
header=new OsOutputHeader(
state_update_output=res_header.state_update_output,
prev_block_number=res_header.prev_block_number,
new_block_number=res_header.new_block_number,
prev_block_hash=res_header.prev_block_hash,
new_block_hash=res_header.new_block_hash,
os_program_hash=res_header.os_program_hash,
starknet_os_config_hash=res_header.starknet_os_config_hash,
use_kzg_da=res_header.use_kzg_da,
full_output=res_header.full_output,
processed_proof_output_low=processed_proof_output_low,
processed_proof_output_high=processed_proof_output_high,
n_proof_facts_transactions=n_proof_facts_transactions,
),
squashed_os_state_update=new SquashedOsStateUpdate(
contract_state_changes=squashed_contract_state_dict,
n_contract_state_changes=n_contract_state_changes,
Expand Down Expand Up @@ -146,7 +169,7 @@ func combine_blocks_inner(aggregated: OsOutput*, n: felt, os_outputs: OsOutput*)
// Check the size of `OsOutput` and `OsOutputHeader` to ensure that if new fields are added
// they are handled by the aggregator.
static_assert OsOutput.SIZE == 4;
static_assert OsOutputHeader.SIZE == 9;
static_assert OsOutputHeader.SIZE == 12;

// Validate fields of the inner OS output of a single task.
assert current_header.use_kzg_da = 0;
Expand Down Expand Up @@ -192,6 +215,9 @@ func combine_blocks_inner(aggregated: OsOutput*, n: felt, os_outputs: OsOutput*)
starknet_os_config_hash=aggregated_header.starknet_os_config_hash,
use_kzg_da=aggregated_header.use_kzg_da,
full_output=aggregated_header.full_output,
processed_proof_output_low=0,
processed_proof_output_high=0,
n_proof_facts_transactions=0,
),
squashed_os_state_update=new SquashedOsStateUpdate(
contract_state_changes=aggregated_update.contract_state_changes,
Expand All @@ -207,3 +233,35 @@ func combine_blocks_inner(aggregated: OsOutput*, n: felt, os_outputs: OsOutput*)

return combine_blocks_inner(aggregated=new_aggregated, n=n - 1, os_outputs=&os_outputs[1]);
}

func combine_proof_facts_folds(n: felt, os_outputs: OsOutput*) -> (
n_proof_facts_transactions: felt, root_output_low: felt, root_output_high: felt
) {
alloc_locals;
let (
local n_proof_facts_transactions, local root_output_low, local root_output_high
) = sum_block_proof_facts_outputs(n=n, os_outputs=os_outputs);
assert n_proof_facts_transactions * (n_proof_facts_transactions - 1) = 0;
return (
n_proof_facts_transactions=n_proof_facts_transactions,
root_output_low=root_output_low,
root_output_high=root_output_high,
);
}

func sum_block_proof_facts_outputs(n: felt, os_outputs: OsOutput*) -> (
n_proof_facts_transactions: felt, root_output_low: felt, root_output_high: felt
) {
if (n == 0) {
return (n_proof_facts_transactions=0, root_output_low=0, root_output_high=0);
}
let (
rest_n_transactions, rest_root_output_low, rest_root_output_high
) = sum_block_proof_facts_outputs(n=n - 1, os_outputs=&os_outputs[1]);
let header = os_outputs[0].header;
return (
n_proof_facts_transactions=rest_n_transactions + header.n_proof_facts_transactions,
root_output_low=rest_root_output_low + header.processed_proof_output_low,
root_output_high=rest_root_output_high + header.processed_proof_output_high,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const STORED_BLOCK_HASH_BUFFER = 10;

// Allowed virtual OS program hashes for client-side proving.
const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_0 = (
0x053f6c9fcfd31d27279ff7d7e422b44623550a732b59fe193354a7316a96daa1
0x07dc1bd0f3938f5f2f5e7c14118402cd79f2867419dccd484532651dda9a36a4
);
const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_1 = (
0x01c7be3225dfb33359b3ba9ffbe1542b7da27879b6d89f47b967e512463fd324
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ from starkware.starknet.core.os.execution.execute_transactions_inner import (
execute_transactions_inner,
)
from starkware.starknet.core.os.output import OsCarriedOutputs
from starkware.starknet.core.os.proof_fact_fold import ProofFactsReference

// Executes the transactions in the hint variable block_input.transactions.
//
Expand All @@ -49,6 +50,7 @@ func execute_transactions{
contract_state_changes: DictAccess*,
contract_class_changes: DictAccess*,
outputs: OsCarriedOutputs*,
proof_facts_references: ProofFactsReference*,
txs_range_check_ptr,
}(block_context: BlockContext*) {
alloc_locals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from starkware.starknet.core.os.execution.transaction_impls import (
execute_l1_handler_transaction,
)
from starkware.starknet.core.os.output import OsCarriedOutputs
from starkware.starknet.core.os.proof_fact_fold import ProofFactsReference

// Inner function for execute_transactions.
// Arguments:
Expand All @@ -26,6 +27,7 @@ func execute_transactions_inner{
contract_state_changes: DictAccess*,
contract_class_changes: DictAccess*,
outputs: OsCarriedOutputs*,
proof_facts_references: ProofFactsReference*,
}(block_context: BlockContext*, n_txs) {
%{ LogRemainingTxs %}
if (n_txs == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from starkware.starknet.core.os.execution.transaction_impls import (
execute_invoke_function_transaction,
)
from starkware.starknet.core.os.output import OsCarriedOutputs
from starkware.starknet.core.os.proof_fact_fold import ProofFactsReference

// In virtual OS mode, we only support a single INVOKE_FUNCTION transaction.
func execute_transactions_inner{
Expand All @@ -15,6 +16,7 @@ func execute_transactions_inner{
contract_state_changes: DictAccess*,
contract_class_changes: DictAccess*,
outputs: OsCarriedOutputs*,
proof_facts_references: ProofFactsReference*,
}(block_context: BlockContext*, n_txs) {
// Part of the VIRTUAL_SNOS0 version contract. Changes must trigger a version bump.
with_attr error_message("Expected exactly one transaction") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ from starkware.starknet.core.os.output import (
OsCarriedOutputs,
os_carried_outputs_new,
)
from starkware.starknet.core.os.proof_fact_fold import (
ProofFactsReference,
record_proof_facts_reference,
)
from starkware.starknet.core.os.state.commitment import StateEntry
from starkware.starknet.core.os.transaction_hash.transaction_hash import (
CommonTxFields,
Expand Down Expand Up @@ -254,6 +258,7 @@ func execute_invoke_function_transaction{
contract_state_changes: DictAccess*,
contract_class_changes: DictAccess*,
outputs: OsCarriedOutputs*,
proof_facts_references: ProofFactsReference*,
}(block_context: BlockContext*) {
alloc_locals;

Expand Down Expand Up @@ -362,6 +367,8 @@ func execute_invoke_function_transaction{

%{ EndTx %}

record_proof_facts_reference(proof_facts_size=proof_facts_size, proof_facts=proof_facts);

return ();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ from starkware.starknet.core.os.output import (
OsCarriedOutputs,
OsOutput,
)
from starkware.starknet.core.os.proof_fact_fold import (
ProofFactsReference,
single_processed_proof_output,
)
from starkware.starknet.core.os.state.state import OsStateUpdate, state_update

// The main entry point of the Starknet OS.
Expand Down Expand Up @@ -219,12 +223,24 @@ func execute_blocks{
}

// Execute transactions.
let (proof_facts_references_start: ProofFactsReference*) = alloc();
let outputs = initial_carried_outputs;
with contract_state_changes, contract_class_changes, outputs {
let proof_facts_references = proof_facts_references_start;
with contract_state_changes, contract_class_changes, outputs, proof_facts_references {
execute_transactions(block_context=block_context);
}
let final_carried_outputs = outputs;

let (
n_proof_facts_transactions, processed_proof_output_low, processed_proof_output_high
) = single_processed_proof_output(
proof_facts_references_start=proof_facts_references_start,
proof_facts_references_end=proof_facts_references,
);
local n_proof_facts_transactions = n_proof_facts_transactions;
local processed_proof_output_low = processed_proof_output_low;
local processed_proof_output_high = processed_proof_output_high;

// Update the state.
%{ EnterScopeWithAliases %}
let (squashed_os_state_update, state_update_output) = state_update{hash_ptr=pedersen_ptr}(
Expand All @@ -243,6 +259,9 @@ func execute_blocks{
block_context=block_context,
state_update_output=state_update_output,
os_global_context=os_global_context,
n_proof_facts_transactions=n_proof_facts_transactions,
processed_proof_output_low=processed_proof_output_low,
processed_proof_output_high=processed_proof_output_high,
);
assert os_output_per_block_dst[0] = OsOutput(
header=os_output_header,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func get_block_os_output_header{poseidon_ptr: PoseidonBuiltin*}(
block_context: BlockContext*,
state_update_output: CommitmentUpdate*,
os_global_context: OsGlobalContext*,
n_proof_facts_transactions: felt,
processed_proof_output_low: felt,
processed_proof_output_high: felt,
) -> OsOutputHeader* {
// Calculate the block hash based on the block info and state root.
// NOTE: both the previous block hash and previous state root are guessed, and the OS
Expand All @@ -145,6 +148,9 @@ func get_block_os_output_header{poseidon_ptr: PoseidonBuiltin*}(
starknet_os_config_hash=os_global_context.starknet_os_config_hash,
use_kzg_da=FALSE,
full_output=TRUE,
processed_proof_output_low=processed_proof_output_low,
processed_proof_output_high=processed_proof_output_high,
n_proof_facts_transactions=n_proof_facts_transactions,
);
return os_output_header;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func get_block_os_output_header{poseidon_ptr: PoseidonBuiltin*}(
block_context: BlockContext*,
state_update_output: CommitmentUpdate*,
os_global_context: OsGlobalContext*,
n_proof_facts_transactions: felt,
processed_proof_output_low: felt,
processed_proof_output_high: felt,
) -> OsOutputHeader* {
assert n_proof_facts_transactions = 0;
// Calculate the previous block hash based on the block info and the **initial** state root.
let (_prev_prev_block_hash, prev_block_hash) = get_block_hashes{poseidon_ptr=poseidon_ptr}(
block_info=block_context.block_info_for_execute, state_root=state_update_output.initial_root
Expand All @@ -68,6 +72,9 @@ func get_block_os_output_header{poseidon_ptr: PoseidonBuiltin*}(
starknet_os_config_hash=os_global_context.starknet_os_config_hash,
use_kzg_da=FALSE,
full_output=TRUE,
processed_proof_output_low=0,
processed_proof_output_high=0,
n_proof_facts_transactions=0,
);
return os_output_header;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ struct OsOutputHeader {
use_kzg_da: felt,
// Indicates whether previous state values are included in the state update information.
full_output: felt,
processed_proof_output_low: felt,
processed_proof_output_high: felt,
n_proof_facts_transactions: felt,
}

// An L2 to L1 message header, the message payload is concatenated to the end of the header.
Expand Down Expand Up @@ -168,6 +171,9 @@ func serialize_output_header{output_ptr: felt*}(os_output_header: OsOutputHeader
serialize_word(os_output_header.starknet_os_config_hash);
serialize_word(os_output_header.use_kzg_da);
serialize_word(os_output_header.full_output);
serialize_word(os_output_header.processed_proof_output_low);
serialize_word(os_output_header.processed_proof_output_high);
serialize_word(os_output_header.n_proof_facts_transactions);

return ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,57 @@ from starkware.cairo.common.registers import get_label_location
const BLAKE2S_DIGEST_N_WORDS = 8;
const PROOF_ENTRY_N_WORDS = 2 * BLAKE2S_DIGEST_N_WORDS;

struct ProofFactsReference {
proof_facts_size: felt,
proof_facts: felt*,
}

func record_proof_facts_reference{proof_facts_references: ProofFactsReference*}(
proof_facts_size: felt, proof_facts: felt*
) {
if (proof_facts_size == 0) {
return ();
}
assert [proof_facts_references] = ProofFactsReference(
proof_facts_size=proof_facts_size, proof_facts=proof_facts
);
let proof_facts_references = &proof_facts_references[1];
return ();
}

func single_processed_proof_output{range_check_ptr}(
proof_facts_references_start: ProofFactsReference*,
proof_facts_references_end: ProofFactsReference*,
) -> (
n_proof_facts_transactions: felt,
processed_proof_output_low: felt,
processed_proof_output_high: felt,
) {
alloc_locals;
local n_proof_facts_transactions = (proof_facts_references_end - proof_facts_references_start) /
ProofFactsReference.SIZE;
if (n_proof_facts_transactions == 0) {
return (
n_proof_facts_transactions=0,
processed_proof_output_low=0,
processed_proof_output_high=0,
);
}
assert n_proof_facts_transactions = 1;
let (output_digest) = compute_processed_proof_output_digest(
proof_facts_size=proof_facts_references_start.proof_facts_size,
proof_facts=proof_facts_references_start.proof_facts,
);
let (processed_proof_output_low, processed_proof_output_high) = pack_output_digest(
output_digest=output_digest
);
return (
n_proof_facts_transactions=1,
processed_proof_output_low=processed_proof_output_low,
processed_proof_output_high=processed_proof_output_high,
);
}

func compute_processed_proof_output_digest{range_check_ptr}(
proof_facts_size: felt, proof_facts: felt*
) -> (output_digest: felt*) {
Expand Down
8 changes: 4 additions & 4 deletions crates/apollo_starknet_os_program/src/program_hash.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"os": "0x1420d23187254d4dcf4006fa6ad997b0728f845416bcfd1478c7e8f804fb429",
"virtual_os": "0x1c7be3225dfb33359b3ba9ffbe1542b7da27879b6d89f47b967e512463fd324",
"aggregator": "0x3e4ce8340259e374200ed856e597a0c0b268d1021119d33573d7c759c5320f9",
"aggregator_with_prefix": "0x2526c12112a2d7f57f7ae74af7be1fe1b2766e4c34b0c88ceda16b70ed2d6c2"
"os": "0x3932c2db6cc720a69e8932bf62e07d90263ae1c2308ef68a096a7cb081bdd13",
"virtual_os": "0x7dc1bd0f3938f5f2f5e7c14118402cd79f2867419dccd484532651dda9a36a4",
"aggregator": "0x38b41528311efc46b895d4326121ebe25042cb694deabc4ec461b1653b89fc0",
"aggregator_with_prefix": "0x1015fe136b9f9ba7728018f2b4d40edb1ebe1dbccbcb8524b543640f8f1e724"
}
4 changes: 2 additions & 2 deletions crates/apollo_starknet_os_program/src/virtual_os_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ fn test_virtual_os_swapped_files() {
#[test]
fn test_program_bytecode_lengths() {
expect![[r#"
16376
16663
"#]]
.assert_debug_eq(&OS_PROGRAM.data_len());
expect![[r#"
11426
11626
"#]]
.assert_debug_eq(&VIRTUAL_OS_PROGRAM.data_len());
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"segment_arena_cells": false,
"os_constants": {
"allowed_virtual_os_program_hashes": [
"0x53f6c9fcfd31d27279ff7d7e422b44623550a732b59fe193354a7316a96daa1",
"0x7dc1bd0f3938f5f2f5e7c14118402cd79f2867419dccd484532651dda9a36a4",
"0x1c7be3225dfb33359b3ba9ffbe1542b7da27879b6d89f47b967e512463fd324"
],
"allowed_proof_versions": [
Expand Down Expand Up @@ -536,7 +536,7 @@
},
"InvokeFunction": {
"constant": {
"n_steps": 4779,
"n_steps": 4794,
"n_memory_holes": 0,
"builtin_instance_counter": {
"range_check_builtin": 110,
Expand Down
Loading