-
Notifications
You must be signed in to change notification settings - Fork 613
fix(txe): align tagging strategy oracle with PXE #24561
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
Changes from all commits
6f5498f
0792034
b8a3a01
1ed50ec
3bc9732
026ac0f
07ec09c
2aa0cdb
36c473e
1daee1c
3495051
f1fe236
62c76d3
7d64a26
da2d484
ad28bcf
51d3d4a
deb3c2f
91933f0
32bad6b
0801ac4
6a1a6fd
4595810
a250dc7
014b001
be81765
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 |
|---|---|---|
| @@ -1,4 +1,11 @@ | ||
| use crate::protocol::{point::EmbeddedCurvePoint, traits::{Deserialize, Serialize}, utils::reader::Reader}; | ||
| use crate::keys::ecdh_shared_secret::compute_app_siloed_shared_secret; | ||
| use crate::protocol::{ | ||
| address::AztecAddress, | ||
| hash::poseidon2_hash, | ||
| point::EmbeddedCurvePoint, | ||
| traits::{Deserialize, Serialize, ToField}, | ||
| utils::reader::Reader, | ||
| }; | ||
|
|
||
| global NON_INTERACTIVE_HANDSHAKE: u8 = 1; | ||
| global ARBITRARY_SECRET: u8 = 2; | ||
|
|
@@ -7,7 +14,7 @@ global INTERACTIVE_HANDSHAKE: u8 = 4; | |
|
|
||
| /// How a message's tagging secret is chosen: the wallet's strategy. | ||
| /// | ||
| /// This type only exists for tests: a Noir test sets it via `with_tagging_secret_strategy` on | ||
| /// This type only exists for tests: a Noir test sets it via `with_default_tag_secret_strategy` on | ||
| /// [`TestEnvironmentOptions`](crate::test::helpers::test_environment::TestEnvironmentOptions). | ||
| /// Production wallets express the strategy in PXE; the Noir path only consumes the resolved | ||
| /// [`ResolvedTaggingStrategy`](crate::messages::delivery::ResolvedTaggingStrategy). | ||
|
|
@@ -45,18 +52,26 @@ impl TaggingSecretStrategy { | |
| /// Validates a raw discriminant, as deserialization must always reject unknown values. | ||
| fn from_parts(kind: u8, secret: EmbeddedCurvePoint) -> Self { | ||
| let strategy = Self { kind, secret }; | ||
| let is_no_payload_strategy = | ||
| (kind == NON_INTERACTIVE_HANDSHAKE) | (kind == INTERACTIVE_HANDSHAKE) | (kind == ADDRESS_DERIVED); | ||
| assert( | ||
| ( | ||
| ((kind == NON_INTERACTIVE_HANDSHAKE) | (kind == ADDRESS_DERIVED) | (kind == INTERACTIVE_HANDSHAKE)) | ||
| & secret.is_infinite() | ||
| ) | ||
| | (kind == ARBITRARY_SECRET), | ||
| (is_no_payload_strategy & secret.is_infinite()) | (kind == ARBITRARY_SECRET), | ||
| f"unrecognized tagging secret strategy kind: {kind}", | ||
| ); | ||
| strategy | ||
| } | ||
| } | ||
|
|
||
| /// Computes the directional tagging secret PXE derives from an arbitrary shared secret point: the point is app-siloed | ||
| /// and the recipient is folded in for direction. Mirrors `AppTaggingSecret.computeDirectional` on the PXE side; tests | ||
| /// use it to derive the secret they expect an [`arbitrary_secret`](TaggingSecretStrategy::arbitrary_secret) strategy | ||
| /// to produce. | ||
| pub fn compute_directional_app_secret(secret: EmbeddedCurvePoint, app: AztecAddress, recipient: AztecAddress) -> Field { | ||
|
Contributor
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. I like that we have this, but I have two questions:
Contributor
Author
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.
Contributor
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.
Contributor
Author
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. Actually we used this method in the new test in |
||
| poseidon2_hash( | ||
| [compute_app_siloed_shared_secret(secret, app), recipient.to_field()], | ||
| ) | ||
| } | ||
|
|
||
| impl Deserialize for TaggingSecretStrategy { | ||
| let N: u32 = 3; | ||
|
|
||
|
|
@@ -81,14 +96,14 @@ mod test { | |
| #[test] | ||
| fn strategy_roundtrips_through_serialization() { | ||
| let non_interactive = TaggingSecretStrategy::non_interactive_handshake(); | ||
| let interactive = TaggingSecretStrategy::interactive_handshake(); | ||
| let address = TaggingSecretStrategy::address_derived(); | ||
| let provided = TaggingSecretStrategy::arbitrary_secret(EmbeddedCurvePoint { x: 7, y: 11 }); | ||
| let interactive = TaggingSecretStrategy::interactive_handshake(); | ||
|
|
||
| assert(TaggingSecretStrategy::deserialize(non_interactive.serialize()) == non_interactive); | ||
| assert(TaggingSecretStrategy::deserialize(interactive.serialize()) == interactive); | ||
| assert(TaggingSecretStrategy::deserialize(address.serialize()) == address); | ||
| assert(TaggingSecretStrategy::deserialize(provided.serialize()) == provided); | ||
| assert(TaggingSecretStrategy::deserialize(interactive.serialize()) == interactive); | ||
| } | ||
|
|
||
| #[test(should_fail_with = "unrecognized tagging secret strategy kind")] | ||
|
|
@@ -98,16 +113,22 @@ mod test { | |
|
|
||
| #[test(should_fail_with = "unrecognized tagging secret strategy kind")] | ||
| fn deserializing_handshake_with_noninfinite_point_fails() { | ||
| let _ = TaggingSecretStrategy::deserialize([1, 7, 11]); | ||
| let _ = TaggingSecretStrategy::deserialize([ | ||
| TaggingSecretStrategy::non_interactive_handshake().kind as Field, | ||
| 7, | ||
| 11, | ||
| ]); | ||
| } | ||
|
|
||
| #[test(should_fail_with = "unrecognized tagging secret strategy kind")] | ||
| fn deserializing_address_derived_with_noninfinite_point_fails() { | ||
| let _ = TaggingSecretStrategy::deserialize([3, 7, 11]); | ||
| let _ = TaggingSecretStrategy::deserialize( | ||
| [TaggingSecretStrategy::address_derived().kind as Field, 7, 11], | ||
| ); | ||
| } | ||
|
|
||
| #[test(should_fail_with = "unrecognized tagging secret strategy kind")] | ||
| fn deserializing_interactive_handshake_with_noninfinite_point_fails() { | ||
| let _ = TaggingSecretStrategy::deserialize([4, 7, 11]); | ||
| let _ = TaggingSecretStrategy::deserialize([TaggingSecretStrategy::interactive_handshake().kind as Field, 7, 11]); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.