core: only check sendernoeoa in non fake mode (#23424)

This commit is contained in:
Daniel Liu 2024-06-13 15:50:50 +08:00
parent e4895bf5c5
commit d850fc4081
8 changed files with 22 additions and 21 deletions

View file

@ -569,7 +569,7 @@ type callMsg struct {
func (m callMsg) From() common.Address { return m.CallMsg.From } func (m callMsg) From() common.Address { return m.CallMsg.From }
func (m callMsg) Nonce() uint64 { return 0 } func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) CheckNonce() bool { return false } func (m callMsg) IsFake() bool { return true }
func (m callMsg) To() *common.Address { return m.CallMsg.To } func (m callMsg) To() *common.Address { return m.CallMsg.To }
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice } func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap } func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }

View file

@ -83,7 +83,7 @@ type Message interface {
Value() *big.Int Value() *big.Int
Nonce() uint64 Nonce() uint64
CheckNonce() bool IsFake() bool
Data() []byte Data() []byte
BalanceTokenFee() *big.Int BalanceTokenFee() *big.Int
AccessList() types.AccessList AccessList() types.AccessList
@ -210,9 +210,10 @@ func (st *StateTransition) buyGas() error {
} }
func (st *StateTransition) preCheck() error { func (st *StateTransition) preCheck() error {
// Make sure this transaction's nonce is correct. // Only check transactions that are not fake
msg := st.msg msg := st.msg
if msg.CheckNonce() { if !msg.IsFake() {
// Make sure this transaction's nonce is correct.
stNonce := st.state.GetNonce(msg.From()) stNonce := st.state.GetNonce(msg.From())
if msgNonce := msg.Nonce(); stNonce < msgNonce { if msgNonce := msg.Nonce(); stNonce < msgNonce {
return fmt.Errorf("%w: address %v, tx: %d state: %d", ErrNonceTooHigh, return fmt.Errorf("%w: address %v, tx: %d state: %d", ErrNonceTooHigh,
@ -224,11 +225,11 @@ func (st *StateTransition) preCheck() error {
return fmt.Errorf("%w: address %v, nonce: %d", ErrNonceMax, return fmt.Errorf("%w: address %v, nonce: %d", ErrNonceMax,
msg.From().Hex(), stNonce) msg.From().Hex(), stNonce)
} }
}
// Make sure the sender is an EOA // Make sure the sender is an EOA
if codeHash := st.state.GetCodeHash(st.msg.From()); codeHash != emptyCodeHash && codeHash != (common.Hash{}) { if codeHash := st.state.GetCodeHash(msg.From()); codeHash != emptyCodeHash && codeHash != (common.Hash{}) {
return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA, return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA,
st.msg.From().Hex(), codeHash) msg.From().Hex(), codeHash)
}
} }
// Make sure that transaction gasFeeCap is greater than the baseFee (post london) // Make sure that transaction gasFeeCap is greater than the baseFee (post london)
if st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) { if st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) {

View file

@ -45,7 +45,7 @@ type callMsg struct {
func (m callMsg) From() common.Address { return m.CallMsg.From } func (m callMsg) From() common.Address { return m.CallMsg.From }
func (m callMsg) Nonce() uint64 { return 0 } func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) CheckNonce() bool { return false } func (m callMsg) IsFake() bool { return true }
func (m callMsg) To() *common.Address { return m.CallMsg.To } func (m callMsg) To() *common.Address { return m.CallMsg.To }
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice } func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap } func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }

View file

