Skip to content

Commit

Permalink
Merge branch 'statemanager/capabilities-refactor' of https://github.c…
Browse files Browse the repository at this point in the history
…om/ethereumjs/ethereumjs-monorepo into statemanager/capabilities-refactor
  • Loading branch information
gabrocheleau committed Aug 12, 2024
2 parents 4864383 + f0b66bf commit b6ee97b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 215 deletions.
40 changes: 0 additions & 40 deletions packages/common/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,46 +49,6 @@ export type Proof = {
storageProof: StorageProof[]
}

/*
* Access List types
*/

export type AccessListItem = {
address: PrefixedHexString
storageKeys: PrefixedHexString[]
}

/*
* An Access List as a tuple of [address: Uint8Array, storageKeys: Uint8Array[]]
*/
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[]

/**
* Verkle related
*
Expand Down
61 changes: 41 additions & 20 deletions packages/tx/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,14 @@ import type { AccessListEIP2930Transaction } from './2930/tx.js'
import type { BlobEIP4844Transaction } from './4844/tx.js'
import type { EOACodeEIP7702Transaction } from './7702/tx.js'
import type { LegacyTransaction } from './legacy/tx.js'
import type {
AccessList,
AccessListBytes,
AuthorizationList,
AuthorizationListBytes,
Common,
Hardfork,
ParamsDict,
} from '@ethereumjs/common'
import type { Common, Hardfork, ParamsDict } from '@ethereumjs/common'
import type {
Address,
AddressLike,
BigIntLike,
BytesLike,
PrefixedHexString,
} from '@ethereumjs/util'
export type {
AccessList,
AccessListBytes,
AccessListBytesItem,
AccessListItem,
AuthorizationList,
AuthorizationListBytes,
AuthorizationListBytesItem,
AuthorizationListItem,
} from '@ethereumjs/common'

/**
* Can be used in conjunction with {@link Transaction[TransactionType].supports}
* to query on tx capabilities
Expand Down Expand Up @@ -596,3 +577,43 @@ export interface JsonRpcTx {
blobVersionedHashes?: string[] // DATA - array of 32 byte versioned hashes for blob transactions
yParity?: string // DATA - parity of the y-coordinate of the public key
}

/*
* Access List types
*/

export type AccessListItem = {
address: PrefixedHexString
storageKeys: PrefixedHexString[]
}

/*
* An Access List as a tuple of [address: Uint8Array, storageKeys: Uint8Array[]]
*/
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[]
3 changes: 2 additions & 1 deletion packages/tx/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import type {
AccessListItem,
AuthorizationList,
AuthorizationListBytes,
AuthorizationListItem,
TransactionType,
} from './types.js'
import type { AuthorizationListItem, Common } from '@ethereumjs/common'
import type { Common } from '@ethereumjs/common'

