aztec-nr - noir_aztec::context::call_interfaces

Struct PublicCallInterface

pub struct PublicCallInterface<let M: u32, T>
{ /* private fields */ }

Implementations

impl<let M: u32, T> PublicCallInterface<M, T>

pub fn new( target_contract: AztecAddress, selector: FunctionSelector, name: str<M>, args: [Field], is_static: bool, ) -> Self
where T: Deserialize
pub fn with_gas(&mut self, gas_opts: GasOpts) -> &mut Self
where T: Deserialize
pub unconstrained fn call(self, context: &mut PublicContext) -> T
where T: Deserialize

Makes the call to this public function.

Will revert if the called function reverts or runs out of gas.

Arguments

  • context - The PublicContext -- made magically available to the body of every #[public] function as context, through the #[public] annotation's macro.

Returns

  • T - Whatever data the called function has returned.
pub unconstrained fn view(self, context: &mut PublicContext) -> T
where T: Deserialize

Makes a read-only call to this public function.

This is similar to Solidity's staticcall. The called function cannot modify state or emit events. Any nested calls are constrained to also be staticcalls.

Will revert if the called function reverts or runs out of gas.

Arguments

  • context - The PublicContext -- made magically available to the body of every #[public] function as context, through the #[public] annotation's macro.

Returns

  • T - Whatever data the called function has returned.
pub fn enqueue(self, context: &mut PrivateContext)
where T: Deserialize

Enqueues a call to this public function, to be executed later.

Unlike private functions which execute immediately on the user's device, public function calls are "enqueued" and executed some time later by a block proposer.

This means a public function cannot return any values back to a private function, because by the time the public function is being executed, the private function which called it has already completed execution. (In fact, the private function has been executed and proven, along with all other private function calls of the user's tx. A single proof of the tx has been submitted to the Aztec network, and some time later a proposer has picked the tx up from the mempool and begun executing all of the enqueued public functions).

Privacy warning

Enqueueing a public function call is an inherently leaky action. Many interesting applications will require some interaction with public state, but smart contract developers should try to use public function calls sparingly, and carefully. Internal public function calls are especially leaky, because they completely leak which private contract made the call. See also: https://docs.aztec.network/developers/reference/considerations/privacy_considerations

Arguments

  • context - The PrivateContext -- made magically available to the body of every #[private] function as context, through the #[private] annotation's macro.
pub fn enqueue_view(self, context: &mut PrivateContext)
where T: Deserialize

Enqueues a read-only call to this public function.

This is similar to Solidity's staticcall. The called function cannot modify state, emit L2->L1 messages, nor emit events. Any nested calls are constrained to also be staticcalls.

Arguments

  • context - The PrivateContext -- made magically available to the body of every #[private] function as context, through the #[private] annotation's macro.
pub fn set_as_teardown(self, context: &mut PrivateContext)
where T: Deserialize

Enqueues a call to this public function, and designates it to be the teardown function for this tx. Only one teardown function call can be made by a tx.

Niche function: Only wallet developers and paymaster contract developers (aka Fee-payment contracts) will need to make use of this function.

Aztec supports a three-phase execution model: setup, app logic, teardown. The phases exist to enable a fee payer to take on the risk of paying a transaction fee, safe in the knowledge that their payment (in whatever token or method the user chooses) will succeed, regardless of whether the app logic will succeed. The "setup" phase ensures the fee payer has sufficient balance to pay the proposer their fees. The teardown phase is primarily intended to: calculate exactly how much the user owes, based on gas consumption, and refund the user any change.

Note: in some cases, the cost of refunding the user (i.e. DA costs of tx side-effects) might exceed the refund amount. For app logic with fairly stable and predictable gas consumption, a material refund amount is unlikely. For app logic with unpredictable gas consumption, a refund might be important to the user (e.g. if a hefty function reverts very early). Wallet/FPC/Paymaster developers should be mindful of this.

See enqueue for more information about enqueuing public function calls.

Arguments

  • context - The PrivateContext -- made magically available to the body of every #[private] function as context, through the #[private] annotation's macro.

Trait implementations

impl<let M: u32, T> CallInterface<M> for PublicCallInterface<M, T>

pub fn get_args(self) -> [Field] pub fn get_selector(self) -> FunctionSelector pub fn get_name(self) -> str<M> pub fn get_contract_address(self) -> AztecAddress pub fn get_is_static(self) -> bool