Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jul 8, 2024
1 parent ace514c commit b3e1ef8
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 23 deletions.
4 changes: 3 additions & 1 deletion noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
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 @@ -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()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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]),
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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>`;
Original file line number Diff line number Diff line change
@@ -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>`;
4 changes: 2 additions & 2 deletions yarn-project/foundation/src/fields/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit b3e1ef8

Please sign in to comment.