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

Implement EIP 7702 #3470

Merged
merged 26 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5bf8c17
common/tx: implement EIP7702
jochem-brouwer Jun 23, 2024
4079bb5
tx: add 7702 cap and update authority checks
jochem-brouwer Jun 23, 2024
2632f4c
vm: add 7702 support
jochem-brouwer Jun 23, 2024
6dd25ae
tx: add 7702 tests
jochem-brouwer Jun 24, 2024
0a8b27a
client: fix build
jochem-brouwer Jun 24, 2024
0ae6f00
evm: support 7702
jochem-brouwer Jun 24, 2024
09108c5
vm: add basic 7702 test and fix decoding auth list
jochem-brouwer Jun 24, 2024
13ec300
vm: add specific eip-161 test
jochem-brouwer Jun 24, 2024
aeccb99
Merge branch 'master' into eip7702
jochem-brouwer Jul 1, 2024
f079602
vm: bump 7702 test coverage with one passing test
jochem-brouwer Jul 1, 2024
9dbb55c
vm: add more 7702 tests
jochem-brouwer Jul 1, 2024
a764192
vm: add extra 7702 tests
jochem-brouwer Jul 1, 2024
74446c1
tx: address feedback
jochem-brouwer Jul 1, 2024
6502801
vm: address review
jochem-brouwer Jul 1, 2024
4d59281
vm: add 7702 test to check for empty code (fails)
jochem-brouwer Jul 1, 2024
69e7268
vm: fix 7702 empty code clearing
jochem-brouwer Jul 2, 2024
d54ff6b
Merge branch 'master' into eip7702
jochem-brouwer Jul 2, 2024
3cebd3c
Merge remote-tracking branch 'origin/master' into eip7702
acolytec3 Jul 2, 2024
bc178f7
Merge branch 'master' into eip7702
ScottyPoi Jul 3, 2024
149c061
add 7702 type to tx factory constructors
acolytec3 Jul 4, 2024
8583642
add 7702 test to runBlock test
acolytec3 Jul 4, 2024
6e31e14
vm: comment 7702 test
jochem-brouwer Jul 4, 2024
c520da4
vm: remove runBlock .only
jochem-brouwer Jul 4, 2024
5a91eef
tx: address reviews
jochem-brouwer Jul 4, 2024
be8e3ac
tx: 7702 do not unpad address in authority list
jochem-brouwer Jul 4, 2024
de44658
vm: update eip7702 test
jochem-brouwer Jul 4, 2024
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
7 changes: 6 additions & 1 deletion packages/client/src/net/protocol/ethprotocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
TransactionFactory,
isAccessListEIP2930Tx,
isBlobEIP4844Tx,
isEOACodeEIP7702Tx,
isFeeMarketEIP1559Tx,
isLegacyTx,
} from '@ethereumjs/tx'
Expand Down Expand Up @@ -255,7 +256,11 @@
// serialize txs as per type
if (isBlobEIP4844Tx(tx)) {
serializedTxs.push(tx.serializeNetworkWrapper())
} else if (isFeeMarketEIP1559Tx(tx) || isAccessListEIP2930Tx(tx)) {
} else if (
isFeeMarketEIP1559Tx(tx) ||
isAccessListEIP2930Tx(tx) ||
isEOACodeEIP7702Tx(tx)
) {

Check warning on line 263 in packages/client/src/net/protocol/ethprotocol.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/src/net/protocol/ethprotocol.ts#L259-L263

Added lines #L259 - L263 were not covered by tests
serializedTxs.push(tx.serialize())
} else if (isLegacyTx(tx)) {
serializedTxs.push(tx.raw())
Expand Down
14 changes: 14 additions & 0 deletions packages/common/src/eips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,20 @@ export const EIPs: EIPsDict = {
requiredEIPs: [3675],
gasPrices: {},
},
7702: {
comment: 'Set EOA account code for one transaction',
url: 'https://github.com/ethereum/EIPs/blob/62419ca3f45375db00b04a368ea37c0bfb05386a/EIPS/eip-7702.md',
status: Status.Review,
// TODO: Set correct minimum hardfork
minimumHardfork: Hardfork.Cancun,
requiredEIPs: [2718, 2929, 2930],
gasPrices: {
perAuthBaseCost: {
v: 2500,
d: 'Gas cost of each authority item',
},
},
},
7709: {
comment: 'Use historical block hashes saved in state for BLOCKHASH',
url: 'https://eips.ethereum.org/EIPS/eip-7709',
Expand Down
24 changes: 24 additions & 0 deletions packages/common/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ export type AccessListBytesItem = [Uint8Array, Uint8Array[]]
export type AccessListBytes = AccessListBytesItem[]
export type AccessList = AccessListItem[]

/**
* Authorization list types
*/
export type AuthorizationListItem = {
chainId: PrefixedHexString
address: PrefixedHexString
nonce: PrefixedHexString[]
yParity: PrefixedHexString
r: PrefixedHexString
s: PrefixedHexString
}

// Tuple of [chain_id, address, [nonce], y_parity, r, s]
export type AuthorizationListBytesItem = [
Uint8Array,
Uint8Array,
Uint8Array[],
Uint8Array,
Uint8Array,
Uint8Array
]
export type AuthorizationListBytes = AuthorizationListBytesItem[]
export type AuthorizationList = AuthorizationListItem[]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not a good reason that we have these AuthorizationList types in the Common interface file (these should really be reserved for the VIIs, to the "Very Important Interfaces" 😂 used to type on other libraries.

Same goes I guess for the access list interfaces (for both: unless I am unaware of some below-tx-library usages).

We should move them over to tx in a small clean-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked, for both (so also AccessList) the only packages which import those are tx and vm, and since vm has a tx dependency we can indeed move these into common.

I don't recall why we put AccessList in common (but to be consistent I also put AuthorizationList in here). I do slightly recall we maybe did this for package consumers to import these types (?) but then they would only need the common package and not import tx? However this does not sound like a very good reason for me, I don't know if there is any use case for those types which would not depend or use tx.

We should indeed clean-up and remove both AuthorizationList and AccessList from common (in same PR)

/**
* Verkle related
*
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/src/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class EVM implements EVMInterface {
const supportedEIPs = [
1153, 1559, 2537, 2565, 2718, 2929, 2930, 2935, 3074, 3198, 3529, 3540, 3541, 3607, 3651,
3670, 3855, 3860, 4399, 4895, 4788, 4844, 5133, 5656, 6110, 6780, 6800, 7002, 7251, 7516,
7685, 7709,
7685, 7702, 7709,
]

for (const eip of this.common.eips()) {
Expand Down
16 changes: 16 additions & 0 deletions packages/tx/src/capabilities/eip7702.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { AccessLists } from '../util.js'

import * as Legacy from './legacy.js'

import type { EIP7702CompatibleTx } from '../types.js'

/**
* The amount of gas paid for the data in this tx
*/
export function getDataFee(tx: EIP7702CompatibleTx): bigint {
const eip2930Cost = BigInt(AccessLists.getDataFeeEIP2930(tx.accessList, tx.common))
const eip7702Cost = BigInt(
tx.authorizationList.length * Number(tx.common.param('gasPrices', 'perAuthBaseCost'))
)
return Legacy.getDataFee(tx, eip2930Cost + eip7702Cost)
}
Loading
Loading