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!: rm outgoing logs #10486

Merged
merged 41 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
54c0cd1
initial attempt to rm logs, with some failing tests
iAmMichaelConnor Dec 8, 2024
a28c87e
nargo fmt
iAmMichaelConnor Dec 8, 2024
0593f5d
update payload test snapshot
iAmMichaelConnor Dec 8, 2024
eccf14f
fix test
iAmMichaelConnor Dec 8, 2024
7a1766a
argh fmt
iAmMichaelConnor Dec 8, 2024
2cdd5c1
convenience script to rebuild one contract
iAmMichaelConnor Dec 9, 2024
762e057
some temp logs
iAmMichaelConnor Dec 9, 2024
af8d125
yarn format
iAmMichaelConnor Dec 9, 2024
8b0db81
rm debug logs
iAmMichaelConnor Dec 9, 2024
140c4fa
Merge branch 'master' into mc/rm-outgoing-logs
iAmMichaelConnor Dec 9, 2024
fcca441
nargo fmt
iAmMichaelConnor Dec 9, 2024
415d788
debug logs
iAmMichaelConnor Dec 9, 2024
f0a0a61
merge
iAmMichaelConnor Dec 9, 2024
6136094
Merge branch 'master' into mc/rm-outgoing-logs
iAmMichaelConnor Dec 9, 2024
82dfe28
nasty debug metadata bug
iAmMichaelConnor Dec 9, 2024
c51ec33
yarn format
iAmMichaelConnor Dec 9, 2024
6d1ddf1
nargo fmt
iAmMichaelConnor Dec 9, 2024
541eb2c
merge
iAmMichaelConnor Dec 9, 2024
99511b7
handle debug symbols error
iAmMichaelConnor Dec 9, 2024
61cd844
yarn format
iAmMichaelConnor Dec 9, 2024
f11c6e0
Merge branch 'master' into mc/rm-outgoing-logs
iAmMichaelConnor Dec 9, 2024
d54f55b
bump e2e block building timeout to 10 mins
iAmMichaelConnor Dec 9, 2024
e608c51
tidy nr debug logs
iAmMichaelConnor Dec 9, 2024
7ee81fb
yarn format
iAmMichaelConnor Dec 9, 2024
035b8b9
tidy
iAmMichaelConnor Dec 9, 2024
db4ede9
merge
iAmMichaelConnor Dec 9, 2024
5967e0b
rm unused debug log imports
iAmMichaelConnor Dec 9, 2024
af9a640
migration notes
iAmMichaelConnor Dec 9, 2024
9eb091c
fix
iAmMichaelConnor Dec 9, 2024
dd40f21
up settimeout
iAmMichaelConnor Dec 10, 2024
8fe7102
Update yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_p…
iAmMichaelConnor Dec 10, 2024
8bcd944
Update noir-projects/aztec-nr/aztec/src/context/private_context.nr
iAmMichaelConnor Dec 10, 2024
691064c
extra migration note
iAmMichaelConnor Dec 10, 2024
ea5fff4
impl review comments
iAmMichaelConnor Dec 10, 2024
ab34ead
merge
iAmMichaelConnor Dec 10, 2024
7bfa2f8
Merge branch 'master' into mc/rm-outgoing-logs
iAmMichaelConnor Dec 10, 2024
b9277a1
revert removal of dummy fn, as it did break something, and it unrelat…
iAmMichaelConnor Dec 10, 2024
c4f4881
Merge branch 'master' into mc/rm-outgoing-logs
iAmMichaelConnor Dec 10, 2024
2369af0
Merge branch 'master' into mc/rm-outgoing-logs
iAmMichaelConnor Dec 10, 2024
ef38723
Merge branch 'master' into mc/rm-outgoing-logs
benesjan Dec 10, 2024
97b02ec
Merge branch 'master' into mc/rm-outgoing-logs
benesjan Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions boxes/boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ contract BoxReact {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender()));
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner, context.msg_sender()));
}

#[private]
Expand All @@ -37,8 +36,7 @@ contract BoxReact {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender()));
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner, context.msg_sender()));
}

unconstrained fn getNumber(owner: AztecAddress) -> pub ValueNote {
Expand Down
6 changes: 2 additions & 4 deletions boxes/boxes/vanilla/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ contract Vanilla {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender()));
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner, context.msg_sender()));
}

