minor suggestions

This commit is contained in:
Hsiao-Wei Wang 2022-06-23 18:40:09 +08:00 committed by GitHub
parent e7e520791d
commit 0ab280d396
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -75,7 +75,7 @@ def bls_modular_inverse(x: BLSFieldElement) -> BLSFieldElement:
#### `div` #### `div`
```python ```python
def div(x, y): def div(x: BLSFieldElement, y: BLSFieldElement) -> BLSFieldElement:
"""Divide two field elements: `x` by `y`""" """Divide two field elements: `x` by `y`"""
return x * inv(y) % BLS_MODULUS return x * inv(y) % BLS_MODULUS
``` ```
@ -111,7 +111,9 @@ def verify_kzg_proof(polynomial_kzg: KZGCommitment,
x: BLSFieldElement, x: BLSFieldElement,
y: BLSFieldElement, y: BLSFieldElement,
quotient_kzg: KZGProof) -> bool: quotient_kzg: KZGProof) -> bool:
"""Verify KZG proof that `p(x) == y` where `p(x)` is the polynomial represented by `polynomial_kzg`""" """
Verify KZG proof that ``p(x) == y`` where ``p(x)`` is the polynomial represented by ``polynomial_kzg``.
"""
# Verify: P - y = Q * (X - x) # Verify: P - y = Q * (X - x)
X_minus_x = bls.add(KZG_SETUP_G2[1], bls.multiply(bls.G2, BLS_MODULUS - x)) X_minus_x = bls.add(KZG_SETUP_G2[1], bls.multiply(bls.G2, BLS_MODULUS - x))
P_minus_y = bls.add(polynomial_kzg, bls.multiply(bls.G1, BLS_MODULUS - y)) P_minus_y = bls.add(polynomial_kzg, bls.multiply(bls.G1, BLS_MODULUS - y))
@ -137,7 +139,7 @@ def evaluate_polynomial_in_evaluation_form(poly: List[BLSFieldElement], x: BLSFi
inverse_width = bls_modular_inverse(width) inverse_width = bls_modular_inverse(width)
for i in range(width): for i in range(width):
r += div(poly[i] * ROOTS_OF_UNITY[i], (x - ROOTS_OF_UNITY[i]) ) r += div(poly[i] * ROOTS_OF_UNITY[i], (x - ROOTS_OF_UNITY[i]))
r = r * (pow(x, width, BLS_MODULUS) - 1) * inverse_width % BLS_MODULUS r = r * (pow(x, width, BLS_MODULUS) - 1) * inverse_width % BLS_MODULUS
return r return r

View File

@ -83,7 +83,7 @@ def vector_lincomb(vectors: List[List[BLSFieldElement]], scalars: List[BLSFieldE
def verify_blobs_sidecar(slot: Slot, beacon_block_root: Root, def verify_blobs_sidecar(slot: Slot, beacon_block_root: Root,
expected_kzgs: Sequence[KZGCommitment], blobs_sidecar: BlobsSidecar): expected_kzgs: Sequence[KZGCommitment], blobs_sidecar: BlobsSidecar) -> None:
assert slot == blobs_sidecar.beacon_block_slot assert slot == blobs_sidecar.beacon_block_slot
assert beacon_block_root == blobs_sidecar.beacon_block_root assert beacon_block_root == blobs_sidecar.beacon_block_root
blobs = blobs_sidecar.blobs blobs = blobs_sidecar.blobs