Skip to content

feat(aztec-nr)!: remove set_sender_for_tags oracle, use builder pattern for sender override#23619

Merged
nchamo merged 13 commits into
merge-train/fairiesfrom
nchamo/remove-set-sender-for-tags
May 29, 2026
Merged

feat(aztec-nr)!: remove set_sender_for_tags oracle, use builder pattern for sender override#23619
nchamo merged 13 commits into
merge-train/fairiesfrom
nchamo/remove-set-sender-for-tags

Conversation

@nchamo
Copy link
Copy Markdown
Contributor

@nchamo nchamo commented May 28, 2026

Why we are doing this

The set_sender_for_tags oracle was a mutable, side-effectful call that contracts used to override which address is used for discovery tag derivation. The connection between the set_sender_for_tags call and the later .deliver() call was non-obvious.

Our fix

Replace the oracle with a .with_sender(address) builder method on OnchainDelivery, making the sender selection explicit at the delivery call site. MessageDelivery::onchain_constrained() and onchain_unconstrained() now return OnchainDelivery (which exposes with_sender), while offchain() returns MessageDelivery directly (no sender override, since offchain delivery does not use tags).

A MessageDeliveryBuilder trait lets deliver() accept both types generically.

Migration

The set_sender_for_tags oracle has been removed. Contracts that used it should pass the sender address via the .with_sender() builder on onchain delivery modes:

- use aztec::oracle::notes::set_sender_for_tags;

- unsafe { set_sender_for_tags(some_address) };
- note.deliver(MessageDelivery::onchain_constrained());
+ note.deliver(MessageDelivery::onchain_constrained().with_sender(some_address));

Contracts that did not call set_sender_for_tags require no changes.

@nchamo nchamo requested a review from nventuro as a code owner May 28, 2026 13:42
@nchamo nchamo self-assigned this May 28, 2026
@nchamo nchamo force-pushed the nchamo/remove-set-sender-for-tags branch from f599bd7 to c919519 Compare May 28, 2026 14:13
Copy link
Copy Markdown
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for trying to make the world a better place.


- unsafe { set_sender_for_tags(some_address) };
- note.deliver(MessageDelivery::onchain_constrained());
+ note.deliver(MessageDelivery::onchain_constrained_with_sender(SenderForTags::explicit(some_address)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit verbose and ad-hoc. Two suggestions:

  1. Have a second method that just takes the param, avoiding the object, similar to TestEnvironment.private_context_at, makes sense when some option is used often
note.deliver(MessageDelivery::onchain_constrained_from(some_address);
  1. Have a more general options object and a variant that takes it, so that we can further extend these options in the future in backwards compatible ways (like TestEnvironment::private_context_opts:
note.deliver(MessageDelivery::onchain_constrained_opts(DeliveryOpts::new().sender(some_address)));

If you think we'll add more options in the future, I'd go with 2. If not 1 might be good enough.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually in this case because the method is already deliver, what you could do instead is have deliver take the full options object and use a builder pattern. This would be more extensible and less verbose

struct DeliveryMethod {
  variant: u8,
  sender: Option<Address>, 
}

impl DeliveryMethod {
  fn onchain_constrained() -> Self {
     Self { variant: ONCHAIN_CONST, sender: none() }
  }

  fn onchain_unconstrained() -> Self { ... }

  fn with_sender(&mut self, sender: Addr) -> Self {
     self.sender = some(sender);
     self
  }
}

and you then do

msg.deliver(DeliveryMethod.onchain_constrained());
// or
msg.deliver(DeliveryMethod.onchain_unconstrained().with_sender(some_sender));

If you want to forbid certain combinations (e.g. not allow with_sender for offchain delivery) then you can either add runtime checks to that fn, or compile time checks by having each delivery fn return a different type, which then each have different methods of their own (the config for each deli mechanism).

Note how in this case we're not exposing the internal types, the members of the struct etc., we just commit to the method chain. So we can freely add more stuff or change the internal repr with no breaking changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really liked this idea, I implemented it so that .offchain() couldn't be chained with .with_sender()

Comment thread noir-projects/aztec-nr/aztec/src/messages/logs/sender_for_tags.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/messages/logs/sender_for_tags.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/messages/message_delivery.nr Outdated
@nchamo nchamo force-pushed the nchamo/remove-set-sender-for-tags branch from c919519 to 9c6cbd8 Compare May 28, 2026 19:56
};

#[test]
fn constructors_produce_distinct_variants() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As requested

@nchamo nchamo changed the title feat(aztec-nr)!: introduce SenderForTags, remove set_sender_for_tags oracle feat(aztec-nr)!: remove set_sender_for_tags oracle, use builder pattern for sender override May 28, 2026
Comment thread docs/docs-developers/docs/aztec-nr/framework-description/note_delivery.md Outdated
Comment thread docs/docs-developers/docs/foundational-topics/advanced/storage/note_discovery.md Outdated
Comment thread noir-projects/aztec-nr/aztec/src/messages/logs/utils.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/messages/message_delivery.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/messages/message_delivery.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/messages/message_delivery.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/messages/message_delivery.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/note/note_message.nr Outdated
/// Unlike [`MessageDelivery`] (which is returned by [`MessageDelivery::offchain`]), this type exposes
/// [`with_sender`](OnchainDelivery::with_sender), which overrides the sender address used for discovery tag
/// derivation.
pub struct OnchainDelivery {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this and MessageDelivery need to be pub?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sadly yes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh it's not too bad I guess, as longs as the members are not pub (and so the thing cannot be constructed directly).

nchamo added 5 commits May 29, 2026 15:31
Introduce a dedicated OffchainDelivery type so the resolved delivery struct
no longer doubles as its own builder, switch with_sender to &mut self, drop a
redundant assert_constant, and clarify the related docstrings, error message,
docs, and account-contract comments.
…/remove-set-sender-for-tags

# Conflicts:
#	noir-projects/aztec-nr/aztec/src/standard_addresses.nr
#	noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/standard_addresses.nr
#	yarn-project/standard-contracts/src/standard_contract_data.ts
The merge brought in message-signing and fallback keys (#23510), which
extended the contract instance (CONTRACT_INSTANCE_LENGTH 10 -> 12). The
previously committed addresses were derived against a stale local TS
build using the old instance layout. Regenerate against the rebuilt
toolchain so the compile_all drift check passes.
@nchamo nchamo enabled auto-merge (squash) May 29, 2026 16:27
@AztecBot
Copy link
Copy Markdown
Collaborator

Flakey Tests

🤖 says: This CI run detected 1 tests that failed, but were tolerated due to a .test_patterns.yml entry.

\033FLAKED\033 (8;;http://ci.aztec-labs.com/969280e836194079�969280e8361940798;;�):  yarn-project/end-to-end/scripts/run_test.sh simple src/e2e_slashing/attested_invalid_proposal.test.ts (363s) (code: 0)

@nchamo nchamo merged commit ca275b7 into merge-train/fairies May 29, 2026
14 checks passed
@nchamo nchamo deleted the nchamo/remove-set-sender-for-tags branch May 29, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants