Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/ibc/core/23-commitment/types: fix MerkleProof.Empty comparisons #8092

Merged
merged 4 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions x/ibc/core/23-commitment/types/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package types

import (
"testing"
)

func BenchmarkMerkleProofEmpty(b *testing.B) {
b.ReportAllocs()
var mk MerkleProof
for i := 0; i < b.N; i++ {
if !mk.Empty() {
b.Fatal("supposed to be empty")
}
}
}
7 changes: 5 additions & 2 deletions x/ibc/core/23-commitment/types/merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ func verifyChainedMembershipProof(root []byte, specs []*ics23.ProofSpec, proofs
}

// Empty returns true if the root is empty
func (proof MerkleProof) Empty() bool {
return proto.Equal(&proof, nil) || proto.Equal(&proof, &MerkleProof{}) || proto.Equal(&proof, &tmcrypto.ProofOps{})
var blankMerkleProof = &MerkleProof{}
var blankProofOps = &tmcrypto.ProofOps{}

func (proof *MerkleProof) Empty() bool {
return proof == nil || proto.Equal(proof, blankMerkleProof) || proto.Equal(proof, blankProofOps)
}

// ValidateBasic checks if the proof is empty.
Expand Down