#[private]
Expand All @@ -37,8 +36,7 @@ contract Vanilla {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender()));
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner, context.msg_sender()));
}

unconstrained fn getNumber(owner: AztecAddress) -> pub ValueNote {
Expand Down
18 changes: 18 additions & 0 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use dep::protocol_types::debug_log::{debug_log, debug_log_format};
iAmMichaelConnor marked this conversation as resolved.
Show resolved Hide resolved

use crate::{
context::{inputs::PrivateContextInputs, packed_returns::PackedReturns},
hash::{ArgsHasher, hash_args_array},
Expand Down Expand Up @@ -136,7 +138,23 @@ impl PrivateContext {
}

pub fn push_note_hash(&mut self, note_hash: Field) {
// debug_log_format(
iAmMichaelConnor marked this conversation as resolved.
Show resolved Hide resolved
// "\n\nMIKE About to push new note hash: (note_hash:{0}, counter: {1})",
// [note_hash, (self.side_effect_counter - 1) as Field],
// );
self.note_hashes.push(NoteHash { value: note_hash, counter: self.next_counter() });
// debug_log("And just to make doubly sure, here is the context after pushing:");

// WARNING: if you delete this debug_log_format line, some tests fail. Be safe out there.
debug_log_format(
"\n\nMIKE context note hash values after pushing: {0}",
self.note_hashes.storage().map(|nh: NoteHash| nh.value),
);
iAmMichaelConnor marked this conversation as resolved.
Show resolved Hide resolved

// debug_log_format("\n\nMIKE context note hash counters after pushing: {0}", self.note_hashes.storage().map(|nh: NoteHash| nh.counter as Field));
// debug_log_format("\n\nMIKE - if you see a value here, the note hash is definitely in the context. self.note_hashes.storage()[0].value: {0}", [self.note_hashes.storage()[0].value]);
// debug_log_format("\n\nMIKE And in case I can't print arrays like I'm trying, here's the [0].value element: {0}", [self.note_hashes.get(0).value]);
// debug_log_format("\n\nMIKE And in case I can't print arrays like I'm trying, here's the [0].counter element: {0}", [self.note_hashes.get(0).counter as Field]);
}

pub fn push_nullifier(&mut self, nullifier: Field) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use crate::{
context::PrivateContext, encrypted_logs::payload::compute_private_log_payload,
event::event_interface::EventInterface, keys::getters::get_ovsk_app,
};
use dep::protocol_types::{
address::AztecAddress, constants::PRIVATE_LOG_SIZE_IN_FIELDS, public_keys::OvpkM,
event::event_interface::EventInterface,
};
use dep::protocol_types::{address::AztecAddress, constants::PRIVATE_LOG_SIZE_IN_FIELDS};

/// Computes private event log payload and a log hash
fn compute_payload<Event, let N: u32>(
context: PrivateContext,
event: Event,
ovsk_app: Field,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> [Field; PRIVATE_LOG_SIZE_IN_FIELDS]
Expand All @@ -21,60 +17,48 @@ where
let contract_address: AztecAddress = context.this_address();
let plaintext = event.to_be_bytes();

compute_private_log_payload(
contract_address,
ovsk_app,
ovpk,
recipient,
sender,
plaintext,
)
compute_private_log_payload(contract_address, recipient, sender, plaintext)
}

unconstrained fn compute_payload_unconstrained<Event, let N: u32>(
context: PrivateContext,
event: Event,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> [Field; PRIVATE_LOG_SIZE_IN_FIELDS]
where
Event: EventInterface<N>,
{
let ovsk_app = get_ovsk_app(ovpk.hash());
compute_payload(context, event, ovsk_app, ovpk, recipient, sender)
compute_payload(context, event, recipient, sender)
}

pub fn encode_and_encrypt_event<Event, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](Event) -> ()
) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](Event) -> ()
where
Event: EventInterface<N>,
{
|e: Event| {
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());
let encrypted_log = compute_payload(*context, e, ovsk_app, ovpk, recipient, sender);
let encrypted_log = compute_payload(*context, e, recipient, sender);
context.emit_private_log(encrypted_log);
}
}

