Skip to content
This repository has been archived by the owner on Feb 18, 2025. It is now read-only.

eth/tracers: fix system transaction and prestate tracer after Venoki #565

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,10 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
// 6. caller has enough balance to cover asset transfer for **topmost** call

// Check clauses 1-3, buy gas if everything is correct
if err := st.preCheck(); err != nil {
return nil, err
if !st.evm.Config.IsSystemTransaction {
if err := st.preCheck(); err != nil {
return nil, err
}
}

if tracer := st.evm.Config.Tracer; tracer != nil {
Expand Down
16 changes: 16 additions & 0 deletions eth/tracers/native/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/params"
)

//go:generate go run github.com/fjl/gencodec -type account -field-override accountMarshaling -out gen_account_json.go
Expand Down Expand Up @@ -101,6 +102,10 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
t.lookupAccount(from)
t.lookupAccount(to)
t.lookupAccount(env.Context.Coinbase)
treasury := env.ChainConfig().RoninTreasuryAddress
if treasury != nil {
t.lookupAccount(*treasury)
}

// The recipient balance includes the value transferred.
toBal := new(big.Int).Sub(t.pre[to].Balance, value)
Expand All @@ -117,6 +122,17 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
} else {
diffFromBal.Add(diffFromBal, consumedGas)
}
// At this time, the blob fee is already subtracted from sender and added to treasury.
// So we need to add blob fee back to sender and subtract from treasury to get the correct
// pre-tx balance.
if len(env.BlobHashes) > 0 {
blobFee := new(big.Int).Mul(big.NewInt(int64(len(env.BlobHashes)*params.BlobTxBlobGasPerBlob)), env.Context.BlobBaseFee)
diffFromBal.Add(diffFromBal, blobFee)
if treasury != nil {
t.pre[*treasury].Balance = new(big.Int).Sub(t.pre[*treasury].Balance, blobFee)
}
}

fromBal.Add(fromBal, diffFromBal)
t.pre[from].Balance = fromBal
t.pre[from].Nonce--
Expand Down
Loading