Skip to content

Commit bcabcea

Browse files
committed
wip
1 parent 7b7de8e commit bcabcea

File tree

5 files changed

+69
-66
lines changed

5 files changed

+69
-66
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,36 @@ export interface ExecutionDataProvider {
214214
assertCompatibleOracleVersion(version: number): void;
215215

216216
/**
217-
* Returns the next app tag for a given sender and recipient pair.
217+
* Returns the next app tag for a given directional app tagging secret.
218+
* @param directionalAppTaggingSecret - The secret that's unique for (sender, recipient, contract) tuple while
219+
* direction of sender -> recipient matters.
220+
* @returns The computed tag.
221+
*/
222+
getNextAppTagAsSender(directionalAppTaggingSecret: Fr): Promise<Fr>;
223+
224+
/**
225+
* Calculates the directional app tagging secret for a given contract, sender and recipient.
218226
* @param contractAddress - The contract address to silo the secret for
219227
* @param sender - The address sending the note
220228
* @param recipient - The address receiving the note
221-
* @returns The computed tag.
229+
* @returns The directional app tagging secret
230+
*/
231+
calculateDirectionalAppTaggingSecret(
232+
contractAddress: AztecAddress,
233+
sender: AztecAddress,
234+
recipient: AztecAddress,
235+
): Promise<Fr>;
236+
237+
/**
238+
* Updates the local index of the shared tagging secret of a (sender, recipient, contract) tuple if a log with
239+
* a larger index is found from the node.
240+
* @param directionalAppTaggingSecret - The secret that's unique for (sender, recipient, contract) tuple while
241+
* direction of sender -> recipient matters.
242+
* @param contractAddress - The address of the contract that the logs are tagged for. Needs to be provided to store
243+
* because the function performs second round of siloing which is necessary because kernels do it as well (they silo
244+
* first field of the private log which corresponds to the tag).
222245
*/
223-
getNextAppTagAsSender(contractAddress: AztecAddress, sender: AztecAddress, recipient: AztecAddress): Promise<Fr>;
246+
syncTaggedLogsAsSender(directionalAppTaggingSecret: Fr, contractAddress: AztecAddress): Promise<void>;
224247

225248
/**
226249
* Synchronizes the private logs tagged with scoped addresses and all the senders in the address book. Stores the found

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,9 @@ describe('Private Execution test suite', () => {
301301
throw new Error(`Unknown address: ${address}. Recipient: ${recipient}, Owner: ${owner}`);
302302
});
303303

304-
executionDataProvider.getNextAppTagAsSender.mockImplementation(
305-
(_contractAddress: AztecAddress, _sender: AztecAddress, _recipient: AztecAddress) => {
306-
return Promise.resolve(Fr.random());
307-
},
308-
);
304+
executionDataProvider.getNextAppTagAsSender.mockImplementation((_directionalAppTaggingSecret: Fr) => {
305+
return Promise.resolve(Fr.random());
306+
});
309307
executionDataProvider.getFunctionArtifact.mockImplementation(async (address, selector) => {
310308
const contract = contracts[address.toString()];
311309
if (!contract) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,17 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
192192
* @returns An app tag to be used in a log.
193193
*/
194194
public async privateGetNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Fr> {
195-
return await this.executionDataProvider.getNextAppTagAsSender(this.contractAddress, sender, recipient);
195+
const directionalAppTaggingSecret = await this.executionDataProvider.calculateDirectionalAppTaggingSecret(
196+
this.contractAddress,
197+
sender,
198+
recipient,
199+
);
200+
201+
// TODO(benesjan): In a follow-up PR we will load here the index from the ExecutionTaggingIndexCache if present
202+
// and if not we will obtain it from the execution data provider.
203+
204+
await this.executionDataProvider.syncTaggedLogsAsSender(directionalAppTaggingSecret, this.contractAddress);
205+
return this.executionDataProvider.getNextAppTagAsSender(directionalAppTaggingSecret);
196206
}
197207

198208
/**

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

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -274,38 +274,29 @@ export class PXEOracleInterface implements ExecutionDataProvider {
274274
* @param sender - The address sending the note
275275
* @param recipient - The address receiving the note
276276
* @returns The computed tag.
277+
* TODO(benesjan): In a follow-up PR this will only return the index and that's it.
277278
*/
278-
public async getNextAppTagAsSender(
279-
contractAddress: AztecAddress,
280-
sender: AztecAddress,
281-
recipient: AztecAddress,
282-
): Promise<Fr> {
283-
await this.syncTaggedLogsAsSender(contractAddress, sender, recipient);
284-
285-
const directionalAppTaggingSecret = await this.#calculateDirectionalAppTaggingSecret(
286-
contractAddress,
287-
sender,
288-
recipient,
289-
);
290-
const [index] = await this.taggingDataProvider.getTaggingSecretsIndexesAsSender([directionalAppTaggingSecret]);
279+
public async getNextAppTagAsSender(directionalAppTaggingSecret: Fr): Promise<Fr> {
280+
const index = await this.taggingDataProvider.getTaggingSecretsIndexAsSender(directionalAppTaggingSecret);
291281

282+
// TODO(benesjan): This will be reworked in a follow-up PR where we will store the new indexes in the db once
283+
// the execution finishes (then we dump the contents of the ExecutionTaggingIndexCache into the db)
292284
// Increment the index for next time
293-
const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
294-
this.log.debug(`Incrementing app tagging secret at ${contractName}(${contractAddress})`, {
295-
directionalAppTaggingSecret,
296-
sender,
297-
recipient,
298-
contractName,
299-
contractAddress,
300-
});
301-
285+
// const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
286+
// this.log.debug(`Incrementing app tagging secret at ${contractName}(${contractAddress})`, {
287+
// directionalAppTaggingSecret,
288+
// sender,
289+
// recipient,
290+
// contractName,
291+
// contractAddress,
292+
// });
302293
await this.taggingDataProvider.setTaggingSecretIndexAsSender(directionalAppTaggingSecret, index + 1);
303294

304295
// Compute and return the tag using the current index
305296
return computeTag(directionalAppTaggingSecret, index);
306297
}
307298

308-
async #calculateDirectionalAppTaggingSecret(
299+
public async calculateDirectionalAppTaggingSecret(
309300
contractAddress: AztecAddress,
310301
sender: AztecAddress,
311302
recipient: AztecAddress,
@@ -359,26 +350,8 @@ export class PXEOracleInterface implements ExecutionDataProvider {
359350
}));
360351
}
361352

