Skip to content

Commit

Permalink
Proof generation panic bug (#398)
Browse files Browse the repository at this point in the history
* proof generation panic

Signed-off-by: Ignacio Hagopian <[email protected]>

* extra test

Signed-off-by: Ignacio Hagopian <[email protected]>

* rebase fixes

Signed-off-by: Ignacio Hagopian <[email protected]>

* add the fix

Signed-off-by: Ignacio Hagopian <[email protected]>

* make linter happy

Signed-off-by: Ignacio Hagopian <[email protected]>

---------

Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign authored Oct 4, 2023
1 parent 1a60d22 commit 0a4e93e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
10 changes: 3 additions & 7 deletions proof_ipa.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,10 @@ func (vp *VerkleProof) Copy() *VerkleProof {
IPAProof: &IPAProof{},
}

for i := range vp.OtherStems {
ret.OtherStems[i] = vp.OtherStems[i]
}

copy(ret.OtherStems, vp.OtherStems)
copy(ret.DepthExtensionPresent, vp.DepthExtensionPresent)
for i := range vp.CommitmentsByPath {
ret.CommitmentsByPath[i] = vp.CommitmentsByPath[i]
}
copy(ret.CommitmentsByPath, vp.CommitmentsByPath)

ret.D = vp.D

if vp.IPAProof != nil {
Expand Down
40 changes: 40 additions & 0 deletions proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,3 +902,43 @@ func TestProofVerificationWithPostState(t *testing.T) {
})
}
}
func TestProofOfAbsenceBorderCase(t *testing.T) {
root := New()

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

// Insert an arbitrary value at key 0000000000000000000000000000000000000000000000000000000000000001
if err := root.Insert(key1, fourtyKeyTest, nil); err != nil {
t.Fatalf("could not insert key: %v", err)
}

// 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.
proof, _, _, _, _ := MakeVerkleMultiProof(root, nil, keylist{key1, key2}, nil)

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 := PreStateTreeFromProof(dproof, root.Commit())
if err != nil {
t.Fatal(err)
}

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

if !droot.(*InternalNode).children[0].Commit().Equal(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 @@ -1410,8 +1410,8 @@ func (n *LeafNode) GetProofItems(keys keylist, _ NodeResolverFn) (*ProofElements
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)
continue
}

Expand Down

0 comments on commit 0a4e93e

Please sign in to comment.