Skip to content

Commit

Permalink
chore: update go deps (#112)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
tac0turtle and tac0turtle authored Nov 10, 2022
1 parent 82313ed commit ff8cea3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 48 deletions.
5 changes: 2 additions & 3 deletions go/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module github.com/confio/ics23/go

go 1.14
go 1.19

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

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

// adds ripemd160 capability to crypto.RIPEMD160
_ "golang.org/x/crypto/ripemd160"

"github.com/pkg/errors"
)

// Apply will calculate the leaf hash given the key and value being proven
Expand All @@ -26,11 +26,11 @@ func (op *LeafOp) Apply(key []byte, value []byte) ([]byte, error) {
}
pkey, err := prepareLeafData(op.PrehashKey, op.Length, key)
if err != nil {
return nil, errors.Wrap(err, "prehash key")
return nil, fmt.Errorf("prehash key, %w", err)
}
pvalue, err := prepareLeafData(op.PrehashValue, op.Length, value)
if err != nil {
return nil, errors.Wrap(err, "prehash value")
return nil, fmt.Errorf("prehash value, %w", err)
}
data := append(op.Prefix, pkey...)
data = append(data, pvalue...)
Expand All @@ -42,27 +42,27 @@ func (op *LeafOp) CheckAgainstSpec(spec *ProofSpec) error {
lspec := spec.LeafSpec

if op.Hash != lspec.Hash {
return errors.Errorf("Unexpected HashOp: %d", op.Hash)
return fmt.Errorf("Unexpected HashOp: %d", op.Hash)
}
if op.PrehashKey != lspec.PrehashKey {
return errors.Errorf("Unexpected PrehashKey: %d", op.PrehashKey)
return fmt.Errorf("Unexpected PrehashKey: %d", op.PrehashKey)
}
if op.PrehashValue != lspec.PrehashValue {
return errors.Errorf("Unexpected PrehashValue: %d", op.PrehashValue)
return fmt.Errorf("Unexpected PrehashValue: %d", op.PrehashValue)
}
if op.Length != lspec.Length {
return errors.Errorf("Unexpected LengthOp: %d", op.Length)
return fmt.Errorf("Unexpected LengthOp: %d", op.Length)
}
if !bytes.HasPrefix(op.Prefix, lspec.Prefix) {
return errors.Errorf("Leaf Prefix doesn't start with %X", lspec.Prefix)
return fmt.Errorf("Leaf Prefix doesn't start with %X", lspec.Prefix)
}
return nil
}

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

leafPrefix := spec.LeafSpec.Prefix
if bytes.HasPrefix(op.Prefix, leafPrefix) {
return errors.Errorf("Inner Prefix starts with %X", leafPrefix)
return fmt.Errorf("Inner Prefix starts with %X", leafPrefix)
}
if len(op.Prefix) < int(spec.InnerSpec.MinPrefixLength) {
return errors.Errorf("InnerOp prefix too short (%d)", len(op.Prefix))
return fmt.Errorf("InnerOp prefix too short (%d)", len(op.Prefix))
}
maxLeftChildBytes := (len(spec.InnerSpec.ChildOrder) - 1) * int(spec.InnerSpec.ChildSize)
if len(op.Prefix) > int(spec.InnerSpec.MaxPrefixLength)+maxLeftChildBytes {
return errors.Errorf("InnerOp prefix too long (%d)", len(op.Prefix))
return fmt.Errorf("InnerOp prefix too long (%d)", len(op.Prefix))
}
return nil
}
Expand Down Expand Up @@ -137,11 +137,12 @@ func doHash(hashOp HashOp, preimage []byte) ([]byte, error) {
hash.Write(preimage)
return hash.Sum(nil), nil
}
return nil, errors.Errorf("Unsupported hashop: %d", hashOp)
return nil, fmt.Errorf("Unsupported hashop: %d", hashOp)
}

