go-ethereum
go-ethereum copied to clipboard
Geth overrides 0x0 genesis gas limit
Seems to be due to this code: https://github.com/ethereum/go-ethereum/blob/01e5e9c2c3fa1cf7a9747148dca22d59ff9839b6/core/genesis.go#L370-L372
Unfortunately, other clients don't have this behavior. I think if an invalid gas limit is explicitly specified in the genesis we should fail to initialize.
$ cat genesis.json | jq
{
"config": {
"chainId": 1,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"arrowGlacierBlock": 0,
"grayGlacierBlock": 0,
"ethash": {}
},
"nonce": "0x0",
"timestamp": "0x0",
"extraData": "0x",
"gasLimit": "0x0",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"658bdf435d810c91414ec09147daa6db62406379": {
"balance": "0x487a9a304539440000"
}
},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": "0x3b9aca00"
}
$ geth --datadir=data init genesis.json
INFO [06-19|16:01:41.250] Maximum peer count ETH=50 LES=0 total=50
INFO [06-19|16:01:41.250] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [06-19|16:01:41.252] Set global gas cap cap=50,000,000
INFO [06-19|16:01:41.252] Allocated cache and file handles database=/home/lc/dev/rpctests/tests/data/geth/chaindata cache=16.00MiB handles=16
INFO [06-19|16:01:41.281] Writing custom genesis block
INFO [06-19|16:01:41.281] Persisted trie from memory database nodes=1 size=148.00B time="94.299µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [06-19|16:01:41.282] Successfully wrote genesis state database=chaindata hash=7ead2c..68bad8
INFO [06-19|16:01:41.282] Allocated cache and file handles database=/home/lc/dev/rpctests/tests/data/geth/lightchaindata cache=16.00MiB handles=16
INFO [06-19|16:01:41.312] Writing custom genesis block
INFO [06-19|16:01:41.313] Persisted trie from memory database nodes=1 size=148.00B time="66.308µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [06-19|16:01:41.313] Successfully wrote genesis state database=lightchaindata hash=7ead2c..68bad8
$ geth --datadir=data init genesis.json
INFO [06-19|16:05:25.288] Maximum peer count ETH=50 LES=0 total=50
INFO [06-19|16:05:25.288] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [06-19|16:05:25.289] Set global gas cap cap=50,000,000
INFO [06-19|16:05:25.289] Allocated cache and file handles database=/home/lc/dev/rpctests/tests/data/geth/chaindata cache=16.00MiB handles=16
INFO [06-19|16:05:25.374] Opened ancient database database=/home/lc/dev/rpctests/tests/data/geth/chaindata/ancient readonly=false
INFO [06-19|16:05:25.375] Writing custom genesis block
INFO [06-19|16:05:25.375] Persisted trie from memory database nodes=1 size=148.00B time="91.823µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [06-19|16:05:25.376] Successfully wrote genesis state database=chaindata hash=7ead2c..68bad8
INFO [06-19|16:05:25.376] Allocated cache and file handles database=/home/lc/dev/rpctests/tests/data/geth/lightchaindata cache=16.00MiB handles=16
INFO [06-19|16:05:25.461] Opened ancient database database=/home/lc/dev/rpctests/tests/data/geth/lightchaindata/ancient readonly=false
INFO [06-19|16:05:25.461] Writing custom genesis block
INFO [06-19|16:05:25.462] Persisted trie from memory database nodes=1 size=148.00B time="85.112µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [06-19|16:05:25.463] Successfully wrote genesis state database=lightchaindata hash=7ead2c..68bad8
$ geth --datadir=data --nodiscover console --port 30333 2>/dev/null
Welcome to the Geth JavaScript console!
instance: Geth/v1.10.19-stable-23bee162/linux-amd64/go1.17.7
at block: 0 (Thu Jan 01 1970 01:00:00 GMT+0100 (CET))
datadir: /home/lc/dev/rpctests/tests/data
modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
To exit, press ctrl-d or type exit
> eth.getBlockByNumber(0)
{
baseFeePerGas: "0x3b9aca00",
difficulty: "0x1",
extraData: "0x",
gasLimit: "0x47e7c4",
gasUsed: "0x0",
hash: "0x7ead2ce6067d325b8e27e55377db7e9acaa63b1de9cc880c174cee690b68bad8",
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
miner: "0x0000000000000000000000000000000000000000",
mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
nonce: "0x0000000000000000",
number: "0x0",
parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
size: "0x1fd",
stateRoot: "0x21b036e39374a278109134aa04d153e16999e838316561a114a563d6ff9e6707",
timestamp: "0x0",
totalDifficulty: "0x1",
transactions: [],
transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: []
}
if g.GasLimit == 0 -- the problem is that GasLimit is a uint64, and if the user didn't specify anything at all, then it's 0. The case where the user explicitly specifies 0 is, I guess, something nobody considered. I don't see any simple way to both "default to params.GenesisLimit if nothing is specified" and "reject explicit zero", but maybe you can figure something out :)