mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
core: mod errors + add test
This commit is contained in:
parent
aed705b18a
commit
034f897b40
3 changed files with 29 additions and 13 deletions
|
|
@ -120,10 +120,11 @@ var (
|
||||||
// Message validation errors:
|
// Message validation errors:
|
||||||
ErrEmptyAuthList = errors.New("EIP-7702 transaction with empty auth list")
|
ErrEmptyAuthList = errors.New("EIP-7702 transaction with empty auth list")
|
||||||
ErrSetCodeTxCreate = errors.New("EIP-7702 transaction cannot be used to create contract")
|
ErrSetCodeTxCreate = errors.New("EIP-7702 transaction cannot be used to create contract")
|
||||||
ErrAuthSignatureVeryHigh = errors.New("EIP-7702 authorization with R or S value greater than 2^256 - 1")
|
)
|
||||||
|
|
||||||
// EIP-7702 state transition errors:
|
// EIP-7702 state transition errors.
|
||||||
// Note these are just informational, and do not cause tx execution abort.
|
// Note these are just informational, and do not cause tx execution abort.
|
||||||
|
var (
|
||||||
ErrAuthorizationWrongChainID = errors.New("EIP-7702 authorization chain ID mismatch")
|
ErrAuthorizationWrongChainID = errors.New("EIP-7702 authorization chain ID mismatch")
|
||||||
ErrAuthorizationNonceOverflow = errors.New("EIP-7702 authorization nonce > 64 bit")
|
ErrAuthorizationNonceOverflow = errors.New("EIP-7702 authorization nonce > 64 bit")
|
||||||
ErrAuthorizationInvalidSignature = errors.New("EIP-7702 authorization has invalid signature")
|
ErrAuthorizationInvalidSignature = errors.New("EIP-7702 authorization has invalid signature")
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ func TestStateProcessorErrors(t *testing.T) {
|
||||||
TerminalTotalDifficulty: big.NewInt(0),
|
TerminalTotalDifficulty: big.NewInt(0),
|
||||||
ShanghaiTime: new(uint64),
|
ShanghaiTime: new(uint64),
|
||||||
CancunTime: new(uint64),
|
CancunTime: new(uint64),
|
||||||
|
PragueTime: new(uint64),
|
||||||
}
|
}
|
||||||
signer = types.LatestSigner(config)
|
signer = types.LatestSigner(config)
|
||||||
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
|
|
@ -110,6 +111,21 @@ func TestStateProcessorErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
var mkSetCodeTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int, authlist []types.Authorization) *types.Transaction {
|
||||||
|
tx, err := types.SignTx(types.NewTx(&types.SetCodeTx{
|
||||||
|
Nonce: nonce,
|
||||||
|
GasTipCap: uint256.MustFromBig(gasTipCap),
|
||||||
|
GasFeeCap: uint256.MustFromBig(gasFeeCap),
|
||||||
|
Gas: gasLimit,
|
||||||
|
To: to,
|
||||||
|
Value: new(uint256.Int),
|
||||||
|
AuthList: authlist,
|
||||||
|
}), signer, key1)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
{ // Tests against a 'recent' chain definition
|
{ // Tests against a 'recent' chain definition
|
||||||
var (
|
var (
|
||||||
|
|
@ -251,6 +267,13 @@ func TestStateProcessorErrors(t *testing.T) {
|
||||||
},
|
},
|
||||||
want: "could not apply tx 0 [0x6c11015985ce82db691d7b2d017acda296db88b811c3c60dc71449c76256c716]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 1, baseFee: 875000000",
|
want: "could not apply tx 0 [0x6c11015985ce82db691d7b2d017acda296db88b811c3c60dc71449c76256c716]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 1, baseFee: 875000000",
|
||||||
},
|
},
|
||||||
|
{ // ErrEmptyAuthList
|
||||||
|
txs: []*types.Transaction{
|
||||||
|
mkSetCodeTx(0, common.Address{}, params.TxGas, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), nil),
|
||||||
|
},
|
||||||
|
want: "could not apply tx 0 [0xc18d10f4c809dbdfa1a074c3300de9bc4b7f16a20f0ec667f6f67312b71b956a]: EIP-7702 transaction with empty auth list (sender 0x71562b71999873DB5b286dF957af199Ec94617F7)",
|
||||||
|
},
|
||||||
|
// ErrSetCodeTxCreate cannot be tested: it is impossible to create a SetCode-tx with nil `to`.
|
||||||
} {
|
} {
|
||||||
block := GenerateBadBlock(gspec.ToBlock(), beacon.New(ethash.NewFaker()), tt.txs, gspec.Config, false)
|
block := GenerateBadBlock(gspec.ToBlock(), beacon.New(ethash.NewFaker()), tt.txs, gspec.Config, false)
|
||||||
_, err := blockchain.InsertChain(types.Blocks{block})
|
_, err := blockchain.InsertChain(types.Blocks{block})
|
||||||
|
|
|
||||||
|
|
@ -379,14 +379,6 @@ func (st *stateTransition) preCheck() error {
|
||||||
if len(msg.AuthList) == 0 {
|
if len(msg.AuthList) == 0 {
|
||||||
return fmt.Errorf("%w (sender %v)", ErrEmptyAuthList, msg.From)
|
return fmt.Errorf("%w (sender %v)", ErrEmptyAuthList, msg.From)
|
||||||
}
|
}
|
||||||
for i, auth := range msg.AuthList {
|
|
||||||
switch {
|
|
||||||
case auth.R.BitLen() > 256:
|
|
||||||
return fmt.Errorf("%w: address %v, authorization %d", ErrAuthSignatureVeryHigh, msg.From.Hex(), i)
|
|
||||||
case auth.S.BitLen() > 256:
|
|
||||||
return fmt.Errorf("%w: address %v, authorization %d", ErrAuthSignatureVeryHigh, msg.From.Hex(), i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return st.buyGas()
|
return st.buyGas()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue