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

Commit

Permalink
eth/tracers: fix system transaction and prestate tracer after Venoki (#…
Browse files Browse the repository at this point in the history
…565)

* core: skip gas check for system transaction when tracing

As system transaction has 0 gas price, it does not pass the check that gas price
must be greater or equal to base fee when base fee is not 0. Skip gas check for
system transaction in TransitionDb, system transaction will go through
TransitionDb only in tracing path not in normal transaction processing path.

* eth/tracers: fix balance tracking in prestate tracer after Venoki

Add ronin treasury to balance tracking after Venoki as base fee and blob fee are
transferred to it. The blob fee is subtracted from sender's balance added to
ronin treasury's balance in buyGas which is before the CaptureStart hook. So we
need to fix these balances up to get the correct balance before the transaction
happens.
  • Loading branch information
minh-bq committed Sep 16, 2024
1 parent 0515ce7 commit e5ba83c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit e5ba83c

Please # to comment.