Skip to content

Commit dfe43ae

Browse files
authored
Merge pull request #1675 from hwwhww/poc_placeholder
Add proof of custody placeholders
2 parents 1ba9d34 + f1a0b20 commit dfe43ae

21 files changed

+238
-79
lines changed

eth/beacon/deposit_helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ def validate_proof_of_possession(state: BeaconState,
5454
pubkey: BLSPubkey,
5555
proof_of_possession: BLSSignature,
5656
withdrawal_credentials: Hash32,
57-
randao_commitment: Hash32) -> None:
57+
randao_commitment: Hash32,
58+
custody_commitment: Hash32) -> None:
5859
deposit_input = DepositInput(
5960
pubkey=pubkey,
6061
withdrawal_credentials=withdrawal_credentials,
6162
randao_commitment=randao_commitment,
63+
custody_commitment=custody_commitment,
6264
proof_of_possession=EMPTY_SIGNATURE,
6365
)
6466

@@ -119,6 +121,7 @@ def process_deposit(*,
119121
proof_of_possession: BLSSignature,
120122
withdrawal_credentials: Hash32,
121123
randao_commitment: Hash32,
124+
custody_commitment: Hash32,
122125
zero_balance_validator_ttl: int) -> Tuple[BeaconState, ValidatorIndex]:
123126
"""
124127
Process a deposit from Ethereum 1.0.
@@ -129,6 +132,7 @@ def process_deposit(*,
129132
proof_of_possession,
130133
withdrawal_credentials,
131134
randao_commitment,
135+
custody_commitment,
132136
)
133137

134138
validator_pubkeys = tuple(v.pubkey for v in state.validator_registry)
@@ -138,6 +142,7 @@ def process_deposit(*,
138142
withdrawal_credentials=withdrawal_credentials,
139143
randao_commitment=randao_commitment,
140144
latest_status_change_slot=state.slot,
145+
custody_commitment=custody_commitment,
141146
)
142147

143148
state, index = add_pending_validator(

eth/beacon/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ def generate_aggregate_pubkeys(validators: Sequence['ValidatorRecord'],
437437
Compute the aggregate pubkey we expect based on
438438
the proof-of-custody indices found in the ``vote_data``.
439439
"""
440-
proof_of_custody_0_indices = vote_data.aggregate_signature_poc_0_indices
441-
proof_of_custody_1_indices = vote_data.aggregate_signature_poc_1_indices
442-
all_indices = (proof_of_custody_0_indices, proof_of_custody_1_indices)
440+
custody_bit_0_indices = vote_data.custody_bit_0_indices
441+
custody_bit_1_indices = vote_data.custody_bit_1_indices
442+
all_indices = (custody_bit_0_indices, custody_bit_1_indices)
443443
get_pubkeys = functools.partial(get_pubkey_for_indices, validators)
444444
return map(
445445
bls.aggregate_pubkeys,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import rlp
2+
from rlp.sedes import (
3+
Boolean,
4+
)
5+
from eth_typing import (
6+
Hash32,
7+
)
8+
9+
from eth.beacon._utils.hash import (
10+
hash_eth2,
11+
)
12+
13+
from .attestation_data import (
14+
AttestationData,
15+
)
16+
17+
18+
class AttestationDataAndCustodyBit(rlp.Serializable):
19+
"""
20+
Note: using RLP until we have standardized serialization format.
21+
"""
22+
fields = [
23+
# Attestation data
24+
('data', AttestationData),
25+
# Custody bit
26+
('custody_bit', Boolean),
27+
]
28+
29+
def __init__(self,
30+
data: AttestationData,
31+
custody_bit: bool)-> None:
32+
33+
super().__init__(
34+
data=data,
35+
custody_bit=custody_bit,
36+
)
37+
38+
_hash = None
39+
40+
@property
41+
def hash(self) -> Hash32:
42+
if self._hash is None:
43+
self._hash = hash_eth2(rlp.encode(self.data))
44+
return self._hash
45+
46+
@property
47+
def root(self) -> Hash32:
48+
# Alias of `hash`.
49+
# Using flat hash, will likely use SSZ tree hash.
50+
return self.hash

eth/beacon/types/blocks.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@
3939

4040

4141
from .attestations import Attestation
42-
from .proposer_slashings import ProposerSlashing
42+
from .custody_challenges import CustodyChallenge
43+
from .custody_reseeds import CustodyReseed
44+
from .custody_responses import CustodyResponse
4345
from .casper_slashings import CasperSlashing
4446
from .deposits import Deposit
4547
from .exits import Exit
48+
from .proposer_slashings import ProposerSlashing
4649

4750
if TYPE_CHECKING:
4851
from eth.beacon.db.chain import BaseBeaconChainDB # noqa: F401
@@ -53,20 +56,29 @@ class BaseBeaconBlockBody(rlp.Serializable):
5356
('proposer_slashings', CountableList(ProposerSlashing)),
5457
('casper_slashings', CountableList(CasperSlashing)),
5558
('attestations', CountableList(Attestation)),
59+
('custody_reseeds', CountableList(CustodyReseed)),
60+
('custody_challenges', CountableList(CustodyChallenge)),
61+
('custody_responses', CountableList(CustodyResponse)),
5662
('deposits', CountableList(Deposit)),
5763
('exits', CountableList(Exit)),
5864
]
5965

