|
|
|
@ -21,10 +21,10 @@ import ( |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil" |
|
|
|
|
"github.com/ethereum/go-ethereum/common/math" |
|
|
|
|
"github.com/ethereum/go-ethereum/core" |
|
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
|
|
"github.com/ethereum/go-ethereum/params" |
|
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// TransactionTest checks RLP decoding and sender derivation of transactions.
|
|
|
|
@ -34,80 +34,157 @@ type TransactionTest struct { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type ttResult struct { |
|
|
|
|
Byzantium ttFork |
|
|
|
|
Constantinople ttFork |
|
|
|
|
Istanbul ttFork |
|
|
|
|
EIP150 ttFork |
|
|
|
|
EIP158 ttFork |
|
|
|
|
Frontier ttFork |
|
|
|
|
Homestead ttFork |
|
|
|
|
Prague *ttFork |
|
|
|
|
Cancun *ttFork |
|
|
|
|
Shanghai *ttFork |
|
|
|
|
Paris *ttFork |
|
|
|
|
London *ttFork |
|
|
|
|
Berlin *ttFork |
|
|
|
|
Byzantium *ttFork |
|
|
|
|
Constantinople *ttFork |
|
|
|
|
Istanbul *ttFork |
|
|
|
|
EIP150 *ttFork |
|
|
|
|
EIP158 *ttFork |
|
|
|
|
Frontier *ttFork |
|
|
|
|
Homestead *ttFork |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type ttFork struct { |
|
|
|
|
Sender common.UnprefixedAddress `json:"sender"` |
|
|
|
|
Hash common.UnprefixedHash `json:"hash"` |
|
|
|
|
Sender *common.UnprefixedAddress `json:"sender"` |
|
|
|
|
Hash *common.UnprefixedHash `json:"hash"` |
|
|
|
|
Exception *string `json:"exception"` |
|
|
|
|
IntrinsicGas math.HexOrDecimal64 `json:"intrinsicGas"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (tt *TransactionTest) validate() error { |
|
|
|
|
if tt.Txbytes == nil { |
|
|
|
|
return fmt.Errorf("missing txbytes") |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.Prague); err != nil { |
|
|
|
|
return fmt.Errorf("invalid Prague: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.Cancun); err != nil { |
|
|
|
|
return fmt.Errorf("invalid Cancun: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.Shanghai); err != nil { |
|
|
|
|
return fmt.Errorf("invalid Shanghai: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.Paris); err != nil { |
|
|
|
|
return fmt.Errorf("invalid Paris: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.London); err != nil { |
|
|
|
|
return fmt.Errorf("invalid London: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.Berlin); err != nil { |
|
|
|
|
return fmt.Errorf("invalid Berlin: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.Byzantium); err != nil { |
|
|
|
|
return fmt.Errorf("invalid Byzantium: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.Constantinople); err != nil { |
|
|
|
|
return fmt.Errorf("invalid Constantinople: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.Istanbul); err != nil { |
|
|
|
|
return fmt.Errorf("invalid Istanbul: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.EIP150); err != nil { |
|
|
|
|
return fmt.Errorf("invalid EIP150: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.EIP158); err != nil { |
|
|
|
|
return fmt.Errorf("invalid EIP158: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.Frontier); err != nil { |
|
|
|
|
return fmt.Errorf("invalid Frontier: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := tt.validateFork(tt.Result.Homestead); err != nil { |
|
|
|
|
return fmt.Errorf("invalid Homestead: %v", err) |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (tt *TransactionTest) validateFork(fork *ttFork) error { |
|
|
|
|
if fork == nil { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
if fork.Hash == nil && fork.Exception == nil { |
|
|
|
|
return fmt.Errorf("missing hash and exception") |
|
|
|
|
} |
|
|
|
|
if fork.Hash != nil && fork.Sender == nil { |
|
|
|
|
return fmt.Errorf("missing sender") |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (tt *TransactionTest) Run(config *params.ChainConfig) error { |
|
|
|
|
validateTx := func(rlpData hexutil.Bytes, signer types.Signer, isHomestead bool, isIstanbul bool) (*common.Address, *common.Hash, error) { |
|
|
|
|
if err := tt.validate(); err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
validateTx := func(rlpData hexutil.Bytes, signer types.Signer, isHomestead, isIstanbul, isShanghai bool) (sender common.Address, hash common.Hash, requiredGas uint64, err error) { |
|
|
|
|
tx := new(types.Transaction) |
|
|
|
|
if err := rlp.DecodeBytes(rlpData, tx); err != nil { |
|
|
|
|
return nil, nil, err |
|
|
|
|
if err = tx.UnmarshalBinary(rlpData); err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
sender, err := types.Sender(signer, tx) |
|
|
|
|
sender, err = types.Sender(signer, tx) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, nil, err |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
// Intrinsic gas
|
|
|
|
|
requiredGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, isHomestead, isIstanbul, false) |
|
|
|
|
requiredGas, err = core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, isHomestead, isIstanbul, isShanghai) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, nil, err |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if requiredGas > tx.Gas() { |
|
|
|
|
return nil, nil, fmt.Errorf("insufficient gas ( %d < %d )", tx.Gas(), requiredGas) |
|
|
|
|
return sender, hash, 0, fmt.Errorf("insufficient gas ( %d < %d )", tx.Gas(), requiredGas) |
|
|
|
|
} |
|
|
|
|
h := tx.Hash() |
|
|
|
|
return &sender, &h, nil |
|
|
|
|
hash = tx.Hash() |
|
|
|
|
return sender, hash, requiredGas, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, testcase := range []struct { |
|
|
|
|
name string |
|
|
|
|
signer types.Signer |
|
|
|
|
fork ttFork |
|
|
|
|
fork *ttFork |
|
|
|
|
isHomestead bool |
|
|
|
|
isIstanbul bool |
|
|
|
|
isShanghai bool |
|
|
|
|
}{ |
|
|
|
|
{"Frontier", types.FrontierSigner{}, tt.Result.Frontier, false, false}, |
|
|
|
|
{"Homestead", types.HomesteadSigner{}, tt.Result.Homestead, true, false}, |
|
|
|
|
{"EIP150", types.HomesteadSigner{}, tt.Result.EIP150, true, false}, |
|
|
|
|
{"EIP158", types.NewEIP155Signer(config.ChainID), tt.Result.EIP158, true, false}, |
|
|
|
|
{"Byzantium", types.NewEIP155Signer(config.ChainID), tt.Result.Byzantium, true, false}, |
|
|
|
|
{"Constantinople", types.NewEIP155Signer(config.ChainID), tt.Result.Constantinople, true, false}, |
|
|
|
|
{"Istanbul", types.NewEIP155Signer(config.ChainID), tt.Result.Istanbul, true, true}, |
|
|
|
|
{"Frontier", types.FrontierSigner{}, tt.Result.Frontier, false, false, false}, |
|
|
|
|
{"Homestead", types.HomesteadSigner{}, tt.Result.Homestead, true, false, false}, |
|
|
|
|
{"EIP150", types.HomesteadSigner{}, tt.Result.EIP150, true, false, false}, |
|
|
|
|
{"EIP158", types.NewEIP155Signer(config.ChainID), tt.Result.EIP158, true, false, false}, |
|
|
|
|
{"Byzantium", types.NewEIP155Signer(config.ChainID), tt.Result.Byzantium, true, false, false}, |
|
|
|
|
{"Constantinople", types.NewEIP155Signer(config.ChainID), tt.Result.Constantinople, true, false, false}, |
|
|
|
|
{"Istanbul", types.NewEIP155Signer(config.ChainID), tt.Result.Istanbul, true, true, false}, |
|
|
|
|
{"Berlin", types.NewEIP2930Signer(config.ChainID), tt.Result.Berlin, true, true, false}, |
|
|
|
|
{"London", types.NewLondonSigner(config.ChainID), tt.Result.London, true, true, false}, |
|
|
|
|
{"Paris", types.NewLondonSigner(config.ChainID), tt.Result.Paris, true, true, false}, |
|
|
|
|
{"Shanghai", types.NewLondonSigner(config.ChainID), tt.Result.Shanghai, true, true, true}, |
|
|
|
|
{"Cancun", types.NewCancunSigner(config.ChainID), tt.Result.Cancun, true, true, true}, |
|
|
|
|
{"Prague", types.NewPragueSigner(config.ChainID), tt.Result.Prague, true, true, true}, |
|
|
|
|
} { |
|
|
|
|
sender, txhash, err := validateTx(tt.Txbytes, testcase.signer, testcase.isHomestead, testcase.isIstanbul) |
|
|
|
|
|
|
|
|
|
if testcase.fork.Sender == (common.UnprefixedAddress{}) { |
|
|
|
|
if err == nil { |
|
|
|
|
return fmt.Errorf("expected error, got none (address %v)[%v]", sender.String(), testcase.name) |
|
|
|
|
} |
|
|
|
|
if testcase.fork == nil { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
// Should resolve the right address
|
|
|
|
|
sender, hash, gas, err := validateTx(tt.Txbytes, testcase.signer, testcase.isHomestead, testcase.isIstanbul, testcase.isShanghai) |
|
|
|
|
if err != nil { |
|
|
|
|
return fmt.Errorf("got error, expected none: %v", err) |
|
|
|
|
if testcase.fork.Hash != nil { |
|
|
|
|
return fmt.Errorf("unexpected error: %v", err) |
|
|
|
|
} |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
if testcase.fork.Exception != nil { |
|
|
|
|
return fmt.Errorf("expected error %v, got none (%v)", *testcase.fork.Exception, err) |
|
|
|
|
} |
|
|
|
|
if sender == nil { |
|
|
|
|
return fmt.Errorf("sender was nil, should be %x", common.Address(testcase.fork.Sender)) |
|
|
|
|
if common.Hash(*testcase.fork.Hash) != hash { |
|
|
|
|
return fmt.Errorf("hash mismatch: got %x, want %x", hash, common.Hash(*testcase.fork.Hash)) |
|
|
|
|
} |
|
|
|
|
if *sender != common.Address(testcase.fork.Sender) { |
|
|
|
|
if common.Address(*testcase.fork.Sender) != sender { |
|
|
|
|
return fmt.Errorf("sender mismatch: got %x, want %x", sender, testcase.fork.Sender) |
|
|
|
|
} |
|
|
|
|
if txhash == nil { |
|
|
|
|
return fmt.Errorf("txhash was nil, should be %x", common.Hash(testcase.fork.Hash)) |
|
|
|
|
if hash != common.Hash(*testcase.fork.Hash) { |
|
|
|
|
return fmt.Errorf("hash mismatch: got %x, want %x", hash, testcase.fork.Hash) |
|
|
|
|
} |
|
|
|
|
if *txhash != common.Hash(testcase.fork.Hash) { |
|
|
|
|
return fmt.Errorf("hash mismatch: got %x, want %x", *txhash, testcase.fork.Hash) |
|
|
|
|
if uint64(testcase.fork.IntrinsicGas) != gas { |
|
|
|
|
return fmt.Errorf("intrinsic gas mismatch: got %d, want %d", gas, uint64(testcase.fork.IntrinsicGas)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|