Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: "refactor: tagging cleanup" #10732

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 3 additions & 6 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,11 @@
"unexcluded",
"unfinalised",
"unprefixed",
"unshift",
"unshifted",
"unsynched",
"unzipit",
"updateable",
"upperfirst",
"unshift",
"unshifted",
"usecase",
"usecases",
"utxo",
Expand Down Expand Up @@ -324,7 +323,5 @@
"lib",
"*.cmake"
],
"flagWords": [
"anonymous"
]
"flagWords": ["anonymous"]
}
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ mod test {
0x25afb798ea6d0b8c1618e50fdeafa463059415013d3b7c75d46abf5e242be70c,
);

let _ = OracleMock::mock("getIndexedTaggingSecretAsSender").returns([69420, 1337]);
let _ = OracleMock::mock("getAppTaggingSecretAsSender").returns([69420, 1337]);

let _ = OracleMock::mock("incrementAppTaggingSecretIndexAsSender").returns(());

Expand Down
14 changes: 7 additions & 7 deletions noir-projects/aztec-nr/aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,25 @@ pub unconstrained fn check_nullifier_exists(inner_nullifier: Field) -> bool {
#[oracle(checkNullifierExists)]
unconstrained fn check_nullifier_exists_oracle(_inner_nullifier: Field) -> Field {}

/// Same as `get_indexed_tagging_secret_as_sender`, except it returns the derived tag, ready to be included in a log.
/// Same as `get_app_tagging_secret_as_sender`, except it returns the derived tag, ready to be included in a log.
pub unconstrained fn get_app_tag_as_sender(sender: AztecAddress, recipient: AztecAddress) -> Field {
get_indexed_tagging_secret_as_sender(sender, recipient).compute_tag(recipient)
get_app_tagging_secret_as_sender(sender, recipient).compute_tag(recipient)
}

/// Returns the tagging secret for a given sender and recipient pair, siloed for the current contract address.
/// Includes the last known index used to send a note tagged with this secret.
/// For this to work, PXE must know the ivsk_m of the sender.
/// For this to work, PXE must know the ivpsk_m of the sender.
/// For the recipient's side, only the address is needed.
pub unconstrained fn get_indexed_tagging_secret_as_sender(
pub unconstrained fn get_app_tagging_secret_as_sender(
sender: AztecAddress,
recipient: AztecAddress,
) -> IndexedTaggingSecret {
let result = get_indexed_tagging_secret_as_sender_oracle(sender, recipient);
let result = get_app_tagging_secret_as_sender_oracle(sender, recipient);
IndexedTaggingSecret::deserialize(result)
}

#[oracle(getIndexedTaggingSecretAsSender)]
unconstrained fn get_indexed_tagging_secret_as_sender_oracle(
#[oracle(getAppTaggingSecretAsSender)]
unconstrained fn get_app_tagging_secret_as_sender_oracle(
_sender: AztecAddress,
_recipient: AztecAddress,
) -> [Field; INDEXED_TAGGING_SECRET_LENGTH] {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ pub global INDEXED_TAGGING_SECRET_LENGTH: u32 = 2;

#[derive(Serialize, Deserialize)]
pub struct IndexedTaggingSecret {
app_tagging_secret: Field,
secret: Field,
index: u32,
}

impl IndexedTaggingSecret {
pub fn compute_tag(self, recipient: AztecAddress) -> Field {
poseidon2_hash(
[self.app_tagging_secret, recipient.to_field(), self.index as Field],
)
poseidon2_hash([self.secret, recipient.to_field(), self.index as Field])
}
}
3 changes: 1 addition & 2 deletions yarn-project/circuits.js/src/keys/derivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ export function deriveKeys(secretKey: Fr) {
};
}

// Returns shared tagging secret computed with Diffie-Hellman key exchange.
export function computeTaggingSecretPoint(knownAddress: CompleteAddress, ivsk: Fq, externalAddress: AztecAddress) {
export function computeTaggingSecret(knownAddress: CompleteAddress, ivsk: Fq, externalAddress: AztecAddress) {
const knownPreaddress = computePreaddress(knownAddress.publicKeys.hash(), knownAddress.partialAddress);
// TODO: #8970 - Computation of address point from x coordinate might fail
const externalAddressPoint = externalAddress.toAddressPoint();
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/structs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export * from './gas_fees.js';
export * from './gas_settings.js';
export * from './global_variables.js';
export * from './block_header.js';
export * from './indexed_tagging_secret.js';
export * from './tagging_secret.js';
export * from './kernel/combined_accumulated_data.js';
export * from './kernel/combined_constant_data.js';
export * from './kernel/private_kernel_empty_inputs.js';
Expand Down
40 changes: 0 additions & 40 deletions yarn-project/circuits.js/src/structs/indexed_tagging_secret.ts

This file was deleted.

24 changes: 24 additions & 0 deletions yarn-project/circuits.js/src/structs/tagging_secret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { type AztecAddress } from '@aztec/foundation/aztec-address';
import { poseidon2Hash } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';

export class IndexedTaggingSecret {
constructor(public secret: Fr, public index: number) {}

toFields(): Fr[] {
return [this.secret, new Fr(this.index)];
}

static fromFields(serialized: Fr[]) {
return new this(serialized[0], serialized[1].toNumber());
}

computeTag(recipient: AztecAddress) {
return poseidon2Hash([this.secret, recipient, this.index]);
}

computeSiloedTag(recipient: AztecAddress, contractAddress: AztecAddress) {
const tag = this.computeTag(recipient);
return poseidon2Hash([contractAddress, tag]);
}
}
4 changes: 1 addition & 3 deletions yarn-project/pxe/src/database/kv_pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,7 @@ export class KVPxeDatabase implements PxeDatabase {

async #setTaggingSecretsIndexes(indexedSecrets: IndexedTaggingSecret[], storageMap: AztecAsyncMap<string, number>) {
await Promise.all(
indexedSecrets.map(indexedSecret =>
storageMap.set(indexedSecret.appTaggingSecret.toString(), indexedSecret.index),
),
indexedSecrets.map(indexedSecret => storageMap.set(indexedSecret.secret.toString(), indexedSecret.index)),
);
}

Expand Down
Loading
Loading