6066
def __init__(self,
61-
proposer_slashings: Sequence[int],
62-
casper_slashings: Sequence[int],
63-
attestations: Sequence[int],
64-
deposits: Sequence[int],
65-
exits: Sequence[int])-> None:
67+
proposer_slashings: Sequence[ProposerSlashing],
68+
casper_slashings: Sequence[CasperSlashing],
69+
attestations: Sequence[Attestation],
70+
custody_reseeds: Sequence[CustodyReseed],
71+
custody_challenges: Sequence[CustodyResponse],
72+
custody_responses: Sequence[CustodyResponse],
73+
deposits: Sequence[Deposit],
74+
exits: Sequence[Exit])-> None:
6675
super().__init__(
6776
proposer_slashings=proposer_slashings,
6877
casper_slashings=casper_slashings,
6978
attestations=attestations,
79+
custody_reseeds=custody_reseeds,
80+
custody_challenges=custody_challenges,
81+
custody_responses=custody_responses,
7082
deposits=deposits,
7183
exits=exits,
7284
)
@@ -166,6 +178,9 @@ def from_root(cls, root: Hash32, chaindb: 'BaseBeaconChainDB') -> 'BeaconBlock':
166178
proposer_slashings=block.body.proposer_slashings,
167179
casper_slashings=block.body.casper_slashings,
168180
attestations=block.body.attestations,
181+
custody_reseeds=block.body.custody_reseeds,
182+
custody_challenges=block.body.custody_challenges,
183+
custody_responses=block.body.custody_responses,
169184
deposits=block.body.deposits,
170185
exits=block.body.exits,
171186
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import rlp
2+
3+
4+
class CustodyChallenge(rlp.Serializable):
5+
pass

eth/beacon/types/custody_reseeds.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import rlp
2+
3+
4+
class CustodyReseed(rlp.Serializable):
5+
pass

eth/beacon/types/custody_responses.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import rlp
2+
3+
4+
class CustodyResponse(rlp.Serializable):
5+
pass

eth/beacon/types/deposit_input.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class DepositInput(rlp.Serializable):
2929
('withdrawal_credentials', hash32),
3030
# Initial RANDAO commitment
3131
('randao_commitment', hash32),
32+
# Initial proof of custody commitment
33+
('custody_commitment', hash32),
3234
# BLS proof of possession (a BLS signature)
3335
('proof_of_possession', CountableList(uint384)),
3436
]
@@ -37,11 +39,13 @@ def __init__(self,
3739
pubkey: BLSPubkey,
3840
withdrawal_credentials: Hash32,
3941
randao_commitment: Hash32,
42+
custody_commitment: Hash32,
4043
proof_of_possession: BLSSignature=EMPTY_SIGNATURE) -> None:
4144
super().__init__(
4245
pubkey=pubkey,
4346
withdrawal_credentials=withdrawal_credentials,
4447
randao_commitment=randao_commitment,
48+
custody_commitment=custody_commitment,
4549
proof_of_possession=proof_of_possession,
4650
)
4751

