Skip to content

Commit d3b7a5a

Browse files
committed
Add proof of custody placeholders
1 parent 1ba9d34 commit d3b7a5a

13 files changed

+103
-12
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/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/states.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
from .pending_attestation_records import PendingAttestationRecord
3535
from .candidate_pow_receipt_root_records import CandidatePoWReceiptRootRecord
36+
from .custody_challenges import CustodyChallenge
3637
from .crosslink_records import CrosslinkRecord
3738
from .fork_data import ForkData
3839
from .shard_committees import ShardCommittee
@@ -64,6 +65,10 @@ class BeaconState(rlp.Serializable):
6465
('persistent_committees', CountableList(CountableList(uint24))),
6566
('persistent_committee_reassignments', CountableList(ShardReassignmentRecord)),
6667

68+
69+
# Proof of custody
70+
('custody_challenges', CountableList(CustodyChallenge)),
71+
6772
# Finality
6873
('previous_justified_slot', uint64),
6974
('justified_slot', uint64),
@@ -103,6 +108,7 @@ def __init__(
103108
shard_committees_at_slots: Sequence[Sequence[ShardCommittee]]=(),
104109
persistent_committees: Sequence[Sequence[ValidatorIndex]]=(),
105110
persistent_committee_reassignments: Sequence[ShardReassignmentRecord]=(),
111+
custody_challenges: Sequence[CustodyChallenge]=(),
106112
latest_crosslinks: Sequence[CrosslinkRecord]=(),
107113
latest_block_roots: Sequence[Hash32]=(),
108114
latest_penalized_exit_balances: Sequence[Gwei]=(),
@@ -127,6 +133,8 @@ def __init__(
127133
shard_committees_at_slots=shard_committees_at_slots,
128134
persistent_committees=persistent_committees,
129135
persistent_committee_reassignments=persistent_committee_reassignments,
136+
# Proof of Custody
137+
custody_challenges=custody_challenges,
130138
# Finality
131139
previous_justified_slot=previous_justified_slot,
132140
justified_slot=justified_slot,

eth/beacon/types/validator_records.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class ValidatorRecord(rlp.Serializable):
4242
('latest_status_change_slot', uint64),
4343
# Sequence number when validator exited (or 0)
4444
('exit_count', uint64),
45+
# Proof of custody commitment
46+
('custody_commitment', hash32),
47+
# Slot the proof of custody seed was last changed
48+
('latest_custody_reseed_slot', uint64),
49+
('penultimate_custody_reseed_slot', uint64),
4550
]
4651

4752
def __init__(self,
@@ -51,7 +56,10 @@ def __init__(self,
5156
randao_layers: int,
5257
status: ValidatorStatusCode,
5358
latest_status_change_slot: SlotNumber,
54-
exit_count: int) -> None:
59+
exit_count: int,
60+
custody_commitment: Hash32,
61+
latest_custody_reseed_slot: SlotNumber,
62+
penultimate_custody_reseed_slot: SlotNumber) -> None:
5563
super().__init__(
5664
pubkey=pubkey,
5765
withdrawal_credentials=withdrawal_credentials,
@@ -60,6 +68,9 @@ def __init__(self,
6068
status=status,
6169
latest_status_change_slot=latest_status_change_slot,
6270
exit_count=exit_count,
71+
custody_commitment=custody_commitment,
72+
latest_custody_reseed_slot=latest_custody_reseed_slot,
73+
penultimate_custody_reseed_slot=penultimate_custody_reseed_slot,
6374
)
6475

6576
@property
@@ -74,7 +85,8 @@ def get_pending_validator(cls,
7485
pubkey: BLSPubkey,
7586
withdrawal_credentials: Hash32,
7687
randao_commitment: Hash32,
77-
latest_status_change_slot: SlotNumber) -> 'ValidatorRecord':
88+
latest_status_change_slot: SlotNumber,
89+
custody_commitment: Hash32) -> 'ValidatorRecord':
7890
"""
7991
Return a new pending ``ValidatorRecord`` with the given fields.
8092
"""
@@ -86,4 +98,7 @@ def get_pending_validator(cls,
8698
status=ValidatorStatusCode.PENDING_ACTIVATION,
8799
latest_status_change_slot=latest_status_change_slot,
88100
exit_count=0,
101+
custody_commitment=custody_commitment,
102+
latest_custody_reseed_slot=SlotNumber(0),
103+
penultimate_custody_reseed_slot=SlotNumber(0),
89104
)

tests/beacon/conftest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def sample_beacon_block_body_params():
123123
'proposer_slashings': (),
124124
'casper_slashings': (),
125125
'attestations': (),
126+
'custody_reseeds': (),
127+
'custody_challenges': (),
128+
'custody_responses': (),
126129
'deposits': (),
127130
'exits': (),
128131
}
@@ -157,6 +160,7 @@ def sample_beacon_state_params(sample_fork_data_params):
157160
'shard_committees_at_slots': (),
158161
'persistent_committees': (),
159162
'persistent_committee_reassignments': (),
163+
'custody_challenges': (),
160164
'previous_justified_slot': 0,
161165
'justified_slot': 0,
162166
'justification_bitfield': b'\x00',
@@ -191,9 +195,10 @@ def sample_crosslink_record_params():
191195
def sample_deposit_input_params():
192196
return {
193197
'pubkey': 123,
194-
'proof_of_possession': (0, 0),
195198
'withdrawal_credentials': b'\11' * 32,
196199
'randao_commitment': b'\11' * 32,
200+
'custody_commitment': ZERO_HASH32,
201+
'proof_of_possession': (0, 0),
197202
}
198203

199204

@@ -307,7 +312,10 @@ def sample_validator_record_params():
307312
'randao_layers': 1,
308313
'status': 1,
309314
'latest_status_change_slot': 0,
310-
'exit_count': 0
315+
'exit_count': 0,
316+
'custody_commitment': ZERO_HASH32,
317+
'latest_custody_reseed_slot': 0,
318+
'penultimate_custody_reseed_slot': 0,
311319
}
312320

313321

@@ -549,6 +557,9 @@ def genesis_validators(init_validator_keys,
549557
status=ValidatorStatusCode.ACTIVE,
550558
latest_status_change_slot=0,
551559
exit_count=0,
560+
custody_commitment=ZERO_HASH32,
561+
latest_custody_reseed_slot=0,
562+
penultimate_custody_reseed_slot=0,
552563
) for pub in init_validator_keys
553564
)
554565

tests/beacon/helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def mock_validator_record(pubkey):
1717
status=ValidatorStatusCode.ACTIVE,
1818
latest_status_change_slot=0,
1919
exit_count=0,
20+
custody_commitment=b'\x55' * 32,
21+
latest_custody_reseed_slot=0,
22+
penultimate_custody_reseed_slot=0,
2023
)
2124

2225

0 commit comments

Comments
 (0)