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,32 +1,37 @@
import { ExtendedDirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
import { ExtendedDirectionalAppTaggingSecret, type TaggingIndexRange } from '@aztec/stdlib/logs';

/**
* A map that stores the tagging index for a given extended directional app tagging secret.
* A map that stores the tagging index range 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();
private taggingIndexMap: Map<string, { lowestIndex: number; highestIndex: number }> = new Map();

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

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}`);
if (currentValue !== undefined && currentValue.highestIndex !== index - 1) {
throw new Error(`Invalid tagging index update. Current value: ${currentValue.highestIndex}, new value: ${index}`);
}
if (currentValue !== undefined) {
currentValue.highestIndex = index;
} else {
this.taggingIndexMap.set(secret.toString(), { lowestIndex: index, highestIndex: index });
}
this.taggingIndexMap.set(secret.toString(), index);
}

/**
* Returns the pre-tags that were used in this execution (and that need to be stored in the db).
* Returns the tagging index ranges that were used in this execution (and that need to be stored in the db).
*/
public getUsedPreTags(): PreTag[] {
return Array.from(this.taggingIndexMap.entries()).map(([secret, index]) => ({
public getUsedTaggingIndexRanges(): TaggingIndexRange[] {
return Array.from(this.taggingIndexMap.entries()).map(([secret, { lowestIndex, highestIndex }]) => ({
extendedSecret: ExtendedDirectionalAppTaggingSecret.fromString(secret),
index,
lowestIndex,
highestIndex,
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function executePrivateFunction(
const newNotes = privateExecutionOracle.getNewNotes();
const noteHashNullifierCounterMap = privateExecutionOracle.getNoteHashNullifierCounterMap();
const offchainEffects = privateExecutionOracle.getOffchainEffects();
const preTags = privateExecutionOracle.getUsedPreTags();
const taggingIndexRanges = privateExecutionOracle.getUsedTaggingIndexRanges();
const nestedExecutionResults = privateExecutionOracle.getNestedExecutionResults();

let timerSubtractionList = nestedExecutionResults;
Expand All @@ -104,7 +104,7 @@ export async function executePrivateFunction(
noteHashNullifierCounterMap,
rawReturnValues,
offchainEffects,
preTags,
taggingIndexRanges,
nestedExecutionResults,
contractClassLogs,
{
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, ExtendedDirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
import { type ContractClassLog, ExtendedDirectionalAppTaggingSecret, type TaggingIndexRange } from '@aztec/stdlib/logs';
import { Tag } from '@aztec/stdlib/logs';
import { Note, type NoteStatus } from '@aztec/stdlib/note';
import {
Expand Down Expand Up @@ -166,10 +166,10 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
}

/**
* Returns the pre-tags that were used in this execution (and that need to be stored in the db).
* Returns the tagging index ranges that were used in this execution (and that need to be stored in the db).
*/
public getUsedPreTags(): PreTag[] {
return this.taggingIndexCache.getUsedPreTags();
public getUsedTaggingIndexRanges(): TaggingIndexRange[] {
return this.taggingIndexCache.getUsedTaggingIndexRanges();
}

/**
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/pxe/src/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,17 +766,17 @@ export class PXE {
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
// storing the tags here prevents linkage of txs sent from the same PXE.
const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
if (preTagsUsedInTheTx.length > 0) {
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
if (taggingIndexRangesUsedInTheTx.length > 0) {
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
const txHash = (await txProvingResult.toTx()).txHash;

await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
this.log.debug(`Stored used pre-tags as sender for the tx`, {
preTagsUsedInTheTx,
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
taggingIndexRangesUsedInTheTx,
});
} else {
this.log.debug(`No pre-tags used in the tx`);
this.log.debug(`No tagging index ranges used in the tx`);
}

return txProvingResult;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/storage/metadata.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PXE_DATA_SCHEMA_VERSION = 3;
export const PXE_DATA_SCHEMA_VERSION = 4;
Loading
Loading