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
11 changes: 2 additions & 9 deletions noir-projects/aztec-nr/aztec/src/messages/encryption/aes128.nr
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,7 @@ mod test {
test::helpers::test_environment::TestEnvironment,
};
use super::AES128;
use protocol_types::{
address::AztecAddress,
indexed_tagging_secret::IndexedTaggingSecret,
traits::{Deserialize, FromField},
};
use protocol_types::{address::AztecAddress, traits::FromField};
use std::{embedded_curve_ops::EmbeddedCurveScalar, test::OracleMock};

#[test]
Expand All @@ -419,10 +415,7 @@ mod test {
let randomness = 0x0101010101010101010101010101010101010101010101010101010101010101;
let _ = OracleMock::mock("utilityGetRandomField").returns(randomness).times(1000000);

let _ = OracleMock::mock("utilityGetIndexedTaggingSecretAsSender").returns(
IndexedTaggingSecret::deserialize([69420, 1337]),
);
let _ = OracleMock::mock("privateIncrementAppTaggingSecretIndexAsSender").returns(());
let _ = OracleMock::mock("privateGetNextAppTagAsSender").returns(42);

// Encrypt the message
let encrypted_message = BoundedVec::from_array(AES128::encrypt(plaintext, recipient));
Expand Down
39 changes: 8 additions & 31 deletions noir-projects/aztec-nr/aztec/src/messages/logs/utils.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::oracle::notes::{
get_app_tag_as_sender, get_sender_for_tags, increment_app_tagging_secret_index_as_sender,
};
use crate::oracle::notes::{get_next_app_tag_as_sender, get_sender_for_tags};
use dep::protocol_types::address::AztecAddress;

// TODO(#14565): Add constrained tagging
Expand All @@ -15,8 +13,7 @@ pub(crate) fn prefix_with_tag<let L: u32>(
let sender = get_sender_for_tags().expect(
f"Sender for tags is not set when emitting a private log. Set it by calling `set_sender_for_tags(...)`.",
);
increment_app_tagging_secret_index_as_sender(sender, recipient);
get_app_tag_as_sender(sender, recipient)
get_next_app_tag_as_sender(sender, recipient)
};

let mut log_with_tag = [0; L + 1];
Expand All @@ -31,30 +28,18 @@ pub(crate) fn prefix_with_tag<let L: u32>(

mod test {
use super::prefix_with_tag;
use protocol_types::{
address::AztecAddress,
indexed_tagging_secret::IndexedTaggingSecret,
traits::{Deserialize, FromField},
};
use protocol_types::{address::AztecAddress, traits::FromField};
use std::test::OracleMock;

#[test(should_fail)]
unconstrained fn no_tag_sender() {
let recipient = AztecAddress::from_field(2);

let app_tagging_secret = 42;
let index = 5;

// I am using the deserialize trait instead of directly instantiating the IndexedTaggingSecret struct because
// direct instantiation functionality is not exposed.
let indexed_tagging_secret = IndexedTaggingSecret::deserialize([app_tagging_secret, index]);
let expected_tag = 42;

// Mock the tagging oracles - note privateGetSenderForTags returns none
let _ = OracleMock::mock("privateGetSenderForTags").returns(Option::<AztecAddress>::none());
let _ = OracleMock::mock("utilityGetIndexedTaggingSecretAsSender").returns(
indexed_tagging_secret,
);
let _ = OracleMock::mock("privateIncrementAppTaggingSecretIndexAsSender").returns(());
let _ = OracleMock::mock("privateGetNextAppTagAsSender").returns(expected_tag);

let log_without_tag = [1, 2, 3];
let _ = prefix_with_tag(log_without_tag, recipient);
Expand All @@ -65,24 +50,16 @@ mod test {
let sender = AztecAddress::from_field(1);
let recipient = AztecAddress::from_field(2);

let app_tagging_secret = 42;
let index = 5;

// I am using the deserialize trait instead of directly instantiating the IndexedTaggingSecret struct because
// direct instantiation functionality is not exposed.
let indexed_tagging_secret = IndexedTaggingSecret::deserialize([app_tagging_secret, index]);
let expected_tag = 42;

// Mock the tagging oracles
let _ = OracleMock::mock("privateGetSenderForTags").returns(Option::some(sender));
let _ = OracleMock::mock("utilityGetIndexedTaggingSecretAsSender").returns(
indexed_tagging_secret,
);
let _ = OracleMock::mock("privateIncrementAppTaggingSecretIndexAsSender").returns(());
let _ = OracleMock::mock("privateGetNextAppTagAsSender").returns(expected_tag);

let log_without_tag = [1, 2, 3];
let log_with_tag = prefix_with_tag(log_without_tag, recipient);

let expected_result = [indexed_tagging_secret.compute_tag(recipient), 1, 2, 3];
let expected_result = [expected_tag, 1, 2, 3];

// Check tag was prefixed correctly
assert_eq(log_with_tag, expected_result, "Tag was not prefixed correctly");
Expand Down
42 changes: 11 additions & 31 deletions noir-projects/aztec-nr/aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::note::{note_interface::NoteType, retrieved_note::RetrievedNote};

use dep::protocol_types::{
address::AztecAddress, indexed_tagging_secret::IndexedTaggingSecret, traits::Packable,
};
use dep::protocol_types::{address::AztecAddress, traits::Packable};

/// Notifies the simulator that a note has been created, so that it can be returned in future read requests in the same
/// transaction. This note should only be added to the non-volatile database if found in an actual block.
Expand Down Expand Up @@ -191,43 +189,25 @@ unconstrained fn check_nullifier_exists_oracle(_inner_nullifier: Field) -> bool

// TODO: Oracles below are generic private log oracles and are not specific to notes. Move them somewhere else.

/// Returns the derived app tagging secret ready to be included in a log for a given sender and recipient pair,
/// siloed for the current contract address.
pub unconstrained fn get_app_tag_as_sender(sender: AztecAddress, recipient: AztecAddress) -> Field {
get_indexed_tagging_secret_as_sender_oracle(sender, recipient).compute_tag(recipient)
}

#[oracle(utilityGetIndexedTaggingSecretAsSender)]
unconstrained fn get_indexed_tagging_secret_as_sender_oracle(
_sender: AztecAddress,
_recipient: AztecAddress,
) -> IndexedTaggingSecret {}

/// Notifies the simulator that a tag has been used in a note, and to therefore increment the associated index so that
/// future notes get a different tag and can be discovered by the recipient.
/// Returns the next app tag for a given sender and recipient pair.
///
/// This also notifies the simulator that a tag has been used in a note, and to therefore increment the
/// associated index so that future notes get a different tag and can be discovered by the recipient.
/// This change should only be persisted in a non-volatile database if the tagged log is found in an actual block -
/// otherwise e.g. a reverting transaction can cause the sender to accidentally skip indices and later produce notes
/// that are not found by the recipient.
pub fn increment_app_tagging_secret_index_as_sender(sender: AztecAddress, recipient: AztecAddress) {
// Safety: This oracle call returns nothing: we only call it for its side effects. It is therefore always safe
// to call.
unsafe {
increment_app_tagging_secret_index_as_sender_wrapper(sender, recipient);
}
}

unconstrained fn increment_app_tagging_secret_index_as_sender_wrapper(
pub unconstrained fn get_next_app_tag_as_sender(
sender: AztecAddress,
recipient: AztecAddress,
) {
increment_app_tagging_secret_index_as_sender_oracle(sender, recipient);
) -> Field {
get_next_app_tag_as_sender_oracle(sender, recipient)
}

#[oracle(privateIncrementAppTaggingSecretIndexAsSender)]
unconstrained fn increment_app_tagging_secret_index_as_sender_oracle(
#[oracle(privateGetNextAppTagAsSender)]
unconstrained fn get_next_app_tag_as_sender_oracle(
_sender: AztecAddress,
_recipient: AztecAddress,
) {}
) -> Field {}

/// Gets the sender for tags.
///
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/oracle/version.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
///
/// @dev Whenever a contract function or Noir test is run, the `utilityAssertCompatibleOracleVersion` oracle is called and
/// if the oracle version is incompatible an error is thrown.
pub global ORACLE_VERSION: Field = 2;
pub global ORACLE_VERSION: Field = 3;

/// Asserts that the version of the oracle is compatible with the version expected by the contract.
pub fn assert_compatible_oracle_version() {
Expand All @@ -30,7 +30,7 @@ mod test {
assert_compatible_oracle_version_oracle(ORACLE_VERSION);
}

#[test(should_fail_with = "Incompatible oracle version. TXE is using version '2', but got a request for '318183437'.")]
#[test(should_fail_with = "Incompatible oracle version. TXE is using version '3', but got a request for '318183437'.")]
unconstrained fn incompatible_oracle_version() {
let arbitrary_incorrect_version = 318183437;
assert_compatible_oracle_version_oracle(arbitrary_incorrect_version);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub mod data;
pub mod storage;
pub mod validate;
pub mod meta;
pub mod indexed_tagging_secret;

pub mod tests;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 { IndexedTaggingSecret } 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';
Expand Down Expand Up @@ -215,30 +214,13 @@ export interface ExecutionDataProvider {
assertCompatibleOracleVersion(version: number): void;

/**
* Returns the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
* Includes the next index to be used used for tagging with this secret.
* Returns the next app tag for a given sender and recipient pair.
* @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 A tagging secret that can be used to tag notes.
* @returns The computed tag.
*/
getIndexedTaggingSecretAsSender(
contractAddress: AztecAddress,
sender: AztecAddress,
recipient: AztecAddress,
): Promise<IndexedTaggingSecret>;

/**
* Increments the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
* @param contractAddress - The contract address to silo the secret for
* @param sender - The address sending the note
* @param recipient - The address receiving the note
*/
incrementAppTaggingSecretIndexAsSender(
contractAddress: AztecAddress,
sender: AztecAddress,
recipient: AztecAddress,
): Promise<void>;
getNextAppTagAsSender(contractAddress: AztecAddress, sender: AztecAddress, recipient: AztecAddress): Promise<Fr>;

/**
* 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 @@ -4,7 +4,7 @@ import type { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
import type { ContractClassLog, IndexedTaggingSecret } from '@aztec/stdlib/logs';
import type { ContractClassLog } from '@aztec/stdlib/logs';
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';
Expand Down Expand Up @@ -100,7 +100,6 @@ export interface IUtilityExecutionOracle {
blockNumber: number,
numberOfElements: number,
): Promise<Fr[]>;
utilityGetIndexedTaggingSecretAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<IndexedTaggingSecret>;
utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr): Promise<void>;
utilityValidateEnqueuedNotesAndEvents(
contractAddress: AztecAddress,
Expand Down Expand Up @@ -153,8 +152,8 @@ export interface IPrivateExecutionOracle {
isStaticCall: boolean,
): Promise<void>;
privateNotifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): Promise<void>;
privateIncrementAppTaggingSecretIndexAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<void>;
privateGetSenderForTags(): Promise<AztecAddress | undefined>;
privateSetSenderForTags(senderForTags: AztecAddress): Promise<void>;
privateGetNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Fr>;
utilityEmitOffchainEffect(data: Fr[]): Promise<void>;
}
17 changes: 3 additions & 14 deletions yarn-project/pxe/src/contract_function_simulator/oracle/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,23 +433,12 @@ export class Oracle {
return Promise.resolve([]);
}

async utilityGetIndexedTaggingSecretAsSender([sender]: ACVMField[], [recipient]: ACVMField[]): Promise<ACVMField[]> {
const taggingSecret = await this.handlerAsUtility().utilityGetIndexedTaggingSecretAsSender(
async privateGetNextAppTagAsSender([sender]: ACVMField[], [recipient]: ACVMField[]): Promise<ACVMField[]> {
const tag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(
AztecAddress.fromString(sender),
AztecAddress.fromString(recipient),
);
return taggingSecret.toFields().map(toACVMField);
}

async privateIncrementAppTaggingSecretIndexAsSender(
[sender]: ACVMField[],
[recipient]: ACVMField[],
): Promise<ACVMField[]> {
await this.handlerAsPrivate().privateIncrementAppTaggingSecretIndexAsSender(
AztecAddress.fromString(sender),
AztecAddress.fromString(recipient),
);
return [];
return [toACVMField(tag)];
}

async utilityFetchTaggedLogs([pendingTaggedLogArrayBaseSlot]: ACVMField[]): Promise<ACVMField[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import {
} from '@aztec/stdlib/hash';
import { KeyValidationRequest } from '@aztec/stdlib/kernel';
import { computeAppNullifierSecretKey, deriveKeys } from '@aztec/stdlib/keys';
import { IndexedTaggingSecret } 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 Down Expand Up @@ -302,10 +301,9 @@ describe('Private Execution test suite', () => {
throw new Error(`Unknown address: ${address}. Recipient: ${recipient}, Owner: ${owner}`);
});

executionDataProvider.getIndexedTaggingSecretAsSender.mockImplementation(
executionDataProvider.getNextAppTagAsSender.mockImplementation(
(_contractAddress: AztecAddress, _sender: AztecAddress, _recipient: AztecAddress) => {
const secret = Fr.random();
return Promise.resolve(new IndexedTaggingSecret(secret, 0));
return Promise.resolve(Fr.random());
},
);
executionDataProvider.getFunctionArtifact.mockImplementation(async (address, selector) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
return Promise.resolve();
}

/**
* Returns the next app tag for a given sender and recipient pair.
* @param sender - The address sending the log
* @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);
}

/**
* Store values in the execution cache.
* @param values - Values to store.
Expand Down Expand Up @@ -567,10 +577,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
return this.executionDataProvider.getDebugFunctionName(this.contractAddress, this.callContext.functionSelector);
}

public async privateIncrementAppTaggingSecretIndexAsSender(sender: AztecAddress, recipient: AztecAddress) {
await this.executionDataProvider.incrementAppTaggingSecretIndexAsSender(this.contractAddress, sender, recipient);
}

public utilityEmitOffchainEffect(data: Fr[]): Promise<void> {
this.offchainEffects.push({ data });
return Promise.resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
import { siloNullifier } from '@aztec/stdlib/hash';
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
import { IndexedTaggingSecret } from '@aztec/stdlib/logs';
import type { NoteStatus } from '@aztec/stdlib/note';
import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
import type { BlockHeader, Capsule } from '@aztec/stdlib/tx';
Expand Down Expand Up @@ -264,21 +263,6 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
this.log[levelName](`${applyStringFormatting(message, fields)}`, { module: `${this.log.module}:debug_log` });
}

/**
* Returns the tagging secret for a given sender and recipient pair, siloed to the current contract address.
* Includes the next index to be used used for tagging with this secret.
* For this to work, the ivsk_m of the sender must be known.
* @param sender - The address sending the note
* @param recipient - The address receiving the note
* @returns A tagging secret that can be used to tag notes.
*/
public async utilityGetIndexedTaggingSecretAsSender(
sender: AztecAddress,
recipient: AztecAddress,
): Promise<IndexedTaggingSecret> {
return await this.executionDataProvider.getIndexedTaggingSecretAsSender(this.contractAddress, sender, recipient);
}

public async utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
await this.executionDataProvider.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);

Expand Down
Loading
Loading