-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhaul the gas and fees section of the whitepaper.
- Loading branch information
1 parent
26cba9e
commit d0b3f06
Showing
12 changed files
with
955 additions
and
386 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
docs/docs/protocol-specs/gas-and-fees/fee-payment-asset.md
This file contains 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,22 @@ | ||
--- | ||
title: Fee Payment Asset | ||
--- | ||
|
||
# Fee Payment Asset | ||
|
||
The Fee Payment Asset (FPA) is an enshrined asset in the Aztec network that is used to pay fees. | ||
|
||
The FPA has several important properties: | ||
|
||
- It is fungible | ||
- It cannot be transferred between accounts on the Aztec network | ||
- It is obtained on Aztec via a bridge from Ethereum | ||
- It only has public balances | ||
|
||
All transactions on the Aztec network have a [non-zero transaction_fee](./fee-schedule.md#da-gas), denominated in FPA, which must be paid for the transaction to be included in the block. | ||
|
||
When a block is successfully published on L1, the sequencer is paid on L1 the sum of all transaction fees in the block, denominated in FPA. | ||
|
||
:::danger | ||
We need a definition of the L1 fee payment asset. | ||
::: |
360 changes: 0 additions & 360 deletions
360
docs/docs/protocol-specs/gas-and-fees/fee-payments-and-metering.md
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,26 +1,107 @@ | ||
# Fee Schedule | ||
|
||
:::info | ||
This section is a placeholder, we will flesh this out in much greater detail when we come to profile operations and assign gas costs | ||
The [transaction fee](./specifying-gas-fee-info.md#transaction-fee) is comprised of a DA component, an L2 component, and an inclusion fee. The DA and L2 components are calculated by multiplying the gas consumed in each dimension by the respective `feePerGas` value. The inclusion fee is a fixed cost associated with the transaction, which is used to cover the cost of verifying the encompassing rollup proof on L1. | ||
|
||
# DA Gas | ||
|
||
DA gas is consumed to cover the costs associated with publishing data associated with a transaction. | ||
|
||
These data include: | ||
- new note hashes | ||
- new nullifiers | ||
- new l2 -> l1 message hashes | ||
- new public data writes | ||
- new logs | ||
- protocol metadata (e.g. the amount of gas consumed, revert code, etc.) | ||
|
||
The DA gas used is then calculated as: | ||
|
||
``` | ||
DA_BYTES_PER_FIELD = 32 | ||
DA_GAS_PER_BYTE = 16 | ||
FIXED_DA_GAS = 512 | ||
# FIXED_DA_GAS covers the protocol metadata, | ||
# which should remain less than 512/16 = 32 bytes | ||
da_gas_per_field = DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE | ||
note_hash_gas = da_gas_per_field * (number of notes) | ||
nullifier_gas = da_gas_per_field * (number of nullifiers) | ||
l2_to_l1_message_gas = da_gas_per_field * (number of l2_to_l1_messages) | ||
# public data writes specify a value and index | ||
public_data_writes_gas = 2 * da_gas_per_field * (number of public_data_writes) | ||
log_gas = DA_GAS_PER_BYTE * (unencrypted_log_preimages_length + encrypted_log_preimages_length) | ||
da_gas_used = FIXED_DA_GAS + | ||
note_hash_gas + | ||
nullifier_gas + | ||
l2_to_l1_message_gas + | ||
public_data_writes_gas + | ||
log_gas + | ||
teardown_da_gas | ||
``` | ||
|
||
:::note Non-zero `transaction_fees` | ||
A side effect of the above calculation is that all transactions will have a non-zero `transaction_fee`. | ||
::: | ||
|
||
<!-- prettier-ignore --> | ||
| Action | Resource Domain | Consumption Calculation | Comment | | ||
| -------- | -------- | -------- | ------- | | ||
| Verifying the private kernel proof | L2 | Fixed L2/Transaction | | | ||
| Verifying each nullifier against the world state | L2 | Fixed L2/Tx nullifier | | | ||
| Verifying each nullifier against others in the same block | L2 | Fixed L2/Tx nullifier | Whilst not strictly a fixed cost, this would need to be allocated as a fixed cost as it depends on the composition of the rollup | | ||
| Verifying log preimages against the sha256 log hashes contained in the private kernel public inputs | L2 | L2 gas per pre-image field | | | ||
| Verifying contract deployment data against the sha256 hash of this data contained in the private kernel public inputs | L2 | L2 gas per hash | | | ||
| Publishing contract data to DA | DA | DA gas per byte | | | ||
| Publishing state updates to DA | DA | DA gas per byte | | | ||
| Publishing notes/tags to DA | DA | DA gas per byte | | | ||
| Publishing L2->L1 messages | L1 | Calldata gas per byte + processing & storing of the message | | | ||
| Public function execution | L2 | L2 gas per function opcode | | | ||
| Proving the public VM circuit for a public function | L2 | Fixed L2/Tx public function | | | ||
| Proving the public kernel circuit for a public function | L2 | Fixed L2/Tx public function | | | ||
| Proving the base rollup circuit | L2 | Fixed L2/Transaction | | ||
| Proving the merge rollup circuit | L2 | Amortized L2/Transaction | | ||
| Proving the root rollup circuit | L2 | Amortized L2/Transaction | | ||
| Publishing the block header to L1 | L1 | Amortized L1/Transaction | | ||
| Verifying the rollup proof | L1 | Amortized L1/Transaction | | ||
# L2 Gas | ||
|
||
L2 gas is consumed to cover the costs associated with executing the public VM, proving the public VM circuit, and proving the public kernel circuit. | ||
|
||
The public vm has an [instruction set](../public-vm/instruction-set.mdx) with opcode level gas metering to cover the cost of actions performed within the public VM. | ||
|
||
Additionally, there is a fixed cost associated with each iteration of the public VM (i.e. the number of enqueued public function calls, plus 1 if there is a teardown function), which is used to cover the cost of proving the public VM circuit. | ||
|
||
The L2 gas used is then calculated as: | ||
|
||
``` | ||
AVM_STARTUP_L2_GAS = 1024 | ||
num_avm_invocations = (number of enqueued public function calls) + | ||
(is there a teardown function ? 1 : 0) | ||
l2_gas_used = AVM_STARTUP_L2_GAS * num_avm_invocations + | ||
teardown_l2_gas + | ||
(gas reported as consumed by the public VM) | ||
``` | ||
|
||
:::warning L2 Gas from Private | ||
In the current implementation, private execution does not consume L2 gas. This will change in future versions of the protocol, because there is still work that needs to be performed by the sequencer correspondent to the private outputs, which is effectively L2 gas. The following operations performed in private execution will likely consume L2 gas in future versions of the protocol: | ||
- emitting note hashes (due to tree insertion) | ||
- emitting nullifiers (due to tree insertion) | ||
- possibly emitting logs (due to validation checks) | ||
::: | ||
|
||
# Max Inclusion Fee | ||
|
||
Each transaction, and each block, has inescapable overhead costs associated with it which are not directly related to the amount of data or computation performed. | ||
|
||
These costs include: | ||
- verifying the private kernel proof of each transaction | ||
- executing/proving the base/merge/root rollup circuits | ||
- includes verifying that every new nullifier is unique across the tx/block | ||
- includes processing l2->l1 messages of each transaction, even if they are empty (and thus have no DA gas cost) | ||
- includes ingesting l1->l2 messages that were posted during the previous block | ||
- injecting a public data write to levy the transaction fee on the `fee_payer` | ||
- publishing the block header to the rollup contract on L1 | ||
- includes verification of the rollup proof | ||
- includes insertion of the new root of the l2->l1 message tree into the L1 Outbox | ||
- consumes the pending messages in the L1 Inbox | ||
- publishing the block header to DA | ||
|
||
See [the l1 contracts section](../l1-smart-contracts/index.md) for more information on the L1 Inbox and Outbox. | ||
|
||
Users cover these costs by [specifying an inclusion fee](./specifying-gas-fee-info.md#specifying-gas--fee-info), which is different from other parameters specified in that it is a fixed fee offered to the sequencer, denominated in [FPA](./fee-payment-asset.md). | ||
|
||
Even though these line items will be the same for every transaction in a block, the **cost** to the sequencer will vary, particularly based on: | ||
- congestion on L1 | ||
- prevailing price of proof generation | ||
|
||
A price discovery mechanism is being developed to help users set the inclusion fee appropriately. | ||
|
||
|
This file contains 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
Oops, something went wrong.