Skip to content

Commit

Permalink
proof generation panic
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Aug 7, 2023
1 parent b2d852d commit 33f049b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,42 @@ func TestStatelessDeserializeDepth2(t *testing.T) {
t.Fatal("differing commitment for child #0")
}
}

func TestProofOfAbsenceBorderCase(t *testing.T) {
root := New()

key1, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000001")
key2, _ := hex.DecodeString("0001000000000000000000000000000000000000000000000000000000000001")

// Insert an arbitrary value at key 0000000000000000000000000000000000000000000000000000000000000001
root.Insert(oneKeyTest, fourtyKeyTest, nil)

// Generate a proof for the following keys:
// - key1, which is present.
// - key2, which isn't present.
// Note that all three keys will land on the same leaf value.

This comment has been minimized.

Copy link
@jsign

jsign Aug 7, 2023

Author Collaborator

Note/typo: should say two keys.

proof, _, _, _, _ := MakeVerkleMultiProof(root, keylist{key1, key2})

serialized, statediff, err := SerializeProof(proof)
if err != nil {
t.Fatalf("could not serialize proof: %v", err)
}

dproof, err := DeserializeProof(serialized, statediff)
if err != nil {
t.Fatalf("error deserializing proof: %v", err)
}

droot, err := TreeFromProof(dproof, root.Commit())
if err != nil {
t.Fatal(err)
}

if !Equal(droot.Commit(), root.Commit()) {
t.Fatal("differing root commitments")
}

if !Equal(droot.(*InternalNode).children[0].Commit(), root.(*InternalNode).children[0].Commit()) {
t.Fatal("differing commitment for child #0")
}
}
2 changes: 1 addition & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ func (n *LeafNode) GetProofItems(keys keylist) (*ProofElements, []byte, [][]byte
if len(esses) == 0 {
esses = append(esses, extStatusAbsentOther|(n.depth<<3))
poass = append(poass, n.stem)
pe.Vals = append(pe.Vals, nil)
pe.Vals = append(pe.Vals, nil) // jsign comment: there's the cause.
}
continue
}
Expand Down

0 comments on commit 33f049b

Please sign in to comment.