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 30 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
23 changes: 23 additions & 0 deletions docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ The `Header` struct has been renamed to `BlockHeader`, and the `get_header()` fa
+ let header = context.get_block_header_at(block_number);
```

### Outgoing Events removed

Previously, every event which was emitted included:
- Incoming Header (to convey the app contract address to the recipient)
- Incoming Ciphertext (to convey the note contents to the recipient)
- Outgoing Header (served as a backup, to convey the app contract address to the "outgoing viewer" - most likely the sender)
- Outgoing Ciphertext (served as a backup, encrypting the summetric key of the incoming ciphertext to the "outgoing viewer" - most likely the sender)

The latter two have been removed from the `.emit()` function, so now only an Incoming Header and Incoming Ciphertext will be emitted.

The interface for emitting a note has therefore changed, slightly. No more ovpk's and ovsk's need to be derived for the `.emit()` function.

```diff
- nfts.at(to).insert(&mut new_note).emit(encode_and_encrypt_note(&mut context, from_ovpk_m, to, from));
+ nfts.at(to).insert(&mut new_note).emit(encode_and_encrypt_note(&mut context, to, from));
```

The `getOutgoingNotes` function is removed from the PXE interface.

Further changes are planned, so that:
- Outgoing ciphertexts (or any kind of abstract ciphertext) can be emitted by a contract, and on the other side discovered and then processed by the contract.
- Headers will be removed, due to the new tagging scheme.

## 0.66

### DEBUG env var is removed
Expand Down
8 changes: 8 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 @@ -137,6 +139,12 @@ impl PrivateContext {

pub fn push_note_hash(&mut self, note_hash: Field) {
self.note_hashes.push(NoteHash { value: note_hash, counter: self.next_counter() });

// WARNING(https://github.com/AztecProtocol/aztec-packages/issues/10558): if you delete this debug_log_format line, some tests fail.
debug_log_format(
"Context.note_hashes, after pushing new note hash: {0}",
self.note_hashes.storage().map(|nh: NoteHash| nh.value),
);
nventuro marked this conversation as resolved.
Show resolved Hide resolved
}

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,16 @@
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 @@ -34,61 +30,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 +87,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