@ -433,7 +433,7 @@ func (tx *Transaction) AsMessage(s Signer, balanceFee, blockNumber, baseFee *big
amount: tx.Value(), amount: tx.Value(),
data: tx.Data(), data: tx.Data(),
accessList: tx.AccessList(), accessList: tx.AccessList(),
checkNonce: true, isFake: false,
balanceTokenFee: balanceFee, balanceTokenFee: balanceFee,
} }
@ -818,11 +818,11 @@ type Message struct {
gasTipCap *big.Int gasTipCap *big.Int
data []byte data []byte
accessList AccessList accessList AccessList
checkNonce bool isFake bool
balanceTokenFee *big.Int balanceTokenFee *big.Int
} }
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, balanceTokenFee *big.Int, number *big.Int) Message { 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, balanceTokenFee *big.Int, number *big.Int) Message {
if balanceTokenFee != nil { if balanceTokenFee != nil {
gasPrice = common.GetGasPrice(number) gasPrice = common.GetGasPrice(number)
} }
@ -837,7 +837,7 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
gasTipCap: gasTipCap, gasTipCap: gasTipCap,
data: data, data: data,
accessList: accessList, accessList: accessList,
checkNonce: checkNonce, isFake: isFake,
balanceTokenFee: balanceTokenFee, balanceTokenFee: balanceTokenFee,
} }
} }
@ -852,7 +852,7 @@ func (m Message) Value() *big.Int { return m.amount }
func (m Message) Gas() uint64 { return m.gasLimit } func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce } func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data } func (m Message) Data() []byte { return m.data }
func (m Message) CheckNonce() bool { return m.checkNonce } func (m Message) IsFake() bool { return m.isFake }
func (m Message) AccessList() AccessList { return m.accessList } func (m Message) AccessList() AccessList { return m.accessList }
func (m *Message) SetNonce(nonce uint64) { m.nonce = nonce } func (m *Message) SetNonce(nonce uint64) { m.nonce = nonce }

View file

@ -172,7 +172,7 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
return nil return nil
} }
// ToMessage converts th transaction arguments to the Message type used by the // ToMessage converts the transaction arguments to the Message type used by the
// core evm. This method is used in calls and traces that do not require a real // core evm. This method is used in calls and traces that do not require a real
// live transaction. // live transaction.
func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap uint64, baseFee *big.Int) (types.Message, error) { func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap uint64, baseFee *big.Int) (types.Message, error) {
@ -252,7 +252,7 @@ func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap
accessList = *args.AccessList accessList = *args.AccessList
} }
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, false, nil, number) msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, true, nil, number)
return msg, nil return msg, nil
} }

View file

@ -133,7 +133,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
if value, ok := feeCapacity[testContractAddr]; ok { if value, ok := feeCapacity[testContractAddr]; ok {
balanceTokenFee = value balanceTokenFee = value
} }
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, balanceTokenFee, header.Number)} 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, balanceTokenFee, header.Number)}
context := core.NewEVMBlockContext(header, bc, nil) context := core.NewEVMBlockContext(header, bc, nil)
txContext := core.NewEVMTxContext(msg) txContext := core.NewEVMTxContext(msg)
@ -154,7 +154,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
if value, ok := feeCapacity[testContractAddr]; ok { if value, ok := feeCapacity[testContractAddr]; ok {
balanceTokenFee = value balanceTokenFee = value
} }
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, false, balanceTokenFee, header.Number)} msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, true, balanceTokenFee, header.Number)}
context := core.NewEVMBlockContext(header, lc, nil) context := core.NewEVMBlockContext(header, lc, nil)
txContext := core.NewEVMTxContext(msg) txContext := core.NewEVMTxContext(msg)
vmenv := vm.NewEVM(context, txContext, statedb, nil, config, vm.Config{NoBaseFee: true}) vmenv := vm.NewEVM(context, txContext, statedb, nil, config, vm.Config{NoBaseFee: true})

View file

@ -185,7 +185,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
if value, ok := feeCapacity[testContractAddr]; ok { if value, ok := feeCapacity[testContractAddr]; ok {
balanceTokenFee = value balanceTokenFee = value
} }
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, balanceTokenFee, header.Number)} 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, balanceTokenFee, header.Number)}
txContext := core.NewEVMTxContext(msg) txContext := core.NewEVMTxContext(msg)
context := core.NewEVMBlockContext(header, chain, nil) context := core.NewEVMBlockContext(header, chain, nil)
vmenv := vm.NewEVM(context, txContext, st, nil, config, vm.Config{NoBaseFee: true}) vmenv := vm.NewEVM(context, txContext, st, nil, config, vm.Config{NoBaseFee: true})

View file

@ -282,7 +282,7 @@ func (tx *stTransaction) toMessage(ps stPostState, number *big.Int, baseFee *big
return nil, errors.New("no gas price provided") return nil, errors.New("no gas price provided")
} }
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, tx.MaxFeePerGas, tx.MaxPriorityFeePerGas, data, accessList, true, nil, number) msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, tx.MaxFeePerGas, tx.MaxPriorityFeePerGas, data, accessList, false, nil, number)
return msg, nil return msg, nil
} }