Skip to content

Commit d02c605

Browse files
core: only check sendernoeoa in non fake mode (#23424)
1 parent c368f72 commit d02c605

File tree

7 files changed

+21
-20
lines changed

7 files changed

+21
-20
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ type callMsg struct {
795795

796796
func (m callMsg) From() common.Address { return m.CallMsg.From }
797797
func (m callMsg) Nonce() uint64 { return 0 }
798-
func (m callMsg) CheckNonce() bool { return false }
798+
func (m callMsg) IsFake() bool { return true }
799799
func (m callMsg) To() *common.Address { return m.CallMsg.To }
800800
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
801801
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }

core/state_transition.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type Message interface {
7474
Value() *big.Int
7575

7676
Nonce() uint64
77-
CheckNonce() bool
77+
IsFake() bool
7878
Data() []byte
7979
AccessList() types.AccessList
8080
}
@@ -212,8 +212,9 @@ func (st *StateTransition) buyGas() error {
212212
}
213213

214214
func (st *StateTransition) preCheck() error {
215-
// Make sure this transaction's nonce is correct.
216-
if st.msg.CheckNonce() {
215+
// Only check transactions that are not fake
216+
if !st.msg.IsFake() {
217+
// Make sure this transaction's nonce is correct.
217218
stNonce := st.state.GetNonce(st.msg.From())
218219
if msgNonce := st.msg.Nonce(); stNonce < msgNonce {
219220
return fmt.Errorf("%w: address %v, tx: %d state: %d", ErrNonceTooHigh,
@@ -222,11 +223,11 @@ func (st *StateTransition) preCheck() error {
222223
return fmt.Errorf("%w: address %v, tx: %d state: %d", ErrNonceTooLow,
223224
st.msg.From().Hex(), msgNonce, stNonce)
224225
}
225-
}
226-
// Make sure the sender is an EOA
227-
if codeHash := st.state.GetCodeHash(st.msg.From()); codeHash != emptyCodeHash && codeHash != (common.Hash{}) {
228-
return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA,
229-
st.msg.From().Hex(), codeHash)
226+
// Make sure the sender is an EOA
227+
if codeHash := st.state.GetCodeHash(st.msg.From()); codeHash != emptyCodeHash && codeHash != (common.Hash{}) {
228+
return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA,
229+
st.msg.From().Hex(), codeHash)
230+
}
230231
}
231232
// Make sure that transaction gasFeeCap is greater than the baseFee (post london)
232233
if st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) {

core/types/transaction.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,10 @@ type Message struct {
579579
gasTipCap *big.Int
580580
data []byte
581581
accessList AccessList
582-
checkNonce bool
582+
isFake bool
583583
}
584584

585-
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, gasFeeCap, gasTipCap *big.Int, data []byte, accessList AccessList, checkNonce bool) Message {
585+
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, gasFeeCap, gasTipCap *big.Int, data []byte, accessList AccessList, isFake bool) Message {
586586
return Message{
587587
from: from,
588588
to: to,
@@ -594,7 +594,7 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
594594
gasTipCap: gasTipCap,
595595
data: data,
596596
accessList: accessList,
597-
checkNonce: checkNonce,
597+
isFake: isFake,
598598
}
599599
}
600600

@@ -610,7 +610,7 @@ func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int) (Message, error) {
610610
amount: tx.Value(),
611611
data: tx.Data(),
612612
accessList: tx.AccessList(),
613-
checkNonce: true,
613+
isFake: false,
614614
}
615615
// If baseFee provided, set gasPrice to effectiveGasPrice.
616616
if baseFee != nil {
@@ -631,4 +631,4 @@ func (m Message) Gas() uint64 { return m.gasLimit }
631631
func (m Message) Nonce() uint64 { return m.nonce }
632632
func (m Message) Data() []byte { return m.data }
633633
func (m Message) AccessList() AccessList { return m.accessList }
634-
func (m Message) CheckNonce() bool { return m.checkNonce }
634+
func (m Message) IsFake() bool { return m.isFake }

internal/ethapi/transaction_args.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
171171
return nil
172172
}
173173

174-
// ToMessage converts th transaction arguments to the Message type used by the
174+
// ToMessage converts the transaction arguments to the Message type used by the
175175
// core evm. This method is used in calls and traces that do not require a real
176176
// live transaction.
177177
func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (types.Message, error) {
@@ -238,7 +238,7 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
238238
if args.AccessList != nil {
239239
accessList = *args.AccessList
240240
}
241-
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, false)
241+
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, true)
242242
return msg, nil
243243
}
244244

les/odr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
135135
from := statedb.GetOrNewStateObject(bankAddr)
136136
from.SetBalance(math.MaxBig256)
137137

138-
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, false)}
138+
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, true)}
139139

140140
context := core.NewEVMBlockContext(header, bc, nil)
141141
txContext := core.NewEVMTxContext(msg)
@@ -150,7 +150,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
150150
header := lc.GetHeaderByHash(bhash)
151151
state := light.NewState(ctx, header, lc.Odr())
152152
state.SetBalance(bankAddr, math.MaxBig256)
153-
msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, false)}
153+
msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, true)}
154154
context := core.NewEVMBlockContext(header, lc, nil)
155155
txContext := core.NewEVMTxContext(msg)
156156
vmenv := vm.NewEVM(context, txContext, state, config, vm.Config{NoBaseFee: true})

light/odr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
194194

195195
// Perform read-only call.
196196
st.SetBalance(testBankAddress, math.MaxBig256)
197-
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, false)}
197+
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, true)}
198198
txContext := core.NewEVMTxContext(msg)
199199
context := core.NewEVMBlockContext(header, chain, nil)
200200
vmenv := vm.NewEVM(context, txContext, st, config, vm.Config{NoBaseFee: true})

tests/state_test_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (core.Messa
348348
}
349349

350350
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, gasPrice,
351-
tx.MaxFeePerGas, tx.MaxPriorityFeePerGas, data, accessList, true)
351+
tx.MaxFeePerGas, tx.MaxPriorityFeePerGas, data, accessList, false)
352352
return msg, nil
353353
}
354354

0 commit comments

Comments
 (0)