@@ -52,7 +52,7 @@ func VerifyMembership(spec *ProofSpec, root CommitmentRoot, proof *CommitmentPro
5252func VerifyNonMembership (spec * ProofSpec , root CommitmentRoot , proof * CommitmentProof , key []byte ) bool {
5353 // decompress it before running code (no-op if not compressed)
5454 proof = Decompress (proof )
55- np := getNonExistProofForKey (proof , key )
55+ np := getNonExistProofForKey (spec , proof , key )
5656 if np == nil {
5757 return false
5858 }
@@ -148,27 +148,27 @@ func getExistProofForKey(proof *CommitmentProof, key []byte) *ExistenceProof {
148148 return nil
149149}
150150
151- func getNonExistProofForKey (proof * CommitmentProof , key []byte ) * NonExistenceProof {
151+ func getNonExistProofForKey (spec * ProofSpec , proof * CommitmentProof , key []byte ) * NonExistenceProof {
152152 switch p := proof .Proof .(type ) {
153153 case * CommitmentProof_Nonexist :
154154 np := p .Nonexist
155- if isLeft (np .Left , key ) && isRight (np .Right , key ) {
155+ if isLeft (spec , np .Left , key ) && isRight (spec , np .Right , key ) {
156156 return np
157157 }
158158 case * CommitmentProof_Batch :
159159 for _ , sub := range p .Batch .Entries {
160- if np := sub .GetNonexist (); np != nil && isLeft (np .Left , key ) && isRight (np .Right , key ) {
160+ if np := sub .GetNonexist (); np != nil && isLeft (spec , np .Left , key ) && isRight (spec , np .Right , key ) {
161161 return np
162162 }
163163 }
164164 }
165165 return nil
166166}
167167
168- func isLeft (left * ExistenceProof , key []byte ) bool {
169- return left == nil || bytes .Compare (left .Key , key ) < 0
168+ func isLeft (spec * ProofSpec , left * ExistenceProof , key []byte ) bool {
169+ return left == nil || bytes .Compare (keyForComparison ( spec , left .Key ), keyForComparison ( spec , key ) ) < 0
170170}
171171
172- func isRight (right * ExistenceProof , key []byte ) bool {
173- return right == nil || bytes .Compare (right .Key , key ) > 0
172+ func isRight (spec * ProofSpec , right * ExistenceProof , key []byte ) bool {
173+ return right == nil || bytes .Compare (keyForComparison ( spec , right .Key ), keyForComparison ( spec , key ) ) > 0
174174}
0 commit comments