Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Delay encrypted log hashing to base rollup #7808

Merged
merged 12 commits into from
Aug 8, 2024
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 @@ -184,13 +184,13 @@ library Constants {
uint256 internal constant PRIVATE_VALIDATION_REQUESTS_LENGTH = 772;
uint256 internal constant PUBLIC_VALIDATION_REQUESTS_LENGTH = 514;
uint256 internal constant PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 3;
uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 388;
uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 610;
uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 43;
uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1336;
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2167;
uint256 internal constant PUBLIC_ACCUMULATED_DATA_LENGTH = 1303;
uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3613;
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 441;
uint256 internal constant PUBLIC_ACCUMULATED_DATA_LENGTH = 1311;
uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3629;
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 663;
uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = 12;
uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 29;
uint256 internal constant GET_NOTES_ORACLE_RETURN_LENGTH = 674;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +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_note_hash, silo_nullifier}, traits::is_empty,
hash::{silo_note_hash, silo_nullifier, mask_encrypted_log_hash}, 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 @@ -276,7 +276,7 @@ impl PrivateKernelCircuitPublicInputsComposer {
fn silo_scoped_values(&mut self) {
self.silo_note_hashes();
self.silo_nullifiers();
self.silo_encrypted_logs();
self.mask_encrypted_logs();
}

fn silo_note_hashes(&mut self) {
Expand All @@ -298,10 +298,10 @@ impl PrivateKernelCircuitPublicInputsComposer {
}
}

fn silo_encrypted_logs(&mut self) {
fn mask_encrypted_logs(&mut self) {
let logs = self.public_inputs.end.encrypted_logs_hashes.storage;
for i in 0..logs.len() {
self.public_inputs.end.encrypted_logs_hashes.storage[i].log_hash.value = silo_encrypted_log_hash(logs[i]);
self.public_inputs.end.encrypted_logs_hashes.storage[i].contract_address = mask_encrypted_log_hash(logs[i]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ impl TailOutputComposer {
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 = source.l2_to_l1_msgs.storage.map(|m: ScopedL2ToL1Message| m.expose_to_public());
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.note_encrypted_logs_hashes = source.note_encrypted_logs_hashes.storage.map(|l: NoteLogHash| l.expose_to_public());
data.encrypted_logs_hashes = source.encrypted_logs_hashes.storage.map(|l: ScopedEncryptedLogHash| 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use dep::types::{
log_hash::{LogHash, NoteLogHash, ScopedEncryptedLogHash, ScopedLogHash}
},
messaging::l2_to_l1_message::ScopedL2ToL1Message,
hash::{compute_tx_logs_hash, compute_tx_note_logs_hash, silo_encrypted_log_hash, silo_note_hash, silo_nullifier},
hash::{compute_tx_logs_hash, compute_tx_note_logs_hash, silo_note_hash, silo_nullifier, mask_encrypted_log_hash},
traits::is_empty,
utils::arrays::{assert_sorted_transformed_value_array, assert_sorted_array_with_order_hints}
};
Expand Down Expand Up @@ -107,39 +107,34 @@ impl TailOutputValidator {

fn validate_accumulated_values(self) {
// note_encrypted_log_hashes
validate_value_transformation(
self.previous_kernel.end.note_encrypted_logs_hashes,
self.hints.note_encrypted_log_hashes,
|nlh: NoteLogHash, lh: LogHash| (nlh.value == lh.value) & (nlh.length == lh.length)
);

assert_sorted_transformed_value_array(
assert_sorted_array_with_order_hints(
self.previous_kernel.end.note_encrypted_logs_hashes,
self.hints.note_encrypted_log_hashes,
self.hints.sorted_note_encrypted_log_hashes,
self.hints.sorted_note_encrypted_log_hash_hints
);

let hash = compute_tx_note_logs_hash(self.hints.sorted_note_encrypted_log_hashes);
assert_eq(hash, self.output.end.note_encrypted_logs_hash, "mismatch note_encrypted_logs_hash");
assert_eq(
self.hints.sorted_note_encrypted_log_hashes.map(|log: NoteLogHash| log.expose_to_public()), self.output.end.note_encrypted_logs_hashes, "mismatch note_encrypted_logs_hashes"
);

// encrypted_log_hashes
validate_value_transformation(
self.previous_kernel.end.encrypted_logs_hashes,
self.hints.siloed_encrypted_log_hashes,
|slh: ScopedEncryptedLogHash, lh: LogHash| (lh.value == silo_encrypted_log_hash(slh)) & (lh.length == slh.log_hash.length)
self.hints.masked_encrypted_log_hashes,
|lh: ScopedEncryptedLogHash, mlh: ScopedLogHash|
(mlh.contract_address == mask_encrypted_log_hash(lh)) &
(lh.log_hash.value == mlh.log_hash.value) &
(lh.log_hash.length == mlh.log_hash.length) &
(mlh.log_hash.counter == 0)
);

assert_sorted_transformed_value_array(
self.previous_kernel.end.encrypted_logs_hashes,
self.hints.siloed_encrypted_log_hashes,
self.hints.sorted_siloed_encrypted_log_hashes,
self.hints.sorted_encrypted_log_hash_hints
self.hints.masked_encrypted_log_hashes,
self.output.end.encrypted_logs_hashes,
self.hints.sorted_masked_encrypted_log_hash_hints
);

let hash = compute_tx_logs_hash(self.hints.sorted_siloed_encrypted_log_hashes);
assert_eq(hash, self.output.end.encrypted_logs_hash, "mismatch encrypted_logs_hash");

// unencrypted_log_hashes
assert_sorted_array_with_order_hints(
self.previous_kernel.end.unencrypted_logs_hashes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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_note_hash, silo_nullifier},
hash::{silo_note_hash, silo_nullifier, mask_encrypted_log_hash},
messaging::l2_to_l1_message::ScopedL2ToL1Message, traits::{Empty, is_empty},
utils::arrays::{OrderHint, sort_by_counters_asc, sort_get_order_hints_asc}
};
Expand All @@ -21,13 +21,11 @@ struct TailOutputHints {
// L2 to l1 msgs.
sorted_l2_to_l1_msg_hints: [OrderHint; MAX_L2_TO_L1_MSGS_PER_TX],
// Note encrypted log hashes.
note_encrypted_log_hashes: [LogHash; MAX_NOTE_ENCRYPTED_LOGS_PER_TX],
sorted_note_encrypted_log_hashes: [LogHash; MAX_NOTE_ENCRYPTED_LOGS_PER_TX],
sorted_note_encrypted_log_hashes: [NoteLogHash; MAX_NOTE_ENCRYPTED_LOGS_PER_TX],
sorted_note_encrypted_log_hash_hints: [OrderHint; MAX_NOTE_ENCRYPTED_LOGS_PER_TX],
// Encrypted log hashes.
siloed_encrypted_log_hashes: [LogHash; MAX_ENCRYPTED_LOGS_PER_TX],
sorted_siloed_encrypted_log_hashes: [LogHash; MAX_ENCRYPTED_LOGS_PER_TX],
sorted_encrypted_log_hash_hints: [OrderHint; MAX_ENCRYPTED_LOGS_PER_TX],
masked_encrypted_log_hashes: [ScopedLogHash; MAX_ENCRYPTED_LOGS_PER_TX],
sorted_masked_encrypted_log_hash_hints: [OrderHint; MAX_ENCRYPTED_LOGS_PER_TX],
// Unencrypted log hashes.
sorted_unencrypted_log_hashes: [ScopedLogHash; MAX_UNENCRYPTED_LOGS_PER_TX],
sorted_unencrypted_log_hash_hints: [OrderHint; MAX_UNENCRYPTED_LOGS_PER_TX],
Expand All @@ -45,18 +43,16 @@ unconstrained pub fn generate_tail_output_hints(previous_kernel: PrivateKernelCi
let sorted_l2_to_l1_msg_hints = sort_get_order_hints_asc(previous_kernel.end.l2_to_l1_msgs);

// note_encrypted_logs
let note_encrypted_log_hashes = previous_kernel.end.note_encrypted_logs_hashes.map(|h: NoteLogHash| h.expose_to_public());
let sorted_note_encrypted_log_hashes = sort_by_counters_asc(previous_kernel.end.note_encrypted_logs_hashes).map(|h: NoteLogHash| h.expose_to_public());
let sorted_note_encrypted_log_hashes = sort_by_counters_asc(previous_kernel.end.note_encrypted_logs_hashes);
let sorted_note_encrypted_log_hash_hints = sort_get_order_hints_asc(previous_kernel.end.note_encrypted_logs_hashes);

// encrypted_logs
let mut siloed_log_hashes = previous_kernel.end.encrypted_logs_hashes;
for i in 0..siloed_log_hashes.len() {
siloed_log_hashes[i].log_hash.value = silo_encrypted_log_hash(previous_kernel.end.encrypted_logs_hashes[i]);
let mut masked_log_hashes = previous_kernel.end.encrypted_logs_hashes;
for i in 0..masked_log_hashes.len() {
masked_log_hashes[i].contract_address = mask_encrypted_log_hash(previous_kernel.end.encrypted_logs_hashes[i]);
}
let sorted_siloed_encrypted_log_hashes = sort_by_counters_asc(siloed_log_hashes).map(|h: ScopedEncryptedLogHash| h.expose_to_public());
let siloed_encrypted_log_hashes = siloed_log_hashes.map(|h: ScopedEncryptedLogHash| h.expose_to_public());
let sorted_encrypted_log_hash_hints = sort_get_order_hints_asc(previous_kernel.end.encrypted_logs_hashes);
let masked_encrypted_log_hashes = masked_log_hashes.map(|h: ScopedEncryptedLogHash| h.expose_to_public());
let sorted_masked_encrypted_log_hash_hints = sort_get_order_hints_asc(previous_kernel.end.encrypted_logs_hashes);

// unencrypted_logs
let sorted_unencrypted_log_hashes = sort_by_counters_asc(previous_kernel.end.unencrypted_logs_hashes);
Expand All @@ -67,12 +63,10 @@ unconstrained pub fn generate_tail_output_hints(previous_kernel: PrivateKernelCi
sorted_nullifier_hints,
siloed_nullifiers,
sorted_l2_to_l1_msg_hints,
note_encrypted_log_hashes,
sorted_note_encrypted_log_hashes,
sorted_siloed_encrypted_log_hashes,
sorted_note_encrypted_log_hash_hints,
siloed_encrypted_log_hashes,
sorted_encrypted_log_hash_hints,
masked_encrypted_log_hashes,
sorted_masked_encrypted_log_hash_hints,
sorted_unencrypted_log_hashes,
sorted_unencrypted_log_hash_hints
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn meter_gas_used(data: PublicAccumulatedData) -> Gas {
metered_da_bytes += note_encrypted_log_preimages_length as u32;
metered_l2_gas += note_encrypted_log_preimages_length as u32 * L2_GAS_PER_LOG_BYTE;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use dep::types::{
nullifier::Nullifier, public_call_request::PublicCallRequest
},
messaging::l2_to_l1_message::ScopedL2ToL1Message, address::AztecAddress,
hash::{silo_encrypted_log_hash, silo_note_hash, silo_nullifier},
hash::{silo_note_hash, silo_nullifier, mask_encrypted_log_hash},
traits::{Empty, is_empty, is_empty_array},
utils::arrays::{
array_length, assert_split_sorted_transformed_value_arrays_asc,
Expand Down Expand Up @@ -157,13 +157,17 @@ impl TailToPublicOutputValidator {
// encrypted_logs_hashes
validate_value_transformation(
prev_data.encrypted_logs_hashes,
hints.siloed_encrypted_logs_hashes,
|slh: ScopedEncryptedLogHash, lh: LogHash| (lh.value == silo_encrypted_log_hash(slh)) & (lh.length == slh.log_hash.length) & (lh.counter == 0)
hints.masked_encrypted_logs_hashes,
|lh: ScopedEncryptedLogHash, mlh: ScopedLogHash|
(mlh.contract_address == mask_encrypted_log_hash(lh)) &
(lh.log_hash.value == mlh.log_hash.value) &
(lh.log_hash.length == mlh.log_hash.length) &
(mlh.log_hash.counter == 0)
);

assert_split_sorted_transformed_value_arrays_asc(
prev_data.encrypted_logs_hashes,
hints.siloed_encrypted_logs_hashes,
hints.masked_encrypted_logs_hashes,
split_counter,
output_non_revertible.encrypted_logs_hashes,
output_revertible.encrypted_logs_hashes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +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_note_hash, silo_nullifier},
hash::{silo_note_hash, silo_nullifier, mask_encrypted_log_hash},
messaging::l2_to_l1_message::ScopedL2ToL1Message,
utils::arrays::{sort_get_split_order_hints_asc, sort_get_split_order_hints_desc, SplitOrderHints}
};
Expand All @@ -25,7 +25,7 @@ struct TailToPublicOutputHints {
note_encrypted_logs_hashes: [LogHash; MAX_NOTE_ENCRYPTED_LOGS_PER_TX],
sorted_note_encrypted_log_hash_hints: SplitOrderHints<MAX_NOTE_ENCRYPTED_LOGS_PER_TX>,
// Encrypted log hashes.
siloed_encrypted_logs_hashes: [LogHash; MAX_ENCRYPTED_LOGS_PER_TX],
masked_encrypted_logs_hashes: [ScopedLogHash; MAX_ENCRYPTED_LOGS_PER_TX],
sorted_encrypted_log_hash_hints: SplitOrderHints<MAX_ENCRYPTED_LOGS_PER_TX>,
// Unencrypted log hashes.
sorted_unencrypted_log_hash_hints: SplitOrderHints<MAX_UNENCRYPTED_LOGS_PER_TX>,
Expand Down Expand Up @@ -59,11 +59,12 @@ unconstrained pub fn generate_tail_to_public_output_hints(previous_kernel: Priva
let sorted_note_encrypted_log_hash_hints = sort_get_split_order_hints_asc(previous_kernel.end.note_encrypted_logs_hashes, split_counter);

// encrypted_logs
let mut siloed_log_hashes = previous_kernel.end.encrypted_logs_hashes;
for i in 0..siloed_log_hashes.len() {
siloed_log_hashes[i].log_hash.value = silo_encrypted_log_hash(previous_kernel.end.encrypted_logs_hashes[i]);
let masked_encrypted_logs_hashes = previous_kernel.end.encrypted_logs_hashes.map(
|mut h: ScopedEncryptedLogHash| {
h.contract_address = mask_encrypted_log_hash(h);
h.expose_to_public()
}
let siloed_encrypted_logs_hashes = siloed_log_hashes.map(|h: ScopedEncryptedLogHash| h.expose_to_public());
);
let sorted_encrypted_log_hash_hints = sort_get_split_order_hints_asc(previous_kernel.end.encrypted_logs_hashes, split_counter);

// unencrypted_logs
Expand All @@ -80,7 +81,7 @@ unconstrained pub fn generate_tail_to_public_output_hints(previous_kernel: Priva
sorted_l2_to_l1_msg_hints,
note_encrypted_logs_hashes,
sorted_note_encrypted_log_hash_hints,
siloed_encrypted_logs_hashes,
masked_encrypted_logs_hashes,
sorted_encrypted_log_hash_hints,
sorted_unencrypted_log_hash_hints,
public_call_requests,
Expand Down
Loading
Loading