Skip to content

Commit aad1ca9

Browse files
jsvisajorgemmsilva
authored andcommitted
eth/tracers: prestate tracer add blob fee (ethereum#29168)
* eth/tracers: prestate balance add blob fee Signed-off-by: jsvisa <[email protected]> * eth/tracers: prestate test support blob tx Signed-off-by: jsvisa <[email protected]> * eth/tracers: add prestate blob tx test Signed-off-by: jsvisa <[email protected]> --------- Signed-off-by: jsvisa <[email protected]>
1 parent 63b53f9 commit aad1ca9

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

eth/tracers/internal/tracetest/prestate_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"testing"
2626

2727
"github.com/ethereum/go-ethereum/common"
28+
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
2829
"github.com/ethereum/go-ethereum/core"
2930
"github.com/ethereum/go-ethereum/core/rawdb"
3031
"github.com/ethereum/go-ethereum/core/types"
@@ -107,6 +108,11 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
107108
)
108109
defer state.Close()
109110

111+
if test.Genesis.ExcessBlobGas != nil && test.Genesis.BlobGasUsed != nil {
112+
excessBlobGas := eip4844.CalcExcessBlobGas(*test.Genesis.ExcessBlobGas, *test.Genesis.BlobGasUsed)
113+
context.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas)
114+
}
115+
110116
tracer, err := tracers.DefaultDirectory.New(tracerName, new(tracers.Context), test.TracerConfig)
111117
if err != nil {
112118
t.Fatalf("failed to create call tracer: %v", err)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"genesis": {
3+
"baseFeePerGas": "7",
4+
"blobGasUsed": "0",
5+
"difficulty": "0",
6+
"excessBlobGas": "36306944",
7+
"extraData": "0xd983010e00846765746888676f312e32312e308664617277696e",
8+
"gasLimit": "15639172",
9+
"hash": "0xc682259fda061bb9ce8ccb491d5b2d436cb73daf04e1025dd116d045ce4ad28c",
10+
"miner": "0x0000000000000000000000000000000000000000",
11+
"mixHash": "0xae1a5ba939a4c9ac38aabeff361169fb55a6fc2c9511457e0be6eff9514faec0",
12+
"nonce": "0x0000000000000000",
13+
"number": "315",
14+
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
15+
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
16+
"timestamp": "1709626771",
17+
"totalDifficulty": "1",
18+
"withdrawals": [],
19+
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
20+
"alloc": {
21+
"0x0000000000000000000000000000000000000000": {
22+
"balance": "0x272e0528"
23+
},
24+
"0x0c2c51a0990aee1d73c1228de158688341557508": {
25+
"balance": "0xde0b6b3a7640000"
26+
}
27+
},
28+
"config": {
29+
"chainId": 1337,
30+
"homesteadBlock": 0,
31+
"eip150Block": 0,
32+
"eip155Block": 0,
33+
"eip158Block": 0,
34+
"byzantiumBlock": 0,
35+
"constantinopleBlock": 0,
36+
"petersburgBlock": 0,
37+
"istanbulBlock": 0,
38+
"muirGlacierBlock": 0,
39+
"berlinBlock": 0,
40+
"londonBlock": 0,
41+
"arrowGlacierBlock": 0,
42+
"grayGlacierBlock": 0,
43+
"shanghaiTime": 0,
44+
"cancunTime": 0,
45+
"terminalTotalDifficulty": 0,
46+
"terminalTotalDifficultyPassed": true
47+
}
48+
},
49+
"context": {
50+
"number": "316",
51+
"difficulty": "0",
52+
"timestamp": "1709626785",
53+
"gasLimit": "15654443",
54+
"miner": "0x0000000000000000000000000000000000000000"
55+
},
56+
"input": "0x03f8b1820539806485174876e800825208940c2c51a0990aee1d73c1228de1586883415575088080c083020000f842a00100c9fbdf97f747e85847b4f3fff408f89c26842f77c882858bf2c89923849aa00138e3896f3c27f2389147507f8bcec52028b0efca6ee842ed83c9158873943880a0dbac3f97a532c9b00e6239b29036245a5bfbb96940b9d848634661abee98b945a03eec8525f261c2e79798f7b45a5d6ccaefa24576d53ba5023e919b86841c0675",
57+
"result": {
58+
"0x0000000000000000000000000000000000000000": { "balance": "0x272e0528" },
59+
"0x0c2c51a0990aee1d73c1228de158688341557508": {
60+
"balance": "0xde0b6b3a7640000"
61+
}
62+
}
63+
}

eth/tracers/native/prestate.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/ethereum/go-ethereum/crypto"
2929
"github.com/ethereum/go-ethereum/eth/tracers"
3030
"github.com/ethereum/go-ethereum/log"
31+
"github.com/ethereum/go-ethereum/params"
3132
)
3233

3334
//go:generate go run github.com/fjl/gencodec -type account -field-override accountMarshaling -out gen_account_json.go
@@ -112,6 +113,12 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
112113
gasPrice := env.TxContext.GasPrice
113114
consumedGas := new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(t.gasLimit))
114115
fromBal.Add(fromBal, new(big.Int).Add(value, consumedGas))
116+
117+
// Add blob fee to the sender's balance.
118+
if env.Context.BlobBaseFee != nil && len(env.TxContext.BlobHashes) > 0 {
119+
blobGas := uint64(params.BlobTxBlobGasPerBlob * len(env.TxContext.BlobHashes))
120+
fromBal.Add(fromBal, new(big.Int).Mul(env.Context.BlobBaseFee, new(big.Int).SetUint64(blobGas)))
121+
}
115122
t.pre[from].Balance = fromBal
116123
t.pre[from].Nonce--
117124

0 commit comments

Comments
 (0)