Calls
Calls
Functions in the Aztec Network can call other functions. There are several types of call:
- Synchronous calls: when a private function calls another private function; or when a public function calls another public function.
- Enqueued calls: when a private function calls a public function.
- Batched calls: when multiple calls to the same function are enqueued and processed as a single call on a concatenation of the arguments.
The protocol also supports alternative call methods, such as static, delegate, and unconstrained calls.
In addition to function calls, the protocol allows for communication via message-passing back-and-forth between L1 and L2, as well as from public to private functions.
📄️ Synchronous calls
Calls from a private function to another private function, as well as calls from a public function to another public function, are synchronous. When a synchronous function call is found during execution, execution jumps to the target of the call, and returns to the caller with a return value from the function called. This allows easy composability across contracts.
📄️ Enqueued calls
Calls from private functions to public functions are asynchronous. Since private and public functions are executed in different domains at different times and in different contexts -- the former are run locally by the user in a PXE and the latter by the sequencer -- it is not possible for a private function to call a public one and await its result. Instead, private functions can enqueue public function calls.
📄️ Batched calls
The low-level specifics of how batched calls will work is still being discussed.
📄️ Static calls
Synchronous calls, both private and public, can be executed as static calls. This means that the called function, and all nested calls within, cannot emit any modifying side effects, such as creating or consuming notes, writing to storage, or emitting events. The purpose of a static call is to query another contract while ensuring that the call will not modify state. Static calls are based on EIP214.
📄️ Delegate calls
Delegate calls are function calls against a contract class identifier instead of an instance. Any call -- synchronous or asynchronous -- can be made as a delegate call. The behavior of a delegate call is to execute the function code in the specified class identifier but in the context of the current instance. This opens the door to script-like executions and upgradeable contracts. Delegate calls are based on EIP7.
📄️ Unconstrained calls
<!--
📄️ Inter-Layer Calls
Public-Private messaging