Skip to content

Commit

Permalink
chore: Refactor tail public inputs (#11031)
Browse files Browse the repository at this point in the history
As preparation for
#9269 remove
legacy stuff from the tail public inputs
  • Loading branch information
sirasistant authored Jan 8, 2025
1 parent 67a6a72 commit 4ed1530
Show file tree
Hide file tree
Showing 57 changed files with 579 additions and 751 deletions.
4 changes: 2 additions & 2 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/noir-protocol-circuits/crates/blob/src/blob.nr
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,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];
}
Expand Down Expand Up @@ -507,7 +507,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];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,47 @@ 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) };
TailOutputValidator::new_with_hints(output, previous_kernel, hints)
}

pub fn new_with_hints(
output: KernelCircuitPublicInputs,
output: PrivateToRollupKernelCircuitPublicInputs,
previous_kernel: PrivateKernelCircuitPublicInputs,
hints: TailOutputHints,
) -> Self {
TailOutputValidator { output, previous_kernel, hints }
}

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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::types::{
block_header::BlockHeader,
KernelCircuitPublicInputs,
PrivateToRollupKernelCircuitPublicInputs,
proof::{
rollup_recursive_proof::RecursiveProof,
traits::Verifiable,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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();
}
Expand All @@ -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,
Expand All @@ -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(),
};
Expand All @@ -108,9 +107,7 @@ mod tests {
#[test]
fn execution_succeeded() {
let mut builder = PrivateKernelTailInputsBuilder::new();
let public_inputs = builder.execute();

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

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod validate_empty_values;
mod validate_gas_used;
mod validate_propagated_sorted_values;
mod validate_propagated_values;
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading

0 comments on commit 4ed1530

Please sign in to comment.