Skip to content

Commit

Permalink
Fix panic when asking for wrong membership digest from the future
Browse files Browse the repository at this point in the history
  • Loading branch information
iknite committed Mar 14, 2019
1 parent 4487821 commit 4aaf38b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
19 changes: 10 additions & 9 deletions balloon/balloon.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,17 @@ func (b Balloon) QueryDigestMembership(keyDigest hashing.Digest, version uint64)
case err == nil:
proof.Exists = true
proof.ActualVersion = util.BytesAsUint64(leaf.Value)
}

if proof.ActualVersion <= version {
wg.Add(1)
go func() {
defer wg.Done()
historyProof, historyErr = b.historyTree.ProveMembership(proof.ActualVersion, version)
}()
} else {
return nil, fmt.Errorf("Query version %d is not on history tree which version is %d", version, proof.ActualVersion)
if proof.ActualVersion <= version {
wg.Add(1)
go func() {
defer wg.Done()
historyProof, historyErr = b.historyTree.ProveMembership(proof.ActualVersion, version)
}()
} else {
return nil, fmt.Errorf("query version %d is not on history tree which version is %d", version, proof.ActualVersion)
}

}

hyperProof, hyperErr = b.hyperTree.QueryMembership(leaf.Key, leaf.Value)
Expand Down
8 changes: 7 additions & 1 deletion protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,16 @@ type IncrementalResponse struct {
// ToMembershipProof translates internal api balloon.MembershipProof to the
// public struct protocol.MembershipResult.
func ToMembershipResult(key []byte, mp *balloon.MembershipProof) *MembershipResult {

var serialized map[string]hashing.Digest
if mp.HistoryProof != nil && mp.HistoryProof.AuditPath != nil {
serialized = mp.HistoryProof.AuditPath.Serialize()
}

return &MembershipResult{
mp.Exists,
mp.HyperProof.AuditPath,
mp.HistoryProof.AuditPath.Serialize(),
serialized,
mp.CurrentVersion,
mp.QueryVersion,
mp.ActualVersion,
Expand Down

0 comments on commit 4aaf38b

Please sign in to comment.