From 8ec29d875fa6432e45da64acc80d31aec588f9ca Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 25 Oct 2024 14:07:08 +0000 Subject: [PATCH] nuking brittle test --- .../src/client/private_execution.test.ts | 6 +- .../simulator/src/client/simulator.test.ts | 34 +---------- .../simulator/src/client/test_utils.ts | 57 ------------------- 3 files changed, 4 insertions(+), 93 deletions(-) delete mode 100644 yarn-project/simulator/src/client/test_utils.ts diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 3d6c21720ef..b72a52b1861 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -50,7 +50,7 @@ import { import { asyncMap } from '@aztec/foundation/async-map'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { times } from '@aztec/foundation/collection'; -import { poseidon2HashWithSeparator, randomInt } from '@aztec/foundation/crypto'; +import { poseidon2Hash, poseidon2HashWithSeparator, randomInt } from '@aztec/foundation/crypto'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; @@ -74,7 +74,6 @@ import { MessageLoadOracleInputs } from '../acvm/index.js'; import { buildL1ToL2Message } from '../test/utils.js'; import { type DBOracle } from './db_oracle.js'; import { AcirSimulator } from './simulator.js'; -import { computeNoteHash } from './test_utils.js'; jest.setTimeout(60_000); @@ -314,7 +313,8 @@ describe('Private Execution test suite', () => { const noteHashIndex = randomInt(1); // mock index in TX's final noteHashes array const nonce = computeNoteHashNonce(mockFirstNullifier, noteHashIndex); const note = new Note([new Fr(amount), ownerNpkMHash, Fr.random()]); - const noteHash = computeNoteHash(storageSlot, note.items); + // Note: The following does not correspond to how note hashing is generally done in real notes. + const noteHash = poseidon2Hash([storageSlot, ...note.items]); return { contractAddress, storageSlot, diff --git a/yarn-project/simulator/src/client/simulator.test.ts b/yarn-project/simulator/src/client/simulator.test.ts index 1e4cbe6d876..951899e10a3 100644 --- a/yarn-project/simulator/src/client/simulator.test.ts +++ b/yarn-project/simulator/src/client/simulator.test.ts @@ -1,9 +1,7 @@ import { type AztecNode, CompleteAddress, Note } from '@aztec/circuit-types'; -import { GeneratorIndex, KeyValidationRequest, computeAppNullifierSecretKey, deriveKeys } from '@aztec/circuits.js'; -import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash'; +import { KeyValidationRequest, computeAppNullifierSecretKey, deriveKeys } from '@aztec/circuits.js'; import { type FunctionArtifact, getFunctionArtifact } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr, type Point } from '@aztec/foundation/fields'; import { TokenBlacklistContractArtifact } from '@aztec/noir-contracts.js'; @@ -11,7 +9,6 @@ import { type MockProxy, mock } from 'jest-mock-extended'; import { type DBOracle } from './db_oracle.js'; import { AcirSimulator } from './simulator.js'; -import { computeNoteHash } from './test_utils.js'; describe('Simulator', () => { let oracle: MockProxy; @@ -59,35 +56,6 @@ describe('Simulator', () => { const createNote = (amount = 123n) => new Note([new Fr(amount), new Fr(0), ownerMasterNullifierPublicKey.hash(), Fr.random()]); - it('should compute note hashes and nullifier', async () => { - oracle.getFunctionArtifactByName.mockResolvedValue(artifact); - - const note = createNote(); - const noteHash = computeNoteHash(storageSlot, note.items); - const uniqueNoteHash = computeUniqueNoteHash(nonce, noteHash); - const siloedNoteHash = siloNoteHash(contractAddress, uniqueNoteHash); - const innerNullifier = poseidon2HashWithSeparator( - [siloedNoteHash, appNullifierSecretKey], - GeneratorIndex.NOTE_NULLIFIER, - ); - - const result = await simulator.computeNoteHashAndOptionallyANullifier( - contractAddress, - nonce, - storageSlot, - noteTypeId, - true, - note, - ); - - expect(result).toEqual({ - noteHash, - uniqueNoteHash, - siloedNoteHash, - innerNullifier, - }); - }); - it('throw if the contract does not implement "compute_note_hash_and_optionally_a_nullifier"', async () => { oracle.getFunctionArtifactByName.mockResolvedValue(undefined); diff --git a/yarn-project/simulator/src/client/test_utils.ts b/yarn-project/simulator/src/client/test_utils.ts deleted file mode 100644 index af7fa0345d9..00000000000 --- a/yarn-project/simulator/src/client/test_utils.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Fq, Fr, Point } from '@aztec/circuits.js'; -import { Grumpkin } from '@aztec/circuits.js/barretenberg'; - -// Copied over from `noir-projects/aztec-nr/aztec/src/generators.nr` -const GENERATORS = [ - new Point( - new Fr(0x30426e64aee30e998c13c8ceecda3a77807dbead52bc2f3bf0eae851b4b710c1n), - new Fr(0x113156a068f603023240c96b4da5474667db3b8711c521c748212a15bc034ea6n), - false, - ), - new Point( - new Fr(0x2825c79cc6a5cbbeef7d6a8f1b6a12b312aa338440aefeb4396148c89147c049n), - new Fr(0x129bfd1da54b7062d6b544e7e36b90736350f6fba01228c41c72099509f5701en), - false, - ), - new Point( - new Fr(0x0edb1e293c3ce91bfc04e3ceaa50d2c541fa9d091c72eb403efb1cfa2cb3357fn), - new Fr(0x1341d675fa030ece3113ad53ca34fd13b19b6e9762046734f414824c4d6ade35n), - false, - ), - new Point( - new Fr(0x0e0dad2250583f2a9f0acb04ededf1701b85b0393cae753fe7e14b88af81cb52n), - new Fr(0x0973b02c5caac339ee4ad5dab51329920f7bf1b6a07e1dabe5df67040b300962n), - false, - ), - new Point( - new Fr(0x2f3342e900e8c488a28931aae68970738fdc68afde2910de7b320c00c902087dn), - new Fr(0x1bf958dc63cb09d59230603a0269ae86d6f92494da244910351f1132df20fc08n), - false, - ), -]; - -const G_SLOT = new Point( - new Fr(0x041223147b680850dc82e8a55a952d4df20256fe0593d949a9541ca00f0abf15n), - new Fr(0x0a8c72e60d0e60f5d804549d48f3044d06140b98ed717a9b532af630c1530791n), - false, -); - -/** - * Computes a note hiding point as is done by the default implementation injected by macros. - * @param storageSlot - The slot to which the note was inserted. - * @param noteContent - The note content (e.g. note.items). - * @returns A note hash. - */ -export function computeNoteHash(storageSlot: Fr, noteContent: Fr[]): Fr { - const grumpkin = new Grumpkin(); - const noteHidingPointBeforeSlotting = noteContent - .slice(1) - .reduce( - (acc, item, i) => grumpkin.add(acc, grumpkin.mul(GENERATORS[i + 1], new Fq(item.toBigInt()))), - grumpkin.mul(GENERATORS[0], new Fq(noteContent[0].toBigInt())), - ); - - const slotPoint = grumpkin.mul(G_SLOT, new Fq(storageSlot.toBigInt())); - const noteHidingPoint = grumpkin.add(noteHidingPointBeforeSlotting, slotPoint); - return noteHidingPoint.x; -}