From 5e33ed8cecb058db654fbcf448749d0fee7cbd5d Mon Sep 17 00:00:00 2001 From: esau <152162806+sklppy88@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:46:04 +0000 Subject: [PATCH] feat: use address book in recipient tag calculation (#9618) A simple refactor to use our address book instead of the complete address db (which was used before because we were using registerRecipient as a standin for the address book) when we calculate tags for getting our incoming notes from the node. --- .../pxe/src/simulator_oracle/index.ts | 19 ++++++++----------- .../simulator_oracle/simulator_oracle.test.ts | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 607514942cf..4d186f8441f 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -297,22 +297,19 @@ export class SimulatorOracle implements DBOracle { recipient: AztecAddress, ): Promise { const recipientCompleteAddress = await this.getCompleteAddress(recipient); - const completeAddresses = await this.db.getCompleteAddresses(); - // Filter out the addresses corresponding to accounts - const accounts = await this.keyStore.getAccounts(); - const senders = completeAddresses.filter( - completeAddress => !accounts.find(account => account.equals(completeAddress.address)), - ); const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient); - const secrets = senders.map(({ address: sender }) => { - const sharedSecret = computeTaggingSecret(recipientCompleteAddress, recipientIvsk, sender); + + // We implicitly add the recipient as a contact, this helps us decrypt tags on notes that we send to ourselves (recipient = us, sender = us) + const contacts = [...this.db.getContactAddresses(), recipient]; + const appTaggingSecrets = contacts.map(contact => { + const sharedSecret = computeTaggingSecret(recipientCompleteAddress, recipientIvsk, contact); return poseidon2Hash([sharedSecret.x, sharedSecret.y, contractAddress]); }); // Ensure the directionality (sender -> recipient) - const directionalSecrets = secrets.map(secret => new TaggingSecret(secret, recipient)); + const directionalSecrets = appTaggingSecrets.map(secret => new TaggingSecret(secret, recipient)); const indexes = await this.db.getTaggingSecretsIndexes(directionalSecrets); - return directionalSecrets.map( - ({ secret, recipient }, i) => new IndexedTaggingSecret(secret, recipient, indexes[i]), + return directionalSecrets.map((directionalSecret, i) => + IndexedTaggingSecret.fromTaggingSecret(directionalSecret, indexes[i]), ); } diff --git a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts index d9e8728ad95..af4cfcdcb2b 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -66,7 +66,7 @@ describe('Simulator oracle', () => { return { completeAddress, ivsk: keys.masterIncomingViewingSecretKey }; }); for (const sender of senders) { - await database.addCompleteAddress(sender.completeAddress); + await database.addContactAddress(sender.completeAddress.address); } const logs: { [k: string]: EncryptedL2NoteLog[] } = {};