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

Proof generation panic bug #398

Merged
merged 5 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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