Skip to content

Commit

Permalink
Add helper functions for aggregated proof verification
Browse files Browse the repository at this point in the history
Also abstract `lincomb()` out of the `blob_to_kzg()` function to be used in the verification.
  • Loading branch information
asn-d6 committed May 24, 2022
1 parent b95ca68 commit 201a077
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions EIPS/eip-4844.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,17 @@ Compared to full data sharding, this EIP has a reduced cap on the number of thes
Converts a blob to its corresponding KZG point:

```python
def lincomb(points: List[KZGCommitment], scalars: List[BLSFieldElement]) -> KZGCommitment:
"""
BLS multiscalar multiplication. This function can be optimized using Pippenger's algorithm and variants.
"""
r = bls.Z1
for x, a in zip(points, scalars):
r = bls.add(r, bls.multiply(x, a))
return r

def blob_to_kzg(blob: Blob) -> KZGCommitment:
computed_kzg = bls.Z1
for value, point_kzg in zip(blob, KZG_SETUP_LAGRANGE):
assert value < BLS_MODULUS
computed_kzg = bls.add(
computed_kzg,
bls.multiply(point_kzg, value)
)
return computed_kzg
return lincomb(blob, KZG_SETUP_LAGRANGE)
```

Converts a KZG point into a versioned hash:
Expand Down Expand Up @@ -404,6 +406,24 @@ def hash_to_bls_field(x: Container) -> BLSFieldElement:
return int.from_bytes(hash_tree_root(x), "little") % BLS_MODULUS


def compute_powers(x: BLSFieldElement, n: uint64) -> List[BLSFieldElement]:
current_power = 1
powers = []
for _ in range(n):
powers.append(BLSFieldElement(current_power))
current_power = current_power * int(x) % BLS_MODULUS
return powers

def vector_lincomb(vectors: List[List[BLSFieldElement]], scalars: List[BLSFieldElement]) -> List[BLSFieldElement]:
"""
Given a list of vectors, compute the linear combination of each column with `scalars`, and return the resulting
vector.
"""
r = [0]*len(vectors[0])
for v, a in zip(vectors, scalars):
for i, x in enumerate(v):
r[i] = (r[i] + a * x) % BLS_MODULUS
return [BLSFieldElement(x) for x in r]

def validate_blob_transaction_wrapper(wrapper: BlobTransactionNetworkWrapper):
versioned_hashes = wrapper.tx.message.blob_versioned_hashes
Expand Down

0 comments on commit 201a077

Please sign in to comment.