From d9c6d832610c53ea24de078864e8115ac49cbede Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Mon, 26 Aug 2024 19:01:26 -0300 Subject: [PATCH] Added get_sync_committee_selection proof --- .../validator/utils.ex | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/lambda_ethereum_consensus/validator/utils.ex b/lib/lambda_ethereum_consensus/validator/utils.ex index 953b2dec7..c657fbd6b 100644 --- a/lib/lambda_ethereum_consensus/validator/utils.ex +++ b/lib/lambda_ethereum_consensus/validator/utils.ex @@ -102,6 +102,29 @@ defmodule LambdaEthereumConsensus.Validator.Utils do end end + @spec get_sync_committee_selection_proof( + BeaconState.t(), + Types.slot(), + non_neg_integer(), + Bls.privkey() + ) :: + Types.bls_signature() + def get_sync_committee_selection_proof(%BeaconState{} = state, slot, subcommittee_i, privkey) do + domain_sc_selection_proof = Constants.domain_sync_committee_selection_proof() + epoch = Misc.compute_epoch_at_slot(slot) + domain = Accessors.get_domain(state, domain_sc_selection_proof, epoch) + + signing_data = %Types.SyncAggregatorSelectionData{ + slot: slot, + subcommittee_index: subcommittee_i + } + + signing_root = Misc.compute_signing_root(signing_data, domain) + + {:ok, signature} = Bls.sign(privkey, signing_root) + signature + end + # `is_sync_committee_aggregator` equivalent @spec sync_committee_aggregator?(Types.bls_signature()) :: boolean() def sync_committee_aggregator?(signature) do