Skip to content

Commit 034f897

Browse files
holimanlightclient
authored andcommitted
core: mod errors + add test
1 parent aed705b commit 034f897

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

core/error.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ var (
118118
// -- EIP-7702 errors --
119119

120120
// Message validation errors:
121-
ErrEmptyAuthList = errors.New("EIP-7702 transaction with empty auth list")
122-
ErrSetCodeTxCreate = errors.New("EIP-7702 transaction cannot be used to create contract")
123-
ErrAuthSignatureVeryHigh = errors.New("EIP-7702 authorization with R or S value greater than 2^256 - 1")
121+
ErrEmptyAuthList = errors.New("EIP-7702 transaction with empty auth list")
122+
ErrSetCodeTxCreate = errors.New("EIP-7702 transaction cannot be used to create contract")
123+
)
124124

125-
// EIP-7702 state transition errors:
126-
// Note these are just informational, and do not cause tx execution abort.
125+
// EIP-7702 state transition errors.
126+
// Note these are just informational, and do not cause tx execution abort.
127+
var (
127128
ErrAuthorizationWrongChainID = errors.New("EIP-7702 authorization chain ID mismatch")
128129
ErrAuthorizationNonceOverflow = errors.New("EIP-7702 authorization nonce > 64 bit")
129130
ErrAuthorizationInvalidSignature = errors.New("EIP-7702 authorization has invalid signature")

core/state_processor_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func TestStateProcessorErrors(t *testing.T) {
6363
TerminalTotalDifficulty: big.NewInt(0),
6464
ShanghaiTime: new(uint64),
6565
CancunTime: new(uint64),
66+
PragueTime: new(uint64),
6667
}
6768
signer = types.LatestSigner(config)
6869
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
@@ -110,6 +111,21 @@ func TestStateProcessorErrors(t *testing.T) {
110111
}
111112
return tx
112113
}
114+
var mkSetCodeTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int, authlist []types.Authorization) *types.Transaction {
115+
tx, err := types.SignTx(types.NewTx(&types.SetCodeTx{
116+
Nonce: nonce,
117+
GasTipCap: uint256.MustFromBig(gasTipCap),
118+
GasFeeCap: uint256.MustFromBig(gasFeeCap),
119+
Gas: gasLimit,
120+
To: to,
121+
Value: new(uint256.Int),
122+
AuthList: authlist,
123+
}), signer, key1)
124+
if err != nil {
125+
t.Fatal(err)
126+
}
127+
return tx
128+
}
113129

114130
{ // Tests against a 'recent' chain definition
115131
var (
@@ -251,6 +267,13 @@ func TestStateProcessorErrors(t *testing.T) {
251267
},
252268
want: "could not apply tx 0 [0x6c11015985ce82db691d7b2d017acda296db88b811c3c60dc71449c76256c716]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 1, baseFee: 875000000",
253269
},
270+
{ // ErrEmptyAuthList
271+
txs: []*types.Transaction{
272+
mkSetCodeTx(0, common.Address{}, params.TxGas, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), nil),
273+
},
274+
want: "could not apply tx 0 [0xc18d10f4c809dbdfa1a074c3300de9bc4b7f16a20f0ec667f6f67312b71b956a]: EIP-7702 transaction with empty auth list (sender 0x71562b71999873DB5b286dF957af199Ec94617F7)",
275+
},
276+
// ErrSetCodeTxCreate cannot be tested: it is impossible to create a SetCode-tx with nil `to`.
254277
} {
255278
block := GenerateBadBlock(gspec.ToBlock(), beacon.New(ethash.NewFaker()), tt.txs, gspec.Config, false)
256279
_, err := blockchain.InsertChain(types.Blocks{block})

core/state_transition.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,6 @@ func (st *stateTransition) preCheck() error {
379379
if len(msg.AuthList) == 0 {
380380
return fmt.Errorf("%w (sender %v)", ErrEmptyAuthList, msg.From)
381381
}
382-
for i, auth := range msg.AuthList {
383-
switch {
384-
case auth.R.BitLen() > 256:
385-
return fmt.Errorf("%w: address %v, authorization %d", ErrAuthSignatureVeryHigh, msg.From.Hex(), i)
386-
case auth.S.BitLen() > 256:
387-
return fmt.Errorf("%w: address %v, authorization %d", ErrAuthSignatureVeryHigh, msg.From.Hex(), i)
388-
}
389-
}
390382
}
391383
return st.buyGas()
392384
}

0 commit comments

Comments
 (0)