From 3d7771e7b4a7003c08098e27bf0e9bed87b19322 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 30 Oct 2024 11:27:16 +0000 Subject: [PATCH] init --- noir-projects/aztec-nr/aztec/src/oracle/notes.nr | 12 ++++++++++++ .../circuits.js/src/structs/tagging_secret.ts | 6 +++++- yarn-project/pxe/src/simulator_oracle/index.ts | 4 ++++ yarn-project/simulator/src/acvm/oracle/oracle.ts | 7 +++++++ .../simulator/src/acvm/oracle/typed_oracle.ts | 4 ++++ .../simulator/src/client/client_execution_context.ts | 5 +++++ yarn-project/simulator/src/client/db_oracle.ts | 2 ++ yarn-project/txe/src/oracle/txe_oracle.ts | 4 ++++ 8 files changed, 43 insertions(+), 1 deletion(-) diff --git a/noir-projects/aztec-nr/aztec/src/oracle/notes.nr b/noir-projects/aztec-nr/aztec/src/oracle/notes.nr index 39ed994516fa..f40c7faddb35 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/notes.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/notes.nr @@ -221,6 +221,18 @@ unconstrained fn get_app_tagging_secret_oracle( _recipient: AztecAddress, ) -> [Field; INDEXED_TAGGING_SECRET_LENGTH] {} + +pub unconstrained fn increment_app_tagging_secret( + to_increment: IndexedTaggingSecret, +) { + increment_app_tagging_secret_oracle(to_increment); +} + +#[oracle(incrementAppTaggingSecret)] +unconstrained fn increment_app_tagging_secret_oracle( + to_increment: IndexedTaggingSecret, +) {} + /// Returns the tagging secrets for a given recipient and all the senders in PXE's address book, // siloed for the current contract address. /// Includes the last known index used for tagging with this secret. diff --git a/yarn-project/circuits.js/src/structs/tagging_secret.ts b/yarn-project/circuits.js/src/structs/tagging_secret.ts index b43e8cb80300..35b2ded6048c 100644 --- a/yarn-project/circuits.js/src/structs/tagging_secret.ts +++ b/yarn-project/circuits.js/src/structs/tagging_secret.ts @@ -1,4 +1,4 @@ -import { type AztecAddress } from '@aztec/foundation/aztec-address'; +import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; export class TaggingSecret { @@ -17,4 +17,8 @@ export class IndexedTaggingSecret extends TaggingSecret { override toFields(): Fr[] { return [this.secret, this.recipient, new Fr(this.index)]; } + + static fromFields(serialized: Fr[]) { + return new this(serialized[0], AztecAddress.fromField(serialized[1]), serialized[2].toNumber()); + } } diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index b67a5dd2da1d..0fa259f33c5e 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -266,6 +266,10 @@ export class SimulatorOracle implements DBOracle { return new IndexedTaggingSecret(siloedSecret, recipient, index); } + public async incrementAppTaggingSecret(indexedSecret: IndexedTaggingSecret): Promise { + await this.db.incrementTaggingSecretsIndexes([new TaggingSecret(indexedSecret.secret, indexedSecret.recipient)]); + } + /** * Returns the siloed tagging secrets for a given recipient and all the senders in the address book * @param contractAddress - The contract address to silo the secret for diff --git a/yarn-project/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index c8fdb5a18b2f..f6f483281545 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -1,4 +1,5 @@ import { MerkleTreeId, UnencryptedL2Log } from '@aztec/circuit-types'; +import { IndexedTaggingSecret } from '@aztec/circuits.js'; import { FunctionSelector, NoteSelector } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -417,6 +418,12 @@ export class Oracle { return taggingSecret.toFields().map(toACVMField); } + async incrementAppTaggingSecret(indexedTaggingSecret: ACVMField[]) { + await this.typedOracle.incrementAppTaggingSecret( + IndexedTaggingSecret.fromFields(indexedTaggingSecret.map(fromACVMField)), + ); + } + async getAppTaggingSecretsForSenders([recipient]: ACVMField[]): Promise { const taggingSecrets = await this.typedOracle.getAppTaggingSecretsForSenders(AztecAddress.fromString(recipient)); return taggingSecrets.flatMap(taggingSecret => taggingSecret.toFields().map(toACVMField)); diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index 284b08f5e0f5..3e12797896fc 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -258,6 +258,10 @@ export abstract class TypedOracle { throw new OracleMethodNotAvailableError('getAppTaggingSecret'); } + incrementAppTaggingSecret(_indexedTaggingSecret: IndexedTaggingSecret): Promise { + throw new OracleMethodNotAvailableError('incrementAppTaggingSecret'); + } + getAppTaggingSecretsForSenders(_recipient: AztecAddress): Promise { throw new OracleMethodNotAvailableError('getAppTaggingSecretsForSenders'); } diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index 06c51c9b0bf4..7dd6f960e56a 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -17,6 +17,7 @@ import { CallContext, FunctionSelector, type Header, + IndexedTaggingSecret, PRIVATE_CONTEXT_INPUTS_LENGTH, PUBLIC_DISPATCH_SELECTOR, PrivateContextInputs, @@ -609,4 +610,8 @@ export class ClientExecutionContext extends ViewDataOracle { public getDebugFunctionName() { return this.db.getDebugFunctionName(this.contractAddress, this.callContext.functionSelector); } + + public override async incrementAppTaggingSecret(indexedTaggingSecret: IndexedTaggingSecret) { + await this.db.incrementAppTaggingSecret(indexedTaggingSecret); + } } diff --git a/yarn-project/simulator/src/client/db_oracle.ts b/yarn-project/simulator/src/client/db_oracle.ts index c19a0b1636ac..a1e73e52130e 100644 --- a/yarn-project/simulator/src/client/db_oracle.ts +++ b/yarn-project/simulator/src/client/db_oracle.ts @@ -209,6 +209,8 @@ export interface DBOracle extends CommitmentsDB { recipient: AztecAddress, ): Promise; + incrementAppTaggingSecret(indexedSecret: IndexedTaggingSecret): Promise; + /** * Returns the siloed tagging secrets for a given recipient and all the senders in the address book * @param contractAddress - The contract address to silo the secret for diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index 1754fa8e8c10..7e4c75d1521d 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -756,6 +756,10 @@ export class TXE implements TypedOracle { return; } + async incrementAppTaggingSecret(indexedSecret: IndexedTaggingSecret): Promise { + await this.txeDatabase.incrementTaggingSecretsIndexes([new TaggingSecret(indexedSecret.secret, indexedSecret.recipient)]); + } + async getAppTaggingSecret(sender: AztecAddress, recipient: AztecAddress): Promise { const senderCompleteAddress = await this.getCompleteAddress(sender); const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);