Merge pull request #3015 from asn-d6/bytes_to_bls_field

EIP4844: Introduce bytes_to_bls_field() helper
This commit is contained in:
George Kadianakis 2022-09-26 23:55:16 +03:00 committed by GitHub
commit 6c2b46ae32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -17,6 +17,7 @@
- [`reverse_bits`](#reverse_bits) - [`reverse_bits`](#reverse_bits)
- [`bit_reversal_permutation`](#bit_reversal_permutation) - [`bit_reversal_permutation`](#bit_reversal_permutation)
- [BLS12-381 helpers](#bls12-381-helpers) - [BLS12-381 helpers](#bls12-381-helpers)
- [`bytes_to_bls_field`](#bytes_to_bls_field)
- [`bls_modular_inverse`](#bls_modular_inverse) - [`bls_modular_inverse`](#bls_modular_inverse)
- [`div`](#div) - [`div`](#div)
- [`g1_lincomb`](#g1_lincomb) - [`g1_lincomb`](#g1_lincomb)
@ -111,6 +112,16 @@ def bit_reversal_permutation(l: Sequence[T]) -> Sequence[T]:
### BLS12-381 helpers ### BLS12-381 helpers
#### `bytes_to_bls_field`
```python
def bytes_to_bls_field(b: Bytes32) -> BLSFieldElement:
"""
Convert bytes to a BLS field scalar. The output is not uniform over the BLS field.
"""
return int.from_bytes(b, "little") % BLS_MODULUS
```
#### `bls_modular_inverse` #### `bls_modular_inverse`
```python ```python

View File

@ -96,7 +96,7 @@ def hash_to_bls_field(x: Container) -> BLSFieldElement:
Compute 32-byte hash of serialized container and convert it to BLS field. Compute 32-byte hash of serialized container and convert it to BLS field.
The output is not uniform over the BLS field. The output is not uniform over the BLS field.
""" """
return int.from_bytes(hash(ssz_serialize(x)), "little") % BLS_MODULUS return bytes_to_bls_field(hash(ssz_serialize(x)))
``` ```
### `compute_powers` ### `compute_powers`