Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
bfbea44
feat: storage slot as point
benesjan Jul 11, 2024
eb7db3e
WIP
benesjan Jul 11, 2024
13cbbbe
WIP
benesjan Jul 12, 2024
c11bf02
WIP
benesjan Jul 17, 2024
4b076c4
WIP
benesjan Jul 17, 2024
7427dc4
WIP
benesjan Jul 17, 2024
be60f53
clarified comment
benesjan Jul 17, 2024
ed6508a
WIP
benesjan Jul 18, 2024
b58e195
WIP
benesjan Jul 18, 2024
7cda71d
WIP
benesjan Jul 18, 2024
a159eac
WIP
benesjan Jul 18, 2024
816a427
WIP
benesjan Jul 18, 2024
ed8599d
WIP on updating macros
benesjan Jul 18, 2024
6a5bbb5
fixed aztec-nr
benesjan Jul 18, 2024
923da4d
Grego's changes
benesjan Jul 18, 2024
ba3d005
fix macro
Thunkar Jul 18, 2024
358f964
WIP
benesjan Jul 19, 2024
4af5e33
WIP
benesjan Jul 19, 2024
e9bb0bd
not using pedersen commitment
benesjan Jul 19, 2024
daf472d
WIP
benesjan Jul 19, 2024
8ca8020
WIP
benesjan Jul 19, 2024
d168d0e
WIP
benesjan Jul 19, 2024
ff2f862
WIP
benesjan Jul 19, 2024
4ef52e5
WIP
benesjan Jul 19, 2024
912b9b4
docs fix
benesjan Jul 22, 2024
3fd0adf
fix
benesjan Jul 22, 2024
1fcb939
WIP
benesjan Jul 22, 2024
21e55bc
WIP
benesjan Jul 22, 2024
9413e09
moving generators and slots
benesjan Jul 22, 2024
713be3a
cleanup
benesjan Jul 22, 2024
086f6c2
updated snaps + fix
benesjan Jul 22, 2024
a2d8683
fixes simulator test
benesjan Jul 22, 2024
8b113ed
fix private exec test
benesjan Jul 22, 2024
0157943
fixed simulator tests
benesjan Jul 22, 2024
8e4b1fb
updated protocol contracts constants
benesjan Jul 22, 2024
ca50c0b
disabled problematic part of base rollup code
benesjan Jul 22, 2024
86d29d6
e2e 2 pxes test fix
benesjan Jul 22, 2024
54acbd9
reverting unintended change
benesjan Jul 22, 2024
b858f15
linter fix
benesjan Jul 22, 2024
dc13b3f
fixes and cleanup
benesjan Jul 22, 2024
be665bc
Update noir-projects/aztec-nr/aztec/src/utils/point.nr
benesjan Jul 23, 2024
d838441
test comments
benesjan Jul 23, 2024
c3b01b5
more todos
benesjan Jul 23, 2024
2d2953b
naming issue
benesjan Jul 23, 2024
e5733b3
fmt fix
benesjan Jul 23, 2024
53c98d0
nuked test2 contract
benesjan Jul 23, 2024
d1a3fa5
linking issue #7515
benesjan Jul 23, 2024
fb91c2b
clarifying why Serialize trait for header
benesjan Jul 23, 2024
d2de32f
more todos
benesjan Jul 23, 2024
803048a
naming fix
benesjan Jul 23, 2024
ee6dff3
key registry test fix
benesjan Jul 23, 2024
6589273
fixed e2e_crowdfunding
benesjan Jul 23, 2024
ea6e430
fixed e2e_account
benesjan Jul 23, 2024
98a12f5
fixed private voting test
benesjan Jul 23, 2024
400cf29
naming fixes
benesjan Jul 23, 2024
3c7f6d6
storing contract storage index in public state vars and not slot
benesjan Jul 24, 2024
eeb0298
moving INITIALIZATION_CONTRACT_STORAGE_INDEX_SEPARATOR to slots.nr
benesjan Jul 24, 2024
786ebeb
map slot test
benesjan Jul 24, 2024
c228b0e
better comments
benesjan Jul 24, 2024
4d461bf
fixed cheatcodes test
benesjan Jul 24, 2024
8c05fb3
fixed e2e_nested test
benesjan Jul 24, 2024
279bf54
fixed e2e_ordering
benesjan Jul 24, 2024
e3be48b
WIP
benesjan Jul 24, 2024
4feccfd
fixed e2e_nested
benesjan Jul 24, 2024
48cbe9c
updated test comment
benesjan Jul 24, 2024
691f05f
fix
benesjan Jul 24, 2024
93d28f2
stale import
benesjan Jul 25, 2024
c0261fb
verification key issue workaround
benesjan Jul 25, 2024
41166b2
fixed browser test
benesjan Jul 25, 2024
0797eb0
optimization
benesjan Jul 25, 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
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ struct CustomNote {
}
```

### After expansaion
### After expansion

```rust
impl CustomNote {
Expand Down Expand Up @@ -255,13 +255,12 @@ impl CustomNote {
)
}

fn to_be_bytes(self, storage_slot: Field) -> [u8; 128] {
assert(128 == 2 * 32 + 64, "Note byte length must be equal to (serialized_length * 32) + 64 bytes");
fn to_be_bytes(self, storage_slot: Point) -> [u8; CUSTOM_NOTE_BYTES_LEN] {
let serialized_note = self.serialize_content();

let mut buffer: [u8; 128] = [0; 128];
let mut buffer: [u8; CUSTOM_NOTE_BYTES_LEN] = [0; CUSTOM_NOTE_BYTES_LEN];

let storage_slot_bytes = storage_slot.to_be_bytes(32);
let storage_slot_bytes = point_to_bytes(storage_slot);
let note_type_id_bytes = CustomNote::get_note_type_id().to_be_bytes(32);

for i in 0..32 {
Expand Down
11 changes: 5 additions & 6 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ library Constants {
uint256 internal constant ARGS_HASH_CHUNK_LENGTH = 16;
uint256 internal constant ARGS_HASH_CHUNK_COUNT = 16;
uint256 internal constant MAX_ARGS_LENGTH = 256;
uint256 internal constant INITIALIZATION_SLOT_SEPARATOR = 1000000000;
uint256 internal constant INITIAL_L2_BLOCK_NUM = 1;
uint256 internal constant BLOB_SIZE_IN_BYTES = 126976;
uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 20000;
Expand Down Expand Up @@ -124,15 +123,15 @@ library Constants {
uint256 internal constant L2_GAS_PER_NOTE_HASH = 32;
uint256 internal constant L2_GAS_PER_NULLIFIER = 64;
uint256 internal constant CANONICAL_KEY_REGISTRY_ADDRESS =
2153455745675440165069577621832684870696142028027528497509357256345838682961;
21002604897410093708477100201638914385100863925743623823186725421598769862581;
uint256 internal constant CANONICAL_AUTH_REGISTRY_ADDRESS =
18091885756106795278141309801070173692350235742979924147720536894670507925831;
18844197343959337477226781811009542647774288930267535903153059057819715808176;
uint256 internal constant DEPLOYER_CONTRACT_ADDRESS =
19511485909966796736993840362353440247573331327062358513665772226446629198132;
3077749756291741958160703262435693846649629333047756518291243914166007507388;
uint256 internal constant REGISTERER_CONTRACT_ADDRESS =
13402924717071282069537366635406026232165444473509746327951838324587448220160;
9106537597827539209583757446796074130561720707558015678434966723134574857086;
uint256 internal constant GAS_TOKEN_ADDRESS =
3159976153131520272419617514531889581796079438158800470341967144801191524489;
18052122229623850597530611627473354790534583502914175510126040829737657095769;
uint256 internal constant AZTEC_ADDRESS_LENGTH = 1;
uint256 internal constant GAS_FEES_LENGTH = 2;
uint256 internal constant GAS_LENGTH = 2;
Expand Down
41 changes: 27 additions & 14 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,27 @@ impl PublicContext {
da_gas_left()
}

fn raw_storage_read<let N: u32>(_self: Self, storage_slot: Field) -> [Field; N] {
storage_read(storage_slot)
fn raw_storage_read<let N: u32>(_self: Self, contract_storage_index: Field) -> [Field; N] {
storage_read(contract_storage_index)
}

fn storage_read<T, let N: u32>(self, storage_slot: Field) -> T where T: Deserialize<N> {
T::deserialize(self.raw_storage_read(storage_slot))
fn storage_read<T, let N: u32>(
self,
contract_storage_index: Field
) -> T where T: Deserialize<N> {
T::deserialize(self.raw_storage_read(contract_storage_index))
}

fn raw_storage_write<let N: u32>(_self: Self, storage_slot: Field, values: [Field; N]) {
storage_write(storage_slot, values);
fn raw_storage_write<let N: u32>(_self: Self, contract_storage_index: Field, values: [Field; N]) {
storage_write(contract_storage_index, values);
}

fn storage_write<T, let N: u32>(self, storage_slot: Field, value: T) where T: Serialize<N> {
self.raw_storage_write(storage_slot, value.serialize());
fn storage_write<T, let N: u32>(
self,
contract_storage_index: Field,
value: T
) where T: Serialize<N> {
self.raw_storage_write(contract_storage_index, value.serialize());
}
}

Expand Down Expand Up @@ -274,12 +281,12 @@ unconstrained fn call_static<let RET_SIZE: u32>(
call_static_opcode(gas, address, args, function_selector)
}

unconstrained fn storage_read<let N: u32>(storage_slot: Field) -> [Field; N] {
storage_read_opcode(storage_slot, N as Field)
unconstrained fn storage_read<let N: u32>(contract_storage_index: Field) -> [Field; N] {
storage_read_opcode(contract_storage_index, N as Field)
}

unconstrained fn storage_write<let N: u32>(storage_slot: Field, values: [Field; N]) {
storage_write_opcode(storage_slot, values);
unconstrained fn storage_write<let N: u32>(contract_storage_index: Field, values: [Field; N]) {
storage_write_opcode(contract_storage_index, values);
}

impl Empty for PublicContext {
Expand Down Expand Up @@ -373,10 +380,16 @@ unconstrained fn call_static_opcode<let RET_SIZE: u32>(
// ^ return data ^ success

#[oracle(avmOpcodeStorageRead)]
unconstrained fn storage_read_opcode<let N: u32>(storage_slot: Field, length: Field) -> [Field; N] {}
unconstrained fn storage_read_opcode<let N: u32>(
contract_storage_index: Field,
length: Field
) -> [Field; N] {}

#[oracle(avmOpcodeStorageWrite)]
unconstrained fn storage_write_opcode<let N: u32>(storage_slot: Field, values: [Field; N]) {}
unconstrained fn storage_write_opcode<let N: u32>(
contract_storage_index: Field,
values: [Field; N]
) {}

struct FunctionReturns<let N: u32> {
values: [Field; N]
Expand Down
15 changes: 11 additions & 4 deletions noir-projects/aztec-nr/aztec/src/context/unconstrained_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,21 @@ impl UnconstrainedContext {
self.chain_id
}

unconstrained fn raw_storage_read<let N: u32>(self: Self, storage_slot: Field) -> [Field; N] {
storage_read(self.this_address(), storage_slot, self.block_number())
unconstrained fn raw_storage_read<let N: u32>(
self: Self,
contract_storage_index: Field
) -> [Field; N] {
storage_read(
self.this_address(),
contract_storage_index,
self.block_number()
)
}

unconstrained fn storage_read<T, let N: u32>(
self,
storage_slot: Field
contract_storage_index: Field
) -> T where T: Deserialize<N> {
T::deserialize(self.raw_storage_read(storage_slot))
T::deserialize(self.raw_storage_read(contract_storage_index))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use dep::protocol_types::{

unconstrained fn compute_unconstrained<Note, let N: u32, let NB: u32, let M: u32>(
contract_address: AztecAddress,
storage_slot: Field,
storage_slot: Point,
ovsk_app: Field,
ovpk: Point,
ivpk: Point,
Expand All @@ -29,7 +29,7 @@ unconstrained fn compute_unconstrained<Note, let N: u32, let NB: u32, let M: u32

fn compute<Note, let N: u32, let NB: u32, let M: u32>(
contract_address: AztecAddress,
storage_slot: Field,
storage_slot: Point,
ovsk_app: Field,
ovpk: Point,
ivpk: Point,
Expand All @@ -55,7 +55,7 @@ fn emit_with_keys<Note, let N: u32, let NB: u32, let M: u32>(
ovpk: Point,
ivpk: Point,
recipient: AztecAddress,
inner_compute: fn(AztecAddress, Field, Field, Point, Point, AztecAddress, Note) -> ([u8; M], Field)
inner_compute: fn(AztecAddress, Point, Field, Point, Point, AztecAddress, Note) -> ([u8; M], Field)
) where Note: NoteInterface<N, NB>, [Field; N]: LensForEncryptedLog<N, M> {
let note_header = note.get_header();
let note_hash_counter = note_header.note_hash_counter;
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn test_encrypted_log_header() {
let ciphertext = header.compute_ciphertext(secret, point);

let expected_header_ciphertext = [
166, 212, 106, 246, 139, 59, 228, 9, 133, 152, 127, 172, 141, 166, 237, 199, 55, 203, 226, 19, 114, 103, 58, 237, 108, 231, 35, 198, 54, 61, 190, 255, 241, 225, 151, 180, 6, 163, 124, 27, 151, 78, 237, 65, 120, 106, 255, 236
226, 240, 253, 6, 28, 52, 19, 131, 33, 132, 178, 212, 245, 62, 14, 190, 194, 44, 7, 131, 160, 83, 64, 181, 98, 38, 153, 214, 62, 171, 253, 161, 111, 191, 28, 247, 216, 26, 222, 171, 176, 218, 48, 209, 73, 89, 200, 209
];

assert_eq(ciphertext, expected_header_ciphertext);
Expand Down
56 changes: 36 additions & 20 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct EncryptedLogIncomingBody<let M: u32> {
}

impl<let M: u32> EncryptedLogIncomingBody<M> {
pub fn from_note<T, let N: u32>(note: T, storage_slot: Field) -> Self where T: NoteInterface<N, M> {
pub fn from_note<T, let N: u32>(note: T, storage_slot: Point) -> Self where T: NoteInterface<N, M> {
let mut plaintext = note.to_be_bytes(storage_slot);
EncryptedLogIncomingBody { plaintext }
}
Expand All @@ -37,16 +37,16 @@ impl<let M: u32> EncryptedLogIncomingBody<M> {
}

mod test {
use crate::encrypted_logs::incoming_body::EncryptedLogIncomingBody;
use dep::protocol_types::{
address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER,
scalar::Scalar, point::Point, traits::Serialize, abis::event_selector::EventSelector
scalar::Scalar, point::Point, traits::Serialize, generators::Ga1,
abis::event_selector::EventSelector
};

use crate::{
note::{note_header::NoteHeader, note_interface::NoteInterface},
event::event_interface::EventInterface, oracle::unsafe_rand::unsafe_rand,
context::PrivateContext
encrypted_logs::incoming_body::EncryptedLogIncomingBody, event::event_interface::EventInterface,
oracle::unsafe_rand::unsafe_rand, context::PrivateContext, utils::point::point_to_bytes
};

struct AddressNote {
Expand All @@ -60,7 +60,9 @@ mod test {
global ADDRESS_NOTE_BYTES_LEN = 32 * 3 + 64;

impl NoteInterface<ADDRESS_NOTE_LEN, ADDRESS_NOTE_BYTES_LEN> for AddressNote {
fn compute_note_content_hash(_self: Self) -> Field {1}
fn compute_note_content_hash(self) -> Point {
Ga1
}

fn get_note_type_id() -> Field {
1
Expand All @@ -82,12 +84,12 @@ mod test {
AddressNote { address: AztecAddress::from_field(fields[0]), owner: AztecAddress::from_field(fields[1]), randomness: fields[2], header: NoteHeader::empty() }
}

fn to_be_bytes(self, storage_slot: Field) -> [u8; ADDRESS_NOTE_BYTES_LEN] {
fn to_be_bytes(self, storage_slot: Point) -> [u8; ADDRESS_NOTE_BYTES_LEN] {
let serialized_note = self.serialize_content();

let mut buffer: [u8; ADDRESS_NOTE_BYTES_LEN] = [0; ADDRESS_NOTE_BYTES_LEN];

let storage_slot_bytes = storage_slot.to_be_bytes(32);
let storage_slot_bytes = point_to_bytes(storage_slot);
let note_type_id_bytes = AddressNote::get_note_type_id().to_be_bytes(32);

for i in 0..32 {
Expand All @@ -112,14 +114,19 @@ mod test {
}

#[test]
fn test_encrypted_note_log_incoming_body() {
fn test_encrypted_note_log_incoming_body_matches_typescript() {
// All the values in this test were copied over from `encrypted_note_log_incoming_body.test.ts`
let note = AddressNote::new(
AztecAddress::from_field(0x1),
AztecAddress::from_field(0x2),
3
);

let storage_slot = 2;
let storage_slot = Point {
x: 0x1d83b1af3f569775af9e3fdae19b84590245098f46d4a407b5963f313000ce37,
y: 0x1537c632779932ccbc415d91dd70801f88ad410fff48179886d3dce035582d76,
is_infinite: false
};

let eph_sk = Scalar {
lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd,
Expand All @@ -131,18 +138,25 @@ mod test {
is_infinite: false
};

/// 1. `EncryptedLogIncomingBody::from_note` calls `note.to_be_bytes(storage_slot)` function which serializes
/// the note to bytes - note that in the case of `AddressNote` the `to_be_bytes` function was automatically
/// implemented by Aztec macros.
let body = EncryptedLogIncomingBody::from_note(note, storage_slot);

/// 2. `body.compute_ciphertext(...)` function then derives symmetric key from `eph_sk` and `ivpk` and encrypts
// the note plaintext using AES-128.
let ciphertext = body.compute_ciphertext(eph_sk, ivpk);

let expected_note_body_ciphertext = [
166, 212, 106, 246, 139, 59, 228, 9, 133, 152, 127, 172, 141, 166, 237, 199, 195, 85, 255, 81, 66, 72, 192, 192, 96, 10, 54, 139, 136, 153, 252, 114, 248, 128, 253, 66, 249, 16, 71, 45, 2, 213, 250, 193, 241, 75, 90, 70, 39, 26, 104, 139, 20, 45, 1, 1, 166, 72, 133, 55, 247, 142, 150, 215, 217, 224, 84, 23, 245, 71, 207, 166, 136, 34, 221, 76, 90, 166, 44, 217, 246, 98, 157, 34, 198, 164, 99, 117, 15, 185, 145, 231, 189, 140, 201, 241, 135, 94, 71, 131, 156, 86, 144, 131, 248, 242, 83, 101, 18, 189, 1, 94, 25, 238, 76, 106, 85, 205, 4, 70, 21, 9, 64, 63, 27, 164, 73, 181, 75, 199, 86, 255, 105, 239, 216, 34, 217, 184, 154, 76, 67, 1, 210, 251, 23, 185, 114, 146, 195, 28, 76, 219, 150, 175, 37, 76, 144, 227, 99, 243, 123, 161, 66, 171, 148, 181, 162, 2, 196, 53, 207, 154, 114, 166, 155, 166
// The following value was generated by `encrypted_note_log_incoming_body.test.ts`.
// --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
let note_body_ciphertext_from_typescript = [
75, 3, 86, 165, 50, 163, 229, 200, 67, 137, 31, 92, 122, 27, 14, 158, 201, 248, 29, 236, 102, 216, 246, 64, 166, 1, 166, 221, 92, 19, 78, 19, 213, 197, 44, 130, 105, 145, 239, 139, 176, 255, 148, 41, 72, 212, 75, 176, 216, 99, 170, 9, 151, 25, 135, 140, 53, 123, 253, 52, 119, 14, 65, 131, 127, 177, 227, 219, 157, 38, 90, 161, 32, 7, 27, 138, 152, 196, 60, 240, 106, 73, 121, 227, 190, 14, 142, 61, 119, 47, 201, 29, 250, 68, 53, 62, 200, 33, 207, 190, 156, 84, 9, 115, 122, 14, 147, 171, 83, 111, 2, 140, 9, 33, 33, 30, 65, 242, 133, 134, 59, 254, 202, 2, 237, 246, 68, 153, 62, 237, 123, 90, 169, 84, 62, 55, 214, 102, 26, 79, 209, 175, 255, 223, 110, 6, 119, 61, 142, 36, 81, 155, 0, 178, 60, 85, 120, 152, 177, 115, 14, 62, 105, 42, 178, 231, 173, 245, 88, 245, 89, 122, 32, 49, 205, 151
];

assert_eq(expected_note_body_ciphertext.len(), ciphertext.len());
assert_eq(note_body_ciphertext_from_typescript.len(), ciphertext.len());

for i in 0..expected_note_body_ciphertext.len() {
assert_eq(ciphertext[i], expected_note_body_ciphertext[i]);
for i in 0..note_body_ciphertext_from_typescript.len() {
assert_eq(ciphertext[i], note_body_ciphertext_from_typescript[i]);
}
}

Expand Down Expand Up @@ -237,14 +251,16 @@ mod test {

let ciphertext = body.compute_ciphertext(eph_sk, ivpk);

let expected_event_body_ciphertext = [
166, 212, 106, 246, 139, 59, 228, 9, 133, 152, 127, 172, 141, 166, 237, 199, 195, 85, 255, 81, 66, 72, 192, 192, 96, 10, 54, 139, 136, 153, 252, 114, 248, 128, 253, 66, 249, 16, 71, 45, 2, 213, 250, 193, 241, 75, 90, 70, 19, 153, 62, 117, 71, 55, 48, 114, 160, 232, 97, 118, 93, 53, 145, 92, 0, 225, 51, 81, 156, 69, 72, 224, 10, 89, 32, 121, 167, 197, 84, 245, 188, 235, 143, 202, 179, 197, 164, 121, 11, 105, 116, 239, 46, 222, 50, 138, 112, 237, 97, 8, 176, 199, 1, 151, 89, 218, 60, 45, 91, 85, 16, 38, 195, 127, 157, 182, 0, 10, 232, 184, 148, 76, 244, 63, 40, 222, 219, 139, 236, 169, 213, 17, 32, 210, 50, 6, 5, 83, 80, 1, 111, 246, 197, 83, 166, 71, 31, 246, 234, 75, 12, 151, 227, 247, 143, 229, 95, 219, 159, 75, 174, 232, 64, 7, 102, 76, 207, 45, 143, 208, 101, 113, 175, 37, 83, 166
// The following value was generated by `encrypted_event_log_incoming_body.test.ts`
// --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
let event_body_ciphertext_from_typescript = [
226, 240, 253, 6, 28, 52, 19, 131, 33, 132, 178, 212, 245, 62, 14, 190, 147, 228, 160, 190, 146, 61, 95, 203, 124, 153, 68, 168, 17, 150, 92, 0, 99, 214, 85, 64, 191, 78, 157, 131, 149, 96, 236, 253, 96, 172, 157, 30, 185, 29, 14, 152, 216, 130, 219, 151, 80, 185, 43, 223, 167, 8, 89, 189, 88, 188, 101, 137, 255, 136, 84, 252, 79, 18, 52, 3, 110, 54, 54, 206, 244, 209, 246, 226, 207, 247, 143, 253, 211, 75, 160, 224, 172, 41, 45, 7, 208, 137, 90, 56, 59, 4, 234, 48, 53, 23, 130, 230, 49, 249, 142, 243, 170, 72, 183, 242, 49, 124, 46, 52, 198, 75, 55, 102, 56, 89, 254, 67, 59, 157, 249, 120, 184, 67, 154, 16, 148, 227, 93, 37, 120, 199, 93, 166, 80, 127, 173, 52, 80, 135, 87, 1, 168, 164, 51, 48, 126, 120, 47, 102, 211, 227, 234, 170, 208, 99, 111, 198, 170, 226, 156, 244, 241, 174, 206, 30
];

assert_eq(expected_event_body_ciphertext.len(), ciphertext.len());
assert_eq(event_body_ciphertext_from_typescript.len(), ciphertext.len());

for i in 0..expected_event_body_ciphertext.len() {
assert_eq(ciphertext[i], expected_event_body_ciphertext[i]);
for i in 0..event_body_ciphertext_from_typescript.len() {
assert_eq(ciphertext[i], event_body_ciphertext_from_typescript[i]);
}
}
}
16 changes: 10 additions & 6 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ impl EncryptedLogOutgoingBody {
Self { eph_sk, recipient, recipient_ivpk }
}

/// Encrypts ephemeral secret key and recipient's ivpk --> with this information the recipient of outgoing will
/// be able to derive the key with which the incoming log can be decrypted.
pub fn compute_ciphertext(self, ovsk_app: Scalar, eph_pk: Point) -> [u8; 144] {
// Again, we could compute `eph_pk` here, but we keep the interface more similar
// and also make it easier to optimise it later as we just pass it along
Expand Down Expand Up @@ -68,7 +70,7 @@ mod test {
use crate::context::PrivateContext;

#[test]
fn test_encrypted_log_outgoing_body() {
fn test_encrypted_log_outgoing_body_matches_typescript() {
let eph_sk = Scalar {
lo: 0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe,
hi: 0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb
Expand All @@ -91,13 +93,15 @@ mod test {

let ciphertext = body.compute_ciphertext(sender_ovsk_app, eph_pk);

let expected_outgoing_body_ciphertext = [
127, 84, 96, 176, 101, 107, 236, 57, 68, 8, 53, 202, 138, 74, 186, 54, 74, 193, 245, 7, 109, 59, 218, 33, 1, 31, 205, 225, 241, 209, 64, 222, 94, 245, 4, 150, 47, 241, 187, 64, 152, 20, 102, 158, 200, 217, 213, 82, 1, 240, 170, 185, 51, 80, 27, 109, 63, 231, 235, 120, 174, 44, 133, 248, 10, 97, 60, 40, 222, 190, 147, 76, 187, 48, 91, 206, 48, 106, 56, 118, 38, 127, 82, 4, 182, 188, 44, 224, 31, 129, 47, 107, 134, 252, 20, 25, 249, 193, 215, 137, 195, 43, 98, 42, 54, 96, 254, 89, 134, 31, 103, 142, 16, 43, 92, 211, 145, 113, 217, 253, 161, 240, 121, 205, 146, 200, 168, 160, 221, 32, 229, 116, 26, 216, 86, 189, 78, 120, 10, 224, 85, 52, 40, 244
// The following value was generated by `encrypted_log_outgoing_body.test.ts`
// --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
let outgoing_body_ciphertext_from_typescript = [
126, 10, 214, 39, 130, 143, 96, 143, 79, 143, 22, 36, 55, 41, 234, 255, 226, 26, 138, 236, 91, 188, 204, 216, 172, 133, 134, 69, 161, 237, 134, 5, 75, 192, 10, 6, 229, 54, 194, 56, 103, 243, 57, 248, 147, 237, 4, 3, 39, 28, 226, 30, 237, 228, 212, 115, 246, 244, 105, 39, 129, 119, 126, 207, 176, 14, 75, 134, 241, 23, 2, 187, 239, 86, 47, 56, 239, 20, 92, 176, 70, 12, 219, 226, 150, 70, 192, 43, 125, 53, 230, 153, 135, 228, 210, 197, 227, 106, 242, 138, 119, 83, 182, 150, 233, 111, 9, 104, 128, 222, 85, 136, 205, 244, 77, 230, 210, 217, 223, 106, 220, 4, 115, 33, 157, 212, 217, 133, 87, 179, 67, 158, 81, 85, 226, 105, 22, 8, 154, 130, 193, 214, 144, 212
];

for i in 0..expected_outgoing_body_ciphertext.len() {
assert_eq(ciphertext[i], expected_outgoing_body_ciphertext[i]);
for i in 0..outgoing_body_ciphertext_from_typescript.len() {
assert_eq(ciphertext[i], outgoing_body_ciphertext_from_typescript[i]);
}
assert_eq(expected_outgoing_body_ciphertext.len(), ciphertext.len());
assert_eq(outgoing_body_ciphertext_from_typescript.len(), ciphertext.len());
}
}
Loading