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
Expand Up @@ -5,10 +5,12 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
import type { L2Block } from '@aztec/stdlib/block';
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
import type { NoteStatus } from '@aztec/stdlib/note';
import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
import type { BlockHeader, NodeStats } from '@aztec/stdlib/tx';

import type { Tag } from '../tagging/tag.js';
import type { NoteData } from './oracle/interfaces.js';
import type { MessageLoadOracleInputs } from './oracle/message_load_oracle_inputs.js';

Expand Down Expand Up @@ -214,13 +216,36 @@ export interface ExecutionDataProvider {
assertCompatibleOracleVersion(version: number): void;

/**
* Returns the next app tag for a given sender and recipient pair.
* Calculates the directional app tagging secret for a given contract, sender and recipient.
* @param contractAddress - The contract address to silo the secret for
* @param sender - The address sending the note
* @param recipient - The address receiving the note
* @returns The directional app tagging secret
*/
calculateDirectionalAppTaggingSecret(
contractAddress: AztecAddress,
sender: AztecAddress,
recipient: AztecAddress,
): Promise<DirectionalAppTaggingSecret>;

/**
* Updates the local index of the shared tagging secret of a (sender, recipient, contract) tuple if a log with
* a larger index is found from the node.
* @param secret - The secret that's unique for (sender, recipient, contract) tuple while the direction
* of sender -> recipient matters.
* @param contractAddress - The address of the contract that the logs are tagged for. Needs to be provided to store
* because the function performs second round of siloing which is necessary because kernels do it as well (they silo
* first field of the private log which corresponds to the tag).
*/
syncTaggedLogsAsSender(secret: DirectionalAppTaggingSecret, contractAddress: AztecAddress): Promise<void>;

/**
* Returns the next app tag for a given directional app tagging secret.
* @param secret - The secret that's unique for (sender, recipient, contract) tuple while
* direction of sender -> recipient matters.
* @returns The computed tag.
*/
getNextAppTagAsSender(contractAddress: AztecAddress, sender: AztecAddress, recipient: AztecAddress): Promise<Fr>;
getNextAppTagAsSender(secret: DirectionalAppTaggingSecret): Promise<Tag>;

/**
* Synchronizes the private logs tagged with scoped addresses and all the senders in the address book. Stores the found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Note, NoteStatus } from '@aztec/stdlib/note';
import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
import type { BlockHeader } from '@aztec/stdlib/tx';

import type { Tag } from '../../tagging/tag.js';
import type { UtilityContext } from '../noir-structs/utility_context.js';
import type { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';

Expand Down Expand Up @@ -154,6 +155,6 @@ export interface IPrivateExecutionOracle {
privateNotifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): Promise<void>;
privateGetSenderForTags(): Promise<AztecAddress | undefined>;
privateSetSenderForTags(senderForTags: AztecAddress): Promise<void>;
privateGetNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Fr>;
privateGetNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Tag>;
utilityEmitOffchainEffect(data: Fr[]): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ export class Oracle {
AztecAddress.fromString(sender),
AztecAddress.fromString(recipient),
);
return [toACVMField(tag)];
return [toACVMField(tag.value)];
}

async utilityFetchTaggedLogs([pendingTaggedLogArrayBaseSlot]: ACVMField[]): Promise<ACVMField[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
} from '@aztec/stdlib/hash';
import { KeyValidationRequest } from '@aztec/stdlib/kernel';
import { computeAppNullifierSecretKey, deriveKeys } from '@aztec/stdlib/keys';
import { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
import { L1Actor, L1ToL2Message, L2Actor } from '@aztec/stdlib/messaging';
import { Note } from '@aztec/stdlib/note';
import { makeHeader } from '@aztec/stdlib/testing';
Expand All @@ -64,6 +65,7 @@ import { jest } from '@jest/globals';
import { Matcher, type MatcherCreator, type MockProxy, mock } from 'jest-mock-extended';
import { toFunctionSelector } from 'viem';

import { Tag } from '../../tagging/tag.js';
import { ContractFunctionSimulator } from '../contract_function_simulator.js';
import type { ExecutionDataProvider } from '../execution_data_provider.js';
import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
Expand Down Expand Up @@ -301,11 +303,9 @@ describe('Private Execution test suite', () => {
throw new Error(`Unknown address: ${address}. Recipient: ${recipient}, Owner: ${owner}`);
});

executionDataProvider.getNextAppTagAsSender.mockImplementation(
(_contractAddress: AztecAddress, _sender: AztecAddress, _recipient: AztecAddress) => {
return Promise.resolve(Fr.random());
},
);
executionDataProvider.getNextAppTagAsSender.mockImplementation((_secret: DirectionalAppTaggingSecret) => {
return Promise.resolve(Tag.compute({ secret: _secret, index: 0 }));
});
executionDataProvider.getFunctionArtifact.mockImplementation(async (address, selector) => {
const contract = contracts[address.toString()];
if (!contract) {
Expand All @@ -331,6 +331,9 @@ describe('Private Execution test suite', () => {
});

executionDataProvider.syncTaggedLogs.mockImplementation((_, __) => Promise.resolve());
executionDataProvider.calculateDirectionalAppTaggingSecret.mockResolvedValue(
DirectionalAppTaggingSecret.fromString('0x1'),
);
executionDataProvider.loadCapsule.mockImplementation((_, __) => Promise.resolve(null));

executionDataProvider.getPublicStorageAt.mockImplementation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
type TxContext,
} from '@aztec/stdlib/tx';

import type { Tag } from '../../tagging/tag.js';
import type { ExecutionDataProvider } from '../execution_data_provider.js';
import type { ExecutionNoteCache } from '../execution_note_cache.js';
import type { HashedValuesCache } from '../hashed_values_cache.js';
Expand Down Expand Up @@ -191,8 +192,22 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
* @param recipient - The address receiving the log
* @returns An app tag to be used in a log.
*/
public async privateGetNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Fr> {
return await this.executionDataProvider.getNextAppTagAsSender(this.contractAddress, sender, recipient);
public async privateGetNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Tag> {
const directionalAppTaggingSecret = await this.executionDataProvider.calculateDirectionalAppTaggingSecret(
this.contractAddress,
sender,
recipient,
);

// TODO(benesjan): In a follow-up PR we will load here the index from the ExecutionTaggingIndexCache if present
// and if not we will obtain it from the execution data provider.

this.log.debug(`Syncing tagged logs as sender ${sender} for contract ${this.contractAddress}`, {
directionalAppTaggingSecret,
recipient,
});
await this.executionDataProvider.syncTaggedLogsAsSender(directionalAppTaggingSecret, this.contractAddress);
return this.executionDataProvider.getNextAppTagAsSender(directionalAppTaggingSecret);
}

/**
Expand Down
Loading
Loading