-
Notifications
You must be signed in to change notification settings - Fork 20.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/evm: add difficulty calculation to t8n tool (#23353)
This PR adds functionality to the evm t8n to calculate ethash difficulty. If the caller does not provide a currentDifficulty, but instead provides the parentTimestamp (well, semi-optional, will default to 0 if not given), and parentDifficulty, we can calculate it for him. The caller can also provide a parentUncleHash. In most, but not all cases, the parent uncle hash also affects the formula. If no such hash is provided (or, if the empty all-zero hash is provided), it's assumed that there were no uncles.
- Loading branch information
Showing
8 changed files
with
172 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { | ||
"balance": "0x5ffd4878be161d74", | ||
"code": "0x", | ||
"nonce": "0xac", | ||
"storage": {} | ||
}, | ||
"0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192":{ | ||
"balance": "0xfeedbead", | ||
"nonce" : "0x00" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", | ||
"currentGasLimit": "0x750a163df65e8a", | ||
"currentBaseFee": "0x500", | ||
"currentNumber": "12800000", | ||
"currentTimestamp": "10015", | ||
"parentTimestamp" : "99999", | ||
"parentDifficulty" : "0x2000000000000" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", | ||
"currentGasLimit": "0x750a163df65e8a", | ||
"currentBaseFee": "0x500", | ||
"currentNumber": "12800000", | ||
"currentTimestamp": "10035", | ||
"parentTimestamp" : "99999", | ||
"parentDifficulty" : "0x2000000000000", | ||
"parentUncleHash" : "0x000000000000000000000000000000000000000000000000000000000000beef" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## Difficulty calculation | ||
|
||
This test shows how the `evm t8n` can be used to calculate the (ethash) difficulty, if none is provided by the caller. | ||
|
||
Calculating it (with an empty set of txs) using `London` rules (and no provided unclehash for the parent block): | ||
``` | ||
[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=London | ||
INFO [08-08|17:35:46.876] Trie dumping started root=6f0588..7f4bdc | ||
INFO [08-08|17:35:46.876] Trie dumping complete accounts=2 elapsed="89.313µs" | ||
INFO [08-08|17:35:46.877] Wrote file file=alloc.json | ||
{ | ||
"result": { | ||
"stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", | ||
"txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", | ||
"receiptRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", | ||
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", | ||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | ||
"receipts": [], | ||
"currentDifficulty": 3311729559732224 | ||
} | ||
} | ||
``` | ||
Same thing, but this time providing a non-empty (and non-`emptyKeccak`) unclehash, which leads to a slightly different result: | ||
``` | ||
[user@work evm]$ ./evm t8n --input.alloc=./testdata/14/alloc.json --input.txs=./testdata/14/txs.json --input.env=./testdata/14/env.uncles.json --output.result=stdout --state.fork=London | ||
INFO [08-08|17:35:49.232] Trie dumping started root=6f0588..7f4bdc | ||
INFO [08-08|17:35:49.232] Trie dumping complete accounts=2 elapsed="83.069µs" | ||
INFO [08-08|17:35:49.233] Wrote file file=alloc.json | ||
{ | ||
"result": { | ||
"stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", | ||
"txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", | ||
"receiptRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", | ||
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", | ||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | ||
"receipts": [], | ||
"currentDifficulty": 3311179803918336 | ||
} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |