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!: encrypted logs refactor #11400

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7336241
refactor encrypted logs stuff
iAmMichaelConnor Jan 17, 2025
ac59923
fix event log
iAmMichaelConnor Jan 22, 2025
e10f5ef
I found some annoying extra hard-coded stuff in the archiver
iAmMichaelConnor Jan 22, 2025
bdb8ee9
Merge branch 'master' into mc/potato-encode
iAmMichaelConnor Jan 22, 2025
9c24ef6
fixing that disgusting encoding
iAmMichaelConnor Jan 22, 2025
b1ea549
Merge branch 'mc/potato-encode' of github.com:AztecProtocol/aztec-pac…
iAmMichaelConnor Jan 22, 2025
5c73e0a
merge w/ master
iAmMichaelConnor Jan 22, 2025
0dc91be
nargo fmt
iAmMichaelConnor Jan 22, 2025
06ebdaf
rm unused big aes fn
iAmMichaelConnor Jan 22, 2025
07acaa5
nargo fmt
iAmMichaelConnor Jan 22, 2025
aa828ac
reinstate some tests and tidying
iAmMichaelConnor Jan 22, 2025
e4fb1e8
nargo fmt
iAmMichaelConnor Jan 22, 2025
b53fd6c
Merge branch 'master' into mc/potato-encode
iAmMichaelConnor Jan 22, 2025
82f5748
more hard-coded partial logs stuff in the memory archiver store
iAmMichaelConnor Jan 22, 2025
c33e819
a comment
iAmMichaelConnor Jan 23, 2025
db309e5
merge
iAmMichaelConnor Jan 23, 2025
8a4a88a
missing await
iAmMichaelConnor Jan 23, 2025
b609f4f
fix missed file txe_oracle
iAmMichaelConnor Jan 23, 2025
4b15d9f
put migration notes in the right place
iAmMichaelConnor Jan 23, 2025
3328c0c
address some poseidon2 encryption comments
iAmMichaelConnor Jan 23, 2025
f323884
revert debugging attempt
iAmMichaelConnor Jan 23, 2025
fdf9530
bytes.nr
iAmMichaelConnor Jan 23, 2025
42c409a
sqrt in field.nr
iAmMichaelConnor Jan 24, 2025
b610bb5
address review comments
iAmMichaelConnor Jan 24, 2025
7e93c6f
address shared secret derivation comments
iAmMichaelConnor Jan 24, 2025
033bd0e
rm poseidon2 encryption from this pr
iAmMichaelConnor Jan 24, 2025
bb6d3dc
stopping myself from renaming a thing
iAmMichaelConnor Jan 24, 2025
f746835
rm debug logs to my mum
iAmMichaelConnor Jan 24, 2025
f375643
fix tests
iAmMichaelConnor Jan 24, 2025
be4cb2f
merge w/ master
iAmMichaelConnor Jan 24, 2025
450ddd5
zeroed instead of [0; length]
iAmMichaelConnor Jan 24, 2025
b5225ef
revert that zeroed change, becuase the compiler didn't like it
iAmMichaelConnor Jan 24, 2025
99e5d04
Merge branch 'master' into mc/potato-encode
iAmMichaelConnor Jan 25, 2025
548c629
Merge branch 'master' into mc/potato-encode
iAmMichaelConnor Jan 25, 2025
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
2 changes: 1 addition & 1 deletion boxes/boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ contract BoxReact {
protocol_types::public_keys::OvpkM,
keys::getters::get_public_keys,
prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
encrypted_logs::log_assembly_strategies::default_aes128::note::encode_and_encrypt_note,
macros::{storage::storage, functions::{private, public, initializer}}
};
use dep::value_note::value_note::ValueNote;
Expand Down
2 changes: 1 addition & 1 deletion boxes/boxes/vanilla/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ contract Vanilla {
protocol_types::public_keys::OvpkM,
keys::getters::get_public_keys,
prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
encrypted_logs::log_assembly_strategies::default_aes128::note::encode_and_encrypt_note,
macros::{storage::storage, functions::{private, public, initializer}}
};
use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};
Expand Down
2 changes: 1 addition & 1 deletion boxes/boxes/vite/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dep::aztec::macros::aztec;
#[aztec]
contract BoxReact {
use dep::aztec::{
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
encrypted_logs::log_assembly_strategies::default_aes128::note::encode_and_encrypt_note,
macros::{functions::{initializer, private}, storage::storage},
prelude::{AztecAddress, Map, PrivateMutable},
};
Expand Down
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"dockerized",
"doesnt",
"dont",
"ecdh",
"elif",
"enrs",
"entrypoints",
Expand Down Expand Up @@ -281,6 +282,7 @@
"unexcluded",
"unfinalised",
"unnullify",
"unpadded",
"unprefixed",
"unshift",
"unshifted",
Expand Down
13 changes: 13 additions & 0 deletions docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ impl Packable<U128_PACKED_LEN> for U128 {
}
```

### Logs for notes, partial notes, and events have been refactored.

We're preparing to make log assembly more customisable. These paths have changed.
```diff
- use dep::aztec::encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
+ use dep::aztec::encrypted_logs::log_assembly_strategies::default_aes128::note::encode_and_encrypt_note,
```

And similar paths for `encode_and_encrypt_note_unconstrained`, and for events and partial notes.

The way in which logs are assembled in this "default_aes128" strategy is has also changed. I repeat: **Encrypted log layouts have changed**. The corresponding typescript for note discovery has also been changed, but if you've rolled your own functions for parsing and decrypting logs, those will be broken by this change.


## 0.72.0
### Some functions in `aztec.js` and `@aztec/accounts` are now async
In our efforts to make libraries more browser-friendly and providing with more bundling options for `bb.js` (like a non top-level-await version), some functions are being made async, in particular those that access our cryptographic functions.
Expand Down
76 changes: 76 additions & 0 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypt/aes128.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use std::hash::{from_field_unsafe as fr_to_fq_unsafe, sha256};

use dep::protocol_types::{
constants::{GENERATOR_INDEX__SYMMETRIC_KEY, GENERATOR_INDEX__SYMMETRIC_KEY_2},
hash::poseidon2_hash_with_separator,
point::Point,
};

use crate::utils::point::point_to_bytes;

fn extract_close_to_uniformly_random_256_bits_from_ecdh_shared_secret_using_poseidon2(
shared_secret: Point,
) -> [u8; 32] {
let rand1: Field = poseidon2_hash_with_separator(
[shared_secret.x, shared_secret.y],
GENERATOR_INDEX__SYMMETRIC_KEY,
);
let rand2: Field = poseidon2_hash_with_separator(
[shared_secret.x, shared_secret.y],
GENERATOR_INDEX__SYMMETRIC_KEY_2,
);
let rand1_bytes: [u8; 16] = rand1.to_le_bytes();
let rand2_bytes: [u8; 16] = rand2.to_le_bytes();
let mut bytes: [u8; 32] = [0; 32];
for i in 0..16 {
bytes[i] = rand1_bytes[i];
bytes[i + 1] = rand2_bytes[i];
}
bytes
}

fn extract_close_to_uniformly_random_256_bits_from_ecdh_shared_secret_using_sha256(
shared_secret: Point,
) -> [u8; 32] {
let shared_secret_bytes: [u8; 32] = point_to_bytes(shared_secret);

let mut shared_secret_bytes_with_separator: [u8; 33] = std::mem::zeroed();
for i in 0..shared_secret_bytes.len() {
shared_secret_bytes_with_separator[i] = shared_secret_bytes[i];
}
shared_secret_bytes_with_separator[32] = GENERATOR_INDEX__SYMMETRIC_KEY;

sha256(shared_secret_bytes_with_separator)
}

fn derive_aes_symmetric_key_and_iv_from_ecdh_shared_secret(
shared_secret: Point,
randomness_extraction_fn: fn(Point) -> [u8; 32],
) -> ([u8; 16], [u8; 16]) {
let random_256_bits = randomness_extraction_fn(shared_secret);
let mut sym_key = [0; 16];
let mut iv = [0; 16];
for i in 0..16 {
sym_key[i] = random_256_bits[i];
iv[i] = random_256_bits[i + 16];
}
(sym_key, iv)
}

pub fn derive_aes_symmetric_key_and_iv_from_ecdh_shared_secret_using_sha256(
shared_secret: Point,
) -> ([u8; 16], [u8; 16]) {
derive_aes_symmetric_key_and_iv_from_ecdh_shared_secret(
shared_secret,
extract_close_to_uniformly_random_256_bits_from_ecdh_shared_secret_using_sha256,
)
}

pub fn derive_aes_symmetric_key_and_iv_from_ecdh_shared_secret_using_poseidon2(
shared_secret: Point,
) -> ([u8; 16], [u8; 16]) {
derive_aes_symmetric_key_and_iv_from_ecdh_shared_secret(
shared_secret,
extract_close_to_uniformly_random_256_bits_from_ecdh_shared_secret_using_poseidon2,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod aes128;

This file was deleted.

This file was deleted.

66 changes: 0 additions & 66 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr

This file was deleted.

Loading
Loading