Skip to content

Commit

Permalink
feat: use address book in recipient tag calculation (#9618)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sklppy88 authored Nov 1, 2024
1 parent a776f1e commit 5e33ed8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,19 @@ export class SimulatorOracle implements DBOracle {
recipient: AztecAddress,
): Promise<IndexedTaggingSecret[]> {
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]),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[] } = {};
Expand Down

0 comments on commit 5e33ed8

Please sign in to comment.