-
Notifications
You must be signed in to change notification settings - Fork 310
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
refactor: tagging cleanup #10675
refactor: tagging cleanup #10675
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,7 +260,7 @@ mod test { | |
0x25afb798ea6d0b8c1618e50fdeafa463059415013d3b7c75d46abf5e242be70c, | ||
); | ||
|
||
let _ = OracleMock::mock("getAppTaggingSecretAsSender").returns([69420, 1337]); | ||
let _ = OracleMock::mock("getIndexedTaggingSecretAsSender").returns([69420, 1337]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this naming change as this was returning an IndexedTaggingSecret struct and I wanted to consistently use the "appTaggingSecret" for the actual appTaggingSecret (the shared/super secret siloed with the contract). Having this consistent made the code less confusing in quite a few places. |
||
|
||
let _ = OracleMock::mock("incrementAppTaggingSecretIndexAsSender").returns(()); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,14 @@ pub global INDEXED_TAGGING_SECRET_LENGTH: u32 = 2; | |
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct IndexedTaggingSecret { | ||
secret: Field, | ||
app_tagging_secret: Field, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was not sure what the secret is at first so I renamed it. |
||
index: u32, | ||
} | ||
|
||
impl IndexedTaggingSecret { | ||
pub fn compute_tag(self, recipient: AztecAddress) -> Field { | ||
poseidon2_hash([self.secret, recipient.to_field(), self.index as Field]) | ||
poseidon2_hash( | ||
[self.app_tagging_secret, recipient.to_field(), self.index as Field], | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 './tagging_secret.js'; | ||
export * from './indexed_tagging_secret.js'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just to have the file names be consistent. |
||
export * from './kernel/combined_accumulated_data.js'; | ||
export * from './kernel/combined_constant_data.js'; | ||
export * from './kernel/private_kernel_empty_inputs.js'; | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shifting back of shifting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shift the shift