Skip to content

Commit 32150f8

Browse files
authored
cmd/geth, cmd/evm, params: implement Arrow Glacier (EIP 4345) (#23810)
This PR adds support for ArrowGlacier, as defined by https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/arrow-glacier.md https://eips.ethereum.org/EIPS/eip-4345 > Starting with FORK_BLOCK_NUMBER the client will calculate the difficulty based on a fake block number suggesting to the client that the difficulty bomb is adjusting 10,700,000 blocks later than the actual block number. This also adds support for evm t8n to return the calculated difficulty, so it can be used to construct test.
1 parent bff3303 commit 32150f8

File tree

22 files changed

+160
-30
lines changed

22 files changed

+160
-30
lines changed

cmd/evm/t8n_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,45 @@ func TestT8n(t *testing.T) {
171171
output: t8nOutput{result: true},
172172
expOut: "exp2.json",
173173
},
174+
{ // Difficulty calculation - with uncles + Berlin
175+
base: "./testdata/14",
176+
input: t8nInput{
177+
"alloc.json", "txs.json", "env.uncles.json", "Berlin", "",
178+
},
179+
output: t8nOutput{result: true},
180+
expOut: "exp_berlin.json",
181+
},
182+
{ // Difficulty calculation on arrow glacier
183+
base: "./testdata/19",
184+
input: t8nInput{
185+
"alloc.json", "txs.json", "env.json", "London", "",
186+
},
187+
output: t8nOutput{result: true},
188+
expOut: "exp_london.json",
189+
},
190+
{ // Difficulty calculation on arrow glacier
191+
base: "./testdata/19",
192+
input: t8nInput{
193+
"alloc.json", "txs.json", "env.json", "ArrowGlacier", "",
194+
},
195+
output: t8nOutput{result: true},
196+
expOut: "exp_arrowglacier.json",
197+
},
174198
} {
175199

176200
args := []string{"t8n"}
177201
args = append(args, tc.output.get()...)
178202
args = append(args, tc.input.get(tc.base)...)
203+
var qArgs []string // quoted args for debugging purposes
204+
for _, arg := range args {
205+
if len(arg) == 0 {
206+
qArgs = append(qArgs, `""`)
207+
} else {
208+
qArgs = append(qArgs, arg)
209+
}
210+
}
211+
tt.Logf("args: %v\n", strings.Join(qArgs, " "))
179212
tt.Run("evm-test", args...)
180-
tt.Logf("args: %v\n", strings.Join(args, " "))
181213
// Compare the expected output, if provided
182214
if tc.expOut != "" {
183215
want, err := os.ReadFile(fmt.Sprintf("%v/%v", tc.base, tc.expOut))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"result": {
3+
"stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc",
4+
"txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
5+
"receiptRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
6+
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
7+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
8+
"receipts": [],
9+
"currentDifficulty": "0x1ff9000000000"
10+
}
11+
}

cmd/evm/testdata/19/alloc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
3+
"balance": "0x5ffd4878be161d74",
4+
"code": "0x",
5+
"nonce": "0xac",
6+
"storage": {}
7+
},
8+
"0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192":{
9+
"balance": "0xfeedbead",
10+
"nonce" : "0x00"
11+
}
12+
}

cmd/evm/testdata/19/env.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b",
3+
"currentGasLimit": "0x750a163df65e8a",
4+
"currentBaseFee": "0x500",
5+
"currentNumber": "13000000",
6+
"currentTimestamp": "100015",
7+
"parentTimestamp" : "99999",
8+
"parentDifficulty" : "0x2000000000000"
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"result": {
3+
"stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc",
4+
"txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
5+
"receiptRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
6+
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
7+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
8+
"currentDifficulty": "0x2000000200000",
9+
"receipts": []
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"result": {
3+
"stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc",
4+
"txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
5+
"receiptRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
6+
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
7+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
8+
"currentDifficulty": "0x2000080000000",
9+
"receipts": []
10+
}
11+
}

cmd/evm/testdata/19/readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Difficulty calculation
2+
3+
This test shows how the `evm t8n` can be used to calculate the (ethash) difficulty, if none is provided by the caller,
4+
this time on `ArrowGlacier` (Eip 4345).
5+
6+
Calculating it (with an empty set of txs) using `ArrowGlacier` rules (and no provided unclehash for the parent block):
7+
```
8+
[user@work evm]$ ./evm t8n --input.alloc=./testdata/14/alloc.json --input.txs=./testdata/14/txs.json --input.env=./testdata/14/env.json --output.result=stdout --state.fork=ArrowGlacier
9+
```

cmd/evm/testdata/19/txs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

cmd/geth/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
156156
// makeFullNode loads geth configuration and creates the Ethereum backend.
157157
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
158158
stack, cfg := makeConfigNode(ctx)
159-
if ctx.GlobalIsSet(utils.OverrideLondonFlag.Name) {
160-
cfg.Eth.OverrideLondon = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideLondonFlag.Name))
159+
if ctx.GlobalIsSet(utils.OverrideArrowGlacierFlag.Name) {
160+
cfg.Eth.OverrideArrowGlacier = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideArrowGlacierFlag.Name))
161161
}
162162
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
163163

cmd/geth/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var (
6666
utils.NoUSBFlag,
6767
utils.USBFlag,
6868
utils.SmartCardDaemonPathFlag,
69-
utils.OverrideLondonFlag,
69+
utils.OverrideArrowGlacierFlag,
7070
utils.EthashCacheDirFlag,
7171
utils.EthashCachesInMemoryFlag,
7272
utils.EthashCachesOnDiskFlag,

0 commit comments

Comments
 (0)