Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { DirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
import { ExtendedDirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';

/**
* A map that stores the tagging index for a given directional app tagging secret.
* A map that stores the tagging index for a given extended directional app tagging secret.
* Note: The directional app tagging secret is unique for a (sender, recipient, contract) tuple while the direction
* of sender -> recipient matters.
*/
export class ExecutionTaggingIndexCache {
private taggingIndexMap: Map<string, number> = new Map();

public getLastUsedIndex(secret: DirectionalAppTaggingSecret): number | undefined {
public getLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret): number | undefined {
return this.taggingIndexMap.get(secret.toString());
}

public setLastUsedIndex(secret: DirectionalAppTaggingSecret, index: number) {
public setLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret, index: number) {
const currentValue = this.taggingIndexMap.get(secret.toString());
if (currentValue !== undefined && currentValue !== index - 1) {
throw new Error(`Invalid tagging index update. Current value: ${currentValue}, new value: ${index}`);
Expand All @@ -25,7 +25,7 @@ export class ExecutionTaggingIndexCache {
*/
public getUsedPreTags(): PreTag[] {
return Array.from(this.taggingIndexMap.entries()).map(([secret, index]) => ({
secret: DirectionalAppTaggingSecret.fromString(secret),
extendedSecret: ExtendedDirectionalAppTaggingSecret.fromString(secret),
index,
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { siloNullifier } from '@aztec/stdlib/hash';
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
import { type ContractClassLog, DirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
import { type ContractClassLog, ExtendedDirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
import { Tag } from '@aztec/stdlib/logs';
import { Note, type NoteStatus } from '@aztec/stdlib/note';
import {
Expand Down Expand Up @@ -216,25 +216,29 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
* @returns An app tag to be used in a log.
*/
public async privateGetNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Tag> {
const secret = await this.#calculateDirectionalAppTaggingSecret(this.contractAddress, sender, recipient);
const extendedSecret = await this.#calculateExtendedDirectionalAppTaggingSecret(
this.contractAddress,
sender,
recipient,
);

const index = await this.#getIndexToUseForSecret(secret);
const index = await this.#getIndexToUseForSecret(extendedSecret);
this.log.debug(
`Incrementing tagging index for sender: ${sender}, recipient: ${recipient}, contract: ${this.contractAddress} to ${index}`,
);
this.taggingIndexCache.setLastUsedIndex(secret, index);
this.taggingIndexCache.setLastUsedIndex(extendedSecret, index);

return Tag.compute({ secret, index });
return Tag.compute({ extendedSecret, index });
}

async #calculateDirectionalAppTaggingSecret(
async #calculateExtendedDirectionalAppTaggingSecret(
contractAddress: AztecAddress,
sender: AztecAddress,
recipient: AztecAddress,
) {
const senderCompleteAddress = await this.getCompleteAddressOrFail(sender);
const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
return DirectionalAppTaggingSecret.compute(
return ExtendedDirectionalAppTaggingSecret.compute(
senderCompleteAddress,
senderIvsk,
recipient,
Expand All @@ -243,7 +247,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
);
}

async #getIndexToUseForSecret(secret: DirectionalAppTaggingSecret): Promise<number> {
async #getIndexToUseForSecret(secret: ExtendedDirectionalAppTaggingSecret): Promise<number> {
// If we have the tagging index in the cache, we use it. If not we obtain it from the execution data provider.
const lastUsedIndexInTx = this.taggingIndexCache.getLastUsedIndex(secret);

Expand All @@ -255,7 +259,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
// that'd be wasteful as most tagging secrets are not used in each tx.
await syncSenderTaggingIndexes(
secret,
this.contractAddress,
this.aztecNode,
this.senderTaggingStore,
await this.anchorBlockHeader.hash(),
Expand Down
13 changes: 9 additions & 4 deletions yarn-project/pxe/src/logs/log_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundatio
import type { KeyStore } from '@aztec/key-store';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
import { DirectionalAppTaggingSecret, PendingTaggedLog, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
import {
ExtendedDirectionalAppTaggingSecret,
PendingTaggedLog,
SiloedTag,
Tag,
TxScopedL2Log,
} from '@aztec/stdlib/logs';
import type { BlockHeader } from '@aztec/stdlib/tx';

import type { AccessScopes } from '../access_scopes.js';
Expand Down Expand Up @@ -130,7 +136,6 @@ export class LogService {
secrets.map(secret =>
loadPrivateLogsForSenderRecipientPair(
secret,
contractAddress,
this.aztecNode,
this.recipientTaggingStore,
anchorBlockNumber,
Expand All @@ -154,7 +159,7 @@ export class LogService {
async #getSecretsForSenders(
contractAddress: AztecAddress,
recipient: AztecAddress,
): Promise<DirectionalAppTaggingSecret[]> {
): Promise<ExtendedDirectionalAppTaggingSecret[]> {
const recipientCompleteAddress = await this.addressStore.getCompleteAddress(recipient);
if (!recipientCompleteAddress) {
return [];
Expand All @@ -172,7 +177,7 @@ export class LogService {

return Promise.all(
deduplicatedSenders.map(sender => {
return DirectionalAppTaggingSecret.compute(
return ExtendedDirectionalAppTaggingSecret.compute(
recipientCompleteAddress,
recipientIvsk,
sender,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Fr } from '@aztec/foundation/curves/bn254';
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
import { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
import type { ExtendedDirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
import { randomExtendedDirectionalAppTaggingSecret } from '@aztec/stdlib/testing';

import { RecipientTaggingStore } from './recipient_tagging_store.js';

describe('RecipientTaggingStore', () => {
let taggingStore: RecipientTaggingStore;
let secret1: DirectionalAppTaggingSecret;
let secret2: DirectionalAppTaggingSecret;
let secret1: ExtendedDirectionalAppTaggingSecret;
let secret2: ExtendedDirectionalAppTaggingSecret;

beforeEach(async () => {
taggingStore = new RecipientTaggingStore(await openTmpStore('test'));
secret1 = DirectionalAppTaggingSecret.fromString(Fr.random().toString());
secret2 = DirectionalAppTaggingSecret.fromString(Fr.random().toString());
secret1 = await randomExtendedDirectionalAppTaggingSecret();
secret2 = await randomExtendedDirectionalAppTaggingSecret();
});

describe('staged writes', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
import type { ExtendedDirectionalAppTaggingSecret } from '@aztec/stdlib/logs';

import type { StagedStore } from '../../job_coordinator/job_coordinator.js';

Expand Down Expand Up @@ -106,11 +106,11 @@ export class RecipientTaggingStore implements StagedStore {
return Promise.resolve();
}

getHighestAgedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
getHighestAgedIndex(secret: ExtendedDirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
return this.#store.transactionAsync(() => this.#readHighestAgedIndex(jobId, secret.toString()));
}

updateHighestAgedIndex(secret: DirectionalAppTaggingSecret, index: number, jobId: string): Promise<void> {
updateHighestAgedIndex(secret: ExtendedDirectionalAppTaggingSecret, index: number, jobId: string): Promise<void> {
return this.#store.transactionAsync(async () => {
const currentIndex = await this.#readHighestAgedIndex(jobId, secret.toString());
if (currentIndex !== undefined && index <= currentIndex) {
Expand All @@ -121,11 +121,15 @@ export class RecipientTaggingStore implements StagedStore {
});
}

getHighestFinalizedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
getHighestFinalizedIndex(secret: ExtendedDirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
return this.#store.transactionAsync(() => this.#readHighestFinalizedIndex(jobId, secret.toString()));
}

updateHighestFinalizedIndex(secret: DirectionalAppTaggingSecret, index: number, jobId: string): Promise<void> {
updateHighestFinalizedIndex(
secret: ExtendedDirectionalAppTaggingSecret,
index: number,
jobId: string,
): Promise<void> {
return this.#store.transactionAsync(async () => {
const currentIndex = await this.#readHighestFinalizedIndex(jobId, secret.toString());
if (currentIndex !== undefined && index < currentIndex) {
Expand Down
Loading
Loading