2021-08-18 23:11:38 +00:00
|
|
|
# Altair -- BLS extensions
|
2021-05-27 18:59:02 +00:00
|
|
|
|
|
|
|
## Table of contents
|
|
|
|
|
|
|
|
<!-- TOC -->
|
|
|
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
|
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
|
|
|
|
|
|
- [Introduction](#introduction)
|
|
|
|
- [Constants](#constants)
|
|
|
|
- [Extensions](#extensions)
|
2021-08-03 13:46:11 +00:00
|
|
|
- [`eth_aggregate_pubkeys`](#eth_aggregate_pubkeys)
|
|
|
|
- [`eth_fast_aggregate_verify`](#eth_fast_aggregate_verify)
|
2021-05-27 18:59:02 +00:00
|
|
|
|
|
|
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
|
|
<!-- /TOC -->
|
|
|
|
|
|
|
|
## Introduction
|
|
|
|
|
|
|
|
A number of extensions are defined to handle BLS signatures in the Altair upgrade.
|
|
|
|
|
|
|
|
Knowledge of the [phase 0 specification](../phase0/beacon-chain.md) is assumed, including type definitions.
|
|
|
|
|
|
|
|
## Constants
|
|
|
|
|
|
|
|
| Name | Value |
|
|
|
|
| - | - |
|
|
|
|
| `G2_POINT_AT_INFINITY` | `BLSSignature(b'\xc0' + b'\x00' * 95)` |
|
|
|
|
|
|
|
|
## Extensions
|
|
|
|
|
2021-08-03 13:46:11 +00:00
|
|
|
### `eth_aggregate_pubkeys`
|
2021-05-27 18:59:02 +00:00
|
|
|
|
|
|
|
An additional function `AggregatePKs` is defined to extend the
|
|
|
|
[IETF BLS signature draft standard v4](https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04)
|
|
|
|
spec referenced in the phase 0 document.
|
|
|
|
|
|
|
|
```python
|
2021-08-03 13:46:11 +00:00
|
|
|
def eth_aggregate_pubkeys(pubkeys: Sequence[BLSPubkey]) -> BLSPubkey:
|
2021-05-27 18:59:02 +00:00
|
|
|
"""
|
|
|
|
Return the aggregate public key for the public keys in ``pubkeys``.
|
|
|
|
|
|
|
|
NOTE: the ``+`` operation should be interpreted as elliptic curve point addition, which takes as input
|
|
|
|
elliptic curve points that must be decoded from the input ``BLSPubkey``s.
|
|
|
|
This implementation is for demonstrative purposes only and ignores encoding/decoding concerns.
|
|
|
|
Refer to the BLS signature draft standard for more information.
|
|
|
|
"""
|
|
|
|
assert len(pubkeys) > 0
|
2021-08-05 04:09:30 +00:00
|
|
|
# Ensure that the given inputs are valid pubkeys
|
|
|
|
assert all(bls.KeyValidate(pubkey) for pubkey in pubkeys)
|
2021-08-04 13:12:19 +00:00
|
|
|
|
2021-05-27 18:59:02 +00:00
|
|
|
result = copy(pubkeys[0])
|
|
|
|
for pubkey in pubkeys[1:]:
|
|
|
|
result += pubkey
|
|
|
|
return result
|
|
|
|
```
|
|
|
|
|
2021-08-03 13:46:11 +00:00
|
|
|
### `eth_fast_aggregate_verify`
|
2021-05-27 18:59:02 +00:00
|
|
|
|
|
|
|
```python
|
2021-08-03 13:46:11 +00:00
|
|
|
def eth_fast_aggregate_verify(pubkeys: Sequence[BLSPubkey], message: Bytes32, signature: BLSSignature) -> bool:
|
2021-05-27 18:59:02 +00:00
|
|
|
"""
|
|
|
|
Wrapper to ``bls.FastAggregateVerify`` accepting the ``G2_POINT_AT_INFINITY`` signature when ``pubkeys`` is empty.
|
|
|
|
"""
|
|
|
|
if len(pubkeys) == 0 and signature == G2_POINT_AT_INFINITY:
|
|
|
|
return True
|
|
|
|
return bls.FastAggregateVerify(pubkeys, message, signature)
|
|
|
|
```
|