From 58bbabc2e0b6e656291997bed7fed863735ddd55 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Fri, 3 Jan 2025 14:25:42 +0000 Subject: [PATCH 01/29] chore: Refactor tail public inputs --- .../src/components/tail_output_composer.nr | 3 +- .../src/components/tail_output_validator.nr | 33 +---- .../src/private_kernel_tail.nr | 5 +- .../crates/rollup-lib/src/abis/mod.nr | 1 + .../crates/rollup-lib/src/abis/tx_effect.nr | 35 +++++ .../src/base/components/constants.nr | 31 ++++- .../src/base/private_base_rollup.nr | 130 +++++++----------- .../rollup-lib/src/base/public_base_rollup.nr | 77 +++++------ .../crates/rollup-lib/src/components.nr | 33 +++-- .../crates/rollup-lib/src/lib.nr | 16 +-- .../combined_accumulated_data.nr | 32 +---- .../kernel_circuit_public_inputs.nr | 22 +-- .../crates/types/src/constants.nr | 10 +- .../crates/types/src/tests/fixture_builder.nr | 9 +- .../circuit-types/src/test/factories.ts | 3 - .../circuit-types/src/tx/processed_tx.ts | 2 +- .../kernel/combined_accumulated_data.ts | 39 +----- .../kernel/kernel_circuit_public_inputs.ts | 29 +--- ...ivate_kernel_tail_circuit_public_inputs.ts | 4 - .../circuits.js/src/tests/factories.ts | 11 -- .../src/conversion/common.ts | 20 +-- .../src/conversion/server.ts | 30 +--- 22 files changed, 197 insertions(+), 378 deletions(-) create mode 100644 noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/tx_effect.nr diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr index 7e8d5b28ac9..562295760c8 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr @@ -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 } 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 b8e22650ef4..543802a374a 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 @@ -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}; @@ -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, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr index 8ca0bd0d934..ea85e388efd 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr @@ -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, @@ -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] 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 0bcaaa80b27..7f61fdfaa04 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,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; \ No newline at end of file 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 new file mode 100644 index 00000000000..d17797d9123 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/tx_effect.nr @@ -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], + } + } +} \ 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 dbe2eb34fd6..4b2d262ba13 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,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", @@ -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", + ); + +} 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 d27dcd2b467..2bd1ef345f6 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,8 +1,8 @@ use crate::{ - abis::base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs}, + abis::tx_effect::TxEffect, abis::base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs}, base::{ components::{ - archive::perform_archive_membership_check, constants::validate_combined_constant_data, + archive::perform_archive_membership_check, fees::compute_fee_payer_fee_juice_balance_leaf_slot, nullifier_tree::nullifier_tree_batch_insert, private_base_rollup_output_composer::compute_transaction_fee, PrivateTubeDataValidator, @@ -14,13 +14,13 @@ use crate::{ }; use dep::types::{ abis::{ - append_only_tree_snapshot::AppendOnlyTreeSnapshot, constant_rollup_data::ConstantRollupData, + 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, }, constants::{ ARCHIVE_HEIGHT, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NOTE_HASH_SUBTREE_HEIGHT, - TUBE_VK_INDEX, + TUBE_VK_INDEX,MAX_UNENCRYPTED_LOGS_PER_TX }, data::{hash::compute_public_data_tree_value, public_data_hint::PublicDataHint}, hash::silo_l2_to_l1_message, @@ -29,8 +29,8 @@ use dep::types::{ }, messaging::l2_to_l1_message::ScopedL2ToL1Message, partial_state_reference::PartialStateReference, - traits::is_empty, }; +use super::components::constants::validate_tx_constant_data; global ALLOWED_PREVIOUS_CIRCUITS: [u32; 1] = [TUBE_VK_INDEX]; @@ -59,9 +59,7 @@ impl PrivateBaseRollupInputs { tube_data_validator.validate_with_rollup_data(self.constants); } - validate_combined_constant_data(self.tube_data.public_inputs.constants, self.constants); - - self.validate_kernel_start_state(); + validate_tx_constant_data(self.tube_data.public_inputs.constants, self.constants); let rollup_validation_requests = self.tube_data.public_inputs.rollup_validation_requests; @@ -113,13 +111,23 @@ impl PrivateBaseRollupInputs { self.tube_data.public_inputs.constants.tx_context.chain_id, ), ); + let out_hash = compute_kernel_out_hash(siloed_l2_to_l1_msgs); - let end_sponge_blob = append_tx_effects_for_blob( - self.tube_data.public_inputs.end, - self.tube_data.public_inputs.revert_code, + let tx_effect = TxEffect { + revert_code: 0, transaction_fee, - all_public_data_update_requests, - siloed_l2_to_l1_msgs, + note_hashes: self.tube_data.public_inputs.end.note_hashes, + nullifiers: self.tube_data.public_inputs.end.nullifiers, + l2_to_l1_msgs: siloed_l2_to_l1_msgs, + public_data_writes: all_public_data_update_requests, + 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_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, ); @@ -170,24 +178,6 @@ impl PrivateBaseRollupInputs { calculate_subtree_root(leaves.map(|leaf: NullifierLeafPreimage| leaf.hash())) } - fn validate_kernel_start_state(self) { - let kernel_state = self.tube_data.public_inputs.start_state; - if !is_empty(kernel_state) { - assert( - kernel_state.note_hash_tree.eq(self.start.note_hash_tree), - "Mismatch start state for note hash tree", - ); - assert( - kernel_state.nullifier_tree.eq(self.start.nullifier_tree), - "Mismatch start state for nullifier tree", - ); - assert( - kernel_state.public_data_tree.eq(self.start.public_data_tree), - "Mismatch start state for public data tree", - ); - } - } - fn build_fee_public_data_write(self, tx_fee: Field) -> PublicDataWrite { let fee_payer = self.tube_data.public_inputs.fee_payer; @@ -237,7 +227,6 @@ mod tests { }; use dep::types::{ abis::{ - accumulated_data::CombinedAccumulatedData, append_only_tree_snapshot::AppendOnlyTreeSnapshot, constant_rollup_data::ConstantRollupData, gas::Gas, gas_fees::GasFees, kernel_circuit_public_inputs::KernelCircuitPublicInputs, @@ -271,6 +260,7 @@ mod tests { field::{field_from_bytes, full_field_less_than}, }, }; + use crate::abis::tx_effect::TxEffect; struct NullifierInsertion { existing_index: u32, @@ -398,8 +388,8 @@ mod tests { fn build_pre_existing_tx_effects( self, - ) -> (CombinedAccumulatedData, [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]) { - let mut res = CombinedAccumulatedData::empty(); + ) -> TxEffect { + let mut res = TxEffect::empty(); res.note_hashes = self.pre_existing_notes; res.nullifiers = self.pre_existing_nullifiers.map(|nullifier: NullifierLeafPreimage| { nullifier.nullifier @@ -409,7 +399,7 @@ mod tests { PublicDataWrite { leaf_slot: leaf_preimage.slot, value: leaf_preimage.value } }, ); - let padded_all_public_data_update_requests = array_concat( + res.public_data_writes = array_concat( all_public_data_update_requests, [ PublicDataWrite::empty(); MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX @@ -417,7 +407,7 @@ mod tests { ], ); - (res, padded_all_public_data_update_requests) + res } fn extract_subtree_sibling_path( @@ -583,15 +573,12 @@ mod tests { public_data_tree: start_public_data_tree_snapshot, }; - let (pre_existing_tx_effects, pre_existing_public_data_update_requests) = + let pre_existing_tx_effects = self.build_pre_existing_tx_effects(); + let start_sponge_blob = append_tx_effects_for_blob( pre_existing_tx_effects, - 0, - 0, - pre_existing_public_data_update_requests, - [0; MAX_L2_TO_L1_MSGS_PER_TX], SpongeBlob::new(TX_EFFECTS_BLOB_HASH_INPUT_FIELDS), ); @@ -903,34 +890,13 @@ mod tests { ); } builder.tube_data.append_l2_to_l1_msgs(NUM_MSGS); - // Copied from public data test below: - builder.pre_existing_public_data[0] = - PublicDataTreeLeafPreimage { slot: 20, value: 40, next_slot: 0, next_index: 0 }; builder.tube_data.append_private_logs(NUM_PRIV_EVENT_LOGS); - builder.tube_data.append_unencrypted_log_hashes(NUM_UNENC_LOGS); // Below will only work with NUM_CC_LOGS=1 builder.tube_data.add_contract_class_log_hash(1, 2); let outputs = builder.execute(); let mut reconstructed_tx_effects = [0; TX_EFFECTS_BLOB_HASH_INPUT_FIELDS]; - // Initial field = TX_START_PREFIX | 0 | txlen[0] txlen[1] | 0 | REVERT_CODE_PREFIX | 0 | revert_code - // revert code = 0 - let total_blob_fields_bytes = (TOTAL_BLOB_FIELDS as Field).to_be_bytes::<2>(); - reconstructed_tx_effects[0] = field_from_bytes( - array_concat( - TX_START_PREFIX.to_be_bytes::<8>(), - [ - 0, - total_blob_fields_bytes[0], - total_blob_fields_bytes[1], - 0, - REVERT_CODE_PREFIX, - 0, - 0, - ], - ), - true, - ); + // tx fee reconstructed_tx_effects[1] = field_from_bytes( array_concat([TX_FEE_PREFIX, 0], tx_fee.to_be_bytes::<29>()), @@ -978,16 +944,6 @@ mod tests { } } offset += total_private_logs_len; - // unenc logs - let unencrypted_logs_prefix = encode_blob_prefix(UNENCRYPTED_LOGS_PREFIX, NUM_UNENC_LOGS); - reconstructed_tx_effects[offset] = unencrypted_logs_prefix; - offset += 1; - for i in 0..NUM_UNENC_LOGS { - reconstructed_tx_effects[offset + i] = types::hash::silo_unencrypted_log_hash( - builder.tube_data.unencrypted_logs_hashes.storage()[i], - ); - } - offset += NUM_UNENC_LOGS; // cc logs let contract_class_logs_prefix = encode_blob_prefix(CONTRACT_CLASS_LOGS_PREFIX, NUM_CC_LOGS); @@ -1000,8 +956,24 @@ mod tests { } offset += NUM_CC_LOGS; - // Sanity check - assert(offset == TOTAL_BLOB_FIELDS); + // Initial field = TX_START_PREFIX | 0 | txlen[0] txlen[1] | 0 | REVERT_CODE_PREFIX | 0 | revert_code + // revert code = 0 + let length_bytes = (offset as Field).to_be_bytes::<2>(); + 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, + ], + ), + true, + ); let mut expected_sponge = outputs.start_sponge_blob; expected_sponge.absorb(reconstructed_tx_effects, offset); @@ -1068,14 +1040,6 @@ mod tests { builder.fails(); } - #[test(should_fail_with = "kernel global variables do not match the rollup global variables")] - unconstrained fn constants_global_variables_dont_match_kernels() { - let mut builder = PrivateBaseRollupInputsBuilder::new(); - builder.tube_data.global_variables.block_number = 6; - builder.constants.global_variables.block_number = 7; - builder.fails(); - } - #[test(should_fail_with = "kernel max_block_number is smaller than block number")] unconstrained fn constants_dont_satisfy_smaller_max_block_number() { let mut builder = PrivateBaseRollupInputsBuilder::new(); 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 4548fe7b63a..b75edfe2140 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,5 @@ use crate::{ - abis::base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs}, + abis::tx_effect::TxEffect, abis::base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs}, base::{ components::{ archive::perform_archive_membership_check, constants::validate_combined_constant_data, @@ -50,9 +50,17 @@ pub struct PublicBaseRollupInputs { } impl PublicBaseRollupInputs { - fn generate_combined_accumulated_data(self, reverted: bool) -> CombinedAccumulatedData { + 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 }; + let siloed_l2_to_l1_msgs = from_public.accumulated_data.l2_to_l1_msgs.map( + |message: ScopedL2ToL1Message| silo_l2_to_l1_message( + message, + combined_constant_data.tx_context.version, + combined_constant_data.tx_context.chain_id, + ), + ); let private_logs = if reverted { from_private.non_revertible_accumulated_data.private_logs @@ -77,16 +85,18 @@ impl PublicBaseRollupInputs { .unencrypted_logs_hashes .fold(0, |len, l: ScopedLogHash| len + l.log_hash.length); - CombinedAccumulatedData { + TxEffect { + revert_code, + transaction_fee: from_public.transaction_fee, note_hashes: from_public.accumulated_data.note_hashes, nullifiers: from_public.accumulated_data.nullifiers, - l2_to_l1_msgs: from_public.accumulated_data.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, contract_class_logs_hashes, - unencrypted_log_preimages_length, - contract_class_log_preimages_length, - public_data_writes: from_public.accumulated_data.public_data_writes, } } @@ -108,8 +118,6 @@ impl PublicBaseRollupInputs { // TODO: Validate tube_data.public_inputs vs avm_proof_data.public_inputs let reverted = self.avm_proof_data.public_inputs.reverted; - let combined_accumulated_data = self.generate_combined_accumulated_data(reverted); - let combined_constant_data = CombinedConstantData::combine( self.tube_data.public_inputs.constants, self.avm_proof_data.public_inputs.global_variables, @@ -130,8 +138,10 @@ impl PublicBaseRollupInputs { ); } + let tx_effect = self.generate_tx_effect(reverted, combined_constant_data); + let commitments_tree_subroot = - calculate_subtree_root(combined_accumulated_data.note_hashes); + calculate_subtree_root(tx_effect.note_hashes); let empty_commitments_subtree_root = calculate_empty_tree_root(NOTE_HASH_SUBTREE_HEIGHT); @@ -145,29 +155,17 @@ impl PublicBaseRollupInputs { // Insert nullifiers: let end_nullifier_tree_snapshot = - self.check_nullifier_tree_non_membership_and_insert_to_tree(combined_accumulated_data); + self.check_nullifier_tree_non_membership_and_insert_to_tree(tx_effect); // Validate public data update requests and update public data tree let end_public_data_tree_snapshot = - self.validate_and_process_public_state(combined_accumulated_data.public_data_writes); + self.validate_and_process_public_state(tx_effect.public_data_writes); // Append the tx effects for blob(s) - let siloed_l2_to_l1_msgs = combined_accumulated_data.l2_to_l1_msgs.map( - |message: ScopedL2ToL1Message| silo_l2_to_l1_message( - message, - combined_constant_data.tx_context.version, - combined_constant_data.tx_context.chain_id, - ), - ); - let out_hash = compute_kernel_out_hash(siloed_l2_to_l1_msgs); - let revert_code = if reverted { 1 } else { 0 }; + let out_hash = compute_kernel_out_hash(tx_effect.l2_to_l1_msgs); let end_sponge_blob = append_tx_effects_for_blob( - combined_accumulated_data, - revert_code, - self.avm_proof_data.public_inputs.transaction_fee, - combined_accumulated_data.public_data_writes, - siloed_l2_to_l1_msgs, + tx_effect, self.start_sponge_blob, ); @@ -217,11 +215,11 @@ impl PublicBaseRollupInputs { fn check_nullifier_tree_non_membership_and_insert_to_tree( self, - accumulated_data: CombinedAccumulatedData, + tx_effect: TxEffect, ) -> AppendOnlyTreeSnapshot { nullifier_tree_batch_insert( self.start.nullifier_tree, - accumulated_data.nullifiers, + tx_effect.nullifiers, self.state_diff_hints.sorted_nullifiers, self.state_diff_hints.sorted_nullifier_indexes, self.state_diff_hints.nullifier_subtree_sibling_path, @@ -323,6 +321,7 @@ mod tests { field::{field_from_bytes, full_field_less_than}, }, }; + use crate::abis::tx_effect::TxEffect; struct NullifierInsertion { existing_index: u32, @@ -423,6 +422,7 @@ mod tests { inputs.constants.global_variables.chain_id = fixtures::CHAIN_ID; inputs.constants.global_variables.version = fixtures::VERSION; + inputs.avm_data.global_variables = inputs.constants.global_variables; inputs.constants.vk_tree_root = inputs.tube_data.vk_tree_root; inputs.pre_existing_blocks[0] = inputs.tube_data.historical_header.hash(); @@ -436,10 +436,10 @@ mod tests { builder } - fn build_pre_existing_tx_effects( + fn build_pre_existing_tx_effects( self, - ) -> (CombinedAccumulatedData, [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]) { - let mut res = CombinedAccumulatedData::empty(); + ) -> TxEffect { + let mut res = TxEffect::empty(); res.note_hashes = self.pre_existing_notes; res.nullifiers = self.pre_existing_nullifiers.map(|nullifier: NullifierLeafPreimage| { nullifier.nullifier @@ -449,7 +449,7 @@ mod tests { PublicDataWrite { leaf_slot: leaf_preimage.slot, value: leaf_preimage.value } }, ); - let padded_all_public_data_update_requests = array_concat( + res.public_data_writes = array_concat( all_public_data_update_requests, [ PublicDataWrite::empty(); MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX @@ -457,7 +457,7 @@ mod tests { ], ); - (res, padded_all_public_data_update_requests) + res } fn extract_subtree_sibling_path( @@ -673,15 +673,11 @@ mod tests { public_data_tree: start_public_data_tree_snapshot, }; - let (pre_existing_tx_effects, pre_existing_public_data_update_requests) = + let tx_effect = self.build_pre_existing_tx_effects(); let start_sponge_blob = append_tx_effects_for_blob( - pre_existing_tx_effects, - 0, - 0, - pre_existing_public_data_update_requests, - [0; MAX_L2_TO_L1_MSGS_PER_TX], + tx_effect, SpongeBlob::new(TX_EFFECTS_BLOB_HASH_INPUT_FIELDS), ); @@ -1183,6 +1179,7 @@ mod tests { unconstrained fn constants_dont_satisfy_smaller_max_block_number() { let mut builder = PublicBaseRollupInputsBuilder::new(); builder.constants.global_variables.block_number = 42; + builder.avm_data.global_variables.block_number = 42; builder.tube_data.set_max_block_number(5); builder.fails(); } @@ -1191,6 +1188,7 @@ mod tests { unconstrained fn constants_satisfy_equal_max_block_number() { let mut builder = PublicBaseRollupInputsBuilder::new(); builder.constants.global_variables.block_number = 42; + builder.avm_data.global_variables.block_number = 42; builder.tube_data.set_max_block_number(42); builder.succeeds(); } @@ -1199,6 +1197,7 @@ mod tests { unconstrained fn constants_satisfy_larger_max_block_number() { let mut builder = PublicBaseRollupInputsBuilder::new(); builder.constants.global_variables.block_number = 42; + builder.avm_data.global_variables.block_number = 42; builder.tube_data.set_max_block_number(4294967295); builder.succeeds(); } 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 cfeb1572561..6232e4a7316 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 @@ -6,7 +6,7 @@ use crate::abis::{ }; use dep::types::{ abis::{ - accumulated_data::CombinedAccumulatedData, log_hash::ScopedLogHash, + log_hash::ScopedLogHash, public_data_write::PublicDataWrite, sponge_blob::SpongeBlob, }, constants::{ @@ -24,6 +24,7 @@ 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 @@ -267,27 +268,24 @@ pub(crate) global TX_EFFECTS_BLOB_HASH_INPUT_FIELDS: u32 = 1 + MAX_UNENCRYPTED_LOGS_PER_TX + MAX_CONTRACT_CLASS_LOGS_PER_TX + 7; -pub fn append_tx_effects_for_blob( - combined: CombinedAccumulatedData, - revert_code: u8, - transaction_fee: Field, - all_public_data_update_requests: [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], - l2_to_l1_msgs: [Field; MAX_L2_TO_L1_MSGS_PER_TX], + +pub(crate) fn append_tx_effects_for_blob( + tx_effect: TxEffect, start_sponge_blob: SpongeBlob, ) -> SpongeBlob { let mut tx_effects_hash_input = [0; TX_EFFECTS_BLOB_HASH_INPUT_FIELDS]; - let note_hashes = combined.note_hashes; - let nullifiers = combined.nullifiers; + let note_hashes = tx_effect.note_hashes; + let nullifiers = tx_effect.nullifiers; // Public writes are the concatenation of all non-empty user update requests and protocol update requests, then padded with zeroes. // The incoming all_public_data_update_requests may have empty update requests in the middle, so we move those to the end of the array. let public_data_update_requests = - get_all_update_requests_for_tx_effects(all_public_data_update_requests); - let private_logs = combined.private_logs; + get_all_update_requests_for_tx_effects(tx_effect.public_data_writes); + let private_logs = tx_effect.private_logs; let unencrypted_logs = - combined.unencrypted_logs_hashes.map(|log: ScopedLogHash| silo_unencrypted_log_hash(log)); - let contract_class_logs = combined.contract_class_logs_hashes.map(|log: ScopedLogHash| { + tx_effect.unencrypted_logs_hashes.map(|log: ScopedLogHash| silo_unencrypted_log_hash(log)); + let contract_class_logs = tx_effect.contract_class_logs_hashes.map(|log: ScopedLogHash| { silo_unencrypted_log_hash(log) }); @@ -304,7 +302,7 @@ pub 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], transaction_fee.to_be_bytes::<29>()), + array_concat([TX_FEE_PREFIX, 0], tx_effect.transaction_fee.to_be_bytes::<29>()), true, ); offset += 1; @@ -339,14 +337,14 @@ pub fn append_tx_effects_for_blob( } // L2 TO L1 MESSAGES - array_len = array_length(l2_to_l1_msgs); + array_len = array_length(tx_effect.l2_to_l1_msgs); if array_len != 0 { let l2_to_l1_msgs_prefix = encode_blob_prefix(L2_L1_MSGS_PREFIX, array_len); tx_effects_hash_input[offset] = l2_to_l1_msgs_prefix; offset += 1; for j in 0..MAX_L2_TO_L1_MSGS_PER_TX { - tx_effects_hash_input[offset + j] = l2_to_l1_msgs[j]; + tx_effects_hash_input[offset + j] = tx_effect.l2_to_l1_msgs[j]; } offset += array_len; } @@ -419,7 +417,7 @@ pub fn append_tx_effects_for_blob( tx_effects_hash_input[0] = field_from_bytes( array_concat( prefix_bytes, - [0, length_bytes[0], length_bytes[1], 0, REVERT_CODE_PREFIX, 0, revert_code], + [0, length_bytes[0], length_bytes[1], 0, REVERT_CODE_PREFIX, 0, tx_effect.revert_code], ), true, ); @@ -437,6 +435,7 @@ pub fn append_tx_effects_for_blob( out_sponge } +// TODO remove this? The avm should be returning public data writes left aligned. fn get_all_update_requests_for_tx_effects( all_public_data_update_requests: [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], ) -> [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] { diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/lib.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/lib.nr index e79a948ebf6..d7ccbb44a7e 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/lib.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/lib.nr @@ -1,20 +1,20 @@ -mod abis; +pub(crate) mod abis; // Base rollup -mod base; +pub(crate) mod base; // Merge rollup -mod merge; +pub(crate) mod merge; // Block root rollup -mod block_root; +pub(crate) mod block_root; // Block merge rollup -mod block_merge; +pub(crate) mod block_merge; // Root rollup -mod root; +pub(crate) mod root; -mod components; +pub(crate) mod components; -mod tests; +pub(crate) mod tests; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index 83921f18c3b..55da457c5a7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -1,9 +1,8 @@ use crate::{ - abis::{log_hash::ScopedLogHash, private_log::PrivateLog, public_data_write::PublicDataWrite}, + abis::{log_hash::ScopedLogHash, private_log::PrivateLog}, constants::{ COMBINED_ACCUMULATED_DATA_LENGTH, 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, }, messaging::l2_to_l1_message::ScopedL2ToL1Message, traits::{Deserialize, Empty, Serialize}, @@ -16,15 +15,11 @@ pub struct CombinedAccumulatedData { pub l2_to_l1_msgs: [ScopedL2ToL1Message; MAX_L2_TO_L1_MSGS_PER_TX], pub private_logs: [PrivateLog; MAX_PRIVATE_LOGS_PER_TX], - pub unencrypted_logs_hashes: [ScopedLogHash; MAX_UNENCRYPTED_LOGS_PER_TX], pub contract_class_logs_hashes: [ScopedLogHash; MAX_CONTRACT_CLASS_LOGS_PER_TX], // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the // variable-length data. - pub unencrypted_log_preimages_length: Field, pub contract_class_log_preimages_length: Field, - - pub public_data_writes: [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], } impl Empty for CombinedAccumulatedData { @@ -34,13 +29,8 @@ impl Empty for CombinedAccumulatedData { nullifiers: [0; MAX_NULLIFIERS_PER_TX], l2_to_l1_msgs: [ScopedL2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_TX], private_logs: [PrivateLog::empty(); MAX_PRIVATE_LOGS_PER_TX], - unencrypted_logs_hashes: [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX], contract_class_logs_hashes: [ScopedLogHash::empty(); MAX_CONTRACT_CLASS_LOGS_PER_TX], - unencrypted_log_preimages_length: 0, contract_class_log_preimages_length: 0, - public_data_writes: [ - PublicDataWrite::empty(); MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX - ], } } } @@ -57,19 +47,11 @@ impl Serialize for CombinedAccumulatedData { for i in 0..self.private_logs.len() { fields.extend_from_array(self.private_logs[i].serialize()); } - for i in 0..self.unencrypted_logs_hashes.len() { - fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); - } for i in 0..self.contract_class_logs_hashes.len() { fields.extend_from_array(self.contract_class_logs_hashes[i].serialize()); } - fields.push(self.unencrypted_log_preimages_length); fields.push(self.contract_class_log_preimages_length); - for i in 0..MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { - fields.extend_from_array(self.public_data_writes[i].serialize()); - } - assert_eq(fields.len(), COMBINED_ACCUMULATED_DATA_LENGTH); fields.storage() @@ -91,20 +73,11 @@ impl Deserialize for CombinedAccumulatedData { PrivateLog::deserialize, [PrivateLog::empty(); MAX_PRIVATE_LOGS_PER_TX], ), - unencrypted_logs_hashes: reader.read_struct_array( - ScopedLogHash::deserialize, - [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX], - ), contract_class_logs_hashes: reader.read_struct_array( ScopedLogHash::deserialize, [ScopedLogHash::empty(); MAX_CONTRACT_CLASS_LOGS_PER_TX], ), - unencrypted_log_preimages_length: reader.read(), contract_class_log_preimages_length: reader.read(), - public_data_writes: reader.read_struct_array( - PublicDataWrite::deserialize, - [PublicDataWrite::empty(); MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], - ), }; reader.finish(); item @@ -117,14 +90,11 @@ impl Eq for CombinedAccumulatedData { & (self.nullifiers == other.nullifiers) & (self.l2_to_l1_msgs == other.l2_to_l1_msgs) & (self.private_logs == other.private_logs) - & (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) & (self.contract_class_logs_hashes == other.contract_class_logs_hashes) - & (self.unencrypted_log_preimages_length == other.unencrypted_log_preimages_length) & ( self.contract_class_log_preimages_length == other.contract_class_log_preimages_length ) - & (self.public_data_writes == other.public_data_writes) } } 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 115beab20f9..a1943eb190c 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,22 +1,18 @@ use crate::{ - abis::{ - accumulated_data::CombinedAccumulatedData, combined_constant_data::CombinedConstantData, + abis::tx_constant_data::TxConstantData, abis::{ + accumulated_data::CombinedAccumulatedData, gas::Gas, validation_requests::RollupValidationRequests, }, address::AztecAddress, constants::KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, - partial_state_reference::PartialStateReference, traits::{Deserialize, Empty, Serialize}, utils::reader::Reader, }; -// TODO: Update it to be specifically for the private_kernel_tail once we remove public_kernel_tail, which also outputs this. pub struct KernelCircuitPublicInputs { + pub constants: TxConstantData, pub rollup_validation_requests: RollupValidationRequests, pub end: CombinedAccumulatedData, - pub constants: CombinedConstantData, - pub start_state: PartialStateReference, - pub revert_code: u8, pub gas_used: Gas, pub fee_payer: AztecAddress, } @@ -26,9 +22,7 @@ impl Empty for KernelCircuitPublicInputs { KernelCircuitPublicInputs { rollup_validation_requests: RollupValidationRequests::empty(), end: CombinedAccumulatedData::empty(), - constants: CombinedConstantData::empty(), - start_state: PartialStateReference::empty(), - revert_code: 0, + constants: TxConstantData::empty(), gas_used: Gas::empty(), fee_payer: AztecAddress::empty(), } @@ -40,8 +34,6 @@ impl Eq for KernelCircuitPublicInputs { (self.rollup_validation_requests.eq(other.rollup_validation_requests)) & (self.end.eq(other.end)) & (self.constants.eq(other.constants)) - & (self.start_state.eq(other.start_state)) - & (self.revert_code == other.revert_code) & (self.gas_used == other.gas_used) & (self.fee_payer.eq(other.fee_payer)) } @@ -54,8 +46,6 @@ impl Serialize for KernelCircuitPublicInput fields.extend_from_array(self.rollup_validation_requests.serialize()); fields.extend_from_array(self.end.serialize()); fields.extend_from_array(self.constants.serialize()); - fields.extend_from_array(self.start_state.serialize()); - fields.push(self.revert_code as Field); fields.extend_from_array(self.gas_used.serialize()); fields.extend_from_array(self.fee_payer.serialize()); @@ -73,9 +63,7 @@ impl Deserialize for KernelCircuitPublicInp let item = Self { rollup_validation_requests: reader.read_struct(RollupValidationRequests::deserialize), end: reader.read_struct(CombinedAccumulatedData::deserialize), - constants: reader.read_struct(CombinedConstantData::deserialize), - start_state: reader.read_struct(PartialStateReference::deserialize), - revert_code: reader.read() as u8, + constants: reader.read_struct(TxConstantData::deserialize), gas_used: reader.read_struct(Gas::deserialize), fee_payer: reader.read_struct(AztecAddress::deserialize), }; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index a8a6480fc23..1d19fa0b48d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -338,11 +338,9 @@ pub global COMBINED_ACCUMULATED_DATA_LENGTH: u32 = MAX_NOTE_HASHES_PER_TX + MAX_NULLIFIERS_PER_TX + (MAX_L2_TO_L1_MSGS_PER_TX * SCOPED_L2_TO_L1_MESSAGE_LENGTH) + (PRIVATE_LOG_SIZE_IN_FIELDS * MAX_PRIVATE_LOGS_PER_TX) - + (SCOPED_LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_TX) - + 1 /* unencrypted_log_preimages_length */ + (SCOPED_LOG_HASH_LENGTH * MAX_CONTRACT_CLASS_LOGS_PER_TX) - + 1 /* contract_class_log_preimages_length */ - + (MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_WRITE_LENGTH); + + 1 /* contract_class_log_preimages_length */; + pub global TX_CONSTANT_DATA_LENGTH: u32 = BLOCK_HEADER_LENGTH + TX_CONTEXT_LENGTH + 1 /* vk_tree_root */ @@ -392,9 +390,7 @@ pub global PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = TX_CONST pub global KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = ROLLUP_VALIDATION_REQUESTS_LENGTH + COMBINED_ACCUMULATED_DATA_LENGTH - + COMBINED_CONSTANT_DATA_LENGTH - + PARTIAL_STATE_REFERENCE_LENGTH - + 1 /* revert_code */ + + TX_CONSTANT_DATA_LENGTH + GAS_LENGTH /* gas_used */ + AZTEC_ADDRESS_LENGTH; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index 404bd4cbc7e..eabf75d54c1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -444,15 +444,10 @@ impl FixtureBuilder { m.expose_to_public() }), private_logs: self.private_logs.storage().map(|l: Scoped| l.inner.log), - unencrypted_logs_hashes: self.unencrypted_logs_hashes.storage().map(|l: ScopedLogHash| { - l.expose_to_public() - }), contract_class_logs_hashes: self.contract_class_logs_hashes.storage().map( |l: ScopedLogHash| l.expose_to_public(), ), - unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, contract_class_log_preimages_length: self.contract_class_log_preimages_length, - public_data_writes: self.public_data_writes.storage(), } } @@ -530,14 +525,12 @@ impl FixtureBuilder { pub fn to_kernel_circuit_public_inputs(self) -> KernelCircuitPublicInputs { let rollup_validation_requests = self.to_rollup_validation_requests(); let end = self.to_combined_accumulated_data(); - let constants = self.to_constant_data(); + let constants = self.to_tx_constant_data(); KernelCircuitPublicInputs { rollup_validation_requests, end, constants, - start_state: self.start_state, - revert_code: self.revert_code, gas_used: self.gas_used, fee_payer: self.fee_payer, } diff --git a/yarn-project/circuit-types/src/test/factories.ts b/yarn-project/circuit-types/src/test/factories.ts index 487bd5a8636..eb3642108ae 100644 --- a/yarn-project/circuit-types/src/test/factories.ts +++ b/yarn-project/circuit-types/src/test/factories.ts @@ -75,9 +75,6 @@ export function makeBloatedProcessedTx({ if (privateOnly) { const data = makeCombinedAccumulatedData(seed + 0x1000); - // Private-only tx has no public data writes. - data.publicDataWrites.forEach((_, i) => (data.publicDataWrites[i] = PublicDataWrite.empty())); - const transactionFee = tx.data.gasUsed.computeFee(globalVariables.gasFees); clearLogs(data); diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index ddbc926647c..963729a4163 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -140,7 +140,7 @@ export function makeProcessedTxFromPrivateOnlyTx( .filter(h => !h.isZero()), publicDataWrites, data.end.privateLogs.filter(l => !l.isEmpty()), - data.end.unencryptedLogPreimagesLength, + Fr.ZERO, data.end.contractClassLogPreimagesLength, tx.unencryptedLogs, tx.contractClassLogs, diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts index 62e1abefdd2..c5c65cac179 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts @@ -13,13 +13,10 @@ import { 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, } from '../../constants.gen.js'; import { ScopedL2ToL1Message } from '../l2_to_l1_message.js'; import { ScopedLogHash } from '../log_hash.js'; import { PrivateLog } from '../private_log.js'; -import { PublicDataWrite } from '../public_data_write.js'; /** * Data that is accumulated during the execution of the transaction. @@ -42,28 +39,15 @@ export class CombinedAccumulatedData { * All the logs created emitted from the private functions in this transaction. */ public privateLogs: Tuple, - /** - * Accumulated unencrypted logs hash from all the previous kernel iterations. - * Note: Truncated to 31 bytes to fit in Fr. - */ - public unencryptedLogsHashes: Tuple, /** * Accumulated contract class logs hash from all the previous kernel iterations. * Note: Truncated to 31 bytes to fit in Fr. */ public contractClassLogsHashes: Tuple, - /** - * Total accumulated length of the unencrypted log preimages emitted in all the previous kernel iterations - */ - public unencryptedLogPreimagesLength: Fr, /** * Total accumulated length of the contract class log preimages emitted in all the previous kernel iterations */ public contractClassLogPreimagesLength: Fr, - /** - * All the public data update requests made in this transaction. - */ - public publicDataWrites: Tuple, ) {} getSize() { @@ -72,11 +56,8 @@ export class CombinedAccumulatedData { arraySerializedSizeOfNonEmpty(this.nullifiers) + arraySerializedSizeOfNonEmpty(this.l2ToL1Msgs) + arraySerializedSizeOfNonEmpty(this.privateLogs) + - arraySerializedSizeOfNonEmpty(this.unencryptedLogsHashes) + arraySerializedSizeOfNonEmpty(this.contractClassLogsHashes) + - this.unencryptedLogPreimagesLength.size + - this.contractClassLogPreimagesLength.size + - arraySerializedSizeOfNonEmpty(this.publicDataWrites) + this.contractClassLogPreimagesLength.size ); } @@ -86,11 +67,8 @@ export class CombinedAccumulatedData { fields.nullifiers, fields.l2ToL1Msgs, fields.privateLogs, - fields.unencryptedLogsHashes, fields.contractClassLogsHashes, - fields.unencryptedLogPreimagesLength, fields.contractClassLogPreimagesLength, - fields.publicDataWrites, ] as const; } @@ -126,11 +104,8 @@ export class CombinedAccumulatedData { reader.readArray(MAX_NULLIFIERS_PER_TX, Fr), reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message), reader.readArray(MAX_PRIVATE_LOGS_PER_TX, PrivateLog), - reader.readArray(MAX_UNENCRYPTED_LOGS_PER_TX, ScopedLogHash), reader.readArray(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash), Fr.fromBuffer(reader), - Fr.fromBuffer(reader), - reader.readArray(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite), ); } @@ -149,11 +124,8 @@ export class CombinedAccumulatedData { makeTuple(MAX_NULLIFIERS_PER_TX, Fr.zero), makeTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message.empty), makeTuple(MAX_PRIVATE_LOGS_PER_TX, PrivateLog.empty), - makeTuple(MAX_UNENCRYPTED_LOGS_PER_TX, ScopedLogHash.empty), makeTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash.empty), Fr.zero(), - Fr.zero(), - makeTuple(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite.empty), ); } @@ -175,20 +147,11 @@ export class CombinedAccumulatedData { .filter(x => !x.isEmpty()) .map(x => inspect(x)) .join(', ')}] - unencryptedLogsHashes: : [${this.unencryptedLogsHashes - .filter(x => !x.isEmpty()) - .map(x => inspect(x)) - .join(', ')}], contractClassLogsHashes: : [${this.contractClassLogsHashes .filter(x => !x.isEmpty()) .map(x => inspect(x)) .join(', ')}], - unencryptedLogPreimagesLength: ${this.unencryptedLogPreimagesLength.toString()}, contractClassLogPreimagesLength: ${this.contractClassLogPreimagesLength.toString()}, - publicDataWrites: [${this.publicDataWrites - .filter(x => !x.isEmpty()) - .map(x => inspect(x)) - .join(', ')}], }`; } } diff --git a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts index e5abfe011f1..0e8286c174f 100644 --- a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts @@ -4,11 +4,9 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { bufferToHex, hexToBuffer } from '@aztec/foundation/string'; import { Gas } from '../gas.js'; -import { PartialStateReference } from '../partial_state_reference.js'; -import { RevertCode } from '../revert_code.js'; import { RollupValidationRequests } from '../rollup_validation_requests.js'; import { CombinedAccumulatedData } from './combined_accumulated_data.js'; -import { CombinedConstantData } from './combined_constant_data.js'; +import { TxConstantData } from './tx_constant_data.js'; /** * Outputs from the public kernel circuits. @@ -27,12 +25,7 @@ export class KernelCircuitPublicInputs { /** * Data which is not modified by the circuits. */ - public constants: CombinedConstantData, - public startState: PartialStateReference, - /** - * Flag indicating whether the transaction reverted. - */ - public revertCode: RevertCode, + public constants: TxConstantData, /** * Gas used during this transaction */ @@ -48,15 +41,7 @@ export class KernelCircuitPublicInputs { } toBuffer() { - return serializeToBuffer( - this.rollupValidationRequests, - this.end, - this.constants, - this.startState, - this.revertCode, - this.gasUsed, - this.feePayer, - ); + return serializeToBuffer(this.rollupValidationRequests, this.end, this.constants, this.gasUsed, this.feePayer); } /** @@ -69,9 +54,7 @@ export class KernelCircuitPublicInputs { return new KernelCircuitPublicInputs( reader.readObject(RollupValidationRequests), reader.readObject(CombinedAccumulatedData), - reader.readObject(CombinedConstantData), - reader.readObject(PartialStateReference), - reader.readObject(RevertCode), + reader.readObject(TxConstantData), reader.readObject(Gas), reader.readObject(AztecAddress), ); @@ -81,9 +64,7 @@ export class KernelCircuitPublicInputs { return new KernelCircuitPublicInputs( RollupValidationRequests.empty(), CombinedAccumulatedData.empty(), - CombinedConstantData.empty(), - PartialStateReference.empty(), - RevertCode.OK, + TxConstantData.empty(), Gas.empty(), AztecAddress.ZERO, ); diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts index 869427fa2ec..54e13f65d18 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts @@ -6,9 +6,7 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { countAccumulatedItems, mergeAccumulatedData } from '../../utils/index.js'; import { Gas } from '../gas.js'; import { GlobalVariables } from '../global_variables.js'; -import { PartialStateReference } from '../partial_state_reference.js'; import { PublicCallRequest } from '../public_call_request.js'; -import { RevertCode } from '../revert_code.js'; import { RollupValidationRequests } from '../rollup_validation_requests.js'; import { CombinedAccumulatedData } from './combined_accumulated_data.js'; import { CombinedConstantData } from './combined_constant_data.js'; @@ -178,8 +176,6 @@ export class PrivateKernelTailCircuitPublicInputs { this.rollupValidationRequests, this.forRollup.end, constants, - PartialStateReference.empty(), - RevertCode.OK, this.gasUsed, this.feePayer, ); diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 2cbedd38627..25427e95532 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -91,7 +91,6 @@ import { PublicKeys, RECURSIVE_PROOF_LENGTH, ReadRequest, - RevertCode, RollupTypes, RootParityInput, RootParityInputs, @@ -312,16 +311,8 @@ export function makeCombinedAccumulatedData(seed = 1, full = false): CombinedAcc tupleGenerator(MAX_NULLIFIERS_PER_TX, fr, seed + 0x200, Fr.zero), tupleGenerator(MAX_L2_TO_L1_MSGS_PER_TX, makeScopedL2ToL1Message, seed + 0x600, ScopedL2ToL1Message.empty), tupleGenerator(MAX_PRIVATE_LOGS_PER_TX, makePrivateLog, seed + 0x700, PrivateLog.empty), - tupleGenerator(MAX_UNENCRYPTED_LOGS_PER_TX, makeScopedLogHash, seed + 0x900, ScopedLogHash.empty), // unencrypted logs tupleGenerator(MAX_CONTRACT_CLASS_LOGS_PER_TX, makeScopedLogHash, seed + 0xa00, ScopedLogHash.empty), // contract class logs - fr(seed + 0xd00), // unencrypted_log_preimages_length fr(seed + 0xe00), // contract_class_log_preimages_length - tupleGenerator( - MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - makePublicDataWrite, - seed + 0xd00, - PublicDataWrite.empty, - ), ); } @@ -428,8 +419,6 @@ export function makeKernelCircuitPublicInputs(seed = 1, fullAccumulatedData = tr makeRollupValidationRequests(seed), makeCombinedAccumulatedData(seed, fullAccumulatedData), makeCombinedConstantData(seed + 0x100), - makePartialStateReference(seed + 0x200), - RevertCode.OK, makeGas(seed + 0x600), makeAztecAddress(seed + 0x700), ); diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts index 8434af0674a..c23c7df708f 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts @@ -19,8 +19,6 @@ import { 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, MaxBlockNumber, type MembershipWitness, NUM_BYTES_PER_SHA256, @@ -31,7 +29,7 @@ import { PrivateLog, PublicCallRequest, type PublicDataTreeLeafPreimage, - PublicDataWrite, + type PublicDataWrite, ScopedL2ToL1Message, ScopedLogHash, StateReference, @@ -660,10 +658,6 @@ function mapScopedLogHashFromNoir(scopedLogHash: ScopedLogHashNoir): ScopedLogHa ); } -function mapPublicDataWriteFromNoir(write: PublicDataWriteNoir) { - return new PublicDataWrite(mapFieldFromNoir(write.leaf_slot), mapFieldFromNoir(write.value)); -} - export function mapPublicDataWriteToNoir(write: PublicDataWrite): PublicDataWriteNoir { return { leaf_slot: mapFieldToNoir(write.leafSlot), @@ -682,23 +676,13 @@ export function mapCombinedAccumulatedDataFromNoir(combinedAccumulatedData: Comb mapTupleFromNoir(combinedAccumulatedData.nullifiers, MAX_NULLIFIERS_PER_TX, mapFieldFromNoir), mapTupleFromNoir(combinedAccumulatedData.l2_to_l1_msgs, MAX_L2_TO_L1_MSGS_PER_TX, mapScopedL2ToL1MessageFromNoir), mapTupleFromNoir(combinedAccumulatedData.private_logs, MAX_PRIVATE_LOGS_PER_TX, mapPrivateLogFromNoir), - mapTupleFromNoir( - combinedAccumulatedData.unencrypted_logs_hashes, - MAX_UNENCRYPTED_LOGS_PER_TX, - mapScopedLogHashFromNoir, - ), + mapTupleFromNoir( combinedAccumulatedData.contract_class_logs_hashes, MAX_CONTRACT_CLASS_LOGS_PER_TX, mapScopedLogHashFromNoir, ), - mapFieldFromNoir(combinedAccumulatedData.unencrypted_log_preimages_length), mapFieldFromNoir(combinedAccumulatedData.contract_class_log_preimages_length), - mapTupleFromNoir( - combinedAccumulatedData.public_data_writes, - MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - mapPublicDataWriteFromNoir, - ), ); } diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts index 5f3a6f9a660..6e1692361b5 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts @@ -7,7 +7,6 @@ import { BLOBS_PER_BLOCK, type BaseParityInputs, type CombinedAccumulatedData, - CombinedConstantData, type EmptyNestedData, Fr, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, @@ -32,7 +31,7 @@ import { type RootParityInputs, type TUBE_PROOF_LENGTH, type TreeSnapshots, - type TxConstantData, + TxConstantData, type VkWitnessData, } from '@aztec/circuits.js'; import { BlobPublicInputs, BlockBlobPublicInputs, Poseidon2Sponge, SpongeBlob } from '@aztec/circuits.js/blobs'; @@ -74,7 +73,6 @@ import type { BlockRootOrBlockMergePublicInputs as BlockRootOrBlockMergePublicInputsNoir, BlockRootRollupInputs as BlockRootRollupInputsNoir, CombinedAccumulatedData as CombinedAccumulatedDataNoir, - CombinedConstantData as CombinedConstantDataNoir, ConstantRollupData as ConstantRollupDataNoir, EmptyBlockRootRollupInputs as EmptyBlockRootRollupInputsNoir, EmptyNestedCircuitPublicInputs as EmptyNestedDataNoir, @@ -479,34 +477,20 @@ export function mapCombinedAccumulatedDataToNoir( nullifiers: mapTuple(combinedAccumulatedData.nullifiers, mapFieldToNoir), l2_to_l1_msgs: mapTuple(combinedAccumulatedData.l2ToL1Msgs, mapScopedL2ToL1MessageToNoir), private_logs: mapTuple(combinedAccumulatedData.privateLogs, mapPrivateLogToNoir), - unencrypted_logs_hashes: mapTuple(combinedAccumulatedData.unencryptedLogsHashes, mapScopedLogHashToNoir), contract_class_logs_hashes: mapTuple(combinedAccumulatedData.contractClassLogsHashes, mapScopedLogHashToNoir), - unencrypted_log_preimages_length: mapFieldToNoir(combinedAccumulatedData.unencryptedLogPreimagesLength), contract_class_log_preimages_length: mapFieldToNoir(combinedAccumulatedData.contractClassLogPreimagesLength), - public_data_writes: mapTuple(combinedAccumulatedData.publicDataWrites, mapPublicDataWriteToNoir), }; } -function mapCombinedConstantDataFromNoir(combinedConstantData: CombinedConstantDataNoir): CombinedConstantData { - return new CombinedConstantData( +function mapTxConstantDataFromNoir(combinedConstantData: TxConstantDataNoir): TxConstantData { + return new TxConstantData( mapHeaderFromNoir(combinedConstantData.historical_header), mapTxContextFromNoir(combinedConstantData.tx_context), mapFieldFromNoir(combinedConstantData.vk_tree_root), mapFieldFromNoir(combinedConstantData.protocol_contract_tree_root), - mapGlobalVariablesFromNoir(combinedConstantData.global_variables), ); } -function mapCombinedConstantDataToNoir(combinedConstantData: CombinedConstantData): CombinedConstantDataNoir { - return { - historical_header: mapHeaderToNoir(combinedConstantData.historicalHeader), - tx_context: mapTxContextToNoir(combinedConstantData.txContext), - vk_tree_root: mapFieldToNoir(combinedConstantData.vkTreeRoot), - protocol_contract_tree_root: mapFieldToNoir(combinedConstantData.protocolContractTreeRoot), - global_variables: mapGlobalVariablesToNoir(combinedConstantData.globalVariables), - }; -} - function mapTxConstantDataToNoir(data: TxConstantData): TxConstantDataNoir { return { historical_header: mapHeaderToNoir(data.historicalHeader), @@ -533,10 +517,8 @@ export function mapPrivateToPublicKernelCircuitPublicInputsToNoir( export function mapKernelCircuitPublicInputsToNoir(inputs: KernelCircuitPublicInputs): KernelCircuitPublicInputsNoir { return { rollup_validation_requests: mapRollupValidationRequestsToNoir(inputs.rollupValidationRequests), - constants: mapCombinedConstantDataToNoir(inputs.constants), + constants: mapTxConstantDataToNoir(inputs.constants), end: mapCombinedAccumulatedDataToNoir(inputs.end), - start_state: mapPartialStateReferenceToNoir(inputs.startState), - revert_code: mapRevertCodeToNoir(inputs.revertCode), gas_used: mapGasToNoir(inputs.gasUsed), fee_payer: mapAztecAddressToNoir(inputs.feePayer), }; @@ -958,9 +940,7 @@ export function mapKernelCircuitPublicInputsFromNoir(inputs: KernelCircuitPublic return new KernelCircuitPublicInputs( mapRollupValidationRequestsFromNoir(inputs.rollup_validation_requests), mapCombinedAccumulatedDataFromNoir(inputs.end), - mapCombinedConstantDataFromNoir(inputs.constants), - mapPartialStateReferenceFromNoir(inputs.start_state), - mapRevertCodeFromNoir(inputs.revert_code), + mapTxConstantDataFromNoir(inputs.constants), mapGasFromNoir(inputs.gas_used), mapAztecAddressFromNoir(inputs.fee_payer), ); From 250a23de57756ab66a42beabbfec3d4e331c56e5 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Fri, 3 Jan 2025 14:47:33 +0000 Subject: [PATCH 02/29] 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, From 31fb61c465748341aee9c1e1b385763626c1db59 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Fri, 3 Jan 2025 17:25:00 +0000 Subject: [PATCH 03/29] rename structs --- .../src/core/libraries/ConstantsGen.sol | 4 +- .../crates/blob/src/blob.nr | 4 +- .../src/main.nr | 6 ++- .../crates/private-kernel-empty/src/main.nr | 4 +- .../src/components/tail_output_composer.nr | 18 +++++---- .../tail_output_composer/meter_gas_used.nr | 7 +++- .../src/components/tail_output_validator.nr | 10 +++-- .../src/private_kernel_empty.nr | 6 +-- .../src/private_kernel_tail.nr | 10 ++--- .../meter_gas_used.nr | 4 +- .../tests/tail_output_composer_builder/mod.nr | 4 +- .../tail_output_validator_builder/mod.nr | 8 ++-- .../private-kernel-tail-simulated/src/main.nr | 4 +- .../crates/private-kernel-tail/src/main.nr | 4 +- .../src/base/private_base_rollup.nr | 4 +- .../rollup-lib/src/base/public_base_rollup.nr | 4 +- .../types/src/abis/accumulated_data/mod.nr | 4 +- ... => private_to_rollup_accumulated_data.nr} | 33 +++++++++------- .../abis/kernel_circuit_public_inputs/mod.nr | 4 +- ...to_rollup_kernel_circuit_public_inputs.nr} | 39 ++++++++++--------- .../crates/types/src/abis/tube.nr | 6 +-- .../crates/types/src/constants.nr | 6 +-- .../crates/types/src/lib.nr | 2 +- .../crates/types/src/tests/fixture_builder.nr | 23 ++++++----- .../bb-prover/src/prover/bb_prover.ts | 12 ++++-- .../bb-prover/src/test/test_circuit_prover.ts | 7 +++- .../src/interfaces/proving-job.ts | 6 +-- .../src/interfaces/server_circuit_prover.ts | 7 +++- yarn-project/circuits.js/src/constants.gen.ts | 4 +- yarn-project/circuits.js/src/structs/index.ts | 2 +- .../kernel/kernel_circuit_public_inputs.ts | 22 +++++------ ...ivate_kernel_tail_circuit_public_inputs.ts | 16 ++++---- ...rivate_to_rollup_accumulated_data.test.ts} | 6 +-- ... => private_to_rollup_accumulated_data.ts} | 22 +++++------ .../src/structs/rollup/private_tube_data.ts | 8 ++-- .../circuits.js/src/tests/factories.ts | 19 +++++---- .../src/conversion/client.ts | 4 +- .../src/conversion/common.ts | 26 +++++++------ .../src/conversion/server.ts | 37 +++++++++++------- .../src/execution/server.ts | 14 ++++--- .../src/block_builder/light.test.ts | 6 ++- .../src/orchestrator/tx-proving-state.ts | 6 ++- .../src/prover-agent/memory-proving-queue.ts | 7 +++- .../proving_broker/broker_prover_facade.ts | 7 +++- .../src/test/bb_prover_base_rollup.test.ts | 2 +- .../prover-client/src/test/mock_prover.ts | 11 ++++-- 46 files changed, 266 insertions(+), 203 deletions(-) rename noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/{combined_accumulated_data.nr => private_to_rollup_accumulated_data.nr} (73%) rename noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/{kernel_circuit_public_inputs.nr => private_to_rollup_kernel_circuit_public_inputs.nr} (55%) rename yarn-project/circuits.js/src/structs/kernel/{combined_accumulated_data.test.ts => private_to_rollup_accumulated_data.test.ts} (53%) rename yarn-project/circuits.js/src/structs/kernel/{combined_accumulated_data.ts => private_to_rollup_accumulated_data.ts} (85%) diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 765546c6c08..73481a664f8 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -195,7 +195,7 @@ library Constants { uint256 internal constant SCOPED_READ_REQUEST_LEN = 3; uint256 internal constant PUBLIC_DATA_READ_LENGTH = 3; uint256 internal constant PRIVATE_VALIDATION_REQUESTS_LENGTH = 772; - uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 902; + uint256 internal constant PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH = 902; uint256 internal constant TX_CONSTANT_DATA_LENGTH = 37; uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 46; uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1412; @@ -204,7 +204,7 @@ library Constants { uint256 internal constant PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH = 160; uint256 internal constant NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS = 3; uint256 internal constant PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1847; - uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 960; + uint256 internal constant PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 960; uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = 13; uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 52; uint256 internal constant BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH = 986; diff --git a/noir-projects/noir-protocol-circuits/crates/blob/src/blob.nr b/noir-projects/noir-protocol-circuits/crates/blob/src/blob.nr index d2f9d809332..1260b182a0d 100644 --- a/noir-projects/noir-protocol-circuits/crates/blob/src/blob.nr +++ b/noir-projects/noir-protocol-circuits/crates/blob/src/blob.nr @@ -474,7 +474,7 @@ mod tests { let mut tx_data = FixtureBuilder::new(); tx_data.add_new_note_hash(1); let mut blob: [Field; FIELDS_PER_BLOB] = [0; FIELDS_PER_BLOB]; - let blob_fields = tx_data.to_combined_accumulated_data().serialize(); + let blob_fields = tx_data.to_private_to_rollup_accumulated_data().serialize(); for i in 0..blob_fields.len() { blob[i] = blob_fields[i]; } @@ -519,7 +519,7 @@ mod tests { tx_data.append_l2_to_l1_msgs(5); tx_data.append_unencrypted_log_hashes(5); let mut blob: [Field; FIELDS_PER_BLOB] = [0; FIELDS_PER_BLOB]; - let blob_fields = tx_data.to_combined_accumulated_data().serialize(); + let blob_fields = tx_data.to_private_to_rollup_accumulated_data().serialize(); for i in 0..blob_fields.len() { blob[i] = blob_fields[i]; } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-empty-simulated/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-empty-simulated/src/main.nr index b41b393668c..095aaa3bf66 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-empty-simulated/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-empty-simulated/src/main.nr @@ -1,6 +1,8 @@ use dep::private_kernel_lib::PrivateKernelEmptyPrivateInputs; -use dep::types::KernelCircuitPublicInputs; +use dep::types::PrivateToRollupKernelCircuitPublicInputs; -unconstrained fn main(input: PrivateKernelEmptyPrivateInputs) -> pub KernelCircuitPublicInputs { +unconstrained fn main( + input: PrivateKernelEmptyPrivateInputs, +) -> pub PrivateToRollupKernelCircuitPublicInputs { input.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-empty/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-empty/src/main.nr index 1eeeb229b1b..b320f0d42cd 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-empty/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-empty/src/main.nr @@ -1,6 +1,6 @@ use dep::private_kernel_lib::PrivateKernelEmptyPrivateInputs; -use dep::types::KernelCircuitPublicInputs; +use dep::types::PrivateToRollupKernelCircuitPublicInputs; -fn main(input: PrivateKernelEmptyPrivateInputs) -> pub KernelCircuitPublicInputs { +fn main(input: PrivateKernelEmptyPrivateInputs) -> pub PrivateToRollupKernelCircuitPublicInputs { input.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr index 562295760c8..5fd0147cab4 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr @@ -3,10 +3,12 @@ mod meter_gas_used; use crate::components::private_kernel_circuit_public_inputs_composer::PrivateKernelCircuitPublicInputsComposer; use dep::types::{ abis::{ - accumulated_data::combined_accumulated_data::CombinedAccumulatedData, + accumulated_data::private_to_rollup_accumulated_data::PrivateToRollupAccumulatedData, combined_constant_data::CombinedConstantData, global_variables::GlobalVariables, - kernel_circuit_public_inputs::{KernelCircuitPublicInputs, PrivateKernelCircuitPublicInputs}, + kernel_circuit_public_inputs::{ + PrivateKernelCircuitPublicInputs, PrivateToRollupKernelCircuitPublicInputs, + }, log_hash::ScopedLogHash, note_hash::ScopedNoteHash, nullifier::ScopedNullifier, @@ -30,20 +32,22 @@ impl TailOutputComposer { TailOutputComposer { output_composer } } - pub unconstrained fn finish(self) -> KernelCircuitPublicInputs { + pub unconstrained fn finish(self) -> PrivateToRollupKernelCircuitPublicInputs { let source = self.output_composer.finish(); - let mut output = KernelCircuitPublicInputs::empty(); + let mut output = PrivateToRollupKernelCircuitPublicInputs::empty(); output.rollup_validation_requests = source.validation_requests.for_rollup; - output.end = self.build_combined_accumulated_data(); + output.end = self.build_private_to_rollup_accumulated_data(); output.gas_used = meter_gas_used(output.end); output.constants = source.constants; output.fee_payer = source.fee_payer; output } - unconstrained fn build_combined_accumulated_data(self) -> CombinedAccumulatedData { + unconstrained fn build_private_to_rollup_accumulated_data( + self, + ) -> PrivateToRollupAccumulatedData { let source = self.output_composer.public_inputs.end; - let mut data = CombinedAccumulatedData::empty(); + let mut data = PrivateToRollupAccumulatedData::empty(); data.note_hashes = source.note_hashes.storage().map(|n: ScopedNoteHash| n.note_hash.value); data.nullifiers = source.nullifiers.storage().map(|n: ScopedNullifier| n.nullifier.value); data.l2_to_l1_msgs = diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer/meter_gas_used.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer/meter_gas_used.nr index a2eaeed7b8b..12acfc1e3df 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer/meter_gas_used.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer/meter_gas_used.nr @@ -1,5 +1,8 @@ use dep::types::{ - abis::{accumulated_data::combined_accumulated_data::CombinedAccumulatedData, gas::Gas}, + abis::{ + accumulated_data::private_to_rollup_accumulated_data::PrivateToRollupAccumulatedData, + gas::Gas, + }, constants::{ DA_BYTES_PER_FIELD, DA_GAS_PER_BYTE, L2_GAS_PER_L2_TO_L1_MSG, L2_GAS_PER_LOG_BYTE, L2_GAS_PER_NOTE_HASH, L2_GAS_PER_NULLIFIER, L2_GAS_PER_PRIVATE_LOG, @@ -8,7 +11,7 @@ use dep::types::{ utils::arrays::array_length, }; -pub fn meter_gas_used(data: CombinedAccumulatedData) -> Gas { +pub fn meter_gas_used(data: PrivateToRollupAccumulatedData) -> Gas { let mut metered_da_fields = 0; let mut metered_l2_gas = 0; 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 437cd4465b4..88518112f9c 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 @@ -3,7 +3,9 @@ pub mod tail_output_hints; use crate::components::tail_output_composer::meter_gas_used; use dep::types::{ abis::{ - kernel_circuit_public_inputs::{KernelCircuitPublicInputs, PrivateKernelCircuitPublicInputs}, + kernel_circuit_public_inputs::{ + PrivateKernelCircuitPublicInputs, PrivateToRollupKernelCircuitPublicInputs, + }, log_hash::ScopedLogHash, private_log::PrivateLogData, side_effect::scoped::Scoped, @@ -14,14 +16,14 @@ use dep::types::{ use tail_output_hints::{generate_tail_output_hints, TailOutputHints}; pub struct TailOutputValidator { - output: KernelCircuitPublicInputs, + output: PrivateToRollupKernelCircuitPublicInputs, previous_kernel: PrivateKernelCircuitPublicInputs, hints: TailOutputHints, } impl TailOutputValidator { pub fn new( - output: KernelCircuitPublicInputs, + output: PrivateToRollupKernelCircuitPublicInputs, previous_kernel: PrivateKernelCircuitPublicInputs, ) -> Self { let hints = unsafe { generate_tail_output_hints(previous_kernel) }; @@ -29,7 +31,7 @@ impl TailOutputValidator { } pub fn new_with_hints( - output: KernelCircuitPublicInputs, + output: PrivateToRollupKernelCircuitPublicInputs, previous_kernel: PrivateKernelCircuitPublicInputs, hints: TailOutputHints, ) -> Self { diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr index 818f77cb6f3..b2d5fd26e65 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr @@ -1,6 +1,6 @@ use dep::types::{ block_header::BlockHeader, - KernelCircuitPublicInputs, + PrivateToRollupKernelCircuitPublicInputs, proof::{ rollup_recursive_proof::RecursiveProof, traits::Verifiable, @@ -36,10 +36,10 @@ pub struct PrivateKernelEmptyPrivateInputs { } impl PrivateKernelEmptyPrivateInputs { - pub fn execute(self) -> KernelCircuitPublicInputs { + pub fn execute(self) -> PrivateToRollupKernelCircuitPublicInputs { self.empty_nested.verify(); - let mut public_inputs = KernelCircuitPublicInputs::empty(); + let mut public_inputs = PrivateToRollupKernelCircuitPublicInputs::empty(); public_inputs.constants.historical_header = self.historical_header; public_inputs.constants.tx_context.chain_id = self.chain_id; public_inputs.constants.tx_context.version = self.version; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr index ea85e388efd..750c82faf75 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr @@ -4,7 +4,7 @@ use crate::components::{ }; use dep::types::{ abis::{ - kernel_circuit_public_inputs::KernelCircuitPublicInputs, + kernel_circuit_public_inputs::PrivateToRollupKernelCircuitPublicInputs, private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, }, constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, @@ -28,11 +28,11 @@ impl PrivateKernelTailCircuitPrivateInputs { } } - unconstrained fn generate_output(self) -> KernelCircuitPublicInputs { + unconstrained fn generate_output(self) -> PrivateToRollupKernelCircuitPublicInputs { TailOutputComposer::new(self.previous_kernel.public_inputs).finish() } - pub fn execute(self) -> KernelCircuitPublicInputs { + pub fn execute(self) -> PrivateToRollupKernelCircuitPublicInputs { if !std::runtime::is_unconstrained() { self.previous_kernel.verify(); } @@ -59,7 +59,7 @@ mod tests { }; use dep::types::{ abis::{ - gas::Gas, kernel_circuit_public_inputs::KernelCircuitPublicInputs, + gas::Gas, kernel_circuit_public_inputs::PrivateToRollupKernelCircuitPublicInputs, max_block_number::MaxBlockNumber, }, address::{AztecAddress, EthAddress}, @@ -88,7 +88,7 @@ mod tests { PrivateKernelTailInputsBuilder { previous_kernel } } - pub fn execute(&mut self) -> KernelCircuitPublicInputs { + pub fn execute(&mut self) -> PrivateToRollupKernelCircuitPublicInputs { let kernel = PrivateKernelTailCircuitPrivateInputs { previous_kernel: self.previous_kernel.to_private_kernel_data(), }; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_composer_builder/meter_gas_used.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_composer_builder/meter_gas_used.nr index a0dd0501ea6..c7bf62dfb18 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_composer_builder/meter_gas_used.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_composer_builder/meter_gas_used.nr @@ -17,7 +17,7 @@ fn new_builder() -> FixtureBuilder { #[test] fn meter_gas_used_empty_succeeds() { let builder = new_builder(); - let data = builder.to_combined_accumulated_data(); + let data = builder.to_private_to_rollup_accumulated_data(); let gas = meter_gas_used(data); assert_eq(gas, Gas::tx_overhead()); } @@ -48,7 +48,7 @@ fn meter_gas_used_everything_succeeds() { metered_da_bytes += 51; computed_l2_gas += 51 * L2_GAS_PER_LOG_BYTE; - let data = builder.to_combined_accumulated_data(); + let data = builder.to_private_to_rollup_accumulated_data(); let gas = meter_gas_used(data); assert_eq( diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_composer_builder/mod.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_composer_builder/mod.nr index 3f9b6ef8043..616215d2e85 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_composer_builder/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_composer_builder/mod.nr @@ -2,7 +2,7 @@ mod meter_gas_used; use crate::components::tail_output_composer::TailOutputComposer; use dep::types::{ - abis::kernel_circuit_public_inputs::KernelCircuitPublicInputs, + abis::kernel_circuit_public_inputs::PrivateToRollupKernelCircuitPublicInputs, tests::fixture_builder::FixtureBuilder, }; @@ -17,7 +17,7 @@ impl TailOutputComposerBuilder { TailOutputComposerBuilder { previous_kernel } } - pub fn finish(self) -> KernelCircuitPublicInputs { + pub fn finish(self) -> PrivateToRollupKernelCircuitPublicInputs { let previous_kernel = self.previous_kernel.to_private_kernel_circuit_public_inputs(); unsafe { let composer = TailOutputComposer::new(previous_kernel); 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 fb0e57272c9..7982dae8ca7 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 @@ -12,7 +12,7 @@ use crate::components::{ use dep::types::{ abis::{ gas::Gas, gas_fees::GasFees, gas_settings::GasSettings, - kernel_circuit_public_inputs::KernelCircuitPublicInputs, + kernel_circuit_public_inputs::PrivateToRollupKernelCircuitPublicInputs, }, constants::{DEFAULT_GAS_LIMIT, DEFAULT_TEARDOWN_GAS_LIMIT}, tests::fixture_builder::FixtureBuilder, @@ -48,8 +48,8 @@ impl TailOutputValidatorBuilder { } } - pub fn export_output(self) -> KernelCircuitPublicInputs { - let mut output = self.output.to_kernel_circuit_public_inputs(); + pub fn export_output(self) -> PrivateToRollupKernelCircuitPublicInputs { + let mut output = self.output.to_private_to_rollup_kernel_circuit_public_inputs(); output.gas_used = meter_gas_used(output.end); output } @@ -59,7 +59,7 @@ impl TailOutputValidatorBuilder { self.validate_with_output(output); } - pub fn validate_with_output(self, output: KernelCircuitPublicInputs) { + pub fn validate_with_output(self, output: PrivateToRollupKernelCircuitPublicInputs) { let previous_kernel = self.previous_kernel.to_private_kernel_circuit_public_inputs(); TailOutputValidator::new(output, previous_kernel).validate(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-simulated/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-simulated/src/main.nr index 285d20b1395..660fa1e8616 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-simulated/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-simulated/src/main.nr @@ -1,12 +1,12 @@ use dep::private_kernel_lib::PrivateKernelTailCircuitPrivateInputs; -use dep::types::KernelCircuitPublicInputs; +use dep::types::PrivateToRollupKernelCircuitPublicInputs; use types::abis::kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs; use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs; unconstrained fn main( previous_kernel: PrivateKernelDataWithoutPublicInputs, previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs, -) -> pub KernelCircuitPublicInputs { +) -> pub PrivateToRollupKernelCircuitPublicInputs { let private_inputs = PrivateKernelTailCircuitPrivateInputs::new(previous_kernel, previous_kernel_public_inputs); private_inputs.execute() diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail/src/main.nr index f520694f68b..caf2a6b8fef 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail/src/main.nr @@ -1,12 +1,12 @@ use dep::private_kernel_lib::PrivateKernelTailCircuitPrivateInputs; -use dep::types::KernelCircuitPublicInputs; +use dep::types::PrivateToRollupKernelCircuitPublicInputs; use types::abis::kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs; use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs; fn main( previous_kernel: PrivateKernelDataWithoutPublicInputs, previous_kernel_public_inputs: call_data(0) PrivateKernelCircuitPublicInputs, -) -> pub KernelCircuitPublicInputs { +) -> pub PrivateToRollupKernelCircuitPublicInputs { let private_inputs = PrivateKernelTailCircuitPrivateInputs::new(previous_kernel, previous_kernel_public_inputs); private_inputs.execute() 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 824a3977308..4aadab2ece4 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 @@ -234,7 +234,7 @@ mod tests { abis::{ append_only_tree_snapshot::AppendOnlyTreeSnapshot, constant_rollup_data::ConstantRollupData, gas::Gas, gas_fees::GasFees, - kernel_circuit_public_inputs::KernelCircuitPublicInputs, + kernel_circuit_public_inputs::PrivateToRollupKernelCircuitPublicInputs, nullifier_leaf_preimage::NullifierLeafPreimage, public_data_write::PublicDataWrite, sponge_blob::SpongeBlob, }, @@ -426,7 +426,7 @@ mod tests { fn update_nullifier_tree_with_new_leaves( mut self, nullifier_tree: &mut NonEmptyMerkleTree, - kernel_public_inputs: &mut KernelCircuitPublicInputs, + kernel_public_inputs: &mut PrivateToRollupKernelCircuitPublicInputs, start_nullifier_tree_snapshot: AppendOnlyTreeSnapshot, ) -> ([NullifierLeafPreimage; MAX_NULLIFIERS_PER_TX], [MembershipWitness; MAX_NULLIFIERS_PER_TX], [Field; MAX_NULLIFIERS_PER_TX], [u32; MAX_NULLIFIERS_PER_TX]) { let mut nullifier_predecessor_preimages = 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 1ecfc2bb0a7..f7adf7aba51 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 @@ -15,7 +15,7 @@ use crate::{ }; use dep::types::{ abis::{ - accumulated_data::{self, CombinedAccumulatedData}, + accumulated_data::{self, PrivateToRollupAccumulatedData}, append_only_tree_snapshot::AppendOnlyTreeSnapshot, avm_circuit_public_inputs::AvmProofData, combined_constant_data::CombinedConstantData, @@ -290,7 +290,7 @@ mod tests { use crate::abis::tx_effect::TxEffect; use dep::types::{ abis::{ - accumulated_data::CombinedAccumulatedData, + accumulated_data::PrivateToRollupAccumulatedData, append_only_tree_snapshot::AppendOnlyTreeSnapshot, constant_rollup_data::ConstantRollupData, nullifier_leaf_preimage::NullifierLeafPreimage, public_data_write::PublicDataWrite, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/mod.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/mod.nr index c61e2014a18..7d026503ab6 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/mod.nr @@ -1,5 +1,5 @@ pub mod avm_accumulated_data; -pub mod combined_accumulated_data; +pub mod private_to_rollup_accumulated_data; pub mod private_accumulated_data; pub mod private_accumulated_data_builder; pub mod private_to_avm_accumulated_data; @@ -7,9 +7,9 @@ pub mod private_to_public_accumulated_data; pub mod private_to_public_accumulated_data_builder; pub use avm_accumulated_data::AvmAccumulatedData; -pub use combined_accumulated_data::CombinedAccumulatedData; pub use private_accumulated_data::PrivateAccumulatedData; pub use private_accumulated_data_builder::PrivateAccumulatedDataBuilder; pub use private_to_avm_accumulated_data::PrivateToAvmAccumulatedData; pub use private_to_public_accumulated_data::PrivateToPublicAccumulatedData; pub use private_to_public_accumulated_data_builder::PrivateToPublicAccumulatedDataBuilder; +pub use private_to_rollup_accumulated_data::PrivateToRollupAccumulatedData; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_to_rollup_accumulated_data.nr similarity index 73% rename from noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr rename to noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_to_rollup_accumulated_data.nr index 55da457c5a7..1d34dab228a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_to_rollup_accumulated_data.nr @@ -1,15 +1,15 @@ use crate::{ abis::{log_hash::ScopedLogHash, private_log::PrivateLog}, constants::{ - COMBINED_ACCUMULATED_DATA_LENGTH, 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_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, PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH, }, messaging::l2_to_l1_message::ScopedL2ToL1Message, traits::{Deserialize, Empty, Serialize}, utils::reader::Reader, }; -pub struct CombinedAccumulatedData { +pub struct PrivateToRollupAccumulatedData { pub note_hashes: [Field; MAX_NOTE_HASHES_PER_TX], pub nullifiers: [Field; MAX_NULLIFIERS_PER_TX], pub l2_to_l1_msgs: [ScopedL2ToL1Message; MAX_L2_TO_L1_MSGS_PER_TX], @@ -22,9 +22,9 @@ pub struct CombinedAccumulatedData { pub contract_class_log_preimages_length: Field, } -impl Empty for CombinedAccumulatedData { +impl Empty for PrivateToRollupAccumulatedData { fn empty() -> Self { - CombinedAccumulatedData { + PrivateToRollupAccumulatedData { note_hashes: [0; MAX_NOTE_HASHES_PER_TX], nullifiers: [0; MAX_NULLIFIERS_PER_TX], l2_to_l1_msgs: [ScopedL2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_TX], @@ -35,9 +35,10 @@ impl Empty for CombinedAccumulatedData { } } -impl Serialize for CombinedAccumulatedData { - fn serialize(self) -> [Field; COMBINED_ACCUMULATED_DATA_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); +impl Serialize for PrivateToRollupAccumulatedData { + fn serialize(self) -> [Field; PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH] { + let mut fields: BoundedVec = + BoundedVec::new(); fields.extend_from_array(self.note_hashes); fields.extend_from_array(self.nullifiers); @@ -52,17 +53,19 @@ impl Serialize for CombinedAccumulatedData { } fields.push(self.contract_class_log_preimages_length); - assert_eq(fields.len(), COMBINED_ACCUMULATED_DATA_LENGTH); + assert_eq(fields.len(), PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH); fields.storage() } } -impl Deserialize for CombinedAccumulatedData { - fn deserialize(fields: [Field; COMBINED_ACCUMULATED_DATA_LENGTH]) -> CombinedAccumulatedData { +impl Deserialize for PrivateToRollupAccumulatedData { + fn deserialize( + fields: [Field; PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH], + ) -> PrivateToRollupAccumulatedData { let mut reader = Reader::new(fields); - let item = CombinedAccumulatedData { + let item = PrivateToRollupAccumulatedData { note_hashes: reader.read_array(), nullifiers: reader.read_array(), l2_to_l1_msgs: reader.read_struct_array( @@ -84,7 +87,7 @@ impl Deserialize for CombinedAccumulatedData { } } -impl Eq for CombinedAccumulatedData { +impl Eq for PrivateToRollupAccumulatedData { fn eq(self, other: Self) -> bool { (self.note_hashes == other.note_hashes) & (self.nullifiers == other.nullifiers) @@ -100,8 +103,8 @@ impl Eq for CombinedAccumulatedData { #[test] fn serialization_of_empty() { - let item = CombinedAccumulatedData::empty(); + let item = PrivateToRollupAccumulatedData::empty(); let serialized = item.serialize(); - let deserialized = CombinedAccumulatedData::deserialize(serialized); + let deserialized = PrivateToRollupAccumulatedData::deserialize(serialized); assert(item.eq(deserialized)); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/mod.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/mod.nr index 4cc319e29cd..478420ce48c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/mod.nr @@ -1,11 +1,11 @@ -pub mod kernel_circuit_public_inputs; +pub mod private_to_rollup_kernel_circuit_public_inputs; pub mod private_kernel_circuit_public_inputs; pub mod private_kernel_circuit_public_inputs_builder; pub mod private_to_public_kernel_circuit_public_inputs; -pub use kernel_circuit_public_inputs::KernelCircuitPublicInputs; pub use private_kernel_circuit_public_inputs::{ PrivateKernelCircuitPublicInputs, PrivateKernelCircuitPublicInputsArrayLengths, }; pub use private_kernel_circuit_public_inputs_builder::PrivateKernelCircuitPublicInputsBuilder; pub use private_to_public_kernel_circuit_public_inputs::PrivateToPublicKernelCircuitPublicInputs; +pub use private_to_rollup_kernel_circuit_public_inputs::PrivateToRollupKernelCircuitPublicInputs; 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/private_to_rollup_kernel_circuit_public_inputs.nr similarity index 55% rename from noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr rename to noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_rollup_kernel_circuit_public_inputs.nr index e0b8999c963..509e62604b6 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/private_to_rollup_kernel_circuit_public_inputs.nr @@ -1,27 +1,27 @@ use crate::{ abis::{ - accumulated_data::CombinedAccumulatedData, gas::Gas, tx_constant_data::TxConstantData, - validation_requests::RollupValidationRequests, + accumulated_data::PrivateToRollupAccumulatedData, gas::Gas, + tx_constant_data::TxConstantData, validation_requests::RollupValidationRequests, }, address::AztecAddress, - constants::KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, + constants::PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, traits::{Deserialize, Empty, Serialize}, utils::reader::Reader, }; -pub struct KernelCircuitPublicInputs { +pub struct PrivateToRollupKernelCircuitPublicInputs { pub constants: TxConstantData, pub rollup_validation_requests: RollupValidationRequests, - pub end: CombinedAccumulatedData, + pub end: PrivateToRollupAccumulatedData, pub gas_used: Gas, pub fee_payer: AztecAddress, } -impl Empty for KernelCircuitPublicInputs { +impl Empty for PrivateToRollupKernelCircuitPublicInputs { fn empty() -> Self { - KernelCircuitPublicInputs { + PrivateToRollupKernelCircuitPublicInputs { rollup_validation_requests: RollupValidationRequests::empty(), - end: CombinedAccumulatedData::empty(), + end: PrivateToRollupAccumulatedData::empty(), constants: TxConstantData::empty(), gas_used: Gas::empty(), fee_payer: AztecAddress::empty(), @@ -29,7 +29,7 @@ impl Empty for KernelCircuitPublicInputs { } } -impl Eq for KernelCircuitPublicInputs { +impl Eq for PrivateToRollupKernelCircuitPublicInputs { fn eq(self, other: Self) -> bool { (self.rollup_validation_requests.eq(other.rollup_validation_requests)) & (self.end.eq(other.end)) @@ -39,9 +39,10 @@ impl Eq for KernelCircuitPublicInputs { } } -impl Serialize for KernelCircuitPublicInputs { - fn serialize(self) -> [Field; KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); +impl Serialize for PrivateToRollupKernelCircuitPublicInputs { + fn serialize(self) -> [Field; PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH] { + let mut fields: BoundedVec = + BoundedVec::new(); fields.extend_from_array(self.rollup_validation_requests.serialize()); fields.extend_from_array(self.end.serialize()); @@ -49,20 +50,20 @@ impl Serialize for KernelCircuitPublicInput fields.extend_from_array(self.gas_used.serialize()); fields.extend_from_array(self.fee_payer.serialize()); - assert_eq(fields.len(), KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); + assert_eq(fields.len(), PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); fields.storage() } } -impl Deserialize for KernelCircuitPublicInputs { +impl Deserialize for PrivateToRollupKernelCircuitPublicInputs { fn deserialize( - fields: [Field; KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH], - ) -> KernelCircuitPublicInputs { + fields: [Field; PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH], + ) -> PrivateToRollupKernelCircuitPublicInputs { let mut reader = Reader::new(fields); let item = Self { rollup_validation_requests: reader.read_struct(RollupValidationRequests::deserialize), - end: reader.read_struct(CombinedAccumulatedData::deserialize), + end: reader.read_struct(PrivateToRollupAccumulatedData::deserialize), constants: reader.read_struct(TxConstantData::deserialize), gas_used: reader.read_struct(Gas::deserialize), fee_payer: reader.read_struct(AztecAddress::deserialize), @@ -75,8 +76,8 @@ impl Deserialize for KernelCircuitPublicInp #[test] fn serialization_of_empty_kernel_circuit_public_inputs() { - let item = KernelCircuitPublicInputs::empty(); + let item = PrivateToRollupKernelCircuitPublicInputs::empty(); let serialized = item.serialize(); - let deserialized = KernelCircuitPublicInputs::deserialize(serialized); + let deserialized = PrivateToRollupKernelCircuitPublicInputs::deserialize(serialized); assert(item.eq(deserialized)); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/tube.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/tube.nr index a7541275ae0..747c2b3d182 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/tube.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/tube.nr @@ -1,6 +1,6 @@ use crate::{ abis::kernel_circuit_public_inputs::{ - KernelCircuitPublicInputs, PrivateToPublicKernelCircuitPublicInputs, + PrivateToPublicKernelCircuitPublicInputs, PrivateToRollupKernelCircuitPublicInputs, }, constants::{PROOF_TYPE_ROLLUP_HONK, ROLLUP_HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS}, proof::{traits::Verifiable, tube_proof::TubeProof, vk_data::VkData}, @@ -26,14 +26,14 @@ impl Verifiable for PublicTubeData { } pub struct PrivateTubeData { - pub public_inputs: KernelCircuitPublicInputs, + pub public_inputs: PrivateToRollupKernelCircuitPublicInputs, pub proof: TubeProof, pub vk_data: VkData, } impl Verifiable for PrivateTubeData { fn verify(self) { - let inputs = KernelCircuitPublicInputs::serialize(self.public_inputs); + let inputs = PrivateToRollupKernelCircuitPublicInputs::serialize(self.public_inputs); std::verify_proof_with_type( self.vk_data.vk.key, self.proof.fields, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 1d19fa0b48d..823245d3038 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -334,7 +334,7 @@ pub global PRIVATE_VALIDATION_REQUESTS_LENGTH: u32 = ROLLUP_VALIDATION_REQUESTS_ + (SCOPED_KEY_VALIDATION_REQUEST_AND_GENERATOR_LENGTH * MAX_KEY_VALIDATION_REQUESTS_PER_TX) + 2; -pub global COMBINED_ACCUMULATED_DATA_LENGTH: u32 = MAX_NOTE_HASHES_PER_TX +pub global PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH: u32 = MAX_NOTE_HASHES_PER_TX + MAX_NULLIFIERS_PER_TX + (MAX_L2_TO_L1_MSGS_PER_TX * SCOPED_L2_TO_L1_MESSAGE_LENGTH) + (PRIVATE_LOG_SIZE_IN_FIELDS * MAX_PRIVATE_LOGS_PER_TX) @@ -388,8 +388,8 @@ pub global PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = TX_CONST + GAS_LENGTH /* gas_used */ + AZTEC_ADDRESS_LENGTH /* fee_payer */; -pub global KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = ROLLUP_VALIDATION_REQUESTS_LENGTH - + COMBINED_ACCUMULATED_DATA_LENGTH +pub global PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = ROLLUP_VALIDATION_REQUESTS_LENGTH + + PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH + TX_CONSTANT_DATA_LENGTH + GAS_LENGTH /* gas_used */ + AZTEC_ADDRESS_LENGTH; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr b/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr index e4e638b113d..024d17987ee 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr @@ -31,5 +31,5 @@ pub mod meta; pub mod indexed_tagging_secret; pub use abis::kernel_circuit_public_inputs::{ - KernelCircuitPublicInputs, PrivateKernelCircuitPublicInputs, + PrivateKernelCircuitPublicInputs, PrivateToRollupKernelCircuitPublicInputs, }; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index eabf75d54c1..329155afadd 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -1,8 +1,9 @@ use crate::{ abis::{ accumulated_data::{ - avm_accumulated_data::AvmAccumulatedData, CombinedAccumulatedData, - PrivateAccumulatedData, PrivateAccumulatedDataBuilder, PrivateToPublicAccumulatedData, + avm_accumulated_data::AvmAccumulatedData, PrivateAccumulatedData, + PrivateAccumulatedDataBuilder, PrivateToPublicAccumulatedData, + PrivateToRollupAccumulatedData, }, append_only_tree_snapshot::AppendOnlyTreeSnapshot, avm_circuit_public_inputs::AvmProofData, @@ -14,8 +15,8 @@ use crate::{ gas_settings::GasSettings, global_variables::GlobalVariables, kernel_circuit_public_inputs::{ - KernelCircuitPublicInputs, PrivateKernelCircuitPublicInputs, - PrivateToPublicKernelCircuitPublicInputs, + PrivateKernelCircuitPublicInputs, PrivateToPublicKernelCircuitPublicInputs, + PrivateToRollupKernelCircuitPublicInputs, }, log::Log, log_hash::{LogHash, ScopedLogHash}, @@ -436,8 +437,8 @@ impl FixtureBuilder { } } - pub fn to_combined_accumulated_data(self) -> CombinedAccumulatedData { - CombinedAccumulatedData { + pub fn to_private_to_rollup_accumulated_data(self) -> PrivateToRollupAccumulatedData { + PrivateToRollupAccumulatedData { note_hashes: self.note_hashes.storage().map(|n: ScopedNoteHash| n.note_hash.value), nullifiers: self.nullifiers.storage().map(|n: ScopedNullifier| n.nullifier.value), l2_to_l1_msgs: self.l2_to_l1_msgs.storage().map(|m: ScopedL2ToL1Message| { @@ -522,12 +523,14 @@ impl FixtureBuilder { RollupValidationRequests { max_block_number: self.max_block_number } } - pub fn to_kernel_circuit_public_inputs(self) -> KernelCircuitPublicInputs { + pub fn to_private_to_rollup_kernel_circuit_public_inputs( + self, + ) -> PrivateToRollupKernelCircuitPublicInputs { let rollup_validation_requests = self.to_rollup_validation_requests(); - let end = self.to_combined_accumulated_data(); + let end = self.to_private_to_rollup_accumulated_data(); let constants = self.to_tx_constant_data(); - KernelCircuitPublicInputs { + PrivateToRollupKernelCircuitPublicInputs { rollup_validation_requests, end, constants, @@ -538,7 +541,7 @@ impl FixtureBuilder { pub fn to_private_tube_data(self) -> PrivateTubeData { let mut result: PrivateTubeData = std::mem::zeroed(); - result.public_inputs = self.to_kernel_circuit_public_inputs(); + result.public_inputs = self.to_private_to_rollup_kernel_circuit_public_inputs(); result } diff --git a/yarn-project/bb-prover/src/prover/bb_prover.ts b/yarn-project/bb-prover/src/prover/bb_prover.ts index 9eb66ac7576..1f6f3706275 100644 --- a/yarn-project/bb-prover/src/prover/bb_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_prover.ts @@ -17,12 +17,12 @@ import { EmptyNestedData, Fr, IPA_CLAIM_LENGTH, - type KernelCircuitPublicInputs, NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, type ParityPublicInputs, type PrivateKernelEmptyInputData, PrivateKernelEmptyInputs, + type PrivateToRollupKernelCircuitPublicInputs, Proof, RECURSIVE_PROOF_LENGTH, RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, @@ -390,7 +390,10 @@ export class BBNativeRollupProver implements ServerCircuitProver { public async getEmptyPrivateKernelProof( inputs: PrivateKernelEmptyInputData, ): Promise< - PublicInputsAndRecursiveProof + PublicInputsAndRecursiveProof< + PrivateToRollupKernelCircuitPublicInputs, + typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH + > > { const emptyNested = await this.getEmptyNestedProof(); const emptyPrivateKernelProof = await this.getEmptyPrivateKernelProofFromEmptyNested( @@ -426,7 +429,10 @@ export class BBNativeRollupProver implements ServerCircuitProver { private async getEmptyPrivateKernelProofFromEmptyNested( inputs: PrivateKernelEmptyInputs, ): Promise< - PublicInputsAndRecursiveProof + PublicInputsAndRecursiveProof< + PrivateToRollupKernelCircuitPublicInputs, + typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH + > > { const { circuitOutput, proof } = await this.createRecursiveProof( inputs, diff --git a/yarn-project/bb-prover/src/test/test_circuit_prover.ts b/yarn-project/bb-prover/src/test/test_circuit_prover.ts index 70257ec280b..b1d9f46a308 100644 --- a/yarn-project/bb-prover/src/test/test_circuit_prover.ts +++ b/yarn-project/bb-prover/src/test/test_circuit_prover.ts @@ -11,12 +11,12 @@ import { type AvmCircuitInputs, type BaseParityInputs, EmptyNestedData, - type KernelCircuitPublicInputs, NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, type ParityPublicInputs, type PrivateKernelEmptyInputData, PrivateKernelEmptyInputs, + type PrivateToRollupKernelCircuitPublicInputs, type Proof, RECURSIVE_PROOF_LENGTH, type RootParityInputs, @@ -98,7 +98,10 @@ export class TestCircuitProver implements ServerCircuitProver { public async getEmptyPrivateKernelProof( inputs: PrivateKernelEmptyInputData, ): Promise< - PublicInputsAndRecursiveProof + PublicInputsAndRecursiveProof< + PrivateToRollupKernelCircuitPublicInputs, + typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH + > > { const emptyNested = new EmptyNestedData( makeRecursiveProof(NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH), diff --git a/yarn-project/circuit-types/src/interfaces/proving-job.ts b/yarn-project/circuit-types/src/interfaces/proving-job.ts index 331f914224f..542ce92c39e 100644 --- a/yarn-project/circuit-types/src/interfaces/proving-job.ts +++ b/yarn-project/circuit-types/src/interfaces/proving-job.ts @@ -2,11 +2,11 @@ import { AVM_PROOF_LENGTH_IN_FIELDS, AvmCircuitInputs, BaseParityInputs, - KernelCircuitPublicInputs, NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, ParityPublicInputs, PrivateKernelEmptyInputData, + PrivateToRollupKernelCircuitPublicInputs, RECURSIVE_PROOF_LENGTH, RecursiveProof, RootParityInputs, @@ -168,7 +168,7 @@ export const ProvingJobResult = z.discriminatedUnion('type', [ z.object({ type: z.literal(ProvingRequestType.PRIVATE_KERNEL_EMPTY), result: schemaForPublicInputsAndRecursiveProof( - KernelCircuitPublicInputs.schema, + PrivateToRollupKernelCircuitPublicInputs.schema, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, ), }), @@ -238,7 +238,7 @@ export const ProvingJobResult = z.discriminatedUnion('type', [ export type ProvingJobResult = z.infer; export type ProvingJobResultsMap = { [ProvingRequestType.PRIVATE_KERNEL_EMPTY]: PublicInputsAndRecursiveProof< - KernelCircuitPublicInputs, + PrivateToRollupKernelCircuitPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH >; [ProvingRequestType.PUBLIC_VM]: ProofAndVerificationKey; diff --git a/yarn-project/circuit-types/src/interfaces/server_circuit_prover.ts b/yarn-project/circuit-types/src/interfaces/server_circuit_prover.ts index 5143bd42708..c1ffc5a9f27 100644 --- a/yarn-project/circuit-types/src/interfaces/server_circuit_prover.ts +++ b/yarn-project/circuit-types/src/interfaces/server_circuit_prover.ts @@ -2,11 +2,11 @@ import { type AVM_PROOF_LENGTH_IN_FIELDS, type AvmCircuitInputs, type BaseParityInputs, - type KernelCircuitPublicInputs, type NESTED_RECURSIVE_PROOF_LENGTH, type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, type ParityPublicInputs, type PrivateKernelEmptyInputData, + type PrivateToRollupKernelCircuitPublicInputs, type RECURSIVE_PROOF_LENGTH, type RootParityInputs, type TUBE_PROOF_LENGTH, @@ -145,7 +145,10 @@ export interface ServerCircuitProver { signal?: AbortSignal, epochNumber?: number, ): Promise< - PublicInputsAndRecursiveProof + PublicInputsAndRecursiveProof< + PrivateToRollupKernelCircuitPublicInputs, + typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH + > >; /** diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 00cc1a9beac..45a9f4c4203 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -173,7 +173,7 @@ export const IPA_CLAIM_LENGTH = 10; export const SCOPED_READ_REQUEST_LEN = 3; export const PUBLIC_DATA_READ_LENGTH = 3; export const PRIVATE_VALIDATION_REQUESTS_LENGTH = 772; -export const COMBINED_ACCUMULATED_DATA_LENGTH = 902; +export const PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH = 902; export const TX_CONSTANT_DATA_LENGTH = 37; export const COMBINED_CONSTANT_DATA_LENGTH = 46; export const PRIVATE_ACCUMULATED_DATA_LENGTH = 1412; @@ -183,7 +183,7 @@ export const PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH = 160; export const NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS = 3; export const AVM_ACCUMULATED_DATA_LENGTH = 320; export const PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1847; -export const KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 960; +export const PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 960; export const AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1011; export const CONSTANT_ROLLUP_DATA_LENGTH = 13; export const BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 52; diff --git a/yarn-project/circuits.js/src/structs/index.ts b/yarn-project/circuits.js/src/structs/index.ts index 68d640ebf13..e4d61d294ac 100644 --- a/yarn-project/circuits.js/src/structs/index.ts +++ b/yarn-project/circuits.js/src/structs/index.ts @@ -16,7 +16,7 @@ export * from './gas_settings.js'; export * from './global_variables.js'; export * from './block_header.js'; export * from './indexed_tagging_secret.js'; -export * from './kernel/combined_accumulated_data.js'; +export * from './kernel/private_to_rollup_accumulated_data.js'; export * from './kernel/combined_constant_data.js'; export * from './kernel/private_kernel_empty_inputs.js'; export * from './kernel/kernel_circuit_public_inputs.js'; diff --git a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts index 0e8286c174f..c0fecd8b999 100644 --- a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts @@ -5,14 +5,14 @@ import { bufferToHex, hexToBuffer } from '@aztec/foundation/string'; import { Gas } from '../gas.js'; import { RollupValidationRequests } from '../rollup_validation_requests.js'; -import { CombinedAccumulatedData } from './combined_accumulated_data.js'; +import { PrivateToRollupAccumulatedData } from './private_to_rollup_accumulated_data.js'; import { TxConstantData } from './tx_constant_data.js'; /** * Outputs from the public kernel circuits. * All Public kernels use this shape for outputs. */ -export class KernelCircuitPublicInputs { +export class PrivateToRollupKernelCircuitPublicInputs { constructor( /** * Validation requests accumulated from private and public execution to be completed by the rollup. @@ -21,7 +21,7 @@ export class KernelCircuitPublicInputs { /** * Data accumulated from both public and private circuits. */ - public end: CombinedAccumulatedData, + public end: PrivateToRollupAccumulatedData, /** * Data which is not modified by the circuits. */ @@ -47,13 +47,13 @@ export class KernelCircuitPublicInputs { /** * Deserializes from a buffer or reader, corresponding to a write in cpp. * @param buffer - Buffer or reader to read from. - * @returns A new instance of KernelCircuitPublicInputs. + * @returns A new instance of PrivateToRollupKernelCircuitPublicInputs. */ - static fromBuffer(buffer: Buffer | BufferReader): KernelCircuitPublicInputs { + static fromBuffer(buffer: Buffer | BufferReader): PrivateToRollupKernelCircuitPublicInputs { const reader = BufferReader.asReader(buffer); - return new KernelCircuitPublicInputs( + return new PrivateToRollupKernelCircuitPublicInputs( reader.readObject(RollupValidationRequests), - reader.readObject(CombinedAccumulatedData), + reader.readObject(PrivateToRollupAccumulatedData), reader.readObject(TxConstantData), reader.readObject(Gas), reader.readObject(AztecAddress), @@ -61,9 +61,9 @@ export class KernelCircuitPublicInputs { } static empty() { - return new KernelCircuitPublicInputs( + return new PrivateToRollupKernelCircuitPublicInputs( RollupValidationRequests.empty(), - CombinedAccumulatedData.empty(), + PrivateToRollupAccumulatedData.empty(), TxConstantData.empty(), Gas.empty(), AztecAddress.ZERO, @@ -75,7 +75,7 @@ export class KernelCircuitPublicInputs { } static fromString(str: string) { - return KernelCircuitPublicInputs.fromBuffer(hexToBuffer(str)); + return PrivateToRollupKernelCircuitPublicInputs.fromBuffer(hexToBuffer(str)); } /** Returns a hex representation for JSON serialization. */ @@ -85,6 +85,6 @@ export class KernelCircuitPublicInputs { /** Creates an instance from a hex string. */ static get schema() { - return bufferSchemaFor(KernelCircuitPublicInputs); + return bufferSchemaFor(PrivateToRollupKernelCircuitPublicInputs); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts index 54e13f65d18..1b2af0296a4 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts @@ -8,11 +8,11 @@ import { Gas } from '../gas.js'; import { GlobalVariables } from '../global_variables.js'; import { PublicCallRequest } from '../public_call_request.js'; import { RollupValidationRequests } from '../rollup_validation_requests.js'; -import { CombinedAccumulatedData } from './combined_accumulated_data.js'; import { CombinedConstantData } from './combined_constant_data.js'; -import { KernelCircuitPublicInputs } from './kernel_circuit_public_inputs.js'; +import { PrivateToRollupKernelCircuitPublicInputs } from './kernel_circuit_public_inputs.js'; import { PrivateToPublicAccumulatedData } from './private_to_public_accumulated_data.js'; import { PrivateToPublicKernelCircuitPublicInputs } from './private_to_public_kernel_circuit_public_inputs.js'; +import { PrivateToRollupAccumulatedData } from './private_to_rollup_accumulated_data.js'; import { TxConstantData } from './tx_constant_data.js'; export class PartialPrivateTailPublicInputsForPublic { @@ -78,11 +78,11 @@ export class PartialPrivateTailPublicInputsForPublic { } export class PartialPrivateTailPublicInputsForRollup { - constructor(public end: CombinedAccumulatedData) {} + constructor(public end: PrivateToRollupAccumulatedData) {} static fromBuffer(buffer: Buffer | BufferReader): PartialPrivateTailPublicInputsForRollup { const reader = BufferReader.asReader(buffer); - return new PartialPrivateTailPublicInputsForRollup(reader.readObject(CombinedAccumulatedData)); + return new PartialPrivateTailPublicInputsForRollup(reader.readObject(PrivateToRollupAccumulatedData)); } getSize() { @@ -94,7 +94,7 @@ export class PartialPrivateTailPublicInputsForRollup { } static empty() { - return new PartialPrivateTailPublicInputsForRollup(CombinedAccumulatedData.empty()); + return new PartialPrivateTailPublicInputsForRollup(PrivateToRollupAccumulatedData.empty()); } } @@ -161,7 +161,7 @@ export class PrivateKernelTailCircuitPublicInputs { ); } - toKernelCircuitPublicInputs() { + toPrivateToRollupKernelCircuitPublicInputs() { if (!this.forRollup) { throw new Error('Private tail public inputs is not for rollup circuit.'); } @@ -172,7 +172,7 @@ export class PrivateKernelTailCircuitPublicInputs { this.constants.protocolContractTreeRoot, GlobalVariables.empty(), ); - return new KernelCircuitPublicInputs( + return new PrivateToRollupKernelCircuitPublicInputs( this.rollupValidationRequests, this.forRollup.end, constants, @@ -288,7 +288,7 @@ export class PrivateKernelTailCircuitPublicInputs { * TODO(#9269): Remove this method as we move away from 1st nullifier as hash. */ static emptyWithNullifier() { - const data = CombinedAccumulatedData.empty(); + const data = PrivateToRollupAccumulatedData.empty(); data.nullifiers[0] = Fr.random(); return new PrivateKernelTailCircuitPublicInputs( TxConstantData.empty(), diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.test.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.test.ts similarity index 53% rename from yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.test.ts rename to yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.test.ts index 64cbcb0cd1d..f7865fde17f 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.test.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.test.ts @@ -1,10 +1,10 @@ import { makeCombinedAccumulatedData } from '../../tests/factories.js'; -import { CombinedAccumulatedData } from './combined_accumulated_data.js'; +import { PrivateToRollupAccumulatedData } from './private_to_rollup_accumulated_data.js'; -describe('CombinedAccumulatedData', () => { +describe('PrivateToRollupAccumulatedData', () => { it('Data after serialization and deserialization is equal to the original', () => { const original = makeCombinedAccumulatedData(); - const afterSerialization = CombinedAccumulatedData.fromBuffer(original.toBuffer()); + const afterSerialization = PrivateToRollupAccumulatedData.fromBuffer(original.toBuffer()); expect(original).toEqual(afterSerialization); }); }); diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts similarity index 85% rename from yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts rename to yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts index c5c65cac179..fc3fcc0b9cb 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts @@ -21,7 +21,7 @@ import { PrivateLog } from '../private_log.js'; /** * Data that is accumulated during the execution of the transaction. */ -export class CombinedAccumulatedData { +export class PrivateToRollupAccumulatedData { constructor( /** * The new note hashes made in this transaction. @@ -61,7 +61,7 @@ export class CombinedAccumulatedData { ); } - static getFields(fields: FieldsOf) { + static getFields(fields: FieldsOf) { return [ fields.noteHashes, fields.nullifiers, @@ -72,12 +72,12 @@ export class CombinedAccumulatedData { ] as const; } - static from(fields: FieldsOf): CombinedAccumulatedData { - return new CombinedAccumulatedData(...CombinedAccumulatedData.getFields(fields)); + static from(fields: FieldsOf): PrivateToRollupAccumulatedData { + return new PrivateToRollupAccumulatedData(...PrivateToRollupAccumulatedData.getFields(fields)); } static get schema() { - return bufferSchemaFor(CombinedAccumulatedData); + return bufferSchemaFor(PrivateToRollupAccumulatedData); } toJSON() { @@ -85,7 +85,7 @@ export class CombinedAccumulatedData { } toBuffer() { - return serializeToBuffer(...CombinedAccumulatedData.getFields(this)); + return serializeToBuffer(...PrivateToRollupAccumulatedData.getFields(this)); } toString() { @@ -97,9 +97,9 @@ export class CombinedAccumulatedData { * @param buffer - Buffer or reader to read from. * @returns Deserialized object. */ - static fromBuffer(buffer: Buffer | BufferReader): CombinedAccumulatedData { + static fromBuffer(buffer: Buffer | BufferReader): PrivateToRollupAccumulatedData { const reader = BufferReader.asReader(buffer); - return new CombinedAccumulatedData( + return new PrivateToRollupAccumulatedData( reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr), reader.readArray(MAX_NULLIFIERS_PER_TX, Fr), reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message), @@ -115,11 +115,11 @@ export class CombinedAccumulatedData { * @returns Deserialized object. */ static fromString(str: string) { - return CombinedAccumulatedData.fromBuffer(hexToBuffer(str)); + return PrivateToRollupAccumulatedData.fromBuffer(hexToBuffer(str)); } static empty() { - return new CombinedAccumulatedData( + return new PrivateToRollupAccumulatedData( makeTuple(MAX_NOTE_HASHES_PER_TX, Fr.zero), makeTuple(MAX_NULLIFIERS_PER_TX, Fr.zero), makeTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message.empty), @@ -130,7 +130,7 @@ export class CombinedAccumulatedData { } [inspect.custom]() { - return `CombinedAccumulatedData { + return `PrivateToRollupAccumulatedData { noteHashes: [${this.noteHashes .filter(x => !x.isZero()) .map(x => inspect(x)) diff --git a/yarn-project/circuits.js/src/structs/rollup/private_tube_data.ts b/yarn-project/circuits.js/src/structs/rollup/private_tube_data.ts index 342b5b388a9..b574dbc49b2 100644 --- a/yarn-project/circuits.js/src/structs/rollup/private_tube_data.ts +++ b/yarn-project/circuits.js/src/structs/rollup/private_tube_data.ts @@ -1,20 +1,20 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '../../constants.gen.js'; -import { KernelCircuitPublicInputs } from '../kernel/kernel_circuit_public_inputs.js'; +import { PrivateToRollupKernelCircuitPublicInputs } from '../kernel/kernel_circuit_public_inputs.js'; import { RecursiveProof, makeEmptyRecursiveProof } from '../recursive_proof.js'; import { VkWitnessData } from '../vk_witness_data.js'; export class PrivateTubeData { constructor( - public publicInputs: KernelCircuitPublicInputs, + public publicInputs: PrivateToRollupKernelCircuitPublicInputs, public proof: RecursiveProof, public vkData: VkWitnessData, ) {} static empty() { return new PrivateTubeData( - KernelCircuitPublicInputs.empty(), + PrivateToRollupKernelCircuitPublicInputs.empty(), makeEmptyRecursiveProof(NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH), VkWitnessData.empty(), ); @@ -23,7 +23,7 @@ export class PrivateTubeData { static fromBuffer(buffer: Buffer | BufferReader) { const reader = BufferReader.asReader(buffer); return new PrivateTubeData( - reader.readObject(KernelCircuitPublicInputs), + reader.readObject(PrivateToRollupKernelCircuitPublicInputs), RecursiveProof.fromBuffer(reader, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH), reader.readObject(VkWitnessData), ); diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 25427e95532..3b4e33c665a 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -26,7 +26,6 @@ import { BLOBS_PER_BLOCK, BaseParityInputs, CallContext, - CombinedAccumulatedData, CombinedConstantData, ContractStorageRead, ContractStorageUpdateRequest, @@ -81,6 +80,7 @@ import { PrivateCallRequest, PrivateCircuitPublicInputs, PrivateKernelTailCircuitPublicInputs, + PrivateToRollupAccumulatedData, Proof, PublicCallRequest, PublicCircuitPublicInputs, @@ -140,7 +140,7 @@ import { TxConstantData, VkWitnessData, } from '../structs/index.js'; -import { KernelCircuitPublicInputs } from '../structs/kernel/kernel_circuit_public_inputs.js'; +import { PrivateToRollupKernelCircuitPublicInputs } from '../structs/kernel/kernel_circuit_public_inputs.js'; import { AvmProofData } from '../structs/rollup/avm_proof_data.js'; import { BaseOrMergeRollupPublicInputs } from '../structs/rollup/base_or_merge_rollup_public_inputs.js'; import { PrivateBaseRollupHints, PublicBaseRollupHints } from '../structs/rollup/base_rollup_hints.js'; @@ -303,10 +303,10 @@ export function makeCombinedConstantData(seed = 1): CombinedConstantData { * @param seed - The seed to use for generating the accumulated data. * @returns An accumulated data. */ -export function makeCombinedAccumulatedData(seed = 1, full = false): CombinedAccumulatedData { +export function makeCombinedAccumulatedData(seed = 1, full = false): PrivateToRollupAccumulatedData { const tupleGenerator = full ? makeTuple : makeHalfFullTuple; - return new CombinedAccumulatedData( + return new PrivateToRollupAccumulatedData( tupleGenerator(MAX_NOTE_HASHES_PER_TX, fr, seed + 0x120, Fr.zero), tupleGenerator(MAX_NULLIFIERS_PER_TX, fr, seed + 0x200, Fr.zero), tupleGenerator(MAX_L2_TO_L1_MSGS_PER_TX, makeScopedL2ToL1Message, seed + 0x600, ScopedL2ToL1Message.empty), @@ -414,8 +414,11 @@ function makePrivateToPublicKernelCircuitPublicInputs(seed = 1) { * @param seed - The seed to use for generating the kernel circuit public inputs. * @returns Public kernel circuit public inputs. */ -export function makeKernelCircuitPublicInputs(seed = 1, fullAccumulatedData = true): KernelCircuitPublicInputs { - return new KernelCircuitPublicInputs( +export function makePrivateToRollupKernelCircuitPublicInputs( + seed = 1, + fullAccumulatedData = true, +): PrivateToRollupKernelCircuitPublicInputs { + return new PrivateToRollupKernelCircuitPublicInputs( makeRollupValidationRequests(seed), makeCombinedAccumulatedData(seed, fullAccumulatedData), makeCombinedConstantData(seed + 0x100), @@ -1111,9 +1114,9 @@ function makeVkWitnessData(seed = 1) { return new VkWitnessData(VerificationKeyData.makeFakeHonk(), seed, makeTuple(VK_TREE_HEIGHT, fr, seed + 0x100)); } -function makePrivateTubeData(seed = 1, kernelPublicInputs?: KernelCircuitPublicInputs) { +function makePrivateTubeData(seed = 1, kernelPublicInputs?: PrivateToRollupKernelCircuitPublicInputs) { return new PrivateTubeData( - kernelPublicInputs ?? makeKernelCircuitPublicInputs(seed, true), + kernelPublicInputs ?? makePrivateToRollupKernelCircuitPublicInputs(seed, true), makeRecursiveProof(TUBE_PROOF_LENGTH, seed + 0x100), makeVkWitnessData(seed + 0x200), ); diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/client.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/client.ts index 5ac5dbc4918..461a0c809eb 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/client.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/client.ts @@ -61,7 +61,6 @@ import type { Counted as CountedPublicCallRequestNoir, FixedLengthArray, FunctionData as FunctionDataNoir, - KernelCircuitPublicInputs as KernelCircuitPublicInputsNoir, KeyValidationHint as KeyValidationHintNoir, KeyValidationRequestAndGenerator as KeyValidationRequestAndGeneratorNoir, KeyValidationRequest as KeyValidationRequestsNoir, @@ -84,6 +83,7 @@ import type { PrivateLogData as PrivateLogDataNoir, PrivateToPublicAccumulatedData as PrivateToPublicAccumulatedDataNoir, PrivateToPublicKernelCircuitPublicInputs as PrivateToPublicKernelCircuitPublicInputsNoir, + PrivateToRollupKernelCircuitPublicInputs as PrivateToRollupKernelCircuitPublicInputsNoir, PrivateValidationRequests as PrivateValidationRequestsNoir, PublicKeys as PublicKeysNoir, ReadRequest as ReadRequestNoir, @@ -683,7 +683,7 @@ export function mapPrivateKernelDataToNoir( } export function mapPrivateKernelTailCircuitPublicInputsForRollupFromNoir( - inputs: KernelCircuitPublicInputsNoir, + inputs: PrivateToRollupKernelCircuitPublicInputsNoir, ): PrivateKernelTailCircuitPublicInputs { const forRollup = new PartialPrivateTailPublicInputsForRollup(mapCombinedAccumulatedDataFromNoir(inputs.end)); return new PrivateKernelTailCircuitPublicInputs( diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts index c23c7df708f..a1f964e8e93 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts @@ -2,7 +2,6 @@ import { AppendOnlyTreeSnapshot, AztecAddress, BlockHeader, - CombinedAccumulatedData, ContentCommitment, EthAddress, Fr, @@ -27,6 +26,7 @@ import { PartialStateReference, Point, PrivateLog, + PrivateToRollupAccumulatedData, PublicCallRequest, type PublicDataTreeLeafPreimage, type PublicDataWrite, @@ -42,7 +42,7 @@ import { type Tuple, mapTuple, toTruncField } from '@aztec/foundation/serialize' import type { AppendOnlyTreeSnapshot as AppendOnlyTreeSnapshotNoir, BlockHeader as BlockHeaderNoir, - CombinedAccumulatedData as CombinedAccumulatedDataNoir, + PrivateToRollupAccumulatedData as CombinedAccumulatedDataNoir, ContentCommitment as ContentCommitmentNoir, Field, FixedLengthArray, @@ -667,22 +667,26 @@ export function mapPublicDataWriteToNoir(write: PublicDataWrite): PublicDataWrit /** * Maps combined accumulated data from noir to the parsed type. - * @param combinedAccumulatedData - The noir combined accumulated data. + * @param PrivateToRollupAccumulatedData - The noir combined accumulated data. * @returns The parsed combined accumulated data. */ -export function mapCombinedAccumulatedDataFromNoir(combinedAccumulatedData: CombinedAccumulatedDataNoir) { - return new CombinedAccumulatedData( - mapTupleFromNoir(combinedAccumulatedData.note_hashes, MAX_NOTE_HASHES_PER_TX, mapFieldFromNoir), - mapTupleFromNoir(combinedAccumulatedData.nullifiers, MAX_NULLIFIERS_PER_TX, mapFieldFromNoir), - mapTupleFromNoir(combinedAccumulatedData.l2_to_l1_msgs, MAX_L2_TO_L1_MSGS_PER_TX, mapScopedL2ToL1MessageFromNoir), - mapTupleFromNoir(combinedAccumulatedData.private_logs, MAX_PRIVATE_LOGS_PER_TX, mapPrivateLogFromNoir), +export function mapCombinedAccumulatedDataFromNoir(PrivateToRollupAccumulatedData: CombinedAccumulatedDataNoir) { + return new PrivateToRollupAccumulatedData( + mapTupleFromNoir(PrivateToRollupAccumulatedData.note_hashes, MAX_NOTE_HASHES_PER_TX, mapFieldFromNoir), + mapTupleFromNoir(PrivateToRollupAccumulatedData.nullifiers, MAX_NULLIFIERS_PER_TX, mapFieldFromNoir), + mapTupleFromNoir( + PrivateToRollupAccumulatedData.l2_to_l1_msgs, + MAX_L2_TO_L1_MSGS_PER_TX, + mapScopedL2ToL1MessageFromNoir, + ), + mapTupleFromNoir(PrivateToRollupAccumulatedData.private_logs, MAX_PRIVATE_LOGS_PER_TX, mapPrivateLogFromNoir), mapTupleFromNoir( - combinedAccumulatedData.contract_class_logs_hashes, + PrivateToRollupAccumulatedData.contract_class_logs_hashes, MAX_CONTRACT_CLASS_LOGS_PER_TX, mapScopedLogHashFromNoir, ), - mapFieldFromNoir(combinedAccumulatedData.contract_class_log_preimages_length), + mapFieldFromNoir(PrivateToRollupAccumulatedData.contract_class_log_preimages_length), ); } diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts index 6e1692361b5..fe54ba9d155 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts @@ -6,11 +6,9 @@ import { type AvmCircuitPublicInputs, BLOBS_PER_BLOCK, type BaseParityInputs, - type CombinedAccumulatedData, type EmptyNestedData, Fr, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, - KernelCircuitPublicInputs, type MembershipWitness, type NESTED_RECURSIVE_PROOF_LENGTH, type NULLIFIER_TREE_HEIGHT, @@ -21,6 +19,8 @@ import { type PrivateToAvmAccumulatedDataArrayLengths, type PrivateToPublicAccumulatedData, type PrivateToPublicKernelCircuitPublicInputs, + type PrivateToRollupAccumulatedData, + PrivateToRollupKernelCircuitPublicInputs, type PublicDataHint, type RECURSIVE_PROOF_LENGTH, ROLLUP_HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, @@ -72,13 +72,12 @@ import type { BlockMergeRollupInputs as BlockMergeRollupInputsNoir, BlockRootOrBlockMergePublicInputs as BlockRootOrBlockMergePublicInputsNoir, BlockRootRollupInputs as BlockRootRollupInputsNoir, - CombinedAccumulatedData as CombinedAccumulatedDataNoir, + PrivateToRollupAccumulatedData as CombinedAccumulatedDataNoir, ConstantRollupData as ConstantRollupDataNoir, EmptyBlockRootRollupInputs as EmptyBlockRootRollupInputsNoir, EmptyNestedCircuitPublicInputs as EmptyNestedDataNoir, FeeRecipient as FeeRecipientNoir, FixedLengthArray, - KernelCircuitPublicInputs as KernelCircuitPublicInputsNoir, MergeRollupInputs as MergeRollupInputsNoir, Field as NoirField, ParityPublicInputs as ParityPublicInputsNoir, @@ -93,6 +92,7 @@ import type { PrivateToAvmAccumulatedData as PrivateToAvmAccumulatedDataNoir, PrivateToPublicAccumulatedData as PrivateToPublicAccumulatedDataNoir, PrivateToPublicKernelCircuitPublicInputs as PrivateToPublicKernelCircuitPublicInputsNoir, + PrivateToRollupKernelCircuitPublicInputs as PrivateToRollupKernelCircuitPublicInputsNoir, PrivateTubeData as PrivateTubeDataNoir, PublicBaseRollupInputs as PublicBaseRollupInputsNoir, PublicBaseStateDiffHints as PublicBaseStateDiffHintsNoir, @@ -470,15 +470,18 @@ export function mapPrivateToPublicAccumulatedDataToNoir( } export function mapCombinedAccumulatedDataToNoir( - combinedAccumulatedData: CombinedAccumulatedData, + PrivateToRollupAccumulatedData: PrivateToRollupAccumulatedData, ): CombinedAccumulatedDataNoir { return { - note_hashes: mapTuple(combinedAccumulatedData.noteHashes, mapFieldToNoir), - nullifiers: mapTuple(combinedAccumulatedData.nullifiers, mapFieldToNoir), - l2_to_l1_msgs: mapTuple(combinedAccumulatedData.l2ToL1Msgs, mapScopedL2ToL1MessageToNoir), - private_logs: mapTuple(combinedAccumulatedData.privateLogs, mapPrivateLogToNoir), - contract_class_logs_hashes: mapTuple(combinedAccumulatedData.contractClassLogsHashes, mapScopedLogHashToNoir), - contract_class_log_preimages_length: mapFieldToNoir(combinedAccumulatedData.contractClassLogPreimagesLength), + note_hashes: mapTuple(PrivateToRollupAccumulatedData.noteHashes, mapFieldToNoir), + nullifiers: mapTuple(PrivateToRollupAccumulatedData.nullifiers, mapFieldToNoir), + l2_to_l1_msgs: mapTuple(PrivateToRollupAccumulatedData.l2ToL1Msgs, mapScopedL2ToL1MessageToNoir), + private_logs: mapTuple(PrivateToRollupAccumulatedData.privateLogs, mapPrivateLogToNoir), + contract_class_logs_hashes: mapTuple( + PrivateToRollupAccumulatedData.contractClassLogsHashes, + mapScopedLogHashToNoir, + ), + contract_class_log_preimages_length: mapFieldToNoir(PrivateToRollupAccumulatedData.contractClassLogPreimagesLength), }; } @@ -514,7 +517,9 @@ export function mapPrivateToPublicKernelCircuitPublicInputsToNoir( }; } -export function mapKernelCircuitPublicInputsToNoir(inputs: KernelCircuitPublicInputs): KernelCircuitPublicInputsNoir { +export function mapPrivateToRollupKernelCircuitPublicInputsToNoir( + inputs: PrivateToRollupKernelCircuitPublicInputs, +): PrivateToRollupKernelCircuitPublicInputsNoir { return { rollup_validation_requests: mapRollupValidationRequestsToNoir(inputs.rollupValidationRequests), constants: mapTxConstantDataToNoir(inputs.constants), @@ -813,7 +818,7 @@ export function mapRootParityInputsToNoir(inputs: RootParityInputs): RootParityI function mapPrivateTubeDataToNoir(data: PrivateTubeData): PrivateTubeDataNoir { return { - public_inputs: mapKernelCircuitPublicInputsToNoir(data.publicInputs), + public_inputs: mapPrivateToRollupKernelCircuitPublicInputsToNoir(data.publicInputs), proof: mapRecursiveProofToNoir(data.proof), vk_data: mapVkWitnessDataToNoir(data.vkData, ROLLUP_HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), }; @@ -936,8 +941,10 @@ export function mapRevertCodeToNoir(revertCode: RevertCode): NoirField { return mapFieldToNoir(revertCode.toField()); } -export function mapKernelCircuitPublicInputsFromNoir(inputs: KernelCircuitPublicInputsNoir) { - return new KernelCircuitPublicInputs( +export function mapPrivateToRollupKernelCircuitPublicInputsFromNoir( + inputs: PrivateToRollupKernelCircuitPublicInputsNoir, +) { + return new PrivateToRollupKernelCircuitPublicInputs( mapRollupValidationRequestsFromNoir(inputs.rollup_validation_requests), mapCombinedAccumulatedDataFromNoir(inputs.end), mapTxConstantDataFromNoir(inputs.constants), diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/server.ts b/yarn-project/noir-protocol-circuits-types/src/execution/server.ts index 722172b9a1e..5d073765229 100644 --- a/yarn-project/noir-protocol-circuits-types/src/execution/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/execution/server.ts @@ -1,8 +1,8 @@ import { type BaseParityInputs, - type KernelCircuitPublicInputs, type ParityPublicInputs, type PrivateKernelEmptyInputs, + type PrivateToRollupKernelCircuitPublicInputs, type RootParityInputs, } from '@aztec/circuits.js'; import { @@ -31,10 +31,10 @@ import { mapBlockRootRollupInputsToNoir, mapEmptyBlockRootRollupInputsToNoir, mapEmptyKernelInputsToNoir, - mapKernelCircuitPublicInputsFromNoir, mapMergeRollupInputsToNoir, mapParityPublicInputsFromNoir, mapPrivateBaseRollupInputsToNoir, + mapPrivateToRollupKernelCircuitPublicInputsFromNoir, mapPublicBaseRollupInputsToNoir, mapRootParityInputsToNoir, mapRootRollupInputsToNoir, @@ -187,23 +187,25 @@ export function convertRootRollupInputsToWitnessMap(inputs: RootRollupInputs): W return initialWitnessMap; } -export function convertPrivateKernelEmptyOutputsFromWitnessMap(outputs: WitnessMap): KernelCircuitPublicInputs { +export function convertPrivateKernelEmptyOutputsFromWitnessMap( + outputs: WitnessMap, +): PrivateToRollupKernelCircuitPublicInputs { const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.PrivateKernelEmptyArtifact.abi, outputs); const returnType = decodedInputs.return_value as PrivateKernelEmptyReturnType; - return mapKernelCircuitPublicInputsFromNoir(returnType); + return mapPrivateToRollupKernelCircuitPublicInputsFromNoir(returnType); } export function convertSimulatedPrivateKernelEmptyOutputsFromWitnessMap( outputs: WitnessMap, -): KernelCircuitPublicInputs { +): PrivateToRollupKernelCircuitPublicInputs { const decodedInputs: DecodedInputs = abiDecode( SimulatedServerCircuitArtifacts.PrivateKernelEmptyArtifact.abi, outputs, ); const returnType = decodedInputs.return_value as PrivateKernelEmptyReturnType; - return mapKernelCircuitPublicInputsFromNoir(returnType); + return mapPrivateToRollupKernelCircuitPublicInputsFromNoir(returnType); } /** diff --git a/yarn-project/prover-client/src/block_builder/light.test.ts b/yarn-project/prover-client/src/block_builder/light.test.ts index 95180821db1..e92e7d6fa0e 100644 --- a/yarn-project/prover-client/src/block_builder/light.test.ts +++ b/yarn-project/prover-client/src/block_builder/light.test.ts @@ -280,7 +280,11 @@ describe('LightBlockBuilder', () => { const vkIndex = TUBE_VK_INDEX; const vkPath = getVKSiblingPath(vkIndex); const vkData = new VkWitnessData(TubeVk, vkIndex, vkPath); - const tubeData = new PrivateTubeData(tx.data.toKernelCircuitPublicInputs(), emptyRollupProof, vkData); + const tubeData = new PrivateTubeData( + tx.data.toPrivateToRollupKernelCircuitPublicInputs(), + emptyRollupProof, + vkData, + ); const hints = await buildBaseRollupHints(tx, globalVariables, expectsFork, spongeBlobState); const inputs = new PrivateBaseRollupInputs(tubeData, hints as PrivateBaseRollupHints); const result = await simulator.getPrivateBaseRollupProof(inputs); diff --git a/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts b/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts index 9bdd2eeda4d..0460b11b3b0 100644 --- a/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts +++ b/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts @@ -60,7 +60,11 @@ export class TxProvingState { } const vkData = this.getTubeVkData(); - const tubeData = new PrivateTubeData(this.processedTx.data.toKernelCircuitPublicInputs(), this.tube.proof, vkData); + const tubeData = new PrivateTubeData( + this.processedTx.data.toPrivateToRollupKernelCircuitPublicInputs(), + this.tube.proof, + vkData, + ); if (!(this.baseRollupHints instanceof PrivateBaseRollupHints)) { throw new Error('Mismatched base rollup hints, expected private base rollup hints'); diff --git a/yarn-project/prover-client/src/prover-agent/memory-proving-queue.ts b/yarn-project/prover-client/src/prover-agent/memory-proving-queue.ts index f4a3fb8433a..a27522f7cd1 100644 --- a/yarn-project/prover-client/src/prover-agent/memory-proving-queue.ts +++ b/yarn-project/prover-client/src/prover-agent/memory-proving-queue.ts @@ -12,11 +12,11 @@ import type { AVM_PROOF_LENGTH_IN_FIELDS, AvmCircuitInputs, BaseParityInputs, - KernelCircuitPublicInputs, NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, ParityPublicInputs, PrivateKernelEmptyInputData, + PrivateToRollupKernelCircuitPublicInputs, RECURSIVE_PROOF_LENGTH, RootParityInputs, TUBE_PROOF_LENGTH, @@ -276,7 +276,10 @@ export class MemoryProvingQueue implements ServerCircuitProver, ProvingJobSource signal?: AbortSignal, epochNumber?: number, ): Promise< - PublicInputsAndRecursiveProof + PublicInputsAndRecursiveProof< + PrivateToRollupKernelCircuitPublicInputs, + typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH + > > { return this.enqueue(ProvingRequestType.PRIVATE_KERNEL_EMPTY, inputs, signal, epochNumber); } diff --git a/yarn-project/prover-client/src/proving_broker/broker_prover_facade.ts b/yarn-project/prover-client/src/proving_broker/broker_prover_facade.ts index a5a0a4a7b86..ae28955a202 100644 --- a/yarn-project/prover-client/src/proving_broker/broker_prover_facade.ts +++ b/yarn-project/prover-client/src/proving_broker/broker_prover_facade.ts @@ -12,11 +12,11 @@ import { type AVM_PROOF_LENGTH_IN_FIELDS, type AvmCircuitInputs, type BaseParityInputs, - type KernelCircuitPublicInputs, type NESTED_RECURSIVE_PROOF_LENGTH, type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, type ParityPublicInputs, type PrivateKernelEmptyInputData, + type PrivateToRollupKernelCircuitPublicInputs, type RECURSIVE_PROOF_LENGTH, type RootParityInputs, type TUBE_PROOF_LENGTH, @@ -199,7 +199,10 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver { signal?: AbortSignal, epochNumber?: number, ): Promise< - PublicInputsAndRecursiveProof + PublicInputsAndRecursiveProof< + PrivateToRollupKernelCircuitPublicInputs, + typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH + > > { return this.enqueueAndWaitForJob( this.generateId(ProvingRequestType.PRIVATE_KERNEL_EMPTY, inputs, epochNumber), diff --git a/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts b/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts index dc43748fcdd..cd977e38d3d 100644 --- a/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts @@ -47,7 +47,7 @@ describe('prover/bb_prover/base-rollup', () => { protocolContractTreeRoot, ); const tubeProof = await context.prover.getEmptyPrivateKernelProof(privateInputs); - expect(tubeProof.inputs).toEqual(tx.data.toKernelCircuitPublicInputs()); + expect(tubeProof.inputs).toEqual(tx.data.toPrivateToRollupKernelCircuitPublicInputs()); const vkIndex = PRIVATE_KERNEL_EMPTY_INDEX; const vkPath = getVKSiblingPath(vkIndex); diff --git a/yarn-project/prover-client/src/test/mock_prover.ts b/yarn-project/prover-client/src/test/mock_prover.ts index ea791dec259..de87b6ef58c 100644 --- a/yarn-project/prover-client/src/test/mock_prover.ts +++ b/yarn-project/prover-client/src/test/mock_prover.ts @@ -15,10 +15,10 @@ import { AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS, type AvmCircuitInputs, type BaseParityInputs, - type KernelCircuitPublicInputs, NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, type PrivateKernelEmptyInputData, + type PrivateToRollupKernelCircuitPublicInputs, RECURSIVE_PROOF_LENGTH, type RootParityInputs, TUBE_PROOF_LENGTH, @@ -41,8 +41,8 @@ import { import { makeBaseOrMergeRollupPublicInputs, makeBlockRootOrBlockMergeRollupPublicInputs, - makeKernelCircuitPublicInputs, makeParityPublicInputs, + makePrivateToRollupKernelCircuitPublicInputs, makeRootRollupPublicInputs, } from '@aztec/circuits.js/testing'; import { times } from '@aztec/foundation/collection'; @@ -224,11 +224,14 @@ export class MockProver implements ServerCircuitProver { _signal?: AbortSignal, _epochNumber?: number, ): Promise< - PublicInputsAndRecursiveProof + PublicInputsAndRecursiveProof< + PrivateToRollupKernelCircuitPublicInputs, + typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH + > > { return Promise.resolve( makePublicInputsAndRecursiveProof( - makeKernelCircuitPublicInputs(), + makePrivateToRollupKernelCircuitPublicInputs(), makeRecursiveProof(NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH), VerificationKeyData.makeFakeHonk(), ), From e7035743127e201e59051f4b78be3753b71b6fc6 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Fri, 3 Jan 2025 17:42:09 +0000 Subject: [PATCH 04/29] fix --- .../src/conversion/common.ts | 14 +++++++------- .../src/conversion/server.ts | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts index a1f964e8e93..aec0954e568 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts @@ -670,23 +670,23 @@ export function mapPublicDataWriteToNoir(write: PublicDataWrite): PublicDataWrit * @param PrivateToRollupAccumulatedData - The noir combined accumulated data. * @returns The parsed combined accumulated data. */ -export function mapCombinedAccumulatedDataFromNoir(PrivateToRollupAccumulatedData: CombinedAccumulatedDataNoir) { +export function mapCombinedAccumulatedDataFromNoir(privateToRollupAccumulatedData: CombinedAccumulatedDataNoir) { return new PrivateToRollupAccumulatedData( - mapTupleFromNoir(PrivateToRollupAccumulatedData.note_hashes, MAX_NOTE_HASHES_PER_TX, mapFieldFromNoir), - mapTupleFromNoir(PrivateToRollupAccumulatedData.nullifiers, MAX_NULLIFIERS_PER_TX, mapFieldFromNoir), + mapTupleFromNoir(privateToRollupAccumulatedData.note_hashes, MAX_NOTE_HASHES_PER_TX, mapFieldFromNoir), + mapTupleFromNoir(privateToRollupAccumulatedData.nullifiers, MAX_NULLIFIERS_PER_TX, mapFieldFromNoir), mapTupleFromNoir( - PrivateToRollupAccumulatedData.l2_to_l1_msgs, + privateToRollupAccumulatedData.l2_to_l1_msgs, MAX_L2_TO_L1_MSGS_PER_TX, mapScopedL2ToL1MessageFromNoir, ), - mapTupleFromNoir(PrivateToRollupAccumulatedData.private_logs, MAX_PRIVATE_LOGS_PER_TX, mapPrivateLogFromNoir), + mapTupleFromNoir(privateToRollupAccumulatedData.private_logs, MAX_PRIVATE_LOGS_PER_TX, mapPrivateLogFromNoir), mapTupleFromNoir( - PrivateToRollupAccumulatedData.contract_class_logs_hashes, + privateToRollupAccumulatedData.contract_class_logs_hashes, MAX_CONTRACT_CLASS_LOGS_PER_TX, mapScopedLogHashFromNoir, ), - mapFieldFromNoir(PrivateToRollupAccumulatedData.contract_class_log_preimages_length), + mapFieldFromNoir(privateToRollupAccumulatedData.contract_class_log_preimages_length), ); } diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts index fe54ba9d155..3586be33712 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts @@ -470,18 +470,18 @@ export function mapPrivateToPublicAccumulatedDataToNoir( } export function mapCombinedAccumulatedDataToNoir( - PrivateToRollupAccumulatedData: PrivateToRollupAccumulatedData, + privateToRollupAccumulatedData: PrivateToRollupAccumulatedData, ): CombinedAccumulatedDataNoir { return { - note_hashes: mapTuple(PrivateToRollupAccumulatedData.noteHashes, mapFieldToNoir), - nullifiers: mapTuple(PrivateToRollupAccumulatedData.nullifiers, mapFieldToNoir), - l2_to_l1_msgs: mapTuple(PrivateToRollupAccumulatedData.l2ToL1Msgs, mapScopedL2ToL1MessageToNoir), - private_logs: mapTuple(PrivateToRollupAccumulatedData.privateLogs, mapPrivateLogToNoir), + note_hashes: mapTuple(privateToRollupAccumulatedData.noteHashes, mapFieldToNoir), + nullifiers: mapTuple(privateToRollupAccumulatedData.nullifiers, mapFieldToNoir), + l2_to_l1_msgs: mapTuple(privateToRollupAccumulatedData.l2ToL1Msgs, mapScopedL2ToL1MessageToNoir), + private_logs: mapTuple(privateToRollupAccumulatedData.privateLogs, mapPrivateLogToNoir), contract_class_logs_hashes: mapTuple( - PrivateToRollupAccumulatedData.contractClassLogsHashes, + privateToRollupAccumulatedData.contractClassLogsHashes, mapScopedLogHashToNoir, ), - contract_class_log_preimages_length: mapFieldToNoir(PrivateToRollupAccumulatedData.contractClassLogPreimagesLength), + contract_class_log_preimages_length: mapFieldToNoir(privateToRollupAccumulatedData.contractClassLogPreimagesLength), }; } From 247eb4c1f76c0b1b05909a85762eb83f7f191adf Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 7 Jan 2025 09:38:32 +0000 Subject: [PATCH 05/29] renaming --- yarn-project/circuit-types/src/test/factories.ts | 4 ++-- .../private_to_rollup_accumulated_data.test.ts | 4 ++-- yarn-project/circuits.js/src/tests/factories.ts | 6 +++--- .../src/conversion/client.ts | 4 ++-- .../src/conversion/common.ts | 6 ++++-- .../src/conversion/server.ts | 12 ++++++------ 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/yarn-project/circuit-types/src/test/factories.ts b/yarn-project/circuit-types/src/test/factories.ts index eb3642108ae..21367837a22 100644 --- a/yarn-project/circuit-types/src/test/factories.ts +++ b/yarn-project/circuit-types/src/test/factories.ts @@ -19,7 +19,7 @@ import { TxConstantData, mergeAccumulatedData, } from '@aztec/circuits.js'; -import { makeCombinedAccumulatedData, makePrivateToPublicAccumulatedData } from '@aztec/circuits.js/testing'; +import { makePrivateToPublicAccumulatedData, makePrivateToRollupAccumulatedData } from '@aztec/circuits.js/testing'; import { makeTuple } from '@aztec/foundation/array'; import { type MerkleTreeReadOperations } from '../interfaces/merkle_tree_operations.js'; @@ -73,7 +73,7 @@ export function makeBloatedProcessedTx({ tx.data.gasUsed = Gas.from({ daGas: FIXED_DA_GAS, l2Gas: FIXED_L2_GAS }); if (privateOnly) { - const data = makeCombinedAccumulatedData(seed + 0x1000); + const data = makePrivateToRollupAccumulatedData(seed + 0x1000); const transactionFee = tx.data.gasUsed.computeFee(globalVariables.gasFees); diff --git a/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.test.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.test.ts index f7865fde17f..4ede3c49065 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.test.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.test.ts @@ -1,9 +1,9 @@ -import { makeCombinedAccumulatedData } from '../../tests/factories.js'; +import { makePrivateToRollupAccumulatedData } from '../../tests/factories.js'; import { PrivateToRollupAccumulatedData } from './private_to_rollup_accumulated_data.js'; describe('PrivateToRollupAccumulatedData', () => { it('Data after serialization and deserialization is equal to the original', () => { - const original = makeCombinedAccumulatedData(); + const original = makePrivateToRollupAccumulatedData(); const afterSerialization = PrivateToRollupAccumulatedData.fromBuffer(original.toBuffer()); expect(original).toEqual(afterSerialization); }); diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 3b4e33c665a..7478b5bc63f 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -303,7 +303,7 @@ export function makeCombinedConstantData(seed = 1): CombinedConstantData { * @param seed - The seed to use for generating the accumulated data. * @returns An accumulated data. */ -export function makeCombinedAccumulatedData(seed = 1, full = false): PrivateToRollupAccumulatedData { +export function makePrivateToRollupAccumulatedData(seed = 1, full = false): PrivateToRollupAccumulatedData { const tupleGenerator = full ? makeTuple : makeHalfFullTuple; return new PrivateToRollupAccumulatedData( @@ -385,7 +385,7 @@ export function makePrivateKernelTailCircuitPublicInputs( ) : undefined; const forRollup = !isForPublic - ? new PartialPrivateTailPublicInputsForRollup(makeCombinedAccumulatedData(seed + 0x100)) + ? new PartialPrivateTailPublicInputsForRollup(makePrivateToRollupAccumulatedData(seed + 0x100)) : undefined; return new PrivateKernelTailCircuitPublicInputs( makeTxConstantData(seed + 0x300), @@ -420,7 +420,7 @@ export function makePrivateToRollupKernelCircuitPublicInputs( ): PrivateToRollupKernelCircuitPublicInputs { return new PrivateToRollupKernelCircuitPublicInputs( makeRollupValidationRequests(seed), - makeCombinedAccumulatedData(seed, fullAccumulatedData), + makePrivateToRollupAccumulatedData(seed, fullAccumulatedData), makeCombinedConstantData(seed + 0x100), makeGas(seed + 0x600), makeAztecAddress(seed + 0x700), diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/client.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/client.ts index 461a0c809eb..0287b5c2c45 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/client.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/client.ts @@ -102,7 +102,6 @@ import type { import { mapAztecAddressFromNoir, mapAztecAddressToNoir, - mapCombinedAccumulatedDataFromNoir, mapFieldFromNoir, mapFieldToNoir, mapFunctionSelectorFromNoir, @@ -124,6 +123,7 @@ import { mapPointToNoir, mapPrivateLogFromNoir, mapPrivateLogToNoir, + mapPrivateToRollupAccumulatedDataFromNoir, mapPublicCallRequestFromNoir, mapPublicCallRequestToNoir, mapScopedL2ToL1MessageFromNoir, @@ -685,7 +685,7 @@ export function mapPrivateKernelDataToNoir( export function mapPrivateKernelTailCircuitPublicInputsForRollupFromNoir( inputs: PrivateToRollupKernelCircuitPublicInputsNoir, ): PrivateKernelTailCircuitPublicInputs { - const forRollup = new PartialPrivateTailPublicInputsForRollup(mapCombinedAccumulatedDataFromNoir(inputs.end)); + const forRollup = new PartialPrivateTailPublicInputsForRollup(mapPrivateToRollupAccumulatedDataFromNoir(inputs.end)); return new PrivateKernelTailCircuitPublicInputs( mapTxConstantDataFromNoir(inputs.constants), mapRollupValidationRequestsFromNoir(inputs.rollup_validation_requests), diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts index aec0954e568..e4fb401537e 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/common.ts @@ -42,7 +42,6 @@ import { type Tuple, mapTuple, toTruncField } from '@aztec/foundation/serialize' import type { AppendOnlyTreeSnapshot as AppendOnlyTreeSnapshotNoir, BlockHeader as BlockHeaderNoir, - PrivateToRollupAccumulatedData as CombinedAccumulatedDataNoir, ContentCommitment as ContentCommitmentNoir, Field, FixedLengthArray, @@ -64,6 +63,7 @@ import type { Option as OptionalNumberNoir, PartialStateReference as PartialStateReferenceNoir, Log as PrivateLogNoir, + PrivateToRollupAccumulatedData as PrivateToRollupAccumulatedDataNoir, PublicCallRequest as PublicCallRequestNoir, PublicDataTreeLeafPreimage as PublicDataTreeLeafPreimageNoir, PublicDataWrite as PublicDataWriteNoir, @@ -670,7 +670,9 @@ export function mapPublicDataWriteToNoir(write: PublicDataWrite): PublicDataWrit * @param PrivateToRollupAccumulatedData - The noir combined accumulated data. * @returns The parsed combined accumulated data. */ -export function mapCombinedAccumulatedDataFromNoir(privateToRollupAccumulatedData: CombinedAccumulatedDataNoir) { +export function mapPrivateToRollupAccumulatedDataFromNoir( + privateToRollupAccumulatedData: PrivateToRollupAccumulatedDataNoir, +) { return new PrivateToRollupAccumulatedData( mapTupleFromNoir(privateToRollupAccumulatedData.note_hashes, MAX_NOTE_HASHES_PER_TX, mapFieldFromNoir), mapTupleFromNoir(privateToRollupAccumulatedData.nullifiers, MAX_NULLIFIERS_PER_TX, mapFieldFromNoir), diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts index 3586be33712..a53043c6082 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts @@ -72,7 +72,6 @@ import type { BlockMergeRollupInputs as BlockMergeRollupInputsNoir, BlockRootOrBlockMergePublicInputs as BlockRootOrBlockMergePublicInputsNoir, BlockRootRollupInputs as BlockRootRollupInputsNoir, - PrivateToRollupAccumulatedData as CombinedAccumulatedDataNoir, ConstantRollupData as ConstantRollupDataNoir, EmptyBlockRootRollupInputs as EmptyBlockRootRollupInputsNoir, EmptyNestedCircuitPublicInputs as EmptyNestedDataNoir, @@ -92,6 +91,7 @@ import type { PrivateToAvmAccumulatedData as PrivateToAvmAccumulatedDataNoir, PrivateToPublicAccumulatedData as PrivateToPublicAccumulatedDataNoir, PrivateToPublicKernelCircuitPublicInputs as PrivateToPublicKernelCircuitPublicInputsNoir, + PrivateToRollupAccumulatedData as PrivateToRollupAccumulatedDataNoir, PrivateToRollupKernelCircuitPublicInputs as PrivateToRollupKernelCircuitPublicInputsNoir, PrivateTubeData as PrivateTubeDataNoir, PublicBaseRollupInputs as PublicBaseRollupInputsNoir, @@ -113,7 +113,6 @@ import { mapAppendOnlyTreeSnapshotToNoir, mapAztecAddressFromNoir, mapAztecAddressToNoir, - mapCombinedAccumulatedDataFromNoir, mapEthAddressFromNoir, mapEthAddressToNoir, mapFieldFromNoir, @@ -134,6 +133,7 @@ import { mapPartialStateReferenceFromNoir, mapPartialStateReferenceToNoir, mapPrivateLogToNoir, + mapPrivateToRollupAccumulatedDataFromNoir, mapPublicCallRequestToNoir, mapPublicDataTreePreimageToNoir, mapPublicDataWriteToNoir, @@ -469,9 +469,9 @@ export function mapPrivateToPublicAccumulatedDataToNoir( }; } -export function mapCombinedAccumulatedDataToNoir( +export function mapPrivateToRollupAccumulatedDataToNoir( privateToRollupAccumulatedData: PrivateToRollupAccumulatedData, -): CombinedAccumulatedDataNoir { +): PrivateToRollupAccumulatedDataNoir { return { note_hashes: mapTuple(privateToRollupAccumulatedData.noteHashes, mapFieldToNoir), nullifiers: mapTuple(privateToRollupAccumulatedData.nullifiers, mapFieldToNoir), @@ -523,7 +523,7 @@ export function mapPrivateToRollupKernelCircuitPublicInputsToNoir( return { rollup_validation_requests: mapRollupValidationRequestsToNoir(inputs.rollupValidationRequests), constants: mapTxConstantDataToNoir(inputs.constants), - end: mapCombinedAccumulatedDataToNoir(inputs.end), + end: mapPrivateToRollupAccumulatedDataToNoir(inputs.end), gas_used: mapGasToNoir(inputs.gasUsed), fee_payer: mapAztecAddressToNoir(inputs.feePayer), }; @@ -946,7 +946,7 @@ export function mapPrivateToRollupKernelCircuitPublicInputsFromNoir( ) { return new PrivateToRollupKernelCircuitPublicInputs( mapRollupValidationRequestsFromNoir(inputs.rollup_validation_requests), - mapCombinedAccumulatedDataFromNoir(inputs.end), + mapPrivateToRollupAccumulatedDataFromNoir(inputs.end), mapTxConstantDataFromNoir(inputs.constants), mapGasFromNoir(inputs.gas_used), mapAztecAddressFromNoir(inputs.fee_payer), From a0f0087fcb681c9449fb38b43e9fda88275d16e9 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 7 Jan 2025 09:46:50 +0000 Subject: [PATCH 06/29] fix bad merge --- .../crates/rollup-lib/src/components.nr | 44 ++++++------------- 1 file changed, 14 insertions(+), 30 deletions(-) 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 e5705074680..c8a854c264b 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 @@ -271,11 +271,7 @@ pub(crate) fn append_tx_effects_for_blob( start_sponge_blob: SpongeBlob, ) -> SpongeBlob { let (mut tx_effects_hash_input, offset) = get_tx_effects_hash_input( - combined, - revert_code, - transaction_fee, - all_public_data_update_requests, - l2_to_l1_msgs, + tx_effect ); // NB: using start.absorb & returning start caused issues in ghost values appearing in @@ -292,33 +288,25 @@ pub(crate) fn append_tx_effects_for_blob( } fn get_tx_effects_hash_input( - combined: CombinedAccumulatedData, - revert_code: u8, - transaction_fee: Field, - all_public_data_update_requests: [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], - l2_to_l1_msgs: [Field; MAX_L2_TO_L1_MSGS_PER_TX], + tx_effect: TxEffect, ) -> ([Field; TX_EFFECTS_BLOB_HASH_INPUT_FIELDS], u32) { let mut tx_effects_hash_input = unsafe { get_tx_effects_hash_input_helper( - combined, - revert_code, - transaction_fee, - all_public_data_update_requests, - l2_to_l1_msgs, + tx_effect ) }; - let note_hashes = combined.note_hashes; - let nullifiers = combined.nullifiers; + let note_hashes = tx_effect.note_hashes; + let nullifiers = tx_effect.nullifiers; // Public writes are the concatenation of all non-empty user update requests and protocol update requests, then padded with zeroes. // The incoming all_public_data_update_requests may have empty update requests in the middle, so we move those to the end of the array. let public_data_update_requests = - get_all_update_requests_for_tx_effects(all_public_data_update_requests); - let private_logs = combined.private_logs; + get_all_update_requests_for_tx_effects(tx_effect.public_data_writes); + let private_logs = tx_effect.private_logs; let unencrypted_logs = - combined.unencrypted_logs_hashes.map(|log: ScopedLogHash| silo_unencrypted_log_hash(log)); - let contract_class_logs = combined.contract_class_logs_hashes.map(|log: ScopedLogHash| { + tx_effect.unencrypted_logs_hashes.map(|log: ScopedLogHash| silo_unencrypted_log_hash(log)); + let contract_class_logs = tx_effect.contract_class_logs_hashes.map(|log: ScopedLogHash| { silo_unencrypted_log_hash(log) }); @@ -336,7 +324,7 @@ fn get_tx_effects_hash_input( assert_eq( tx_effects_hash_input[offset], field_from_bytes( - array_concat([TX_FEE_PREFIX, 0], transaction_fee.to_be_bytes::<29>()), + array_concat([TX_FEE_PREFIX, 0], tx_effect.transaction_fee.to_be_bytes::<29>()), true, ), ); @@ -376,7 +364,7 @@ fn get_tx_effects_hash_input( } // L2 TO L1 MESSAGES - array_len = array_length(l2_to_l1_msgs); + array_len = array_length(tx_effect.l2_to_l1_msgs); if array_len != 0 { let l2_to_l1_msgs_prefix = encode_blob_prefix(L2_L1_MSGS_PREFIX, array_len); assert_eq(tx_effects_hash_input[offset], l2_to_l1_msgs_prefix); @@ -384,7 +372,7 @@ fn get_tx_effects_hash_input( for j in 0..MAX_L2_TO_L1_MSGS_PER_TX { if j < array_len { - assert_eq(tx_effects_hash_input[offset + j], l2_to_l1_msgs[j]); + assert_eq(tx_effects_hash_input[offset + j], tx_effect.l2_to_l1_msgs[j]); } } offset += array_len; @@ -474,7 +462,7 @@ fn get_tx_effects_hash_input( field_from_bytes( array_concat( prefix_bytes, - [0, length_bytes[0], length_bytes[1], 0, REVERT_CODE_PREFIX, 0, revert_code], + [0, length_bytes[0], length_bytes[1], 0, REVERT_CODE_PREFIX, 0, tx_effect.revert_code], ), true, ), @@ -484,11 +472,7 @@ fn get_tx_effects_hash_input( } unconstrained fn get_tx_effects_hash_input_helper( - combined: CombinedAccumulatedData, - revert_code: u8, - transaction_fee: Field, - all_public_data_update_requests: [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], - l2_to_l1_msgs: [Field; MAX_L2_TO_L1_MSGS_PER_TX], + tx_effect: TxEffect, ) -> [Field; TX_EFFECTS_BLOB_HASH_INPUT_FIELDS] { let mut tx_effects_hash_input = [0; TX_EFFECTS_BLOB_HASH_INPUT_FIELDS]; From 4938eb0dbb03054088350b2b0cf65817d8e76d9e Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 7 Jan 2025 09:50:15 +0000 Subject: [PATCH 07/29] fmt --- .../crates/rollup-lib/src/components.nr | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) 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 c8a854c264b..28057fb9c69 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 @@ -270,9 +270,7 @@ pub(crate) fn append_tx_effects_for_blob( tx_effect: TxEffect, start_sponge_blob: SpongeBlob, ) -> SpongeBlob { - let (mut tx_effects_hash_input, offset) = get_tx_effects_hash_input( - tx_effect - ); + let (mut tx_effects_hash_input, offset) = get_tx_effects_hash_input(tx_effect); // NB: using start.absorb & returning start caused issues in ghost values appearing in // base_rollup_inputs.start when using a fresh sponge. These only appeared when simulating via wasm. @@ -290,11 +288,7 @@ pub(crate) fn append_tx_effects_for_blob( fn get_tx_effects_hash_input( tx_effect: TxEffect, ) -> ([Field; TX_EFFECTS_BLOB_HASH_INPUT_FIELDS], u32) { - let mut tx_effects_hash_input = unsafe { - get_tx_effects_hash_input_helper( - tx_effect - ) - }; + let mut tx_effects_hash_input = unsafe { get_tx_effects_hash_input_helper(tx_effect) }; let note_hashes = tx_effect.note_hashes; let nullifiers = tx_effect.nullifiers; @@ -324,7 +318,10 @@ fn get_tx_effects_hash_input( assert_eq( 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, ), ); @@ -462,7 +459,15 @@ fn get_tx_effects_hash_input( field_from_bytes( array_concat( prefix_bytes, - [0, length_bytes[0], length_bytes[1], 0, REVERT_CODE_PREFIX, 0, tx_effect.revert_code], + [ + 0, + length_bytes[0], + length_bytes[1], + 0, + REVERT_CODE_PREFIX, + 0, + tx_effect.revert_code, + ], ), true, ), From 52c94d49c23fd8da6f83ba0c164b7ea6ea15d407 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 7 Jan 2025 11:59:08 +0000 Subject: [PATCH 08/29] fix --- .../src/components/tail_output_composer.nr | 2 -- .../rollup-lib/src/base/public_base_rollup.nr | 14 ++++---------- .../private_kernel_tail_circuit_public_inputs.ts | 5 +---- yarn-project/circuits.js/src/tests/factories.ts | 2 +- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr index 5fd0147cab4..32503d6ad70 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr @@ -4,8 +4,6 @@ use crate::components::private_kernel_circuit_public_inputs_composer::PrivateKer use dep::types::{ abis::{ accumulated_data::private_to_rollup_accumulated_data::PrivateToRollupAccumulatedData, - combined_constant_data::CombinedConstantData, - global_variables::GlobalVariables, kernel_circuit_public_inputs::{ PrivateKernelCircuitPublicInputs, PrivateToRollupKernelCircuitPublicInputs, }, 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 f7adf7aba51..da383ffec88 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 @@ -15,16 +15,10 @@ use crate::{ }; use dep::types::{ abis::{ - accumulated_data::{self, PrivateToRollupAccumulatedData}, - append_only_tree_snapshot::AppendOnlyTreeSnapshot, - avm_circuit_public_inputs::AvmProofData, - combined_constant_data::CombinedConstantData, - constant_rollup_data::ConstantRollupData, - log_hash::ScopedLogHash, - nullifier_leaf_preimage::NullifierLeafPreimage, - public_data_write::PublicDataWrite, - sponge_blob::SpongeBlob, - tube::PublicTubeData, + append_only_tree_snapshot::AppendOnlyTreeSnapshot, avm_circuit_public_inputs::AvmProofData, + combined_constant_data::CombinedConstantData, constant_rollup_data::ConstantRollupData, + log_hash::ScopedLogHash, nullifier_leaf_preimage::NullifierLeafPreimage, + public_data_write::PublicDataWrite, sponge_blob::SpongeBlob, tube::PublicTubeData, }, constants::{ ARCHIVE_HEIGHT, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NOTE_HASH_SUBTREE_HEIGHT, diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts index 1b2af0296a4..14d20e21a11 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts @@ -5,10 +5,8 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { countAccumulatedItems, mergeAccumulatedData } from '../../utils/index.js'; import { Gas } from '../gas.js'; -import { GlobalVariables } from '../global_variables.js'; import { PublicCallRequest } from '../public_call_request.js'; import { RollupValidationRequests } from '../rollup_validation_requests.js'; -import { CombinedConstantData } from './combined_constant_data.js'; import { PrivateToRollupKernelCircuitPublicInputs } from './kernel_circuit_public_inputs.js'; import { PrivateToPublicAccumulatedData } from './private_to_public_accumulated_data.js'; import { PrivateToPublicKernelCircuitPublicInputs } from './private_to_public_kernel_circuit_public_inputs.js'; @@ -165,12 +163,11 @@ export class PrivateKernelTailCircuitPublicInputs { if (!this.forRollup) { throw new Error('Private tail public inputs is not for rollup circuit.'); } - const constants = new CombinedConstantData( + const constants = new TxConstantData( this.constants.historicalHeader, this.constants.txContext, this.constants.vkTreeRoot, this.constants.protocolContractTreeRoot, - GlobalVariables.empty(), ); return new PrivateToRollupKernelCircuitPublicInputs( this.rollupValidationRequests, diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 7478b5bc63f..1f7cde5ddfd 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -421,7 +421,7 @@ export function makePrivateToRollupKernelCircuitPublicInputs( return new PrivateToRollupKernelCircuitPublicInputs( makeRollupValidationRequests(seed), makePrivateToRollupAccumulatedData(seed, fullAccumulatedData), - makeCombinedConstantData(seed + 0x100), + makeTxConstantData(seed + 0x100), makeGas(seed + 0x600), makeAztecAddress(seed + 0x700), ); From 2986210d122e8d7a9163501f90b10ee6b0a70181 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 7 Jan 2025 12:39:01 +0000 Subject: [PATCH 09/29] update constants --- l1-contracts/src/core/libraries/ConstantsGen.sol | 4 ++-- yarn-project/circuits.js/src/constants.gen.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 5aee909fe39..744f48a5f67 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -195,7 +195,7 @@ library Constants { uint256 internal constant SCOPED_READ_REQUEST_LEN = 3; uint256 internal constant PUBLIC_DATA_READ_LENGTH = 3; uint256 internal constant PRIVATE_VALIDATION_REQUESTS_LENGTH = 772; - uint256 internal constant PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH = 902; + uint256 internal constant PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH = 741; uint256 internal constant TX_CONSTANT_DATA_LENGTH = 37; uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 46; uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1412; @@ -204,7 +204,7 @@ library Constants { uint256 internal constant PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH = 160; uint256 internal constant NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS = 3; uint256 internal constant PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1847; - uint256 internal constant PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 960; + uint256 internal constant PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 783; uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = 13; uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 52; uint256 internal constant BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH = 986; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index fbfb13af35e..2153492a399 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -173,7 +173,7 @@ export const IPA_CLAIM_LENGTH = 10; export const SCOPED_READ_REQUEST_LEN = 3; export const PUBLIC_DATA_READ_LENGTH = 3; export const PRIVATE_VALIDATION_REQUESTS_LENGTH = 772; -export const PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH = 902; +export const PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH = 741; export const TX_CONSTANT_DATA_LENGTH = 37; export const COMBINED_CONSTANT_DATA_LENGTH = 46; export const PRIVATE_ACCUMULATED_DATA_LENGTH = 1412; @@ -183,7 +183,7 @@ export const PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH = 160; export const NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS = 3; export const AVM_ACCUMULATED_DATA_LENGTH = 320; export const PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1847; -export const PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 960; +export const PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 783; export const AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1011; export const CONSTANT_ROLLUP_DATA_LENGTH = 13; export const BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 52; From f74cf0af5fd05685a4e34bcf9989e414ba6b6e1d Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 7 Jan 2025 14:28:58 +0000 Subject: [PATCH 10/29] wip tx hash --- .../crates/rollup-lib/src/abis/tx_effect.nr | 2 ++ .../rollup-lib/src/base/private_base_rollup.nr | 3 ++- .../rollup-lib/src/base/public_base_rollup.nr | 1 + .../crates/rollup-lib/src/components.nr | 11 +++++++++-- yarn-project/circuit-types/src/tx_effect.ts | 15 ++++++++++----- 5 files changed, 24 insertions(+), 8 deletions(-) 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 54fcf722f76..fe5f3cab437 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 @@ -9,6 +9,7 @@ use types::{ }; pub(crate) struct TxEffect { + pub(crate) tx_hash: Field, pub(crate) revert_code: u8, pub(crate) transaction_fee: Field, pub(crate) note_hashes: [Field; MAX_NOTE_HASHES_PER_TX], @@ -25,6 +26,7 @@ pub(crate) struct TxEffect { impl Empty for TxEffect { fn empty() -> Self { TxEffect { + tx_hash: 0, revert_code: 0, transaction_fee: 0, note_hashes: [0; MAX_NOTE_HASHES_PER_TX], 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 4aadab2ece4..75dff1c708a 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 @@ -117,6 +117,7 @@ impl PrivateBaseRollupInputs { let out_hash = compute_kernel_out_hash(siloed_l2_to_l1_msgs); let tx_effect = TxEffect { + tx_hash: 27, revert_code: 0, transaction_fee, note_hashes: self.tube_data.public_inputs.end.note_hashes, @@ -247,7 +248,7 @@ mod tests { NULLIFIER_SUBTREE_HEIGHT, NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH, NULLIFIER_TREE_HEIGHT, NULLIFIERS_PREFIX, PRIVATE_KERNEL_EMPTY_INDEX, PRIVATE_LOG_SIZE_IN_FIELDS, PRIVATE_LOGS_PREFIX, PUBLIC_DATA_TREE_HEIGHT, REVERT_CODE_PREFIX, TUBE_VK_INDEX, - TX_FEE_PREFIX, TX_START_PREFIX, UNENCRYPTED_LOGS_PREFIX, + TX_FEE_PREFIX, TX_START_PREFIX, }, data::{public_data_hint::PublicDataHint, PublicDataTreeLeaf, PublicDataTreeLeafPreimage}, hash::silo_l2_to_l1_message, 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 da383ffec88..f358b2cf4b0 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 @@ -87,6 +87,7 @@ impl PublicBaseRollupInputs { .fold(0, |len, l: ScopedLogHash| len + l.log_hash.length); TxEffect { + tx_hash: 27, revert_code, transaction_fee: from_public.transaction_fee, note_hashes: from_public.accumulated_data.note_hashes, 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 28057fb9c69..6ce371efcf9 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 @@ -256,6 +256,7 @@ pub fn encode_blob_prefix(input_type: u8, array_len: u32) -> Field { // MAX_CONTRACT_CLASS_LOGS_PER_TX fields for contract class logs // 7 fields for prefixes for each of the above categories pub(crate) global TX_EFFECTS_BLOB_HASH_INPUT_FIELDS: u32 = 1 + + 1 + 1 + MAX_NOTE_HASHES_PER_TX + MAX_NULLIFIERS_PER_TX @@ -277,8 +278,8 @@ pub(crate) fn append_tx_effects_for_blob( let mut out_sponge = start_sponge_blob; // If we have an empty tx (usually a padding tx), we don't want to absorb anything - // An empty tx will only have 2 effects - revert code and fee - hence offset = 2 - if offset != 2 { + // An empty tx will only have 3 effects - revert code, tx hash and fee - hence offset = 3 + if offset != 3 { out_sponge.absorb(tx_effects_hash_input, offset); } @@ -313,6 +314,9 @@ fn get_tx_effects_hash_input( // We only know the value once the appending is complete, hence we overwrite input[0] below offset += 1; + assert_eq(tx_effects_hash_input[offset], tx_effect.tx_hash); + offset += 1; + // TX FEE // Using 29 bytes to encompass all reasonable fee lengths assert_eq( @@ -505,6 +509,9 @@ unconstrained fn get_tx_effects_hash_input_helper( tx_effects_hash_input[offset] = 0; offset += 1; + tx_effects_hash_input[offset] = tx_effect.tx_hash; + offset += 1; + // TX FEE // Using 29 bytes to encompass all reasonable fee lengths tx_effects_hash_input[offset] = field_from_bytes( diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index d0ae676ad39..fbd2d4d941b 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -53,6 +53,10 @@ export class TxEffect { * Whether the transaction reverted during public app logic. */ public revertCode: RevertCode, + /** + * The identifier of the transaction. + */ + public txHash: TxHash, /** * The transaction fee, denominated in FPA. */ @@ -162,6 +166,7 @@ export class TxEffect { return new TxEffect( RevertCode.fromBuffer(reader), + TxHash.fromBuffer(reader), Fr.fromBuffer(reader), reader.readVectorUint8Prefix(Fr), reader.readVectorUint8Prefix(Fr), @@ -208,6 +213,7 @@ export class TxEffect { const contractClassLogs = ContractClassTxL2Logs.random(1, 1); return new TxEffect( RevertCode.random(), + TxHash.random(), new Fr(Math.floor(Math.random() * 100_000)), makeTuple(MAX_NOTE_HASHES_PER_TX, Fr.random), makeTuple(MAX_NULLIFIERS_PER_TX, Fr.random), @@ -224,6 +230,7 @@ export class TxEffect { static empty(): TxEffect { return new TxEffect( RevertCode.OK, + TxHash.zero(), Fr.ZERO, [], [], @@ -490,9 +497,10 @@ export class TxEffect { }); } - static from(fields: Omit, 'txHash'>) { + static from(fields: FieldsOf) { return new TxEffect( fields.revertCode, + fields.txHash, fields.transactionFee, fields.noteHashes, fields.nullifiers, @@ -510,6 +518,7 @@ export class TxEffect { return z .object({ revertCode: RevertCode.schema, + txHash: TxHash.schema, transactionFee: schemas.Fr, noteHashes: z.array(schemas.Fr), nullifiers: z.array(schemas.Fr), @@ -548,8 +557,4 @@ export class TxEffect { static fromString(str: string) { return TxEffect.fromBuffer(hexToBuffer(str)); } - - get txHash(): TxHash { - return new TxHash(this.nullifiers[0]); - } } From 3d9022c4016ecaa03758a28ba31349f384ed1cf9 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 7 Jan 2025 16:41:16 +0000 Subject: [PATCH 11/29] update tx hash computation --- .../src/base/private_base_rollup.nr | 44 ++++++++----------- .../rollup-lib/src/base/public_base_rollup.nr | 30 ++++++++----- ..._to_public_kernel_circuit_public_inputs.nr | 13 +++++- ..._to_rollup_kernel_circuit_public_inputs.nr | 13 +++++- .../crates/types/src/constants.nr | 21 ++------- yarn-project/circuit-types/src/tx/tx.ts | 9 ++-- yarn-project/circuits.js/src/constants.gen.ts | 2 + ...ivate_kernel_tail_circuit_public_inputs.ts | 2 +- .../kernel/private_to_avm_accumulated_data.ts | 25 ++++++++++- .../private_to_public_accumulated_data.ts | 19 +++++++- ..._to_public_kernel_circuit_public_inputs.ts | 32 +++++++++++++- .../private_to_rollup_accumulated_data.ts | 19 +++++++- .../src/structs/kernel/tx_constant_data.ts | 13 +++++- .../src/structs/l2_to_l1_message.ts | 19 +++++++- .../src/structs/rollup_validation_requests.ts | 18 +++++++- .../src/orchestrator/tx-proving-state.ts | 2 +- .../simulator/src/public/public_tx_context.ts | 23 ++-------- .../src/public/public_tx_simulator.ts | 6 +-- 18 files changed, 213 insertions(+), 97 deletions(-) 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 75dff1c708a..733d724caba 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 @@ -117,7 +117,7 @@ impl PrivateBaseRollupInputs { let out_hash = compute_kernel_out_hash(siloed_l2_to_l1_msgs); let tx_effect = TxEffect { - tx_hash: 27, + tx_hash: self.tube_data.public_inputs.hash(), revert_code: 0, transaction_fee, note_hashes: self.tube_data.public_inputs.end.note_hashes, @@ -823,12 +823,13 @@ mod tests { unconstrained fn non_empty_tx_effects_sponge() { let mut builder = PrivateBaseRollupInputsBuilder::new(); builder.tube_data.append_note_hashes(50); - let outputs = builder.execute(); - let mut tx_effects = [0; 53]; - // TODO(#8954): This test uses 50 notes and 3 extra absorbed fields + let inputs = builder.build_inputs(); + let outputs = inputs.execute(); + let mut tx_effects = [0; 54]; + // TODO(#8954): This test uses 50 notes and 4 extra absorbed fields // This may change when logs are deconstructed // Initial field = TX_START_PREFIX | 0 | txlen[0] txlen[1] | 0 | REVERT_CODE_PREFIX | 0 | revert_code - // The first 3 are: i=0 init field, i=1: tx fee, i=2: note prefix + // The first 4 are: i=0 init field, i=1: tx hash, i=2: tx fee, i=3: note prefix tx_effects[0] = field_from_bytes( array_concat( TX_START_PREFIX.to_be_bytes::<8>(), @@ -836,13 +837,15 @@ mod tests { ), true, ); - tx_effects[1] = field_from_bytes( + // TX hash + tx_effects[1] = inputs.tube_data.public_inputs.hash(); + tx_effects[2] = field_from_bytes( array_concat([TX_FEE_PREFIX, 0], (0).to_be_bytes::<29>()), true, ); - tx_effects[2] = encode_blob_prefix(NOTES_PREFIX, 50); + tx_effects[3] = encode_blob_prefix(NOTES_PREFIX, 50); for i in 0..50 { - tx_effects[i + 3] = builder.tube_data.note_hashes.storage()[i].value(); + tx_effects[i + 4] = builder.tube_data.note_hashes.storage()[i].value(); } let mut expected_sponge = outputs.start_sponge_blob; @@ -856,21 +859,8 @@ mod tests { let NUM_NULLIFIERS = 3; let NUM_MSGS = 5; let NUM_PRIV_EVENT_LOGS = 4; - let NUM_UNENC_LOGS = 6; let NUM_CC_LOGS = 1; - let TOTAL_BLOB_FIELDS = 2 // revert code and tx fee - + NUM_NOTES - + 1 // notes and prefix - + NUM_NULLIFIERS - + 1 // nullifiers and prefix - + NUM_MSGS - + 1 // L2 to L1 msgs and prefix - + NUM_UNENC_LOGS - + 1 // unenc. logs and prefix - + NUM_CC_LOGS - + 1 // contract class logs and prefix - + (NUM_NOTES + NUM_PRIV_EVENT_LOGS) * PRIVATE_LOG_SIZE_IN_FIELDS - + 1; // private logs and prefix + let mut builder = PrivateBaseRollupInputsBuilder::new(); builder.tube_data.set_gas_used(100, 200); builder.constants.global_variables.gas_fees.fee_per_da_gas = 1; @@ -894,17 +884,19 @@ mod tests { builder.tube_data.append_private_logs(NUM_PRIV_EVENT_LOGS); // Below will only work with NUM_CC_LOGS=1 builder.tube_data.add_contract_class_log_hash(1, 2); - let outputs = builder.execute(); + let inputs = builder.build_inputs(); + let outputs = inputs.execute(); let mut reconstructed_tx_effects = [0; TX_EFFECTS_BLOB_HASH_INPUT_FIELDS]; - + // tx hash + reconstructed_tx_effects[1] = inputs.tube_data.public_inputs.hash(); // tx fee - reconstructed_tx_effects[1] = field_from_bytes( + reconstructed_tx_effects[2] = field_from_bytes( array_concat([TX_FEE_PREFIX, 0], tx_fee.to_be_bytes::<29>()), true, ); // notes - let mut offset = 2; + let mut offset = 3; let notes_prefix = encode_blob_prefix(NOTES_PREFIX, NUM_NOTES); reconstructed_tx_effects[offset] = notes_prefix; offset += 1; 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 f358b2cf4b0..48ae1a689a8 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 @@ -87,7 +87,7 @@ impl PublicBaseRollupInputs { .fold(0, |len, l: ScopedLogHash| len + l.log_hash.length); TxEffect { - tx_hash: 27, + tx_hash: self.tube_data.public_inputs.hash(), revert_code, transaction_fee: from_public.transaction_fee, note_hashes: from_public.accumulated_data.note_hashes, @@ -918,12 +918,13 @@ mod tests { unconstrained fn non_empty_tx_effects_sponge() { let mut builder = PublicBaseRollupInputsBuilder::new(); builder.avm_data.append_note_hashes(50); - let outputs = builder.execute(); - let mut tx_effects = [0; 53]; - // TODO(#8954): This test uses 50 notes and 3 extra absorbed fields + let inputs = builder.build_inputs(); + let outputs = inputs.execute(); + let mut tx_effects = [0; 54]; + // TODO(#8954): This test uses 50 notes and 4 extra absorbed fields // This may change when logs are deconstructed // Initial field = TX_START_PREFIX | 0 | txlen[0] txlen[1] | 0 | REVERT_CODE_PREFIX | 0 | revert_code - // The first 3 are: i=0 init field, i=1: tx fee, i=2: note prefix + // The first 4 are: i=0 init field, i=1: tx hash, i=2: tx fee, i=3: note prefix tx_effects[0] = field_from_bytes( array_concat( TX_START_PREFIX.to_be_bytes::<8>(), @@ -931,13 +932,15 @@ mod tests { ), true, ); - tx_effects[1] = field_from_bytes( + // TX hash + tx_effects[1] = inputs.tube_data.public_inputs.hash(); + tx_effects[2] = field_from_bytes( array_concat([TX_FEE_PREFIX, 0], (0).to_be_bytes::<29>()), true, ); - tx_effects[2] = encode_blob_prefix(NOTES_PREFIX, 50); + tx_effects[3] = encode_blob_prefix(NOTES_PREFIX, 50); for i in 0..50 { - tx_effects[i + 3] = builder.avm_data.note_hashes.storage()[i].value(); + tx_effects[i + 4] = builder.avm_data.note_hashes.storage()[i].value(); } let mut expected_sponge = outputs.start_sponge_blob; @@ -955,7 +958,7 @@ mod tests { let NUM_CC_LOGS = 1; let PUB_DATA_SLOT = 25; let PUB_DATA_VALUE = 60; - let TOTAL_BLOB_FIELDS = 2 // revert code and tx fee + let TOTAL_BLOB_FIELDS = 3 // revert code, tx hash and tx fee + NUM_NOTES + 1 // notes and prefix + NUM_NULLIFIERS @@ -995,7 +998,8 @@ mod tests { builder.avm_data.append_unencrypted_log_hashes(NUM_UNENC_LOGS); // Below will only work with NUM_CC_LOGS=1 builder.tube_data.add_contract_class_log_hash(1, 2); - let outputs = builder.execute(); + let inputs = builder.build_inputs(); + let outputs = inputs.execute(); let mut reconstructed_tx_effects = [0; TX_EFFECTS_BLOB_HASH_INPUT_FIELDS]; // Initial field = TX_START_PREFIX | 0 | txlen[0] txlen[1] | 0 | REVERT_CODE_PREFIX | 0 | revert_code @@ -1016,13 +1020,15 @@ mod tests { ), true, ); + // tx hash + reconstructed_tx_effects[1] = inputs.tube_data.public_inputs.hash(); // tx fee - reconstructed_tx_effects[1] = field_from_bytes( + reconstructed_tx_effects[2] = field_from_bytes( array_concat([TX_FEE_PREFIX, 0], tx_fee.to_be_bytes::<29>()), true, ); // notes - let mut offset = 2; + let mut offset = 3; let notes_prefix = encode_blob_prefix(NOTES_PREFIX, NUM_NOTES); reconstructed_tx_effects[offset] = notes_prefix; offset += 1; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_public_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_public_kernel_circuit_public_inputs.nr index 517f6870590..265fc2e1ba2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_public_kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_public_kernel_circuit_public_inputs.nr @@ -5,8 +5,11 @@ use crate::{ validation_requests::RollupValidationRequests, }, address::AztecAddress, - constants::PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, - traits::{Deserialize, Empty, Serialize}, + constants::{ + GENERATOR_INDEX__PUBLIC_TX_HASH, PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, + }, + hash::poseidon2_hash_with_separator, + traits::{Deserialize, Empty, Hash, Serialize}, utils::reader::Reader, }; @@ -65,6 +68,12 @@ impl Serialize for Privat } } +impl Hash for PrivateToPublicKernelCircuitPublicInputs { + fn hash(self) -> Field { + poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_TX_HASH) + } +} + impl Deserialize for PrivateToPublicKernelCircuitPublicInputs { fn deserialize( fields: [Field; PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_rollup_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_rollup_kernel_circuit_public_inputs.nr index 509e62604b6..1a3a31ee3f5 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_rollup_kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_rollup_kernel_circuit_public_inputs.nr @@ -4,8 +4,11 @@ use crate::{ tx_constant_data::TxConstantData, validation_requests::RollupValidationRequests, }, address::AztecAddress, - constants::PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, - traits::{Deserialize, Empty, Serialize}, + constants::{ + GENERATOR_INDEX__PRIVATE_TX_HASH, PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, + }, + hash::poseidon2_hash_with_separator, + traits::{Deserialize, Empty, Hash, Serialize}, utils::reader::Reader, }; @@ -56,6 +59,12 @@ impl Serialize for Privat } } +impl Hash for PrivateToRollupKernelCircuitPublicInputs { + fn hash(self) -> Field { + poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__PRIVATE_TX_HASH) + } +} + impl Deserialize for PrivateToRollupKernelCircuitPublicInputs { fn deserialize( fields: [Field; PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 9be98412f5c..d0114e662a3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -490,20 +490,7 @@ pub global AVM_PROOF_LENGTH_IN_FIELDS: u32 = 4155; pub global AVM_PUBLIC_COLUMN_MAX_SIZE: u32 = 1024; pub global AVM_PUBLIC_INPUTS_FLATTENED_SIZE: u32 = 2 * AVM_PUBLIC_COLUMN_MAX_SIZE + PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH; -/** - * Enumerate the hash_indices which are used for pedersen hashing. - * We start from 1 to avoid the default generators. The generator indices are listed - * based on the number of elements each index hashes. The following conditions must be met: - * - * +-----------+-------------------------------+----------------------+ - * | Hash size | Number of elements hashed (n) | Condition to use | - * |-----------+-------------------------------+----------------------| - * | LOW | n <= 8 | 0 < hash_index <= 32 | - * | MID | 8 < n <= 16 | 32 < hash_index <= 40 | - * | HIGH | 16 < n <= 48 | 40 < hash_index <= 48 | - * +-----------+-------------------------------+----------------------+ - */ -// Indices with size <= 8 + pub global GENERATOR_INDEX__NOTE_HASH: u32 = 1; pub global GENERATOR_INDEX__NOTE_HASH_NONCE: u32 = 2; pub global GENERATOR_INDEX__UNIQUE_NOTE_HASH: u32 = 3; @@ -536,14 +523,11 @@ pub global GENERATOR_INDEX__SIDE_EFFECT: u32 = 29; pub global GENERATOR_INDEX__FEE_PAYLOAD: u32 = 30; pub global GENERATOR_INDEX__COMBINED_PAYLOAD: u32 = 31; pub global GENERATOR_INDEX__TX_NULLIFIER: u32 = 32; -// Indices with size <= 16 pub global GENERATOR_INDEX__TX_REQUEST: u32 = 33; pub global GENERATOR_INDEX__SIGNATURE_PAYLOAD: u32 = 34; -// Indices with size <= 44 pub global GENERATOR_INDEX__VK: u32 = 41; pub global GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS: u32 = 42; pub global GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS: u32 = 43; -// TODO: Function args generator index is being used to hash 64 items pub global GENERATOR_INDEX__FUNCTION_ARGS: u32 = 44; pub global GENERATOR_INDEX__AUTHWIT_INNER: u32 = 45; pub global GENERATOR_INDEX__AUTHWIT_OUTER: u32 = 46; @@ -558,6 +542,9 @@ pub global GENERATOR_INDEX__NOTE_NULLIFIER: u32 = 53; pub global GENERATOR_INDEX__NOTE_HIDING_POINT: u32 = 54; pub global GENERATOR_INDEX__SYMMETRIC_KEY: u8 = 55; +pub global GENERATOR_INDEX__PUBLIC_TX_HASH: u32 = 56; +pub global GENERATOR_INDEX__PRIVATE_TX_HASH: u32 = 57; + // AVM memory tags pub global MEM_TAG_FF: Field = 0; pub global MEM_TAG_U1: Field = 1; diff --git a/yarn-project/circuit-types/src/tx/tx.ts b/yarn-project/circuit-types/src/tx/tx.ts index 4f95a81af7b..d5fcf03ead2 100644 --- a/yarn-project/circuit-types/src/tx/tx.ts +++ b/yarn-project/circuit-types/src/tx/tx.ts @@ -171,11 +171,10 @@ export class Tx extends Gossipable { * @returns The transaction's hash. */ getTxHash(): TxHash { - // Private kernel functions are executed client side and for this reason tx hash is already set as first nullifier - const firstNullifier = this.data.getNonEmptyNullifiers()[0]; - if (!firstNullifier || firstNullifier.isZero()) { - throw new Error(`Cannot get tx hash since first nullifier is missing`); - } + const hash = this.data.forPublic + ? this.data.toPrivateToPublicKernelCircuitPublicInputs().hash() + : this.data.toPrivateToRollupKernelCircuitPublicInputs().hash(); + return new TxHash(firstNullifier); } diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 2153492a399..ef28cb8f1ca 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -396,4 +396,6 @@ export enum GeneratorIndex { NOTE_NULLIFIER = 53, NOTE_HIDING_POINT = 54, SYMMETRIC_KEY = 55, + PUBLIC_TX_HASH = 56, + PRIVATE_TX_HASH = 57, } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts index 14d20e21a11..fe26df4df1c 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts @@ -144,7 +144,7 @@ export class PrivateKernelTailCircuitPublicInputs { ); } - toPublicKernelCircuitPublicInputs() { + toPrivateToPublicKernelCircuitPublicInputs() { if (!this.forPublic) { throw new Error('Private tail public inputs is not for public circuit.'); } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_to_avm_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_avm_accumulated_data.ts index 75026cd5371..66eaee844ea 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_to_avm_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_avm_accumulated_data.ts @@ -1,11 +1,22 @@ import { type FieldsOf, makeTuple } from '@aztec/foundation/array'; import { arraySerializedSizeOfNonEmpty } from '@aztec/foundation/collection'; import { Fr } from '@aztec/foundation/fields'; -import { BufferReader, FieldReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; +import { + BufferReader, + FieldReader, + type Tuple, + serializeToBuffer, + serializeToFields, +} from '@aztec/foundation/serialize'; import { inspect } from 'util'; -import { MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX } from '../../constants.gen.js'; +import { + MAX_L2_TO_L1_MSGS_PER_TX, + MAX_NOTE_HASHES_PER_TX, + MAX_NULLIFIERS_PER_TX, + PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH, +} from '../../constants.gen.js'; import { ScopedL2ToL1Message } from '../l2_to_l1_message.js'; import { type UInt32 } from '../shared.js'; @@ -37,6 +48,16 @@ export class PrivateToAvmAccumulatedData { ); } + toFields(): Fr[] { + const fields = serializeToFields(...PrivateToAvmAccumulatedData.getFields(this)); + if (fields.length !== PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH) { + throw new Error( + `Invalid number of fields for PrivateToAvmAccumulatedData. Expected ${PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH}, got ${fields.length}`, + ); + } + return fields; + } + static from(fields: FieldsOf) { return new PrivateToAvmAccumulatedData(...PrivateToAvmAccumulatedData.getFields(fields)); } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_to_public_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_public_accumulated_data.ts index 99a3c48fa22..b9df967a756 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_to_public_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_public_accumulated_data.ts @@ -1,7 +1,13 @@ import { type FieldsOf, makeTuple } from '@aztec/foundation/array'; import { arraySerializedSizeOfNonEmpty } from '@aztec/foundation/collection'; import { Fr } from '@aztec/foundation/fields'; -import { BufferReader, FieldReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; +import { + BufferReader, + FieldReader, + type Tuple, + serializeToBuffer, + serializeToFields, +} from '@aztec/foundation/serialize'; import { inspect } from 'util'; @@ -12,6 +18,7 @@ import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX, + PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH, } from '../../constants.gen.js'; import { ScopedL2ToL1Message } from '../l2_to_l1_message.js'; import { ScopedLogHash } from '../log_hash.js'; @@ -82,6 +89,16 @@ export class PrivateToPublicAccumulatedData { return serializeToBuffer(...PrivateToPublicAccumulatedData.getFields(this)); } + toFields(): Fr[] { + const fields = serializeToFields(...PrivateToPublicAccumulatedData.getFields(this)); + if (fields.length !== PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH) { + throw new Error( + `Invalid number of fields for PrivateToPublicAccumulatedData. Expected ${PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH}, got ${fields.length}`, + ); + } + return fields; + } + static empty() { return new PrivateToPublicAccumulatedData( makeTuple(MAX_NOTE_HASHES_PER_TX, Fr.zero), diff --git a/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts index ed837be8084..0c5a5247e5d 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts @@ -1,7 +1,11 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; +import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; +import { type Fr } from '@aztec/foundation/fields'; +import { BufferReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize'; import { bufferToHex, hexToBuffer } from '@aztec/foundation/string'; +import { type FieldsOf } from '@aztec/foundation/types'; +import { GeneratorIndex, PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH } from '../../constants.gen.js'; import { Gas } from '../gas.js'; import { PublicCallRequest } from '../public_call_request.js'; import { RollupValidationRequests } from '../rollup_validation_requests.js'; @@ -31,6 +35,18 @@ export class PrivateToPublicKernelCircuitPublicInputs { ); } + static getFields(fields: FieldsOf) { + return [ + fields.constants, + fields.rollupValidationRequests, + fields.nonRevertibleAccumulatedData, + fields.revertibleAccumulatedData, + fields.publicTeardownCallRequest, + fields.gasUsed, + fields.feePayer, + ] as const; + } + static fromBuffer(buffer: Buffer | BufferReader) { const reader = BufferReader.asReader(buffer); return new PrivateToPublicKernelCircuitPublicInputs( @@ -63,4 +79,18 @@ export class PrivateToPublicKernelCircuitPublicInputs { toString() { return bufferToHex(this.toBuffer()); } + + toFields(): Fr[] { + const fields = serializeToFields(...PrivateToPublicKernelCircuitPublicInputs.getFields(this)); + if (fields.length !== PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH) { + throw new Error( + `Invalid number of fields for PrivateToPublicKernelCircuitPublicInputs. Expected ${PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH}, got ${fields.length}`, + ); + } + return fields; + } + + hash() { + return poseidon2HashWithSeparator(this.toFields(), GeneratorIndex.PUBLIC_TX_HASH); + } } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts index fc3fcc0b9cb..be7155c90d1 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts @@ -1,18 +1,21 @@ import { type FieldsOf, makeTuple } from '@aztec/foundation/array'; import { arraySerializedSizeOfNonEmpty } from '@aztec/foundation/collection'; +import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { bufferSchemaFor } from '@aztec/foundation/schemas'; -import { BufferReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; +import { BufferReader, type Tuple, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize'; import { bufferToHex, hexToBuffer } from '@aztec/foundation/string'; import { inspect } from 'util'; import { + GeneratorIndex, 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, + PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH, } from '../../constants.gen.js'; import { ScopedL2ToL1Message } from '../l2_to_l1_message.js'; import { ScopedLogHash } from '../log_hash.js'; @@ -129,6 +132,20 @@ export class PrivateToRollupAccumulatedData { ); } + toFields(): Fr[] { + const fields = serializeToFields(...PrivateToRollupAccumulatedData.getFields(this)); + if (fields.length !== PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH) { + throw new Error( + `Invalid number of fields for PrivateToRollupAccumulatedData. Expected ${PRIVATE_TO_ROLLUP_ACCUMULATED_DATA_LENGTH}, got ${fields.length}`, + ); + } + return fields; + } + + hash() { + return poseidon2HashWithSeparator(this.toFields(), GeneratorIndex.PRIVATE_TX_HASH); + } + [inspect.custom]() { return `PrivateToRollupAccumulatedData { noteHashes: [${this.noteHashes diff --git a/yarn-project/circuits.js/src/structs/kernel/tx_constant_data.ts b/yarn-project/circuits.js/src/structs/kernel/tx_constant_data.ts index 67549544e4a..361852982ad 100644 --- a/yarn-project/circuits.js/src/structs/kernel/tx_constant_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/tx_constant_data.ts @@ -1,7 +1,8 @@ import { Fr } from '@aztec/foundation/fields'; -import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize'; +import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize'; import { type FieldsOf } from '@aztec/foundation/types'; +import { TX_CONSTANT_DATA_LENGTH } from '../../constants.gen.js'; import { BlockHeader } from '../block_header.js'; import { TxContext } from '../tx_context.js'; @@ -49,6 +50,16 @@ export class TxConstantData { ); } + toFields(): Fr[] { + const fields = serializeToFields(...TxConstantData.getFields(this)); + if (fields.length !== TX_CONSTANT_DATA_LENGTH) { + throw new Error( + `Invalid number of fields for TxConstantData. Expected ${TX_CONSTANT_DATA_LENGTH}, got ${fields.length}`, + ); + } + return fields; + } + static fromBuffer(buffer: Buffer | BufferReader): TxConstantData { const reader = BufferReader.asReader(buffer); return new TxConstantData( diff --git a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts index 37d1ae3c811..d6954188600 100644 --- a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts +++ b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts @@ -1,9 +1,10 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; -import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize'; +import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize'; +import { type FieldsOf } from '@aztec/foundation/types'; -import { L2_TO_L1_MESSAGE_LENGTH } from '../constants.gen.js'; +import { L2_TO_L1_MESSAGE_LENGTH, SCOPED_L2_TO_L1_MESSAGE_LENGTH } from '../constants.gen.js'; export class L2ToL1Message { constructor(public recipient: EthAddress, public content: Fr, public counter: number) {} @@ -85,6 +86,10 @@ export class L2ToL1Message { export class ScopedL2ToL1Message { constructor(public message: L2ToL1Message, public contractAddress: AztecAddress) {} + static getFields(fields: FieldsOf) { + return [fields.message, fields.contractAddress] as const; + } + static empty() { return new ScopedL2ToL1Message(L2ToL1Message.empty(), AztecAddress.ZERO); } @@ -107,6 +112,16 @@ export class ScopedL2ToL1Message { return new ScopedL2ToL1Message(reader.readObject(L2ToL1Message), reader.readObject(AztecAddress)); } + toFields(): Fr[] { + const fields = serializeToFields(...ScopedL2ToL1Message.getFields(this)); + if (fields.length !== SCOPED_L2_TO_L1_MESSAGE_LENGTH) { + throw new Error( + `Invalid number of fields for ScopedL2ToL1Message. Expected ${SCOPED_L2_TO_L1_MESSAGE_LENGTH}, got ${fields.length}`, + ); + } + return fields; + } + isEmpty(): boolean { return this.message.isEmpty() && this.contractAddress.isZero(); } diff --git a/yarn-project/circuits.js/src/structs/rollup_validation_requests.ts b/yarn-project/circuits.js/src/structs/rollup_validation_requests.ts index 2d2279b8c88..c415c981782 100644 --- a/yarn-project/circuits.js/src/structs/rollup_validation_requests.ts +++ b/yarn-project/circuits.js/src/structs/rollup_validation_requests.ts @@ -1,7 +1,9 @@ import { type Fr } from '@aztec/foundation/fields'; -import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize'; +import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize'; import { bufferToHex, hexToBuffer } from '@aztec/foundation/string'; +import { type FieldsOf } from '@aztec/foundation/types'; +import { ROLLUP_VALIDATION_REQUESTS_LENGTH } from '../constants.gen.js'; import { MaxBlockNumber } from './max_block_number.js'; /** @@ -27,11 +29,25 @@ export class RollupValidationRequests { return bufferToHex(this.toBuffer()); } + static getFields(fields: FieldsOf) { + return [fields.maxBlockNumber] as const; + } + static fromFields(fields: Fr[] | FieldReader) { const reader = FieldReader.asReader(fields); return new RollupValidationRequests(MaxBlockNumber.fromFields(reader)); } + toFields(): Fr[] { + const fields = serializeToFields(...RollupValidationRequests.getFields(this)); + if (fields.length !== ROLLUP_VALIDATION_REQUESTS_LENGTH) { + throw new Error( + `Invalid number of fields for RollupValidationRequests. Expected ${ROLLUP_VALIDATION_REQUESTS_LENGTH}, got ${fields.length}`, + ); + } + return fields; + } + /** * Deserializes from a buffer or reader, corresponding to a write in cpp. * @param buffer - Buffer or reader to read from. diff --git a/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts b/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts index 0460b11b3b0..32774d94c98 100644 --- a/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts +++ b/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts @@ -84,7 +84,7 @@ export class TxProvingState { } const tubeData = new PublicTubeData( - this.processedTx.data.toPublicKernelCircuitPublicInputs(), + this.processedTx.data.toPrivateToPublicKernelCircuitPublicInputs(), this.tube.proof, this.getTubeVkData(), ); diff --git a/yarn-project/simulator/src/public/public_tx_context.ts b/yarn-project/simulator/src/public/public_tx_context.ts index 0c376934a20..9cbc53cca2b 100644 --- a/yarn-project/simulator/src/public/public_tx_context.ts +++ b/yarn-project/simulator/src/public/public_tx_context.ts @@ -7,7 +7,7 @@ import { type SimulationError, type Tx, TxExecutionPhase, - TxHash, + type TxHash, } from '@aztec/circuit-types'; import { AvmCircuitInputs, @@ -61,6 +61,7 @@ export class PublicTxContext { public avmProvingRequest: AvmProvingRequest | undefined; // FIXME(dbanks12): remove constructor( + public readonly txHash: TxHash, public readonly state: PhaseStateManager, private readonly globalVariables: GlobalVariables, private readonly startStateReference: StateReference, @@ -108,7 +109,7 @@ export class PublicTxContext { worldStateDB, enqueuedCallTrace, doMerkleOperations, - fetchTxHash(nonRevertibleAccumulatedDataFromPrivate), + tx.getTxHash(), ); const gasSettings = tx.data.constants.txContext.gasSettings; @@ -117,6 +118,7 @@ export class PublicTxContext { const gasAllocatedToPublic = applyMaxToAvailableGas(gasSettings.gasLimits.sub(gasUsedByPrivate)); return new PublicTxContext( + tx.getTxHash(), new PhaseStateManager(txStateManager), globalVariables, await db.getStateReference(), @@ -188,14 +190,6 @@ export class PublicTxContext { return this.revertCode; } - /** - * Construct & return transaction hash. - * @returns The transaction's hash. - */ - getTxHash(): TxHash { - return fetchTxHash(this.nonRevertibleAccumulatedDataFromPrivate); - } - /** * Are there any call requests for the speciiied phase? */ @@ -452,12 +446,3 @@ function applyMaxToAvailableGas(availableGas: Gas) { /*l2Gas=*/ Math.min(availableGas.l2Gas, MAX_L2_GAS_PER_TX_PUBLIC_PORTION), ); } - -function fetchTxHash(nonRevertibleAccumulatedData: PrivateToPublicAccumulatedData): TxHash { - // Private kernel functions are executed client side and for this reason tx hash is already set as first nullifier - const firstNullifier = nonRevertibleAccumulatedData.nullifiers[0]; - if (!firstNullifier || firstNullifier.isZero()) { - throw new Error(`Cannot get tx hash since first nullifier is missing`); - } - return new TxHash(firstNullifier); -} diff --git a/yarn-project/simulator/src/public/public_tx_simulator.ts b/yarn-project/simulator/src/public/public_tx_simulator.ts index b4c91484e27..e973d28f654 100644 --- a/yarn-project/simulator/src/public/public_tx_simulator.ts +++ b/yarn-project/simulator/src/public/public_tx_simulator.ts @@ -219,8 +219,8 @@ export class PublicTxSimulator { const callRequests = context.getCallRequestsForPhase(phase); const executionRequests = context.getExecutionRequestsForPhase(phase); - this.log.debug(`Processing phase ${TxExecutionPhase[phase]} for tx ${context.getTxHash()}`, { - txHash: context.getTxHash().toString(), + this.log.debug(`Processing phase ${TxExecutionPhase[phase]} for tx ${context.txHash}`, { + txHash: context.txHash.toString(), phase: TxExecutionPhase[phase], callRequests: callRequests.length, executionRequests: executionRequests.length, @@ -266,7 +266,7 @@ export class PublicTxSimulator { * @returns The result of execution. */ @trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, _callRequest, executionRequest) => ({ - [Attributes.TX_HASH]: context.getTxHash().toString(), + [Attributes.TX_HASH]: context.txHash.toString(), [Attributes.TARGET_ADDRESS]: executionRequest.callContext.contractAddress.toString(), [Attributes.SENDER_ADDRESS]: executionRequest.callContext.msgSender.toString(), [Attributes.SIMULATOR_PHASE]: TxExecutionPhase[phase].toString(), From e4de49d45dc81a1bd63b4216c06f050e0de82b55 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 7 Jan 2025 17:12:32 +0000 Subject: [PATCH 12/29] fix constants in processedtx --- yarn-project/circuit-types/src/tx/processed_tx.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index d0b166fd1b4..3aa13b5af68 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -4,10 +4,11 @@ import { CombinedConstantData, Fr, Gas, - type GlobalVariables, + GlobalVariables, PrivateKernelTailCircuitPublicInputs, type PublicDataWrite, RevertCode, + TxConstantData, } from '@aztec/circuits.js'; import { siloL2ToL1Message } from '@aztec/circuits.js/hash'; @@ -92,7 +93,7 @@ export function makeEmptyProcessedTx( vkTreeRoot: Fr, protocolContractTreeRoot: Fr, ): ProcessedTx { - const constants = CombinedConstantData.empty(); + const constants = TxConstantData.empty(); constants.historicalHeader = header; constants.txContext.chainId = chainId; constants.txContext.version = version; @@ -107,7 +108,7 @@ export function makeEmptyProcessedTx( data: clientProofOutput, clientIvcProof: ClientIvcProof.empty(), avmProvingRequest: undefined, - constants, + constants: CombinedConstantData.combine(constants, GlobalVariables.empty()), txEffect: TxEffect.empty(), gasUsed: { totalGas: Gas.empty(), From c6d133e87b83fafc45b8c7404cd9624813138f4e Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 7 Jan 2025 17:58:20 +0000 Subject: [PATCH 13/29] fix --- .../aztec-node/src/aztec-node/server.test.ts | 24 +++++++------------ .../circuit-types/src/tx/processed_tx.ts | 6 +++-- yarn-project/circuit-types/src/tx/tx.ts | 2 +- .../kernel/kernel_circuit_public_inputs.ts | 24 ++++++++++++++++++- .../private_to_rollup_accumulated_data.ts | 6 ----- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/yarn-project/aztec-node/src/aztec-node/server.test.ts b/yarn-project/aztec-node/src/aztec-node/server.test.ts index 942c544b26f..2734e7be2f6 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.test.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.test.ts @@ -10,7 +10,7 @@ import { type WorldStateSynchronizer, mockTxForRollup, } from '@aztec/circuit-types'; -import { type ContractDataSource, EthAddress, Fr, MaxBlockNumber } from '@aztec/circuits.js'; +import { type ContractDataSource, EthAddress, Fr, MaxBlockNumber, RollupValidationRequests } from '@aztec/circuits.js'; import { type P2P } from '@aztec/p2p'; import { type GlobalVariableBuilder } from '@aztec/sequencer-client'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; @@ -102,7 +102,7 @@ describe('aztec node', () => { expect(await node.isValidTx(doubleSpendTx)).toBe(true); // We push a duplicate nullifier that was created in the same transaction - doubleSpendTx.data.forRollup!.end.nullifiers.push(doubleSpendTx.data.forRollup!.end.nullifiers[0]); + doubleSpendTx.data.forRollup!.end.nullifiers[1] = doubleSpendTx.data.forRollup!.end.nullifiers[0]; expect(await node.isValidTx(doubleSpendTx)).toBe(false); @@ -142,19 +142,13 @@ describe('aztec node', () => { const invalidMaxBlockNumberMetadata = txs[1]; const validMaxBlockNumberMetadata = txs[2]; - invalidMaxBlockNumberMetadata.data.rollupValidationRequests = { - maxBlockNumber: new MaxBlockNumber(true, new Fr(1)), - getSize: () => 1, - toBuffer: () => Fr.ZERO.toBuffer(), - toString: () => Fr.ZERO.toString(), - }; - - validMaxBlockNumberMetadata.data.rollupValidationRequests = { - maxBlockNumber: new MaxBlockNumber(true, new Fr(5)), - getSize: () => 1, - toBuffer: () => Fr.ZERO.toBuffer(), - toString: () => Fr.ZERO.toString(), - }; + invalidMaxBlockNumberMetadata.data.rollupValidationRequests = new RollupValidationRequests( + new MaxBlockNumber(true, new Fr(1)), + ); + + validMaxBlockNumberMetadata.data.rollupValidationRequests = new RollupValidationRequests( + new MaxBlockNumber(true, new Fr(5)), + ); lastBlockNumber = 3; diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index 3aa13b5af68..7b1d56d0394 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -133,6 +133,7 @@ export function makeProcessedTxFromPrivateOnlyTx( const data = tx.data.forRollup!; const txEffect = new TxEffect( RevertCode.OK, + tx.getTxHash(), transactionFee, data.end.noteHashes.filter(h => !h.isZero()), data.end.nullifiers.filter(h => !h.isZero()), @@ -154,7 +155,7 @@ export function makeProcessedTxFromPrivateOnlyTx( } satisfies GasUsed; return { - hash: tx.getTxHash(), + hash: txEffect.txHash, data: tx.data, clientIvcProof: tx.clientIvcProof, avmProvingRequest: undefined, @@ -196,6 +197,7 @@ export function makeProcessedTxFromTxWithPublicCalls( const txEffect = new TxEffect( revertCode, + tx.getTxHash(), avmOutput.transactionFee, avmOutput.accumulatedData.noteHashes.filter(h => !h.isZero()), avmOutput.accumulatedData.nullifiers.filter(h => !h.isZero()), @@ -211,7 +213,7 @@ export function makeProcessedTxFromTxWithPublicCalls( ); return { - hash: tx.getTxHash(), + hash: txEffect.txHash, data: tx.data, clientIvcProof: tx.clientIvcProof, avmProvingRequest, diff --git a/yarn-project/circuit-types/src/tx/tx.ts b/yarn-project/circuit-types/src/tx/tx.ts index d5fcf03ead2..14e9c6d8ad0 100644 --- a/yarn-project/circuit-types/src/tx/tx.ts +++ b/yarn-project/circuit-types/src/tx/tx.ts @@ -175,7 +175,7 @@ export class Tx extends Gossipable { ? this.data.toPrivateToPublicKernelCircuitPublicInputs().hash() : this.data.toPrivateToRollupKernelCircuitPublicInputs().hash(); - return new TxHash(firstNullifier); + return new TxHash(hash); } /** Returns the tx hash, or undefined if none is set. */ diff --git a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts index c0fecd8b999..95c015fe353 100644 --- a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts @@ -1,8 +1,12 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; +import { type Fr } from '@aztec/foundation/fields'; import { bufferSchemaFor } from '@aztec/foundation/schemas'; -import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; +import { BufferReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize'; import { bufferToHex, hexToBuffer } from '@aztec/foundation/string'; +import { type FieldsOf } from '@aztec/foundation/types'; +import { GeneratorIndex, PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH } from '../../constants.gen.js'; import { Gas } from '../gas.js'; import { RollupValidationRequests } from '../rollup_validation_requests.js'; import { PrivateToRollupAccumulatedData } from './private_to_rollup_accumulated_data.js'; @@ -83,8 +87,26 @@ export class PrivateToRollupKernelCircuitPublicInputs { return this.toBuffer(); } + static getFields(fields: FieldsOf) { + return [fields.rollupValidationRequests, fields.end, fields.constants, fields.gasUsed, fields.feePayer] as const; + } + /** Creates an instance from a hex string. */ static get schema() { return bufferSchemaFor(PrivateToRollupKernelCircuitPublicInputs); } + + toFields(): Fr[] { + const fields = serializeToFields(...PrivateToRollupKernelCircuitPublicInputs.getFields(this)); + if (fields.length !== PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH) { + throw new Error( + `Invalid number of fields for PrivateToRollupKernelCircuitPublicInputs. Expected ${PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH}, got ${fields.length}`, + ); + } + return fields; + } + + hash() { + return poseidon2HashWithSeparator(this.toFields(), GeneratorIndex.PRIVATE_TX_HASH); + } } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts index be7155c90d1..7d511c61ca9 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.ts @@ -1,6 +1,5 @@ import { type FieldsOf, makeTuple } from '@aztec/foundation/array'; import { arraySerializedSizeOfNonEmpty } from '@aztec/foundation/collection'; -import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { bufferSchemaFor } from '@aztec/foundation/schemas'; import { BufferReader, type Tuple, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize'; @@ -9,7 +8,6 @@ import { bufferToHex, hexToBuffer } from '@aztec/foundation/string'; import { inspect } from 'util'; import { - GeneratorIndex, MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, @@ -142,10 +140,6 @@ export class PrivateToRollupAccumulatedData { return fields; } - hash() { - return poseidon2HashWithSeparator(this.toFields(), GeneratorIndex.PRIVATE_TX_HASH); - } - [inspect.custom]() { return `PrivateToRollupAccumulatedData { noteHashes: [${this.noteHashes From eb0afc0f84954dfd63ac399b8acea2413d49b345 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 7 Jan 2025 20:24:34 +0000 Subject: [PATCH 14/29] fix tobuffer --- yarn-project/circuit-types/src/tx_effect.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index fbd2d4d941b..aa1eb2828f4 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -143,6 +143,7 @@ export class TxEffect { toBuffer(): Buffer { return serializeToBuffer([ this.revertCode, + this.txHash, this.transactionFee, serializeArrayOfBufferableToVector(this.noteHashes, 1), serializeArrayOfBufferableToVector(this.nullifiers, 1), From 0058c2b1d83dcadafa098af2c698eeba79553b8f Mon Sep 17 00:00:00 2001 From: sirasistant Date: Wed, 8 Jan 2025 11:12:46 +0000 Subject: [PATCH 15/29] fix --- .../private_to_rollup_kernel_circuit_public_inputs.nr | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_rollup_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_rollup_kernel_circuit_public_inputs.nr index efc67678613..887be0af24e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_rollup_kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_rollup_kernel_circuit_public_inputs.nr @@ -4,8 +4,11 @@ use crate::{ tx_constant_data::TxConstantData, validation_requests::RollupValidationRequests, }, address::AztecAddress, - constants::PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, - traits::{Deserialize, Empty, Serialize}, + constants::{ + GENERATOR_INDEX__PRIVATE_TX_HASH, PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, + }, + hash::poseidon2_hash_with_separator, + traits::{Deserialize, Empty, Hash, Serialize}, utils::reader::Reader, }; use std::meta::derive; From 9f7b6d5b2e516901f71fa698f91daee0098294a1 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Wed, 8 Jan 2025 12:34:03 +0000 Subject: [PATCH 16/29] fix blob parsing --- yarn-project/circuit-types/src/tx_effect.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index 4a86c8ccec3..3dd3e27b4ab 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -347,6 +347,8 @@ export class TxEffect { const flattened: Fr[] = []; // We reassign the first field when we know the length of all effects - see below flattened.push(Fr.ZERO); + + flattened.push(this.txHash.hash); // TODO: how long should tx fee be? For now, not using toPrefix() flattened.push( new Fr( @@ -417,6 +419,8 @@ export class TxEffect { } const { length: _, revertCode } = this.decodeFirstField(firstField); effect.revertCode = RevertCode.fromField(new Fr(revertCode)); + + effect.txHash = new TxHash(reader.readField()); // TODO: how long should tx fee be? For now, not using fromPrefix() const prefixedFee = reader.readField(); // NB: Fr.fromBuffer hangs here if you provide a buffer less than 32 in len From 6bf9a22c98053504048e54b389040f51b37d11af Mon Sep 17 00:00:00 2001 From: sirasistant Date: Wed, 8 Jan 2025 17:20:08 +0000 Subject: [PATCH 17/29] fixes --- .../aztec-node/src/aztec-node/server.ts | 2 +- yarn-project/circuit-types/src/tx/tx.ts | 40 ++++++++++++------- yarn-project/circuits.js/src/structs/index.ts | 2 +- ...ivate_kernel_tail_circuit_public_inputs.ts | 4 +- ..._to_public_kernel_circuit_public_inputs.ts | 2 +- ...to_rollup_kernel_circuit_public_inputs.ts} | 14 +++---- .../src/structs/rollup/private_tube_data.ts | 2 +- .../circuits.js/src/tests/factories.ts | 4 +- .../src/conversion/server.ts | 2 +- .../src/mem_pools/tx_pool/aztec_kv_tx_pool.ts | 13 +++++- .../mem_pools/tx_pool/tx_pool_test_suite.ts | 10 +++-- .../p2p/src/services/reqresp/reqresp.test.ts | 2 + .../prover-node/src/prover-node.test.ts | 4 +- .../brute_force_note_info.ts | 2 +- .../produce_note_daos.ts | 2 + .../produce_note_daos_for_key.ts | 2 + .../pxe/src/pxe_service/pxe_service.ts | 4 +- .../pxe/src/simulator_oracle/index.ts | 1 + .../simulator/src/public/public_processor.ts | 2 +- 19 files changed, 70 insertions(+), 44 deletions(-) rename yarn-project/circuits.js/src/structs/kernel/{kernel_circuit_public_inputs.ts => private_to_rollup_kernel_circuit_public_inputs.ts} (96%) diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 4b882875a94..102f16091ad 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -829,7 +829,7 @@ export class AztecNodeService implements AztecNode, Traceable { * @param tx - The transaction to simulate. **/ @trackSpan('AztecNodeService.simulatePublicCalls', (tx: Tx) => ({ - [Attributes.TX_HASH]: tx.tryGetTxHash()?.toString(), + [Attributes.TX_HASH]: tx.getTxHash().toString(), })) public async simulatePublicCalls(tx: Tx, enforceFeePayment = true): Promise { const txHash = tx.getTxHash(); diff --git a/yarn-project/circuit-types/src/tx/tx.ts b/yarn-project/circuit-types/src/tx/tx.ts index 22dd5d439d7..2c2f5319273 100644 --- a/yarn-project/circuit-types/src/tx/tx.ts +++ b/yarn-project/circuit-types/src/tx/tx.ts @@ -27,6 +27,8 @@ import { TxHash } from './tx_hash.js'; */ export class Tx extends Gossipable { static override p2pTopic: string; + // For memoization + private txHash: TxHash | undefined; constructor( /** @@ -169,24 +171,27 @@ export class Tx extends Gossipable { } /** - * Construct & return transaction hash. + * Computes (if necessary) & return transaction hash. * @returns The transaction's hash. */ - getTxHash(): TxHash { - const hash = this.data.forPublic - ? this.data.toPrivateToPublicKernelCircuitPublicInputs().hash() - : this.data.toPrivateToRollupKernelCircuitPublicInputs().hash(); - - return new TxHash(hash); + getTxHash(forceRecompute = false): TxHash { + if (!this.txHash || forceRecompute) { + const hash = this.data.forPublic + ? this.data.toPrivateToPublicKernelCircuitPublicInputs().hash() + : this.data.toPrivateToRollupKernelCircuitPublicInputs().hash(); + this.txHash = new TxHash(hash); + } + return this.txHash!; } - /** Returns the tx hash, or undefined if none is set. */ - tryGetTxHash(): TxHash | undefined { - try { - return this.getTxHash(); - } catch { - return undefined; - } + /** + * Allows setting the hash of the Tx. + * Use this when you want to skip computing it from the original data. + * Don't set a Tx hash received from an untrusted source. + * @param hash - The hash to set. + */ + setTxHash(hash: TxHash) { + this.txHash = hash; } /** Returns stats about this tx. */ @@ -277,7 +282,7 @@ export class Tx extends Gossipable { PublicExecutionRequest.fromBuffer(x.toBuffer()), ); const publicTeardownFunctionCall = PublicExecutionRequest.fromBuffer(tx.publicTeardownFunctionCall.toBuffer()); - return new Tx( + const clonedTx = new Tx( publicInputs, clientIvcProof, unencryptedLogs, @@ -285,6 +290,11 @@ export class Tx extends Gossipable { enqueuedPublicFunctionCalls, publicTeardownFunctionCall, ); + if (tx.txHash) { + clonedTx.setTxHash(TxHash.fromBuffer(tx.txHash.toBuffer())); + } + + return clonedTx; } static random() { diff --git a/yarn-project/circuits.js/src/structs/index.ts b/yarn-project/circuits.js/src/structs/index.ts index e4d61d294ac..5f5a43e9aca 100644 --- a/yarn-project/circuits.js/src/structs/index.ts +++ b/yarn-project/circuits.js/src/structs/index.ts @@ -19,7 +19,7 @@ export * from './indexed_tagging_secret.js'; export * from './kernel/private_to_rollup_accumulated_data.js'; export * from './kernel/combined_constant_data.js'; export * from './kernel/private_kernel_empty_inputs.js'; -export * from './kernel/kernel_circuit_public_inputs.js'; +export * from './kernel/private_to_rollup_kernel_circuit_public_inputs.js'; export * from './kernel/private_accumulated_data.js'; export * from './kernel/private_call_data.js'; export * from './kernel/private_kernel_circuit_public_inputs.js'; diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts index fe26df4df1c..9b389874bde 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts @@ -7,10 +7,10 @@ import { countAccumulatedItems, mergeAccumulatedData } from '../../utils/index.j import { Gas } from '../gas.js'; import { PublicCallRequest } from '../public_call_request.js'; import { RollupValidationRequests } from '../rollup_validation_requests.js'; -import { PrivateToRollupKernelCircuitPublicInputs } from './kernel_circuit_public_inputs.js'; import { PrivateToPublicAccumulatedData } from './private_to_public_accumulated_data.js'; import { PrivateToPublicKernelCircuitPublicInputs } from './private_to_public_kernel_circuit_public_inputs.js'; import { PrivateToRollupAccumulatedData } from './private_to_rollup_accumulated_data.js'; +import { PrivateToRollupKernelCircuitPublicInputs } from './private_to_rollup_kernel_circuit_public_inputs.js'; import { TxConstantData } from './tx_constant_data.js'; export class PartialPrivateTailPublicInputsForPublic { @@ -170,9 +170,9 @@ export class PrivateKernelTailCircuitPublicInputs { this.constants.protocolContractTreeRoot, ); return new PrivateToRollupKernelCircuitPublicInputs( + constants, this.rollupValidationRequests, this.forRollup.end, - constants, this.gasUsed, this.feePayer, ); diff --git a/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts index 0c5a5247e5d..1ab9f06abde 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts @@ -91,6 +91,6 @@ export class PrivateToPublicKernelCircuitPublicInputs { } hash() { - return poseidon2HashWithSeparator(this.toFields(), GeneratorIndex.PUBLIC_TX_HASH); + return poseidon2HashWithSeparator(this.toFields(), GeneratorIndex.PRIVATE_TX_HASH); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_kernel_circuit_public_inputs.ts similarity index 96% rename from yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts rename to yarn-project/circuits.js/src/structs/kernel/private_to_rollup_kernel_circuit_public_inputs.ts index 95c015fe353..c3d218f99f9 100644 --- a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_kernel_circuit_public_inputs.ts @@ -18,6 +18,10 @@ import { TxConstantData } from './tx_constant_data.js'; */ export class PrivateToRollupKernelCircuitPublicInputs { constructor( + /** + * Data which is not modified by the circuits. + */ + public constants: TxConstantData, /** * Validation requests accumulated from private and public execution to be completed by the rollup. */ @@ -26,10 +30,6 @@ export class PrivateToRollupKernelCircuitPublicInputs { * Data accumulated from both public and private circuits. */ public end: PrivateToRollupAccumulatedData, - /** - * Data which is not modified by the circuits. - */ - public constants: TxConstantData, /** * Gas used during this transaction */ @@ -56,9 +56,9 @@ export class PrivateToRollupKernelCircuitPublicInputs { static fromBuffer(buffer: Buffer | BufferReader): PrivateToRollupKernelCircuitPublicInputs { const reader = BufferReader.asReader(buffer); return new PrivateToRollupKernelCircuitPublicInputs( + reader.readObject(TxConstantData), reader.readObject(RollupValidationRequests), reader.readObject(PrivateToRollupAccumulatedData), - reader.readObject(TxConstantData), reader.readObject(Gas), reader.readObject(AztecAddress), ); @@ -66,9 +66,9 @@ export class PrivateToRollupKernelCircuitPublicInputs { static empty() { return new PrivateToRollupKernelCircuitPublicInputs( + TxConstantData.empty(), RollupValidationRequests.empty(), PrivateToRollupAccumulatedData.empty(), - TxConstantData.empty(), Gas.empty(), AztecAddress.ZERO, ); @@ -88,7 +88,7 @@ export class PrivateToRollupKernelCircuitPublicInputs { } static getFields(fields: FieldsOf) { - return [fields.rollupValidationRequests, fields.end, fields.constants, fields.gasUsed, fields.feePayer] as const; + return [fields.constants, fields.rollupValidationRequests, fields.end, fields.gasUsed, fields.feePayer] as const; } /** Creates an instance from a hex string. */ diff --git a/yarn-project/circuits.js/src/structs/rollup/private_tube_data.ts b/yarn-project/circuits.js/src/structs/rollup/private_tube_data.ts index b574dbc49b2..a6eac678493 100644 --- a/yarn-project/circuits.js/src/structs/rollup/private_tube_data.ts +++ b/yarn-project/circuits.js/src/structs/rollup/private_tube_data.ts @@ -1,7 +1,7 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '../../constants.gen.js'; -import { PrivateToRollupKernelCircuitPublicInputs } from '../kernel/kernel_circuit_public_inputs.js'; +import { PrivateToRollupKernelCircuitPublicInputs } from '../kernel/private_to_rollup_kernel_circuit_public_inputs.js'; import { RecursiveProof, makeEmptyRecursiveProof } from '../recursive_proof.js'; import { VkWitnessData } from '../vk_witness_data.js'; diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 1f7cde5ddfd..e7c222284f6 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -140,7 +140,7 @@ import { TxConstantData, VkWitnessData, } from '../structs/index.js'; -import { PrivateToRollupKernelCircuitPublicInputs } from '../structs/kernel/kernel_circuit_public_inputs.js'; +import { PrivateToRollupKernelCircuitPublicInputs } from '../structs/kernel/private_to_rollup_kernel_circuit_public_inputs.js'; import { AvmProofData } from '../structs/rollup/avm_proof_data.js'; import { BaseOrMergeRollupPublicInputs } from '../structs/rollup/base_or_merge_rollup_public_inputs.js'; import { PrivateBaseRollupHints, PublicBaseRollupHints } from '../structs/rollup/base_rollup_hints.js'; @@ -419,9 +419,9 @@ export function makePrivateToRollupKernelCircuitPublicInputs( fullAccumulatedData = true, ): PrivateToRollupKernelCircuitPublicInputs { return new PrivateToRollupKernelCircuitPublicInputs( + makeTxConstantData(seed + 0x100), makeRollupValidationRequests(seed), makePrivateToRollupAccumulatedData(seed, fullAccumulatedData), - makeTxConstantData(seed + 0x100), makeGas(seed + 0x600), makeAztecAddress(seed + 0x700), ); diff --git a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts index a53043c6082..6a6abf845bd 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts @@ -945,9 +945,9 @@ export function mapPrivateToRollupKernelCircuitPublicInputsFromNoir( inputs: PrivateToRollupKernelCircuitPublicInputsNoir, ) { return new PrivateToRollupKernelCircuitPublicInputs( + mapTxConstantDataFromNoir(inputs.constants), mapRollupValidationRequestsFromNoir(inputs.rollup_validation_requests), mapPrivateToRollupAccumulatedDataFromNoir(inputs.end), - mapTxConstantDataFromNoir(inputs.constants), mapGasFromNoir(inputs.gas_used), mapAztecAddressFromNoir(inputs.fee_payer), ); diff --git a/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts b/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts index 70c858f08fb..07708c60513 100644 --- a/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +++ b/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts @@ -111,7 +111,12 @@ export class AztecKVTxPool implements TxPool { */ public getTxByHash(txHash: TxHash): Tx | undefined { const buffer = this.#txs.get(txHash.toString()); - return buffer ? Tx.fromBuffer(buffer) : undefined; + if (buffer) { + const tx = Tx.fromBuffer(buffer); + tx.setTxHash(txHash); + return tx; + } + return undefined; } /** @@ -177,7 +182,11 @@ export class AztecKVTxPool implements TxPool { * @returns Array of tx objects in the order they were added to the pool. */ public getAllTxs(): Tx[] { - return Array.from(this.#txs.values()).map(buffer => Tx.fromBuffer(buffer)); + return Array.from(this.#txs.entries()).map(([hash, buffer]) => { + const tx = Tx.fromBuffer(buffer); + tx.setTxHash(TxHash.fromString(hash)); + return tx; + }); } /** diff --git a/yarn-project/p2p/src/mem_pools/tx_pool/tx_pool_test_suite.ts b/yarn-project/p2p/src/mem_pools/tx_pool/tx_pool_test_suite.ts index 35af12fbd68..7d8552f033d 100644 --- a/yarn-project/p2p/src/mem_pools/tx_pool/tx_pool_test_suite.ts +++ b/yarn-project/p2p/src/mem_pools/tx_pool/tx_pool_test_suite.ts @@ -67,10 +67,12 @@ export function describeTxPool(getTxPool: () => TxPool) { await pool.addTxs([tx1]); // this peer knows that tx2 was mined, but it does not have the tx object await pool.markAsMined([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], 1); - expect(pool.getMinedTxHashes()).toEqual([ - [tx1.getTxHash(), 1], - [someTxHashThatThisPeerDidNotSee, 1], - ]); + expect(new Set(pool.getMinedTxHashes())).toEqual( + new Set([ + [tx1.getTxHash(), 1], + [someTxHashThatThisPeerDidNotSee, 1], + ]), + ); // reorg: both txs should now become available again await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee]); diff --git a/yarn-project/p2p/src/services/reqresp/reqresp.test.ts b/yarn-project/p2p/src/services/reqresp/reqresp.test.ts index 11a951d9e33..e99e2f4cb55 100644 --- a/yarn-project/p2p/src/services/reqresp/reqresp.test.ts +++ b/yarn-project/p2p/src/services/reqresp/reqresp.test.ts @@ -153,6 +153,8 @@ describe('ReqResp', () => { await sleep(500); const res = await nodes[0].req.sendRequest(TX_REQ_PROTOCOL, txHash); + // Set tx hash since expect will compare private properties + res.getTxHash(); expect(res).toEqual(tx); }); diff --git a/yarn-project/prover-node/src/prover-node.test.ts b/yarn-project/prover-node/src/prover-node.test.ts index 56581e5e23d..10e223642fb 100644 --- a/yarn-project/prover-node/src/prover-node.test.ts +++ b/yarn-project/prover-node/src/prover-node.test.ts @@ -153,9 +153,7 @@ describe('prover-node', () => { l2BlockSource.getBlocksForEpoch.mockResolvedValue(blocks); // Coordination plays along and returns a tx whenever requested - mockCoordination.getTxByHash.mockImplementation(hash => - Promise.resolve(mock({ getTxHash: () => hash, tryGetTxHash: () => hash })), - ); + mockCoordination.getTxByHash.mockImplementation(hash => Promise.resolve(mock({ getTxHash: () => hash }))); // A sample claim claim = { epochToProve: 10n, bondProvider: address } as EpochProofClaim; diff --git a/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts b/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts index 7ce0ade4c4a..abbae919f82 100644 --- a/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts +++ b/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts @@ -34,6 +34,7 @@ export async function bruteForceNoteInfo( simulator: AcirSimulator, uniqueNoteHashes: Fr[], txHash: TxHash, + firstNullifier: Fr, contractAddress: AztecAddress, storageSlot: Fr, noteTypeId: NoteSelector, @@ -46,7 +47,6 @@ export async function bruteForceNoteInfo( let noteHash: Fr | undefined; let uniqueNoteHash: Fr | undefined; let innerNullifier: Fr | undefined; - const firstNullifier = Fr.fromBuffer(txHash.toBuffer()); for (; noteHashIndex < uniqueNoteHashes.length; ++noteHashIndex) { if (excludedIndices.has(noteHashIndex)) { diff --git a/yarn-project/pxe/src/note_decryption_utils/produce_note_daos.ts b/yarn-project/pxe/src/note_decryption_utils/produce_note_daos.ts index 7e1f94abe03..242b34b39ff 100644 --- a/yarn-project/pxe/src/note_decryption_utils/produce_note_daos.ts +++ b/yarn-project/pxe/src/note_decryption_utils/produce_note_daos.ts @@ -31,6 +31,7 @@ export async function produceNoteDaos( addressPoint: PublicKey | undefined, payload: L1NotePayload, txHash: TxHash, + firstNullifier: Fr, l2BlockNumber: number, l2BlockHash: string, noteHashes: Fr[], @@ -51,6 +52,7 @@ export async function produceNoteDaos( addressPoint, payload, txHash, + firstNullifier, l2BlockNumber, l2BlockHash, noteHashes, diff --git a/yarn-project/pxe/src/note_decryption_utils/produce_note_daos_for_key.ts b/yarn-project/pxe/src/note_decryption_utils/produce_note_daos_for_key.ts index 291d9efd80d..ef78cf7a76b 100644 --- a/yarn-project/pxe/src/note_decryption_utils/produce_note_daos_for_key.ts +++ b/yarn-project/pxe/src/note_decryption_utils/produce_note_daos_for_key.ts @@ -13,6 +13,7 @@ export async function produceNoteDaosForKey( pkM: PublicKey, payload: L1NotePayload, txHash: TxHash, + firstNullifier: Fr, l2BlockNumber: number, l2BlockHash: string, noteHashes: Fr[], @@ -39,6 +40,7 @@ export async function produceNoteDaosForKey( simulator, noteHashes, txHash, + firstNullifier, payload.contractAddress, payload.storageSlot, payload.noteTypeId, diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index b57ea54df95..acf6e8868d1 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -529,8 +529,8 @@ export class PXEService implements PXE { } } - this.log.info(`Simulation completed for ${simulatedTx.tryGetTxHash()} in ${timer.ms()}ms`, { - txHash: simulatedTx.tryGetTxHash(), + this.log.info(`Simulation completed for ${simulatedTx.getTxHash()} in ${timer.ms()}ms`, { + txHash: simulatedTx.getTxHash(), ...txInfo, ...(profileResult ? { gateCounts: profileResult.gateCounts } : {}), ...(publicOutput diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 137b4137d95..192937779f7 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -603,6 +603,7 @@ export class SimulatorOracle implements DBOracle { notePayload ? recipient.toAddressPoint() : undefined, payload!, txEffect.data.txHash, + txEffect.data.nullifiers[0], txEffect.l2BlockNumber, txEffect.l2BlockHash, txEffect.data.noteHashes, diff --git a/yarn-project/simulator/src/public/public_processor.ts b/yarn-project/simulator/src/public/public_processor.ts index eb3f743d963..1160bc1e169 100644 --- a/yarn-project/simulator/src/public/public_processor.ts +++ b/yarn-project/simulator/src/public/public_processor.ts @@ -290,7 +290,7 @@ export class PublicProcessor implements Traceable { return [result, failed, returns]; } - @trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.tryGetTxHash()?.toString() })) + @trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.getTxHash()?.toString() })) private async processTx(tx: Tx, deadline?: Date): Promise<[ProcessedTx, NestedProcessReturnValues[]]> { const [time, [processedTx, returnValues]] = await elapsed(() => this.processTxWithinDeadline(tx, deadline)); From 6a7427c0b97173f1d973a27bbf8bf21f4f299a6c Mon Sep 17 00:00:00 2001 From: sirasistant Date: Wed, 8 Jan 2025 17:33:53 +0000 Subject: [PATCH 18/29] fix note processing unit test --- yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts index e4e95f0ada5..11e9a6aaaf4 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -490,7 +490,7 @@ describe('Simulator oracle', () => { }); function mockTaggedLogs(requests: MockNoteRequest[], nullifiers: number = 0) { - const txEffectsMap: { [k: string]: { noteHashes: Fr[]; txHash: TxHash } } = {}; + const txEffectsMap: { [k: string]: { noteHashes: Fr[]; txHash: TxHash; nullifiers: Fr[] } } = {}; const taggedLogs: TxScopedL2Log[] = []; const groupedByTx = requests.reduce<{ [i: number]: { [j: number]: MockNoteRequest[] } }>((acc, request) => { if (!acc[request.blockNumber]) { @@ -513,6 +513,7 @@ describe('Simulator oracle', () => { if (!txEffectsMap[txHash.toString()]) { txEffectsMap[txHash.toString()] = { txHash, + nullifiers: [new Fr(txHash.hash.toBigInt() + 27n)], noteHashes: Array(maxNoteIndex + 1) .fill(0) .map(() => Fr.random()), From d21015e03e52c8c06ca9ae568d506a6f97d16da0 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Thu, 9 Jan 2025 09:09:46 +0000 Subject: [PATCH 19/29] fix public nonce computation --- .../cpp/src/barretenberg/vm/avm/trace/trace.cpp | 7 ++++--- .../cpp/src/barretenberg/vm/avm/trace/trace.hpp | 2 +- .../note_decryption_utils/brute_force_note_info.ts | 1 + .../simulator/src/avm/avm_simulator.test.ts | 2 +- yarn-project/simulator/src/avm/fixtures/index.ts | 6 +++--- .../simulator/src/avm/journal/journal.test.ts | 2 +- yarn-project/simulator/src/avm/journal/journal.ts | 13 ++++++------- .../src/avm/opcodes/accrued_substate.test.ts | 2 +- .../simulator/src/public/public_tx_context.ts | 4 +++- 9 files changed, 21 insertions(+), 18 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp index cd7e26908bd..346ac3b059d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp @@ -288,7 +288,8 @@ void AvmTraceBuilder::insert_private_revertible_state(const std::vector& sil for (size_t i = 0; i < siloed_note_hashes.size(); i++) { size_t note_index_in_tx = i + get_inserted_note_hashes_count(); - FF nonce = AvmMerkleTreeTraceBuilder::unconstrained_compute_note_hash_nonce(get_tx_hash(), note_index_in_tx); + FF nonce = + AvmMerkleTreeTraceBuilder::unconstrained_compute_note_hash_nonce(get_first_nullifier(), note_index_in_tx); unique_note_hashes.push_back( AvmMerkleTreeTraceBuilder::unconstrained_compute_unique_note_hash(nonce, siloed_note_hashes.at(i))); } @@ -3101,8 +3102,8 @@ AvmError AvmTraceBuilder::op_emit_note_hash(uint8_t indirect, uint32_t note_hash AppendTreeHint note_hash_write_hint = execution_hints.note_hash_write_hints.at(note_hash_write_counter++); FF siloed_note_hash = AvmMerkleTreeTraceBuilder::unconstrained_silo_note_hash( current_public_call_request.contract_address, row.main_ia); - FF nonce = - AvmMerkleTreeTraceBuilder::unconstrained_compute_note_hash_nonce(get_tx_hash(), inserted_note_hashes_count); + FF nonce = AvmMerkleTreeTraceBuilder::unconstrained_compute_note_hash_nonce(get_first_nullifier(), + inserted_note_hashes_count); FF unique_note_hash = AvmMerkleTreeTraceBuilder::unconstrained_compute_unique_note_hash(nonce, siloed_note_hash); ASSERT(unique_note_hash == note_hash_write_hint.leaf_value); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp index 0ae4e06d904..a2c750d633e 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp @@ -395,7 +395,7 @@ class AvmTraceBuilder { uint32_t get_inserted_note_hashes_count(); uint32_t get_inserted_nullifiers_count(); uint32_t get_public_data_writes_count(); - FF get_tx_hash() const { return public_inputs.previous_non_revertible_accumulated_data.nullifiers[0]; } + FF get_first_nullifier() const { return public_inputs.previous_non_revertible_accumulated_data.nullifiers[0]; } // TODO: remove these once everything is constrained. AvmMemoryTag unconstrained_get_memory_tag(AddressWithMode addr); diff --git a/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts b/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts index abbae919f82..42756d0cd9d 100644 --- a/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts +++ b/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts @@ -47,6 +47,7 @@ export async function bruteForceNoteInfo( let noteHash: Fr | undefined; let uniqueNoteHash: Fr | undefined; let innerNullifier: Fr | undefined; + console.log({ firstNullifier, txHash }); for (; noteHashIndex < uniqueNoteHashes.length; ++noteHashIndex) { if (excludedIndices.has(noteHashIndex)) { diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index 7ee18457dbf..d6fff38670f 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -642,7 +642,7 @@ describe('AVM simulator: transpiled Noir contracts', () => { expect(trace.traceNewNoteHash).toHaveBeenCalledTimes(1); const siloedNotehash = siloNoteHash(address, value0); - const nonce = computeNoteHashNonce(Fr.fromBuffer(context.persistableState.txHash.toBuffer()), 0); + const nonce = computeNoteHashNonce(context.persistableState.firstNullifier, 0); const uniqueNoteHash = computeUniqueNoteHash(nonce, siloedNotehash); expect(trace.traceNewNoteHash).toHaveBeenCalledWith(uniqueNoteHash); }); diff --git a/yarn-project/simulator/src/avm/fixtures/index.ts b/yarn-project/simulator/src/avm/fixtures/index.ts index 7990a0b2c3b..494a500f412 100644 --- a/yarn-project/simulator/src/avm/fixtures/index.ts +++ b/yarn-project/simulator/src/avm/fixtures/index.ts @@ -1,4 +1,4 @@ -import { TxHash, isNoirCallStackUnresolved } from '@aztec/circuit-types'; +import { isNoirCallStackUnresolved } from '@aztec/circuit-types'; import { GasFees, GlobalVariables, MAX_L2_GAS_PER_TX_PUBLIC_PORTION } from '@aztec/circuits.js'; import { type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; @@ -45,7 +45,7 @@ export function initPersistableStateManager(overrides?: { nullifiers?: NullifierManager; doMerkleOperations?: boolean; merkleTrees?: AvmEphemeralForest; - txHash?: TxHash; + firstNullifier?: Fr; }): AvmPersistableStateManager { const worldStateDB = overrides?.worldStateDB || mock(); return new AvmPersistableStateManager( @@ -55,7 +55,7 @@ export function initPersistableStateManager(overrides?: { overrides?.nullifiers || new NullifierManager(worldStateDB), overrides?.doMerkleOperations || false, overrides?.merkleTrees || mock(), - overrides?.txHash || new TxHash(new Fr(27)), + overrides?.firstNullifier || new Fr(27), ); } diff --git a/yarn-project/simulator/src/avm/journal/journal.test.ts b/yarn-project/simulator/src/avm/journal/journal.test.ts index 9aae7f88889..afd936960e4 100644 --- a/yarn-project/simulator/src/avm/journal/journal.test.ts +++ b/yarn-project/simulator/src/avm/journal/journal.test.ts @@ -85,7 +85,7 @@ describe('journal', () => { persistableState.writeNoteHash(address, utxo); expect(trace.traceNewNoteHash).toHaveBeenCalledTimes(1); const siloedNotehash = siloNoteHash(address, utxo); - const nonce = computeNoteHashNonce(Fr.fromBuffer(persistableState.txHash.toBuffer()), 1); + const nonce = computeNoteHashNonce(persistableState.firstNullifier, 1); const uniqueNoteHash = computeUniqueNoteHash(nonce, siloedNotehash); expect(trace.traceNewNoteHash).toHaveBeenCalledWith(uniqueNoteHash); }); diff --git a/yarn-project/simulator/src/avm/journal/journal.ts b/yarn-project/simulator/src/avm/journal/journal.ts index f962f2aa3b8..ff47f5d6561 100644 --- a/yarn-project/simulator/src/avm/journal/journal.ts +++ b/yarn-project/simulator/src/avm/journal/journal.ts @@ -1,4 +1,4 @@ -import { MerkleTreeId, type TxHash } from '@aztec/circuit-types'; +import { MerkleTreeId } from '@aztec/circuit-types'; import { AztecAddress, CANONICAL_AUTH_REGISTRY_ADDRESS, @@ -61,7 +61,7 @@ export class AvmPersistableStateManager { private readonly doMerkleOperations: boolean = false, /** Ephmeral forest for merkle tree operations */ public merkleTrees: AvmEphemeralForest, - public readonly txHash: TxHash, + public readonly firstNullifier: Fr, ) {} /** @@ -71,7 +71,7 @@ export class AvmPersistableStateManager { worldStateDB: WorldStateDB, trace: PublicSideEffectTraceInterface, doMerkleOperations: boolean = false, - txHash: TxHash, + firstNullifier: Fr, ) { const ephemeralForest = await AvmEphemeralForest.create(worldStateDB.getMerkleInterface()); return new AvmPersistableStateManager( @@ -81,7 +81,7 @@ export class AvmPersistableStateManager { /*nullifiers=*/ new NullifierManager(worldStateDB), /*doMerkleOperations=*/ doMerkleOperations, ephemeralForest, - txHash, + firstNullifier, ); } @@ -96,7 +96,7 @@ export class AvmPersistableStateManager { this.nullifiers.fork(), this.doMerkleOperations, this.merkleTrees.fork(), - this.txHash, + this.firstNullifier, ); } @@ -293,8 +293,7 @@ export class AvmPersistableStateManager { * @param noteHash - the non unique note hash to write */ public writeSiloedNoteHash(noteHash: Fr): void { - const txHash = Fr.fromBuffer(this.txHash.toBuffer()); - const nonce = computeNoteHashNonce(txHash, this.trace.getNoteHashCount()); + const nonce = computeNoteHashNonce(this.firstNullifier, this.trace.getNoteHashCount()); const uniqueNoteHash = computeUniqueNoteHash(nonce, noteHash); this.writeUniqueNoteHash(uniqueNoteHash); diff --git a/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts b/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts index af4fd095786..2fd3d84edba 100644 --- a/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts @@ -125,7 +125,7 @@ describe('Accrued Substate', () => { await new EmitNoteHash(/*indirect=*/ 0, /*offset=*/ value0Offset).execute(context); expect(trace.traceNewNoteHash).toHaveBeenCalledTimes(1); const siloedNotehash = siloNoteHash(address, value0); - const nonce = computeNoteHashNonce(Fr.fromBuffer(context.persistableState.txHash.toBuffer()), 0); + const nonce = computeNoteHashNonce(persistableState.firstNullifier, 0); const uniqueNoteHash = computeUniqueNoteHash(nonce, siloedNotehash); expect(trace.traceNewNoteHash).toHaveBeenCalledWith(uniqueNoteHash); }); diff --git a/yarn-project/simulator/src/public/public_tx_context.ts b/yarn-project/simulator/src/public/public_tx_context.ts index 9cbc53cca2b..194838dd018 100644 --- a/yarn-project/simulator/src/public/public_tx_context.ts +++ b/yarn-project/simulator/src/public/public_tx_context.ts @@ -104,12 +104,14 @@ export class PublicTxContext { previousAccumulatedDataArrayLengths, ); + const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0]; + // Transaction level state manager that will be forked for revertible phases. const txStateManager = await AvmPersistableStateManager.create( worldStateDB, enqueuedCallTrace, doMerkleOperations, - tx.getTxHash(), + firstNullifier, ); const gasSettings = tx.data.constants.txContext.gasSettings; From d145dcb94fa50124a1af1f46fea6bc374c42a2d8 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Thu, 9 Jan 2025 09:26:33 +0000 Subject: [PATCH 20/29] remove console log --- .../pxe/src/note_decryption_utils/brute_force_note_info.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts b/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts index 42756d0cd9d..abbae919f82 100644 --- a/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts +++ b/yarn-project/pxe/src/note_decryption_utils/brute_force_note_info.ts @@ -47,7 +47,6 @@ export async function bruteForceNoteInfo( let noteHash: Fr | undefined; let uniqueNoteHash: Fr | undefined; let innerNullifier: Fr | undefined; - console.log({ firstNullifier, txHash }); for (; noteHashIndex < uniqueNoteHashes.length; ++noteHashIndex) { if (excludedIndices.has(noteHashIndex)) { From 8d79883dea1abf014f1f2250964555404dacce8c Mon Sep 17 00:00:00 2001 From: sirasistant Date: Thu, 9 Jan 2025 13:35:57 +0000 Subject: [PATCH 21/29] fix --- .../kernel/private_to_rollup_kernel_circuit_public_inputs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_kernel_circuit_public_inputs.ts index c3d218f99f9..f822a51ac7e 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_kernel_circuit_public_inputs.ts @@ -45,7 +45,7 @@ export class PrivateToRollupKernelCircuitPublicInputs { } toBuffer() { - return serializeToBuffer(this.rollupValidationRequests, this.end, this.constants, this.gasUsed, this.feePayer); + return serializeToBuffer(this.constants, this.rollupValidationRequests, this.end, this.gasUsed, this.feePayer); } /** From 3254f232dc889a4c49a0a2a7c072ebc272548c9a Mon Sep 17 00:00:00 2001 From: sirasistant Date: Thu, 9 Jan 2025 14:28:13 +0000 Subject: [PATCH 22/29] fix --- .../noir-protocol-circuits/crates/rollup-lib/src/components.nr | 1 + yarn-project/circuit-types/src/tx_effect.ts | 1 + .../kernel/private_to_public_kernel_circuit_public_inputs.ts | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) 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 6ce371efcf9..d618e81a6f9 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 @@ -245,6 +245,7 @@ pub fn encode_blob_prefix(input_type: u8, array_len: u32) -> Field { // Tx effects consist of // 1 field for revert code +// 1 field for tx hash // 1 field for transaction fee // MAX_NOTE_HASHES_PER_TX fields for note hashes // MAX_NULLIFIERS_PER_TX fields for nullifiers diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index 3dd3e27b4ab..a5995915736 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -546,6 +546,7 @@ export class TxEffect { [inspect.custom]() { return `TxEffect { revertCode: ${this.revertCode}, + txHash: ${this.txHash}, transactionFee: ${this.transactionFee}, note hashes: [${this.noteHashes.map(h => h.toString()).join(', ')}], nullifiers: [${this.nullifiers.map(h => h.toString()).join(', ')}], diff --git a/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts index 1ab9f06abde..0c5a5247e5d 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_public_kernel_circuit_public_inputs.ts @@ -91,6 +91,6 @@ export class PrivateToPublicKernelCircuitPublicInputs { } hash() { - return poseidon2HashWithSeparator(this.toFields(), GeneratorIndex.PRIVATE_TX_HASH); + return poseidon2HashWithSeparator(this.toFields(), GeneratorIndex.PUBLIC_TX_HASH); } } From a835bf60fd014902930e73f99a5cd3cbe75b237d Mon Sep 17 00:00:00 2001 From: sirasistant Date: Thu, 9 Jan 2025 16:58:26 +0000 Subject: [PATCH 23/29] added profiling --- yarn-project/p2p/src/services/libp2p/libp2p_service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yarn-project/p2p/src/services/libp2p/libp2p_service.ts b/yarn-project/p2p/src/services/libp2p/libp2p_service.ts index 5b47bc91ca3..b86f2032368 100644 --- a/yarn-project/p2p/src/services/libp2p/libp2p_service.ts +++ b/yarn-project/p2p/src/services/libp2p/libp2p_service.ts @@ -589,7 +589,9 @@ export class LibP2PService extends WithTracer implement msg: Message, ): Promise { const tx = Tx.fromBuffer(Buffer.from(msg.data)); + const startTime = Date.now(); const isValid = await this.validatePropagatedTx(tx, propagationSource); + this.logger.info(`validatePropagatedTx: Took ${Date.now() - startTime}ms is public? ${!!tx.data.forPublic}`); this.logger.trace(`validatePropagatedTx: ${isValid}`, { [Attributes.TX_HASH]: tx.getTxHash().toString(), [Attributes.P2P_ID]: propagationSource.toString(), From cb68fabe7cfb2806022df95a64396b31c9d54492 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Thu, 9 Jan 2025 17:04:00 +0000 Subject: [PATCH 24/29] fix logs --- yarn-project/circuit-types/src/tx/tx.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/yarn-project/circuit-types/src/tx/tx.ts b/yarn-project/circuit-types/src/tx/tx.ts index 2c2f5319273..bab92c3b540 100644 --- a/yarn-project/circuit-types/src/tx/tx.ts +++ b/yarn-project/circuit-types/src/tx/tx.ts @@ -8,6 +8,7 @@ import { } from '@aztec/circuits.js'; import { Buffer32 } from '@aztec/foundation/buffer'; import { arraySerializedSizeOfNonEmpty } from '@aztec/foundation/collection'; +import { createLogger } from '@aztec/foundation/log'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { type FieldsOf } from '@aztec/foundation/types'; @@ -176,9 +177,12 @@ export class Tx extends Gossipable { */ getTxHash(forceRecompute = false): TxHash { if (!this.txHash || forceRecompute) { + const logger = createLogger(`Tx`); + const startTime = Date.now(); const hash = this.data.forPublic ? this.data.toPrivateToPublicKernelCircuitPublicInputs().hash() : this.data.toPrivateToRollupKernelCircuitPublicInputs().hash(); + logger.debug(`Tx hash computed in ${Date.now() - startTime}ms, isPublic? ${!!this.data.forPublic}`); this.txHash = new TxHash(hash); } return this.txHash!; From df53d4ff9cb53f87829bbb52c2bbecd1eccfe4c2 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Thu, 9 Jan 2025 17:35:38 +0000 Subject: [PATCH 25/29] fix log level --- yarn-project/circuit-types/src/tx/tx.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/circuit-types/src/tx/tx.ts b/yarn-project/circuit-types/src/tx/tx.ts index bab92c3b540..4e161e1c857 100644 --- a/yarn-project/circuit-types/src/tx/tx.ts +++ b/yarn-project/circuit-types/src/tx/tx.ts @@ -182,7 +182,7 @@ export class Tx extends Gossipable { const hash = this.data.forPublic ? this.data.toPrivateToPublicKernelCircuitPublicInputs().hash() : this.data.toPrivateToRollupKernelCircuitPublicInputs().hash(); - logger.debug(`Tx hash computed in ${Date.now() - startTime}ms, isPublic? ${!!this.data.forPublic}`); + logger.info(`Tx hash computed in ${Date.now() - startTime}ms, isPublic? ${!!this.data.forPublic}`); this.txHash = new TxHash(hash); } return this.txHash!; From 67de841d9b72dc2ce6d6dd9969b1b0967f6ebbc5 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Fri, 10 Jan 2025 09:25:58 +0000 Subject: [PATCH 26/29] remove profiling logs --- yarn-project/circuit-types/src/tx/tx.ts | 6 +----- yarn-project/p2p/src/services/libp2p/libp2p_service.ts | 2 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/yarn-project/circuit-types/src/tx/tx.ts b/yarn-project/circuit-types/src/tx/tx.ts index 4e161e1c857..1dbd2cdc927 100644 --- a/yarn-project/circuit-types/src/tx/tx.ts +++ b/yarn-project/circuit-types/src/tx/tx.ts @@ -8,7 +8,6 @@ import { } from '@aztec/circuits.js'; import { Buffer32 } from '@aztec/foundation/buffer'; import { arraySerializedSizeOfNonEmpty } from '@aztec/foundation/collection'; -import { createLogger } from '@aztec/foundation/log'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { type FieldsOf } from '@aztec/foundation/types'; @@ -173,16 +172,13 @@ export class Tx extends Gossipable { /** * Computes (if necessary) & return transaction hash. - * @returns The transaction's hash. + * @returns The hash of the public inputs of the private kernel tail circuit. */ getTxHash(forceRecompute = false): TxHash { if (!this.txHash || forceRecompute) { - const logger = createLogger(`Tx`); - const startTime = Date.now(); const hash = this.data.forPublic ? this.data.toPrivateToPublicKernelCircuitPublicInputs().hash() : this.data.toPrivateToRollupKernelCircuitPublicInputs().hash(); - logger.info(`Tx hash computed in ${Date.now() - startTime}ms, isPublic? ${!!this.data.forPublic}`); this.txHash = new TxHash(hash); } return this.txHash!; diff --git a/yarn-project/p2p/src/services/libp2p/libp2p_service.ts b/yarn-project/p2p/src/services/libp2p/libp2p_service.ts index b86f2032368..5b47bc91ca3 100644 --- a/yarn-project/p2p/src/services/libp2p/libp2p_service.ts +++ b/yarn-project/p2p/src/services/libp2p/libp2p_service.ts @@ -589,9 +589,7 @@ export class LibP2PService extends WithTracer implement msg: Message, ): Promise { const tx = Tx.fromBuffer(Buffer.from(msg.data)); - const startTime = Date.now(); const isValid = await this.validatePropagatedTx(tx, propagationSource); - this.logger.info(`validatePropagatedTx: Took ${Date.now() - startTime}ms is public? ${!!tx.data.forPublic}`); this.logger.trace(`validatePropagatedTx: ${isValid}`, { [Attributes.TX_HASH]: tx.getTxHash().toString(), [Attributes.P2P_ID]: propagationSource.toString(), From 9b51829449aa5f39bf616a00ca282b24798fd631 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Fri, 10 Jan 2025 09:30:49 +0000 Subject: [PATCH 27/29] remvoe optional --- yarn-project/simulator/src/public/public_processor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/simulator/src/public/public_processor.ts b/yarn-project/simulator/src/public/public_processor.ts index 1160bc1e169..b67d187cdaa 100644 --- a/yarn-project/simulator/src/public/public_processor.ts +++ b/yarn-project/simulator/src/public/public_processor.ts @@ -290,7 +290,7 @@ export class PublicProcessor implements Traceable { return [result, failed, returns]; } - @trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.getTxHash()?.toString() })) + @trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.getTxHash().toString() })) private async processTx(tx: Tx, deadline?: Date): Promise<[ProcessedTx, NestedProcessReturnValues[]]> { const [time, [processedTx, returnValues]] = await elapsed(() => this.processTxWithinDeadline(tx, deadline)); From 3cb2efa7dfa68ae09fa4bb14085407f6b124cfd0 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Fri, 10 Jan 2025 10:14:06 +0000 Subject: [PATCH 28/29] fix docs --- .../contracts/easy_private_voting_contract/src/main.nr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr b/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr index c7f51654c76..d293a2c0171 100644 --- a/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr @@ -1,8 +1,10 @@ +// docs:start:declaration mod test; use dep::aztec::macros::aztec; #[aztec] contract EasyPrivateVoting { + // docs:end:declaration // docs:start:imports use dep::aztec::{ keys::getters::get_public_keys, From 7be5e5050bfea07ab81d796d632a0e9aee4658dc Mon Sep 17 00:00:00 2001 From: sirasistant Date: Fri, 10 Jan 2025 11:08:57 +0000 Subject: [PATCH 29/29] fix test of blob building --- .../block_root/block_root_rollup_inputs.nr | 14 +++++++------ .../block_building_helpers.test.ts | 20 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr index ebc342151a8..45bf221e1ef 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr @@ -202,13 +202,15 @@ pub(crate) mod tests { // The below values are generated from block_building_helper.test.ts. let blob_fields_0 = [ - 0x000000000000000000000000000000000074785f737461727400000400010000, + 0x000000000000000000000000000000000074785f737461727400000500010000, + 0x000000000000000000000000000000000000000000000000000000000000002a, 0x0002000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000004000001, 0x0000000000000000000000000000000000000000000000000000000000000123, ]; let blob_fields_1 = [ - 0x000000000000000000000000000000000074785f737461727400000600010000, + 0x000000000000000000000000000000000074785f737461727400000700010000, + 0x000000000000000000000000000000000000000000000000000000000000002b, 0x0002000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000003000001, 0x0000000000000000000000000000000000000000000000000000000000006789, @@ -216,12 +218,12 @@ pub(crate) mod tests { 0x0000000000000000000000000000000000000000000000000000000000000045, ]; let expected_blob_commitment = [ - 0x00ad8be66e7276942652627bb00fe1e65dc1c3c6701ab27cc05eff662950071d, - 0x00000000000000000000000000000071baf7a9af9757f1d3878b37b438797213, + 0x008c32fe581c8fdba12c0d7597911dead2d937d68525bae655508412bb53bb98, + 0x0000000000000000000000000000006aaa0680f21270e7d8de4e19da5164f95c, ]; let expected_blobs_hash = - 0x00dc577f5c94c82b847693b76ee69cd33d4e5eee3adb6f37d8d7ab662c84725d; - let expected_z = 0x1582b354f32263abde313d597582ebceafe17d4e2a68dd47533383e85b4cb780; + 0x00a965619c8668b834755678b32d023b9c5e8588ce449f44f7fa9335455b5cc5; + let expected_z = 0x1f92b871671f27a378d23f1cef10fbd8f0d90dd7172da9e3c3fc1aa745a072c3; let mut builder = TestBuilder::new_with_blobs_fields(blob_fields_0, blob_fields_1); builder.data.blob_commitments[0].inner = expected_blob_commitment; diff --git a/yarn-project/prover-client/src/orchestrator/block_building_helpers.test.ts b/yarn-project/prover-client/src/orchestrator/block_building_helpers.test.ts index 20043b613ca..97f67d24ce0 100644 --- a/yarn-project/prover-client/src/orchestrator/block_building_helpers.test.ts +++ b/yarn-project/prover-client/src/orchestrator/block_building_helpers.test.ts @@ -1,4 +1,4 @@ -import { TxEffect } from '@aztec/circuit-types'; +import { TxEffect, TxHash } from '@aztec/circuit-types'; import { Fr } from '@aztec/circuits.js'; import { BlobPublicInputs } from '@aztec/circuits.js/blobs'; import { updateInlineTestData } from '@aztec/foundation/testing/files'; @@ -49,29 +49,33 @@ describe('buildBlobHints', () => { it('correctly builds hints for non-empty blob fields', () => { const txEffect0 = TxEffect.empty(); + txEffect0.txHash = new TxHash(new Fr(42)); txEffect0.nullifiers[0] = new Fr(0x123); const txEffect1 = TxEffect.empty(); + txEffect1.txHash = new TxHash(new Fr(43)); txEffect1.noteHashes[0] = new Fr(0x6789); txEffect1.nullifiers[0] = new Fr(0x45); const { blobFields, blobCommitments, blobsHash, blobs } = buildBlobHints([txEffect0, txEffect1]); - const blobFields0Str = fieldArrToStr(blobFields.slice(0, 4)); - const blobFields1Str = fieldArrToStr(blobFields.slice(4)); - expect(blobFields.length).toBe(4 + 6); + const blobFields0Str = fieldArrToStr(blobFields.slice(0, 5)); + const blobFields1Str = fieldArrToStr(blobFields.slice(5)); + expect(blobFields.length).toBe(5 + 7); expect(blobCommitments.length).toBe(1); const blobCommitmentStr = fieldArrToStr(blobCommitments[0]); expect(blobCommitmentStr).toMatchInlineSnapshot( - `"[0x00ad8be66e7276942652627bb00fe1e65dc1c3c6701ab27cc05eff662950071d, 0x00000000000000000000000000000071baf7a9af9757f1d3878b37b438797213]"`, + `"[0x008c32fe581c8fdba12c0d7597911dead2d937d68525bae655508412bb53bb98, 0x0000000000000000000000000000006aaa0680f21270e7d8de4e19da5164f95c]"`, ); const blobsHashStr = blobsHash.toString(); - expect(blobsHashStr).toMatchInlineSnapshot(`"0x00dc577f5c94c82b847693b76ee69cd33d4e5eee3adb6f37d8d7ab662c84725d"`); + expect(blobsHashStr).toMatchInlineSnapshot(`"0x00a965619c8668b834755678b32d023b9c5e8588ce449f44f7fa9335455b5cc5"`); const publicInputs = BlobPublicInputs.fromBlob(blobs[0]); - expect(publicInputs.y).toBe(11463660905914812112228400842008710735611240877901286242511876802170210355245n); + expect(publicInputs.y).toMatchInlineSnapshot( + `17179655213294173540446545222866729565951946174336496855332549059993428157821n`, + ); const zStr = publicInputs.z.toString(); - expect(zStr).toMatchInlineSnapshot(`"0x1582b354f32263abde313d597582ebceafe17d4e2a68dd47533383e85b4cb780"`); + expect(zStr).toMatchInlineSnapshot(`"0x1f92b871671f27a378d23f1cef10fbd8f0d90dd7172da9e3c3fc1aa745a072c3"`); // Run with AZTEC_GENERATE_TEST_DATA=1 to update noir test data. updateInlineTestData(