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

Remove serialization from consensus #924

Merged
merged 7 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ The initial deployment phases of Ethereum 2.0 are implemented without consensus

### Deposit arguments

The deposit contract has a single `deposit` function which takes as argument a SimpleSerialize'd `DepositData`.
The deposit contract has a single `deposit` function which takes as argument the `DepositData` elements.

### Withdrawal credentials

Expand Down Expand Up @@ -2127,7 +2127,7 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:

# Verify the Merkle branch
merkle_branch_is_valid = verify_merkle_branch(
leaf=hash(serialize(deposit.data)), # 48 + 32 + 8 + 96 = 184 bytes serialization
leaf=hash_tree_root(deposit.data),
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this mean that we also need to calculate the SSZ root of the deposit data in the Vyper contract?

Copy link
Collaborator Author

@JustinDrake JustinDrake Apr 14, 2019

Choose a reason for hiding this comment

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

Yes, we need to calculate hash_tree_root in the contract. Assuming def deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], amount: bytes[8], signature: bytes[96]) it's something like:

pubkey_root = hash(pubkey + zero_hash[0:16])
signature_root = hash(
    hash(signature[0:64]) +
    hash(signature[64:96] + zero_hash)
)
hash_tree_root = hash(
    hash(pubkey_root + withdrawal_credentials) +
    hash(amount + zero_hash[0:24] + signature_root)
)

proof=deposit.proof,
depth=DEPOSIT_CONTRACT_TREE_DEPTH,
index=deposit.index,
Expand Down
4 changes: 2 additions & 2 deletions test_libs/pyspec/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def create_mock_genesis_validator_deposits(num_validators, deposit_data_leaves=N
amount=spec.MAX_DEPOSIT_AMOUNT,
proof_of_possession=proof_of_possession,
)
item = hash(deposit_data.serialize())
item = deposit_data.hash_tree_root()
deposit_data_leaves.append(item)
tree = calc_merkle_tree_from_leaves(tuple(deposit_data_leaves))
root = get_merkle_root((tuple(deposit_data_leaves)))
Expand Down Expand Up @@ -208,7 +208,7 @@ def build_deposit(state,
amount):
deposit_data = build_deposit_data(state, pubkey, privkey, amount)

item = hash(deposit_data.serialize())
item = deposit_data.hash_tree_root()
index = len(deposit_data_leaves)
deposit_data_leaves.append(item)
tree = calc_merkle_tree_from_leaves(tuple(deposit_data_leaves))
Expand Down
4 changes: 2 additions & 2 deletions test_libs/pyspec/tests/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def test_deposit_in_block(state):
privkey = privkeys[index]
deposit_data = build_deposit_data(pre_state, pubkey, privkey, spec.MAX_DEPOSIT_AMOUNT)

item = hash(deposit_data.serialize())
item = deposit_data.hash_tree_root()
test_deposit_data_leaves.append(item)
tree = calc_merkle_tree_from_leaves(tuple(test_deposit_data_leaves))
root = get_merkle_root((tuple(test_deposit_data_leaves)))
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_deposit_top_up(state):
deposit_data = build_deposit_data(pre_state, pubkey, privkey, amount)

merkle_index = len(test_deposit_data_leaves)
item = hash(deposit_data.serialize())
item = deposit_data.hash_tree_root()
test_deposit_data_leaves.append(item)
tree = calc_merkle_tree_from_leaves(tuple(test_deposit_data_leaves))
root = get_merkle_root((tuple(test_deposit_data_leaves)))
Expand Down