attestationutil

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2021 License: GPL-3.0 Imports: 12 Imported by: 45

Documentation

Overview

Package attestationutil contains useful helpers for converting attestations into indexed form.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttDataIsEqual added in v1.0.0

func AttDataIsEqual(attData1, attData2 *ethpb.AttestationData) bool

AttDataIsEqual this function performs an equality check between 2 attestation data, if they're unequal, it will return false.

func AttestingIndices

func AttestingIndices(bf bitfield.Bitfield, committee []types.ValidatorIndex) ([]uint64, error)

AttestingIndices returns the attesting participants indices from the attestation data. The committee is provided as an argument rather than a imported implementation from the spec definition. Having the committee as an argument allows for re-use of beacon committees when possible.

Spec pseudocode definition:

def get_attesting_indices(state: BeaconState,
                       data: AttestationData,
                       bits: Bitlist[MAX_VALIDATORS_PER_COMMITTEE]) -> Set[ValidatorIndex]:
 """
 Return the set of attesting indices corresponding to ``data`` and ``bits``.
 """
 committee = get_beacon_committee(state, data.slot, data.index)
 return set(index for i, index in enumerate(committee) if bits[i])

func CheckPointIsEqual added in v1.0.0

func CheckPointIsEqual(checkPt1, checkPt2 *ethpb.Checkpoint) bool

CheckPointIsEqual performs an equality check between 2 check points, returns false if unequal.

func ConvertToIndexed

func ConvertToIndexed(ctx context.Context, attestation *ethpb.Attestation, committee []types.ValidatorIndex) (*ethpb.IndexedAttestation, error)

ConvertToIndexed converts attestation to (almost) indexed-verifiable form.

Note about spec pseudocode definition. The state was used by get_attesting_indices to determine the attestation committee. Now that we provide this as an argument, we no longer need to provide a state.

Spec pseudocode definition:

def get_indexed_attestation(state: BeaconState, attestation: Attestation) -> IndexedAttestation:
 """
 Return the indexed attestation corresponding to ``attestation``.
 """
 attesting_indices = get_attesting_indices(state, attestation.data, attestation.aggregation_bits)

 return IndexedAttestation(
     attesting_indices=sorted(attesting_indices),
     data=attestation.data,
     signature=attestation.signature,
 )

func IsValidAttestationIndices added in v1.0.0

func IsValidAttestationIndices(ctx context.Context, indexedAttestation *ethpb.IndexedAttestation) error

IsValidAttestationIndices this helper function performs the first part of the spec indexed attestation validation starting at Check if “indexed_attestation“ comment and ends at Verify aggregate signature comment.

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 VerifyIndexedAttestationSig added in v1.0.0

func VerifyIndexedAttestationSig(ctx context.Context, indexedAtt *ethpb.IndexedAttestation, pubKeys []bls.PublicKey, domain []byte) error

VerifyIndexedAttestationSig this helper function performs the last part of the spec indexed attestation validation starting at Verify aggregate signature comment.

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)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL