core: reject missing request predeploy code

This commit is contained in:
二狗同学 2026-07-06 17:41:26 +08:00
parent 2919267b64
commit d3f8d0a2f1
32 changed files with 305 additions and 60 deletions

View file

@ -21,6 +21,18 @@
"code": "0x6042805500",
"storage": {}
},
"0x00000961ef480eb55e80d19ad83579a64c007002": {
"nonce": "0x01",
"balance": "0x0",
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd",
"storage": {}
},
"0x0000bbddc7ce488642fb579f8b00f3a590007251": {
"nonce": "0x01",
"balance": "0x0",
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd",
"storage": {}
},
"0x71562b71999873DB5b286dF957af199Ec94617F7": {
"nonce": "0x00",
"balance": "0x6124fee993bc0000",

View file

@ -8,6 +8,16 @@
"code": "0x6042805500",
"balance": "0x29a2241af62c0000"
},
"0x00000961ef480eb55e80d19ad83579a64c007002": {
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd",
"balance": "0x0",
"nonce": "0x1"
},
"0x0000bbddc7ce488642fb579f8b00f3a590007251": {
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd",
"balance": "0x0",
"nonce": "0x1"
},
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
"balance": "0x2bf52"
},
@ -35,29 +45,33 @@
}
},
"result": {
"stateRoot": "0x9fdcacd4510e93c4488e537dc51578b5c6d505771db64a2610036eeb4be7b26f",
"stateRoot": "0x862606a83f3adba7e201d226aba4665e2781911fa129e0c0f04c3fd486883a2a",
"txRoot": "0x5d13a0b074e80388dc754da92b22922313a63417b3e25a10f324935e09697a53",
"receiptsRoot": "0x504c5d86c34391f70d210e6c482615b391db4bdb9f43479366399d9c5599850a",
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","receipts": [{
"type": "0x4",
"root": "0x",
"status": "0x1",
"cumulativeGasUsed": "0x15fa9",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","logs": [],"transactionHash": "0x0417aab7c1d8a3989190c3167c132876ce9b8afd99262c5a0f9d06802de3d7ef",
"contractAddress": "0x0000000000000000000000000000000000000000",
"gasUsed": "0x15fa9",
"effectiveGasPrice": null,
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
"blockNumber": "0x1",
"transactionIndex": "0x0"
}
],
"currentDifficulty": null,
"gasUsed": "0x15fa9",
"currentBaseFee": "0x7",
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"requestsHash": "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"requests": []
}
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"receipts": [
{
"type": "0x4",
"root": "0x",
"status": "0x1",
"cumulativeGasUsed": "0x15fa9",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"logs": [],
"transactionHash": "0x0417aab7c1d8a3989190c3167c132876ce9b8afd99262c5a0f9d06802de3d7ef",
"contractAddress": "0x0000000000000000000000000000000000000000",
"gasUsed": "0x15fa9",
"effectiveGasPrice": null,
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
"blockNumber": "0x1",
"transactionIndex": "0x0"
}
],
"currentDifficulty": null,
"gasUsed": "0x15fa9",
"currentBaseFee": "0x7",
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"requestsHash": "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"requests": []
}
}

View file

@ -2,5 +2,17 @@
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0x1000000000000000000",
"nonce": "0x0"
},
"0x00000961ef480eb55e80d19ad83579a64c007002": {
"nonce": "0x01",
"balance": "0x0",
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd",
"storage": {}
},
"0x0000bbddc7ce488642fb579f8b00f3a590007251": {
"nonce": "0x01",
"balance": "0x0",
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd",
"storage": {}
}
}

View file

