Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions core/hardcoded_tx_gas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package core

import (
"github.com/ethereum/go-ethereum/common"
)

// HardcodedTxGasUsed maps specific transaction hashes to the amount of GAS used by that
// specific transaction alone.
var HardcodedTxGasUsed = map[common.Hash]uint64{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have something in the name about it being a reverted transaction.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in ae8da64

common.HexToHash("0x58df300a7f04fe31d41d24672786cbe1c58b4f3d8329d0d74392d814dd9f7e40"): 45606,
}
18 changes: 17 additions & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,23 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
ret []byte
vmerr error // vm errors do not effect consensus and are therefore not assigned to err
)
if contractCreation {

// Check against hardcoded transaction hashes that has previously failed, so instead
// of executing the transaction we just update state nonce and remaining gas to avoid
// state divergence.
if l2GasUsed, ok := HardcodedTxGasUsed[msg.Tx.Hash()]; ok {
st.state.SetNonce(msg.From, st.state.GetNonce(msg.From)+1, tracing.NonceChangeEoACall)
// l2GasUsed contains params.TxGas which is why we need to first subtract params.TxGas
// from l2GasUsed. The new l2GasUsed is the same amount of gas consumed as if we were
// to execute this transaction via st.evm.Call()
l2GasUsed -= params.TxGas
st.gasRemaining -= l2GasUsed

// Update multigas and set vmerr to ErrExecutionReverted
multiGas = multigas.ComputationGas(l2GasUsed)
usedMultiGas = usedMultiGas.SaturatingAdd(multiGas)
vmerr = vm.ErrExecutionReverted
} else if contractCreation {
deployedContract = &common.Address{}
ret, *deployedContract, st.gasRemaining, multiGas, vmerr = st.evm.Create(msg.From, msg.Data, st.gasRemaining, value)
usedMultiGas = usedMultiGas.SaturatingAdd(multiGas)
Expand Down
Loading