Skip to content

Commit

Permalink
chore: Refactor tail public inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant committed Jan 3, 2025
1 parent b9e7109 commit 58bbabc
Show file tree
Hide file tree
Showing 22 changed files with 197 additions and 378 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ impl TailOutputComposer {
output.rollup_validation_requests = source.validation_requests.for_rollup;
output.end = self.build_combined_accumulated_data();
output.gas_used = meter_gas_used(output.end);
output.constants =
CombinedConstantData::combine(source.constants, GlobalVariables::empty());
output.constants = source.constants;
output.fee_payer = source.fee_payer;
output
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use dep::types::{
side_effect::scoped::Scoped,
},
messaging::l2_to_l1_message::ScopedL2ToL1Message,
traits::{is_empty, is_empty_array},
utils::arrays::assert_exposed_sorted_transformed_value_array,
};
use tail_output_hints::{generate_tail_output_hints, TailOutputHints};
Expand Down Expand Up @@ -38,43 +37,13 @@ impl TailOutputValidator {
}

pub fn validate(self) {
self.validate_empty_values();
self.validate_propagated_values();
self.validate_propagated_sorted_values();
self.validate_gas_used();
}

fn validate_empty_values(self) {
assert(is_empty(self.output.start_state), "start_state must be empty");
assert_eq(self.output.revert_code, 0, "revert_code must be empty");
assert(
is_empty_array(self.output.end.unencrypted_logs_hashes),
"unencrypted logs in private must be empty",
);
}

fn validate_propagated_values(self) {
assert_eq(
self.output.constants.historical_header,
self.previous_kernel.constants.historical_header,
"mismatch historical_header",
);
assert_eq(
self.output.constants.tx_context,
self.previous_kernel.constants.tx_context,
"mismatch tx_context",
);
assert_eq(
self.output.constants.vk_tree_root,
self.previous_kernel.constants.vk_tree_root,
"mismatch vk_tree_root",
);
assert_eq(
self.output.constants.protocol_contract_tree_root,
self.previous_kernel.constants.protocol_contract_tree_root,
"mismatch protocol_contract_tree_root",
);
assert(is_empty(self.output.constants.global_variables), "global_variables must be empty");
assert_eq(self.output.constants, self.previous_kernel.constants, "mismatch constants");

assert_eq(
self.output.rollup_validation_requests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ mod tests {
messaging::l2_to_l1_message::ScopedL2ToL1Message,
point::Point,
tests::fixture_builder::FixtureBuilder,
traits::is_empty,
};
use dep::types::constants::{
DA_BYTES_PER_FIELD, DA_GAS_PER_BYTE, EMPTY_NESTED_INDEX, GENERATOR_INDEX__IVSK_M,
Expand Down Expand Up @@ -108,9 +107,7 @@ mod tests {
#[test]
fn execution_succeeded() {
let mut builder = PrivateKernelTailInputsBuilder::new();
let public_inputs = builder.execute();

assert(is_empty(public_inputs.start_state));
let _public_inputs = builder.execute();
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub(crate) mod base_or_merge_rollup_public_inputs;
pub(crate) mod block_root_or_block_merge_public_inputs;
pub(crate) mod previous_rollup_data;
pub(crate) mod previous_rollup_block_data;
pub(crate) mod tx_effect;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use types::{traits::Empty, abis::{log_hash::ScopedLogHash, private_log::PrivateLog, public_data_write::PublicDataWrite}, constants::{
MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PRIVATE_LOGS_PER_TX
}};

pub(crate) struct TxEffect {
pub(crate) revert_code: u8,
pub(crate) transaction_fee: Field,
pub(crate) note_hashes: [Field; MAX_NOTE_HASHES_PER_TX],
pub(crate) nullifiers: [Field; MAX_NULLIFIERS_PER_TX],
pub(crate) l2_to_l1_msgs: [Field; MAX_L2_TO_L1_MSGS_PER_TX],
pub(crate) public_data_writes: [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX],
pub(crate) private_logs: [PrivateLog; MAX_PRIVATE_LOGS_PER_TX],
pub(crate) unencrypted_log_preimages_length: Field,
pub(crate) unencrypted_logs_hashes: [ScopedLogHash; MAX_UNENCRYPTED_LOGS_PER_TX],
pub(crate) contract_class_log_preimages_length: Field,
pub(crate) contract_class_logs_hashes: [ScopedLogHash; MAX_CONTRACT_CLASS_LOGS_PER_TX],
}

impl Empty for TxEffect {
fn empty() -> Self {
TxEffect {
revert_code: 0,
transaction_fee: 0,
note_hashes: [0; MAX_NOTE_HASHES_PER_TX],
nullifiers: [0; MAX_NULLIFIERS_PER_TX],
l2_to_l1_msgs: [0; MAX_L2_TO_L1_MSGS_PER_TX],
public_data_writes: [PublicDataWrite::empty(); MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX],
private_logs: [PrivateLog::empty(); MAX_PRIVATE_LOGS_PER_TX],
unencrypted_log_preimages_length: 0,
unencrypted_logs_hashes: [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX],
contract_class_log_preimages_length: 0,
contract_class_logs_hashes: [ScopedLogHash::empty(); MAX_CONTRACT_CLASS_LOGS_PER_TX],
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use types::abis::{
combined_constant_data::CombinedConstantData, constant_rollup_data::ConstantRollupData,
tx_constant_data::TxConstantData, combined_constant_data::CombinedConstantData, constant_rollup_data::ConstantRollupData,
};

pub(crate) fn validate_combined_constant_data(
constants: CombinedConstantData,
rollup_constants: ConstantRollupData,
) {
// Verify the kernel chain_id and versions
assert(
constants.tx_context.chain_id == rollup_constants.global_variables.chain_id,
"kernel chain_id does not match the rollup chain_id",
Expand All @@ -24,11 +23,31 @@ pub(crate) fn validate_combined_constant_data(
"kernel protocol_contract_tree_root does not match the rollup protocol_contract_tree_root",
);

// Verify the kernel global variables if set, note these can be empty if this is a request coming directly from the private kernel tail.
// TODO(@spalladino) How can we check that this is a request coming from the private kernel tail?
assert(
constants.global_variables.is_empty()
| (constants.global_variables == rollup_constants.global_variables),
constants.global_variables == rollup_constants.global_variables,
"kernel global variables do not match the rollup global variables",
);
}

pub(crate) fn validate_tx_constant_data(
constants: TxConstantData,
rollup_constants: ConstantRollupData,
) {
assert(
constants.tx_context.chain_id == rollup_constants.global_variables.chain_id,
"kernel chain_id does not match the rollup chain_id",
);
assert(
constants.tx_context.version == rollup_constants.global_variables.version,
"kernel version does not match the rollup version",
);
assert(
constants.vk_tree_root == rollup_constants.vk_tree_root,
"kernel vk_tree_root does not match the rollup vk_tree_root",
);
assert(
constants.protocol_contract_tree_root == rollup_constants.protocol_contract_tree_root,
"kernel protocol_contract_tree_root does not match the rollup protocol_contract_tree_root",
);

}
Loading

0 comments on commit 58bbabc

Please sign in to comment.