From 250a23de57756ab66a42beabbfec3d4e331c56e5 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Fri, 3 Jan 2025 14:47:33 +0000 Subject: [PATCH] fixes --- .../src/components/tail_output_validator.nr | 21 +++++++- .../tail_output_validator_builder/mod.nr | 1 - .../validate_empty_values.nr | 35 -------------- .../validate_propagated_values.nr | 10 ---- .../crates/rollup-lib/src/abis/mod.nr | 2 +- .../crates/rollup-lib/src/abis/tx_effect.nr | 18 +++++-- .../src/base/components/constants.nr | 4 +- .../src/base/private_base_rollup.nr | 48 ++++++++----------- .../rollup-lib/src/base/public_base_rollup.nr | 34 ++++++------- .../crates/rollup-lib/src/components.nr | 12 ++--- .../kernel_circuit_public_inputs.nr | 6 +-- 11 files changed, 82 insertions(+), 109 deletions(-) delete mode 100644 noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_empty_values.nr diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator.nr index 543802a374a..437cd4465b4 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator.nr @@ -43,7 +43,26 @@ impl TailOutputValidator { } fn validate_propagated_values(self) { - assert_eq(self.output.constants, self.previous_kernel.constants, "mismatch constants"); + 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_eq( self.output.rollup_validation_requests, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/mod.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/mod.nr index e147656197e..fb0e57272c9 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/mod.nr @@ -1,4 +1,3 @@ -mod validate_empty_values; mod validate_gas_used; mod validate_propagated_sorted_values; mod validate_propagated_values; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_empty_values.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_empty_values.nr deleted file mode 100644 index 2e4be7bed2f..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_empty_values.nr +++ /dev/null @@ -1,35 +0,0 @@ -use crate::tests::tail_output_validator_builder::TailOutputValidatorBuilder; - -#[test] -fn validate_empty_values_succeeds() { - let builder = TailOutputValidatorBuilder::new(); - builder.validate(); -} - -#[test(should_fail_with = "start_state must be empty")] -fn validate_empty_values_non_empty_start_state_fails() { - let mut builder = TailOutputValidatorBuilder::new(); - - builder.output.start_state.public_data_tree.root = 123; - - builder.validate(); -} - -#[test(should_fail_with = "revert_code must be empty")] -fn validate_empty_values_non_empty_revert_code_fails() { - let mut builder = TailOutputValidatorBuilder::new(); - - builder.output.revert_code = 1; - - builder.validate(); -} - -#[test(should_fail_with = "unencrypted logs in private must be empty")] -fn validate_empty_values_non_empty_unencrypted_log_fails() { - let mut builder = TailOutputValidatorBuilder::new(); - - builder.output.add_unencrypted_log_hash(1, 2); - - builder.validate(); -} - diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_values.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_values.nr index 27d59065348..81d47398929 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_values.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_values.nr @@ -58,16 +58,6 @@ fn validate_propagated_values_protocol_contract_tree_root_mismatch_fails() { builder.validate(); } -#[test(should_fail_with = "global_variables must be empty")] -fn validate_propagated_values_global_variables_non_empty_fails() { - let mut builder = TailOutputValidatorBuilder::new(); - - // Tweak the value in the output. - builder.output.global_variables.chain_id = 1; - - builder.validate(); -} - /** * max_block_number */ diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/mod.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/mod.nr index 7f61fdfaa04..09dbeaf35d4 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/mod.nr @@ -2,4 +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; \ No newline at end of file +pub(crate) mod tx_effect; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/tx_effect.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/tx_effect.nr index d17797d9123..54fcf722f76 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/tx_effect.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/tx_effect.nr @@ -1,6 +1,12 @@ -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 -}}; +use types::{ + abis::{log_hash::ScopedLogHash, private_log::PrivateLog, public_data_write::PublicDataWrite}, + constants::{ + MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, + MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX, + MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, + }, + traits::Empty, +}; pub(crate) struct TxEffect { pub(crate) revert_code: u8, @@ -24,7 +30,9 @@ impl Empty for TxEffect { 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], + 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], @@ -32,4 +40,4 @@ impl Empty for TxEffect { contract_class_logs_hashes: [ScopedLogHash::empty(); MAX_CONTRACT_CLASS_LOGS_PER_TX], } } -} \ No newline at end of file +} diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/constants.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/constants.nr index 4b2d262ba13..8d7f2c9b80c 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/constants.nr @@ -1,5 +1,6 @@ use types::abis::{ - tx_constant_data::TxConstantData, combined_constant_data::CombinedConstantData, constant_rollup_data::ConstantRollupData, + combined_constant_data::CombinedConstantData, constant_rollup_data::ConstantRollupData, + tx_constant_data::TxConstantData, }; pub(crate) fn validate_combined_constant_data( @@ -49,5 +50,4 @@ pub(crate) fn validate_tx_constant_data( 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", ); - } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/private_base_rollup.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/private_base_rollup.nr index 2bd1ef345f6..824a3977308 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/private_base_rollup.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/private_base_rollup.nr @@ -1,5 +1,8 @@ use crate::{ - abis::tx_effect::TxEffect, abis::base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs}, + abis::{ + base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs}, + tx_effect::TxEffect, + }, base::{ components::{ archive::perform_archive_membership_check, @@ -12,15 +15,16 @@ use crate::{ }, components::{append_tx_effects_for_blob, compute_kernel_out_hash}, }; +use super::components::constants::validate_tx_constant_data; use dep::types::{ abis::{ - log_hash::ScopedLogHash, append_only_tree_snapshot::AppendOnlyTreeSnapshot, constant_rollup_data::ConstantRollupData, - nullifier_leaf_preimage::NullifierLeafPreimage, public_data_write::PublicDataWrite, - sponge_blob::SpongeBlob, tube::PrivateTubeData, + append_only_tree_snapshot::AppendOnlyTreeSnapshot, constant_rollup_data::ConstantRollupData, + log_hash::ScopedLogHash, nullifier_leaf_preimage::NullifierLeafPreimage, + public_data_write::PublicDataWrite, sponge_blob::SpongeBlob, tube::PrivateTubeData, }, constants::{ - ARCHIVE_HEIGHT, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NOTE_HASH_SUBTREE_HEIGHT, - TUBE_VK_INDEX,MAX_UNENCRYPTED_LOGS_PER_TX + ARCHIVE_HEIGHT, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, + NOTE_HASH_SUBTREE_HEIGHT, TUBE_VK_INDEX, }, data::{hash::compute_public_data_tree_value, public_data_hint::PublicDataHint}, hash::silo_l2_to_l1_message, @@ -30,7 +34,6 @@ use dep::types::{ messaging::l2_to_l1_message::ScopedL2ToL1Message, partial_state_reference::PartialStateReference, }; -use super::components::constants::validate_tx_constant_data; global ALLOWED_PREVIOUS_CIRCUITS: [u32; 1] = [TUBE_VK_INDEX]; @@ -123,13 +126,14 @@ impl PrivateBaseRollupInputs { private_logs: self.tube_data.public_inputs.end.private_logs, unencrypted_log_preimages_length: 0, unencrypted_logs_hashes: [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX], - contract_class_log_preimages_length: self.tube_data.public_inputs.end.contract_class_log_preimages_length, + contract_class_log_preimages_length: self + .tube_data + .public_inputs + .end + .contract_class_log_preimages_length, contract_class_logs_hashes: self.tube_data.public_inputs.end.contract_class_logs_hashes, }; - let end_sponge_blob = append_tx_effects_for_blob( - tx_effect, - self.start_sponge_blob, - ); + let end_sponge_blob = append_tx_effects_for_blob(tx_effect, self.start_sponge_blob); // Perform membership checks that the notes provided exist within the historical trees data perform_archive_membership_check( @@ -225,6 +229,7 @@ mod tests { append_tx_effects_for_blob, encode_blob_prefix, TX_EFFECTS_BLOB_HASH_INPUT_FIELDS, }, }; + use crate::abis::tx_effect::TxEffect; use dep::types::{ abis::{ append_only_tree_snapshot::AppendOnlyTreeSnapshot, @@ -260,7 +265,6 @@ mod tests { field::{field_from_bytes, full_field_less_than}, }, }; - use crate::abis::tx_effect::TxEffect; struct NullifierInsertion { existing_index: u32, @@ -386,9 +390,7 @@ mod tests { gas_used.compute_fee(gas_fees) } - fn build_pre_existing_tx_effects( - self, - ) -> TxEffect { + fn build_pre_existing_tx_effects(self) -> TxEffect { let mut res = TxEffect::empty(); res.note_hashes = self.pre_existing_notes; res.nullifiers = self.pre_existing_nullifiers.map(|nullifier: NullifierLeafPreimage| { @@ -573,9 +575,7 @@ mod tests { public_data_tree: start_public_data_tree_snapshot, }; - let pre_existing_tx_effects = - self.build_pre_existing_tx_effects(); - + let pre_existing_tx_effects = self.build_pre_existing_tx_effects(); let start_sponge_blob = append_tx_effects_for_blob( pre_existing_tx_effects, @@ -962,15 +962,7 @@ mod tests { reconstructed_tx_effects[0] = field_from_bytes( array_concat( TX_START_PREFIX.to_be_bytes::<8>(), - [ - 0, - length_bytes[0], - length_bytes[1], - 0, - REVERT_CODE_PREFIX, - 0, - 0, - ], + [0, length_bytes[0], length_bytes[1], 0, REVERT_CODE_PREFIX, 0, 0], ), true, ); diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr index b75edfe2140..1ecfc2bb0a7 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr @@ -1,5 +1,8 @@ use crate::{ - abis::tx_effect::TxEffect, abis::base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs}, + abis::{ + base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs}, + tx_effect::TxEffect, + }, base::{ components::{ archive::perform_archive_membership_check, constants::validate_combined_constant_data, @@ -50,7 +53,11 @@ pub struct PublicBaseRollupInputs { } impl PublicBaseRollupInputs { - fn generate_tx_effect(self, reverted: bool, combined_constant_data: CombinedConstantData) -> TxEffect { + fn generate_tx_effect( + self, + reverted: bool, + combined_constant_data: CombinedConstantData, + ) -> TxEffect { let from_private = self.tube_data.public_inputs; let from_public = self.avm_proof_data.public_inputs; let revert_code = if reverted { 1 } else { 0 }; @@ -90,12 +97,12 @@ impl PublicBaseRollupInputs { transaction_fee: from_public.transaction_fee, note_hashes: from_public.accumulated_data.note_hashes, nullifiers: from_public.accumulated_data.nullifiers, - l2_to_l1_msgs:siloed_l2_to_l1_msgs , + l2_to_l1_msgs: siloed_l2_to_l1_msgs, public_data_writes: from_public.accumulated_data.public_data_writes, private_logs, unencrypted_logs_hashes: from_public.accumulated_data.unencrypted_logs_hashes, - unencrypted_log_preimages_length, - contract_class_log_preimages_length, + unencrypted_log_preimages_length, + contract_class_log_preimages_length, contract_class_logs_hashes, } } @@ -140,8 +147,7 @@ impl PublicBaseRollupInputs { let tx_effect = self.generate_tx_effect(reverted, combined_constant_data); - let commitments_tree_subroot = - calculate_subtree_root(tx_effect.note_hashes); + let commitments_tree_subroot = calculate_subtree_root(tx_effect.note_hashes); let empty_commitments_subtree_root = calculate_empty_tree_root(NOTE_HASH_SUBTREE_HEIGHT); @@ -164,10 +170,7 @@ impl PublicBaseRollupInputs { let out_hash = compute_kernel_out_hash(tx_effect.l2_to_l1_msgs); - let end_sponge_blob = append_tx_effects_for_blob( - tx_effect, - self.start_sponge_blob, - ); + let end_sponge_blob = append_tx_effects_for_blob(tx_effect, self.start_sponge_blob); // Perform membership checks that the notes provided exist within the historical trees data perform_archive_membership_check( @@ -284,6 +287,7 @@ mod tests { append_tx_effects_for_blob, encode_blob_prefix, TX_EFFECTS_BLOB_HASH_INPUT_FIELDS, }, }; + use crate::abis::tx_effect::TxEffect; use dep::types::{ abis::{ accumulated_data::CombinedAccumulatedData, @@ -321,7 +325,6 @@ mod tests { field::{field_from_bytes, full_field_less_than}, }, }; - use crate::abis::tx_effect::TxEffect; struct NullifierInsertion { existing_index: u32, @@ -436,9 +439,7 @@ mod tests { builder } - fn build_pre_existing_tx_effects( - self, - ) -> TxEffect { + fn build_pre_existing_tx_effects(self) -> TxEffect { let mut res = TxEffect::empty(); res.note_hashes = self.pre_existing_notes; res.nullifiers = self.pre_existing_nullifiers.map(|nullifier: NullifierLeafPreimage| { @@ -673,8 +674,7 @@ mod tests { public_data_tree: start_public_data_tree_snapshot, }; - let tx_effect = - self.build_pre_existing_tx_effects(); + let tx_effect = self.build_pre_existing_tx_effects(); let start_sponge_blob = append_tx_effects_for_blob( tx_effect, diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/components.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/components.nr index 6232e4a7316..80009fc83a9 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/components.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/components.nr @@ -4,11 +4,9 @@ use crate::abis::{ previous_rollup_block_data::PreviousRollupBlockData, previous_rollup_data::PreviousRollupData, }; +use super::abis::tx_effect::TxEffect; use dep::types::{ - abis::{ - log_hash::ScopedLogHash, - public_data_write::PublicDataWrite, sponge_blob::SpongeBlob, - }, + abis::{log_hash::ScopedLogHash, public_data_write::PublicDataWrite, sponge_blob::SpongeBlob}, constants::{ AZTEC_MAX_EPOCH_DURATION, CONTRACT_CLASS_LOGS_PREFIX, L2_L1_MSGS_PREFIX, MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, @@ -24,7 +22,6 @@ use dep::types::{ utils::{arrays::{array_concat, array_length, array_merge}, field::field_from_bytes}, }; use blob::blob_public_inputs::BlockBlobPublicInputs; -use super::abis::tx_effect::TxEffect; /** * Asserts that the tree formed by rollup circuits is filled greedily from L to R @@ -302,7 +299,10 @@ pub(crate) fn append_tx_effects_for_blob( // TX FEE // Using 29 bytes to encompass all reasonable fee lengths tx_effects_hash_input[offset] = field_from_bytes( - array_concat([TX_FEE_PREFIX, 0], tx_effect.transaction_fee.to_be_bytes::<29>()), + array_concat( + [TX_FEE_PREFIX, 0], + tx_effect.transaction_fee.to_be_bytes::<29>(), + ), true, ); offset += 1; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr index a1943eb190c..e0b8999c963 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr @@ -1,7 +1,7 @@ use crate::{ - abis::tx_constant_data::TxConstantData, abis::{ - accumulated_data::CombinedAccumulatedData, - gas::Gas, validation_requests::RollupValidationRequests, + abis::{ + accumulated_data::CombinedAccumulatedData, gas::Gas, tx_constant_data::TxConstantData, + validation_requests::RollupValidationRequests, }, address::AztecAddress, constants::KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH,