Skip to content

Commit

Permalink
feat: Sync from noir (#7432)
Browse files Browse the repository at this point in the history
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore: unbundle `check_array_is_initialized`
(noir-lang/noir#5451)
feat: Sync from aztec-packages
(noir-lang/noir#5467)
chore: bump bb to 0.45.1 (noir-lang/noir#5469)
feat: prefix operator overload trait dispatch
(noir-lang/noir#5423)
feat: add CLI argument for debugging comptime blocks
(noir-lang/noir#5192)
chore: document EmbeddedCurvePoint
(noir-lang/noir#5468)
feat: lsp rename/find-all-references for struct members
(noir-lang/noir#5443)
feat(optimization): Deduplicate more instructions
(noir-lang/noir#5457)
fix: remove compile-time error for invalid indices
(noir-lang/noir#5466)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: benesjan <janbenes1234@gmail.com>
  • Loading branch information
3 people committed Jul 12, 2024
1 parent 43118ec commit 045a7fc
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 69 deletions.
18 changes: 9 additions & 9 deletions aztec/src/encrypted_logs/header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ impl EncryptedLogHeader {
fn test_encrypted_log_header() {
let address = AztecAddress::from_field(0xdeadbeef);
let header = EncryptedLogHeader::new(address);
let secret = Scalar::new(
0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd,
0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06
);
let point = Point::new(
0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
false
);
let secret = Scalar {
lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd,
hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06
};
let point = Point {
x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
is_infinite: false
};

let ciphertext = header.compute_ciphertext(secret, point);

Expand Down
36 changes: 18 additions & 18 deletions aztec/src/encrypted_logs/incoming_body.nr
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ mod test {

let storage_slot = 2;

let eph_sk = Scalar::new(
0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd,
0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06
);
let ivpk_app = Point::new(
0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
false
);
let eph_sk = Scalar {
lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd,
hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06
};
let ivpk_app = Point {
x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
is_infinite: false
};

let body = EncryptedLogIncomingBody::from_note(note, storage_slot);

Expand Down Expand Up @@ -217,16 +217,16 @@ mod test {
fn test_encrypted_log_event_incoming_body() {
let test_event = TestEvent { value0: 1, value1: 2, value2: 3 };

let eph_sk = Scalar::new(
0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd,
0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06
);
let eph_sk = Scalar {
lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd,
hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06
};

let ivpk_app = Point::new(
0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
false
);
let ivpk_app = Point {
x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
is_infinite: false
};

let randomness = 2;

Expand Down
32 changes: 16 additions & 16 deletions aztec/src/encrypted_logs/outgoing_body.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use dep::protocol_types::{
address::AztecAddress, scalar::Scalar, point::Point, constants::GENERATOR_INDEX__SYMMETRIC_KEY,
hash::poseidon2_hash
};

use std::aes128::aes128_encrypt;

use crate::keys::point_to_symmetric_key::point_to_symmetric_key;
Expand Down Expand Up @@ -65,26 +64,27 @@ mod test {
address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER,
scalar::Scalar, point::Point, hash::poseidon2_hash
};
use std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key;

use crate::context::PrivateContext;

#[test]
fn test_encrypted_log_outgoing_body() {
let eph_sk = Scalar::new(
0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe,
0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb
);
let recipient_ivsk_app = Scalar::new(
0x000000000000000000000000000000004828f8f95676ebb481df163f87fd4022,
0x000000000000000000000000000000000f4d97c25d578f9348251a71ca17ae31
);
let sender_ovsk_app = Scalar::new(
0x0000000000000000000000000000000074d2e28c6bc5176ac02cf7c7d36a444e,
0x00000000000000000000000000000000089c6887cb1446d86c64e81afc78048b
);

let eph_pk = eph_sk.derive_public_key();
let recipient_ivpk_app = recipient_ivsk_app.derive_public_key();
let eph_sk = Scalar {
lo: 0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe,
hi: 0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb
};
let recipient_ivsk_app = Scalar {
lo: 0x000000000000000000000000000000004828f8f95676ebb481df163f87fd4022,
hi: 0x000000000000000000000000000000000f4d97c25d578f9348251a71ca17ae31
};
let sender_ovsk_app = Scalar {
lo: 0x0000000000000000000000000000000074d2e28c6bc5176ac02cf7c7d36a444e,
hi: 0x00000000000000000000000000000000089c6887cb1446d86c64e81afc78048b
};

let eph_pk = derive_public_key(eph_sk);
let recipient_ivpk_app = derive_public_key(recipient_ivsk_app);

let recipient = AztecAddress::from_field(0xdeadbeef);

Expand Down
16 changes: 8 additions & 8 deletions aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dep::protocol_types::{
address::AztecAddress, scalar::Scalar, point::{Point, pub_key_to_bytes},
constants::{GENERATOR_INDEX__IVSK_M, GENERATOR_INDEX__OVSK_M}, hash::poseidon2_hash
};

use std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key;
use std::field::bytes32_to_field;

use crate::oracle::unsafe_rand::unsafe_rand;
Expand All @@ -25,7 +25,7 @@ pub fn compute_encrypted_event_log<Event, NB, MB, OB>(
) -> [u8; OB] where Event: EventInterface<NB, MB> {
// @todo Need to draw randomness from the full domain of Fq not only Fr
let eph_sk: Scalar = fr_to_fq(unsafe_rand());
let eph_pk = eph_sk.derive_public_key();
let eph_pk = derive_public_key(eph_sk);

// TODO: (#7177) This value needs to be populated!
let recipient = AztecAddress::from_field(0);
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn compute_encrypted_note_log<Note, N, NB, M>(
) -> [u8; M] where Note: NoteInterface<N, NB> {
// @todo Need to draw randomness from the full domain of Fq not only Fr
let eph_sk: Scalar = fr_to_fq(unsafe_rand());
let eph_pk = eph_sk.derive_public_key();
let eph_pk = derive_public_key(eph_sk);

// TODO: (#7177) This value needs to be populated!
let recipient = AztecAddress::from_field(0);
Expand Down Expand Up @@ -142,10 +142,10 @@ fn fr_to_fq(r: Field) -> Scalar {
low_bytes[16 + i] = r_bytes[i + 16];
}

let low = bytes32_to_field(low_bytes);
let high = bytes32_to_field(high_bytes);
let lo = bytes32_to_field(low_bytes);
let hi = bytes32_to_field(high_bytes);

Scalar::new(low, high)
Scalar { lo, hi }
}

fn compute_ivpk_app(ivpk: Point, contract_address: AztecAddress) -> Point {
Expand All @@ -158,12 +158,12 @@ fn compute_ivpk_app(ivpk: Point, contract_address: AztecAddress) -> Point {
assert((ivpk.x != 0) & (ivpk.y != 0), "ivpk is infinite");
let i = fr_to_fq(poseidon2_hash([contract_address.to_field(), ivpk.x, ivpk.y, GENERATOR_INDEX__IVSK_M]));
let I = i.derive_public_key();
let I = derive_public_key(i);
let embed_I = Point { x: I.x, y: I.y, is_infinite: false };
let embed_ivpk = Point { x: ivpk.x, y: ivpk.y, is_infinite: false };
let embed_result = embedded_curve_add(embed_I, embed_ivpk);
Point::new(embed_result.x, embed_result.y)*/
Point { x: embed_result.x, embed_result.y)*/
}
2 changes: 1 addition & 1 deletion aztec/src/keys/getters.nr
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn fetch_key_from_registry(
let x_coordinate = x_coordinate_registry.get_value_in_private(header);
let y_coordinate = y_coordinate_registry.get_value_in_private(header);

Point::new(x_coordinate, y_coordinate, false)
Point { x: x_coordinate, y: y_coordinate, is_infinite: false }
}

// Passes only when keys were not rotated - is expected to be called only when keys were not registered yet
Expand Down
18 changes: 9 additions & 9 deletions aztec/src/keys/point_to_symmetric_key.nr
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ pub fn point_to_symmetric_key(secret: Scalar, point: Point) -> [u8; 32] {
#[test]
fn check_point_to_symmetric_key() {
// Value taken from "derive shared secret" test in encrypt_buffer.test.ts
let secret = Scalar::new(
0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd,
0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06
);
let point = Point::new(
0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
false
);
let secret = Scalar {
lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd,
hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06
};
let point = Point {
x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
is_infinite: false
};

let key = point_to_symmetric_key(secret, point);
// The following value gets updated when running encrypt_buffer.test.ts with AZTEC_GENERATE_TEST_DATA=1
Expand Down
8 changes: 4 additions & 4 deletions aztec/src/keys/public_keys.nr
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ impl Serialize<PUBLIC_KEYS_LENGTH> for PublicKeys {
impl Deserialize<PUBLIC_KEYS_LENGTH> for PublicKeys {
fn deserialize(serialized: [Field; PUBLIC_KEYS_LENGTH]) -> PublicKeys {
PublicKeys {
npk_m: Point::new(serialized[0], serialized[1], serialized[2] as bool),
ivpk_m: Point::new(serialized[3], serialized[4], serialized[5] as bool),
ovpk_m: Point::new(serialized[6], serialized[7], serialized[8] as bool),
tpk_m: Point::new(serialized[9], serialized[10], serialized[11] as bool)
npk_m: Point { x:serialized[0], y:serialized[1], is_infinite: serialized[2] as bool },
ivpk_m: Point { x:serialized[3], y: serialized[4], is_infinite: serialized[5] as bool },
ovpk_m: Point { x:serialized[6], y: serialized[7], is_infinite: serialized[8] as bool },
tpk_m: Point { x:serialized[9], y: serialized[10], is_infinite: serialized[11] as bool }
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions aztec/src/oracle/keys.nr
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ fn get_public_keys_and_partial_address(address: AztecAddress) -> (PublicKeys, Pa
let result = get_public_keys_and_partial_address_oracle_wrapper(address);

let keys = PublicKeys {
npk_m: Point::new(result[0], result[1], result[2] as bool),
ivpk_m: Point::new(result[3], result[4], result[5] as bool),
ovpk_m: Point::new(result[6], result[7], result[8] as bool),
tpk_m: Point::new(result[9], result[10], result[11] as bool)
npk_m: Point { x: result[0], y: result[1], is_infinite: result[2] as bool },
ivpk_m: Point { x: result[3], y: result[4], is_infinite: result[5] as bool },
ovpk_m: Point { x: result[6], y: result[7], is_infinite: result[8] as bool },
tpk_m: Point { x: result[9], y: result[10], is_infinite: result[11] as bool }
};

let partial_address = PartialAddress::from_field(result[12]);
Expand Down

0 comments on commit 045a7fc

Please sign in to comment.