// doLengthOp will calculate the proper prefix and return it prepended
// doLengthOp(op, data) -> length(data) || data
//
// doLengthOp(op, data) -> length(data) || data
func doLengthOp(lengthOp LengthOp, data []byte) ([]byte, error) {
switch lengthOp {
case LengthOp_NO_PREFIX:
Expand All @@ -151,12 +152,12 @@ func doLengthOp(lengthOp LengthOp, data []byte) ([]byte, error) {
return res, nil
case LengthOp_REQUIRE_32_BYTES:
if len(data) != 32 {
return nil, errors.Errorf("Data was %d bytes, not 32", len(data))
return nil, fmt.Errorf("Data was %d bytes, not 32", len(data))
}
return data, nil
case LengthOp_REQUIRE_64_BYTES:
if len(data) != 64 {
return nil, errors.Errorf("Data was %d bytes, not 64", len(data))
return nil, fmt.Errorf("Data was %d bytes, not 64", len(data))
}
return data, nil
case LengthOp_FIXED32_LITTLE:
Expand All @@ -170,7 +171,7 @@ func doLengthOp(lengthOp LengthOp, data []byte) ([]byte, error) {
// case LengthOp_FIXED64_BIG:
// case LengthOp_FIXED64_LITTLE:
}
return nil, errors.Errorf("Unsupported lengthop: %d", lengthOp)
return nil, fmt.Errorf("Unsupported lengthop: %d", lengthOp)
}

func encodeVarintProto(l int) []byte {
Expand Down
40 changes: 20 additions & 20 deletions go/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package ics23

import (
"bytes"

"github.com/pkg/errors"
"errors"
"fmt"
)

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

if !bytes.Equal(key, p.Key) {
return errors.Errorf("Provided key doesn't match proof")
return fmt.Errorf("Provided key doesn't match proof")
}
if !bytes.Equal(value, p.Value) {
return errors.Errorf("Provided value doesn't match proof")
return fmt.Errorf("Provided value doesn't match proof")
}

calc, err := p.Calculate()
if err != nil {
return errors.Wrap(err, "Error calculating root")
return fmt.Errorf("Error calculating root, %w", err)
}
if !bytes.Equal(root, calc) {
return errors.Errorf("Calculcated root doesn't match provided root")
return fmt.Errorf("Calculcated root doesn't match provided root")
}

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

// the rest just take the output of the last step (reducing it)
for _, step := range p.Path {
res, err = step.Apply(res)
if err != nil {
return nil, errors.WithMessage(err, "inner")
return nil, fmt.Errorf("inner, %w", err)
}
}
return res, nil
Expand Down Expand Up @@ -162,18 +162,18 @@ func (p *ExistenceProof) CheckAgainstSpec(spec *ProofSpec) error {
}
err := p.Leaf.CheckAgainstSpec(spec)
if err != nil {
return errors.WithMessage(err, "leaf")
return fmt.Errorf("leaf, %w", err)
}
if spec.MinDepth > 0 && len(p.Path) < int(spec.MinDepth) {
return errors.Errorf("InnerOps depth too short: %d", len(p.Path))
return fmt.Errorf("InnerOps depth too short: %d", len(p.Path))
}
if spec.MaxDepth > 0 && len(p.Path) > int(spec.MaxDepth) {
return errors.Errorf("InnerOps depth too long: %d", len(p.Path))
return fmt.Errorf("InnerOps depth too long: %d", len(p.Path))
}

for _, inner := range p.Path {
if err := inner.CheckAgainstSpec(spec); err != nil {
return errors.WithMessage(err, "inner")
return fmt.Errorf("inner, %w", err)
}
}
return nil
Expand All @@ -186,13 +186,13 @@ func (p *NonExistenceProof) Verify(spec *ProofSpec, root CommitmentRoot, key []b
var leftKey, rightKey []byte
if p.Left != nil {
if err := p.Left.Verify(spec, root, p.Left.Key, p.Left.Value); err != nil {
return errors.Wrap(err, "left proof")
return fmt.Errorf("left proof, %w", err)
}
leftKey = p.Left.Key
}
if p.Right != nil {
if err := p.Right.Verify(spec, root, p.Right.Key, p.Right.Value); err != nil {
return errors.Wrap(err, "right proof")
return fmt.Errorf("right proof, %w", err)
}
rightKey = p.Right.Key
}
Expand Down Expand Up @@ -259,10 +259,10 @@ func IsRightMost(spec *InnerSpec, path []*InnerOp) bool {

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

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

0 comments on commit ff8cea3

Please sign in to comment.