Skip to content

SyncCommitteeContribution construction #837

Closed
@Arkenan

Description

@Arkenan

A sync aggregator must collect all valid sync_committee_messages from the sync_committee_{subnet_id} topic during the selected slot that match its own beacon block root, and then turned into a single SyncCommitteeContribution. Finally, it needs to be signed to build a SignedContributionAndProof struct.

A pseudoelixir code describing this:

sync_message =  get_sync_committee_message(state, block_root, validator_index, privkey)

aggregation_bits = 
  sync_committee_messages
  |> Enum.filter(& &1.beacon_block_root == sync_message.beacon_block_root)
  |> Enum.map(& &1.validator_index |> validator_index_to_sync_committee_index())
  |> Enum.reduce(
    BitVector.new(Constants.sync_committee_size), 
    fn idx, bv -> BitVector.set(bv, idx) end)

# Maybe we can add a BitVector.from_index_list(size, index_list) function that does this last step.

contribution = %SyncCommitteeContribution{
  slot: state.slot,
  beacon_block_root: sync_message.beacon_block_root,
  subcommittee_index: subnet_id,
  aggregation_bits: aggregation_bits,
  signature: bls.Aggregate(Enum.map(sync_committee_messages, & &1.signature))
}

cont = get_contribution_and_proof(state, aggregator_index, contribution, privkey)
sig = get_contribution_and_proof_signature(state, cont, privkey)
%SignedContributionAndProof{messsage: cont, signature: sig}

Spec ref: link

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions