Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: checking compute_encrypted_note_log against TS impl #7491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 42 additions & 0 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,45 @@ fn compute_ivpk_app(ivpk: Point, contract_address: AztecAddress) -> Point {

Point { x: embed_result.x, embed_result.y)*/
}

mod test {
use crate::{
encrypted_logs::payload::compute_encrypted_note_log,
test::mocks::mock_note::{MockNoteBuilder, MockNote}
};
use dep::protocol_types::{address::AztecAddress, point::Point};
use std::test::OracleMock;

#[test]
fn test_compute_encrypted_note_log() {
let contract_address = AztecAddress::from_field(0x10f48cd9eff7ae5b209c557c70de2e657ee79166868676b787e9417e19260e04);
let storage_slot = 0x0fe46be583b71f4ab5b70c2657ff1d05cccf1d292a9369628d1a194f944e6599;
let ovsk_app = 0x1b99ba138fa7ef8a2f122a98dd80c8ee70d447218dd780f45e165ac17ca38a5e;
let ovpk_m = Point {
x: 0x1961448682803198631f299340e4206bb12809d4bebbf012b30f59af73ba1a15,
y: 0x133674060c3925142aceb4f1dcd9f9137d0217d37ff8729ee5ceaa6e2790353d,
is_infinite: false
};
let ivpk_m = Point {
x: 0x260cd3904f6df16e974c29944fdc839e40fb5cf293f03df2eb370851d3a527bc,
y: 0x0eef2964fe6640e84c82b5d2915892409b38e9e25d39f68dd79edb725c55387f,
is_infinite: false
};

let note_value = 0x301640ceea758391b2e161c92c0513f129020f4125256afdae2646ce31099f5c;
let note = MockNoteBuilder::new(note_value).contract_address(contract_address).storage_slot(storage_slot).build();

let eph_sk = 0x1358d15019d4639393d62b97e1588c095957ce74a1c32d6ec7d62fe6705d9538;
OracleMock::mock("getRandomField").returns(eph_sk);

let log: [u8; 512] = compute_encrypted_note_log(contract_address, storage_slot, ovsk_app, ovpk_m, ivpk_m, note);

let expected_encrypted_note_log = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 70, 12, 14, 67, 77, 132, 110, 193, 234, 40, 110, 64, 144, 235, 86, 55, 111, 242, 123, 221, 193, 170, 202, 225, 216, 86, 84, 159, 112, 31, 167, 17, 160, 52, 217, 22, 191, 84, 175, 25, 133, 53, 220, 2, 251, 32, 105, 198, 147, 24, 131, 202, 112, 149, 136, 66, 205, 254, 3, 134, 195, 101, 73, 212, 19, 232, 42, 39, 191, 165, 183, 8, 7, 18, 118, 74, 69, 91, 146, 69, 16, 184, 101, 144, 48, 25, 190, 254, 181, 223, 24, 183, 175, 118, 159, 176, 135, 62, 255, 169, 124, 170, 3, 92, 81, 122, 107, 65, 125, 95, 97, 110, 198, 200, 74, 147, 217, 93, 23, 227, 84, 59, 15, 75, 108, 122, 49, 230, 228, 246, 207, 173, 7, 60, 16, 74, 236, 201, 102, 237, 48, 179, 223, 191, 223, 248, 78, 167, 61, 203, 25, 114, 223, 58, 60, 180, 255, 116, 170, 136, 173, 178, 40, 2, 125, 229, 20, 220, 82, 28, 191, 147, 133, 137, 1, 45, 243, 229, 140, 115, 165, 150, 154, 96, 22, 120, 223, 237, 213, 182, 252, 192, 8, 132, 43, 21, 56, 243, 116, 144, 182, 75, 16, 30, 222, 222, 60, 205, 147, 214, 53, 41, 62, 53, 16, 147, 117, 72, 169, 220, 125, 208, 210, 12, 186, 204, 143, 114, 50, 101, 80, 157, 55, 73, 11, 125, 27, 236, 202, 2, 242, 81, 153, 206, 165, 215, 215, 116, 50, 93, 177, 236, 240, 26, 164, 68, 160, 91, 136, 250, 39, 177, 22, 37, 38, 82, 248, 55, 125, 108, 38, 234, 209, 151, 69, 187, 150, 105, 120, 187, 236, 212, 161, 78, 22, 6, 231, 229, 110, 248, 35, 22, 254, 17, 32, 191, 75, 35, 252, 227, 111, 46, 146, 52, 21, 171, 105, 20, 112, 233, 143, 177, 99, 185, 193, 164, 246, 192, 62, 234, 175, 198, 157, 31, 230, 233, 237, 26, 65, 24, 65, 72, 220, 247, 223, 61, 75, 246, 144, 94, 99, 132, 235, 149, 93, 3, 115, 131, 132, 250, 238, 138, 194, 233, 144, 156, 140, 1, 42, 44, 12, 214, 94, 137, 130, 56, 105, 149, 124, 81, 178, 1, 73, 79, 156, 26, 65, 163, 18, 152, 116, 138, 128, 158, 63, 151, 205, 151, 73, 68, 173, 220, 126, 213, 72, 112, 237, 15, 235, 178, 217, 122, 146, 224, 89, 213, 217, 34, 172, 4, 164, 40, 102, 220, 174, 222, 250, 221, 149, 238, 174, 97, 65, 183, 255, 168, 139, 67, 122, 124, 41, 89, 147, 255, 109, 57, 197, 150, 174, 186, 221, 50, 19, 216, 14, 100, 176
];
for i in 0..expected_encrypted_note_log.len() {
assert_eq(log[i], expected_encrypted_note_log[i]);
}
assert_eq(expected_encrypted_note_log.len(), log.len());
}
}
42 changes: 40 additions & 2 deletions yarn-project/circuit-types/src/logs/l1_payload/tagged_log.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { AztecAddress, KeyValidationRequest, computeOvskApp, derivePublicKeyFromSecretKey } from '@aztec/circuits.js';
import { EventSelector } from '@aztec/foundation/abi';
import { EventSelector, NoteSelector } from '@aztec/foundation/abi';
import { pedersenHash } from '@aztec/foundation/crypto';
import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
import { updateInlineTestData } from '@aztec/foundation/testing';

import { EncryptedL2Log } from '../encrypted_l2_log.js';
import { L1EventPayload } from './l1_event_payload.js';
import { L1NotePayload } from './l1_note_payload.js';
import { Event } from './payload.js';
import { Event, Note } from './payload.js';
import { TaggedLog } from './tagged_log.js';

describe('L1 Note Payload', () => {
Expand Down Expand Up @@ -55,6 +56,43 @@ describe('L1 Note Payload', () => {
});
});

it('encrypted tagged log matches Noir', () => {
const contract = AztecAddress.fromString('0x10f48cd9eff7ae5b209c557c70de2e657ee79166868676b787e9417e19260e04');
const storageSlot = new Fr(0x0fe46be583b71f4ab5b70c2657ff1d05cccf1d292a9369628d1a194f944e6599n);
const noteValue = new Fr(0x301640ceea758391b2e161c92c0513f129020f4125256afdae2646ce31099f5cn);
const noteTypeId = new NoteSelector(0);

const payload = new L1NotePayload(new Note([noteValue]), contract, storageSlot, noteTypeId);

const ovskM = new GrumpkinScalar(0x06b76394ac57b8a18ceb08b14ed15b5b778d5c506b4cfb7edc203324eab27c05n);
const ivskM = new GrumpkinScalar(0x03fd94b1101e834e829cda4f227043f60490b5c7b3073875f5bfbe5028ed05ccn);

const ovKeys = getKeyValidationRequest(ovskM, payload.contractAddress);

const ephSk = new GrumpkinScalar(0x1358d15019d4639393d62b97e1588c095957ce74a1c32d6ec7d62fe6705d9538n);

// TODO: (#7177) This value needs to be populated!
const recipientAddress = AztecAddress.ZERO;
const ivpk = derivePublicKeyFromSecretKey(ivskM);

const taggedLog = new TaggedLog(payload, new Fr(0), new Fr(0));

const encrypted = taggedLog.encrypt(ephSk, recipientAddress, ivpk, ovKeys).toString('hex');

expect(encrypted).toMatchInlineSnapshot(
`"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d460c0e434d846ec1ea286e4090eb56376ff27bddc1aacae1d856549f701fa711a034d916bf54af198535dc02fb2069c6931883ca70958842cdfe0386c36549d413e82a27bfa5b7080712764a455b924510b865903019befeb5df18b7af769fb0873effa97caa035c517a6b417d5f616ec6c84a93d95d17e3543b0f4b6c7a31e6e4f6cfad073c104aecc966ed30b3dfbfdff84ea73dcb1972df3a3cb4ff74aa88adb228027de514dc521cbf938589012df3e58c73a5969a601678dfedd5b6fcc008842b1538f37490b64b101edede3ccd93d635293e3510937548a9dc7dd0d20cbacc8f723265509d37490b7d1becca02f25199cea5d7d774325db1ecf01aa444a05b88fa27b116252652f8377d6c26ead19745bb966978bbecd4a14e1606e7e56ef82316fe1120bf4b23fce36f2e923415ab691470e98fb163b9c1a4f6c03eeaafc69d1fe6e9ed1a41184148dcf7df3d4bf6905e6384eb955d03738384faee8ac2e9909c8c012a2c0cd65e89823869957c51b201494f9c1a41a31298748a809e3f97cd974944addc7ed54870ed0febb2d97a92e059d5d922ac04a42866dcaedefadd95eeae6141b7ffa88b437a7c295993ff6d39c596aebadd3213d80e64b0"`,
);

const byteArrayString = `[${encrypted.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16))}]`;

// Run with AZTEC_GENERATE_TEST_DATA=1 to update noir test data
updateInlineTestData(
'noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr',
'expected_encrypted_note_log',
byteArrayString,
);
});

const getKeyValidationRequest = (ovskM: GrumpkinScalar, app: AztecAddress) => {
const ovskApp = computeOvskApp(ovskM, app);
const ovpkM = derivePublicKeyFromSecretKey(ovskM);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@
"engines": {
"node": ">=18"
}
}
}
Loading