Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Feb 18, 2025
1 parent 74ede22 commit cceedb2
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 152 deletions.
3 changes: 0 additions & 3 deletions yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ export abstract class BaseWallet implements Wallet {
addNote(note: ExtendedNote): Promise<void> {
return this.pxe.addNote(note, this.getAddress());
}
addNullifiedNote(note: ExtendedNote): Promise<void> {
return this.pxe.addNullifiedNote(note);
}
getBlock(number: number): Promise<L2Block | undefined> {
return this.pxe.getBlock(number);
}
Expand Down
8 changes: 0 additions & 8 deletions yarn-project/circuit-types/src/interfaces/pxe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ describe('PXESchema', () => {
await context.client.addNote(await ExtendedNote.random(), address);
});

it('addNullifiedNote', async () => {
await context.client.addNullifiedNote(await ExtendedNote.random());
});

it('getBlock', async () => {
const result = await context.client.getBlock(1);
expect(result).toBeInstanceOf(L2Block);
Expand Down Expand Up @@ -463,10 +459,6 @@ class MockPXE implements PXE {
expect(scope).toEqual(this.address);
return Promise.resolve();
}
addNullifiedNote(note: ExtendedNote): Promise<void> {
expect(note).toBeInstanceOf(ExtendedNote);
return Promise.resolve();
}
getBlock(number: number): Promise<L2Block | undefined> {
return Promise.resolve(L2Block.random(number));
}
Expand Down
11 changes: 0 additions & 11 deletions yarn-project/circuit-types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,6 @@ export interface PXE {
*/
addNote(note: ExtendedNote, scope?: AztecAddress): Promise<void>;

/**
* Adds a nullified note to the database.
* @throws If the note hash of the note doesn't exist in the tree.
* @param note - The note to add.
* @dev We are not deriving a nullifier in this function since that would require having the nullifier secret key
* which is undesirable. Instead, we are just adding the note to the database as nullified and the nullifier is set
* to 0 in the db.
*/
addNullifiedNote(note: ExtendedNote): Promise<void>;

/**
* Get the given block.
* @param number - The block number being requested.
Expand Down Expand Up @@ -520,7 +510,6 @@ export const PXESchema: ApiSchemaFor<PXE> = {
.args(z.number(), schemas.Fr)
.returns(z.tuple([schemas.BigInt, SiblingPath.schema])),
addNote: z.function().args(ExtendedNote.schema, optional(schemas.AztecAddress)).returns(z.void()),
addNullifiedNote: z.function().args(ExtendedNote.schema).returns(z.void()),
getBlock: z
.function()
.args(z.number())
Expand Down
46 changes: 0 additions & 46 deletions yarn-project/end-to-end/src/e2e_2_pxes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
sleep,
} from '@aztec/aztec.js';
import { ChildContract } from '@aztec/noir-contracts.js/Child';
import { TestContract } from '@aztec/noir-contracts.js/Test';
import { TokenContract } from '@aztec/noir-contracts.js/Token';

import { expect, jest } from '@jest/globals';
Expand Down Expand Up @@ -226,49 +225,4 @@ describe('e2e_2_pxes', () => {
await expectTokenBalance(walletB, token, walletB.getAddress(), transferAmount2, logger);
await expectTokenBalance(sharedWalletOnB, token, sharedAccountAddress, transferAmount1 - transferAmount2, logger);
});

it('adds and fetches a nullified note', async () => {
// 1. Deploys test contract through PXE A
const testContract = await TestContract.deploy(walletA).send().deployed();

// 2. Create a note
const noteStorageSlot = 10;
const noteValue = 5;
let note: ExtendedNote;
{
const owner = walletA.getAddress();
const sender = owner;

const receipt = await testContract.methods
.call_create_note(noteValue, owner, sender, noteStorageSlot)
.send()
.wait();
await testContract.methods.sync_notes().simulate();
const notes = await walletA.getNotes({ txHash: receipt.txHash });
expect(notes).toHaveLength(1);
note = notes[0];
}

// 3. Nullify the note
{
const receipt = await testContract.methods.call_destroy_note(noteStorageSlot).send().wait({ debug: true });
// Check that we got 2 nullifiers - 1 for tx hash, 1 for the note
expect(receipt.debugInfo?.nullifiers).toHaveLength(2);
}

// 4. Adds the nullified public key note to PXE B
{
// We need to register the contract to be able to compute the note hash by calling compute_note_hash_and_optionally_a_nullifier(...)
await pxeB.registerContract(testContract);
await pxeB.addNullifiedNote(note);
}

// 5. Try fetching the nullified note
{
const testContractWithWalletB = await TestContract.at(testContract.address, walletB);
const noteValue = await testContractWithWalletB.methods.call_get_notes(noteStorageSlot, true).simulate();
expect(noteValue).toBe(noteValue);
// --> We have successfully obtained the nullified note from PXE B verifying that pxe.addNullifiedNote(...) works
}
});
});
46 changes: 0 additions & 46 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ export class PXEService implements PXE {
nonce,
note.storageSlot,
note.noteTypeId,
true,
note.note,
);

Expand Down Expand Up @@ -424,50 +423,6 @@ export class PXEService implements PXE {
}
}

public async addNullifiedNote(note: ExtendedNote) {
const { data: nonces, l2BlockHash, l2BlockNumber } = await this.#getNoteNonces(note);
if (nonces.length === 0) {
throw new Error(`Cannot find the note in tx: ${note.txHash}.`);
}

for (const nonce of nonces) {
const { noteHash, uniqueNoteHash, innerNullifier } = await this.simulator.computeNoteHashAndOptionallyANullifier(
note.contractAddress,
nonce,
note.storageSlot,
note.noteTypeId,
false,
note.note,
);

if (!innerNullifier.equals(Fr.ZERO)) {
throw new Error('Unexpectedly received non-zero nullifier.');
}

const [index] = await this.node.findLeavesIndexes('latest', MerkleTreeId.NOTE_HASH_TREE, [uniqueNoteHash]);
if (index === undefined) {
throw new Error('Note does not exist.');
}

await this.db.addNullifiedNote(
new NoteDao(
note.note,
note.contractAddress,
note.storageSlot,
nonce,
noteHash,
Fr.ZERO, // We are not able to derive
note.txHash,
l2BlockNumber,
l2BlockHash,
index,
await note.owner.toAddressPoint(),
note.noteTypeId,
),
);
}
}

/**
* Finds the nonce(s) for a given note.
* @param note - The note to find the nonces for.
Expand Down Expand Up @@ -495,7 +450,6 @@ export class PXEService implements PXE {
nonce,
note.storageSlot,
note.noteTypeId,
false,
note.note,
);
if (hash.equals(uniqueNoteHash)) {
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/simulator/src/client/private_execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ describe('Private Execution test suite', () => {
nonce,
storageSlot,
valueNoteTypeId,
true,
note,
),
);
Expand Down Expand Up @@ -508,7 +507,6 @@ describe('Private Execution test suite', () => {
nonce,
storageSlot,
valueNoteTypeId,
true,
note,
),
);
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/simulator/src/client/simulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Simulator', () => {

const note = await createNote();
await expect(
simulator.computeNoteHashAndOptionallyANullifier(contractAddress, nonce, storageSlot, noteTypeId, true, note),
simulator.computeNoteHashAndOptionallyANullifier(contractAddress, nonce, storageSlot, noteTypeId, note),
).rejects.toThrow(/Mandatory implementation of "compute_note_hash_and_optionally_a_nullifier" missing/);
});

Expand All @@ -78,7 +78,7 @@ describe('Simulator', () => {
oracle.getFunctionArtifactByName.mockResolvedValue(modifiedArtifact);

await expect(
simulator.computeNoteHashAndOptionallyANullifier(contractAddress, nonce, storageSlot, noteTypeId, true, note),
simulator.computeNoteHashAndOptionallyANullifier(contractAddress, nonce, storageSlot, noteTypeId, note),
).rejects.toThrow(
new RegExp(
`Expected 6 parameters in mandatory implementation of "compute_note_hash_and_optionally_a_nullifier", but found 5 in noir contract ${contractAddress}.`,
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('Simulator', () => {
oracle.getFunctionArtifactByName.mockResolvedValue(modifiedArtifact);

await expect(
simulator.computeNoteHashAndOptionallyANullifier(contractAddress, nonce, storageSlot, noteTypeId, true, note),
simulator.computeNoteHashAndOptionallyANullifier(contractAddress, nonce, storageSlot, noteTypeId, note),
).rejects.toThrow(
new RegExp(
`"compute_note_hash_and_optionally_a_nullifier" can only handle a maximum of ${wrongPreimageLength} fields`,
Expand Down
37 changes: 4 additions & 33 deletions yarn-project/simulator/src/client/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,19 @@ export class AcirSimulator {
}

/**
* Computes the inner nullifier of a note.
* Computes the note hash and inner nullifier of a note.
* @param contractAddress - The address of the contract.
* @param nonce - The nonce of the note hash.
* @param storageSlot - The storage slot.
* @param noteTypeId - The note type identifier.
* @param computeNullifier - A flag indicating whether to compute the nullifier or just return 0.
* @param note - The note.
* @returns The nullifier.
* @returns The note hash (and intermediary forms) and inner nullifier.
*/
public async computeNoteHashAndOptionallyANullifier(
public async computeNoteHashAndNullifier(
contractAddress: AztecAddress,
nonce: Fr,
storageSlot: Fr,
noteTypeId: NoteSelector,
computeNullifier: boolean,
note: Note,
) {
const artifact: FunctionArtifact | undefined = await this.db.getFunctionArtifactByName(
Expand Down Expand Up @@ -212,14 +210,7 @@ export class AcirSimulator {
selector,
type: FunctionType.UNCONSTRAINED,
isStatic: artifact.isStatic,
args: encodeArguments(artifact, [
contractAddress,
nonce,
storageSlot,
noteTypeId,
computeNullifier,
extendedNoteItems,
]),
args: encodeArguments(artifact, [contractAddress, nonce, storageSlot, noteTypeId, true, extendedNoteItems]),
returnTypes: artifact.returnTypes,
};

Expand All @@ -237,24 +228,4 @@ export class AcirSimulator {
innerNullifier: new Fr(innerNullifier),
};
}

/**
* Computes a hash of the note.
* @param contractAddress - The address of the contract.
* @param storageSlot - The storage slot.
* @param noteTypeId - The note type identifier.
* @param note - The note.
* @returns The note hash.
*/
public async computeNoteHash(contractAddress: AztecAddress, storageSlot: Fr, noteTypeId: NoteSelector, note: Note) {
const { noteHash } = await this.computeNoteHashAndOptionallyANullifier(
contractAddress,
Fr.ZERO,
storageSlot,
noteTypeId,
false,
note,
);
return noteHash;
}
}

0 comments on commit cceedb2

Please sign in to comment.