Update for bls scheme 2

This commit is contained in:
mratsim 2018-11-12 10:13:24 +01:00
parent 998771e7e8
commit 6a3c7d6aa5
2 changed files with 8 additions and 8 deletions

View File

@ -20,15 +20,14 @@ import
import milagro_crypto
# nimble install https://github.com/status-im/nim-milagro-crypto@#master
# Defines
# - SigKey (private/secret key) (48 bytes)
# - Signature and AggregatedSignature (97 bytes)
# - VerKey (public key) and AggregatedVerKey (192 bytes)
# - SigKey (private/secret key) (48 bytes - 384-bit)
# - Signature (48 bytes - 384-bit)
# - VerKey (public key) (192 bytes)
type
# Alias
BLSPublicKey* = VerKey
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
Uint24* = range[0'u32 .. 0xFFFFFF'u32] # TODO: wrap-around
@ -96,7 +95,7 @@ type
attester_bitfield*: IntSet # Who is participating
justified_slot*: int64
justified_block_hash: Blake2_256_Digest
aggregate_sig*: BLSaggregateSig # The actual signature
aggregate_sig*: Signature # The actual signature
ValidatorStatusCodes* {.pure.} = enum
PendingActivation = 0

View File

@ -58,12 +58,13 @@ func process_block*(active_state: ActiveState, crystallized_state: CrystallizedS
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
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:
if attester_idx in attestation.attester_bitfield:
let validator = crystallized_state.validators[attester_idx]
all_pubkeys.add validator.pubkey
let agg_pubkey = all_pubkeys.initAggregatedKey()
if empty: agg_pubkey = validator.pubkey
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.
var msg: array[32, byte]