362-
/**
363-
* Updates the local index of the shared tagging secret of a sender / recipient pair
364-
* if a log with a larger index is found from the node.
365-
* @param contractAddress - The address of the contract that the logs are tagged for
366-
* @param sender - The address of the sender, we must know the sender's ivsk_m.
367-
* @param recipient - The address of the recipient.
368-
* TODO: This is used only withing PXEOracleInterface and tests so we most likely just want to hide this.
369-
*/
370-
public async syncTaggedLogsAsSender(
371-
contractAddress: AztecAddress,
372-
sender: AztecAddress,
373-
recipient: AztecAddress,
374-
): Promise<void> {
375-
const directionalAppTaggingSecret = await this.#calculateDirectionalAppTaggingSecret(
376-
contractAddress,
377-
sender,
378-
recipient,
379-
);
380-
381-
const [oldIndex] = await this.taggingDataProvider.getTaggingSecretsIndexesAsSender([directionalAppTaggingSecret]);
353+
public async syncTaggedLogsAsSender(directionalAppTaggingSecret: Fr, contractAddress: AztecAddress): Promise<void> {
354+
const oldIndex = await this.taggingDataProvider.getTaggingSecretsIndexAsSender(directionalAppTaggingSecret);
382355

383356
// This algorithm works such that:
384357
// 1. If we find minimum consecutive empty logs in a window of logs we set the index to the index of the last log
@@ -417,15 +390,18 @@ export class PXEOracleInterface implements ExecutionDataProvider {
417390
if (currentIndex !== oldIndex) {
418391
await this.taggingDataProvider.setTaggingSecretIndexAsSender(directionalAppTaggingSecret, currentIndex);
419392

420-
this.log.debug(`Syncing logs for sender ${sender} at contract ${contractName}(${contractAddress})`, {
421-
sender,
422-
secret: directionalAppTaggingSecret,
423-
index: currentIndex,
424-
contractName,
425-
contractAddress,
426-
});
393+
this.log.debug(
394+
`Syncing logs for secret ${directionalAppTaggingSecret.toString()} at contract ${contractName}(${contractAddress})`,
395+
{
396+
index: currentIndex,
397+
contractName,
398+
contractAddress,
399+
},
400+
);
427401
} else {
428-
this.log.debug(`No new logs found for sender ${sender} at contract ${contractName}(${contractAddress})`);
402+
this.log.debug(
403+
`No new logs found for secret ${directionalAppTaggingSecret.toString()} at contract ${contractName}(${contractAddress})`,
404+
);
429405
}
430406
}
431407

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ export class TaggingDataProvider {
3636
);
3737
}
3838

39-
getTaggingSecretsIndexesAsSender(directionalAppTaggingSecrets: Fr[]): Promise<number[]> {
40-
return Promise.all(
41-
directionalAppTaggingSecrets.map(
42-
async secret => (await this.#taggingSecretIndexesForSenders.getAsync(secret.toString())) ?? 0,
43-
),
44-
);
39+
async getTaggingSecretsIndexAsSender(directionalAppTaggingSecret: Fr): Promise<number> {
40+
return (await this.#taggingSecretIndexesForSenders.getAsync(directionalAppTaggingSecret.toString())) ?? 0;
4541
}
4642

4743
getTaggingSecretsIndexesAsRecipient(directionalAppTaggingSecrets: Fr[]): Promise<number[]> {

0 commit comments

Comments
 (0)