export function checkMaxInitCodeSize(common: Common, length: number) {
const maxInitCodeSize = common.param('maxInitCodeSize')
Expand Down
199 changes: 46 additions & 153 deletions packages/tx/test/eip7702.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { assert, describe, it } from 'vitest'

import { create7702EOACodeTx } from '../src/index.js'

import type { TxData } from '../src/7702/tx.js'
import type { AuthorizationListItem } from '../src/index.js'
import type { PrefixedHexString } from '@ethereumjs/util'

const common = new Common({ chain: Mainnet, hardfork: Hardfork.Cancun, eips: [7702] })
Expand All @@ -13,6 +15,26 @@ const addr = createAddressFromPrivateKey(pkey)

const ones32 = `0x${'01'.repeat(32)}` as PrefixedHexString

function getTxData(override: Partial<AuthorizationListItem> = {}): TxData {
const validAuthorizationList: AuthorizationListItem = {
chainId: '0x',
address: `0x${'20'.repeat(20)}`,
nonce: ['0x1'],
yParity: '0x1',
r: ones32,
s: ones32,
}

return {
authorizationList: [
{
...validAuthorizationList,
...override,
},
],
}
}

describe('[EOACodeEIP7702Transaction]', () => {
it('sign()', () => {
const txn = create7702EOACodeTx(
Expand All @@ -36,166 +58,37 @@ describe('[EOACodeEIP7702Transaction]', () => {
})

it('valid and invalid authorizationList values', () => {
assert.throws(() => {
create7702EOACodeTx(
{
authorizationList: [
{
chainId: '0x',
address: `0x${'20'.repeat(21)}`,
nonce: [],
yParity: '0x1',
r: ones32,
s: ones32,
},
],
},
{ common },
)
}, 'address length should be 20 bytes')

assert.throws(() => {
create7702EOACodeTx(
{
authorizationList: [
{
chainId: '0x',
address: `0x${'20'.repeat(20)}`,
nonce: ['0x1', '0x2'],
yParity: '0x1',
r: ones32,
s: ones32,
},
],
},
{ common },
)
}, 'nonce list should consist of at most 1 item')

assert.throws(() => {
create7702EOACodeTx(
{
authorizationList: [
{
chainId: '0x',
address: `0x${'20'.repeat(20)}`,
nonce: ['0x1'],
yParity: '0x1',
r: ones32,
s: undefined as never,
},
],
},
{ common },
)
}, 's is not defined')

assert.throws(() => {
create7702EOACodeTx(
{
authorizationList: [
{
chainId: '0x',
address: `0x${'20'.repeat(20)}`,
nonce: ['0x1'],
yParity: '0x1',
r: undefined as never,
s: ones32,
},
],
},
{ common },
)
}, 'r is not defined')

assert.throws(() => {
create7702EOACodeTx(
{
authorizationList: [
{
chainId: '0x',
address: `0x${'20'.repeat(20)}`,
nonce: ['0x1'],
yParity: undefined as never,
r: ones32,
s: ones32,
},
],
},
{ common },
)
}, 'yParity is not defined')

assert.throws(() => {
create7702EOACodeTx(
const tests: [Partial<AuthorizationListItem>, string][] = [
[
{
authorizationList: [
{
chainId: '0x',
address: `0x${'20'.repeat(20)}`,
nonce: undefined as never,
yParity: '0x1',
r: ones32,
s: ones32,
},
],
address: `0x${'20'.repeat(21)}`,
},
{ common },
)
}, 'nonce is not defined')

assert.throws(() => {
create7702EOACodeTx(
'address length should be 20 bytes',
],
[
{
authorizationList: [
{
chainId: '0x',
address: undefined as never,
nonce: ['0x1'],
yParity: '0x1',
r: ones32,
s: ones32,
},
],
nonce: ['0x1', '0x2'],
},
{ common },
)
}, 'address is not defined')
'nonce list should consist of at most 1 item',
],
[{ s: undefined as never }, 's is not defined'],
[{ r: undefined as never }, 'r is not defined'],
[{ yParity: undefined as never }, 'yParity is not defined'],
[{ nonce: undefined as never }, 'nonce is not defined'],
[{ address: undefined as never }, 'address is not defined'],
[{ chainId: undefined as never }, 'chainId is not defined'],
]

assert.throws(() => {
create7702EOACodeTx(
{
authorizationList: [
{
chainId: undefined as never,
address: `0x${'20'.repeat(20)}`,
nonce: ['0x1'],
yParity: '0x1',
r: ones32,
s: ones32,
},
],
},
{ common },
)
}, 'chainId is not defined')
for (const test of tests) {
const txData = getTxData(test[0])
const testName = test[1]
assert.throws(() => {
create7702EOACodeTx(txData, { common }), testName
})
}

assert.doesNotThrow(() => {
create7702EOACodeTx(
{
authorizationList: [
{
chainId: '0x',
address: `0x${'20'.repeat(20)}`,
nonce: ['0x1'],
yParity: '0x1',
r: ones32,
s: ones32,
},
],
},
{ common },
)
create7702EOACodeTx(getTxData(), { common })
})
})
})
4 changes: 3 additions & 1 deletion packages/vm/src/runTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ import type {
} from './types.js'
import type { VM } from './vm.js'
import type { Block } from '@ethereumjs/block'
import type { AccessList, AccessListItem, Common } from '@ethereumjs/common'
import type { Common } from '@ethereumjs/common'
import type { EVM } from '@ethereumjs/evm'
import type {
AccessList,
AccessListEIP2930Transaction,
AccessListItem,
EIP7702CompatibleTx,
FeeMarketEIP1559Transaction,
LegacyTransaction,
Expand Down

0 comments on commit b6ee97b

Please sign in to comment.