core: fix 7778 logic

This commit is contained in:
MariusVanDerWijden 2026-02-03 08:15:18 +01:00
parent 7869c18c0a
commit ce8f1bd856
2 changed files with 19 additions and 16 deletions

View file

@ -61,7 +61,8 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
var ( var (
config = p.chainConfig() config = p.chainConfig()
receipts types.Receipts receipts types.Receipts
usedGas = new(uint64) chargedGas = new(uint64)
usedGas = uint64(0)
header = block.Header() header = block.Header()
blockHash = block.Hash() blockHash = block.Hash()
blockNumber = block.Number() blockNumber = block.Number()
@ -102,10 +103,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
} }
statedb.SetTxContext(tx.Hash(), i) statedb.SetTxContext(tx.Hash(), i)
receipt, err := ApplyTransactionWithEVM(msg, gp, statedb, blockNumber, blockHash, context.Time, tx, usedGas, evm) receipt, err := ApplyTransactionWithEVM(msg, gp, statedb, blockNumber, blockHash, context.Time, tx, chargedGas, evm)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
} }
usedGas += receipt.GasUsed
receipts = append(receipts, receipt) receipts = append(receipts, receipt)
allLogs = append(allLogs, receipt.Logs...) allLogs = append(allLogs, receipt.Logs...)
} }
@ -134,7 +136,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
Receipts: receipts, Receipts: receipts,
Requests: requests, Requests: requests,
Logs: allLogs, Logs: allLogs,
GasUsed: *usedGas, GasUsed: usedGas,
}, nil }, nil
} }
@ -183,7 +185,11 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b
receipt.Status = types.ReceiptStatusSuccessful receipt.Status = types.ReceiptStatusSuccessful
} }
receipt.TxHash = tx.Hash() receipt.TxHash = tx.Hash()
receipt.GasUsed = result.UsedGas if evm.ChainConfig().IsAmsterdam(blockNumber, blockTime) {
receipt.GasUsed = result.MaxUsedGas
} else {
receipt.GasUsed = result.UsedGas
}
if tx.Type() == types.BlobTxType { if tx.Type() == types.BlobTxType {
receipt.BlobGasUsed = uint64(len(tx.BlobHashes()) * params.BlobTxBlobGasPerBlob) receipt.BlobGasUsed = uint64(len(tx.BlobHashes()) * params.BlobTxBlobGasPerBlob)

View file

@ -528,7 +528,6 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
peakGasUsed := st.gasUsed() peakGasUsed := st.gasUsed()
// Compute refund counter, capped to a refund quotient. // Compute refund counter, capped to a refund quotient.
gasBeforeRefunds := peakGasUsed
st.gasRemaining += st.calcRefund() st.gasRemaining += st.calcRefund()
if rules.IsPrague { if rules.IsPrague {
// After EIP-7623: Data-heavy transactions pay the floor gas. // After EIP-7623: Data-heavy transactions pay the floor gas.
@ -543,7 +542,14 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
peakGasUsed = floorDataGas peakGasUsed = floorDataGas
} }
} }
st.returnGas(rules, gasBeforeRefunds) // Return gas to the user
st.returnGas()
// Return gas to the gas pool
if rules.IsAmsterdam {
st.gp.AddGas(st.initialGas - peakGasUsed)
} else {
st.gp.AddGas(st.gasRemaining)
}
effectiveTip := msg.GasPrice effectiveTip := msg.GasPrice
if rules.IsLondon { if rules.IsLondon {
@ -653,7 +659,7 @@ func (st *stateTransition) calcRefund() uint64 {
// returnGas returns ETH for remaining gas, // returnGas returns ETH for remaining gas,
// exchanged at the original rate. // exchanged at the original rate.
func (st *stateTransition) returnGas(rules params.Rules, gasBeforeRefunds uint64) { func (st *stateTransition) returnGas() {
remaining := uint256.NewInt(st.gasRemaining) remaining := uint256.NewInt(st.gasRemaining)
remaining.Mul(remaining, uint256.MustFromBig(st.msg.GasPrice)) remaining.Mul(remaining, uint256.MustFromBig(st.msg.GasPrice))
st.state.AddBalance(st.msg.From, remaining, tracing.BalanceIncreaseGasReturn) st.state.AddBalance(st.msg.From, remaining, tracing.BalanceIncreaseGasReturn)
@ -661,15 +667,6 @@ func (st *stateTransition) returnGas(rules params.Rules, gasBeforeRefunds uint64
if st.evm.Config.Tracer != nil && st.evm.Config.Tracer.OnGasChange != nil && st.gasRemaining > 0 { if st.evm.Config.Tracer != nil && st.evm.Config.Tracer.OnGasChange != nil && st.gasRemaining > 0 {
st.evm.Config.Tracer.OnGasChange(st.gasRemaining, 0, tracing.GasChangeTxLeftOverReturned) st.evm.Config.Tracer.OnGasChange(st.gasRemaining, 0, tracing.GasChangeTxLeftOverReturned)
} }
if !rules.IsAmsterdam {
// Pre-Amsterdam return remaining gas to the block gas counter so it is
// available for the next transaction.
st.gp.AddGas(st.gasRemaining)
} else {
// Post-Amsterdam only return the remaining gas minus the refunds.
st.gp.AddGas(gasBeforeRefunds)
}
} }
// gasUsed returns the amount of gas used up by the state transition. // gasUsed returns the amount of gas used up by the state transition.