Skip to content

Commit

Permalink
doc for eip EIP2930&1559 (scroll-tech#1115)
Browse files Browse the repository at this point in the history
* doc for eip EIP2930_1559

* add 1559 gadget

* modify md format
  • Loading branch information
DreamWuGit authored Feb 22, 2024
1 parent 7d41598 commit 44fd11f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
54 changes: 54 additions & 0 deletions docs/EIP2930_1559.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
tags: scroll documentation
---

# EIP 2930 & 1559
this doc describles how to support EIP2930 & 1559 in copy circuit and evm circuit.
## links
- EIP2930 https://eips.ethereum.org/EIPS/eip-2930
- EIP1559 https://eips.ethereum.org/EIPS/eip-1559

## copy circuit
- EIP2030 generates copy event for variable length of access list items (two types: address, storage key), it is done by evm bussmaping side. so copy circuit need to handle such situation.
- added two additinonal `CopyDataType`:
- CopyDataType::AccessListAddresses: When copy event is access-list addresses (EIP-2930), source is tx-table and destination is rw-table.
- CopyDataType::AccessListStorageKeys: When copy event is access-list storage keys (EIP-2930), source is tx-table and destination is rw-table.
- constraints:
- `constrain_tag` method include new `is_access_list_address`, `is_access_list_storage_key` constraint.
- Tx access list address lookup(tx table with `TxContextFieldTag::AccessListAddress`)
- Rw access list address lookup(rw table with `RwTableTag::TxAccessListAccount`)
- Tx access list storage key lookup (tx table with `TxContextFieldTag::AccessListStorageKey`)
- Rw access list storage key lookup (rw table with `RwTableTag::TxAccessListAccountStorage`)

### EVM Circuit

- **Bus Mapping**
- New methods in `bus-mapping/src/evm/opcodes/begin_end_tx.rs` of `add_access_list_address_copy_event` and `add_access_list_storage_key_copy_event` to generate copy events which copy circuit handles.

- **Circuit Gadgets**
- **TxAccessListGadget**: Handles access-list for EIP-1559 and EIP-2930
- Fields:
- `is_eip1559_tx`: Checks if it's a 1559 transaction type.
- `is_eip2930_tx`: Checks if it's a 2930 transaction type.
- `is_address_len_zero`: Checks if there are no access list addresses (AccessListAddressesLen == 0).
- `address_len`: Length of access list addresses.
- `storage_key_len`: Length of storage keys under one access list address item.
- Constraints:
- tx table lookups for [AccessListAddressesLen, AccessListStorageKeysLen]
- Copy table lookups for tx-table's access list addresses (CopyDataType::AccessListAddresses) when `is_address_len_zero` is not true.
- Copy table lookups for tx-table's access list storage keys (CopyDataType::AccessListStorageKeys) when `is_storage_key_len_zero` is not true.

- **TxEip1559Gadget**: Gadget to check sender balance before transfer
- Fields:
- `is_eip1559_tx`: Checks if it's a 1559 transaction type.
- `gas_fee_cap`: MaxFeePerGas in 1559.
- `gas_tip_cap`: MaxPriorityFeePerGas in 1559.
- `mul_gas_fee_cap_by_gas`: Calculates total gas amount.
- `balance_check`: Calculates minimal caller's balance required = `mul_gas_fee_cap_by_gas` + `tx.value` + `tx_l1_fee`.
- is_insufficient_balance: check balance is sufficient compared to
minimal balance required.
- gas_fee_cap_lt_gas_tip_cap: make sure gas_fee_cap not less than gas_tip_gap.
- constraints:
- tx table lookups for [MaxFeePerGas, MaxPriorityFeePerGas]
- sender balance must be sufficient, means gas_fee_cap >= gas_tip_cap
- `begin_tx` : take use of `TxAccessListGadget` and `TxEip1559Gadget` to implement corresponding constraints.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(crate) struct TxEip1559Gadget<F> {
// <https://github.com/ethereum/go-ethereum/blob/master/core/state_transition.go#L255>
is_insufficient_balance: LtWordGadget<F>,
// Error condition
// <https://github.com/ethereum/go-ethereum/blob/master/core/state_transition.go#L304>
// <https://github.com/ethereum/go-ethereum/blob/master/core/state_transition.go#L310>
gas_fee_cap_lt_gas_tip_cap: LtWordGadget<F>,
}

Expand Down

0 comments on commit 44fd11f

Please sign in to comment.