Skip to content

Commit

Permalink
Use *new* optional_fast_aggregate_verify
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Nov 25, 2020
1 parent edee05c commit f0864b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 18 additions & 1 deletion specs/lightclient/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ This is a standalone beacon chain patch adding light client support via sync com
| - | - |
| `SYNC_COMMITTEE_SIZE` | `uint64(2**10)` (= 1024) |
| `SYNC_COMMITTEE_PUBKEY_AGGREGATES_SIZE` | `uint64(2**6)` (= 64) |
| `G2_INFINITY_POINT_SIG` | `BLSSignature(b'\xc0' + b'\x00' * 95)` |

### Time parameters

Expand Down Expand Up @@ -96,6 +97,22 @@ class SyncCommittee(Container):

## Helper functions

### `Predicates`

#### `optional_fast_aggregate_verify`

```python
def optional_fast_aggregate_verify(pubkeys: Sequence[BLSPubkey], message: Bytes32, signature: BLSSignature) -> bool:
"""
If ``pubkeys`` is an empty list, the given ``signature`` should be a stub ``G2_INFINITY_POINT_SIG``.
Otherwise, verify it with standard BLS FastAggregateVerify API.
"""
if len(pubkeys) == 0:
return signature == G2_INFINITY_POINT_SIG
else:
return bls.FastAggregateVerify(pubkeys, message, signature)
```

### Beacon state accessors

#### `get_sync_committee_indices`
Expand Down Expand Up @@ -159,7 +176,7 @@ def process_sync_committee(state: BeaconState, body: BeaconBlockBody) -> None:
participant_pubkeys = [state.validators[participant_index].pubkey for participant_index in participant_indices]
domain = get_domain(state, DOMAIN_SYNC_COMMITTEE, compute_epoch_at_slot(previous_slot))
signing_root = compute_signing_root(get_block_root_at_slot(state, previous_slot), domain)
assert bls.FastAggregateVerify(participant_pubkeys, signing_root, body.sync_committee_signature)
assert optional_fast_aggregate_verify(participant_pubkeys, signing_root, body.sync_committee_signature)

# Reward sync committee participants
participant_rewards = Gwei(0)
Expand Down
5 changes: 5 additions & 0 deletions tests/core/pyspec/eth2spec/test/helpers/block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from eth2spec.test.context import LIGHTCLIENT
from eth2spec.test.helpers.keys import privkeys
from eth2spec.utils import bls
from eth2spec.utils.bls import only_with_bls
Expand Down Expand Up @@ -89,6 +90,10 @@ def build_empty_block(spec, state, slot=None):
empty_block.proposer_index = spec.get_beacon_proposer_index(state)
empty_block.body.eth1_data.deposit_count = state.eth1_deposit_index
empty_block.parent_root = parent_block_root

if spec.fork == LIGHTCLIENT:
empty_block.body.sync_committee_signature = spec.G2_INFINITY_POINT_SIG

apply_randao_reveal(spec, state, empty_block)
return empty_block

Expand Down

0 comments on commit f0864b8

Please sign in to comment.