Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<Storage, CallSelf, CallSelfStatic, CallInternal> ContractSelfPublic<Storage
///
/// Public event emission is achieved by emitting public transaction logs. A total of `N+1` fields are emitted,
/// where `N` is the serialization length of the event.
pub fn emit<Event>(&mut self, event: Event)
pub unconstrained fn emit<Event>(&mut self, event: Event)
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.

Why is this required?

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.

We could just call the inner emit_event_in_public method with unsafe (we need emit_event_in_public to be unconstrained as #[inline_never] is an unconstrained-only attribute in Noir). I figured as this is on ContractSelfPublic it was actually more accurate to have it be marked unconstrained explicitly.

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.

If we add this here, aren't we forcing all contracts to add a safety tag when emitting events?

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.

The doc comments on this type state: "Core interface for interacting with aztec-nr contract features in public execution contexts." I was going off the assumption that ContractSelfPublic would only ever be used in the public runtime which is always unconstrained Noir. This looks to be the case for all our tests (which is what I would expect).

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.

Yes, the fucntions themselves are not because it confuses people. It's a long-standing issue: Noir has two execution modes, but Aztec has three. It makes me profoundly unhappy. Developers are taught that unconstraed == scary, and so public functions being unconstrained seems odd. They're actually constrained, it's just that the constraining happens by the AVM.

where
Event: EventInterface + Serialize,
{
Expand Down
3 changes: 2 additions & 1 deletion noir-projects/aztec-nr/aztec/src/event/event_emission.nr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ where
}

/// Equivalent to `self.emit(event)`: see [`crate::contract_self::ContractSelfPublic::emit`].
pub fn emit_event_in_public<Event>(context: PublicContext, event: Event)
#[inline_never]
pub unconstrained fn emit_event_in_public<Event>(context: PublicContext, event: Event)
where
Event: EventInterface + Serialize,
{
Expand Down
Loading