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 <[email protected]>
Co-authored-by: benesjan <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent 399917b commit 97ecff5
Show file tree
Hide file tree
Showing 82 changed files with 1,501 additions and 396 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bb6913ac53620fabd73e24ca1a2b1369225903ec
e59ff8c6a12978407be4f9f474d5208bdabb8c29
1 change: 1 addition & 0 deletions avm-transpiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions noir-projects/aztec-nr/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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ contract Test {
};
use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash};
use dep::value_note::value_note::ValueNote;
use std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key;

use crate::test_note::TestNote;

Expand Down Expand Up @@ -427,7 +428,7 @@ contract Test {
recipient_ivpk_app: Point,
ovsk_app: Scalar
) -> [u8; 176] {
let eph_pk = eph_sk.derive_public_key();
let eph_pk = derive_public_key(eph_sk);
EncryptedLogOutgoingBody::new(eph_sk, recipient, recipient_ivpk_app).compute_ciphertext(ovsk_app, eph_pk)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ mod tests {
let remaining_nullifier_rr_index = builder.previous_kernel.add_read_request_for_pending_nullifier(1);
let nullifier_rr = builder.previous_kernel.nullifier_read_requests.storage[remaining_nullifier_rr_index];

let key_validation_index = builder.previous_kernel.add_request_for_key_validation(Point::new(1, 2, false), 27, GENERATOR_INDEX__OVSK_M);
let key_validation_index = builder.previous_kernel.add_request_for_key_validation(
Point { x: 1, y: 2, is_infinite: false },
27,
GENERATOR_INDEX__OVSK_M
);
let key_validation = builder.previous_kernel.scoped_key_validation_requests_and_generators.storage[key_validation_index];

// Check that they have been propagated to the next kernel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ mod tests {
#[test(should_fail_with="Non empty key validation requests")]
fn non_empty_key_validations() {
let mut builder = PrivateKernelTailInputsBuilder::new();
let _void = builder.previous_kernel.add_request_for_key_validation(Point::new(1, 2, false), 27, GENERATOR_INDEX__IVSK_M);
let _void = builder.previous_kernel.add_request_for_key_validation(
Point { x: 1, y: 2, is_infinite: false },
27,
GENERATOR_INDEX__IVSK_M
);
builder.failed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ mod tests {
#[test(should_fail_with="Non empty key validation requests")]
fn non_empty_key_validations() {
let mut builder = PrivateKernelTailToPublicInputsBuilder::new();
let _void = builder.previous_kernel.add_request_for_key_validation(Point::new(1, 2, false), 27, GENERATOR_INDEX__TSK_M);
let _void = builder.previous_kernel.add_request_for_key_validation(
Point { x: 1, y: 2, is_infinite: false },
27,
GENERATOR_INDEX__TSK_M
);
builder.failed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use dep::types::{
constants::MAX_KEY_VALIDATION_REQUESTS_PER_TX, scalar::Scalar, hash::poseidon2_hash,
utils::arrays::filter_array_to_bounded_vec
};
use std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key;

struct KeyValidationHint {
sk_m: Scalar,
Expand Down Expand Up @@ -44,7 +45,7 @@ pub fn reset_key_validation_requests<N>(
let sk_app_generator = request_and_generator.sk_app_generator;

// First we check that derived public key matches master public key from request
let pk_m = sk_m.derive_public_key();
let pk_m = derive_public_key(sk_m);
assert(
pk_m.eq(request.pk_m), "Failed to derive matching master public key from the secret key."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Serialize<KEY_VALIDATION_REQUEST_LENGTH> for KeyValidationRequest {
impl Deserialize<KEY_VALIDATION_REQUEST_LENGTH> for KeyValidationRequest {
fn deserialize(fields: [Field; KEY_VALIDATION_REQUEST_LENGTH]) -> Self {
Self {
pk_m: Point::new(fields[0], fields[1], fields[2] as bool),
pk_m: Point { x:fields[0], y: fields[1], is_infinite: fields[2] as bool},
sk_app: fields[3],
}
}
Expand Down
2 changes: 1 addition & 1 deletion noir/bb-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.43.0
0.46.1
2 changes: 1 addition & 1 deletion noir/noir-repo/acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ mod tests {
use std::collections::BTreeSet;

use super::{
opcodes::{BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput},
opcodes::{BlackBoxFuncCall, FunctionInput},
Circuit, Compression, Opcode, PublicInputs,
};
use crate::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ mod tests {
use crate::{circuit::Opcode, native_types::Witness};
use acir_field::{AcirField, FieldElement};

use super::{BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput};
use super::{BlackBoxFuncCall, FunctionInput};

fn keccakf1600_opcode<F: AcirField>() -> Opcode<F> {
let inputs: Box<[FunctionInput<F>; 25]> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::collections::BTreeSet;
use acir::{
circuit::{
brillig::{BrilligBytecode, BrilligInputs, BrilligOutputs},
opcodes::{BlackBoxFuncCall, BlockId, ConstantOrWitnessEnum, FunctionInput, MemOp},
opcodes::{BlackBoxFuncCall, BlockId, FunctionInput, MemOp},
Circuit, Opcode, Program, PublicInputs,
},
native_types::{Expression, Witness},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ mod tests {
use crate::compiler::optimizers::redundant_range::RangeOptimizer;
use acir::{
circuit::{
opcodes::{BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput},
opcodes::{BlackBoxFuncCall, FunctionInput},
Circuit, ExpressionWidth, Opcode, PublicInputs,
},
native_types::{Expression, Witness},
Expand Down
1 change: 1 addition & 0 deletions noir/noir-repo/compiler/fm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license.workspace = true

[dependencies]
codespan-reporting.workspace = true
iter-extended.workspace = true
serde.workspace = true

[dev-dependencies]
Expand Down
Loading

0 comments on commit 97ecff5

Please sign in to comment.