Skip to content
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

chore: remove l1 gas #6069

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions avm-transpiler/src/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub enum AvmOpcode {
ADDRESS,
STORAGEADDRESS,
SENDER,
FEEPERL1GAS,
FEEPERL2GAS,
FEEPERDAGAS,
CONTRACTCALLDEPTH,
Expand All @@ -31,12 +30,10 @@ pub enum AvmOpcode {
BLOCKNUMBER,
TIMESTAMP,
COINBASE,
BLOCKL1GASLIMIT,
BLOCKL2GASLIMIT,
BLOCKDAGASLIMIT,
CALLDATACOPY,
// Gas
L1GASLEFT,
L2GASLEFT,
DAGASLEFT,
// Control flow
Expand Down Expand Up @@ -101,7 +98,6 @@ impl AvmOpcode {
AvmOpcode::ADDRESS => "ADDRESS",
AvmOpcode::STORAGEADDRESS => "STORAGEADDRESS",
AvmOpcode::SENDER => "SENDER",
AvmOpcode::FEEPERL1GAS => "FEEPERL1GAS",
AvmOpcode::FEEPERL2GAS => "FEEPERL2GAS",
AvmOpcode::FEEPERDAGAS => "FEEPERDAGAS",
AvmOpcode::CONTRACTCALLDEPTH => "CONTRACTCALLDEPTH",
Expand All @@ -111,15 +107,13 @@ impl AvmOpcode {
AvmOpcode::BLOCKNUMBER => "BLOCKNUMBER",
AvmOpcode::TIMESTAMP => "TIMESTAMP",
AvmOpcode::COINBASE => "COINBASE",
AvmOpcode::BLOCKL1GASLIMIT => "BLOCKL1GASLIMIT",
AvmOpcode::BLOCKL2GASLIMIT => "BLOCKL2GASLIMIT",
AvmOpcode::BLOCKDAGASLIMIT => "BLOCKDAGASLIMIT",
// Execution Environment - Calldata
AvmOpcode::CALLDATACOPY => "CALLDATACOPY",

// Machine State
// Machine State - Gas
AvmOpcode::L1GASLEFT => "L1GASLEFT",
AvmOpcode::L2GASLEFT => "L2GASLEFT",
AvmOpcode::DAGASLEFT => "DAGASLEFT",
// Machine State - Internal Control Flow
Expand Down
6 changes: 2 additions & 4 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ fn handle_external_call(
let gas = inputs[0];
let gas_offset = match gas {
ValueOrArray::HeapArray(HeapArray { pointer, size }) => {
assert!(size == 3, "Call instruction's gas input should be a HeapArray of size 3 (`[l1Gas, l2Gas, daGas]`)");
assert!(size == 2, "Call instruction's gas input should be a HeapArray of size 2 (`[l2Gas, daGas]`)");
pointer.0 as u32
}
ValueOrArray::HeapVector(_) => panic!("Call instruction's gas input must be a HeapArray, not a HeapVector. Make sure you are explicitly defining its size as 3 (`[l1Gas, l2Gas, daGas]`)!"),
ValueOrArray::HeapVector(_) => panic!("Call instruction's gas input must be a HeapArray, not a HeapVector. Make sure you are explicitly defining its size as 2 (`[l2Gas, daGas]`)!"),
_ => panic!("Call instruction's gas input should be a HeapArray"),
};
let address_offset = match &inputs[1] {
Expand Down Expand Up @@ -741,14 +741,12 @@ fn handle_getter_instruction(
"avmOpcodeAddress" => AvmOpcode::ADDRESS,
"avmOpcodeStorageAddress" => AvmOpcode::STORAGEADDRESS,
"avmOpcodeSender" => AvmOpcode::SENDER,
"avmOpcodeFeePerL1Gas" => AvmOpcode::FEEPERL1GAS,
"avmOpcodeFeePerL2Gas" => AvmOpcode::FEEPERL2GAS,
"avmOpcodeFeePerDaGas" => AvmOpcode::FEEPERDAGAS,
"avmOpcodeChainId" => AvmOpcode::CHAINID,
"avmOpcodeVersion" => AvmOpcode::VERSION,
"avmOpcodeBlockNumber" => AvmOpcode::BLOCKNUMBER,
"avmOpcodeTimestamp" => AvmOpcode::TIMESTAMP,
"avmOpcodeL1GasLeft" => AvmOpcode::L1GASLEFT,
"avmOpcodeL2GasLeft" => AvmOpcode::L2GASLEFT,
"avmOpcodeDaGasLeft" => AvmOpcode::DAGASLEFT,
// "callStackDepth" => AvmOpcode::CallStackDepth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ enum class OpCode : uint8_t {
ADDRESS,
STORAGEADDRESS,
SENDER,
FEEPERL1GAS,
FEEPERL2GAS,
FEEPERDAGAS,
CONTRACTCALLDEPTH,
Expand All @@ -51,15 +50,13 @@ enum class OpCode : uint8_t {
BLOCKNUMBER,
TIMESTAMP,
COINBASE,
BLOCKL1GASLIMIT,
BLOCKL2GASLIMIT,
BLOCKDAGASLIMIT,
// Execution Environment - Calldata
CALLDATACOPY,

// Machine State
// Machine State - Gas
L1GASLEFT,
L2GASLEFT,
DAGASLEFT,
// Machine State - Internal Control Flow
Expand Down
3 changes: 0 additions & 3 deletions docs/docs/protocol-specs/circuits/private-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ After generating a proof for a private function circuit, that proof (and associa
| `da.gas_limit` | `u32` | Total limit for DA gas for the transaction. |
| `da.teardown_gas_limit` | `u32` | Limit for DA gas specific to the teardown phase. |
| `da.max_fee_per_gas` | `field` | Maximum amount that the sender is willing to pay per unit of DA gas. |
| `l1.gas_limit` | `u32` | Total limit for L1 gas for the transaction. |
| `l1.teardown_gas_limit` | `u32` | Limit for L1 gas specific to the teardown phase. |
| `l1.max_fee_per_gas` | `field` | Maximum amount that the sender is willing to pay per unit of L1 gas. |
| `l2.gas_limit` | `u32` | Total limit for L2 gas for the transaction. |
| `l2.teardown_gas_limit` | `u32` | Limit for L2 gas specific to the teardown phase. |
| `l2.max_fee_per_gas` | `field` | Maximum amount that the sender is willing to pay per unit of L2 gas. |
Expand Down
6 changes: 2 additions & 4 deletions docs/docs/protocol-specs/public-vm/_nested-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ nestedExecutionEnvironment = ExecutionEnvironment {
sender: isDelegateCall ? context.sender : context.address,
address: M[addrOffset],
storageAddress: isDelegateCall ? context.storageAddress : M[addrOffset],
feePerL1Gas: context.environment.feePerL1Gas,
feePerL2Gas: context.environment.feePerL2Gas,
feePerDaGas: context.environment.feePerDaGas,
contractCallDepth: context.contractCallDepth + 1,
Expand All @@ -29,9 +28,8 @@ nestedExecutionEnvironment = ExecutionEnvironment {
}

nestedMachineState = MachineState {
l1GasLeft: context.machineState.memory[M[gasOffset]],
l2GasLeft: context.machineState.memory[M[gasOffset+1]],
daGasLeft: context.machineState.memory[M[gasOffset+2]],
l2GasLeft: context.machineState.memory[M[gasOffset]],
daGasLeft: context.machineState.memory[M[gasOffset+1]],
pc = 0,
internalCallStack = [], // initialized as empty
memory = [0, ..., 0], // all 2^32 entries are initialized to zero
Expand Down
3 changes: 0 additions & 3 deletions docs/docs/protocol-specs/public-vm/avm-circuit.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ The VM circuit's I/O (`AvmPublicInputs`) is defined below:
```
AvmSessionInputs {
// Initializes Execution Environment
feePerL1Gas: field,
feePerL2Gas: field,
feePerDaGas: field,
globals: PublicGlobalVariables,
Expand All @@ -189,12 +188,10 @@ AvmSessionInputs {
isStaticCall: boolean,
isDelegateCall: boolean,
// Initializes Machine State
l1GasLeft: field,
l2GasLeft: field,
daGasLeft: field,
}
AvmSessionResults {
l1GasLeft: field,
l2GasLeft: field,
daGasLeft: field,
reverted: boolean,
Expand Down
3 changes: 0 additions & 3 deletions docs/docs/protocol-specs/public-vm/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ A context's **execution environment** remains constant throughout a contract cal
| storageAddress | `AztecAddress` | |
| sender | `AztecAddress` | |
| portal | `EthAddress` | |
| feePerL1Gas | `field` | |
| feePerL2Gas | `field` | |
| feePerDaGas | `field` | |
| contractCallDepth | `field` | Depth of the current call (how many nested calls deep is it). |
Expand Down Expand Up @@ -74,7 +73,6 @@ INITIAL_EXECUTION_ENVIRONMENT = ExecutionEnvironment {
storageAddress: PublicCallRequest.CallContext.storageContractAddress,
sender: PublicCallRequest.CallContext.msgSender,
portal: PublicCallRequest.CallContext.portalContractAddress,
feePerL1Gas: TxRequest.feePerL1Gas,
feePerL2Gas: TxRequest.feePerL2Gas,
feePerDaGas: TxRequest.feePerDaGas,
contractCallDepth: 0,
Expand All @@ -86,7 +84,6 @@ INITIAL_EXECUTION_ENVIRONMENT = ExecutionEnvironment {
}

INITIAL_MACHINE_STATE = MachineState {
l1GasLeft: TxRequest.l1GasLimit,
l2GasLeft: TxRequest.l2GasLimit,
daGasLeft: TxRequest.daGasLimit,
pc: 0,
Expand Down
14 changes: 4 additions & 10 deletions docs/docs/protocol-specs/public-vm/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,34 @@ The `INTERNALCALL` instruction pushes `machineState.pc+1` to `machineState.inter
## Gas checks and tracking
> See ["Gas and Fees"](../gas-and-fees) for a deeper dive into Aztec's gas model and for definitions of each type of gas.

Each instruction has an associated `l1GasCost`, `l2GasCost`, and `daGasCost`. The AVM uses these values to enforce that sufficient gas is available before executing an instruction, and to deduct the cost from the context's remaining gas. The process of checking and charging gas is referred to in other sections using the following shorthand:
Each instruction has an associated `l2GasCost` and `daGasCost`. The AVM uses these values to enforce that sufficient gas is available before executing an instruction, and to deduct the cost from the context's remaining gas. The process of checking and charging gas is referred to in other sections using the following shorthand:

```jsx
chargeGas(context, l1GasCost, l2GasCost, daGasCost)
chargeGas(context, l2GasCost, daGasCost)
```

### Checking gas

Before an instruction is executed, the VM enforces that there is sufficient gas remaining via the following assertions:
```
assert machineState.l1GasLeft - instr.l1GasCost >= 0
assert machineState.l2GasLeft - instr.l2GasCost >= 0
assert machineState.daGasLeft - instr.daGasCost >= 0
```

> Many instructions (like arithmetic operations) have 0 `l1GasCost` and `daGasCost`. Instructions only incur an L1 or DA cost if they modify the [world state](./state#avm-world-state) or [accrued substate](./state#accrued-substate).
> Many instructions (like arithmetic operations) have 0 `daGasCost`. Instructions only incur a DA cost if they modify the [world state](./state#avm-world-state) or [accrued substate](./state#accrued-substate).

### Charging gas

If these assertions pass, the machine state's gas left is decreased prior to the instruction's core execution:

```
machineState.l1GasLeft -= instr.l1GasCost
machineState.l2GasLeft -= instr.l2GasCost
machineState.daGasLeft -= instr.daGasCost
```

If either of these assertions _fail_ for an instruction, this triggers an exceptional halt. The gas left is set to 0 and execution reverts.

```
machineState.l1GasLeft = 0
machineState.l2GasLeft = 0
machineState.daGasLeft = 0
```
Expand All @@ -116,7 +113,7 @@ machineState.daGasLeft = 0

An instruction's gas cost is meant to reflect the computational cost of generating a proof of its correct execution. For some instructions, this computational cost changes based on inputs. Here are some examples and important notes:

- All instructions have a base cost. [`JUMP`](./instruction-set/#isa-section-jump) is an example of an instruction with constant gas cost. Regardless of its inputs, the instruction always incurs the same `l1GasCost`, `l2GasCost`, and `daGasCost`.
- All instructions have a base cost. [`JUMP`](./instruction-set/#isa-section-jump) is an example of an instruction with constant gas cost. Regardless of its inputs, the instruction always incurs the same `l2GasCost` and `daGasCost`.
- The [`SET`](./instruction-set/#isa-section-set) instruction operates on a different sized constant (based on its `dstTag`). Therefore, this instruction's gas cost increases with the size of its input.
- In addition to the base cost, the cost of an instruction increases with the number of reads and writes to memory. This is affected by the total number of input and outputs: the gas cost for [`AND`](./instruction-set/#isa-section-and) should be greater than that of [`NOT`](./instruction-set/#isa-section-not) since it takes one more input.
- Input parameters flagged as "indirect" require an extra memory access, so these should further increase the gas cost of the instruction.
Expand All @@ -136,7 +133,6 @@ A context's execution can end with a **normal halt** or **exceptional halt**. A
A normal halt occurs when the VM encounters an explicit halting instruction ([`RETURN`](./instruction-set#isa-section-return) or [`REVERT`](./instruction-set#isa-section-revert)). Such instructions consume gas normally and optionally initialize some output data before finally halting the current context's execution.

```
machineState.l1GasLeft -= instr.l1GasCost
machineState.l2GasLeft -= instr.l2GasCost
machineState.daGasLeft -= instr.daGasCost
results.reverted = instr.opcode == REVERT
Expand All @@ -154,7 +150,6 @@ An exceptional halt is not explicitly triggered by an instruction but instead oc
When an exceptional halt occurs, the context is flagged as consuming all of its allocated gas and is marked as `reverted` with _no output data_, and then execution within the current context ends.

```
machineState.l1GasLeft = 0
machineState.l2GasLeft = 0
machineState.daGasLeft = 0
results.reverted = true
Expand All @@ -165,7 +160,6 @@ The AVM's exceptional halting conditions area listed below:

1. **Insufficient gas**
```
assert machineState.l1GasLeft - instr.l1GasCost >= 0
assert machineState.l2GasLeft - instr.l2GasCost >= 0
assert machineState.daGasLeft - instr.l2GasCost >= 0
```
Expand Down
Loading
Loading