-
Notifications
You must be signed in to change notification settings - Fork 614
docs(yellowpaper): AVM intro sections #3692
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
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
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,78 @@ | ||
| --- | ||
| sidebar_position: 0 | ||
| --- | ||
|
|
||
| # Aztec Virtual Machine | ||
|
|
||
| :::important disclaimer | ||
| This is a draft. These requirements need to be considered by the wider team, and might change significantly before a mainnet release. | ||
| ::: | ||
| :::note reference | ||
| Many terms and definitions here are borrowed from the [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf). | ||
| ::: | ||
|
|
||
| ## Introduction | ||
| An Aztec transaction may include one or more public execution requests. A public execution request represents an initial "message call" to a contract, providing input data and triggering the execution of that contract's public code in the Aztec Virtual Machine. Given a message call to a contract, the AVM executes the corresponding code one instruction at a time, treating each instruction as a transition function on its state. | ||
|
|
||
| > Public execution requests may originate as [`enqueuedPublicFunctionCalls`](../calls/enqueued-calls.md) triggered during the transaction's private execution. | ||
|
|
||
| This document contains the following sections: | ||
| - **Public contract bytecode** (aka AVM bytecode) | ||
| - **Execution Context**, outlining the AVM's environment and state | ||
| - **Execution**, outlining control flow, gas tracking, halting, and reverting | ||
| - **Nested calls**, outlining the initiation of message calls, processing of sub-context results, gas refunds, and world state reverts | ||
|
|
||
| The **["AVM Instruction Set"](./InstructionSet)** document supplements this one with the list of all supported instructions and their associated state transition functions. | ||
|
|
||
| > Note: The Aztec Virtual Machine, while designed with a SNARK implementation in mind, is not strictly tied to any particular implementation and therefore is defined without SNARK or circuit-centric verbiage. That being said, considerations for a SNARK implementation are raised or linked when particularly relevant or helpful. | ||
|
|
||
| ## Public contract bytecode | ||
| A contract's public bytecode is series of execution instructions for the AVM. When a message call is made to a contract, the AVM retrieves the corresponding bytecode from the world state (`worldState.contracts[address].bytecode`) and triggers execution of the first instruction (`bytecode[0]`). The world state is described in more detail later. | ||
|
|
||
| > Note: While a Noir contract may have multiple public functions, they are inlined so that the **entirety of a contract's public code exists in a single bytecode**. Internal calls to Noir functions within the same contract are compiled to simple program-counter changes, as are internal returns. In a manner similar to the Ethereum Virtual Machine, the AVM is not itself aware of function selectors and internal function calls. The Noir compiler may implement these constructs by treating the first word in a message call's calldata as a function selector, and beginning a contract's bytecode with a series of conditional jumps. | ||
|
|
||
| > Note: See the [Bytecode Validation Circuit](./bytecode-validation-circuit.md) to see how a contract's bytecode can be validated and committed to which is particularly relevant for a SNARK implementation of the AVM. | ||
|
dbanks12 marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## Execution Context | ||
| :::note REMINDER | ||
| Many terms and definitions here are borrowed from the [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf). | ||
| ::: | ||
|
|
||
| An "Execution Context" includes the information necessary to trigger AVM execution along with the state maintained by the AVM throughout execution: | ||
| ``` | ||
| AVMContext { | ||
| environment: ExecutionEnvironment, | ||
| machineState: MachineState, | ||
| worldState: WorldState, | ||
| accruedSubstate: AccruedSubstate, | ||
| results: MessageCallResults, | ||
| } | ||
| ``` | ||
|
|
||
| The "Execution Environment" is provided by the execution agent and remains constant throughout a message call's execution. A new environment is initialized for any nested message calls. | ||
| ``` | ||
| ExecutionEnvironment { | ||
| address, | ||
| origin, | ||
| l1GasPrice, | ||
| l2GasPrice, | ||
| calldata: [], | ||
| sender, | ||
| portal, | ||
| bytecode: [], | ||
| blockHeader, | ||
| messageCallDepth, | ||
| isStaticCall, | ||
| } | ||
| ``` | ||
| > TODO: what about global variables? | ||
|
|
||
| "Machine State" belongs to single message call and is transformed on an instruction-per-instruction basis. A message call's machine state is initialized, alongside its execution environment, prior to the start of its execution: | ||
|
dbanks12 marked this conversation as resolved.
Outdated
|
||
| ``` | ||
| MachineState { | ||
| l1GasLeft, | ||
| l2GasLeft, | ||
| pc, | ||
| memory: [], | ||
| } | ||
| ``` | ||
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.