-
Notifications
You must be signed in to change notification settings - Fork 609
feat(aztec-nr): extend OnchainDelivery builder for secret origin #23865
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
Merged
vezenovm
merged 49 commits into
merge-train/fairies-v5
from
mv/f-697-general-delivery-builder
Jun 10, 2026
Merged
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
5a3d077
refactor(aztec-nr)!: move messages::message_delivery to messages::del…
vezenovm 29664d5
fix: regenerate yarn-project/yarn.lock for noir 1.0.0-beta.22 (v5 base)
AztecBot 0a7dc40
Merge branch 'merge-train/fairies-v5' into mv/move-message-delivery-m…
vezenovm 956993c
feat(aztec-nr): extend OnchainDelivery builder for secret origin
vezenovm c9aff0b
refactor(aztec-nr): hide OnchainDeliveryMode constructors behind the …
vezenovm 989948d
docs'
vezenovm 95e5137
typo
vezenovm f3e91b3
try static_assert
vezenovm befb4ea
chore: re-pin HandshakeRegistry standard contract on the fairies-v5 base
vezenovm 51cd497
default to handshake registry standard contract and do not panic on m…
vezenovm 1636dc6
test: cover constrained note-log survival in pending_note_hashes squa…
vezenovm 5269722
comment
vezenovm 33c69d4
Merge branch 'merge-train/fairies-v5' into mv/move-message-delivery-m…
vezenovm 248696b
fix(aztec-nr): repair doc link to renamed delivery module
vezenovm d2c9a4e
Merge branch 'merge-train/fairies-v5' into mv/move-message-delivery-m…
vezenovm 46aa057
Merge remote-tracking branch 'origin/mv/move-message-delivery-module'…
vezenovm e110055
merge
vezenovm 224871d
option OnchainDeliveryMode
vezenovm 2687058
docs: restore constrained delivery warning
vezenovm 87a6034
docs: use exact constrained delivery warning
vezenovm 78db3d3
restore exact warning
vezenovm 13808b4
rename
vezenovm 7c2f8f0
rename
vezenovm c8edad1
comment
vezenovm 4a19b4c
Apply suggestion from @vezenovm
vezenovm 422ec8e
Apply suggestion from @nchamo
vezenovm 71e305a
Apply suggestion from @nchamo
vezenovm 54e0907
Apply suggestion from @nchamo
vezenovm e6f1b12
refactor(aztec-nr): replace secret origin delivery config
vezenovm a889141
refactor(aztec-nr): simplify onchain delivery builder
vezenovm fd212c7
conflict
vezenovm 70e6e64
validate in deserialize
vezenovm be865bc
split OnchainDelivery type
vezenovm 4d2a9dc
small comment
vezenovm 658142b
simplfiy comments
vezenovm a744124
comments
vezenovm 33acb61
.
vezenovm d2ccc25
pr reviews, cleanup of API, tightened comments
vezenovm 876ef91
consolidate tests
vezenovm c95ebcb
comment
vezenovm fc38308
DeliveryMode
vezenovm cf38f47
consolidate constructors
vezenovm 5a91cfb
be more explicit about mocking enums, use equality checks rather than…
vezenovm a2b7989
cleanup
vezenovm b562b4d
split up delivery module root file into submodules
vezenovm c54bda8
improve vis
vezenovm a2afd82
Merge branch 'merge-train/fairies-v5' into mv/f-697-general-delivery-…
vezenovm e46cd06
rename module to mode
vezenovm ba2c977
pr cleanup, resolve inside delivery root module, and typos
vezenovm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
395 changes: 395 additions & 0 deletions
395
noir-projects/aztec-nr/aztec/src/messages/delivery/builder.nr
Large diffs are not rendered by default.
Oops, something went wrong.
324 changes: 57 additions & 267 deletions
324
noir-projects/aztec-nr/aztec/src/messages/delivery/mod.nr
Large diffs are not rendered by default.
Oops, something went wrong.
142 changes: 142 additions & 0 deletions
142
noir-projects/aztec-nr/aztec/src/messages/delivery/mode.nr
This file contains hidden or 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,142 @@ | ||
| use crate::protocol::{traits::{Deserialize, Serialize, ToField}, utils::reader::Reader}; | ||
|
|
||
| /// Noir does not support enums, so this wrapper models delivery variants while keeping raw discriminants private. | ||
| pub(crate) struct DeliveryMode { | ||
| inner: u8, | ||
| } | ||
|
|
||
| impl DeliveryMode { | ||
| pub(crate) fn offchain() -> Self { | ||
| Self { inner: 1 } | ||
| } | ||
|
|
||
| pub(crate) fn onchain_unconstrained() -> Self { | ||
| OnchainDeliveryMode::onchain_unconstrained().into() | ||
| } | ||
|
|
||
| pub(crate) fn onchain_constrained() -> Self { | ||
| OnchainDeliveryMode::onchain_constrained().into() | ||
| } | ||
|
|
||
| pub(crate) fn assert_is_constant(self) { | ||
| assert_constant(self.inner); | ||
| } | ||
|
|
||
| pub(crate) fn onchain_mode(self) -> Option<OnchainDeliveryMode> { | ||
| if self == Self::offchain() { | ||
| Option::none() | ||
| } else { | ||
| Option::some(OnchainDeliveryMode::from_u8(self.inner)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Eq for DeliveryMode { | ||
| fn eq(self, other: Self) -> bool { | ||
| self.inner == other.inner | ||
| } | ||
| } | ||
|
|
||
| /// The mode of an on-chain message delivery: unconstrained or constrained tagging. | ||
| /// | ||
| /// This is kept separate from the private [`DeliveryMode`] wrapper because it is used in external ABIs and therefore | ||
| /// owns the serialization and validation for the on-chain-only subset. | ||
| /// | ||
| /// Consumers derive modes through the delivery API, e.g. | ||
| /// `let mode: OnchainDeliveryMode = MessageDelivery::onchain_unconstrained().into()`. | ||
| #[derive(Serialize)] | ||
| pub struct OnchainDeliveryMode { | ||
| inner: u8, | ||
| } | ||
|
|
||
| impl OnchainDeliveryMode { | ||
| /// On-chain delivery without constrained encryption/tagging. | ||
| /// | ||
| /// `unconstrained` alone is a reserved Noir keyword. | ||
| pub(crate) fn onchain_unconstrained() -> Self { | ||
| Self { inner: 2 } | ||
| } | ||
|
|
||
| /// On-chain delivery with constrained encryption/tagging. | ||
| pub(crate) fn onchain_constrained() -> Self { | ||
| Self { inner: 3 } | ||
| } | ||
|
|
||
| fn from_u8(inner: u8) -> Self { | ||
| let mode = Self { inner }; | ||
| assert(mode.is_valid(), "unrecognized delivery mode"); | ||
| mode | ||
| } | ||
|
|
||
| /// Whether `self` is one of the valid on-chain delivery modes. | ||
| fn is_valid(self) -> bool { | ||
| (self == Self::onchain_unconstrained()) | (self == Self::onchain_constrained()) | ||
| } | ||
| } | ||
|
|
||
| impl Deserialize for OnchainDeliveryMode { | ||
| let N: u32 = <u8 as Deserialize>::N; | ||
|
|
||
| fn deserialize(fields: [Field; Self::N]) -> Self { | ||
| Self::from_u8(<u8 as Deserialize>::deserialize(fields)) | ||
| } | ||
|
|
||
| fn stream_deserialize<let K: u32>(reader: &mut Reader<K>) -> Self { | ||
| Self::from_u8(reader.read() as u8) | ||
| } | ||
| } | ||
|
|
||
| impl Eq for OnchainDeliveryMode { | ||
| fn eq(self, other: Self) -> bool { | ||
| self.inner == other.inner | ||
| } | ||
| } | ||
|
|
||
| impl ToField for OnchainDeliveryMode { | ||
| fn to_field(self) -> Field { | ||
| self.inner as Field | ||
| } | ||
| } | ||
|
|
||
| impl From<OnchainDeliveryMode> for DeliveryMode { | ||
| fn from(mode: OnchainDeliveryMode) -> DeliveryMode { | ||
| DeliveryMode { inner: mode.inner } | ||
| } | ||
| } | ||
|
|
||
| mod test { | ||
| use crate::protocol::traits::{Deserialize, Serialize}; | ||
| use super::{DeliveryMode, OnchainDeliveryMode}; | ||
|
|
||
| #[test] | ||
| fn onchain_delivery_modes_are_valid() { | ||
| assert(OnchainDeliveryMode::onchain_unconstrained().is_valid()); | ||
| assert(OnchainDeliveryMode::onchain_constrained().is_valid()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn mode_roundtrips_through_serialization() { | ||
| let unconstrained_mode = OnchainDeliveryMode::onchain_unconstrained(); | ||
| let constrained_mode = OnchainDeliveryMode::onchain_constrained(); | ||
|
|
||
| assert(OnchainDeliveryMode::deserialize(unconstrained_mode.serialize()) == unconstrained_mode); | ||
| assert(OnchainDeliveryMode::deserialize(constrained_mode.serialize()) == constrained_mode); | ||
| } | ||
|
|
||
| #[test(should_fail_with = "unrecognized delivery mode")] | ||
| fn deserializing_invalid_mode_fails() { | ||
| let _ = OnchainDeliveryMode::deserialize([99]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn delivery_mode_maps_to_onchain_subset() { | ||
| assert(DeliveryMode::offchain().onchain_mode().is_none()); | ||
| assert( | ||
| DeliveryMode::onchain_constrained().onchain_mode().unwrap() == OnchainDeliveryMode::onchain_constrained(), | ||
| ); | ||
| assert( | ||
| DeliveryMode::onchain_unconstrained().onchain_mode().unwrap() | ||
| == OnchainDeliveryMode::onchain_unconstrained(), | ||
| ); | ||
| } | ||
| } | ||
59 changes: 59 additions & 0 deletions
59
noir-projects/aztec-nr/aztec/src/messages/delivery/tag_secret_derivation.nr
This file contains hidden or 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,59 @@ | ||
| use super::mode::OnchainDeliveryMode; | ||
|
|
||
| /// Noir does not support enums, so this wrapper models tag-secret derivation variants. | ||
| pub(crate) struct TagSecretDerivation { | ||
| inner: u8, | ||
| } | ||
|
|
||
| impl TagSecretDerivation { | ||
| pub(crate) fn wallet_default() -> Self { | ||
| Self { inner: 0 } | ||
| } | ||
|
|
||
| pub(crate) fn address_secret() -> Self { | ||
| Self { inner: 1 } | ||
| } | ||
|
|
||
| pub(crate) fn non_interactive_handshake() -> Self { | ||
| Self { inner: 2 } | ||
| } | ||
|
|
||
| pub(crate) fn assert_is_constant(self) { | ||
| assert_constant(self.inner); | ||
| } | ||
|
|
||
| pub(crate) fn resolve_for_mode(self, mode: OnchainDeliveryMode) -> Self { | ||
|
vezenovm marked this conversation as resolved.
Outdated
|
||
| if self == Self::wallet_default() { | ||
| // TODO(F-699): resolve the wallet default through PXE's delivery privacy preference. | ||
| if mode == OnchainDeliveryMode::onchain_constrained() { | ||
| Self::non_interactive_handshake() | ||
| } else { | ||
| Self::address_secret() | ||
| } | ||
| } else { | ||
| self | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Eq for TagSecretDerivation { | ||
| fn eq(self, other: Self) -> bool { | ||
| self.inner == other.inner | ||
| } | ||
| } | ||
|
|
||
| mod test { | ||
| use super::{OnchainDeliveryMode, TagSecretDerivation}; | ||
|
|
||
| #[test] | ||
| fn wallet_default_resolves_for_the_current_mode() { | ||
| assert( | ||
| TagSecretDerivation::wallet_default().resolve_for_mode(OnchainDeliveryMode::onchain_unconstrained()) | ||
| == TagSecretDerivation::address_secret(), | ||
| ); | ||
| assert( | ||
| TagSecretDerivation::wallet_default().resolve_for_mode(OnchainDeliveryMode::onchain_constrained()) | ||
| == TagSecretDerivation::non_interactive_handshake(), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.