Skip to content

Commit 3cbe139

Browse files
Use global error
1 parent cfc3b2e commit 3cbe139

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

trie/proof.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func VerifyRangeProof(rootHash common.Hash, firstKey []byte, keys [][]byte, valu
489489
for i := 0; i < len(keys)-1; i++ {
490490
// See: https://github.com/ava-labs/coreth/issues/907
491491
if len(keys[i]) != len(keys[i+1]) {
492-
return false, errors.New("keys do not have constant length")
492+
return false, errKeysHaveDifferentLengths
493493
}
494494
if bytes.Compare(keys[i], keys[i+1]) >= 0 {
495495
return false, errors.New("range is not monotonically increasing")

trie/proof.libevm.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2025 the libevm authors.
2+
//
3+
// The libevm additions to go-ethereum are free software: you can redistribute
4+
// them and/or modify them under the terms of the GNU Lesser General Public License
5+
// as published by the Free Software Foundation, either version 3 of the License,
6+
// or (at your option) any later version.
7+
//
8+
// The libevm additions are distributed in the hope that they will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
11+
// General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU Lesser General Public License
14+
// along with the go-ethereum library. If not, see
15+
// <http://www.gnu.org/licenses/>.
16+
17+
package trie
18+
19+
import (
20+
"errors"
21+
)
22+
23+
var errKeysHaveDifferentLengths = errors.New("keys have different lengths")

trie/proof.libevm_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package trie
1919
import (
2020
"testing"
2121

22+
"github.com/stretchr/testify/require"
23+
2224
"github.com/ava-labs/libevm/common"
2325
)
2426

@@ -42,7 +44,5 @@ func TestRangeProofKeysWithDifferentLengths(t *testing.T) {
4244
values,
4345
nil, // force it to use stacktrie
4446
)
45-
if err == nil {
46-
t.Fatalf("unexpectedly verified invalid range proof: %v", err)
47-
}
47+
require.ErrorIs(t, err, errKeysHaveDifferentLengths)
4848
}

0 commit comments

Comments
 (0)