@ -1,17 +1,27 @@
{
"alloc": {
"0x00000961ef480eb55e80d19ad83579a64c007002": {
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd",
"balance": "0x0",
"nonce": "0x1"
},
"0x0000bbddc7ce488642fb579f8b00f3a590007251": {
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd",
"balance": "0x0",
"nonce": "0x1"
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0x1000000000000000000"
}
},
"result": {
"stateRoot": "0x01c28492482a1a1f66224726ef1059a7036fce69d1d2c991b65cd013725d5742",
"stateRoot": "0x483ed12ebbb83ddc8d5c6de80d5cb352580800285a5a141697bd922cac1d5a49",
"txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"currentDifficulty": null,
"receipts": [],
"currentDifficulty": null,
"gasUsed": "0x0",
"currentBaseFee": "0x10",
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",

View file

@ -4016,6 +4016,22 @@ func TestEIP3651(t *testing.T) {
// Simple deposit generator, source: https://gist.github.com/lightclient/54abb2af2465d6969fa6d1920b9ad9d7
var depositsGeneratorCode = common.FromHex("6080604052366103aa575f603067ffffffffffffffff811115610025576100246103ae565b5b6040519080825280601f01601f1916602001820160405280156100575781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f8151811061007d5761007c6103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f602067ffffffffffffffff8111156100c7576100c66103ae565b5b6040519080825280601f01601f1916602001820160405280156100f95781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f8151811061011f5761011e6103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f600867ffffffffffffffff811115610169576101686103ae565b5b6040519080825280601f01601f19166020018201604052801561019b5781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f815181106101c1576101c06103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f606067ffffffffffffffff81111561020b5761020a6103ae565b5b6040519080825280601f01601f19166020018201604052801561023d5781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f81518110610263576102626103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f600867ffffffffffffffff8111156102ad576102ac6103ae565b5b6040519080825280601f01601f1916602001820160405280156102df5781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f81518110610305576103046103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f8081819054906101000a900460ff168092919061035090610441565b91906101000a81548160ff021916908360ff160217905550507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c585858585856040516103a09594939291906104d9565b60405180910390a1005b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f60ff82169050919050565b5f61044b82610435565b915060ff820361045e5761045d610408565b5b600182019050919050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6104ab82610469565b6104b58185610473565b93506104c5818560208601610483565b6104ce81610491565b840191505092915050565b5f60a0820190508181035f8301526104f181886104a1565b9050818103602083015261050581876104a1565b9050818103604083015261051981866104a1565b9050818103606083015261052d81856104a1565b9050818103608083015261054181846104a1565b9050969550505050505056fea26469706673582212208569967e58690162d7d6fe3513d07b393b4c15e70f41505cbbfd08f53eba739364736f6c63430008190033")
func addPragueRequestPredeploys(alloc types.GenesisAlloc) types.GenesisAlloc {
if alloc == nil {
alloc = types.GenesisAlloc{}
}
alloc[params.WithdrawalQueueAddress] = types.Account{Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0}
alloc[params.ConsolidationQueueAddress] = types.Account{Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0}
return alloc
}
func addAmsterdamRequestPredeploys(alloc types.GenesisAlloc) types.GenesisAlloc {
alloc = addPragueRequestPredeploys(alloc)
alloc[params.BuilderDepositAddress] = types.Account{Nonce: 1, Code: params.BuilderDepositCode, Balance: common.Big0}
alloc[params.BuilderExitAddress] = types.Account{Nonce: 1, Code: params.BuilderExitCode, Balance: common.Big0}
return alloc
}
// This is a smoke test for EIP-7685 requests added in the Prague fork. The test first
// creates a block containing requests, and then inserts it into the chain to run
// validation.
@ -4114,7 +4130,7 @@ func TestEIP7702(t *testing.T) {
)
gspec := &Genesis{
Config: &config,
Alloc: types.GenesisAlloc{
Alloc: addPragueRequestPredeploys(types.GenesisAlloc{
addr1: {Balance: funds},
addr2: {Balance: funds},
aa: { // The address 0xAAAA calls into addr2
@ -4127,7 +4143,7 @@ func TestEIP7702(t *testing.T) {
Nonce: 0,
Balance: big.NewInt(0),
},
},
}),
}
// Sign authorization tuples.
@ -4432,7 +4448,7 @@ func TestGetCanonicalReceipt(t *testing.T) {
funds = big.NewInt(1000000000000000000)
gspec = &Genesis{
Config: params.MergedTestChainConfig,
Alloc: types.GenesisAlloc{address: {Balance: funds}},
Alloc: addPragueRequestPredeploys(types.GenesisAlloc{address: {Balance: funds}}),
BaseFee: big.NewInt(params.InitialBaseFee),
}
signer = types.LatestSigner(gspec.Config)

View file

@ -44,10 +44,10 @@ func TestGeneratePOSChain(t *testing.T) {
config = *params.MergedTestChainConfig
gspec = &Genesis{
Config: &config,
Alloc: types.GenesisAlloc{
Alloc: addPragueRequestPredeploys(types.GenesisAlloc{
address: {Balance: funds},
params.BeaconRootsAddress: {Code: params.BeaconRootsCode},
},
}),
BaseFee: big.NewInt(params.InitialBaseFee),
Difficulty: common.Big1,
GasLimit: 5_000_000,

View file

@ -52,9 +52,9 @@ func TestEIP8246SelfdestructNoBurn(t *testing.T) {
gspec := &Genesis{
Config: &config,
Alloc: types.GenesisAlloc{
Alloc: addAmsterdamRequestPredeploys(types.GenesisAlloc{
addr1: {Balance: newGwei(1_000_000_000)},
},
}),
}
// The contract created by addr1's first (nonce 0) transaction.
created := crypto.CreateAddress(addr1, 0)

View file

@ -82,11 +82,11 @@ func testEthTransferLogs(t *testing.T, value uint64) {
gspec := &Genesis{
Config: &config,
Alloc: types.GenesisAlloc{
Alloc: addAmsterdamRequestPredeploys(types.GenesisAlloc{
addr1: {Balance: newGwei(1000000000)},
addr2: {Code: ethTransferTestCode},
addr3: {Code: ethTransferTestCode},
},
}),
}
_, blocks, receipts := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {
tx := types.MustSignNewTx(key1, signer, &types.DynamicFeeTx{

View file

@ -401,6 +401,9 @@ func ProcessBuilderExitQueue(requests *[][]byte, rules params.Rules, evm *vm.EVM
}
func processRequestsSystemCall(requests *[][]byte, rules params.Rules, evm *vm.EVM, requestType byte, addr common.Address, blockAccessIndex uint32, blockAccessList *bal.ConstructionBlockAccessList) error {
if evm.StateDB.GetCodeSize(addr) == 0 {
return fmt.Errorf("system contract address %s does not contain code", addr.Hex())
}
if tracer := evm.Config.Tracer; tracer != nil {
onSystemCallStart(tracer, evm.GetVMContext())
if tracer.OnSystemCallEnd != nil {

View file

@ -20,6 +20,7 @@ import (
"crypto/ecdsa"
"math"
"math/big"
"strings"
"testing"
"github.com/ethereum/go-ethereum/common"
@ -29,7 +30,10 @@ import (
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/keccak"
"github.com/ethereum/go-ethereum/params"
@ -39,6 +43,80 @@ import (
func u64(val uint64) *uint64 { return &val }
func TestProcessRequestsSystemCallMissingCode(t *testing.T) {
config := *params.MergedTestChainConfig
number := big.NewInt(1)
time := uint64(10)
rules := config.Rules(number, true, time)
newEVM := func(t *testing.T, addr common.Address, code []byte) *vm.EVM {
t.Helper()
statedb, err := state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
if err != nil {
t.Fatalf("failed to create state: %v", err)
}
if code != nil {
statedb.SetNonce(addr, 1, tracing.NonceChangeUnspecified)
statedb.SetCode(addr, code, tracing.CodeChangeUnspecified)
}
header := &types.Header{
Number: number,
Time: time,
GasLimit: 30_000_000,
Difficulty: new(big.Int),
}
vmContext := NewEVMBlockContext(header, &BlockChain{chainConfig: &config}, new(common.Address))
return vm.NewEVM(vmContext, statedb, &config, vm.Config{})
}
for _, tt := range []struct {
name string
addr common.Address
code []byte
process func(*[][]byte, *vm.EVM) error
}{
{
name: "withdrawal queue",
addr: params.WithdrawalQueueAddress,
code: params.WithdrawalQueueCode,
process: func(requests *[][]byte, evm *vm.EVM) error {
return ProcessWithdrawalQueue(requests, rules, evm, 0, nil)
},
},
{
name: "consolidation queue",
addr: params.ConsolidationQueueAddress,
code: params.ConsolidationQueueCode,
process: func(requests *[][]byte, evm *vm.EVM) error {
return ProcessConsolidationQueue(requests, rules, evm, 0, nil)
},
},
} {
t.Run(tt.name+"/missing code", func(t *testing.T) {
var requests [][]byte
err := tt.process(&requests, newEVM(t, tt.addr, nil))
if err == nil {
t.Fatal("expected missing system contract code error")
}
if !strings.Contains(err.Error(), "does not contain code") {
t.Fatalf("unexpected error: %v", err)
}
if len(requests) != 0 {
t.Fatalf("unexpected requests: %x", requests)
}
})
t.Run(tt.name+"/empty queue", func(t *testing.T) {
var requests [][]byte
if err := tt.process(&requests, newEVM(t, tt.addr, tt.code)); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(requests) != 0 {
t.Fatalf("unexpected requests: %x", requests)
}
})
}
}
// TestStateProcessorErrors tests the output from the 'core' errors
// as defined in core/error.go. These errors are generated when the
// blockchain imports bad blocks, meaning blocks which have valid headers but

View file

@ -77,7 +77,7 @@ func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) {
genesis := &core.Genesis{
Config: &config,
Alloc: types.GenesisAlloc{
Alloc: addPragueRequestPredeploys(types.GenesisAlloc{
testAddr: {Balance: testBalance},
params.BeaconRootsAddress: {Balance: common.Big0, Code: common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b6201800042064281555f359062018000015500")},
config.DepositContractAddress: {
@ -86,7 +86,7 @@ func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) {
Nonce: 0,
Balance: big.NewInt(0),
},
},
}),
ExtraData: []byte("test genesis"),
Timestamp: 9000,
BaseFee: big.NewInt(params.InitialBaseFee),
@ -112,6 +112,15 @@ func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) {
return genesis, blocks
}
func addPragueRequestPredeploys(alloc types.GenesisAlloc) types.GenesisAlloc {
if alloc == nil {
alloc = types.GenesisAlloc{}
}
alloc[params.WithdrawalQueueAddress] = types.Account{Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0}
alloc[params.ConsolidationQueueAddress] = types.Account{Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0}
return alloc
}
func TestEth2AssembleBlock(t *testing.T) {
genesis, blocks := generateMergeChain(10, false)
n, ethservice := startEthService(t, genesis, blocks)

View file

@ -28,12 +28,22 @@ import (
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types/bal"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/holiman/uint256"
)
func addPragueRequestPredeploys(alloc types.GenesisAlloc) types.GenesisAlloc {
if alloc == nil {
alloc = types.GenesisAlloc{}
}
alloc[params.WithdrawalQueueAddress] = types.Account{Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0}
alloc[params.ConsolidationQueueAddress] = types.Account{Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0}
return alloc
}
func makeTestBAL(minSize int) *bal.BlockAccessList {
n := minSize/33 + 1 // 33 bytes per storage read slot in RLP
access := bal.AccountAccess{
@ -56,6 +66,7 @@ func makeTestBAL(minSize int) *bal.BlockAccessList {
func getChainWithBALs(nBlocks int, balSize int) (*core.BlockChain, []common.Hash, []rlp.RawValue) {
gspec := &core.Genesis{
Config: params.MergedTestChainConfig,
Alloc: addPragueRequestPredeploys(nil),
}
db := rawdb.NewMemoryDatabase()
engine := beacon.New(ethash.NewFaker())

View file

@ -95,6 +95,15 @@ func newTestBackend(t *testing.T, n int, gspec *core.Genesis, generator func(i i
return backend
}
func addPragueRequestPredeploys(alloc types.GenesisAlloc) types.GenesisAlloc {
if alloc == nil {
alloc = types.GenesisAlloc{}
}
alloc[params.WithdrawalQueueAddress] = types.Account{Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0}
alloc[params.ConsolidationQueueAddress] = types.Account{Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0}
return alloc
}
func (b *testBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
return b.chain.GetHeaderByHash(hash), nil
}
@ -1389,12 +1398,12 @@ func TestTraceBlockWithBasefee(t *testing.T) {
target := common.HexToAddress("0x1111111111111111111111111111111111111111")
genesis := &core.Genesis{
Config: params.AllDevChainProtocolChanges,
Alloc: types.GenesisAlloc{
Alloc: addPragueRequestPredeploys(types.GenesisAlloc{
accounts[0].addr: {Balance: big.NewInt(1 * params.Ether)},
target: {Nonce: 1, Code: []byte{
byte(vm.BASEFEE), byte(vm.STOP),
}},
},
}),
}
genBlocks := 1
signer := types.HomesteadSigner{}

View file

@ -146,6 +146,9 @@ func setupTestBlockchain(t *testing.T, genesis *core.Genesis, tx *types.Transact
} else {
engine = ethash.NewFaker()
}
if useBeacon {
genesis.Alloc = addPragueRequestPredeploys(genesis.Alloc)
}
_, blocks, _ := core.GenerateChainWithGenesis(genesis, engine, 1, func(i int, b *core.BlockGen) {
b.AddTx(tx)

View file

@ -67,11 +67,21 @@ type supplyInfo struct {
func emptyBlockGenerationFunc(b *core.BlockGen) {}
func addPragueRequestPredeploys(alloc types.GenesisAlloc) types.GenesisAlloc {
if alloc == nil {
alloc = types.GenesisAlloc{}
}
alloc[params.WithdrawalQueueAddress] = types.Account{Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0}
alloc[params.ConsolidationQueueAddress] = types.Account{Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0}
return alloc
}
func TestSupplyOmittedFields(t *testing.T) {
var (
config = *params.MergedTestChainConfig
gspec = &core.Genesis{
Config: &config,
Alloc: addPragueRequestPredeploys(nil),
}
)
@ -84,7 +94,7 @@ func TestSupplyOmittedFields(t *testing.T) {
expected := supplyInfo{
Number: 0,
Hash: common.HexToHash("0x3055fc27d6b4a08eb07033a0d1ee755a4b2988086f28a6189eac1b507525eeb1"),
Hash: common.HexToHash("0x27c7fd72c3f07448e76eba06b5a3f95be9cfb948116c21d4ef4a8315adbe0bfb"),
ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
}
actual := out[expected.Number]
@ -273,6 +283,7 @@ func TestSupplyWithdrawals(t *testing.T) {
config = *params.MergedTestChainConfig
gspec = &core.Genesis{
Config: &config,
Alloc: addPragueRequestPredeploys(nil),
}
)

View file

@ -65,12 +65,21 @@ var (
revertCode = common.FromHex("7f08c379a0000000000000000000000000000000000000000000000000000000006000526020600452600a6024527f75736572206572726f7200000000000000000000000000000000000000000000604452604e6000fd")
)
func addPragueRequestPredeploys(alloc types.GenesisAlloc) types.GenesisAlloc {
if alloc == nil {
alloc = types.GenesisAlloc{}
}
alloc[params.WithdrawalQueueAddress] = types.Account{Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0}
alloc[params.ConsolidationQueueAddress] = types.Account{Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0}
return alloc
}
var genesis = &core.Genesis{
Config: params.AllDevChainProtocolChanges,
Alloc: types.GenesisAlloc{
Alloc: addPragueRequestPredeploys(types.GenesisAlloc{
testAddr: {Balance: testBalance},
revertContractAddr: {Code: revertCode},
},
}),
ExtraData: []byte("test genesis"),
Timestamp: 9000,
BaseFee: big.NewInt(params.InitialBaseFee),

View file

@ -82,7 +82,7 @@ func NewBackend(alloc types.GenesisAlloc, options ...func(nodeConf *node.Config,
ethConf.Genesis = &core.Genesis{
Config: params.AllDevChainProtocolChanges,
GasLimit: ethconfig.Defaults.Miner.GasCeil,
Alloc: alloc,
Alloc: addRequestPredeploys(alloc),
}
ethConf.SyncMode = ethconfig.FullSync
ethConf.TxPool.NoLocals = true
@ -104,6 +104,18 @@ func NewBackend(alloc types.GenesisAlloc, options ...func(nodeConf *node.Config,
return sim
}
func addRequestPredeploys(alloc types.GenesisAlloc) types.GenesisAlloc {
withPredeploys := make(types.GenesisAlloc, len(alloc)+4)
for address, account := range alloc {
withPredeploys[address] = account
}
withPredeploys[params.WithdrawalQueueAddress] = types.Account{Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0}
withPredeploys[params.ConsolidationQueueAddress] = types.Account{Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0}
withPredeploys[params.BuilderDepositAddress] = types.Account{Nonce: 1, Code: params.BuilderDepositCode, Balance: common.Big0}
withPredeploys[params.BuilderExitAddress] = types.Account{Nonce: 1, Code: params.BuilderExitCode, Balance: common.Big0}
return withPredeploys
}
// newWithNode sets up a simulated backend on an existing node. The provided node
// must not be started and will be started by this method.
func newWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*Backend, error) {

View file

@ -17,6 +17,7 @@
package simulated
import (
"bytes"
"context"
"crypto/ecdsa"
"crypto/sha256"
@ -128,6 +129,29 @@ func TestNewBackend(t *testing.T) {
}
}
func TestNewBackendRequestPredeploys(t *testing.T) {
sim := NewBackend(types.GenesisAlloc{})
defer sim.Close()
for _, tt := range []struct {
address common.Address
code []byte
}{
{params.WithdrawalQueueAddress, params.WithdrawalQueueCode},
{params.ConsolidationQueueAddress, params.ConsolidationQueueCode},
{params.BuilderDepositAddress, params.BuilderDepositCode},
{params.BuilderExitAddress, params.BuilderExitCode},
} {
code, err := sim.Client().CodeAt(context.Background(), tt.address, big.NewInt(0))
if err != nil {
t.Fatalf("failed to retrieve code for %s: %v", tt.address, err)
}
if !bytes.Equal(code, tt.code) {
t.Fatalf("code mismatch for %s: have %x, want %x", tt.address, code, tt.code)
}
}
}
func TestAdjustTime(t *testing.T) {
sim := NewBackend(types.GenesisAlloc{})
defer sim.Close()

View file

@ -461,11 +461,23 @@ func fakeBlockHash(txh common.Hash) common.Hash {
return crypto.Keccak256Hash([]byte("testblock"), txh.Bytes())
}
func addPragueRequestPredeploys(alloc types.GenesisAlloc) types.GenesisAlloc {
if alloc == nil {
alloc = types.GenesisAlloc{}
}
alloc[params.WithdrawalQueueAddress] = types.Account{Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0}
alloc[params.ConsolidationQueueAddress] = types.Account{Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0}
return alloc
}
func newTestBackend(t *testing.T, n int, gspec *core.Genesis, engine consensus.Engine, generator func(i int, b *core.BlockGen)) *testBackend {
options := core.DefaultConfig().WithArchive(true)
options.TxLookupLimit = 0 // index all txs
accman, acc := newTestAccountManager(t)
if gspec.Config != nil && gspec.Config.IsPrague(big.NewInt(1), gspec.Timestamp+10) {
gspec.Alloc = addPragueRequestPredeploys(gspec.Alloc)
}
gspec.Alloc[acc.Address] = types.Account{Balance: big.NewInt(params.Ether)}
// Generate blocks for testing
@ -2526,10 +2538,10 @@ func TestSimulateV1ChainLinkage(t *testing.T) {
recipient = common.Address{0xbb, 0xbb}
gspec = &core.Genesis{
Config: params.MergedTestChainConfig,
Alloc: types.GenesisAlloc{
Alloc: addPragueRequestPredeploys(types.GenesisAlloc{
sender: {Balance: big.NewInt(params.Ether)},
contractAddr: {Code: common.Hex2Bytes("5f35405f8114600f575f5260205ff35b5f80fd")},
},
}),
}
signer = types.LatestSigner(params.MergedTestChainConfig)
)

View file

@ -2,7 +2,7 @@
{
"blobGasPrice": "0x1",
"blobGasUsed": "0x20000",
"blockHash": "0x5f58514bcb3b216908f0aff6ced44666c3aa250df06093150ac850a7a7850f3c",
"blockHash": "0x81ea8f3118b9b11ccfb07900132340bf30b4560c85820dde65687756d3d00c96",
"blockNumber": "0x6",
"contractAddress": null,
"cumulativeGasUsed": "0x5208",

View file

@ -1,6 +1,6 @@
[
{
"blockHash": "0xb3e447c77374fd285964cba692e96b1673a88a959726826b5b6e2dca15472b0a",
"blockHash": "0xcbc79a9d32e417b1bb6432917de4406c97d295b0c7d3c3092c4ca75889a1a2dc",
"blockNumber": "0x2",
"contractAddress": "0xae9bea628c4ce503dcfd7e305cab4e29e7476592",
"cumulativeGasUsed": "0xcf50",

View file

@ -1,6 +1,6 @@
[
{
"blockHash": "0x47cd44027bb55856a175e36be0396bad221e52172529d9c1bf12bf5424a041ae",
"blockHash": "0xc1fb0b8793d39eda962ab10af8400a5169f81402d0cab00f013c433b10b5c543",
"blockNumber": "0x4",
"contractAddress": null,
"cumulativeGasUsed": "0x5564",

View file

@ -1,6 +1,6 @@
[
{
"blockHash": "0xcc6225bf39327429a3d869af71182d619a354155187d0b5a8ecd6a9309cffcaa",
"blockHash": "0x69bfe49b2fa20c994f5a45ed6feb4092569002de2743ca707c9210e1cc565d6a",
"blockNumber": "0x3",
"contractAddress": null,
"cumulativeGasUsed": "0x5e28",
@ -19,7 +19,7 @@
"blockNumber": "0x3",
"transactionHash": "0xeaf3921cbf03ba45bad4e6ab807b196ce3b2a0b5bacc355b6272fa96b11b4287",
"transactionIndex": "0x0",
"blockHash": "0xcc6225bf39327429a3d869af71182d619a354155187d0b5a8ecd6a9309cffcaa",
"blockHash": "0x69bfe49b2fa20c994f5a45ed6feb4092569002de2743ca707c9210e1cc565d6a",
"blockTimestamp": "0x1e",
"logIndex": "0x0",
"removed": false

View file

@ -1,6 +1,6 @@
[
{
"blockHash": "0xe9bd1d8c303b1af5c704b9d78e62c54a34af47e0db04ac1389a5ef74a619b9da",
"blockHash": "0x28a2e256d84975af5e27de6aa2ed6cd25824dba6fd59933ead3507d68c3a5281",
"blockNumber": "0x1",
"contractAddress": null,
"cumulativeGasUsed": "0x5208",

View file

@ -2,7 +2,7 @@
{
"blobGasPrice": "0x1",
"blobGasUsed": "0x20000",
"blockHash": "0x5f58514bcb3b216908f0aff6ced44666c3aa250df06093150ac850a7a7850f3c",
"blockHash": "0x81ea8f3118b9b11ccfb07900132340bf30b4560c85820dde65687756d3d00c96",
"blockNumber": "0x6",
"contractAddress": null,
"cumulativeGasUsed": "0x5208",

View file

@ -1,6 +1,6 @@
[
{
"blockHash": "0xc74cf882395ec92eec3673d93a57f9a3bf1a5e696fae3e52f252059af62756c8",
"blockHash": "0xcd173e00a5594a27d245d3a532eb3136ac492d9ec2a7f2403ca0a253398225be",
"blockNumber": "0x7",
"contractAddress": null,
"cumulativeGasUsed": "0x5208",

View file

@ -1,7 +1,7 @@
{
"blobGasPrice": "0x1",
"blobGasUsed": "0x20000",
"blockHash": "0x5f58514bcb3b216908f0aff6ced44666c3aa250df06093150ac850a7a7850f3c",
"blockHash": "0x81ea8f3118b9b11ccfb07900132340bf30b4560c85820dde65687756d3d00c96",
"blockNumber": "0x6",
"contractAddress": null,
"cumulativeGasUsed": "0x5208",

View file

@ -1,5 +1,5 @@
{
"blockHash": "0xb3e447c77374fd285964cba692e96b1673a88a959726826b5b6e2dca15472b0a",
"blockHash": "0xcbc79a9d32e417b1bb6432917de4406c97d295b0c7d3c3092c4ca75889a1a2dc",
"blockNumber": "0x2",
"contractAddress": "0xae9bea628c4ce503dcfd7e305cab4e29e7476592",
"cumulativeGasUsed": "0xcf50",

View file

@ -1,5 +1,5 @@
{
"blockHash": "0x5bff93f8f94ba7ee52bef1a80062b9fed22c6d1eebb2b0e87a4a003365a7bd66",
"blockHash": "0x518b313d05ff3b4e9940719ba4f34ca2f40a5ceeead4094d9b115d310f7270f5",
"blockNumber": "0x5",
"contractAddress": "0xfdaa97661a584d977b4d3abb5370766ff5b86a18",
"cumulativeGasUsed": "0xe01c",

View file

@ -1,5 +1,5 @@
{
"blockHash": "0x47cd44027bb55856a175e36be0396bad221e52172529d9c1bf12bf5424a041ae",
"blockHash": "0xc1fb0b8793d39eda962ab10af8400a5169f81402d0cab00f013c433b10b5c543",
"blockNumber": "0x4",
"contractAddress": null,
"cumulativeGasUsed": "0x5564",

View file

@ -1,5 +1,5 @@
{
"blockHash": "0xe9bd1d8c303b1af5c704b9d78e62c54a34af47e0db04ac1389a5ef74a619b9da",
"blockHash": "0x28a2e256d84975af5e27de6aa2ed6cd25824dba6fd59933ead3507d68c3a5281",
"blockNumber": "0x1",
"contractAddress": null,
"cumulativeGasUsed": "0x5208",

View file

@ -1,5 +1,5 @@
{
"blockHash": "0xcc6225bf39327429a3d869af71182d619a354155187d0b5a8ecd6a9309cffcaa",
"blockHash": "0x69bfe49b2fa20c994f5a45ed6feb4092569002de2743ca707c9210e1cc565d6a",
"blockNumber": "0x3",
"contractAddress": null,
"cumulativeGasUsed": "0x5e28",
@ -18,7 +18,7 @@
"blockNumber": "0x3",
"transactionHash": "0xeaf3921cbf03ba45bad4e6ab807b196ce3b2a0b5bacc355b6272fa96b11b4287",
"transactionIndex": "0x0",
"blockHash": "0xcc6225bf39327429a3d869af71182d619a354155187d0b5a8ecd6a9309cffcaa",
"blockHash": "0x69bfe49b2fa20c994f5a45ed6feb4092569002de2743ca707c9210e1cc565d6a",
"blockTimestamp": "0x1e",
"logIndex": "0x0",
"removed": false