Skip to content

Commit

Permalink
feat!: migrate public to avm simulator (#6448)
Browse files Browse the repository at this point in the history
This PR migrates the public (execution) environment to use the AVM
simulator. The idea of this PR is to be as minimal as possible, as to
enable easy rollbacks if needed. If things go well, there is a lot of
cleanup to do afterwards, which we are tracking in [this
issue](#5818).

Major Changes
* `PublicContext` gets replaced with what was the `AvmContext`.
* Noir Aztec macros now always take the AVM path for public.
* Migration notes are added.

Other changes
* Delegate call tests are disabled, since the AVM doesn't support
delegate calls.
* ACIR public execution tests are disabled.
* Fees were changed in `bench_tx_size_fees` since the cost is now
different (bytecode and L2 gas changes).

---------

Co-authored-by: dbanks12 <[email protected]>
  • Loading branch information
fcarreiro and dbanks12 authored May 21, 2024
1 parent da82b58 commit c45e8c2
Show file tree
Hide file tree
Showing 32 changed files with 459 additions and 1,235 deletions.
2 changes: 1 addition & 1 deletion avm-transpiler/src/transpile_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl From<CompiledAcirContractArtifact> for TranspiledContractArtifact {
// TODO(4269): once functions are tagged for transpilation to AVM, check tag
if function
.custom_attributes
.contains(&"aztec(public-vm)".to_string())
.contains(&"aztec(public)".to_string())
{
info!(
"Transpiling AVM function {} on contract {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,7 @@ New L2 to L1 messages contains messages that are delivered to the [l1 outbox](/p

## Public Context

The Public Context includes all of the information passed from the `Public VM` into the execution environment. It is very similar to the [Private Context](#the-private-context), however it has some minor differences (detailed below).

### Public Context Inputs

In the current version of the system, the public context is almost a clone of the private execution context.

#include_code public-context-inputs /noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr rust
The Public Context includes all of the information passed from the `Public VM` into the execution environment. Its interface is very similar to the [Private Context](#the-private-context), however it has some minor differences (detailed below).

### Public Global Variables

Expand Down
33 changes: 27 additions & 6 deletions docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,30 @@ keywords: [sandbox, cli, aztec, notes, migration, updating, upgrading]

Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them.

## 0.41.0
## 0.42.0

## Public execution migrated to the Aztec Virtual Machine

**What does this mean for me?**

It should be mostly transparent, with a few caveats:

- Not all Noir blackbox functions are supported by the AVM. Only `Sha256`, `PedersenHash`, `Poseidon2Permutation`, `Keccak256`, and `ToRadix` are supported.
- For public functions, `context.nullifier_exists(...)` will now also consider pending nullifiers.
- The following methods of `PublicContext` are not supported anymore: `fee_recipient`, `fee_per_da_gas`, `fee_per_l2_gas`, `call_public_function_no_args`, `static_call_public_function_no_args`, `delegate_call_public_function_no_args`, `call_public_function_with_packed_args`, `set_return_hash`, `finish`. However, in terms of functionality, the new context's interface should be equivalent (unless otherwise specified in this list).
- Delegate calls are not yet supported in the AVM.
- If you have types with custom serialization that you use across external contracts calls, you might need to modify its serialization to match how Noir would serialize it. This is a known problem unrelated to the AVM, but triggered more often when using it.
- A few error messages might change format, so you might need to change your test assertions.

**Internal details**

Before this change, public bytecode was executed using the same simulator as in private: the ACIR simulator (and internally, the Brillig VM). On the Aztec.nr side, public functions accessed the context through `PublicContext`.

After this change, public bytecode will be run using the AVM simulator (the simulator for our upcoming zkVM). This bytecode is generated from Noir contracts in two steps: First, `nargo compile` produces an artifact which has Brillig bytecode for public functions, just as it did before. Second: the `avm-transpiler` takes that artifact, and it transpiles Brillig bytecode to AVM bytecode. This final artifact can now be deployed and used with the new public runtime.

On the Aztec.nr side, public functions keep accessing the context using `PublicContext` but the underlying implementation is switch with what formerly was the `AvmContext`.

## 0.41.0

### [Aztec.nr] State variable rework

Expand All @@ -27,7 +48,8 @@ fn get_decimals() -> pub u8 {
}
```

The compiler will now error out with
The compiler will now error out with

```
Expected type SharedImmutable<_, &mut PrivateContext>, found type SharedImmutable<u8, &mut PublicContext>
```
Expand All @@ -44,7 +66,7 @@ This means that, without any additional features, we'd end up with some extra bo
#[aztec(storage)]
- struct Storage {
+ struct Storage<Context> {
- nonce_for_burn_approval: PublicMutable<Field>,
- nonce_for_burn_approval: PublicMutable<Field>,
+ nonce_for_burn_approval: PublicMutable<Field, Context>,
- portal_address: SharedImmutable<EthAddress>,
+ portal_address: SharedImmutable<EthAddress, Context>,
Expand Down Expand Up @@ -90,8 +112,8 @@ Additionally, the Noir LSP will now honor "go to definitions" requests for contr

### [Aztec.js] Simulate changes

* `.simulate()` now tracks closer the process performed by `.send().wait()`, specifically going through the account contract entrypoint instead of directly calling the intended function.
* `wallet.viewTx(...)` has been renamed to `wallet.simulateUnconstrained(...)` to better clarify what it does.
- `.simulate()` now tracks closer the process performed by `.send().wait()`, specifically going through the account contract entrypoint instead of directly calling the intended function.
- `wallet.viewTx(...)` has been renamed to `wallet.simulateUnconstrained(...)` to better clarify what it does.

### [Aztec.nr] Keys: Token note now stores an owner master nullifying public key hash instead of an owner address

Expand Down Expand Up @@ -119,7 +141,6 @@ Creating a token note and adding it to storage now looks like this:

Computing the nullifier similarly changes to use this master nullifying public key hash.


## 0.40.0

### [Aztec.nr] Debug logging
Expand Down
5 changes: 1 addition & 4 deletions noir-projects/aztec-nr/aztec/src/context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod inputs;

mod private_context;
mod public_context;
mod avm_context;
mod interface;
mod call_interfaces;
mod gas;
Expand All @@ -12,11 +11,9 @@ use interface::ContextInterface;
use call_interfaces::{
PrivateCallInterface, PrivateStaticCallInterface, PublicCallInterface, PublicStaticCallInterface,
PrivateVoidCallInterface, PrivateStaticVoidCallInterface, PublicVoidCallInterface,
PublicStaticVoidCallInterface, AvmCallInterface, AvmStaticCallInterface, AvmVoidCallInterface,
AvmStaticVoidCallInterface
PublicStaticVoidCallInterface
};
use private_context::PrivateContext;
use private_context::PackedReturns;
use public_context::PublicContext;
use public_context::FunctionReturns;
use avm_context::AvmContext;
Loading

0 comments on commit c45e8c2

Please sign in to comment.