Documentation ¶
Overview ¶
Package blocks contains block processing libraries according to the Ethereum beacon chain spec.
Index ¶
- Variables
- func ActivateValidatorWithEffectiveBalance(beaconState state.BeaconState, deposits []*ethpb.Deposit) (state.BeaconState, error)
- func AreEth1DataEqual(a, b *ethpb.Eth1Data) bool
- func AttestationSignatureBatch(ctx context.Context, beaconState state.ReadOnlyBeaconState, ...) (*bls.SignatureBatch, error)
- func BatchVerifyDepositsSignatures(ctx context.Context, deposits []*ethpb.Deposit) (bool, error)
- func BlockSignatureBatch(beaconState state.ReadOnlyBeaconState, proposerIndex types.ValidatorIndex, ...) (*bls.SignatureBatch, error)
- func Eth1DataHasEnoughSupport(beaconState state.ReadOnlyBeaconState, data *ethpb.Eth1Data) (bool, error)
- func GetBlockPayloadHash(blk interfaces.BeaconBlock) ([32]byte, error)
- func IsExecutionBlock(body interfaces.BeaconBlockBody) (bool, error)
- func IsExecutionEnabled(st state.BeaconState, body interfaces.BeaconBlockBody) (bool, error)
- func IsExecutionEnabledUsingHeader(header *enginev1.ExecutionPayloadHeader, body interfaces.BeaconBlockBody) (bool, error)
- func IsMergeTransitionComplete(st state.BeaconState) (bool, error)
- func IsPreBellatrixVersion(v int) bool
- func IsSlashableAttestationData(data1, data2 *ethpb.AttestationData) bool
- func NewGenesisBlock(stateRoot []byte) *ethpb.SignedBeaconBlock
- func ProcessAttestationNoVerifySignature(ctx context.Context, beaconState state.BeaconState, att *ethpb.Attestation) (state.BeaconState, error)
- func ProcessAttestationsNoVerifySignature(ctx context.Context, beaconState state.BeaconState, ...) (state.BeaconState, error)
- func ProcessAttesterSlashing(ctx context.Context, beaconState state.BeaconState, ...) (state.BeaconState, error)
- func ProcessAttesterSlashings(ctx context.Context, beaconState state.BeaconState, ...) (state.BeaconState, error)
- func ProcessBLSToExecutionChange(st state.BeaconState, signed *ethpb.SignedBLSToExecutionChange) (state.BeaconState, error)
- func ProcessBlockHeader(ctx context.Context, beaconState state.BeaconState, ...) (state.BeaconState, error)
- func ProcessBlockHeaderNoVerify(ctx context.Context, beaconState state.BeaconState, slot types.Slot, ...) (state.BeaconState, error)
- func ProcessDeposit(beaconState state.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (state.BeaconState, bool, error)
- func ProcessDeposits(ctx context.Context, beaconState state.BeaconState, deposits []*ethpb.Deposit) (state.BeaconState, error)
- func ProcessEth1DataInBlock(_ context.Context, beaconState state.BeaconState, eth1Data *ethpb.Eth1Data) (state.BeaconState, error)
- func ProcessPayload(st state.BeaconState, payload interfaces.ExecutionData) (state.BeaconState, error)
- func ProcessPayloadHeader(st state.BeaconState, header interfaces.ExecutionData) (state.BeaconState, error)
- func ProcessPreGenesisDeposits(ctx context.Context, beaconState state.BeaconState, deposits []*ethpb.Deposit) (state.BeaconState, error)
- func ProcessProposerSlashing(ctx context.Context, beaconState state.BeaconState, ...) (state.BeaconState, error)
- func ProcessProposerSlashings(ctx context.Context, beaconState state.BeaconState, ...) (state.BeaconState, error)
- func ProcessRandao(ctx context.Context, beaconState state.BeaconState, ...) (state.BeaconState, error)
- func ProcessRandaoNoVerify(beaconState state.BeaconState, randaoReveal []byte) (state.BeaconState, error)
- func ProcessVoluntaryExits(ctx context.Context, beaconState state.BeaconState, ...) (state.BeaconState, error)
- func RandaoSignatureBatch(ctx context.Context, beaconState state.ReadOnlyBeaconState, reveal []byte) (*bls.SignatureBatch, error)
- func SlashableAttesterIndices(slashing *ethpb.AttesterSlashing) []uint64
- func ValidatePayload(st state.BeaconState, payload interfaces.ExecutionData) error
- func ValidatePayloadHeader(st state.BeaconState, header interfaces.ExecutionData) error
- func ValidatePayloadHeaderWhenMergeCompletes(st state.BeaconState, header interfaces.ExecutionData) error
- func ValidatePayloadWhenMergeCompletes(st state.BeaconState, payload interfaces.ExecutionData) error
- func VerifyAttestationNoVerifySignature(ctx context.Context, beaconState state.ReadOnlyBeaconState, ...) error
- func VerifyAttestationSignature(ctx context.Context, beaconState state.ReadOnlyBeaconState, ...) error
- func VerifyAttesterSlashing(ctx context.Context, beaconState state.ReadOnlyBeaconState, ...) error
- func VerifyBlockHeaderSignature(beaconState state.BeaconState, header *ethpb.SignedBeaconBlockHeader) error
- func VerifyBlockSignature(beaconState state.ReadOnlyBeaconState, proposerIndex types.ValidatorIndex, ...) error
- func VerifyBlockSignatureUsingCurrentFork(beaconState state.ReadOnlyBeaconState, blk interfaces.SignedBeaconBlock) error
- func VerifyExitAndSignature(validator state.ReadOnlyValidator, currentSlot types.Slot, fork *ethpb.Fork, ...) error
- func VerifyIndexedAttestation(ctx context.Context, beaconState state.ReadOnlyBeaconState, ...) error
- func VerifyProposerSlashing(beaconState state.ReadOnlyBeaconState, slashing *ethpb.ProposerSlashing) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidPayloadBlockHash = errors.New("invalid payload block hash") ErrInvalidPayloadTimeStamp = errors.New("invalid payload timestamp") ErrInvalidPayloadPrevRandao = errors.New("invalid payload previous randao") )
var ValidatorAlreadyExitedMsg = "has already submitted an exit, which will take place at epoch"
ValidatorAlreadyExitedMsg defines a message saying that a validator has already exited.
var ValidatorCannotExitYetMsg = "validator has not been active long enough to exit"
ValidatorCannotExitYetMsg defines a message saying that a validator cannot exit because it has not been active long enough.
Functions ¶
func ActivateValidatorWithEffectiveBalance ¶
func ActivateValidatorWithEffectiveBalance(beaconState state.BeaconState, deposits []*ethpb.Deposit) (state.BeaconState, error)
ActivateValidatorWithEffectiveBalance updates validator's effective balance, and if it's above MaxEffectiveBalance, validator becomes active in genesis.
func AreEth1DataEqual ¶
AreEth1DataEqual checks equality between two eth1 data objects.
func AttestationSignatureBatch ¶
func AttestationSignatureBatch(ctx context.Context, beaconState state.ReadOnlyBeaconState, atts []*ethpb.Attestation) (*bls.SignatureBatch, error)
AttestationSignatureBatch retrieves all the related attestation signature data such as the relevant public keys, signatures and attestation signing data and collate it into a signature batch object.
func BatchVerifyDepositsSignatures ¶
BatchVerifyDepositsSignatures batch verifies deposit signatures.
func BlockSignatureBatch ¶
func BlockSignatureBatch(beaconState state.ReadOnlyBeaconState, proposerIndex types.ValidatorIndex, sig []byte, rootFunc func() ([32]byte, error)) (*bls.SignatureBatch, error)
BlockSignatureBatch retrieves the block signature batch from the provided block and its corresponding state.
func Eth1DataHasEnoughSupport ¶
func Eth1DataHasEnoughSupport(beaconState state.ReadOnlyBeaconState, data *ethpb.Eth1Data) (bool, error)
Eth1DataHasEnoughSupport returns true when the given eth1data has more than 50% votes in the eth1 voting period. A vote is cast by including eth1data in a block and part of state processing appends eth1data to the state in the Eth1DataVotes list. Iterating through this list checks the votes to see if they match the eth1data.
func GetBlockPayloadHash ¶
func GetBlockPayloadHash(blk interfaces.BeaconBlock) ([32]byte, error)
GetBlockPayloadHash returns the hash of the execution payload of the block
func IsExecutionBlock ¶
func IsExecutionBlock(body interfaces.BeaconBlockBody) (bool, error)
IsExecutionBlock returns whether the block has a non-empty ExecutionPayload.
Spec code: def is_execution_block(block: BeaconBlock) -> bool:
return block.body.execution_payload != ExecutionPayload()
func IsExecutionEnabled ¶
func IsExecutionEnabled(st state.BeaconState, body interfaces.BeaconBlockBody) (bool, error)
IsExecutionEnabled returns true if the beacon chain can begin executing. Meaning the payload header is beacon state is non-empty or the payload in block body is non-empty.
Spec code: def is_execution_enabled(state: BeaconState, body: BeaconBlockBody) -> bool:
return is_merge_block(state, body) or is_merge_complete(state)
func IsExecutionEnabledUsingHeader ¶
func IsExecutionEnabledUsingHeader(header *enginev1.ExecutionPayloadHeader, body interfaces.BeaconBlockBody) (bool, error)
IsExecutionEnabledUsingHeader returns true if the execution is enabled using post processed payload header and block body. This is an optimized version of IsExecutionEnabled where beacon state is not required as an argument.
func IsMergeTransitionComplete ¶
func IsMergeTransitionComplete(st state.BeaconState) (bool, error)
IsMergeTransitionComplete returns true if the transition to Bellatrix has completed. Meaning the payload header in beacon state is not `ExecutionPayloadHeader()` (i.e. not empty).
Spec code: def is_merge_transition_complete(state: BeaconState) -> bool:
return state.latest_execution_payload_header != ExecutionPayloadHeader()
func IsPreBellatrixVersion ¶
IsPreBellatrixVersion returns true if input version is before bellatrix fork.
func IsSlashableAttestationData ¶
func IsSlashableAttestationData(data1, data2 *ethpb.AttestationData) bool
IsSlashableAttestationData verifies a slashing against the Casper Proof of Stake FFG rules.
Spec pseudocode definition:
def is_slashable_attestation_data(data_1: AttestationData, data_2: AttestationData) -> bool: """ Check if ``data_1`` and ``data_2`` are slashable according to Casper FFG rules. """ return ( # Double vote (data_1 != data_2 and data_1.target.epoch == data_2.target.epoch) or # Surround vote (data_1.source.epoch < data_2.source.epoch and data_2.target.epoch < data_1.target.epoch) )
func NewGenesisBlock ¶
func NewGenesisBlock(stateRoot []byte) *ethpb.SignedBeaconBlock
NewGenesisBlock returns the canonical, genesis block for the beacon chain protocol.
func ProcessAttestationNoVerifySignature ¶
func ProcessAttestationNoVerifySignature( ctx context.Context, beaconState state.BeaconState, att *ethpb.Attestation, ) (state.BeaconState, error)
ProcessAttestationNoVerifySignature processes the attestation without verifying the attestation signature. This method is used to validate attestations whose signatures have already been verified.
func ProcessAttestationsNoVerifySignature ¶
func ProcessAttestationsNoVerifySignature( ctx context.Context, beaconState state.BeaconState, b interfaces.SignedBeaconBlock, ) (state.BeaconState, error)
ProcessAttestationsNoVerifySignature applies processing operations to a block's inner attestation records. The only difference would be that the attestation signature would not be verified.
func ProcessAttesterSlashing ¶
func ProcessAttesterSlashing( ctx context.Context, beaconState state.BeaconState, slashing *ethpb.AttesterSlashing, slashFunc slashValidatorFunc, ) (state.BeaconState, error)
ProcessAttesterSlashing processes individual attester slashing.
func ProcessAttesterSlashings ¶
func ProcessAttesterSlashings( ctx context.Context, beaconState state.BeaconState, slashings []*ethpb.AttesterSlashing, slashFunc slashValidatorFunc, ) (state.BeaconState, error)
ProcessAttesterSlashings is one of the operations performed on each processed beacon block to slash attesters based on Casper FFG slashing conditions if any slashable events occurred.
Spec pseudocode definition:
def process_attester_slashing(state: BeaconState, attester_slashing: AttesterSlashing) -> None: attestation_1 = attester_slashing.attestation_1 attestation_2 = attester_slashing.attestation_2 assert is_slashable_attestation_data(attestation_1.data, attestation_2.data) assert is_valid_indexed_attestation(state, attestation_1) assert is_valid_indexed_attestation(state, attestation_2) slashed_any = False indices = set(attestation_1.attesting_indices).intersection(attestation_2.attesting_indices) for index in sorted(indices): if is_slashable_validator(state.validators[index], get_current_epoch(state)): slash_validator(state, index) slashed_any = True assert slashed_any
func ProcessBLSToExecutionChange ¶
func ProcessBLSToExecutionChange(st state.BeaconState, signed *ethpb.SignedBLSToExecutionChange) (state.BeaconState, error)
ProcessBLSToExecutionChange validates a SignedBLSToExecution message and changes the validator's withdrawal address accordingly.
Spec pseudocode definition:
def process_bls_to_execution_change(state: BeaconState, signed_address_change: SignedBLSToExecutionChange) -> None:
validator = state.validators[address_change.validator_index] assert validator.withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX assert validator.withdrawal_credentials[1:] == hash(address_change.from_bls_pubkey)[1:] domain = get_domain(state, DOMAIN_BLS_TO_EXECUTION_CHANGE) signing_root = compute_signing_root(address_change, domain) assert bls.Verify(address_change.from_bls_pubkey, signing_root, signed_address_change.signature) validator.withdrawal_credentials = ( ETH1_ADDRESS_WITHDRAWAL_PREFIX + b'\x00' * 11 + address_change.to_execution_address )
func ProcessBlockHeader ¶
func ProcessBlockHeader( ctx context.Context, beaconState state.BeaconState, block interfaces.SignedBeaconBlock, ) (state.BeaconState, error)
ProcessBlockHeader validates a block by its header.
Spec pseudocode definition:
def process_block_header(state: BeaconState, block: BeaconBlock) -> None: # Verify that the slots match assert block.slot == state.slot # Verify that the block is newer than latest block header assert block.slot > state.latest_block_header.slot # Verify that proposer index is the correct index assert block.proposer_index == get_beacon_proposer_index(state) # Verify that the parent matches assert block.parent_root == hash_tree_root(state.latest_block_header) # Cache current block as the new latest block state.latest_block_header = BeaconBlockHeader( slot=block.slot, proposer_index=block.proposer_index, parent_root=block.parent_root, state_root=Bytes32(), # Overwritten in the next process_slot call body_root=hash_tree_root(block.body), ) # Verify proposer is not slashed proposer = state.validators[block.proposer_index] assert not proposer.slashed
func ProcessBlockHeaderNoVerify ¶
func ProcessBlockHeaderNoVerify( ctx context.Context, beaconState state.BeaconState, slot types.Slot, proposerIndex types.ValidatorIndex, parentRoot, bodyRoot []byte, ) (state.BeaconState, error)
ProcessBlockHeaderNoVerify validates a block by its header but skips proposer signature verification.
WARNING: This method does not verify proposer signature. This is used for proposer to compute state root using a unsigned block.
Spec pseudocode definition:
def process_block_header(state: BeaconState, block: BeaconBlock) -> None: # Verify that the slots match assert block.slot == state.slot # Verify that the block is newer than latest block header assert block.slot > state.latest_block_header.slot # Verify that proposer index is the correct index assert block.proposer_index == get_beacon_proposer_index(state) # Verify that the parent matches assert block.parent_root == hash_tree_root(state.latest_block_header) # Cache current block as the new latest block state.latest_block_header = BeaconBlockHeader( slot=block.slot, proposer_index=block.proposer_index, parent_root=block.parent_root, state_root=Bytes32(), # Overwritten in the next process_slot call body_root=hash_tree_root(block.body), ) # Verify proposer is not slashed proposer = state.validators[block.proposer_index] assert not proposer.slashed
func ProcessDeposit ¶
func ProcessDeposit(beaconState state.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (state.BeaconState, bool, error)
ProcessDeposit takes in a deposit object and inserts it into the registry as a new validator or balance change. Returns the resulting state, a boolean to indicate whether or not the deposit resulted in a new validator entry into the beacon state, and any error.
Spec pseudocode definition: def process_deposit(state: BeaconState, deposit: Deposit) -> None:
# Verify the Merkle branch assert is_valid_merkle_branch( leaf=hash_tree_root(deposit.data), branch=deposit.proof, depth=DEPOSIT_CONTRACT_TREE_DEPTH + 1, # Add 1 for the List length mix-in index=state.eth1_deposit_index, root=state.eth1_data.deposit_root, ) # Deposits must be processed in order state.eth1_deposit_index += 1 pubkey = deposit.data.pubkey amount = deposit.data.amount validator_pubkeys = [v.pubkey for v in state.validators] if pubkey not in validator_pubkeys: # Verify the deposit signature (proof of possession) which is not checked by the deposit contract deposit_message = DepositMessage( pubkey=deposit.data.pubkey, withdrawal_credentials=deposit.data.withdrawal_credentials, amount=deposit.data.amount, ) domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks signing_root = compute_signing_root(deposit_message, domain) if not bls.Verify(pubkey, signing_root, deposit.data.signature): return # Add validator and balance entries state.validators.append(get_validator_from_deposit(state, deposit)) state.balances.append(amount) else: # Increase balance by deposit amount index = ValidatorIndex(validator_pubkeys.index(pubkey)) increase_balance(state, index, amount)
func ProcessDeposits ¶
func ProcessDeposits( ctx context.Context, beaconState state.BeaconState, deposits []*ethpb.Deposit, ) (state.BeaconState, error)
ProcessDeposits is one of the operations performed on each processed beacon block to verify queued validators from the Ethereum 1.0 Deposit Contract into the beacon chain.
Spec pseudocode definition:
For each deposit in block.body.deposits: process_deposit(state, deposit)
func ProcessEth1DataInBlock ¶
func ProcessEth1DataInBlock(_ context.Context, beaconState state.BeaconState, eth1Data *ethpb.Eth1Data) (state.BeaconState, error)
ProcessEth1DataInBlock is an operation performed on each beacon block to ensure the ETH1 data votes are processed into the beacon state.
Official spec definition:
def process_eth1_data(state: BeaconState, body: BeaconBlockBody) -> None: state.eth1_data_votes.append(body.eth1_data) if state.eth1_data_votes.count(body.eth1_data) * 2 > EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH: state.eth1_data = body.eth1_data
func ProcessPayload ¶
func ProcessPayload(st state.BeaconState, payload interfaces.ExecutionData) (state.BeaconState, error)
ProcessPayload processes input execution payload using beacon state. ValidatePayloadWhenMergeCompletes validates if payload is valid versus input beacon state. These validation steps ONLY apply to post merge.
Spec code: def process_execution_payload(state: BeaconState, payload: ExecutionPayload, execution_engine: ExecutionEngine) -> None:
# Verify consistency of the parent hash with respect to the previous execution payload header if is_merge_complete(state): assert payload.parent_hash == state.latest_execution_payload_header.block_hash # Verify random assert payload.random == get_randao_mix(state, get_current_epoch(state)) # Verify timestamp assert payload.timestamp == compute_timestamp_at_slot(state, state.slot) # Verify the execution payload is valid assert execution_engine.execute_payload(payload) # Cache execution payload header state.latest_execution_payload_header = ExecutionPayloadHeader( parent_hash=payload.parent_hash, FeeRecipient=payload.FeeRecipient, state_root=payload.state_root, receipt_root=payload.receipt_root, logs_bloom=payload.logs_bloom, random=payload.random, block_number=payload.block_number, gas_limit=payload.gas_limit, gas_used=payload.gas_used, timestamp=payload.timestamp, extra_data=payload.extra_data, base_fee_per_gas=payload.base_fee_per_gas, block_hash=payload.block_hash, transactions_root=hash_tree_root(payload.transactions), )
func ProcessPayloadHeader ¶
func ProcessPayloadHeader(st state.BeaconState, header interfaces.ExecutionData) (state.BeaconState, error)
ProcessPayloadHeader processes the payload header.
func ProcessPreGenesisDeposits ¶
func ProcessPreGenesisDeposits( ctx context.Context, beaconState state.BeaconState, deposits []*ethpb.Deposit, ) (state.BeaconState, error)
ProcessPreGenesisDeposits processes a deposit for the beacon state before chainstart.
func ProcessProposerSlashing ¶
func ProcessProposerSlashing( ctx context.Context, beaconState state.BeaconState, slashing *ethpb.ProposerSlashing, slashFunc slashValidatorFunc, ) (state.BeaconState, error)
ProcessProposerSlashing processes individual proposer slashing.
func ProcessProposerSlashings ¶
func ProcessProposerSlashings( ctx context.Context, beaconState state.BeaconState, slashings []*ethpb.ProposerSlashing, slashFunc slashValidatorFunc, ) (state.BeaconState, error)
ProcessProposerSlashings is one of the operations performed on each processed beacon block to slash proposers based on slashing conditions if any slashable events occurred.
Spec pseudocode definition:
def process_proposer_slashing(state: BeaconState, proposer_slashing: ProposerSlashing) -> None: header_1 = proposer_slashing.signed_header_1.message header_2 = proposer_slashing.signed_header_2.message # Verify header slots match assert header_1.slot == header_2.slot # Verify header proposer indices match assert header_1.proposer_index == header_2.proposer_index # Verify the headers are different assert header_1 != header_2 # Verify the proposer is slashable proposer = state.validators[header_1.proposer_index] assert is_slashable_validator(proposer, get_current_epoch(state)) # Verify signatures for signed_header in (proposer_slashing.signed_header_1, proposer_slashing.signed_header_2): domain = get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_at_slot(signed_header.message.slot)) signing_root = compute_signing_root(signed_header.message, domain) assert bls.Verify(proposer.pubkey, signing_root, signed_header.signature) slash_validator(state, header_1.proposer_index)
func ProcessRandao ¶
func ProcessRandao( ctx context.Context, beaconState state.BeaconState, b interfaces.SignedBeaconBlock, ) (state.BeaconState, error)
ProcessRandao checks the block proposer's randao commitment and generates a new randao mix to update in the beacon state's latest randao mixes slice.
Spec pseudocode definition:
def process_randao(state: BeaconState, body: BeaconBlockBody) -> None: epoch = get_current_epoch(state) # Verify RANDAO reveal proposer = state.validators[get_beacon_proposer_index(state)] signing_root = compute_signing_root(epoch, get_domain(state, DOMAIN_RANDAO)) assert bls.Verify(proposer.pubkey, signing_root, body.randao_reveal) # Mix in RANDAO reveal mix = xor(get_randao_mix(state, epoch), hash(body.randao_reveal)) state.randao_mixes[epoch % EPOCHS_PER_HISTORICAL_VECTOR] = mix
func ProcessRandaoNoVerify ¶
func ProcessRandaoNoVerify( beaconState state.BeaconState, randaoReveal []byte, ) (state.BeaconState, error)
ProcessRandaoNoVerify generates a new randao mix to update in the beacon state's latest randao mixes slice.
Spec pseudocode definition:
# Mix it in state.latest_randao_mixes[get_current_epoch(state) % LATEST_RANDAO_MIXES_LENGTH] = ( xor(get_randao_mix(state, get_current_epoch(state)), hash(body.randao_reveal)) )
func ProcessVoluntaryExits ¶
func ProcessVoluntaryExits( ctx context.Context, beaconState state.BeaconState, exits []*ethpb.SignedVoluntaryExit, ) (state.BeaconState, error)
ProcessVoluntaryExits is one of the operations performed on each processed beacon block to determine which validators should exit the state's validator registry.
Spec pseudocode definition:
def process_voluntary_exit(state: BeaconState, signed_voluntary_exit: SignedVoluntaryExit) -> None: voluntary_exit = signed_voluntary_exit.message validator = state.validators[voluntary_exit.validator_index] # Verify the validator is active assert is_active_validator(validator, get_current_epoch(state)) # Verify exit has not been initiated assert validator.exit_epoch == FAR_FUTURE_EPOCH # Exits must specify an epoch when they become valid; they are not valid before then assert get_current_epoch(state) >= voluntary_exit.epoch # Verify the validator has been active long enough assert get_current_epoch(state) >= validator.activation_epoch + SHARD_COMMITTEE_PERIOD # Verify signature domain = get_domain(state, DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch) signing_root = compute_signing_root(voluntary_exit, domain) assert bls.Verify(validator.pubkey, signing_root, signed_voluntary_exit.signature) # Initiate exit initiate_validator_exit(state, voluntary_exit.validator_index)
func RandaoSignatureBatch ¶
func RandaoSignatureBatch( ctx context.Context, beaconState state.ReadOnlyBeaconState, reveal []byte, ) (*bls.SignatureBatch, error)
RandaoSignatureBatch retrieves the relevant randao specific signature batch object from a block and its corresponding state.
func SlashableAttesterIndices ¶
func SlashableAttesterIndices(slashing *ethpb.AttesterSlashing) []uint64
SlashableAttesterIndices returns the intersection of attester indices from both attestations in this slashing.
func ValidatePayload ¶
func ValidatePayload(st state.BeaconState, payload interfaces.ExecutionData) error
ValidatePayload validates if payload is valid versus input beacon state. These validation steps apply to both pre merge and post merge.
Spec code:
# Verify random assert payload.random == get_randao_mix(state, get_current_epoch(state)) # Verify timestamp assert payload.timestamp == compute_timestamp_at_slot(state, state.slot)
func ValidatePayloadHeader ¶
func ValidatePayloadHeader(st state.BeaconState, header interfaces.ExecutionData) error
ValidatePayloadHeader validates the payload header.
func ValidatePayloadHeaderWhenMergeCompletes ¶
func ValidatePayloadHeaderWhenMergeCompletes(st state.BeaconState, header interfaces.ExecutionData) error
ValidatePayloadHeaderWhenMergeCompletes validates the payload header when the merge completes.
func ValidatePayloadWhenMergeCompletes ¶
func ValidatePayloadWhenMergeCompletes(st state.BeaconState, payload interfaces.ExecutionData) error
ValidatePayloadWhenMergeCompletes validates if payload is valid versus input beacon state. These validation steps ONLY apply to post merge.
Spec code:
# Verify consistency of the parent hash with respect to the previous execution payload header if is_merge_complete(state): assert payload.parent_hash == state.latest_execution_payload_header.block_hash
func VerifyAttestationNoVerifySignature ¶
func VerifyAttestationNoVerifySignature( ctx context.Context, beaconState state.ReadOnlyBeaconState, att *ethpb.Attestation, ) error
VerifyAttestationNoVerifySignature verifies the attestation without verifying the attestation signature. This is used before processing attestation with the beacon state.
func VerifyAttestationSignature ¶
func VerifyAttestationSignature(ctx context.Context, beaconState state.ReadOnlyBeaconState, att *ethpb.Attestation) error
VerifyAttestationSignature converts and attestation into an indexed attestation and verifies the signature in that attestation.
func VerifyAttesterSlashing ¶
func VerifyAttesterSlashing(ctx context.Context, beaconState state.ReadOnlyBeaconState, slashing *ethpb.AttesterSlashing) error
VerifyAttesterSlashing validates the attestation data in both attestations in the slashing object.
func VerifyBlockHeaderSignature ¶
func VerifyBlockHeaderSignature(beaconState state.BeaconState, header *ethpb.SignedBeaconBlockHeader) error
VerifyBlockHeaderSignature verifies the proposer signature of a beacon block header.
func VerifyBlockSignature ¶
func VerifyBlockSignature(beaconState state.ReadOnlyBeaconState, proposerIndex types.ValidatorIndex, sig []byte, rootFunc func() ([32]byte, error)) error
VerifyBlockSignature verifies the proposer signature of a beacon block.
func VerifyBlockSignatureUsingCurrentFork ¶
func VerifyBlockSignatureUsingCurrentFork(beaconState state.ReadOnlyBeaconState, blk interfaces.SignedBeaconBlock) error
VerifyBlockSignatureUsingCurrentFork verifies the proposer signature of a beacon block. This differs from the above method by not using fork data from the state and instead retrieving it via the respective epoch.
func VerifyExitAndSignature ¶
func VerifyExitAndSignature( validator state.ReadOnlyValidator, currentSlot types.Slot, fork *ethpb.Fork, signed *ethpb.SignedVoluntaryExit, genesisRoot []byte, ) error
VerifyExitAndSignature implements the spec defined validation for voluntary exits.
Spec pseudocode definition:
def process_voluntary_exit(state: BeaconState, signed_voluntary_exit: SignedVoluntaryExit) -> None: voluntary_exit = signed_voluntary_exit.message validator = state.validators[voluntary_exit.validator_index] # Verify the validator is active assert is_active_validator(validator, get_current_epoch(state)) # Verify exit has not been initiated assert validator.exit_epoch == FAR_FUTURE_EPOCH # Exits must specify an epoch when they become valid; they are not valid before then assert get_current_epoch(state) >= voluntary_exit.epoch # Verify the validator has been active long enough assert get_current_epoch(state) >= validator.activation_epoch + SHARD_COMMITTEE_PERIOD # Verify signature domain = get_domain(state, DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch) signing_root = compute_signing_root(voluntary_exit, domain) assert bls.Verify(validator.pubkey, signing_root, signed_voluntary_exit.signature) # Initiate exit initiate_validator_exit(state, voluntary_exit.validator_index)
func VerifyIndexedAttestation ¶
func VerifyIndexedAttestation(ctx context.Context, beaconState state.ReadOnlyBeaconState, indexedAtt *ethpb.IndexedAttestation) error
VerifyIndexedAttestation determines the validity of an indexed attestation.
Spec pseudocode definition:
def is_valid_indexed_attestation(state: BeaconState, indexed_attestation: IndexedAttestation) -> bool: """ Check if ``indexed_attestation`` is not empty, has sorted and unique indices and has a valid aggregate signature. """ # Verify indices are sorted and unique indices = indexed_attestation.attesting_indices if len(indices) == 0 or not indices == sorted(set(indices)): return False # Verify aggregate signature pubkeys = [state.validators[i].pubkey for i in indices] domain = get_domain(state, DOMAIN_BEACON_ATTESTER, indexed_attestation.data.target.epoch) signing_root = compute_signing_root(indexed_attestation.data, domain) return bls.FastAggregateVerify(pubkeys, signing_root, indexed_attestation.signature)
func VerifyProposerSlashing ¶
func VerifyProposerSlashing( beaconState state.ReadOnlyBeaconState, slashing *ethpb.ProposerSlashing, ) error
VerifyProposerSlashing verifies that the data provided from slashing is valid.
Types ¶
This section is empty.