Skip to content

Commit b256243

Browse files
bshastryclaudemacfarla
authored
fix(evmtool): use excessBlobGas from test environment in state-test (#9545)
* fix(evmtool): use excessBlobGas from test environment in state-test The state-test command was hardcoding BlobGas.ZERO when calculating blob gas price, ignoring the currentExcessBlobGas from the test environment. This caused incorrect BLOBBASEFEE opcode results and state root divergence with geth. With excessBlobGas=0x240000 and Cancun blob fee fraction: - Before: BLOBBASEFEE returns 1 (using zero) - After: BLOBBASEFEE returns 2 (using actual value) Signed-off-by: Bhargava Shastry <bhargava.shastry@ethereum.org> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix(evmtool): correct excess-blob-gas test file format for EvmToolSpecTests The excess-blob-gas.json file was in raw state test format but placed in the state-test/ directory which is scanned by EvmToolSpecTests. This caused a NullPointerException because EvmToolSpecTests expects a spec wrapper format with cli, stdin, stdout fields. - Convert state-test/excess-blob-gas.json to spec wrapper format - Create separate excess-blob-gas.json in parent directory for StateTestSubCommandTest - Update StateTestSubCommandTest to reference the new file location 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Bhargava Shastry <bhargava.shastry@ethereum.org> * formatting Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com> --------- Signed-off-by: Bhargava Shastry <bhargava.shastry@ethereum.org> Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
1 parent 55819c5 commit b256243

File tree

4 files changed

+162
-2
lines changed

4 files changed

+162
-2
lines changed

ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,9 @@ private void traceTestSpecs(
278278
final MainnetTransactionProcessor processor = protocolSpec.getTransactionProcessor();
279279
final WorldUpdater worldStateUpdater = worldState.updater();
280280
final Stopwatch timer = Stopwatch.createStarted();
281-
// Todo: EIP-4844 use the excessBlobGas of the parent instead of BlobGas.ZERO
282-
final Wei blobGasPrice = protocolSpec.getFeeMarket().blobGasPricePerGas(BlobGas.ZERO);
281+
// EIP-4844: use excessBlobGas from block header for correct blob gas price calculation
282+
final BlobGas excessBlobGas = blockHeader.getExcessBlobGas().orElse(BlobGas.ZERO);
283+
final Wei blobGasPrice = protocolSpec.getFeeMarket().blobGasPricePerGas(excessBlobGas);
283284
final TransactionProcessingResult result =
284285
processor.processTransaction(
285286
worldStateUpdater,

ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/StateTestSubCommandTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,25 @@ void invalidTransactionShouldNotModifyState() {
154154
// Both error and validationError fields should be present for invalid transactions
155155
assertThat(output).contains("\"error\":\"Upfront gas cost cannot exceed 2^256 Wei\"");
156156
}
157+
158+
@Test
159+
void shouldUseExcessBlobGasFromEnvironment() {
160+
// Tests that BLOBBASEFEE opcode uses currentExcessBlobGas from the test environment.
161+
// With excessBlobGas=0x240000 and Cancun blob fee fraction (3338477), blob price = 2.
162+
// The contract stores BLOBBASEFEE result in storage slot 0.
163+
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
164+
EvmToolCommand parentCommand =
165+
new EvmToolCommand(System.in, new PrintWriter(baos, true, UTF_8));
166+
final StateTestSubCommand stateTestSubCommand = new StateTestSubCommand(parentCommand);
167+
final CommandLine cmd = new CommandLine(stateTestSubCommand);
168+
cmd.parseArgs(StateTestSubCommandTest.class.getResource("excess-blob-gas.json").getPath());
169+
stateTestSubCommand.run();
170+
171+
final String output = baos.toString(UTF_8);
172+
// State root should match expected value (computed with correct blob gas price = 2)
173+
assertThat(output)
174+
.contains(
175+
"\"stateRoot\":\"0x4f0dafcdc942cf538ffe1f870ab031c2761857b3066f595e56c74bcb222eb0bb\"");
176+
assertThat(output).contains("\"pass\":true");
177+
}
157178
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"excessBlobGasTest": {
3+
"_info": {
4+
"comment": "Test that verifies BLOBBASEFEE opcode correctly uses currentExcessBlobGas from environment"
5+
},
6+
"env": {
7+
"currentCoinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
8+
"currentGasLimit": "0x05f5e100",
9+
"currentNumber": "0x01",
10+
"currentTimestamp": "0x03e8",
11+
"currentRandom": "0x0000000000000000000000000000000000000000000000000000000000000000",
12+
"currentDifficulty": "0x00",
13+
"currentBaseFee": "0x0a",
14+
"currentExcessBlobGas": "0x240000"
15+
},
16+
"pre": {
17+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
18+
"nonce": "0x00",
19+
"balance": "0x3635c9adc5dea00000",
20+
"code": "0x",
21+
"storage": {}
22+
},
23+
"0x1000000000000000000000000000000000000000": {
24+
"nonce": "0x00",
25+
"balance": "0x00",
26+
"code": "0x4a600055",
27+
"storage": {}
28+
}
29+
},
30+
"transaction": {
31+
"nonce": "0x00",
32+
"gasPrice": "0x0a",
33+
"gasLimit": [
34+
"0x030d40"
35+
],
36+
"to": "0x1000000000000000000000000000000000000000",
37+
"value": [
38+
"0x00"
39+
],
40+
"data": [
41+
"0x"
42+
],
43+
"sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
44+
"secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
45+
},
46+
"post": {
47+
"Cancun": [
48+
{
49+
"hash": "0x4f0dafcdc942cf538ffe1f870ab031c2761857b3066f595e56c74bcb222eb0bb",
50+
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
51+
"indexes": {
52+
"data": 0,
53+
"gas": 0,
54+
"value": 0
55+
}
56+
}
57+
]
58+
}
59+
}
60+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"cli": [
3+
"state-test",
4+
"stdin",
5+
"--trace",
6+
"--trace.memory",
7+
"--trace.stack",
8+
"--trace.returndata",
9+
"--trace.noeip-3155",
10+
"--notime"
11+
],
12+
"stdin": {
13+
"excessBlobGasTest": {
14+
"_info": {
15+
"comment": "Test that verifies BLOBBASEFEE opcode correctly uses currentExcessBlobGas from environment"
16+
},
17+
"env": {
18+
"currentCoinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
19+
"currentGasLimit": "0x05f5e100",
20+
"currentNumber": "0x01",
21+
"currentTimestamp": "0x03e8",
22+
"currentRandom": "0x0000000000000000000000000000000000000000000000000000000000000000",
23+
"currentDifficulty": "0x00",
24+
"currentBaseFee": "0x0a",
25+
"currentExcessBlobGas": "0x240000"
26+
},
27+
"pre": {
28+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
29+
"nonce": "0x00",
30+
"balance": "0x3635c9adc5dea00000",
31+
"code": "0x",
32+
"storage": {}
33+
},
34+
"0x1000000000000000000000000000000000000000": {
35+
"nonce": "0x00",
36+
"balance": "0x00",
37+
"code": "0x4a600055",
38+
"storage": {}
39+
}
40+
},
41+
"transaction": {
42+
"nonce": "0x00",
43+
"gasPrice": "0x0a",
44+
"gasLimit": [
45+
"0x030d40"
46+
],
47+
"to": "0x1000000000000000000000000000000000000000",
48+
"value": [
49+
"0x00"
50+
],
51+
"data": [
52+
"0x"
53+
],
54+
"sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
55+
"secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
56+
},
57+
"post": {
58+
"Cancun": [
59+
{
60+
"hash": "0x4f0dafcdc942cf538ffe1f870ab031c2761857b3066f595e56c74bcb222eb0bb",
61+
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
62+
"indexes": {
63+
"data": 0,
64+
"gas": 0,
65+
"value": 0
66+
}
67+
}
68+
]
69+
}
70+
}
71+
},
72+
"stdout": [
73+
{"pc":0,"op":"0x4a","gas":179000,"gasCost":2,"memSize":0,"stack":[],"depth":1,"refund":0,"opName":"BLOBBASEFEE"},
74+
{"pc":1,"op":"0x60","gas":178998,"gasCost":3,"memSize":0,"stack":["0x2"],"depth":1,"refund":0,"opName":"PUSH1"},
75+
{"pc":3,"op":"0x55","gas":178995,"gasCost":22100,"memSize":0,"stack":["0x2","0x0"],"depth":1,"refund":0,"opName":"SSTORE"},
76+
{"output":"","gasUsed":43105,"test":"excessBlobGasTest","fork":"Cancun","d":0,"g":0,"v":0,"stateRoot":"0x4f0dafcdc942cf538ffe1f870ab031c2761857b3066f595e56c74bcb222eb0bb","postLogsHash":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","pass":true}
77+
]
78+
}

0 commit comments

Comments
 (0)