mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-02 01:36:06 +00:00
Update for bls scheme 2
This commit is contained in:
parent
998771e7e8
commit
6a3c7d6aa5
@ -20,15 +20,14 @@ import
|
|||||||
import milagro_crypto
|
import milagro_crypto
|
||||||
# nimble install https://github.com/status-im/nim-milagro-crypto@#master
|
# nimble install https://github.com/status-im/nim-milagro-crypto@#master
|
||||||
# Defines
|
# Defines
|
||||||
# - SigKey (private/secret key) (48 bytes)
|
# - SigKey (private/secret key) (48 bytes - 384-bit)
|
||||||
# - Signature and AggregatedSignature (97 bytes)
|
# - Signature (48 bytes - 384-bit)
|
||||||
# - VerKey (public key) and AggregatedVerKey (192 bytes)
|
# - VerKey (public key) (192 bytes)
|
||||||
|
|
||||||
type
|
type
|
||||||
# Alias
|
# Alias
|
||||||
BLSPublicKey* = VerKey
|
BLSPublicKey* = VerKey
|
||||||
BLSsig* = Signature
|
BLSsig* = Signature
|
||||||
BLSaggregateSig* = AggregatedSignature
|
|
||||||
Blake2_256_Digest* = Hash256 # TODO change to Blake2b-512[0 ..< 32] see https://github.com/status-im/nim-beacon-chain/issues/3
|
Blake2_256_Digest* = Hash256 # TODO change to Blake2b-512[0 ..< 32] see https://github.com/status-im/nim-beacon-chain/issues/3
|
||||||
Uint24* = range[0'u32 .. 0xFFFFFF'u32] # TODO: wrap-around
|
Uint24* = range[0'u32 .. 0xFFFFFF'u32] # TODO: wrap-around
|
||||||
|
|
||||||
@ -96,7 +95,7 @@ type
|
|||||||
attester_bitfield*: IntSet # Who is participating
|
attester_bitfield*: IntSet # Who is participating
|
||||||
justified_slot*: int64
|
justified_slot*: int64
|
||||||
justified_block_hash: Blake2_256_Digest
|
justified_block_hash: Blake2_256_Digest
|
||||||
aggregate_sig*: BLSaggregateSig # The actual signature
|
aggregate_sig*: Signature # The actual signature
|
||||||
|
|
||||||
ValidatorStatusCodes* {.pure.} = enum
|
ValidatorStatusCodes* {.pure.} = enum
|
||||||
PendingActivation = 0
|
PendingActivation = 0
|
||||||
|
@ -58,12 +58,13 @@ func process_block*(active_state: ActiveState, crystallized_state: CrystallizedS
|
|||||||
doAssert attestation.attester_bitfield.len == attestation_indices.committee.len
|
doAssert attestation.attester_bitfield.len == attestation_indices.committee.len
|
||||||
|
|
||||||
# Derive a group public key by adding the public keys of all of the attesters in attestation_indices for whom the corresponding bit in attester_bitfield (the ith bit is (attester_bitfield[i // 8] >> (7 - (i %8))) % 2) equals 1
|
# Derive a group public key by adding the public keys of all of the attesters in attestation_indices for whom the corresponding bit in attester_bitfield (the ith bit is (attester_bitfield[i // 8] >> (7 - (i %8))) % 2) equals 1
|
||||||
var all_pubkeys: seq[BLSPublicKey] # We have to collect all pubkeys first as aggregate public keys need sorting to avoid some attacks.
|
var agg_pubkey: BLSPublicKey
|
||||||
|
var empty: bool
|
||||||
for attester_idx in attestation_indices.committee:
|
for attester_idx in attestation_indices.committee:
|
||||||
if attester_idx in attestation.attester_bitfield:
|
if attester_idx in attestation.attester_bitfield:
|
||||||
let validator = crystallized_state.validators[attester_idx]
|
let validator = crystallized_state.validators[attester_idx]
|
||||||
all_pubkeys.add validator.pubkey
|
if empty: agg_pubkey = validator.pubkey
|
||||||
let agg_pubkey = all_pubkeys.initAggregatedKey()
|
else: agg_pubkey.combine(validator.pubkey)
|
||||||
|
|
||||||
# Verify that aggregate_sig verifies using the group pubkey generated and hash((slot % CYCLE_LENGTH).to_bytes(8, 'big') + parent_hashes + shard_id + shard_block_hash) as the message.
|
# Verify that aggregate_sig verifies using the group pubkey generated and hash((slot % CYCLE_LENGTH).to_bytes(8, 'big') + parent_hashes + shard_id + shard_block_hash) as the message.
|
||||||
var msg: array[32, byte]
|
var msg: array[32, byte]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user