Skip to content

Commit

Permalink
Linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jan 30, 2024
1 parent 6769f44 commit 46c6238
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 45 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: '1.20'
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# https://github.com/golangci/golangci-lint-action/issues/535
version: v1.47.3
# version: latest
args: --timeout=60m
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: '1.20'
- uses: actions/checkout@v3
- uses: n8maninger/action-golang-test@v1
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ linters:
- interfacer
- ireturn
- maligned
- nestif
- nosnakecase
- scopelint
- structcheck
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/wealdtech/go-merkletree/v2

go 1.19
go 1.20

require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.5.0
golang.org/x/crypto v0.18.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/sys v0.16.0 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
28 changes: 17 additions & 11 deletions multiproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,24 @@ func (p *MultiProof) Verify(data [][]byte, root []byte) (bool, error) {
// Step 2 calculate values up the tree.
for i := p.Values - 1; i > 0; i-- {
_, exists := p.Hashes[i]
if exists {
continue
}

child1, exists := p.Hashes[i*2]
if !exists {
continue
}

child2, exists := p.Hashes[i*2+1]
if !exists {
child1, exists := p.Hashes[i*2]
if exists {
child2, exists := p.Hashes[i*2+1]
if exists {
if p.sorted && bytes.Compare(child1, child2) == 1 {
p.Hashes[i] = p.hash.Hash(child2, child1)
} else {
p.Hashes[i] = p.hash.Hash(child1, child2)
}
}
}
continue
}

if p.sorted && bytes.Compare(child1, child2) == 1 {
p.Hashes[i] = p.hash.Hash(child2, child1)
} else {
p.Hashes[i] = p.hash.Hash(child1, child2)
}
}

Expand Down
34 changes: 13 additions & 21 deletions multiproof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,23 @@ func TestMultiProof(t *testing.T) {
WithSorted(test.sorted),
)
assert.Nil(t, err, fmt.Sprintf("failed to create tree at test %d", i))
// Test proof for each data item individually
for j, data := range test.data {
proof, err := tree.GenerateMultiProof([][]byte{data})
assert.Nil(t, err, fmt.Sprintf("failed to create multiproof at test %d data %d", i, j))
proven, err := proof.Verify([][]byte{data}, tree.Root())
assert.Nil(t, err, fmt.Sprintf("error verifying multiproof at test %d data %d", i, j))
assert.True(t, proven, fmt.Sprintf("failed to verify multiproof at test %d data %d", i, j))
}
// Test proof for each data item cumulatively.

// Test proof for all combinations of data.
var proof *MultiProof
for j, data := range test.data {
if j == 0 {
proof, err = tree.GenerateMultiProof([][]byte{data})
assert.Nil(t, err, fmt.Sprintf("failed to create multiproof at test %d data %d", i, j))
combinations := 1<<len(test.data) - 1
for j := 1; j <= combinations; j++ {
items := make([][]byte, 0)
for k := 0; k < len(test.data); k++ {
if (j>>k)&1 == 1 {
items = append(items, test.data[k])
}
}
proven, err := proof.Verify([][]byte{data}, tree.Root())
proof, err = tree.GenerateMultiProof(items)
assert.Nil(t, err, fmt.Sprintf("failed to create multiproof at test %d data %d", i, j))
proven, err := proof.Verify(items, tree.Root())
assert.Nil(t, err, fmt.Sprintf("error verifying multiproof at test %d data %d", i, j))
assert.True(t, proven, fmt.Sprintf("failed to verify multiproof at test %d data %d", i, j))
}
// Test proof for all data
proof, err = tree.GenerateMultiProof(test.data)
assert.Nil(t, err, fmt.Sprintf("failed to create multiproof at test %d", i))
proven, err := proof.Verify(test.data, tree.Root())
assert.Nil(t, err, fmt.Sprintf("error verifying multiproof at test %d", i))
assert.True(t, proven, fmt.Sprintf("failed to verify multiproof at test %d", i))
}
}
}
Expand Down Expand Up @@ -147,7 +139,7 @@ func TestSavings(t *testing.T) {
tree, err := New(data)
assert.Nil(t, err, "failed to create tree")

rand.Seed(0)
rand := rand.New(rand.NewSource(0))
proofSize := 0
pollardSize := 0
multiProofSize := 0
Expand Down

0 comments on commit 46c6238

Please sign in to comment.