From a50a81a48e9152815b5c48281b78c522fe6db9db Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Fri, 18 Nov 2022 19:21:05 +0200 Subject: [PATCH] EIP4844: Refactor precompile to use bytes-based verify_kzg_proof() See https://github.com/ethereum/consensus-specs/pull/3097 for the changes to the verify_kzg_proof API --- EIPS/eip-4844.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/EIPS/eip-4844.md b/EIPS/eip-4844.md index 19dcd394a0958c..66a2b9880b68d4 100644 --- a/EIPS/eip-4844.md +++ b/EIPS/eip-4844.md @@ -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([]) ```