Skip to content

Commit af84cf7

Browse files
committed
chore(all): remove vmerrs package
- Import errors from libevm/vmerrs - Define subnet-evm specific errors in plugin/evm/vmerrors See original PR ava-labs/coreth#829
1 parent 18c1ac7 commit af84cf7

File tree

24 files changed

+92
-134
lines changed

24 files changed

+92
-134
lines changed

accounts/abi/bind/precompilebind/precompile_contract_template.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ import (
3737
"github.com/ava-labs/subnet-evm/precompile/allowlist"
3838
{{- end}}
3939
"github.com/ava-labs/subnet-evm/precompile/contract"
40-
"github.com/ava-labs/subnet-evm/vmerrs"
4140
4241
_ "embed"
4342
4443
"github.com/ava-labs/libevm/common"
44+
"github.com/ava-labs/libevm/core/vm"
4545
)
4646
{{$contract := .Contract}}
4747
const (
@@ -67,7 +67,7 @@ var (
6767
_ = abi.JSON
6868
_ = errors.New
6969
_ = big.NewInt
70-
_ = vmerrs.ErrOutOfGas
70+
_ = vm.ErrOutOfGas
7171
_ = common.Big0
7272
)
7373
@@ -230,7 +230,7 @@ func {{decapitalise .Normalized.Name}}(accessibleState contract.AccessibleState,
230230
231231
{{- if not .Original.IsConstant}}
232232
if readOnly {
233-
return nil, remainingGas, vmerrs.ErrWriteProtection
233+
return nil, remainingGas, vm.ErrWriteProtection
234234
}
235235
{{- end}}
236236
@@ -294,7 +294,7 @@ func {{decapitalise $contract.Type}}Fallback (accessibleState contract.Accessibl
294294
}
295295
296296
if readOnly {
297-
return nil, remainingGas, vmerrs.ErrWriteProtection
297+
return nil, remainingGas, vm.ErrWriteProtection
298298
}
299299
300300
{{- if $contract.AllowList}}

accounts/abi/bind/precompilebind/precompile_contract_test_template.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import (
1919
"github.com/ava-labs/subnet-evm/precompile/allowlist"
2020
{{- end}}
2121
"github.com/ava-labs/subnet-evm/precompile/testutils"
22-
"github.com/ava-labs/subnet-evm/vmerrs"
2322
"github.com/ava-labs/libevm/common"
23+
"github.com/ava-labs/libevm/core/vm"
2424
"github.com/stretchr/testify/require"
2525
)
2626
2727
var (
28-
_ = vmerrs.ErrOutOfGas
28+
_ = vm.ErrOutOfGas
2929
_ = big.NewInt
3030
_ = common.Big0
3131
_ = require.New
@@ -121,7 +121,7 @@ var(
121121
},
122122
SuppliedGas: {{$func.Normalized.Name}}GasCost,
123123
ReadOnly: true,
124-
ExpectedErr: vmerrs.ErrWriteProtection.Error(),
124+
ExpectedErr: vm.ErrWriteProtection.Error(),
125125
},
126126
{{- end}}
127127
"insufficient gas for {{decapitalise $func.Normalized.Name}} should fail": {
@@ -147,7 +147,7 @@ var(
147147
},
148148
SuppliedGas: {{$func.Normalized.Name}}GasCost - 1,
149149
ReadOnly: false,
150-
ExpectedErr: vmerrs.ErrOutOfGas.Error(),
150+
ExpectedErr: vm.ErrOutOfGas.Error(),
151151
},
152152
{{- end}}
153153
{{- if .Contract.Fallback}}
@@ -156,14 +156,14 @@ var(
156156
Input: []byte{},
157157
SuppliedGas: {{.Contract.Type}}FallbackGasCost - 1,
158158
ReadOnly: false,
159-
ExpectedErr: vmerrs.ErrOutOfGas.Error(),
159+
ExpectedErr: vm.ErrOutOfGas.Error(),
160160
},
161161
"readOnly fallback should fail": {
162162
Caller: common.Address{1},
163163
Input: []byte{},
164164
SuppliedGas: {{.Contract.Type}}FallbackGasCost,
165165
ReadOnly: true,
166-
ExpectedErr: vmerrs.ErrWriteProtection.Error(),
166+
ExpectedErr: vm.ErrWriteProtection.Error(),
167167
},
168168
"fallback should succeed": {
169169
Caller: common.Address{1},

consensus/dummy/consensus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"github.com/ava-labs/subnet-evm/core/types"
1919
"github.com/ava-labs/subnet-evm/params"
2020
"github.com/ava-labs/subnet-evm/params/extras"
21+
"github.com/ava-labs/subnet-evm/plugin/evm/vmerrors"
2122
"github.com/ava-labs/subnet-evm/utils"
22-
"github.com/ava-labs/subnet-evm/vmerrs"
2323

2424
customheader "github.com/ava-labs/subnet-evm/plugin/evm/header"
2525
)
@@ -121,7 +121,7 @@ func (eng *DummyEngine) verifyCoinbase(header *types.Header, parent *types.Heade
121121
// we fetch the configured coinbase at the parent's state
122122
// to check against the coinbase in [header].
123123
if configuredAddressAtParent != header.Coinbase {
124-
return fmt.Errorf("%w: %v does not match required coinbase address %v", vmerrs.ErrInvalidCoinbase, header.Coinbase, configuredAddressAtParent)
124+
return fmt.Errorf("%w: %v does not match required coinbase address %v", vmerrors.ErrInvalidCoinbase, header.Coinbase, configuredAddressAtParent)
125125
}
126126
return nil
127127
}

core/state_processor_ext_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// (c) 2025, Ava Labs, Inc.
1+
// (c) 2025, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
23

34
package core
45

core/state_transition.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ import (
3737
"github.com/ava-labs/libevm/crypto/kzg4844"
3838
"github.com/ava-labs/subnet-evm/core/types"
3939
"github.com/ava-labs/subnet-evm/params"
40+
"github.com/ava-labs/subnet-evm/plugin/evm/vmerrors"
4041
"github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist"
4142
"github.com/ava-labs/subnet-evm/utils"
42-
"github.com/ava-labs/subnet-evm/vmerrs"
4343
"github.com/holiman/uint256"
4444
)
4545

@@ -73,7 +73,7 @@ func (result *ExecutionResult) Return() []byte {
7373
// Revert returns the concrete revert reason if the execution is aborted by `REVERT`
7474
// opcode. Note the reason can be nil if no data supplied with revert opcode.
7575
func (result *ExecutionResult) Revert() []byte {
76-
if result.Err != vmerrs.ErrExecutionReverted {
76+
if result.Err != vm.ErrExecutionReverted {
7777
return nil
7878
}
7979
return common.CopyBytes(result.ReturnData)
@@ -358,7 +358,7 @@ func (st *StateTransition) preCheck() error {
358358
if params.GetExtra(st.evm.ChainConfig()).IsPrecompileEnabled(txallowlist.ContractAddress, st.evm.Context.Time) {
359359
txAllowListRole := txallowlist.GetTxAllowListStatus(st.state, msg.From)
360360
if !txAllowListRole.IsEnabled() {
361-
return fmt.Errorf("%w: %s", vmerrs.ErrSenderAddressNotAllowListed, msg.From)
361+
return fmt.Errorf("%w: %s", vmerrors.ErrSenderAddressNotAllowListed, msg.From)
362362
}
363363
}
364364
}
@@ -485,7 +485,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
485485

486486
// Check whether the init code size has been exceeded.
487487
if rulesExtra.IsDurango && contractCreation && len(msg.Data) > params.MaxInitCodeSize {
488-
return nil, fmt.Errorf("%w: code size %v limit %v", vmerrs.ErrMaxInitCodeSizeExceeded, len(msg.Data), params.MaxInitCodeSize)
488+
return nil, fmt.Errorf("%w: code size %v limit %v", vm.ErrMaxInitCodeSizeExceeded, len(msg.Data), params.MaxInitCodeSize)
489489
}
490490

491491
// Execute the preparatory steps for state transition which includes:

core/txpool/validation.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ import (
3232
"math/big"
3333

3434
"github.com/ava-labs/libevm/common"
35+
"github.com/ava-labs/libevm/core/vm"
3536
"github.com/ava-labs/libevm/crypto/kzg4844"
3637
"github.com/ava-labs/libevm/log"
3738
"github.com/ava-labs/subnet-evm/core"
3839
"github.com/ava-labs/subnet-evm/core/state"
3940
"github.com/ava-labs/subnet-evm/core/types"
4041
"github.com/ava-labs/subnet-evm/params"
42+
"github.com/ava-labs/subnet-evm/plugin/evm/vmerrors"
4143
"github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist"
42-
"github.com/ava-labs/subnet-evm/vmerrs"
4344
)
4445

4546
var (
@@ -86,7 +87,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
8687
}
8788
// Check whether the init code size has been exceeded
8889
if opts.Config.IsShanghai(head.Number, head.Time) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
89-
return fmt.Errorf("%w: code size %v, limit %v", vmerrs.ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize)
90+
return fmt.Errorf("%w: code size %v, limit %v", vm.ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize)
9091
}
9192
// Transactions can't be negative. This may never happen using RLP decoded
9293
// transactions but may occur for transactions created using the RPC.
@@ -277,7 +278,7 @@ func ValidateTransactionWithState(tx *types.Transaction, signer types.Signer, op
277278
if params.GetRulesExtra(opts.Rules).IsPrecompileEnabled(txallowlist.ContractAddress) {
278279
txAllowListRole := txallowlist.GetTxAllowListStatus(opts.State, from)
279280
if !txAllowListRole.IsEnabled() {
280-
return fmt.Errorf("%w: %s", vmerrs.ErrSenderAddressNotAllowListed, from)
281+
return fmt.Errorf("%w: %s", vmerrors.ErrSenderAddressNotAllowListed, from)
281282
}
282283
}
283284

eth/gasestimator/gasestimator.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"github.com/ava-labs/subnet-evm/core/state"
4141
"github.com/ava-labs/subnet-evm/core/types"
4242
"github.com/ava-labs/subnet-evm/params"
43-
"github.com/ava-labs/subnet-evm/vmerrs"
4443
)
4544

4645
// Options are the contextual parameters to execute the requested call.
@@ -128,7 +127,7 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin
128127
return 0, nil, err
129128
}
130129
if failed {
131-
if result != nil && !errors.Is(result.Err, vmerrs.ErrOutOfGas) {
130+
if result != nil && !errors.Is(result.Err, vm.ErrOutOfGas) {
132131
return 0, result.Revert(), result.Err
133132
}
134133
return 0, nil, fmt.Errorf("gas required exceeds allowance (%d)", hi)

internal/ethapi/errors.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
"fmt"
3131

3232
"github.com/ava-labs/libevm/common/hexutil"
33+
"github.com/ava-labs/libevm/core/vm"
3334
"github.com/ava-labs/subnet-evm/accounts/abi"
34-
"github.com/ava-labs/subnet-evm/vmerrs"
3535
)
3636

3737
// revertError is an API error that encompasses an EVM revert with JSON error
@@ -54,11 +54,11 @@ func (e *revertError) ErrorData() interface{} {
5454

5555
// newRevertError creates a revertError instance with the provided revert data.
5656
func newRevertError(revert []byte) *revertError {
57-
err := vmerrs.ErrExecutionReverted
57+
err := vm.ErrExecutionReverted
5858

5959
reason, errUnpack := abi.UnpackRevert(revert)
6060
if errUnpack == nil {
61-
err = fmt.Errorf("%w: %v", vmerrs.ErrExecutionReverted, reason)
61+
err = fmt.Errorf("%w: %v", vm.ErrExecutionReverted, reason)
6262
}
6363
return &revertError{
6464
error: err,

plugin/evm/vm_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ import (
4949
"github.com/ava-labs/subnet-evm/params/extras"
5050
"github.com/ava-labs/subnet-evm/plugin/evm/config"
5151
"github.com/ava-labs/subnet-evm/plugin/evm/header"
52+
"github.com/ava-labs/subnet-evm/plugin/evm/vmerrors"
5253
"github.com/ava-labs/subnet-evm/precompile/allowlist"
5354
"github.com/ava-labs/subnet-evm/precompile/contracts/deployerallowlist"
5455
"github.com/ava-labs/subnet-evm/precompile/contracts/feemanager"
5556
"github.com/ava-labs/subnet-evm/precompile/contracts/rewardmanager"
5657
"github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist"
5758
"github.com/ava-labs/subnet-evm/rpc"
5859
"github.com/ava-labs/subnet-evm/utils"
59-
"github.com/ava-labs/subnet-evm/vmerrs"
6060

6161
avagoconstants "github.com/ava-labs/avalanchego/utils/constants"
6262
)
@@ -2163,7 +2163,7 @@ func TestTxAllowListSuccessfulTx(t *testing.T) {
21632163
}
21642164

21652165
errs = vm.txPool.AddRemotesSync([]*types.Transaction{signedTx1})
2166-
if err := errs[0]; !errors.Is(err, vmerrs.ErrSenderAddressNotAllowListed) {
2166+
if err := errs[0]; !errors.Is(err, vmerrors.ErrSenderAddressNotAllowListed) {
21672167
t.Fatalf("expected ErrSenderAddressNotAllowListed, got: %s", err)
21682168
}
21692169

@@ -2173,7 +2173,7 @@ func TestTxAllowListSuccessfulTx(t *testing.T) {
21732173
require.NoError(t, err)
21742174

21752175
errs = vm.txPool.AddRemotesSync([]*types.Transaction{signedTx2})
2176-
require.ErrorIs(t, errs[0], vmerrs.ErrSenderAddressNotAllowListed)
2176+
require.ErrorIs(t, errs[0], vmerrors.ErrSenderAddressNotAllowListed)
21772177

21782178
blk := issueAndAccept(t, issuer, vm)
21792179
newHead := <-newTxPoolHeadChan
@@ -2377,7 +2377,7 @@ func TestTxAllowListDisablePrecompile(t *testing.T) {
23772377
}
23782378

23792379
errs = vm.txPool.AddRemotesSync([]*types.Transaction{signedTx1})
2380-
if err := errs[0]; !errors.Is(err, vmerrs.ErrSenderAddressNotAllowListed) {
2380+
if err := errs[0]; !errors.Is(err, vmerrors.ErrSenderAddressNotAllowListed) {
23812381
t.Fatalf("expected ErrSenderAddressNotAllowListed, got: %s", err)
23822382
}
23832383

@@ -2597,7 +2597,7 @@ func TestAllowFeeRecipientDisabled(t *testing.T) {
25972597

25982598
modifiedBlk := vm.newBlock(modifiedBlock)
25992599

2600-
require.ErrorIs(t, modifiedBlk.Verify(context.Background()), vmerrs.ErrInvalidCoinbase)
2600+
require.ErrorIs(t, modifiedBlk.Verify(context.Background()), vmerrors.ErrInvalidCoinbase)
26012601
}
26022602

26032603
func TestAllowFeeRecipientEnabled(t *testing.T) {

plugin/evm/vm_upgrade_bytes_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
"github.com/ava-labs/subnet-evm/core"
2626
"github.com/ava-labs/subnet-evm/core/types"
2727
"github.com/ava-labs/subnet-evm/params/extras"
28+
"github.com/ava-labs/subnet-evm/plugin/evm/vmerrors"
2829
"github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist"
2930
"github.com/ava-labs/subnet-evm/utils"
30-
"github.com/ava-labs/subnet-evm/vmerrs"
3131
"github.com/holiman/uint256"
3232
"github.com/stretchr/testify/assert"
3333
"github.com/stretchr/testify/require"
@@ -71,7 +71,7 @@ func TestVMUpgradeBytesPrecompile(t *testing.T) {
7171
t.Fatal(err)
7272
}
7373
errs = vm.txPool.AddRemotesSync([]*types.Transaction{signedTx1})
74-
if err := errs[0]; !errors.Is(err, vmerrs.ErrSenderAddressNotAllowListed) {
74+
if err := errs[0]; !errors.Is(err, vmerrors.ErrSenderAddressNotAllowListed) {
7575
t.Fatalf("expected ErrSenderAddressNotAllowListed, got: %s", err)
7676
}
7777

@@ -128,7 +128,7 @@ func TestVMUpgradeBytesPrecompile(t *testing.T) {
128128

129129
// Submit a rejected transaction, should throw an error
130130
errs = vm.txPool.AddRemotesSync([]*types.Transaction{signedTx1})
131-
if err := errs[0]; !errors.Is(err, vmerrs.ErrSenderAddressNotAllowListed) {
131+
if err := errs[0]; !errors.Is(err, vmerrors.ErrSenderAddressNotAllowListed) {
132132
t.Fatalf("expected ErrSenderAddressNotAllowListed, got: %s", err)
133133
}
134134

0 commit comments

Comments
 (0)