eth/beacon/types/pending_attestation_records.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class PendingAttestationRecord(rlp.Serializable):
2525
('data', AttestationData),
2626
# Attester participation bitfield
2727
('participation_bitfield', binary),
28-
# Proof of custody bitfield
28+
# Custody bitfield
2929
('custody_bitfield', binary),
30-
# Slot in which it was included
30+
# Slot the attestation was included
3131
('slot_included', uint64),
3232
]
3333

eth/beacon/types/slashable_vote_data.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,32 @@
2121
from eth.beacon.constants import EMPTY_SIGNATURE
2222

2323
from .attestation_data import AttestationData
24+
from .attestation_data_and_custody_bits import AttestationDataAndCustodyBit
2425

2526

2627
class SlashableVoteData(rlp.Serializable):
2728
"""
2829
Note: using RLP until we have standardized serialization format.
2930
"""
3031
fields = [
31-
# Proof-of-custody indices (0 bits)
32-
('aggregate_signature_poc_0_indices', CountableList(uint24)),
33-
# Proof-of-custody indices (1 bits)
34-
('aggregate_signature_poc_1_indices', CountableList(uint24)),
32+
# Validator indices with custody bit equal to 0
33+
('custody_bit_0_indices', CountableList(uint24)),
34+
# Validator indices with custody bit equal to 1
35+
('custody_bit_1_indices', CountableList(uint24)),
3536
# Attestation data
3637
('data', AttestationData),
3738
# Aggregate signature
3839
('aggregate_signature', CountableList(uint384)),
3940
]
4041

4142
def __init__(self,
42-
aggregate_signature_poc_0_indices: Sequence[ValidatorIndex],
43-
aggregate_signature_poc_1_indices: Sequence[ValidatorIndex],
43+
custody_bit_0_indices: Sequence[ValidatorIndex],
44+
custody_bit_1_indices: Sequence[ValidatorIndex],
4445
data: AttestationData,
4546
aggregate_signature: BLSSignature = EMPTY_SIGNATURE) -> None:
4647
super().__init__(
47-
aggregate_signature_poc_0_indices,
48-
aggregate_signature_poc_1_indices,
48+
custody_bit_0_indices,
49+
custody_bit_1_indices,
4950
data,
5051
aggregate_signature,
5152
)
@@ -69,19 +70,18 @@ def root(self) -> Hash32:
6970
@property
7071
def vote_count(self) -> int:
7172
if self._vote_count is None:
72-
count_zero_indices = len(self.aggregate_signature_poc_0_indices)
73-
count_one_indices = len(self.aggregate_signature_poc_1_indices)
73+
count_zero_indices = len(self.custody_bit_0_indices)
74+
count_one_indices = len(self.custody_bit_1_indices)
7475
self._vote_count = count_zero_indices + count_one_indices
7576
return self._vote_count
7677

7778
@property
78-
def messages(self) -> Tuple[bytes, bytes]:
79+
def messages(self) -> Tuple[Hash32, Hash32]:
7980
"""
8081
Build the messages that validators are expected to sign for a ``CasperSlashing`` operation.
8182
"""
82-
# TODO: change to hash_tree_root(vote_data) when we have SSZ tree hashing
83-
vote_data_root = self.root
83+
# TODO: change to hash_tree_root when we have SSZ tree hashing
8484
return (
85-
vote_data_root + (0).to_bytes(1, 'big'),
86-
vote_data_root + (1).to_bytes(1, 'big'),
85+
AttestationDataAndCustodyBit(self.data, False).root,
86+
AttestationDataAndCustodyBit(self.data, True).root,
8787
)

0 commit comments

Comments
 (0)