From b3e1ef8a6cf1d1ddc98ed3cf3e1d8c237f8584fa Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 8 Jul 2024 15:51:48 +0000 Subject: [PATCH] fixes --- .../aztec-nr/aztec/src/encrypted_logs/header.nr | 4 +++- .../aztec/src/encrypted_logs/incoming_body.nr | 8 ++++++-- .../aztec/src/encrypted_logs/outgoing_body.nr | 4 +++- .../aztec/src/keys/point_to_symmetric_key.nr | 4 +++- .../aztec-nr/aztec/src/keys/public_keys.nr | 8 ++++---- .../types/src/abis/private_call_stack_item.nr | 2 +- .../src/abis/private_circuit_public_inputs.nr | 2 +- .../validation_requests/key_validation_request.nr | 2 +- .../crates/types/src/embedded_curve_point.nr | 14 +++++++++++++- .../src/barretenberg/crypto/grumpkin/index.ts | 8 ++++---- .../src/barretenberg/crypto/schnorr/index.ts | 6 ++++-- .../private_call_stack_item.test.ts.snap | 2 +- .../private_circuit_public_inputs.test.ts.snap | 2 +- yarn-project/foundation/src/fields/point.ts | 4 ++-- 14 files changed, 47 insertions(+), 23 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr index 038e2ffba35..a4fbe883934 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr @@ -47,7 +47,9 @@ fn test_encrypted_log_header() { let ciphertext = header.compute_ciphertext(secret, point); - let expected_header_ciphertext = [228,9,65,81,62,59,249,207,90,196,206,72,39,199,82,196,23,131,32,226,26,176,43,39,239,177,177,192,85,216,17,15,18,187,35,225,135,192,63,88,29,173,232,46,72,82,187,139]; + let expected_header_ciphertext = [ + 228, 9, 65, 81, 62, 59, 249, 207, 90, 196, 206, 72, 39, 199, 82, 196, 23, 131, 32, 226, 26, 176, 43, 39, 239, 177, 177, 192, 85, 216, 17, 15, 18, 187, 35, 225, 135, 192, 63, 88, 29, 173, 232, 46, 72, 82, 187, 139 + ]; assert_eq(ciphertext, expected_header_ciphertext); } diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr index 8f4d7948191..a20b94c58d8 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr @@ -133,7 +133,9 @@ mod test { let ciphertext = body.compute_ciphertext(eph_sk, ivpk_app); - let expected_note_body_ciphertext = [228,9,65,81,62,59,249,207,90,196,206,72,39,199,82,196,63,127,188,251,150,188,238,205,3,86,102,164,175,12,137,158,163,111,205,10,229,230,46,202,110,107,156,180,67,192,161,201,48,153,169,1,25,182,93,39,39,207,251,218,234,147,156,13,110,180,190,199,41,6,211,203,176,110,165,186,110,127,199,22,201,149,92,249,219,68,145,68,179,29,233,34,98,123,197,234,169,53,44,14,81,60,92,27,250,134,49,248,57,119,236,118,158,104,82,243,98,164,60,72,74,27,177,194,221,225,193,150,67,235,205,106,150,24,126,186,220,178,199,189,113,54,181,55,46,15,236,236,9,159,5,172,237,154,110,50,241,64,92,13,37,53,20,140,42,146,229,63,97,25,159,63,235,104,68,100]; + let expected_note_body_ciphertext = [ + 228, 9, 65, 81, 62, 59, 249, 207, 90, 196, 206, 72, 39, 199, 82, 196, 63, 127, 188, 251, 150, 188, 238, 205, 3, 86, 102, 164, 175, 12, 137, 158, 163, 111, 205, 10, 229, 230, 46, 202, 110, 107, 156, 180, 67, 192, 161, 201, 48, 153, 169, 1, 25, 182, 93, 39, 39, 207, 251, 218, 234, 147, 156, 13, 110, 180, 190, 199, 41, 6, 211, 203, 176, 110, 165, 186, 110, 127, 199, 22, 201, 149, 92, 249, 219, 68, 145, 68, 179, 29, 233, 34, 98, 123, 197, 234, 169, 53, 44, 14, 81, 60, 92, 27, 250, 134, 49, 248, 57, 119, 236, 118, 158, 104, 82, 243, 98, 164, 60, 72, 74, 27, 177, 194, 221, 225, 193, 150, 67, 235, 205, 106, 150, 24, 126, 186, 220, 178, 199, 189, 113, 54, 181, 55, 46, 15, 236, 236, 9, 159, 5, 172, 237, 154, 110, 50, 241, 64, 92, 13, 37, 53, 20, 140, 42, 146, 229, 63, 97, 25, 159, 63, 235, 104, 68, 100 + ]; assert_eq(expected_note_body_ciphertext.len(), ciphertext.len()); @@ -233,7 +235,9 @@ mod test { let ciphertext = body.compute_ciphertext(eph_sk, ivpk_app); - let expected_event_body_ciphertext = [228,9,65,81,62,59,249,207,90,196,206,72,39,199,82,196,63,127,188,251,150,188,238,205,3,86,102,164,175,12,137,158,163,111,205,10,229,230,46,202,110,107,156,180,67,192,161,201,66,122,29,35,42,33,153,216,199,208,103,207,126,153,189,136,19,220,238,15,169,29,255,11,123,107,70,192,53,40,36,93,187,32,123,136,104,23,229,245,152,90,84,2,136,112,42,27,82,214,104,14,250,48,199,245,88,22,200,77,38,51,127,56,138,255,16,46,179,129,215,185,185,116,148,16,133,62,56,180,10,132,109,77,206,199,21,167,7,163,171,158,244,23,18,121,108,42,107,7,48,84,212,104,39,16,109,7,108,129,60,80,112,241,223,140,186,158,38,74,230,213,159,175,142,228,128,160]; + let expected_event_body_ciphertext = [ + 228, 9, 65, 81, 62, 59, 249, 207, 90, 196, 206, 72, 39, 199, 82, 196, 63, 127, 188, 251, 150, 188, 238, 205, 3, 86, 102, 164, 175, 12, 137, 158, 163, 111, 205, 10, 229, 230, 46, 202, 110, 107, 156, 180, 67, 192, 161, 201, 66, 122, 29, 35, 42, 33, 153, 216, 199, 208, 103, 207, 126, 153, 189, 136, 19, 220, 238, 15, 169, 29, 255, 11, 123, 107, 70, 192, 53, 40, 36, 93, 187, 32, 123, 136, 104, 23, 229, 245, 152, 90, 84, 2, 136, 112, 42, 27, 82, 214, 104, 14, 250, 48, 199, 245, 88, 22, 200, 77, 38, 51, 127, 56, 138, 255, 16, 46, 179, 129, 215, 185, 185, 116, 148, 16, 133, 62, 56, 180, 10, 132, 109, 77, 206, 199, 21, 167, 7, 163, 171, 158, 244, 23, 18, 121, 108, 42, 107, 7, 48, 84, 212, 104, 39, 16, 109, 7, 108, 129, 60, 80, 112, 241, 223, 140, 186, 158, 38, 74, 230, 213, 159, 175, 142, 228, 128, 160 + ]; assert_eq(expected_event_body_ciphertext.len(), ciphertext.len()); diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr index 25d427b6312..dee4589ab0d 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr @@ -103,7 +103,9 @@ 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,122,191,158,69,35,255,215,171,196,45,91,184,83,80,238,201,1,233,235,159,171,130,158,64,176,165,132,30,84,81,71,195,145,47,82,247,210,192,23,4,220,90,56,109,46,105,79,251,165,141,185,233,191,118,219,153,191,162,99,238,241,249,9,74,210,241,54,28,126,226,85,235,174,75,239,207,100,184,248,194]; + 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, 122, 191, 158, 69, 35, 255, 215, 171, 196, 45, 91, 184, 83, 80, 238, 201, 1, 233, 235, 159, 171, 130, 158, 64, 176, 165, 132, 30, 84, 81, 71, 195, 145, 47, 82, 247, 210, 192, 23, 4, 220, 90, 56, 109, 46, 105, 79, 251, 165, 141, 185, 233, 191, 118, 219, 153, 191, 162, 99, 238, 241, 249, 9, 74, 210, 241, 54, 28, 126, 226, 85, 235, 174, 75, 239, 207, 100, 184, 248, 194 + ]; for i in 0..expected_outgoing_body_ciphertext.len() { assert_eq(ciphertext[i], expected_outgoing_body_ciphertext[i]); diff --git a/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr b/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr index 66ccfb6f82c..2857f6f54a1 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr @@ -34,6 +34,8 @@ fn check_point_to_symmetric_key() { 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 - let expected_key = [49,167,146,222,151,129,138,184,87,210,245,249,99,100,1,59,223,180,5,99,14,7,177,236,159,203,231,72,220,180,241,23]; + let expected_key = [ + 49, 167, 146, 222, 151, 129, 138, 184, 87, 210, 245, 249, 99, 100, 1, 59, 223, 180, 5, 99, 14, 7, 177, 236, 159, 203, 231, 72, 220, 180, 241, 23 + ]; assert_eq(key, expected_key); } diff --git a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr index 668cee98925..a78bb4739a1 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr @@ -16,10 +16,10 @@ struct PublicKeys { impl Empty for PublicKeys { fn empty() -> Self { PublicKeys { - npk_m : EmbeddedCurvePoint::point_at_infinity(), - ivpk_m : EmbeddedCurvePoint::point_at_infinity(), - ovpk_m : EmbeddedCurvePoint::point_at_infinity(), - tpk_m : EmbeddedCurvePoint::point_at_infinity() + npk_m : EmbeddedCurvePoint::empty(), + ivpk_m : EmbeddedCurvePoint::empty(), + ovpk_m : EmbeddedCurvePoint::empty(), + tpk_m : EmbeddedCurvePoint::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr index 106d87b763d..cac20bc55a7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr @@ -85,6 +85,6 @@ fn empty_hash() { let hash = item.hash(); // Value from private_call_stack_item.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x18aa4273e592b49ec4507210f8b01a6f5c961165d85888fb06dad4d7d6c382ab; + let test_data_empty_hash = 0x267a892d425b73b18f984607ec388d71df8058819eddbfcf2cb8a749596a507e; assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index e173476140f..28b568ec5e8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -250,6 +250,6 @@ fn empty_hash() { let inputs = PrivateCircuitPublicInputs::empty(); let hash = inputs.hash(); // Value from private_circuit_public_inputs.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x2af549c0cdad3e0e278d50e971118d0fa077fcb18b196477d677cd6471ef3378; + let test_data_empty_hash = 0x142dd7d24536af9139b3b190d2061a64c224a50b5c8d5a854b564c2b1032ba49; assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request.nr index 361ce9c2726..715b7871b7c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request.nr @@ -18,7 +18,7 @@ impl Eq for KeyValidationRequest { impl Empty for KeyValidationRequest { fn empty() -> Self { KeyValidationRequest { - pk_m: EmbeddedCurvePoint::point_at_infinity(), + pk_m: EmbeddedCurvePoint::empty(), sk_app: 0, } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/embedded_curve_point.nr b/noir-projects/noir-protocol-circuits/crates/types/src/embedded_curve_point.nr index 0e393d89cca..18e76d0b4c7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/embedded_curve_point.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/embedded_curve_point.nr @@ -1,5 +1,5 @@ use dep::std::embedded_curve_ops::EmbeddedCurvePoint; -use crate::{traits::{Serialize, Hash}, hash::poseidon2_hash}; +use crate::{traits::{Empty, Hash, Serialize}, hash::poseidon2_hash}; global EMBEDDED_CURVE_POINT_LENGTH: Field = 3; @@ -14,3 +14,15 @@ impl Hash for EmbeddedCurvePoint { poseidon2_hash(self.serialize()) } } + +impl Empty for EmbeddedCurvePoint { + /// Note: Does not return a valid point on curve - instead represents an empty/"unpopulated" point struct (e.g. + /// empty/unpopulated value in an array of points). + fn empty() -> Self { + EmbeddedCurvePoint { + x: 0, + y: 0, + is_infinite: false + } + } +} diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts index e6bee737825..13ebf420a4f 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts @@ -8,9 +8,7 @@ export class Grumpkin { private wasm = BarretenbergSync.getSingleton().getWasm(); // TODO(#7386): correctly handle point at infinity in our BB API and nuke Grumpkin.notAPointAtInfinityBuf - static notAPointAtInfinityBuf = Buffer.from([ - 0x00 - ]); + static notAPointAtInfinityBuf = Buffer.from([0x00]); // prettier-ignore static generator = Point.fromBuffer(Buffer.concat([Buffer.from([ @@ -69,7 +67,9 @@ export class Grumpkin { */ public batchMul(points: Point[], scalar: GrumpkinScalar) { // TODO(#7386): remove the ugly subarray hack below - const concatenatedPoints: Buffer = Buffer.concat(points.map(point => point.toBuffer().subarray(0, Fr.SIZE_IN_BYTES * 2))); + const concatenatedPoints: Buffer = Buffer.concat( + points.map(point => point.toBuffer().subarray(0, Fr.SIZE_IN_BYTES * 2)), + ); const pointsByteLength = points.length * Point.SIZE_IN_BYTES; const mem = this.wasm.call('bbmalloc', pointsByteLength * 2); diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.ts index 83a65c8be32..08437e56d6e 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.ts @@ -4,8 +4,8 @@ import { numToUInt32BE } from '@aztec/foundation/serialize'; import { type GrumpkinPrivateKey } from '../../../types/grumpkin_private_key.js'; import { type PublicKey } from '../../../types/public_key.js'; -import { SchnorrSignature } from './signature.js'; import { Grumpkin } from '../grumpkin/index.js'; +import { SchnorrSignature } from './signature.js'; export * from './signature.js'; @@ -24,7 +24,9 @@ export class Schnorr { this.wasm.writeMemory(0, privateKey.toBuffer()); this.wasm.call('schnorr_compute_public_key', 0, 32); // TODO(#7386): correctly handle point at infinity in our API and nuke Grumpkin.notAPointAtInfinityBuf - return Point.fromBuffer(Buffer.concat([Buffer.from(this.wasm.getMemorySlice(32, 96)), Grumpkin.notAPointAtInfinityBuf])); + return Point.fromBuffer( + Buffer.concat([Buffer.from(this.wasm.getMemorySlice(32, 96)), Grumpkin.notAPointAtInfinityBuf]), + ); } /** diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap index 2077b9beff8..7e7bf6b5dd6 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PrivateCallStackItem computes empty item hash 1`] = `Fr<0x18aa4273e592b49ec4507210f8b01a6f5c961165d85888fb06dad4d7d6c382ab>`; +exports[`PrivateCallStackItem computes empty item hash 1`] = `Fr<0x267a892d425b73b18f984607ec388d71df8058819eddbfcf2cb8a749596a507e>`; exports[`PrivateCallStackItem computes hash 1`] = `Fr<0x0b97fe2235bd5cf9e172a119299a7c2074a0277ccc4c062237dd76811a443779>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap index 58f7943ade9..6e1915e515a 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PrivateCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x2af549c0cdad3e0e278d50e971118d0fa077fcb18b196477d677cd6471ef3378>`; +exports[`PrivateCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x142dd7d24536af9139b3b190d2061a64c224a50b5c8d5a854b564c2b1032ba49>`; exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x2f9b476628870a5740e3a6aae52234d8872b3eba7df610977eca31f93769a18f>`; diff --git a/yarn-project/foundation/src/fields/point.ts b/yarn-project/foundation/src/fields/point.ts index 57b0694e635..7ef2c312dcd 100644 --- a/yarn-project/foundation/src/fields/point.ts +++ b/yarn-project/foundation/src/fields/point.ts @@ -8,7 +8,7 @@ import { Fr } from './fields.js'; * converting instances to various output formats, and checking the equality of points. */ export class Point { - static ZERO = new Point(Fr.ZERO, Fr.ZERO, true); + static ZERO = new Point(Fr.ZERO, Fr.ZERO, false); static SIZE_IN_BYTES = Fr.SIZE_IN_BYTES * 2 + 1; // + 1 for isInfinite /** Used to differentiate this class from AztecAddress */ @@ -153,7 +153,7 @@ export class Point { * Check this is consistent with how bb is encoding the point at infinity */ public get inf() { - return this.x == Fr.ZERO; + return this.x.isZero() && this.y.isZero() && this.isInfinite; } isOnGrumpkin() {