Skip to content

Compute Neighbor during Map Inclusion Verification#772

Merged
gdbelvin merged 3 commits intogoogle:masterfrom
gdbelvin:verifier
Aug 3, 2017
Merged

Compute Neighbor during Map Inclusion Verification#772
gdbelvin merged 3 commits intogoogle:masterfrom
gdbelvin:verifier

Conversation

@gdbelvin
Copy link
Copy Markdown
Contributor

@gdbelvin gdbelvin commented Aug 1, 2017

Have the Map verification algorithm compute the proper neighbor nodes. This is a requirement of verification correctness.

This updates and simplifies the Sibling() logic in storage.NodeID.
The only functional change is masking off the unused bits.

merkle/common.go Outdated
return r
}

// Neighbor returns index with only the left i bits set and the i'th bit flipped.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give a bit more details on this? In particular we have a Sibling() function for logs, which could lead to confusion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move this functionality to Sibling

proof := incl.GetInclusion()

if got, want := leafHash, hasher.HashLeaf(treeID, index, hasher.BitLen(), leaf); !bytes.Equal(got, want) {
if got, want := leafHash, hasher.HashLeaf(treeID, index, 0, leaf); !bytes.Equal(got, want) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need tests at non zero depth?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map doesn't support leaves at non-zero depths, so I think not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need that parameter then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, strictly speaking, we don't.
If we were to support leaves at non-zero levels in the future, we would.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supporting that would be a fairly big change. I could argue for removing this parameter until it's used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the PR to remove it: #769

proof := incl.GetInclusion()

if got, want := leafHash, hasher.HashLeaf(treeID, index, hasher.BitLen(), leaf); !bytes.Equal(got, want) {
if got, want := leafHash, hasher.HashLeaf(treeID, index, 0, leaf); !bytes.Equal(got, want) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supporting that would be a fairly big change. I could argue for removing this parameter until it's used.

storage/types.go Outdated
return n
}

// Neighbor sets this node to be it's own neighbor.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not sure if this means the same as Sibling(), or is it equivalent to Sibling() for maps. Can you expand the documentation?

Copy link
Copy Markdown
Contributor Author

@gdbelvin gdbelvin Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this so it does exactly the same thing as the previous version of Sibling. The steps have just been broken up for clarity.

Neighbor is doing the following snippet from the previous:

bi = n.PathLenBits() - n.PrefixLenBits + i ==
height = n.PathLenBits() - (n.PrefixLenBits - i)
r[i].SetBit(bi, n.Bit(bi)^1)

Mask Left is doing this snippet

r[i].PrefixLenBits =  n.PrefixLenBits - i

The only additional piece is Mask which sets the unused bits to 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. it looks like this is only used by maps / SMT. In the C++ version we had Sibling() which was used by logs but that wasn't carried over to the new code. I wanted to make sure that there wasn't going to be API confusion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. In either case, the original functionality has been maintained.

@gdbelvin gdbelvin force-pushed the verifier branch 2 times, most recently from 4bf878f to 4a65a2f Compare August 2, 2017 15:20
@Martin2112
Copy link
Copy Markdown
Contributor

Is this all merged now via other PRs?

@gdbelvin
Copy link
Copy Markdown
Contributor Author

gdbelvin commented Aug 3, 2017

This is not merged yet. Several other PRs have been rebased on it though.

@gdbelvin gdbelvin merged commit baa77c6 into google:master Aug 3, 2017
@gdbelvin gdbelvin deleted the verifier branch August 3, 2017 10:42
@gdbelvin gdbelvin mentioned this pull request Aug 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants