diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 8d2325e2b20..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 COMBINED_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 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/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 7e8d5b28ac9..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 @@ -3,10 +3,10 @@ mod meter_gas_used; use crate::components::private_kernel_circuit_public_inputs_composer::PrivateKernelCircuitPublicInputsComposer; use dep::types::{ abis::{ - accumulated_data::combined_accumulated_data::CombinedAccumulatedData, - combined_constant_data::CombinedConstantData, - global_variables::GlobalVariables, - kernel_circuit_public_inputs::{KernelCircuitPublicInputs, PrivateKernelCircuitPublicInputs}, + accumulated_data::private_to_rollup_accumulated_data::PrivateToRollupAccumulatedData, + kernel_circuit_public_inputs::{ + PrivateKernelCircuitPublicInputs, PrivateToRollupKernelCircuitPublicInputs, + }, log_hash::ScopedLogHash, note_hash::ScopedNoteHash, nullifier::ScopedNullifier, @@ -30,21 +30,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 = - CombinedConstantData::combine(source.constants, GlobalVariables::empty()); + 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 b8e22650ef4..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,26 +3,27 @@ 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, }, 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}; 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) }; @@ -30,7 +31,7 @@ impl TailOutputValidator { } pub fn new_with_hints( - output: KernelCircuitPublicInputs, + output: PrivateToRollupKernelCircuitPublicInputs, previous_kernel: PrivateKernelCircuitPublicInputs, hints: TailOutputHints, ) -> Self { @@ -38,21 +39,11 @@ 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, @@ -74,7 +65,6 @@ impl TailOutputValidator { 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.rollup_validation_requests, 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 8ca0bd0d934..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,14 +59,13 @@ 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}, 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, @@ -89,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(), }; @@ -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/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 e147656197e..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 @@ -1,4 +1,3 @@ -mod validate_empty_values; mod validate_gas_used; mod validate_propagated_sorted_values; mod validate_propagated_values; @@ -13,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, @@ -49,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 } @@ -60,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-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/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/abis/mod.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/mod.nr index 0bcaaa80b27..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,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; 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..54fcf722f76 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/tx_effect.nr @@ -0,0 +1,43 @@ +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, + 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], + } + } +} 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..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,12 +1,12 @@ use types::abis::{ combined_constant_data::CombinedConstantData, constant_rollup_data::ConstantRollupData, + tx_constant_data::TxConstantData, }; 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 +24,30 @@ 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..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 @@ -1,8 +1,11 @@ use crate::{ - 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, + 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, @@ -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::{ append_only_tree_snapshot::AppendOnlyTreeSnapshot, constant_rollup_data::ConstantRollupData, - nullifier_leaf_preimage::NullifierLeafPreimage, public_data_write::PublicDataWrite, - sponge_blob::SpongeBlob, tube::PrivateTubeData, + 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, + 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, @@ -29,7 +33,6 @@ use dep::types::{ }, messaging::l2_to_l1_message::ScopedL2ToL1Message, partial_state_reference::PartialStateReference, - traits::is_empty, }; global ALLOWED_PREVIOUS_CIRCUITS: [u32; 1] = [TUBE_VK_INDEX]; @@ -59,9 +62,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,15 +114,26 @@ 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, - self.start_sponge_blob, - ); + 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); // Perform membership checks that the notes provided exist within the historical trees data perform_archive_membership_check( @@ -170,24 +182,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; @@ -235,12 +229,12 @@ 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, 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, }, @@ -396,10 +390,8 @@ mod tests { gas_used.compute_fee(gas_fees) } - fn build_pre_existing_tx_effects( - self, - ) -> (CombinedAccumulatedData, [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]) { - let mut res = CombinedAccumulatedData::empty(); + 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| { nullifier.nullifier @@ -409,7 +401,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 +409,7 @@ mod tests { ], ); - (res, padded_all_public_data_update_requests) + res } fn extract_subtree_sibling_path( @@ -434,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 = @@ -583,15 +575,10 @@ mod tests { public_data_tree: start_public_data_tree_snapshot, }; - let (pre_existing_tx_effects, pre_existing_public_data_update_requests) = - 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, - 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,16 @@ 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 +1032,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..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 @@ -1,5 +1,8 @@ use crate::{ - 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, @@ -12,16 +15,10 @@ use crate::{ }; use dep::types::{ abis::{ - accumulated_data::{self, CombinedAccumulatedData}, - 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, @@ -50,9 +47,21 @@ 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 +86,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, - contract_class_logs_hashes, unencrypted_log_preimages_length, contract_class_log_preimages_length, - public_data_writes: from_public.accumulated_data.public_data_writes, + contract_class_logs_hashes, } } @@ -108,8 +119,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 +139,9 @@ impl PublicBaseRollupInputs { ); } - let commitments_tree_subroot = - calculate_subtree_root(combined_accumulated_data.note_hashes); + let tx_effect = self.generate_tx_effect(reverted, combined_constant_data); + + let commitments_tree_subroot = calculate_subtree_root(tx_effect.note_hashes); let empty_commitments_subtree_root = calculate_empty_tree_root(NOTE_HASH_SUBTREE_HEIGHT); @@ -145,31 +155,16 @@ 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, - 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( @@ -217,11 +212,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, @@ -286,9 +281,10 @@ 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, + accumulated_data::PrivateToRollupAccumulatedData, append_only_tree_snapshot::AppendOnlyTreeSnapshot, constant_rollup_data::ConstantRollupData, nullifier_leaf_preimage::NullifierLeafPreimage, public_data_write::PublicDataWrite, @@ -423,6 +419,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 +433,8 @@ mod tests { builder } - fn build_pre_existing_tx_effects( - self, - ) -> (CombinedAccumulatedData, [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]) { - let mut res = CombinedAccumulatedData::empty(); + 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| { nullifier.nullifier @@ -449,7 +444,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 +452,7 @@ mod tests { ], ); - (res, padded_all_public_data_update_requests) + res } fn extract_subtree_sibling_path( @@ -673,15 +668,10 @@ mod tests { public_data_tree: start_public_data_tree_snapshot, }; - let (pre_existing_tx_effects, pre_existing_public_data_update_requests) = - self.build_pre_existing_tx_effects(); + 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 +1173,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 +1182,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 +1191,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 5a6a911c4ab..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 @@ -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::{ - accumulated_data::CombinedAccumulatedData, 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, @@ -267,21 +265,12 @@ 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, offset) = get_tx_effects_hash_input( - combined, - revert_code, - transaction_fee, - all_public_data_update_requests, - l2_to_l1_msgs, - ); + 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. @@ -297,33 +286,21 @@ pub 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, - ) - }; - - let note_hashes = combined.note_hashes; - let nullifiers = combined.nullifiers; + 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; // 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) }); @@ -341,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], transaction_fee.to_be_bytes::<29>()), + array_concat( + [TX_FEE_PREFIX, 0], + tx_effect.transaction_fee.to_be_bytes::<29>(), + ), true, ), ); @@ -381,7 +361,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); @@ -389,7 +369,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; @@ -479,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, revert_code], + [ + 0, + length_bytes[0], + length_bytes[1], + 0, + REVERT_CODE_PREFIX, + 0, + tx_effect.revert_code, + ], ), true, ), @@ -489,25 +477,21 @@ 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]; - 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) }); @@ -524,7 +508,10 @@ unconstrained fn get_tx_effects_hash_input_helper( // 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; @@ -559,14 +546,14 @@ unconstrained fn get_tx_effects_hash_input_helper( } // 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; } @@ -639,7 +626,7 @@ unconstrained fn get_tx_effects_hash_input_helper( 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, ); @@ -647,6 +634,7 @@ unconstrained fn get_tx_effects_hash_input_helper( tx_effects_hash_input } +// 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/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 53% 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 83921f18c3b..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,53 +1,44 @@ 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, + 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], 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 { +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], 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 - ], } } } -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); @@ -57,30 +48,24 @@ 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); + 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( @@ -91,47 +76,35 @@ 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 } } -impl Eq for CombinedAccumulatedData { +impl Eq for PrivateToRollupAccumulatedData { fn eq(self, other: Self) -> bool { (self.note_hashes == other.note_hashes) & (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) } } #[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/kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr deleted file mode 100644 index 115beab20f9..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr +++ /dev/null @@ -1,94 +0,0 @@ -use crate::{ - abis::{ - accumulated_data::CombinedAccumulatedData, combined_constant_data::CombinedConstantData, - 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 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, -} - -impl Empty for KernelCircuitPublicInputs { - fn empty() -> Self { - KernelCircuitPublicInputs { - rollup_validation_requests: RollupValidationRequests::empty(), - end: CombinedAccumulatedData::empty(), - constants: CombinedConstantData::empty(), - start_state: PartialStateReference::empty(), - revert_code: 0, - gas_used: Gas::empty(), - fee_payer: AztecAddress::empty(), - } - } -} - -impl Eq for KernelCircuitPublicInputs { - fn eq(self, other: Self) -> bool { - (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)) - } -} - -impl Serialize for KernelCircuitPublicInputs { - fn serialize(self) -> [Field; 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()); - 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()); - - assert_eq(fields.len(), KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); - - fields.storage() - } -} - -impl Deserialize for KernelCircuitPublicInputs { - fn deserialize( - fields: [Field; KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH], - ) -> KernelCircuitPublicInputs { - let mut reader = Reader::new(fields); - 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, - gas_used: reader.read_struct(Gas::deserialize), - fee_payer: reader.read_struct(AztecAddress::deserialize), - }; - - reader.finish(); - item - } -} - -#[test] -fn serialization_of_empty_kernel_circuit_public_inputs() { - let item = KernelCircuitPublicInputs::empty(); - let serialized = item.serialize(); - let deserialized = KernelCircuitPublicInputs::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/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 new file mode 100644 index 00000000000..9f00f0320e5 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_to_rollup_kernel_circuit_public_inputs.nr @@ -0,0 +1,75 @@ +use crate::{ + abis::{ + accumulated_data::PrivateToRollupAccumulatedData, gas::Gas, + tx_constant_data::TxConstantData, validation_requests::RollupValidationRequests, + }, + address::AztecAddress, + constants::PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, + traits::{Deserialize, Empty, Serialize}, + utils::reader::Reader, +}; +use std::meta::derive; + +#[derive(Eq)] +pub struct PrivateToRollupKernelCircuitPublicInputs { + pub constants: TxConstantData, + pub rollup_validation_requests: RollupValidationRequests, + pub end: PrivateToRollupAccumulatedData, + pub gas_used: Gas, + pub fee_payer: AztecAddress, +} + +impl Empty for PrivateToRollupKernelCircuitPublicInputs { + fn empty() -> Self { + PrivateToRollupKernelCircuitPublicInputs { + rollup_validation_requests: RollupValidationRequests::empty(), + end: PrivateToRollupAccumulatedData::empty(), + constants: TxConstantData::empty(), + gas_used: Gas::empty(), + fee_payer: AztecAddress::empty(), + } + } +} + +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.constants.serialize()); + fields.extend_from_array(self.rollup_validation_requests.serialize()); + fields.extend_from_array(self.end.serialize()); + fields.extend_from_array(self.gas_used.serialize()); + fields.extend_from_array(self.fee_payer.serialize()); + + assert_eq(fields.len(), PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); + + fields.storage() + } +} + +impl Deserialize for PrivateToRollupKernelCircuitPublicInputs { + fn deserialize( + fields: [Field; PRIVATE_TO_ROLLUP_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH], + ) -> PrivateToRollupKernelCircuitPublicInputs { + let mut reader = Reader::new(fields); + let item = Self { + constants: reader.read_struct(TxConstantData::deserialize), + rollup_validation_requests: reader.read_struct(RollupValidationRequests::deserialize), + end: reader.read_struct(PrivateToRollupAccumulatedData::deserialize), + gas_used: reader.read_struct(Gas::deserialize), + fee_payer: reader.read_struct(AztecAddress::deserialize), + }; + + reader.finish(); + item + } +} + +#[test] +fn serialization_of_empty_kernel_circuit_public_inputs() { + let item = PrivateToRollupKernelCircuitPublicInputs::empty(); + let serialized = item.serialize(); + 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 8b9d45514a7..9be98412f5c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -334,15 +334,13 @@ 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) - + (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 */ @@ -390,11 +388,9 @@ 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 - + COMBINED_CONSTANT_DATA_LENGTH - + PARTIAL_STATE_REFERENCE_LENGTH - + 1 /* revert_code */ +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 404bd4cbc7e..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,23 +437,18 @@ 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| { 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(), } } @@ -527,17 +523,17 @@ 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 constants = self.to_constant_data(); + let end = self.to_private_to_rollup_accumulated_data(); + let constants = self.to_tx_constant_data(); - KernelCircuitPublicInputs { + PrivateToRollupKernelCircuitPublicInputs { 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, } @@ -545,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/circuit-types/src/test/factories.ts b/yarn-project/circuit-types/src/test/factories.ts index 487bd5a8636..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,10 +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); - - // Private-only tx has no public data writes. - data.publicDataWrites.forEach((_, i) => (data.publicDataWrites[i] = PublicDataWrite.empty())); + const data = makePrivateToRollupAccumulatedData(seed + 0x1000); const transactionFee = tx.data.gasUsed.computeFee(globalVariables.gasFees); diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index b9c4c465333..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(), @@ -140,7 +141,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/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 80b30fd6343..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 COMBINED_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 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; 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/combined_accumulated_data.test.ts b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.test.ts deleted file mode 100644 index 64cbcb0cd1d..00000000000 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.test.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { makeCombinedAccumulatedData } from '../../tests/factories.js'; -import { CombinedAccumulatedData } from './combined_accumulated_data.js'; - -describe('CombinedAccumulatedData', () => { - it('Data after serialization and deserialization is equal to the original', () => { - const original = makeCombinedAccumulatedData(); - const afterSerialization = CombinedAccumulatedData.fromBuffer(original.toBuffer()); - expect(original).toEqual(afterSerialization); - }); -}); 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..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 @@ -4,17 +4,15 @@ 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 { 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. @@ -23,16 +21,11 @@ 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. */ - public constants: CombinedConstantData, - public startState: PartialStateReference, - /** - * Flag indicating whether the transaction reverted. - */ - public revertCode: RevertCode, + public constants: TxConstantData, /** * Gas used during this transaction */ @@ -48,42 +41,30 @@ 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); } /** * 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(CombinedConstantData), - reader.readObject(PartialStateReference), - reader.readObject(RevertCode), + reader.readObject(PrivateToRollupAccumulatedData), + reader.readObject(TxConstantData), reader.readObject(Gas), reader.readObject(AztecAddress), ); } static empty() { - return new KernelCircuitPublicInputs( + return new PrivateToRollupKernelCircuitPublicInputs( RollupValidationRequests.empty(), - CombinedAccumulatedData.empty(), - CombinedConstantData.empty(), - PartialStateReference.empty(), - RevertCode.OK, + PrivateToRollupAccumulatedData.empty(), + TxConstantData.empty(), Gas.empty(), AztecAddress.ZERO, ); @@ -94,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. */ @@ -104,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 869427fa2ec..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,16 +5,12 @@ 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'; -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 { @@ -80,11 +76,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() { @@ -96,7 +92,7 @@ export class PartialPrivateTailPublicInputsForRollup { } static empty() { - return new PartialPrivateTailPublicInputsForRollup(CombinedAccumulatedData.empty()); + return new PartialPrivateTailPublicInputsForRollup(PrivateToRollupAccumulatedData.empty()); } } @@ -163,23 +159,20 @@ export class PrivateKernelTailCircuitPublicInputs { ); } - toKernelCircuitPublicInputs() { + toPrivateToRollupKernelCircuitPublicInputs() { 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 KernelCircuitPublicInputs( + return new PrivateToRollupKernelCircuitPublicInputs( this.rollupValidationRequests, this.forRollup.end, constants, - PartialStateReference.empty(), - RevertCode.OK, this.gasUsed, this.feePayer, ); @@ -292,7 +285,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/private_to_rollup_accumulated_data.test.ts b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.test.ts new file mode 100644 index 00000000000..4ede3c49065 --- /dev/null +++ b/yarn-project/circuits.js/src/structs/kernel/private_to_rollup_accumulated_data.test.ts @@ -0,0 +1,10 @@ +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 = makePrivateToRollupAccumulatedData(); + 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 64% 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 62e1abefdd2..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 @@ -13,18 +13,15 @@ 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. */ -export class CombinedAccumulatedData { +export class PrivateToRollupAccumulatedData { constructor( /** * The new note hashes made in this 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,34 +56,28 @@ 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 ); } - static getFields(fields: FieldsOf) { + static getFields(fields: FieldsOf) { return [ fields.noteHashes, fields.nullifiers, fields.l2ToL1Msgs, fields.privateLogs, - fields.unencryptedLogsHashes, fields.contractClassLogsHashes, - fields.unencryptedLogPreimagesLength, fields.contractClassLogPreimagesLength, - fields.publicDataWrites, ] 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() { @@ -107,7 +85,7 @@ export class CombinedAccumulatedData { } toBuffer() { - return serializeToBuffer(...CombinedAccumulatedData.getFields(this)); + return serializeToBuffer(...PrivateToRollupAccumulatedData.getFields(this)); } toString() { @@ -119,18 +97,15 @@ 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), 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), ); } @@ -140,25 +115,22 @@ 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), 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), ); } [inspect.custom]() { - return `CombinedAccumulatedData { + return `PrivateToRollupAccumulatedData { noteHashes: [${this.noteHashes .filter(x => !x.isZero()) .map(x => inspect(x)) @@ -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/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 2cbedd38627..1f7cde5ddfd 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, @@ -91,7 +91,6 @@ import { PublicKeys, RECURSIVE_PROOF_LENGTH, ReadRequest, - RevertCode, RollupTypes, RootParityInput, RootParityInputs, @@ -141,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'; @@ -304,24 +303,16 @@ 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 makePrivateToRollupAccumulatedData(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), 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, - ), ); } @@ -394,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), @@ -423,13 +414,14 @@ 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), - makePartialStateReference(seed + 0x200), - RevertCode.OK, + makePrivateToRollupAccumulatedData(seed, fullAccumulatedData), + makeTxConstantData(seed + 0x100), makeGas(seed + 0x600), makeAztecAddress(seed + 0x700), ); @@ -1122,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..0287b5c2c45 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, @@ -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, @@ -683,9 +683,9 @@ export function mapPrivateKernelDataToNoir( } export function mapPrivateKernelTailCircuitPublicInputsForRollupFromNoir( - inputs: KernelCircuitPublicInputsNoir, + 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 8434af0674a..e4fb401537e 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, @@ -19,8 +18,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, @@ -29,9 +26,10 @@ import { PartialStateReference, Point, PrivateLog, + PrivateToRollupAccumulatedData, PublicCallRequest, type PublicDataTreeLeafPreimage, - PublicDataWrite, + type PublicDataWrite, ScopedL2ToL1Message, ScopedLogHash, StateReference, @@ -44,7 +42,6 @@ import { type Tuple, mapTuple, toTruncField } from '@aztec/foundation/serialize' import type { AppendOnlyTreeSnapshot as AppendOnlyTreeSnapshotNoir, BlockHeader as BlockHeaderNoir, - CombinedAccumulatedData as CombinedAccumulatedDataNoir, ContentCommitment as ContentCommitmentNoir, Field, FixedLengthArray, @@ -66,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, @@ -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), @@ -673,32 +667,28 @@ 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 mapPrivateToRollupAccumulatedDataFromNoir( + privateToRollupAccumulatedData: PrivateToRollupAccumulatedDataNoir, +) { + return new PrivateToRollupAccumulatedData( + mapTupleFromNoir(privateToRollupAccumulatedData.note_hashes, MAX_NOTE_HASHES_PER_TX, mapFieldFromNoir), + mapTupleFromNoir(privateToRollupAccumulatedData.nullifiers, MAX_NULLIFIERS_PER_TX, mapFieldFromNoir), mapTupleFromNoir( - combinedAccumulatedData.unencrypted_logs_hashes, - MAX_UNENCRYPTED_LOGS_PER_TX, - mapScopedLogHashFromNoir, + 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.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, - ), + 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 5f3a6f9a660..a53043c6082 100644 --- a/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/conversion/server.ts @@ -6,12 +6,9 @@ import { type AvmCircuitPublicInputs, BLOBS_PER_BLOCK, type BaseParityInputs, - type CombinedAccumulatedData, - CombinedConstantData, type EmptyNestedData, Fr, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, - KernelCircuitPublicInputs, type MembershipWitness, type NESTED_RECURSIVE_PROOF_LENGTH, type NULLIFIER_TREE_HEIGHT, @@ -22,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, @@ -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'; @@ -73,14 +72,11 @@ import type { BlockMergeRollupInputs as BlockMergeRollupInputsNoir, BlockRootOrBlockMergePublicInputs as BlockRootOrBlockMergePublicInputsNoir, BlockRootRollupInputs as BlockRootRollupInputsNoir, - CombinedAccumulatedData as CombinedAccumulatedDataNoir, - CombinedConstantData as CombinedConstantDataNoir, 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, @@ -95,6 +91,8 @@ import type { PrivateToAvmAccumulatedData as PrivateToAvmAccumulatedDataNoir, PrivateToPublicAccumulatedData as PrivateToPublicAccumulatedDataNoir, PrivateToPublicKernelCircuitPublicInputs as PrivateToPublicKernelCircuitPublicInputsNoir, + PrivateToRollupAccumulatedData as PrivateToRollupAccumulatedDataNoir, + PrivateToRollupKernelCircuitPublicInputs as PrivateToRollupKernelCircuitPublicInputsNoir, PrivateTubeData as PrivateTubeDataNoir, PublicBaseRollupInputs as PublicBaseRollupInputsNoir, PublicBaseStateDiffHints as PublicBaseStateDiffHintsNoir, @@ -115,7 +113,6 @@ import { mapAppendOnlyTreeSnapshotToNoir, mapAztecAddressFromNoir, mapAztecAddressToNoir, - mapCombinedAccumulatedDataFromNoir, mapEthAddressFromNoir, mapEthAddressToNoir, mapFieldFromNoir, @@ -136,6 +133,7 @@ import { mapPartialStateReferenceFromNoir, mapPartialStateReferenceToNoir, mapPrivateLogToNoir, + mapPrivateToRollupAccumulatedDataFromNoir, mapPublicCallRequestToNoir, mapPublicDataTreePreimageToNoir, mapPublicDataWriteToNoir, @@ -471,42 +469,31 @@ export function mapPrivateToPublicAccumulatedDataToNoir( }; } -export function mapCombinedAccumulatedDataToNoir( - combinedAccumulatedData: CombinedAccumulatedData, -): CombinedAccumulatedDataNoir { +export function mapPrivateToRollupAccumulatedDataToNoir( + privateToRollupAccumulatedData: PrivateToRollupAccumulatedData, +): PrivateToRollupAccumulatedDataNoir { 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), - 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), + 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), }; } -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), @@ -530,13 +517,13 @@ export function mapPrivateToPublicKernelCircuitPublicInputsToNoir( }; } -export function mapKernelCircuitPublicInputsToNoir(inputs: KernelCircuitPublicInputs): KernelCircuitPublicInputsNoir { +export function mapPrivateToRollupKernelCircuitPublicInputsToNoir( + inputs: PrivateToRollupKernelCircuitPublicInputs, +): PrivateToRollupKernelCircuitPublicInputsNoir { return { rollup_validation_requests: mapRollupValidationRequestsToNoir(inputs.rollupValidationRequests), - constants: mapCombinedConstantDataToNoir(inputs.constants), - end: mapCombinedAccumulatedDataToNoir(inputs.end), - start_state: mapPartialStateReferenceToNoir(inputs.startState), - revert_code: mapRevertCodeToNoir(inputs.revertCode), + constants: mapTxConstantDataToNoir(inputs.constants), + end: mapPrivateToRollupAccumulatedDataToNoir(inputs.end), gas_used: mapGasToNoir(inputs.gasUsed), fee_payer: mapAztecAddressToNoir(inputs.feePayer), }; @@ -831,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), }; @@ -954,13 +941,13 @@ 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), - mapCombinedConstantDataFromNoir(inputs.constants), - mapPartialStateReferenceFromNoir(inputs.start_state), - mapRevertCodeFromNoir(inputs.revert_code), + mapPrivateToRollupAccumulatedDataFromNoir(inputs.end), + mapTxConstantDataFromNoir(inputs.constants), mapGasFromNoir(inputs.gas_used), mapAztecAddressFromNoir(inputs.fee_payer), ); 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(), ),