mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
core: apply change
This commit is contained in:
parent
0c92e31779
commit
c5e22b6124
3 changed files with 21 additions and 16 deletions
|
|
@ -17,7 +17,6 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -192,15 +191,22 @@ func TestEIP2780NewAccountFunded(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestEIP2780InsufficientGasForCallCharge verifies that a value transfer
|
// TestEIP2780InsufficientGasForCallCharge verifies that a value transfer
|
||||||
// creating a new account is rejected when the gas limit only covers the 21,000
|
// creating a new account, whose gas limit only covers the 21,000 intrinsic base
|
||||||
// intrinsic base and not the additional new-account state gas charged before the
|
// and not the additional new-account state gas charged before the call executes,
|
||||||
// call executes.
|
// halts out of gas. The transaction stays valid (no consensus error) but
|
||||||
|
// execution fails and the recipient is not created.
|
||||||
func TestEIP2780InsufficientGasForCallCharge(t *testing.T) {
|
func TestEIP2780InsufficientGasForCallCharge(t *testing.T) {
|
||||||
fresh := common.HexToAddress("0xbeef000000000000000000000000000000000003")
|
fresh := common.HexToAddress("0xbeef000000000000000000000000000000000003")
|
||||||
sdb := mkState(senderAlloc(nil))
|
sdb := mkState(senderAlloc(nil))
|
||||||
_, _, err := applyMsg(t, sdb, callTx(0, fresh, 1, 21_000, nil))
|
res, _, err := applyMsg(t, sdb, callTx(0, fresh, 1, 21_000, nil))
|
||||||
if !errors.Is(err, ErrEIP2780CallRecipientCharge) {
|
if err != nil {
|
||||||
t.Fatalf("expected ErrEIP2780CallRecipientCharge, got %v", err)
|
t.Fatalf("transaction should remain valid: %v", err)
|
||||||
|
}
|
||||||
|
if res.Err != vm.ErrOutOfGas {
|
||||||
|
t.Fatalf("expected out of gas, got %v", res.Err)
|
||||||
|
}
|
||||||
|
if res.UsedGas != 21_000 {
|
||||||
|
t.Fatalf("expected used gas, got %v", res.UsedGas)
|
||||||
}
|
}
|
||||||
if sdb.Exist(fresh) {
|
if sdb.Exist(fresh) {
|
||||||
t.Fatal("recipient should not be created when the call charge cannot be paid")
|
t.Fatal("recipient should not be created when the call charge cannot be paid")
|
||||||
|
|
|
||||||
|
|
@ -81,10 +81,6 @@ var (
|
||||||
// than required for the data floor cost.
|
// than required for the data floor cost.
|
||||||
ErrFloorDataGas = errors.New("insufficient gas for floor data gas cost")
|
ErrFloorDataGas = errors.New("insufficient gas for floor data gas cost")
|
||||||
|
|
||||||
// ErrEIP2780CallRecipientCharge is returned if the transaction doesn't have
|
|
||||||
// sufficient gas to cover the cost of EIP-2780 call charge.
|
|
||||||
ErrEIP2780CallRecipientCharge = errors.New("insufficient gas for EIP-2780 call recipient charge")
|
|
||||||
|
|
||||||
// ErrTxTypeNotSupported is returned if a transaction is not supported in the
|
// ErrTxTypeNotSupported is returned if a transaction is not supported in the
|
||||||
// current network configuration.
|
// current network configuration.
|
||||||
ErrTxTypeNotSupported = types.ErrTxTypeNotSupported
|
ErrTxTypeNotSupported = types.ErrTxTypeNotSupported
|
||||||
|
|
|
||||||
|
|
@ -746,13 +746,16 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
|
||||||
if addr, ok := types.ParseDelegation(st.state.GetCode(*msg.To)); ok {
|
if addr, ok := types.ParseDelegation(st.state.GetCode(*msg.To)); ok {
|
||||||
st.state.AddAddressToAccessList(addr)
|
st.state.AddAddressToAccessList(addr)
|
||||||
}
|
}
|
||||||
// EIP-2780: charge the transaction's top-level recipient costs.
|
// EIP-2780: charge the transaction's top-level recipient costs. If the
|
||||||
|
// budget cannot cover the charge, the top frame halts out of gas.
|
||||||
if rules.IsAmsterdam && !st.chargeCallRecipientEIP2780(value) {
|
if rules.IsAmsterdam && !st.chargeCallRecipientEIP2780(value) {
|
||||||
return nil, fmt.Errorf("%w: address %v", ErrEIP2780CallRecipientCharge, msg.To.Hex())
|
vmerr = vm.ErrOutOfGas
|
||||||
|
st.gasRemaining = st.gasRemaining.ExitHalt()
|
||||||
|
} else {
|
||||||
|
// Execute the transaction's call.
|
||||||
|
ret, result, vmerr = st.evm.Call(msg.From, st.to(), msg.Data, st.gasRemaining.ForwardAll(), value)
|
||||||
|
st.gasRemaining.Absorb(result)
|
||||||
}
|
}
|
||||||
// Execute the transaction's call.
|
|
||||||
ret, result, vmerr = st.evm.Call(msg.From, st.to(), msg.Data, st.gasRemaining.ForwardAll(), value)
|
|
||||||
st.gasRemaining.Absorb(result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EIP-8037 (fork.py:1086): on any transaction error, the state gas
|
// EIP-8037 (fork.py:1086): on any transaction error, the state gas
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue