Skip to content

Commit 2153bd7

Browse files
authored
Merge pull request #1048 from ethereumjs/eip2718-eip2930
Implement EIP2718 and EIP2930
2 parents 93c1110 + 9c6f2f6 commit 2153bd7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2049
-494
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "ethereum-tests"]
22
path = packages/ethereum-tests
3-
url = https://github.com/ethereum/tests.git
3+
url = https://github.com/qbzzt/tests.git
44
branch = develop

packages/block/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
(modification: no type change headlines) and this project adheres to
77
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
88

9+
## UNRELEASED
10+
11+
- Integration of [EIP2718](https://eips.ethereum.org/EIPS/eip-2718) (Typed Transactions) and [EIP2930](https://eips.ethereum.org/EIPS/eip-2930) (Access List Transaction), PR [#1048](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1048). It is now possible to create blocks with access list transactions.
12+
913
## 3.1.0 - 2021-02-22
1014

1115
### Clique/PoA Support

packages/block/src/block.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { BaseTrie as Trie } from 'merkle-patricia-tree'
44
import { BN, rlp, keccak256, KECCAK256_RLP } from 'ethereumjs-util'
55
import Common from '@ethereumjs/common'
6-
import { Transaction, TxOptions } from '@ethereumjs/tx'
6+
import { TransactionFactory, Transaction, TxOptions } from '@ethereumjs/tx'
77
import { BlockHeader } from './header'
88
import { BlockData, BlockOptions, JsonBlock, BlockBuffer, Blockchain } from './types'
99

@@ -31,7 +31,7 @@ export class Block {
3131
// parse transactions
3232
const transactions = []
3333
for (const txData of txsData || []) {
34-
const tx = Transaction.fromTxData(txData, {
34+
const tx = TransactionFactory.fromTxData(txData, {
3535
...opts,
3636
// Use header common in case of hardforkByBlockNumber being activated
3737
common: header._common,
@@ -91,7 +91,7 @@ export class Block {
9191
const transactions = []
9292
for (const txData of txsData || []) {
9393
transactions.push(
94-
Transaction.fromValuesArray(txData, {
94+
TransactionFactory.fromBlockBodyData(txData, {
9595
...opts,
9696
// Use header common in case of hardforkByBlockNumber being activated
9797
common: header._common,
@@ -154,7 +154,7 @@ export class Block {
154154
raw(): BlockBuffer {
155155
return [
156156
this.header.raw(),
157-
this.transactions.map((tx) => tx.raw()),
157+
this.transactions.map((tx) => <Buffer[]>tx.raw()),
158158
this.uncleHeaders.map((uh) => uh.raw()),
159159
]
160160
}
@@ -223,7 +223,7 @@ export class Block {
223223
const errors: string[] = []
224224

225225
this.transactions.forEach(function (tx, i) {
226-
const errs = tx.validate(true)
226+
const errs = <string[]>tx.validate(true)
227227
if (errs.length > 0) {
228228
errors.push(`errors at tx ${i}: ${errs.join(', ')}`)
229229
}

packages/block/src/from-rpc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Transaction, TxData } from '@ethereumjs/tx'
1+
import { TransactionFactory, Transaction, TxData } from '@ethereumjs/tx'
22
import { toBuffer, setLengthLeft } from 'ethereumjs-util'
33
import { Block, BlockOptions } from './index'
44

@@ -37,7 +37,7 @@ export default function blockFromRpc(blockParams: any, uncles: any[] = [], optio
3737
const opts = { common: header._common }
3838
for (const _txParams of blockParams.transactions) {
3939
const txParams = normalizeTxParams(_txParams)
40-
const tx = Transaction.fromTxData(txParams as TxData, opts)
40+
const tx = TransactionFactory.fromTxData(txParams as TxData, opts)
4141
transactions.push(tx)
4242
}
4343
}

packages/common/src/eips/2718.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "EIP-2718",
3+
"comment": "Typed Transaction Envelope",
4+
"url": "https://eips.ethereum.org/EIPS/eip-2718",
5+
"status": "Draft",
6+
"minimumHardfork": "chainstart",
7+
"gasConfig": {},
8+
"gasPrices": {},
9+
"vm": {},
10+
"pow": {}
11+
}
12+

packages/common/src/eips/2930.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "EIP-2929",
3+
"comment": "Optional access lists",
4+
"url": "https://eips.ethereum.org/EIPS/eip-2930",
5+
"status": "Draft",
6+
"minimumHardfork": "istanbul",
7+
"requiredEIPs": [2718, 2929],
8+
"gasConfig": {},
9+
"gasPrices": {
10+
"accessListStorageKeyCost": {
11+
"v": 1900,
12+
"d": "Gas cost per storage key in an Access List transaction"
13+
},
14+
"accessListAddressCost": {
15+
"v": 2400,
16+
"d": "Gas cost per storage key in an Access List transaction"
17+
}
18+
},
19+
"vm": {},
20+
"pow": {}
21+
}
22+

packages/common/src/eips/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ export const EIPs: eipsType = {
44
2315: require('./2315.json'),
55
2537: require('./2537.json'),
66
2565: require('./2565.json'),
7+
2718: require('./2718.json'),
78
2929: require('./2929.json'),
9+
2930: require('./2930.json'),
810
}

packages/common/src/hardforks/berlin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"comment": "HF targeted for July 2020 following the Muir Glacier HF",
44
"url": "https://eips.ethereum.org/EIPS/eip-2070",
55
"status": "Draft",
6-
"eips": [ 2315, 2565, 2929 ]
6+
"eips": [ 2315, 2565, 2929, 2718, 2930 ]
77
}

packages/common/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ export default class Common extends EventEmitter {
274274
`${eip} cannot be activated on hardfork ${this.hardfork()}, minimumHardfork: ${minHF}`
275275
)
276276
}
277+
if (EIPs[eip].requiredEIPs) {
278+
// eslint-disable-next-line prettier/prettier
279+
(<number[]>EIPs[eip].requiredEIPs).forEach((elem: number) => {
280+
if (!(eips.includes(elem) || this.isActivatedEIP(elem))) {
281+
throw new Error(`${eip} requires EIP ${elem}, but is not included in the EIP list`)
282+
}
283+
})
284+
}
277285
}
278286
this._eips = eips
279287
}

packages/common/tests/eips.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ import Common from '../src/'
33

44
tape('[Common]: Initialization / Chain params', function (t: tape.Test) {
55
t.test('Correct initialization', function (st: tape.Test) {
6-
const eips = [2537, 2929]
6+
let eips = [2537, 2929]
77
const c = new Common({ chain: 'mainnet', eips })
88
st.equal(c.eips(), eips, 'should initialize with supported EIP')
9+
10+
eips = [2718, 2929, 2930]
11+
new Common({ chain: 'mainnet', eips, hardfork: 'istanbul' })
12+
st.pass('Should not throw when initializing with a consistent EIP list')
13+
14+
eips = [2930]
15+
const msg =
16+
'should throw when initializing with an EIP with required EIPs not being activated along'
17+
const f = () => {
18+
new Common({ chain: 'mainnet', eips, hardfork: 'istanbul' })
19+
}
20+
st.throws(f, msg)
21+
922
st.end()
1023
})
1124

0 commit comments

Comments
 (0)