Skip to content

Commit 94451c2

Browse files
holimanMariusVanDerWijdenlightclientfjl
authored
all: implement EIP-1559 (#22837)
This is the initial implementation of EIP-1559 in packages core/types and core. Mining, RPC, etc. will be added in subsequent commits. Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de> Co-authored-by: lightclient@protonmail.com <lightclient@protonmail.com> Co-authored-by: Felix Lange <fjl@twurst.com>
1 parent 14bc6e5 commit 94451c2

Some content is hidden

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

59 files changed

+1522
-173
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,8 @@ func (m callMsg) Nonce() uint64 { return 0 }
716716
func (m callMsg) CheckNonce() bool { return false }
717717
func (m callMsg) To() *common.Address { return m.CallMsg.To }
718718
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
719+
func (m callMsg) FeeCap() *big.Int { return m.CallMsg.FeeCap }
720+
func (m callMsg) Tip() *big.Int { return m.CallMsg.Tip }
719721
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
720722
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
721723
func (m callMsg) Data() []byte { return m.CallMsg.Data }

accounts/external/backend.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
217217
if chainID != nil {
218218
args.ChainID = (*hexutil.Big)(chainID)
219219
}
220-
// However, if the user asked for a particular chain id, then we should
221-
// use that instead.
222-
if tx.Type() != types.LegacyTxType && tx.ChainId() != nil {
223-
args.ChainID = (*hexutil.Big)(tx.ChainId())
224-
}
225-
if tx.Type() == types.AccessListTxType {
220+
if tx.Type() != types.LegacyTxType {
221+
// However, if the user asked for a particular chain id, then we should
222+
// use that instead.
223+
if tx.ChainId() != nil {
224+
args.ChainID = (*hexutil.Big)(tx.ChainId())
225+
}
226226
accessList := tx.AccessList()
227227
args.AccessList = &accessList
228228
}

cmd/evm/internal/t8ntool/execution.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type stEnv struct {
6969
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
7070
BlockHashes map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"`
7171
Ommers []ommer `json:"ommers,omitempty"`
72+
BaseFee *big.Int `json:"currentBaseFee,omitempty"`
7273
}
7374

7475
type stEnvMarshaling struct {
@@ -77,6 +78,7 @@ type stEnvMarshaling struct {
7778
GasLimit math.HexOrDecimal64
7879
Number math.HexOrDecimal64
7980
Timestamp math.HexOrDecimal64
81+
BaseFee *math.HexOrDecimal256
8082
}
8183

8284
// Apply applies a set of transactions to a pre-state
@@ -120,6 +122,10 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
120122
GasLimit: pre.Env.GasLimit,
121123
GetHash: getHash,
122124
}
125+
// If currentBaseFee is defined, add it to the vmContext.
126+
if pre.Env.BaseFee != nil {
127+
vmContext.BaseFee = new(big.Int).Set(pre.Env.BaseFee)
128+
}
123129
// If DAO is supported/enabled, we need to handle it here. In geth 'proper', it's
124130
// done in StateProcessor.Process(block, ...), right before transactions are applied.
125131
if chainConfig.DAOForkSupport &&
@@ -129,7 +135,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
129135
}
130136

131137
for i, tx := range txs {
132-
msg, err := tx.AsMessage(signer)
138+
msg, err := tx.AsMessage(signer, pre.Env.BaseFee)
133139
if err != nil {
134140
log.Info("rejected tx", "index", i, "hash", tx.Hash(), "error", err)
135141
rejectedTxs = append(rejectedTxs, i)

cmd/evm/internal/t8ntool/gen_stenv.go

Lines changed: 14 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/evm/internal/t8ntool/transition.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package t8ntool
1919
import (
2020
"crypto/ecdsa"
2121
"encoding/json"
22+
"errors"
2223
"fmt"
2324
"io/ioutil"
2425
"math/big"
@@ -210,9 +211,12 @@ func Main(ctx *cli.Context) error {
210211
if txs, err = signUnsignedTransactions(txsWithKeys, signer); err != nil {
211212
return NewError(ErrorJson, fmt.Errorf("failed signing transactions: %v", err))
212213
}
213-
214-
// Iterate over all the tests, run them and aggregate the results
215-
214+
// Sanity check, to not `panic` in state_transition
215+
if chainConfig.IsLondon(big.NewInt(int64(prestate.Env.Number))) {
216+
if prestate.Env.BaseFee == nil {
217+
return NewError(ErrorVMConfig, errors.New("EIP-1559 config but missing 'currentBaseFee' in env section"))
218+
}
219+
}
216220
// Run the test and aggregate the result
217221
s, result, err := prestate.Apply(vmConfig, chainConfig, txs, ctx.Int64(RewardFlag.Name), getTracer)
218222
if err != nil {

cmd/evm/poststate.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

cmd/evm/testdata/10/alloc.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"0x1111111111111111111111111111111111111111" : {
3+
"balance" : "0x010000000000",
4+
"code" : "0xfe",
5+
"nonce" : "0x01",
6+
"storage" : {
7+
}
8+
},
9+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
10+
"balance" : "0x010000000000",
11+
"code" : "0x",
12+
"nonce" : "0x01",
13+
"storage" : {
14+
}
15+
},
16+
"0xd02d72e067e77158444ef2020ff2d325f929b363" : {
17+
"balance" : "0x01000000000000",
18+
"code" : "0x",
19+
"nonce" : "0x01",
20+
"storage" : {
21+
}
22+
}
23+
}

cmd/evm/testdata/10/env.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
3+
"currentDifficulty" : "0x020000",
4+
"currentNumber" : "0x01",
5+
"currentTimestamp" : "0x079e",
6+
"previousHash" : "0xcb23ee65a163121f640673b41788ee94633941405f95009999b502eedfbbfd4f",
7+
"currentGasLimit" : "0x40000000",
8+
"currentBaseFee" : "0x036b",
9+
"blockHashes" : {
10+
"0" : "0xcb23ee65a163121f640673b41788ee94633941405f95009999b502eedfbbfd4f"
11+
}
12+
}

cmd/evm/testdata/10/readme.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
## EIP-1559 testing
2+
3+
This test contains testcases for EIP-1559, which were reported by Ori as misbehaving.
4+
5+
```
6+
[user@work evm]$ dir=./testdata/10 && ./evm t8n --state.fork=London --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json --output.alloc=stdout --output.result=stdout 2>&1
7+
INFO [05-09|22:11:59.436] rejected tx index=3 hash=db07bf..ede1e8 from=0xd02d72E067e77158444ef2020Ff2d325f929B363 error="gas limit reached"
8+
```
9+
Output:
10+
```json
11+
{
12+
"alloc": {
13+
"0x1111111111111111111111111111111111111111": {
14+
"code": "0xfe",
15+
"balance": "0x10000000000",
16+
"nonce": "0x1"
17+
},
18+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
19+
"balance": "0x10000000000",
20+
"nonce": "0x1"
21+
},
22+
"0xd02d72e067e77158444ef2020ff2d325f929b363": {
23+
"balance": "0xff5beffffc95",
24+
"nonce": "0x4"
25+
}
26+
},
27+
"result": {
28+
"stateRoot": "0xf91a7ec08e4bfea88719aab34deabb000c86902360532b52afa9599d41f2bb8b",
29+
"txRoot": "0xda925f2306a52fa24c15d5cd212d736ee016415fd8dd0c45fd368de7917d64bb",
30+
"receiptRoot": "0x439a25f7fc424c10fb1f89800e4aa1df74156b137239d9ac3eaa7c911c353cd5",
31+
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
32+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
33+
"receipts": [
34+
{
35+
"type": "0x2",
36+
"root": "0x",
37+
"status": "0x0",
38+
"cumulativeGasUsed": "0x10000001",
39+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
40+
"logs": null,
41+
"transactionHash": "0x88980f6efcc5358d9c359663e7b9414722d430497637340ea056b076bc206701",
42+
"contractAddress": "0x0000000000000000000000000000000000000000",
43+
"gasUsed": "0x10000001",
44+
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
45+
"transactionIndex": "0x0"
46+
},
47+
{
48+
"type": "0x2",
49+
"root": "0x",
50+
"status": "0x0",
51+
"cumulativeGasUsed": "0x20000001",
52+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
53+
"logs": null,
54+
"transactionHash": "0xd7bf3886f4e2aef74d525ae072c680f3846f550254401b67cbfda4a233757582",
55+
"contractAddress": "0x0000000000000000000000000000000000000000",
56+
"gasUsed": "0x10000000",
57+
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
58+
"transactionIndex": "0x1"
59+
},
60+
{
61+
"type": "0x2",
62+
"root": "0x",
63+
"status": "0x0",
64+
"cumulativeGasUsed": "0x30000001",
65+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
66+
"logs": null,
67+
"transactionHash": "0x50308296760f01f1eeec7500e9e73cad67469249b1f59e9a9f55e6625a4923db",
68+
"contractAddress": "0x0000000000000000000000000000000000000000",
69+
"gasUsed": "0x10000000",
70+
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
71+
"transactionIndex": "0x2"
72+
}
73+
],
74+
"rejected": [
75+
3
76+
]
77+
}
78+
}
79+
```

cmd/evm/testdata/10/txs.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[
2+
{
3+
"input" : "0x",
4+
"gas" : "0x10000001",
5+
"nonce" : "0x1",
6+
"to" : "0x1111111111111111111111111111111111111111",
7+
"value" : "0x0",
8+
"v" : "0x0",
9+
"r" : "0x7a45f00bcde9036b026cdf1628b023cd8a31a95c62b5e4dbbee2fa7debe668fb",
10+
"s" : "0x3cc9d6f2cd00a045b0263f2d6dad7d60938d5d13d061af4969f95928aa934d4a",
11+
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
12+
"chainId" : "0x1",
13+
"type" : "0x2",
14+
"feeCap" : "0xfa0",
15+
"tip" : "0x0",
16+
"accessList" : [
17+
]
18+
},
19+
{
20+
"input" : "0x",
21+
"gas" : "0x10000000",
22+
"nonce" : "0x2",
23+
"to" : "0x1111111111111111111111111111111111111111",
24+
"value" : "0x0",
25+
"v" : "0x0",
26+
"r" : "0x4c564b94b0281a8210eeec2dd1fe2e16ff1c1903a8c3a1078d735d7f8208b2af",
27+
"s" : "0x56432b2593e6de95db1cb997b7385217aca03f1615327e231734446b39f266d",
28+
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
29+
"chainId" : "0x1",
30+
"type" : "0x2",
31+
"feeCap" : "0xfa0",
32+
"tip" : "0x0",
33+
"accessList" : [
34+
]
35+
},
36+
{
37+
"input" : "0x",
38+
"gas" : "0x10000000",
39+
"nonce" : "0x3",
40+
"to" : "0x1111111111111111111111111111111111111111",
41+
"value" : "0x0",
42+
"v" : "0x0",
43+
"r" : "0x2ed2ef52f924f59d4a21e1f2a50d3b1109303ce5e32334a7ece9b46f4fbc2a57",
44+
"s" : "0x2980257129cbd3da987226f323d50ba3975a834d165e0681f991b75615605c44",
45+
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
46+
"chainId" : "0x1",
47+
"type" : "0x2",
48+
"feeCap" : "0xfa0",
49+
"tip" : "0x0",
50+
"accessList" : [
51+
]
52+
},
53+
{
54+
"input" : "0x",
55+
"gas" : "0x10000000",
56+
"nonce" : "0x4",
57+
"to" : "0x1111111111111111111111111111111111111111",
58+
"value" : "0x0",
59+
"v" : "0x0",
60+
"r" : "0x5df7d7f8f8e15b36fc9f189cacb625040fad10398d08fc90812595922a2c49b2",
61+
"s" : "0x565fc1803f77a84d754ffe3c5363ab54a8d93a06ea1bb9d4c73c73a282b35917",
62+
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
63+
"chainId" : "0x1",
64+
"type" : "0x2",
65+
"feeCap" : "0xfa0",
66+
"tip" : "0x0",
67+
"accessList" : [
68+
]
69+
}
70+
]

cmd/evm/testdata/11/alloc.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
3+
"balance" : "0x0de0b6b3a7640000",
4+
"code" : "0x61ffff5060046000f3",
5+
"nonce" : "0x01",
6+
"storage" : {
7+
}
8+
},
9+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
10+
"balance" : "0x0de0b6b3a7640000",
11+
"code" : "0x",
12+
"nonce" : "0x00",
13+
"storage" : {
14+
"0x00" : "0x00"
15+
}
16+
},
17+
"0xb94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
18+
"balance" : "0x00",
19+
"code" : "0x6001600055",
20+
"nonce" : "0x00",
21+
"storage" : {
22+
}
23+
}
24+
}
25+

cmd/evm/testdata/11/env.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
3+
"currentDifficulty" : "0x020000",
4+
"currentNumber" : "0x01",
5+
"currentTimestamp" : "0x03e8",
6+
"previousHash" : "0xfda4419b3660e99f37e536dae1ab081c180136bb38c837a93e93d9aab58553b2",
7+
"currentGasLimit" : "0x0f4240",
8+
"blockHashes" : {
9+
"0" : "0xfda4419b3660e99f37e536dae1ab081c180136bb38c837a93e93d9aab58553b2"
10+
}
11+
}
12+

0 commit comments

Comments
 (0)