|
2 | 2 | repeat,
|
3 | 3 | )
|
4 | 4 |
|
5 |
| -from cytoolz import ( |
6 |
| - pipe |
7 |
| -) |
8 | 5 | from typing import (
|
9 | 6 | Any,
|
10 | 7 | Iterable,
|
|
21 | 18 | Hash32,
|
22 | 19 | )
|
23 | 20 |
|
24 |
| -from eth.utils import bls |
25 |
| -from eth.utils.bitfield import ( |
26 |
| - set_voted, |
27 |
| -) |
28 |
| -from eth.utils.blake import blake |
29 | 21 | from eth.utils.numeric import (
|
30 | 22 | clamp,
|
31 | 23 | )
|
@@ -394,105 +386,3 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
|
394 | 386 | proposer_committee_size=proposer_committee_size,
|
395 | 387 | shards_and_committees=shards_and_committees,
|
396 | 388 | )
|
397 |
| - |
398 |
| - |
399 |
| -# |
400 |
| -# Signatures and Aggregation |
401 |
| -# |
402 |
| -def create_signing_message(slot: int, |
403 |
| - parent_hashes: Iterable[Hash32], |
404 |
| - shard_id: int, |
405 |
| - shard_block_hash: Hash32, |
406 |
| - justified_slot: int) -> bytes: |
407 |
| - # TODO: will be updated to hashed encoded attestation |
408 |
| - return blake( |
409 |
| - slot.to_bytes(8, byteorder='big') + |
410 |
| - b''.join(parent_hashes) + |
411 |
| - shard_id.to_bytes(2, byteorder='big') + |
412 |
| - shard_block_hash + |
413 |
| - justified_slot.to_bytes(8, 'big') |
414 |
| - ) |
415 |
| - |
416 |
| - |
417 |
| -def aggregate_attestation_record(last_justified_slot: int, |
418 |
| - recent_block_hashes: Iterable[Hash32], |
419 |
| - block: 'BaseBeaconBlock', |
420 |
| - votes: Iterable[Tuple[int, bytes, int]], |
421 |
| - proposer_attestation: 'AttestationRecord', |
422 |
| - cycle_length: int) -> 'AttestationRecord': |
423 |
| - """ |
424 |
| - Aggregate the votes. |
425 |
| -
|
426 |
| - TODO: Write tests |
427 |
| - """ |
428 |
| - # Get signing message |
429 |
| - parent_hashes = get_hashes_to_sign( |
430 |
| - recent_block_hashes, |
431 |
| - block, |
432 |
| - cycle_length, |
433 |
| - ) |
434 |
| - message = create_signing_message( |
435 |
| - block.slot_number, |
436 |
| - parent_hashes, |
437 |
| - proposer_attestation.shard_id, |
438 |
| - proposer_attestation.shard_block_hash, |
439 |
| - last_justified_slot, |
440 |
| - ) |
441 |
| - |
442 |
| - # Verify |
443 |
| - # TODO: Verification is very slow, needs to compute in parallel |
444 |
| - voting_sigs, committee_indices = verify_votes(message, votes) |
445 |
| - |
446 |
| - # Aggregate the votes |
447 |
| - bitfield, sigs = aggregate_votes( |
448 |
| - bitfield=proposer_attestation.bitfield, |
449 |
| - sigs=proposer_attestation.aggregate_sig, |
450 |
| - voting_sigs=voting_sigs, |
451 |
| - voting_committee_indices=committee_indices |
452 |
| - ) |
453 |
| - |
454 |
| - return proposer_attestation.copy( |
455 |
| - bitfield=bitfield, |
456 |
| - sigs=bls.aggregate_sigs(sigs), |
457 |
| - ) |
458 |
| - |
459 |
| - |
460 |
| -def verify_votes( |
461 |
| - message: bytes, |
462 |
| - votes: Iterable[Tuple[int, bytes, int]]) -> Tuple[Tuple[bytes, ...], Tuple[int, ...]]: |
463 |
| - """ |
464 |
| - Verify the given votes |
465 |
| - """ |
466 |
| - sigs_with_committe_info = tuple( |
467 |
| - (sig, committee_index) |
468 |
| - for (committee_index, sig, public_key) |
469 |
| - in votes |
470 |
| - if bls.verify(message, public_key, sig) |
471 |
| - ) |
472 |
| - try: |
473 |
| - sigs, committee_indices = zip(*sigs_with_committe_info) |
474 |
| - except ValueError: |
475 |
| - sigs = tuple() |
476 |
| - committee_indices = tuple() |
477 |
| - |
478 |
| - return sigs, committee_indices |
479 |
| - |
480 |
| - |
481 |
| -def aggregate_votes(bitfield: bytes, |
482 |
| - sigs: Iterable[bytes], |
483 |
| - voting_sigs: Iterable[bytes], |
484 |
| - voting_committee_indices: Iterable[int]) -> Tuple[bytes, Tuple[int]]: |
485 |
| - """ |
486 |
| - Aggregate the votes |
487 |
| - """ |
488 |
| - # Update the bitfield and append the signatures |
489 |
| - sigs = tuple(sigs) + tuple(voting_sigs) |
490 |
| - bitfield = pipe( |
491 |
| - bitfield, |
492 |
| - *( |
493 |
| - set_voted(index=committee_index) |
494 |
| - for committee_index in voting_committee_indices |
495 |
| - ) |
496 |
| - ) |
497 |
| - |
498 |
| - return bitfield, bls.aggregate_sigs(sigs) |
0 commit comments