-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
231 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
yarn-project/circuits.js/src/structs/indexed_tagging_secret.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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 appTaggingSecret: Fr, public index: number) {} | ||
|
||
toFields(): Fr[] { | ||
return [this.appTaggingSecret, new Fr(this.index)]; | ||
} | ||
|
||
static fromFields(serialized: Fr[]) { | ||
return new this(serialized[0], serialized[1].toNumber()); | ||
} | ||
|
||
/** | ||
* Computes the tag based on the app tagging secret, recipient and index. | ||
* @dev By including the recipient we achieve "directionality" of the tag (when sending a note in the other | ||
* direction, the tag will be different). | ||
* @param recipient The recipient of the note | ||
* @returns The tag. | ||
*/ | ||
computeTag(recipient: AztecAddress) { | ||
return poseidon2Hash([this.appTaggingSecret, recipient, this.index]); | ||
} | ||
|
||
/** | ||
* Computes the tag as it is submitted on-chain. | ||
* @dev We do this second layer of siloing (one was already done as the tagging secret is app-siloed) because kernels | ||
* do that to protect against contract impersonation attacks. This extra layer of siloing in kernels ensures that | ||
* a malicious contract cannot emit a note with a tag corresponding to another contract. | ||
* @param recipient The recipient of the note | ||
* @param app The app address | ||
* @returns The tag as it is submitted on-chain in a log. | ||
*/ | ||
computeSiloedTag(recipient: AztecAddress, app: AztecAddress) { | ||
const tag = this.computeTag(recipient); | ||
return poseidon2Hash([app, tag]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.