diff --git a/yarn-project/pxe/src/database/deferred_note_dao.test.ts b/yarn-project/pxe/src/database/deferred_note_dao.test.ts index d3c1e5d520b6..00ede18ca9cb 100644 --- a/yarn-project/pxe/src/database/deferred_note_dao.test.ts +++ b/yarn-project/pxe/src/database/deferred_note_dao.test.ts @@ -5,7 +5,7 @@ import { randomInt } from '@aztec/foundation/crypto'; import { DeferredNoteDao } from './deferred_note_dao.js'; export const randomDeferredNoteDao = ({ - publicKey = Point.random(), + ivpkM = Point.random(), note = Note.random(), contractAddress = AztecAddress.random(), txHash = randomTxHash(), @@ -15,7 +15,7 @@ export const randomDeferredNoteDao = ({ dataStartIndexForTx = randomInt(100), }: Partial = {}) => { return new DeferredNoteDao( - publicKey, + ivpkM, note, contractAddress, storageSlot, diff --git a/yarn-project/pxe/src/database/deferred_note_dao.ts b/yarn-project/pxe/src/database/deferred_note_dao.ts index d45d179e5b28..0851f4dadcf1 100644 --- a/yarn-project/pxe/src/database/deferred_note_dao.ts +++ b/yarn-project/pxe/src/database/deferred_note_dao.ts @@ -9,8 +9,11 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; */ export class DeferredNoteDao { constructor( - /** The public key associated with this note */ - public publicKey: PublicKey, + /** + * The incoming viewing public key the note was encrypted with. + * @dev Will never be ovpkM because there are no deferred notes for outgoing. + */ + public ivpkM: PublicKey, /** The note as emitted from the Noir contract. */ public note: Note, /** The contract address this note is created in. */ @@ -29,7 +32,7 @@ export class DeferredNoteDao { toBuffer(): Buffer { return serializeToBuffer( - this.publicKey, + this.ivpkM, this.note, this.contractAddress, this.storageSlot, diff --git a/yarn-project/pxe/src/database/pxe_database_test_suite.ts b/yarn-project/pxe/src/database/pxe_database_test_suite.ts index b02ce9c8948e..3095494580a0 100644 --- a/yarn-project/pxe/src/database/pxe_database_test_suite.ts +++ b/yarn-project/pxe/src/database/pxe_database_test_suite.ts @@ -68,7 +68,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { }); }); - describe('notes', () => { + describe('incoming notes', () => { let owners: CompleteAddress[]; let contractAddresses: AztecAddress[]; let storageSlots: Fr[]; @@ -198,6 +198,8 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { }); }); + // TODO(#6867): Add tests for outgoing notes + describe('block header', () => { it('stores and retrieves the block header', async () => { const header = makeHeader(randomInt(1000), INITIAL_L2_BLOCK_NUM); diff --git a/yarn-project/pxe/src/note_processor/note_processor.test.ts b/yarn-project/pxe/src/note_processor/note_processor.test.ts index 561f5acac1c0..b3dde087d1ae 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -29,7 +29,7 @@ import { NoteProcessor } from './note_processor.js'; const TXS_PER_BLOCK = 4; const NUM_NOTE_HASHES_PER_BLOCK = TXS_PER_BLOCK * MAX_NEW_NOTE_HASHES_PER_TX; -/** A wrapper containing info about a note we want to mock and insert into a block */ +/** A wrapper containing info about a note we want to mock and insert into a block. */ class MockNoteRequest { constructor( /** Note we want to insert into a block. */ @@ -125,17 +125,15 @@ describe('Note Processor', () => { beforeAll(() => { const ownerSk = Fr.random(); const partialAddress = Fr.random(); - account = CompleteAddress.fromSecretKeyAndPartialAddress(ownerSk, partialAddress); - const allOwnerKeys = deriveKeys(ownerSk); + account = CompleteAddress.fromSecretKeyAndPartialAddress(ownerSk, partialAddress); + ownerIvpkM = account.publicKeys.masterIncomingViewingPublicKey; - ownerIvpkM = allOwnerKeys.publicKeys.masterIncomingViewingPublicKey; - ownerIvskM = allOwnerKeys.masterIncomingViewingSecretKey; + ({ masterIncomingViewingSecretKey: ownerIvskM, masterOutgoingViewingSecretKey: ownerOvskM } = deriveKeys(ownerSk)); - ownerOvskM = allOwnerKeys.masterOutgoingViewingSecretKey; ownerOvKeys = new KeyValidationRequest( - allOwnerKeys.publicKeys.masterOutgoingViewingPublicKey, - computeOvskApp(allOwnerKeys.masterOutgoingViewingSecretKey, app), + account.publicKeys.masterOutgoingViewingPublicKey, + computeOvskApp(ownerOvskM, app), ); }); diff --git a/yarn-project/pxe/src/note_processor/note_processor.ts b/yarn-project/pxe/src/note_processor/note_processor.ts index 542f603d7311..fa1b6ccb21b3 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.ts @@ -278,35 +278,29 @@ export class NoteProcessor { * Retry decoding the given deferred notes because we now have the contract code. * * @param deferredNoteDaos - notes that we have previously deferred because the contract was not found - * @returns An array of NoteDaos that were successfully decoded. + * @returns An array of incoming notes that were successfully decoded. * * @remarks Caller is responsible for making sure that we have the contract for the * deferred notes provided: we will not retry notes that fail again. */ - public async decodeDeferredNotes( - deferredNoteDaos: DeferredNoteDao[], - ): Promise<{ incomingNotes: IncomingNoteDao[]; outgoingNotes: OutgoingNoteDao[] }> { + public async decodeDeferredNotes(deferredNoteDaos: DeferredNoteDao[]): Promise { const excludedIndices: Set = new Set(); const incomingNotes: IncomingNoteDao[] = []; - const outgoingNotes: OutgoingNoteDao[] = []; for (const deferredNote of deferredNoteDaos) { - const { publicKey, note, contractAddress, storageSlot, noteTypeId, txHash, newNoteHashes, dataStartIndexForTx } = + const { ivpkM, note, contractAddress, storageSlot, noteTypeId, txHash, newNoteHashes, dataStartIndexForTx } = deferredNote; const payload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId); - const isIncoming = publicKey.equals(this.ivpkM); - const isOutgoing = publicKey.equals(this.ovpkM); - - if (!isIncoming && !isOutgoing) { + if (!ivpkM.equals(this.ivpkM)) { // The note is not for this account, so we skip it. continue; } - const { incomingNote, outgoingNote } = await produceNoteDaos( + const { incomingNote } = await produceNoteDaos( this.simulator, - isIncoming ? this.ivpkM : undefined, - isOutgoing ? this.ovpkM : undefined, + this.ivpkM, + undefined, payload, txHash, newNoteHashes, @@ -315,16 +309,14 @@ export class NoteProcessor { this.log, ); - if (incomingNote) { - incomingNotes.push(incomingNote); - this.stats.decrypted++; - } - if (outgoingNote) { - outgoingNotes.push(outgoingNote); - this.stats.decrypted++; + if (!incomingNote) { + throw new Error('Deferred note could not be decoded.'); } + + incomingNotes.push(incomingNote); + this.stats.decrypted++; } - return { incomingNotes, outgoingNotes }; + return incomingNotes; } } diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index fd6181132de6..475d902531e0 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -345,20 +345,18 @@ export class Synchronizer { // keep track of decoded notes const incomingNotes: IncomingNoteDao[] = []; - const outgoingNotes: OutgoingNoteDao[] = []; // now process each txHash for (const deferredNotes of txHashToDeferredNotes.values()) { // to be safe, try each note processor in case the deferred notes are for different accounts. for (const processor of this.noteProcessors) { const notes = await processor.decodeDeferredNotes(deferredNotes); - incomingNotes.push(...notes.incomingNotes); - outgoingNotes.push(...notes.outgoingNotes); + incomingNotes.push(...notes); } } // now drop the deferred notes, and add the decoded notes await this.db.removeDeferredNotesByContract(contractAddress); - await this.db.addNotes(incomingNotes, outgoingNotes); + await this.db.addNotes(incomingNotes, []); incomingNotes.forEach(noteDao => { this.log.debug(