pub fn encode_and_encrypt_event_unconstrained<Event, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](Event) -> ()
) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](Event) -> ()
where
Event: EventInterface<N>,
{
|e: Event| {
// Unconstrained logs have both their content and encryption unconstrained - it could occur that the
// recipient is unable to decrypt the payload.
let encrypted_log =
unsafe { compute_payload_unconstrained(*context, e, ovpk, recipient, sender) };
unsafe { compute_payload_unconstrained(*context, e, recipient, sender) };
context.emit_private_log(encrypted_log);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use dep::protocol_types::debug_log::{debug_log, debug_log_format};

use crate::{
context::PrivateContext,
encrypted_logs::payload::compute_private_log_payload,
keys::getters::get_ovsk_app,
note::{note_emission::NoteEmission, note_interface::NoteInterface},
};
use dep::protocol_types::{
abis::note_hash::NoteHash, address::AztecAddress, constants::PRIVATE_LOG_SIZE_IN_FIELDS,
public_keys::OvpkM,
};

/// Computes private note log payload
fn compute_payload<Note, let N: u32>(
context: PrivateContext,
note: Note,
ovsk_app: Field,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> ([Field; PRIVATE_LOG_SIZE_IN_FIELDS], u32)
Expand All @@ -25,6 +23,17 @@ where
let note_hash_counter = note_header.note_hash_counter;
let storage_slot = note_header.storage_slot;

// debug_log_format(
iAmMichaelConnor marked this conversation as resolved.
Show resolved Hide resolved
// "\n\nMIKE Looking for note: (note_hash_counter: {0}, storage_slot: {1})",
// [note_hash_counter as Field, storage_slot],
// );

debug_log_format(
"\n\nMIKE context note hash values: {0}",
context.note_hashes.storage().map(|nh: NoteHash| nh.value),
);
// debug_log_format("\n\nMIKE context note hash counters: {0}", context.note_hashes.storage().map(|nh: NoteHash| nh.counter as Field));

// TODO(#8589): use typesystem to skip this check when not needed
let note_exists =
context.note_hashes.storage().any(|n: NoteHash| n.counter == note_hash_counter);
Expand All @@ -34,61 +43,48 @@ where

let plaintext = note.to_be_bytes(storage_slot);

let payload = compute_private_log_payload(
contract_address,
ovsk_app,
ovpk,
recipient,
sender,
plaintext,
);
let payload = compute_private_log_payload(contract_address, recipient, sender, plaintext);

(payload, note_hash_counter)
}

unconstrained fn compute_payload_unconstrained<Note, let N: u32>(
context: PrivateContext,
note: Note,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> ([Field; PRIVATE_LOG_SIZE_IN_FIELDS], u32)
where
Note: NoteInterface<N>,
{
let ovsk_app = get_ovsk_app(ovpk.hash());
compute_payload(context, note, ovsk_app, ovpk, recipient, sender)
compute_payload(context, note, recipient, sender)
}

// This function seems to be affected by the following Noir bug:
// https://github.com/noir-lang/noir/issues/5771
// If you get weird behavior it might be because of it.
pub fn encode_and_encrypt_note<Note, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
recipient: AztecAddress,
// TODO: We need this because to compute a tagging secret, we require a sender. Should we have the tagging secret oracle take a ovpk_m as input instead of the address?
// We need this because to compute a tagging secret, we require a sender:
sender: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](NoteEmission<Note>) -> ()
) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission<Note>) -> ()
where
Note: NoteInterface<N>,
{
|e: NoteEmission<Note>| {
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());

let (encrypted_log, note_hash_counter) =
compute_payload(*context, e.note, ovsk_app, ovpk, recipient, sender);
compute_payload(*context, e.note, recipient, sender);
context.emit_raw_note_log(encrypted_log, note_hash_counter);
}
}

pub fn encode_and_encrypt_note_unconstrained<Note, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
recipient: AztecAddress,
// TODO: We need this because to compute a tagging secret, we require a sender. Should we have the tagging secret oracle take a ovpk_m as input instead of the address?
// We need this because to compute a tagging secret, we require a sender:
sender: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](NoteEmission<Note>) -> ()
) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission<Note>) -> ()
where
Note: NoteInterface<N>,
{
Expand All @@ -104,7 +100,7 @@ where
// return the log from this function to the app, otherwise it could try to do stuff with it and then that might
// be wrong.
let (encrypted_log, note_hash_counter) =
unsafe { compute_payload_unconstrained(*context, e.note, ovpk, recipient, sender) };
unsafe { compute_payload_unconstrained(*context, e.note, recipient, sender) };
context.emit_raw_note_log(encrypted_log, note_hash_counter);
}
}
Loading
Loading