Skip to content

Commit ff8cea3

Browse files
authored
chore: update go deps (#112)
* add go tests * add js tests * fix how license is shown * add rust flow * fix syntax * cd into rust * test * test++ * test++ * test++ * migrate * add rust linting * fix concurrency * formatting * lint pr * rename main to master * fix test * fix clippy issues * clean deps and update Co-authored-by: Marko Baricevic <[email protected]>
1 parent 82313ed commit ff8cea3

File tree

4 files changed

+68
-48
lines changed

4 files changed

+68
-48
lines changed

go/go.mod

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module github.com/confio/ics23/go
22

3-
go 1.14
3+
go 1.19
44

55
require (
66
github.com/gogo/protobuf v1.3.1
7-
github.com/pkg/errors v0.8.1
8-
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
7+
golang.org/x/crypto v0.2.0
98
)

go/go.sum

+26-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,33 @@ github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
22
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
33
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
44
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
5-
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
6-
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
5+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
76
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
8-
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
9-
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
10-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
7+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
8+
golang.org/x/crypto v0.2.0 h1:BRXPfhNivWL5Yq0BGQ39a2sW6t44aODpfxkWjYdzewE=
9+
golang.org/x/crypto v0.2.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
10+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
11+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
12+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
13+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
14+
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
15+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
16+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
1117
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
12-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
18+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
19+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
21+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
22+
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
23+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
24+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
25+
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
1326
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
27+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
28+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
29+
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
30+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
1431
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
32+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
33+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
34+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

go/ops.go

+20-19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"bytes"
55
"crypto"
66
"encoding/binary"
7+
"errors"
8+
"fmt"
79

810
// adds sha256 capability to crypto.SHA256
911
_ "crypto/sha256"
@@ -12,8 +14,6 @@ import (
1214

1315
// adds ripemd160 capability to crypto.RIPEMD160
1416
_ "golang.org/x/crypto/ripemd160"
15-
16-
"github.com/pkg/errors"
1717
)
1818

1919
// Apply will calculate the leaf hash given the key and value being proven
@@ -26,11 +26,11 @@ func (op *LeafOp) Apply(key []byte, value []byte) ([]byte, error) {
2626
}
2727
pkey, err := prepareLeafData(op.PrehashKey, op.Length, key)
2828
if err != nil {
29-
return nil, errors.Wrap(err, "prehash key")
29+
return nil, fmt.Errorf("prehash key, %w", err)
3030
}
3131
pvalue, err := prepareLeafData(op.PrehashValue, op.Length, value)
3232
if err != nil {
33-
return nil, errors.Wrap(err, "prehash value")
33+
return nil, fmt.Errorf("prehash value, %w", err)
3434
}
3535
data := append(op.Prefix, pkey...)
3636
data = append(data, pvalue...)
@@ -42,27 +42,27 @@ func (op *LeafOp) CheckAgainstSpec(spec *ProofSpec) error {
4242
lspec := spec.LeafSpec
4343

4444
if op.Hash != lspec.Hash {
45-
return errors.Errorf("Unexpected HashOp: %d", op.Hash)
45+
return fmt.Errorf("Unexpected HashOp: %d", op.Hash)
4646
}
4747
if op.PrehashKey != lspec.PrehashKey {
48-
return errors.Errorf("Unexpected PrehashKey: %d", op.PrehashKey)
48+
return fmt.Errorf("Unexpected PrehashKey: %d", op.PrehashKey)
4949
}
5050
if op.PrehashValue != lspec.PrehashValue {
51-
return errors.Errorf("Unexpected PrehashValue: %d", op.PrehashValue)
51+
return fmt.Errorf("Unexpected PrehashValue: %d", op.PrehashValue)
5252
}
5353
if op.Length != lspec.Length {
54-
return errors.Errorf("Unexpected LengthOp: %d", op.Length)
54+
return fmt.Errorf("Unexpected LengthOp: %d", op.Length)
5555
}
5656
if !bytes.HasPrefix(op.Prefix, lspec.Prefix) {
57-
return errors.Errorf("Leaf Prefix doesn't start with %X", lspec.Prefix)
57+
return fmt.Errorf("Leaf Prefix doesn't start with %X", lspec.Prefix)
5858
}
5959
return nil
6060
}
6161

6262
// Apply will calculate the hash of the next step, given the hash of the previous step
6363
func (op *InnerOp) Apply(child []byte) ([]byte, error) {
6464
if len(child) == 0 {
65-
return nil, errors.Errorf("Inner op needs child value")
65+
return nil, errors.New("Inner op needs child value")
6666
}
6767
preimage := append(op.Prefix, child...)
6868
preimage = append(preimage, op.Suffix...)
@@ -72,19 +72,19 @@ func (op *InnerOp) Apply(child []byte) ([]byte, error) {
7272
// CheckAgainstSpec will verify the InnerOp is in the format defined in spec
7373
func (op *InnerOp) CheckAgainstSpec(spec *ProofSpec) error {
7474
if op.Hash != spec.InnerSpec.Hash {
75-
return errors.Errorf("Unexpected HashOp: %d", op.Hash)
75+
return fmt.Errorf("Unexpected HashOp: %d", op.Hash)
7676
}
7777

7878
leafPrefix := spec.LeafSpec.Prefix
7979
if bytes.HasPrefix(op.Prefix, leafPrefix) {
80-
return errors.Errorf("Inner Prefix starts with %X", leafPrefix)
80+
return fmt.Errorf("Inner Prefix starts with %X", leafPrefix)
8181
}
8282
if len(op.Prefix) < int(spec.InnerSpec.MinPrefixLength) {
83-
return errors.Errorf("InnerOp prefix too short (%d)", len(op.Prefix))
83+
return fmt.Errorf("InnerOp prefix too short (%d)", len(op.Prefix))
8484
}
8585
maxLeftChildBytes := (len(spec.InnerSpec.ChildOrder) - 1) * int(spec.InnerSpec.ChildSize)
8686
if len(op.Prefix) > int(spec.InnerSpec.MaxPrefixLength)+maxLeftChildBytes {
87-
return errors.Errorf("InnerOp prefix too long (%d)", len(op.Prefix))
87+
return fmt.Errorf("InnerOp prefix too long (%d)", len(op.Prefix))
8888
}
8989
return nil
9090
}
@@ -137,11 +137,12 @@ func doHash(hashOp HashOp, preimage []byte) ([]byte, error) {
137137
hash.Write(preimage)
138138
return hash.Sum(nil), nil
139139
}
140-
return nil, errors.Errorf("Unsupported hashop: %d", hashOp)
140+
return nil, fmt.Errorf("Unsupported hashop: %d", hashOp)
141141
}
142142

143143
// doLengthOp will calculate the proper prefix and return it prepended
144-
// doLengthOp(op, data) -> length(data) || data
144+
//
145+
// doLengthOp(op, data) -> length(data) || data
145146
func doLengthOp(lengthOp LengthOp, data []byte) ([]byte, error) {
146147
switch lengthOp {
147148
case LengthOp_NO_PREFIX:
@@ -151,12 +152,12 @@ func doLengthOp(lengthOp LengthOp, data []byte) ([]byte, error) {
151152
return res, nil
152153
case LengthOp_REQUIRE_32_BYTES:
153154
if len(data) != 32 {
154-
return nil, errors.Errorf("Data was %d bytes, not 32", len(data))
155+
return nil, fmt.Errorf("Data was %d bytes, not 32", len(data))
155156
}
156157
return data, nil
157158
case LengthOp_REQUIRE_64_BYTES:
158159
if len(data) != 64 {
159-
return nil, errors.Errorf("Data was %d bytes, not 64", len(data))
160+
return nil, fmt.Errorf("Data was %d bytes, not 64", len(data))
160161
}
161162
return data, nil
162163
case LengthOp_FIXED32_LITTLE:
@@ -170,7 +171,7 @@ func doLengthOp(lengthOp LengthOp, data []byte) ([]byte, error) {
170171
// case LengthOp_FIXED64_BIG:
171172
// case LengthOp_FIXED64_LITTLE:
172173
}
173-
return nil, errors.Errorf("Unsupported lengthop: %d", lengthOp)
174+
return nil, fmt.Errorf("Unsupported lengthop: %d", lengthOp)
174175
}
175176

176177
func encodeVarintProto(l int) []byte {

go/proof.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package ics23
22

33
import (
44
"bytes"
5-
6-
"github.com/pkg/errors"
5+
"errors"
6+
"fmt"
77
)
88

99
// IavlSpec constrains the format from proofs-iavl (iavl merkle proofs)
@@ -98,18 +98,18 @@ func (p *ExistenceProof) Verify(spec *ProofSpec, root CommitmentRoot, key []byte
9898
}
9999

100100
if !bytes.Equal(key, p.Key) {
101-
return errors.Errorf("Provided key doesn't match proof")
101+
return fmt.Errorf("Provided key doesn't match proof")
102102
}
103103
if !bytes.Equal(value, p.Value) {
104-
return errors.Errorf("Provided value doesn't match proof")
104+
return fmt.Errorf("Provided value doesn't match proof")
105105
}
106106

107107
calc, err := p.Calculate()
108108
if err != nil {
109-
return errors.Wrap(err, "Error calculating root")
109+
return fmt.Errorf("Error calculating root, %w", err)
110110
}
111111
if !bytes.Equal(root, calc) {
112-
return errors.Errorf("Calculcated root doesn't match provided root")
112+
return fmt.Errorf("Calculcated root doesn't match provided root")
113113
}
114114

115115
return nil
@@ -127,14 +127,14 @@ func (p *ExistenceProof) Calculate() (CommitmentRoot, error) {
127127
// leaf step takes the key and value as input
128128
res, err := p.Leaf.Apply(p.Key, p.Value)
129129
if err != nil {
130-
return nil, errors.WithMessage(err, "leaf")
130+
return nil, fmt.Errorf("leaf, %w", err)
131131
}
132132

133133
// the rest just take the output of the last step (reducing it)
134134
for _, step := range p.Path {
135135
res, err = step.Apply(res)
136136
if err != nil {
137-
return nil, errors.WithMessage(err, "inner")
137+
return nil, fmt.Errorf("inner, %w", err)
138138
}
139139
}
140140
return res, nil
@@ -162,18 +162,18 @@ func (p *ExistenceProof) CheckAgainstSpec(spec *ProofSpec) error {
162162
}
163163
err := p.Leaf.CheckAgainstSpec(spec)
164164
if err != nil {
165-
return errors.WithMessage(err, "leaf")
165+
return fmt.Errorf("leaf, %w", err)
166166
}
167167
if spec.MinDepth > 0 && len(p.Path) < int(spec.MinDepth) {
168-
return errors.Errorf("InnerOps depth too short: %d", len(p.Path))
168+
return fmt.Errorf("InnerOps depth too short: %d", len(p.Path))
169169
}
170170
if spec.MaxDepth > 0 && len(p.Path) > int(spec.MaxDepth) {
171-
return errors.Errorf("InnerOps depth too long: %d", len(p.Path))
171+
return fmt.Errorf("InnerOps depth too long: %d", len(p.Path))
172172
}
173173

174174
for _, inner := range p.Path {
175175
if err := inner.CheckAgainstSpec(spec); err != nil {
176-
return errors.WithMessage(err, "inner")
176+
return fmt.Errorf("inner, %w", err)
177177
}
178178
}
179179
return nil
@@ -186,13 +186,13 @@ func (p *NonExistenceProof) Verify(spec *ProofSpec, root CommitmentRoot, key []b
186186
var leftKey, rightKey []byte
187187
if p.Left != nil {
188188
if err := p.Left.Verify(spec, root, p.Left.Key, p.Left.Value); err != nil {
189-
return errors.Wrap(err, "left proof")
189+
return fmt.Errorf("left proof, %w", err)
190190
}
191191
leftKey = p.Left.Key
192192
}
193193
if p.Right != nil {
194194
if err := p.Right.Verify(spec, root, p.Right.Key, p.Right.Value); err != nil {
195-
return errors.Wrap(err, "right proof")
195+
return fmt.Errorf("right proof, %w", err)
196196
}
197197
rightKey = p.Right.Key
198198
}
@@ -259,10 +259,10 @@ func IsRightMost(spec *InnerSpec, path []*InnerOp) bool {
259259

260260
// IsLeftNeighbor returns true if `right` is the next possible path right of `left`
261261
//
262-
// Find the common suffix from the Left.Path and Right.Path and remove it. We have LPath and RPath now, which must be neighbors.
263-
// Validate that LPath[len-1] is the left neighbor of RPath[len-1]
264-
// For step in LPath[0..len-1], validate step is right-most node
265-
// For step in RPath[0..len-1], validate step is left-most node
262+
// Find the common suffix from the Left.Path and Right.Path and remove it. We have LPath and RPath now, which must be neighbors.
263+
// Validate that LPath[len-1] is the left neighbor of RPath[len-1]
264+
// For step in LPath[0..len-1], validate step is right-most node
265+
// For step in RPath[0..len-1], validate step is left-most node
266266
func IsLeftNeighbor(spec *InnerSpec, left []*InnerOp, right []*InnerOp) bool {
267267
// count common tail (from end, near root)
268268
left, topleft := left[:len(left)-1], left[len(left)-1]
@@ -387,14 +387,14 @@ func rightBranchesAreEmpty(spec *InnerSpec, op *InnerOp) bool {
387387
// the index of this branch
388388
func getPosition(order []int32, branch int32) int {
389389
if branch < 0 || int(branch) >= len(order) {
390-
panic(errors.Errorf("Invalid branch: %d", branch))
390+
panic(fmt.Errorf("Invalid branch: %d", branch))
391391
}
392392
for i, item := range order {
393393
if branch == item {
394394
return i
395395
}
396396
}
397-
panic(errors.Errorf("Branch %d not found in order %v", branch, order))
397+
panic(fmt.Errorf("Branch %d not found in order %v", branch, order))
398398
}
399399

400400
// This will look at the proof and determine which order it is...

0 commit comments

Comments
 (0)