Skip to content

Commit

Permalink
feat: Pass through unencrypted logs to base rollup (#7457)
Browse files Browse the repository at this point in the history
Instead of siloing and crunching together all the unencrypted logs in
the private kernels and the public kernels, we pass them through to the
base rollup who will do that work.
  • Loading branch information
sirasistant authored Jul 15, 2024
1 parent 09299e3 commit 0381502
Show file tree
Hide file tree
Showing 41 changed files with 481 additions and 288 deletions.
8 changes: 4 additions & 4 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ library Constants {
uint256 internal constant PUBLIC_DATA_READ_LENGTH = 2;
uint256 internal constant VALIDATION_REQUESTS_LENGTH = 1090;
uint256 internal constant PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 3;
uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 333;
uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 364;
uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 41;
uint256 internal constant PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH = 15;
uint256 internal constant CALL_REQUEST_LENGTH = 7;
uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1160;
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2300;
uint256 internal constant PUBLIC_ACCUMULATED_DATA_LENGTH = 983;
uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3323;
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 384;
uint256 internal constant PUBLIC_ACCUMULATED_DATA_LENGTH = 991;
uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3339;
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 415;
uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = 11;
uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 28;
uint256 internal constant ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = 9;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use dep::types::{
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NOTE_HASHES_PER_TX,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL
},
hash::{
silo_encrypted_log_hash, silo_l2_to_l1_message, silo_note_hash, silo_nullifier,
silo_unencrypted_log_hash
},
hash::{silo_encrypted_log_hash, silo_l2_to_l1_message, silo_note_hash, silo_nullifier},
traits::is_empty, transaction::tx_request::TxRequest,
utils::arrays::{array_length, array_to_bounded_vec, sort_by_counters_asc, sort_by_counters_desc}
};
Expand Down Expand Up @@ -293,7 +290,6 @@ impl PrivateKernelCircuitPublicInputsComposer {
self.silo_nullifiers();
self.silo_l2_to_l1_messages();
self.silo_encrypted_logs();
self.silo_unencrypted_logs();
}

fn silo_note_hashes(&mut self) {
Expand Down Expand Up @@ -333,11 +329,4 @@ impl PrivateKernelCircuitPublicInputsComposer {
self.public_inputs.end.encrypted_logs_hashes.storage[i].log_hash.value = silo_encrypted_log_hash(logs[i]);
}
}

fn silo_unencrypted_logs(&mut self) {
let logs = self.public_inputs.end.unencrypted_logs_hashes.storage;
for i in 0..logs.len() {
self.public_inputs.end.unencrypted_logs_hashes.storage[i].log_hash.value = silo_unencrypted_log_hash(logs[i]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl TailOutputComposer {
data.l2_to_l1_msgs = source.l2_to_l1_msgs.storage.map(|m: ScopedL2ToL1Message| m.message.content);
data.note_encrypted_logs_hash = compute_tx_note_logs_hash(source.note_encrypted_logs_hashes.storage.map(|l: NoteLogHash| l.expose_to_public()));
data.encrypted_logs_hash = compute_tx_logs_hash(source.encrypted_logs_hashes.storage.map(|l: ScopedEncryptedLogHash| l.expose_to_public()));
data.unencrypted_logs_hash = compute_tx_logs_hash(source.unencrypted_logs_hashes.storage.map(|l: ScopedLogHash| l.expose_to_public()));
data.unencrypted_logs_hashes = source.unencrypted_logs_hashes.storage.map(|l: ScopedLogHash| l.expose_to_public());
data.note_encrypted_log_preimages_length = source.note_encrypted_logs_hashes.storage.fold(0, |len, l: NoteLogHash| len + l.length);
data.encrypted_log_preimages_length = source.encrypted_logs_hashes.storage.fold(0, |len, l: ScopedEncryptedLogHash| len + l.log_hash.length);
data.unencrypted_log_preimages_length = source.unencrypted_logs_hashes.storage.fold(0, |len, l: ScopedLogHash| len + l.log_hash.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use dep::types::{
},
hash::{
compute_tx_logs_hash, compute_tx_note_logs_hash, silo_encrypted_log_hash, silo_l2_to_l1_message,
silo_note_hash, silo_nullifier, silo_unencrypted_log_hash
silo_note_hash, silo_nullifier
},
traits::is_empty, utils::arrays::assert_sorted_transformed_value_array
traits::is_empty,
utils::arrays::{assert_sorted_transformed_value_array, assert_sorted_array_with_order_hints}
};

struct TailOutputValidator {
Expand Down Expand Up @@ -136,21 +137,16 @@ impl TailOutputValidator {
assert_eq(hash, self.output.end.encrypted_logs_hash, "mismatch encrypted_logs_hash");

// unencrypted_log_hashes
validate_value_transformation(
self.previous_kernel.end.unencrypted_logs_hashes,
hints.siloed_unencrypted_log_hashes,
|slh: ScopedLogHash, lh: LogHash| (lh.value == silo_unencrypted_log_hash(slh)) & (lh.length == slh.log_hash.length)
);

assert_sorted_transformed_value_array(
assert_sorted_array_with_order_hints(
self.previous_kernel.end.unencrypted_logs_hashes,
hints.siloed_unencrypted_log_hashes,
hints.sorted_siloed_unencrypted_log_hashes,
hints.sorted_unencrypted_log_hashes,
hints.sorted_unencrypted_log_hash_hints
);

let hash = compute_tx_logs_hash(hints.sorted_siloed_unencrypted_log_hashes);
assert_eq(hash, self.output.end.unencrypted_logs_hash, "mismatch unencrypted_logs_hash");
assert_eq(
hints.sorted_unencrypted_log_hashes.map(|log: ScopedLogHash| log.expose_to_public()), self.output.end.unencrypted_logs_hashes, "mismatch unencrypted_logs_hashes"
);
}

fn validate_gas_limits(self) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use dep::types::{
MAX_ENCRYPTED_LOGS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX,
MAX_NOTE_ENCRYPTED_LOGS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX
},
hash::{
silo_encrypted_log_hash, silo_l2_to_l1_message, silo_note_hash, silo_nullifier,
silo_unencrypted_log_hash
},
hash::{silo_encrypted_log_hash, silo_l2_to_l1_message, silo_note_hash, silo_nullifier},
messaging::l2_to_l1_message::ScopedL2ToL1Message, traits::{Empty, is_empty},
utils::arrays::{OrderHint, sort_by_counters_asc, sort_get_order_hints_asc}
};
Expand All @@ -34,8 +31,7 @@ struct Hints {
sorted_siloed_encrypted_log_hashes: [LogHash; MAX_ENCRYPTED_LOGS_PER_TX],
sorted_encrypted_log_hash_hints: [OrderHint; MAX_ENCRYPTED_LOGS_PER_TX],
// Unencrypted log hashes.
siloed_unencrypted_log_hashes: [LogHash; MAX_UNENCRYPTED_LOGS_PER_TX],
sorted_siloed_unencrypted_log_hashes: [LogHash; MAX_UNENCRYPTED_LOGS_PER_TX],
sorted_unencrypted_log_hashes: [ScopedLogHash; MAX_UNENCRYPTED_LOGS_PER_TX],
sorted_unencrypted_log_hash_hints: [OrderHint; MAX_UNENCRYPTED_LOGS_PER_TX],
}

Expand Down Expand Up @@ -83,12 +79,7 @@ unconstrained pub fn generate_kernel_circuit_output_hints(previous_kernel: Priva
let sorted_encrypted_log_hash_hints = sort_get_order_hints_asc(previous_kernel.end.encrypted_logs_hashes);

// unencrypted_logs
let mut siloed_log_hashes = previous_kernel.end.unencrypted_logs_hashes;
for i in 0..siloed_log_hashes.len() {
siloed_log_hashes[i].log_hash.value = silo_unencrypted_log_hash(previous_kernel.end.unencrypted_logs_hashes[i]);
}
let sorted_siloed_unencrypted_log_hashes = sort_by_counters_asc(siloed_log_hashes).map(|h: ScopedLogHash| h.inner());
let siloed_unencrypted_log_hashes = siloed_log_hashes.map(|h: ScopedLogHash| h.inner());
let sorted_unencrypted_log_hashes = sort_by_counters_asc(previous_kernel.end.unencrypted_logs_hashes);
let sorted_unencrypted_log_hash_hints = sort_get_order_hints_asc(previous_kernel.end.unencrypted_logs_hashes);

Hints {
Expand All @@ -104,8 +95,7 @@ unconstrained pub fn generate_kernel_circuit_output_hints(previous_kernel: Priva
sorted_note_encrypted_log_hash_hints,
siloed_encrypted_log_hashes,
sorted_encrypted_log_hash_hints,
siloed_unencrypted_log_hashes,
sorted_siloed_unencrypted_log_hashes,
sorted_unencrypted_log_hashes,
sorted_unencrypted_log_hash_hints
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dep::types::{
abis::{
accumulated_data::{public_accumulated_data_builder::PublicAccumulatedDataBuilder}, gas::Gas,
log_hash::LogHash
log_hash::{LogHash, ScopedLogHash}
},
constants::{
DA_BYTES_PER_FIELD, DA_GAS_PER_BYTE, FIXED_AVM_STARTUP_L2_GAS, L2_GAS_PER_NOTE_HASH,
Expand Down Expand Up @@ -29,7 +29,7 @@ fn meter_gas_used(data: PublicAccumulatedDataBuilder) -> Gas {
metered_da_bytes += encrypted_log_preimages_length as u32;
metered_l2_gas += encrypted_log_preimages_length as u32 * L2_GAS_PER_LOG_BYTE;

let unencrypted_log_preimages_length = data.unencrypted_logs_hashes.storage.fold(0, |len, l: LogHash| len + l.length);
let unencrypted_log_preimages_length = data.unencrypted_logs_hashes.storage.fold(0, |len, l: ScopedLogHash| len + l.log_hash.length);
metered_da_bytes += unencrypted_log_preimages_length as u32;
metered_l2_gas += unencrypted_log_preimages_length as u32 * L2_GAS_PER_LOG_BYTE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use dep::types::{
kernel_circuit_public_inputs::{PrivateKernelCircuitPublicInputs, PublicKernelCircuitPublicInputs},
log_hash::{LogHash, ScopedEncryptedLogHash, NoteLogHash, ScopedLogHash}, nullifier::Nullifier
},
hash::{
silo_encrypted_log_hash, silo_l2_to_l1_message, silo_note_hash, silo_nullifier,
silo_unencrypted_log_hash
},
hash::{silo_encrypted_log_hash, silo_l2_to_l1_message, silo_note_hash, silo_nullifier},
traits::{Empty, is_empty_array},
utils::arrays::{assert_split_sorted_transformed_value_arrays_asc, assert_split_sorted_transformed_value_arrays_desc}
};
Expand Down Expand Up @@ -151,15 +148,10 @@ impl TailToPublicOutputValidator {
);

// unencrypted_logs_hashes
validate_value_transformation(
prev_data.unencrypted_logs_hashes,
hints.siloed_unencrypted_logs_hashes,
|slh: ScopedLogHash, lh: LogHash| (lh.value == silo_unencrypted_log_hash(slh)) & (lh.length == slh.log_hash.length) & (lh.counter == 0)
);

assert_split_sorted_transformed_value_arrays_asc(
prev_data.unencrypted_logs_hashes,
hints.siloed_unencrypted_logs_hashes,
prev_data.unencrypted_logs_hashes,
split_counter,
output_non_revertible.unencrypted_logs_hashes,
output_revertible.unencrypted_logs_hashes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use dep::types::{
MAX_ENCRYPTED_LOGS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX,
MAX_NOTE_ENCRYPTED_LOGS_PER_TX, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX
},
hash::{
silo_encrypted_log_hash, silo_l2_to_l1_message, silo_note_hash, silo_nullifier,
silo_unencrypted_log_hash
},
hash::{silo_encrypted_log_hash, silo_l2_to_l1_message, silo_note_hash, silo_nullifier},
messaging::l2_to_l1_message::ScopedL2ToL1Message,
utils::arrays::{sort_get_split_order_hints_asc, sort_get_split_order_hints_desc, SplitOrderHints}
};
Expand All @@ -33,7 +30,6 @@ struct TailToPublicOutputHints {
siloed_encrypted_logs_hashes: [LogHash; MAX_ENCRYPTED_LOGS_PER_TX],
sorted_encrypted_log_hash_hints: SplitOrderHints<MAX_ENCRYPTED_LOGS_PER_TX>,
// Unencrypted log hashes.
siloed_unencrypted_logs_hashes: [LogHash; MAX_UNENCRYPTED_LOGS_PER_TX],
sorted_unencrypted_log_hash_hints: SplitOrderHints<MAX_UNENCRYPTED_LOGS_PER_TX>,
// Public call requests.
public_call_requests: [CallRequest; MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX],
Expand Down Expand Up @@ -91,11 +87,6 @@ unconstrained pub fn generate_tail_to_public_output_hints(previous_kernel: Priva
let sorted_encrypted_log_hash_hints = sort_get_split_order_hints_asc(previous_kernel.end.encrypted_logs_hashes, split_counter);

// unencrypted_logs
let mut siloed_log_hashes = previous_kernel.end.unencrypted_logs_hashes;
for i in 0..siloed_log_hashes.len() {
siloed_log_hashes[i].log_hash.value = silo_unencrypted_log_hash(previous_kernel.end.unencrypted_logs_hashes[i]);
}
let siloed_unencrypted_logs_hashes = siloed_log_hashes.map(|h: ScopedLogHash| h.inner());
let sorted_unencrypted_log_hash_hints = sort_get_split_order_hints_asc(previous_kernel.end.unencrypted_logs_hashes, split_counter);

// public_call_requests
Expand All @@ -115,7 +106,6 @@ unconstrained pub fn generate_tail_to_public_output_hints(previous_kernel: Priva
sorted_note_encrypted_log_hash_hints,
siloed_encrypted_logs_hashes,
sorted_encrypted_log_hash_hints,
siloed_unencrypted_logs_hashes,
sorted_unencrypted_log_hash_hints,
public_call_requests,
sorted_public_call_request_hints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ mod tests {
use dep::types::{
abis::{
kernel_circuit_public_inputs::KernelCircuitPublicInputs, max_block_number::MaxBlockNumber,
note_hash::{NoteHash, ScopedNoteHash}, nullifier::{Nullifier, ScopedNullifier}, gas::Gas
note_hash::{NoteHash, ScopedNoteHash}, nullifier::{Nullifier, ScopedNullifier}, gas::Gas,
log_hash::ScopedLogHash
},
address::{AztecAddress, EthAddress}, scalar::Scalar,
hash::{
sha256_to_field, silo_note_hash, silo_nullifier, compute_siloed_encrypted_log_hash,
compute_siloed_unencrypted_log_hash
},
hash::{sha256_to_field, silo_note_hash, silo_nullifier, compute_siloed_encrypted_log_hash},
tests::fixture_builder::FixtureBuilder, utils::{arrays::array_length},
traits::{Empty, is_empty}, point::Point
};
Expand Down Expand Up @@ -176,23 +174,9 @@ mod tests {
let expected_encrypted_logs_hash = sha256_to_field(hash_bytes);
assert_eq(public_inputs.end.encrypted_logs_hash, expected_encrypted_logs_hash);

let siloed_unencrypted_logs_hashes = [
compute_siloed_unencrypted_log_hash(
builder.previous_kernel.storage_contract_address,
prev_unencrypted_logs_hash
), compute_siloed_unencrypted_log_hash(
builder.previous_kernel.storage_contract_address,
unencrypted_logs_hash
)
];
// noir-fmt:ignore
let hash_bytes: [u8; MAX_UNENCRYPTED_LOGS_PER_TX * 32] = siloed_unencrypted_logs_hashes[0]
.to_be_bytes(32)
.append(siloed_unencrypted_logs_hashes[1].to_be_bytes(32))
.append(&[0; MAX_UNENCRYPTED_LOGS_PER_TX * 32 - 64])
.as_array();
let expected_unencrypted_logs_hash = sha256_to_field(hash_bytes);
assert_eq(public_inputs.end.unencrypted_logs_hash, expected_unencrypted_logs_hash);
assert_eq(
public_inputs.end.unencrypted_logs_hashes, builder.previous_kernel.unencrypted_logs_hashes.storage.map(|log: ScopedLogHash| log.expose_to_public())
);
}

unconstrained fn compute_hash_bytes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ fn validate_accumulated_values_unencrypted_log_hashes_unordered_succeeds() {
builder.validate();
}

#[test(should_fail_with="mismatch unencrypted_logs_hash")]
fn validate_accumulated_values_unencrypted_log_hashes_wrong_hash_fails() {
#[test(should_fail_with="mismatch unencrypted_logs_hashes")]
fn validate_accumulated_values_unencrypted_log_hashes_wrong_order_fails() {
let mut builder = TailOutputValidatorBuilder::new();

builder.previous_kernel.append_unencrypted_log_hashes(3);
builder.output.append_unencrypted_log_hashes(3);
// Swap the items in the output, making them out of order, and then hash.
// Swap the items in the output, making them out of order
swap_items(&mut builder.output.unencrypted_logs_hashes, 0, 2);
builder.output.hash_unencrypted_log_hashes();

builder.validate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fn tail_to_public_output_composer_succeeds() {
siloed_data_builder.add_siloed_encrypted_log_hash(2001, 2);

builder.previous_kernel.add_unencrypted_log_hash(3001, 51);
siloed_data_builder.add_siloed_unencrypted_log_hash(3001, 51);

builder.previous_kernel.append_public_call_requests(2);

Expand All @@ -56,7 +55,6 @@ fn tail_to_public_output_composer_succeeds() {
siloed_data_builder.add_siloed_encrypted_log_hash(2003, 24);

builder.previous_kernel.add_unencrypted_log_hash(3002, 4);
siloed_data_builder.add_siloed_unencrypted_log_hash(3002, 4);

builder.previous_kernel.append_public_call_requests(3);

Expand Down Expand Up @@ -112,12 +110,12 @@ fn tail_to_public_output_composer_succeeds() {
assert_array_eq(output.end.encrypted_logs_hashes, [siloed[1], siloed[2]]);

// unencrypted_logs_hashes
let siloed = siloed_data.unencrypted_logs_hashes;
let unsiloed = unsiloed_data.unencrypted_logs_hashes;
assert_array_eq(
output.end_non_revertible.unencrypted_logs_hashes,
[siloed[0]]
[unsiloed[0]]
);
assert_array_eq(output.end.unencrypted_logs_hashes, [siloed[1]]);
assert_array_eq(output.end.unencrypted_logs_hashes, [unsiloed[1]]);

// public_call_stack
let unsiloed = unsiloed_data.public_call_stack;
Expand Down
Loading

0 comments on commit 0381502

Please sign in to comment.