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

Merkleise SSZ container elements #595

Merged
merged 1 commit into from
Feb 12, 2019
Merged

Merkleise SSZ container elements #595

merged 1 commit into from
Feb 12, 2019

Conversation

JustinDrake
Copy link
Collaborator

Reasons to use merkle_hash instead of hash for containers:

  1. Smaller witnesses: BeaconState is a somewhat wide container (26 fields as of now, likely 30+ in phase 2). With concatenation and plain concatenation the size of the Merkle witnesses for the top level are ~32 bytes per field element.
  2. Faster incremental hashing
  3. Consistency: Consistent with merkle_hash for lists/vectors.

Reasons to use `merkle_hash` instead of  `hash` for containers:

1) **Smaller witnesses**: `BeaconState` is a somewhat wide container (26 fields as of now, likely 30+ in phase 2). With concatenation and plain concatenation the size of the Merkle witnesses for the top level are ~32 bytes per field element.
2) **Faster incremental hashing**
3) **Consistency**: Consistent with `merkle_hash` for lists/vectors.
@vbuterin
Copy link
Contributor

The main practical downside I see is that it would increase the cost of re-hashing a validator record. That said, if we use the existing merkle_hash function with a 128 byte chunk size, then I suppose the slowdown is not large, and we still get the largest part of the gain in terms of reducing the portion of the Merkle proof that passes through the top-level state object....

@hwwhww hwwhww added the scope:SSZ Simple Serialize label Feb 11, 2019
@djrtwo
Copy link
Contributor

djrtwo commented Feb 11, 2019

We don't frequently re-hash individual validator records because we pulled balances out to a separate array so I think this is fine.

@JustinDrake
Copy link
Collaborator Author

it would increase the cost of re-hashing a validator record

Would it not decrease the cost of re-hashing? A validator container has 7 fields. For the sake of argument, let's say we update one field and that SSZ chunks are 32 bytes. Without Merkleisation we would have 7*32 = 224 bytes of hashing overhead. With Merkleisation we would have log2(ceil(7))*32 = 96 bytes of overhead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:SSZ Simple Serialize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants