Skip to content

Commit

Permalink
EIP4844: Refactor precompile to use bytes-based verify_kzg_proof()
Browse files Browse the repository at this point in the history
See ethereum/consensus-specs#3097 for the changes to the verify_kzg_proof API
  • Loading branch information
asn-d6 committed Nov 18, 2022
1 parent c14bc7f commit a50a81a
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions EIPS/eip-4844.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,23 @@ The precompile costs `POINT_EVALUATION_PRECOMPILE_GAS` and executes the followin

```python
def point_evaluation_precompile(input: Bytes) -> Bytes:
# Verify P(z) = a
# versioned hash: first 32 bytes
"""
Verify p(z) = y given commitment that corresponds to the polynomial p(x) and a KZG proof.
Also verify that the provided commitment matches the provided versioned_hash.
"""
# The data is encoded as follows: versioned_hash | z | y | commitment | proof |
versioned_hash = input[:32]
# Evaluation point: next 32 bytes
x = int.from_bytes(input[32:64], 'little')
assert x < BLS_MODULUS
# Expected output: next 32 bytes
y = int.from_bytes(input[64:96], 'little')
assert y < BLS_MODULUS
# The remaining data will always be the proof, including in future versions
# input kzg point: next 48 bytes
data_kzg = input[96:144]
assert kzg_to_versioned_hash(data_kzg) == versioned_hash
# Quotient kzg: next 48 bytes
quotient_kzg = input[144:192]
assert verify_kzg_proof(data_kzg, x, y, quotient_kzg)
z = input[32:64]
y = input[64:96]
commitment = input[96:144]
kzg_proof = input[144:192]

# Verify KZG proof
assert verify_kzg_proof(commitment, z, y, kzg_proof)

# Verify commitment matches versioned_hash
assert kzg_to_versioned_hash(commitment) == versioned_hash

return Bytes([])
```

Expand Down

0 comments on commit a50a81a

Please sign in to comment.