Skip to content

Commit 778aeaa

Browse files
committed
refactor: renaming IndexedTaggingSecret as PreTag
1 parent 3b0d5e2 commit 778aeaa

File tree

14 files changed

+76
-71
lines changed

14 files changed

+76
-71
lines changed

yarn-project/pxe/src/contract_function_simulator/execution_tagging_index_cache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DirectionalAppTaggingSecret, type IndexedTaggingSecret } from '@aztec/stdlib/logs';
1+
import { DirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
22

33
/**
44
* A map that stores the tagging index for a given directional app tagging secret.
@@ -21,9 +21,9 @@ export class ExecutionTaggingIndexCache {
2121
}
2222

2323
/**
24-
* Returns the indexed tagging secrets that were used in this execution.
24+
* Returns the pre tags that were used in this execution (and that need to be stored in the db).
2525
*/
26-
public getUsedIndexedTaggingSecrets(): IndexedTaggingSecret[] {
26+
public getUsedPreTags(): PreTag[] {
2727
return Array.from(this.taggingIndexMap.entries()).map(([secret, index]) => ({
2828
secret: DirectionalAppTaggingSecret.fromString(secret),
2929
index,

yarn-project/pxe/src/contract_function_simulator/oracle/private_execution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function executePrivateFunction(
8888
const newNotes = privateExecutionOracle.getNewNotes();
8989
const noteHashNullifierCounterMap = privateExecutionOracle.getNoteHashNullifierCounterMap();
9090
const offchainEffects = privateExecutionOracle.getOffchainEffects();
91-
const indexedTaggingSecrets = privateExecutionOracle.getUsedIndexedTaggingSecrets();
91+
const preTags = privateExecutionOracle.getUsedPreTags();
9292
const nestedExecutionResults = privateExecutionOracle.getNestedExecutionResults();
9393

9494
let timerSubtractionList = nestedExecutionResults;
@@ -112,7 +112,7 @@ export async function executePrivateFunction(
112112
noteHashNullifierCounterMap,
113113
rawReturnValues,
114114
offchainEffects,
115-
indexedTaggingSecrets,
115+
preTags,
116116
nestedExecutionResults,
117117
contractClassLogs,
118118
{

yarn-project/pxe/src/contract_function_simulator/oracle/private_execution_oracle.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
1414
import { AztecAddress } from '@aztec/stdlib/aztec-address';
1515
import { computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
1616
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
17-
import type { ContractClassLog, DirectionalAppTaggingSecret, IndexedTaggingSecret } from '@aztec/stdlib/logs';
17+
import type { ContractClassLog, DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
1818
import { Note, type NoteStatus } from '@aztec/stdlib/note';
1919
import {
2020
type BlockHeader,
@@ -152,10 +152,10 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
152152
}
153153

154154
/**
155-
* Returns the indexed tagging secrets that were used in this execution.
155+
* Returns the pre tags that were used in this execution (and that need to be stored in the db).
156156
*/
157-
public getUsedIndexedTaggingSecrets(): IndexedTaggingSecret[] {
158-
return this.taggingIndexCache.getUsedIndexedTaggingSecrets();
157+
public getUsedPreTags(): PreTag[] {
158+
return this.taggingIndexCache.getUsedPreTags();
159159
}
160160

161161
/**

yarn-project/pxe/src/contract_function_simulator/pxe_oracle_interface.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ import {
4646
SiloedTag,
4747
Tag,
4848
WINDOW_HALF_SIZE,
49-
getIndexedTaggingSecretsForTheWindow,
5049
getInitialIndexesMap,
50+
getPreTagsForTheWindow,
5151
} from '../tagging/index.js';
5252
import { EventValidationRequest } from './noir-structs/event_validation_request.js';
5353
import { LogRetrievalRequest } from './noir-structs/log_retrieval_request.js';
@@ -289,15 +289,19 @@ export class PXEOracleInterface implements ExecutionDataProvider {
289289
}
290290

291291
/**
292-
* Returns the indexed tagging secrets for a given recipient and all the senders in the address book
292+
* Returns the last used tagging indexes along with the directional app tagging secrets for a given recipient and all
293+
* the senders in the address book.
293294
* This method should be exposed as an oracle call to allow aztec.nr to perform the orchestration
294295
* of the syncTaggedLogs and processTaggedLogs methods. However, it is not possible to do so at the moment,
295296
* so we're keeping it private for now.
296297
* @param contractAddress - The contract address to silo the secret for
297298
* @param recipient - The address receiving the notes
298-
* @returns A list of indexed tagging secrets. If the corresponding secret was never used, the index is undefined.
299+
* @returns A list of directional app tagging secrets along with the last used tagging indexes. If the corresponding
300+
* secret was never used, the index is undefined.
301+
* TODO(benesjan): The naming here is broken as the function name does not reflect the return type. Fix when associating
302+
* indexes with tx hash.
299303
*/
300-
async #getLastUsedIndexedTaggingSecretsForSenders(
304+
async #getLastUsedTaggingIndexesForSenders(
301305
contractAddress: AztecAddress,
302306
recipient: AztecAddress,
303307
): Promise<{ secret: DirectionalAppTaggingSecret; index: number | undefined }[]> {
@@ -425,7 +429,7 @@ export class PXEOracleInterface implements ExecutionDataProvider {
425429
const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
426430
for (const recipient of recipients) {
427431
// Get all the secrets for the recipient and sender pairs (#9365)
428-
const indexedSecrets = await this.#getLastUsedIndexedTaggingSecretsForSenders(contractAddress, recipient);
432+
const indexedSecrets = await this.#getLastUsedTaggingIndexesForSenders(contractAddress, recipient);
429433

430434
// We fetch logs for a window of indexes in a range:
431435
// <latest_log_index - WINDOW_HALF_SIZE, latest_log_index + WINDOW_HALF_SIZE>.
@@ -459,10 +463,10 @@ export class PXEOracleInterface implements ExecutionDataProvider {
459463
const initialIndexesMap = getInitialIndexesMap(indexedSecrets);
460464

461465
while (secretsAndWindows.length > 0) {
462-
const secretsForTheWholeWindow = getIndexedTaggingSecretsForTheWindow(secretsAndWindows);
466+
const preTagsForTheWholeWindow = getPreTagsForTheWindow(secretsAndWindows);
463467
const tagsForTheWholeWindow = await Promise.all(
464-
secretsForTheWholeWindow.map(async indexedSecret => {
465-
return SiloedTag.compute(await Tag.compute(indexedSecret), contractAddress);
468+
preTagsForTheWholeWindow.map(async preTag => {
469+
return SiloedTag.compute(await Tag.compute(preTag), contractAddress);
466470
}),
467471
);
468472

@@ -495,25 +499,25 @@ export class PXEOracleInterface implements ExecutionDataProvider {
495499
filteredLogsByBlockNumber,
496500
);
497501

498-
// We retrieve the indexed tagging secret corresponding to the log as I need that to evaluate whether
502+
// We retrieve the pre tag corresponding to the log as I need that to evaluate whether
499503
// a new largest index have been found.
500-
const secretCorrespondingToLog = secretsForTheWholeWindow[logIndex];
501-
const initialIndex = initialIndexesMap[secretCorrespondingToLog.secret.toString()];
504+
const preTagCorrespondingToLog = preTagsForTheWholeWindow[logIndex];
505+
const initialIndex = initialIndexesMap[preTagCorrespondingToLog.secret.toString()];
502506

503507
if (
504-
secretCorrespondingToLog.index >= initialIndex &&
505-
(newLargestIndexMapForIteration[secretCorrespondingToLog.secret.toString()] === undefined ||
506-
secretCorrespondingToLog.index >=
507-
newLargestIndexMapForIteration[secretCorrespondingToLog.secret.toString()])
508+
preTagCorrespondingToLog.index >= initialIndex &&
509+
(newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()] === undefined ||
510+
preTagCorrespondingToLog.index >=
511+
newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()])
508512
) {
509513
// We have found a new largest index so we store it for later processing (storing it in the db + fetching
510514
// the difference of the window sets of current and the next iteration)
511-
newLargestIndexMapForIteration[secretCorrespondingToLog.secret.toString()] =
512-
secretCorrespondingToLog.index + 1;
515+
newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()] =
516+
preTagCorrespondingToLog.index + 1;
513517

514518
this.log.debug(
515519
`Incrementing index to ${
516-
secretCorrespondingToLog.index + 1
520+
preTagCorrespondingToLog.index + 1
517521
} at contract ${contractName}(${contractAddress})`,
518522
);
519523
}

yarn-project/pxe/src/pxe.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -742,14 +742,14 @@ export class PXE {
742742
nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
743743
});
744744

745-
const indexedTaggingSecretsIncrementedInTheTx = privateExecutionResult.entrypoint.indexedTaggingSecrets;
746-
if (indexedTaggingSecretsIncrementedInTheTx.length > 0) {
747-
await this.taggingDataProvider.setLastUsedIndexesAsSender(indexedTaggingSecretsIncrementedInTheTx);
748-
this.log.debug(`Stored last used tagging secret indexes as sender for the tx`, {
749-
indexedTaggingSecretsIncrementedInTheTx,
745+
const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
746+
if (preTagsUsedInTheTx.length > 0) {
747+
await this.taggingDataProvider.setLastUsedIndexesAsSender(preTagsUsedInTheTx);
748+
this.log.debug(`Stored used pre tags as sender for the tx`, {
749+
preTagsUsedInTheTx,
750750
});
751751
} else {
752-
this.log.debug(`No tagging secret indexes incremented in the tx`);
752+
this.log.debug(`No pre tags used in the tx`);
753753
}
754754

755755
return txProvingResult;

yarn-project/pxe/src/storage/tagging_data_provider/tagging_data_provider.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { toArray } from '@aztec/foundation/iterable';
22
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
33
import { AztecAddress } from '@aztec/stdlib/aztec-address';
4-
import type { DirectionalAppTaggingSecret, IndexedTaggingSecret } from '@aztec/stdlib/logs';
4+
import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
55

66
export class TaggingDataProvider {
77
#store: AztecAsyncKVStore;
@@ -23,34 +23,37 @@ export class TaggingDataProvider {
2323

2424
/**
2525
* Sets the last used indexes when sending a log.
26-
* @param indexedSecrets - The indexed secrets to set the last used indexes for.
27-
* @throws If there are duplicate secrets in the input array
26+
* @param preTags - The pre tags containing the directional app tagging secrets and the indexes that are to be
27+
* updated in the db.
28+
* @throws If any two pre tags contain the same directional app tagging secret
2829
*/
29-
setLastUsedIndexesAsSender(indexedSecrets: IndexedTaggingSecret[]) {
30-
this.#assertUniqueSecrets(indexedSecrets, 'sender');
30+
setLastUsedIndexesAsSender(preTags: PreTag[]) {
31+
this.#assertUniqueSecrets(preTags, 'sender');
3132

3233
return Promise.all(
33-
indexedSecrets.map(({ secret, index }) => this.#lastUsedIndexesAsSenders.set(secret.toString(), index)),
34+
preTags.map(({ secret, index }) => this.#lastUsedIndexesAsSenders.set(secret.toString(), index)),
3435
);
3536
}
3637

3738
/**
3839
* Sets the last used indexes when looking for logs.
39-
* @param indexedSecrets - The indexed secrets to set the last used indexes for.
40-
* @throws If there are duplicate secrets in the input array
40+
* @param preTags - The pre tags containing the directional app tagging secrets and the indexes that are to be
41+
* updated in the db.
42+
* @throws If any two pre tags contain the same directional app tagging secret
4143
*/
42-
setLastUsedIndexesAsRecipient(indexedSecrets: IndexedTaggingSecret[]) {
43-
this.#assertUniqueSecrets(indexedSecrets, 'recipient');
44+
setLastUsedIndexesAsRecipient(preTags: PreTag[]) {
45+
this.#assertUniqueSecrets(preTags, 'recipient');
4446

4547
return Promise.all(
46-
indexedSecrets.map(({ secret, index }) => this.#lastUsedIndexesAsRecipients.set(secret.toString(), index)),
48+
preTags.map(({ secret, index }) => this.#lastUsedIndexesAsRecipients.set(secret.toString(), index)),
4749
);
4850
}
4951

50-
// It should never happen that we would receive a duplicate secrets on the input of the setters as everywhere
51-
// we always just apply the largest index. Hence this check is a good way to catch bugs.
52-
#assertUniqueSecrets(indexedSecrets: IndexedTaggingSecret[], role: 'sender' | 'recipient'): void {
53-
const secretStrings = indexedSecrets.map(({ secret }) => secret.toString());
52+
// It should never happen that we would receive any two pre tags on the input containing the same directional app
53+
// tagging secret as everywhere we always just apply the largest index. Hence this check is a good way to catch
54+
// bugs.
55+
#assertUniqueSecrets(preTags: PreTag[], role: 'sender' | 'recipient'): void {
56+
const secretStrings = preTags.map(({ secret }) => secret.toString());
5457
const uniqueSecrets = new Set(secretStrings);
5558
if (uniqueSecrets.size !== secretStrings.length) {
5659
throw new Error(`Duplicate secrets found when setting last used indexes as ${role}`);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
// Half the size of the window we slide over the tagging secret indexes.
1+
// Half the size of the window we slide over the tagging indexes.
22
export const WINDOW_HALF_SIZE = 10;

yarn-project/pxe/src/tagging/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export * from './constants.js';
33
export * from './siloed_tag.js';
44
export * from './utils.js';
55
export { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
6-
export { type IndexedTaggingSecret } from '@aztec/stdlib/logs';
6+
export { type PreTag } from '@aztec/stdlib/logs';
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { poseidon2Hash } from '@aztec/foundation/crypto';
22
import type { Fr } from '@aztec/foundation/fields';
3-
import type { IndexedTaggingSecret } from '@aztec/stdlib/logs';
3+
import type { PreTag } from '@aztec/stdlib/logs';
44

55
/**
66
* Represents a tag of a private log. This is not the tag that "appears" on the chain as this tag is first siloed
@@ -9,8 +9,8 @@ import type { IndexedTaggingSecret } from '@aztec/stdlib/logs';
99
export class Tag {
1010
private constructor(public readonly value: Fr) {}
1111

12-
static async compute(indexedTaggingSecret: IndexedTaggingSecret): Promise<Tag> {
13-
const tag = await poseidon2Hash([indexedTaggingSecret.secret.value, indexedTaggingSecret.index]);
12+
static async compute(preTag: PreTag): Promise<Tag> {
13+
const tag = await poseidon2Hash([preTag.secret.value, preTag.index]);
1414
return new Tag(tag);
1515
}
1616
}

yarn-project/pxe/src/tagging/utils.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { DirectionalAppTaggingSecret, IndexedTaggingSecret } from '@aztec/stdlib/logs';
1+
import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
22

33
// TODO(benesjan): Make this return tags instead - this will moves some complexity from syncTaggedLogs
4-
export function getIndexedTaggingSecretsForTheWindow(
4+
export function getPreTagsForTheWindow(
55
secretsAndWindows: { secret: DirectionalAppTaggingSecret; leftMostIndex: number; rightMostIndex: number }[],
6-
): IndexedTaggingSecret[] {
6+
): PreTag[] {
77
const secrets = [];
88
for (const secretAndWindow of secretsAndWindows) {
99
for (let i = secretAndWindow.leftMostIndex; i <= secretAndWindow.rightMostIndex; i++) {
@@ -15,18 +15,16 @@ export function getIndexedTaggingSecretsForTheWindow(
1515

1616
/**
1717
* Creates a map from directional app tagging secret to initial index.
18-
* @param indexedTaggingSecrets - The indexed tagging secrets to get the initial indexes from.
18+
* @param preTags - The pre tags to get the initial indexes map from.
1919
* @returns The map from directional app tagging secret to initial index.
2020
*/
21-
export function getInitialIndexesMap(
22-
indexedTaggingSecrets: { secret: DirectionalAppTaggingSecret; index: number | undefined }[],
23-
): {
21+
export function getInitialIndexesMap(preTags: { secret: DirectionalAppTaggingSecret; index: number | undefined }[]): {
2422
[k: string]: number;
2523
} {
2624
const initialIndexes: { [k: string]: number } = {};
2725

28-
for (const indexedTaggingSecret of indexedTaggingSecrets) {
29-
initialIndexes[indexedTaggingSecret.secret.toString()] = indexedTaggingSecret.index ?? 0;
26+
for (const preTag of preTags) {
27+
initialIndexes[preTag.secret.toString()] = preTag.index ?? 0;
3028
}
3129

3230
return initialIndexes;

0 commit comments

Comments
 (0)