Skip to content

Instantly share code, notes, and snippets.

@benjaminion
Last active January 18, 2022 11:00
Show Gist options
  • Save benjaminion/06465e1b0e441022691bc5939c360831 to your computer and use it in GitHub Desktop.
Save benjaminion/06465e1b0e441022691bc5939c360831 to your computer and use it in GitHub Desktop.
Running the Eth2 spec
> git clone https://github.com/ethereum/consensus-specs.git
> python3 -m venv consensus-specs/
> cd consensus-specs/
> source bin/activate
> python --version
Python 3.8.10
> python setup.py install
... tons of output ...
> make install_test
... some failures, then it installs cytoolz and sorts itself out ...
> python setup.py pyspecdev
> cd tests/core/pyspec/
> # You need to copy sizes.py to here
> python sizes.py | jq
{
"AggregateAndProof": {
"min_size": 337,
"max_size": 593
},
"Attestation": {
"min_size": 229,
"max_size": 485
},
"AttestationData": {
"size": 128
},
"AttesterSlashing": {
"min_size": 464,
"max_size": 33232
},
"BeaconBlock": {
"min_size": 464,
"max_size": 157816
},
"BeaconBlockBody": {
"min_size": 380,
"max_size": 157732
},
"BeaconBlockHeader": {
"size": 112
},
"BeaconState": {
"min_size": 2736629,
"max_size": 152832656015861
},
"Checkpoint": {
"size": 40
},
"ContributionAndProof": {
"size": 264
},
"Deposit": {
"size": 1240
},
"DepositData": {
"size": 184
},
"DepositMessage": {
"size": 88
},
"Eth1Block": {
"size": 48
},
"Eth1Data": {
"size": 72
},
"Fork": {
"size": 16
},
"ForkData": {
"size": 36
},
"HistoricalBatch": {
"size": 524288
},
"IndexedAttestation": {
"min_size": 228,
"max_size": 16612
},
"LightClientUpdate": {
"size": 25364
},
"PendingAttestation": {
"min_size": 149,
"max_size": 405
},
"ProposerSlashing": {
"size": 416
},
"SignedAggregateAndProof": {
"min_size": 437,
"max_size": 693
},
"SignedBeaconBlock": {
"min_size": 564,
"max_size": 157916
},
"SignedBeaconBlockHeader": {
"size": 208
},
"SignedContributionAndProof": {
"size": 360
},
"SignedVoluntaryExit": {
"size": 112
},
"SigningData": {
"size": 64
},
"SyncAggregate": {
"size": 160
},
"SyncAggregatorSelectionData": {
"size": 16
},
"SyncCommittee": {
"size": 24624
},
"SyncCommitteeContribution": {
"size": 160
},
"SyncCommitteeMessage": {
"size": 144
},
"Validator": {
"size": 121
},
"VoluntaryExit": {
"size": 16
},
"MetaData": {
"size": 16
},
"Status": {
"size": 84
},
"Goodbye": {
"size": 8
},
"BeaconBlocksByRange": {
"size": 24
}
}
# From https://gist.github.com/protolambda/db75c7faa1e94f2464787a480e5d613e with minor modifications
from inspect import getmembers, isclass
from eth2spec.utils.ssz.ssz_typing import Container, uint64, Bitvector
from eth2spec.altair import mainnet
from eth2spec.altair.mainnet import ForkDigest, Root, Slot, Epoch
ATTESTATION_SUBNET_COUNT = 64
class MetaData(Container):
seq_number: uint64
attnets: Bitvector[ATTESTATION_SUBNET_COUNT]
class Status(Container):
fork_digest: ForkDigest
finalized_root: Root
finalized_epoch: Epoch
head_root: Root
head_slot: Slot
class Goodbye(uint64):
pass
class BeaconBlocksByRange(Container):
start_slot: Slot
count: uint64
step: uint64
def get_spec_ssz_types():
return [
value for (_, value) in getmembers(mainnet, isclass)
if issubclass(value, Container) and value != Container # only the subclasses, not the imported base class
] + [MetaData, Status, Goodbye, BeaconBlocksByRange]
type_bounds = {
value.__name__: ({
'size': value.type_byte_length()
} if value.is_fixed_byte_length() else {
'min_size': value.min_byte_length(),
'max_size': value.max_byte_length(),
}) for value in get_spec_ssz_types()
}
import json
print(json.dumps(type_bounds))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment