core: improve checks for 7702

- prevent SetCodeTx in create mode (similar to blob tx)
- move check for non-empty auth list to preCheck
This commit is contained in:
Felix Lange 2024-12-02 13:45:35 +01:00 committed by lightclient
parent 33888a9e6b
commit e7c0f80e4f
No known key found for this signature in database
GPG key ID: 75C916AFEE20183E
2 changed files with 18 additions and 17 deletions

View file

@ -117,12 +117,10 @@ var (
// -- EIP-7702 errors --
// ErrEmptyAuthList is returned if a set code transaction has an empty auth list.
ErrEmptyAuthList = errors.New("set code transaction with empty auth list")
// ErrAuthSignatureVeryHigh is returned if a set code transaction has a
// signature with R or S larger than 2^256-1.
ErrAuthSignatureVeryHigh = errors.New("set code transaction has authorization with R or S value greater than 2^256 - 1")
// Message validation errors:
ErrEmptyAuthList = errors.New("EIP-7702 transaction with empty auth list")
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:
ErrAuthorizationWrongChainID = errors.New("EIP-7702 authorization chain ID mismatch")

View file

@ -372,12 +372,20 @@ func (st *stateTransition) preCheck() error {
}
}
// Check that EIP-7702 authorization list signatures are well formed.
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)
if msg.AuthList != nil {
if msg.To == nil {
return fmt.Errorf("%w (sender %v)", ErrSetCodeTxCreate, msg.From)
}
if len(msg.AuthList) == 0 {
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()
@ -451,11 +459,6 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
return nil, fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(msg.Data), params.MaxInitCodeSize)
}
// If an authorization list exists, verify it is not empty.
if msg.AuthList != nil && len(msg.AuthList) == 0 {
return nil, fmt.Errorf("%w: address %v", ErrEmptyAuthList, msg.From.Hex())
}
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
// - reset transient storage(eip 1153)