ethereum.cancun.vm.precompiled_contracts.point_evaluation

Ethereum Virtual Machine (EVM) POINT EVALUATION PRECOMPILED CONTRACT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Implementation of the POINT EVALUATION precompiled contract.

FIELD_ELEMENTS_PER_BLOB

25
FIELD_ELEMENTS_PER_BLOB = 4096

BLS_MODULUS

26
BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513

VERSIONED_HASH_VERSION_KZG

27
VERSIONED_HASH_VERSION_KZG = b"\x01"

point_evaluation

A pre-compile that verifies a KZG proof which claims that a blob (represented by a commitment) evaluates to a given value at a given point.

Parameters

evm : The current EVM frame.

def point_evaluation(evm: Evm) -> None:
31
    """
32
    A pre-compile that verifies a KZG proof which claims that a blob
33
    (represented by a commitment) evaluates to a given value at a given point.
34
35
    Parameters
36
    ----------
37
    evm :
38
        The current EVM frame.
39
40
    """
41
    data = evm.message.data
42
    if len(data) != 192:
43
        raise KZGProofError
44
45
    versioned_hash = data[:32]
46
    z = Bytes32(data[32:64])
47
    y = Bytes32(data[64:96])
48
    commitment = KZGCommitment(data[96:144])
49
    proof = Bytes48(data[144:192])
50
51
    # GAS
52
    charge_gas(evm, GAS_POINT_EVALUATION)
53
    if kzg_commitment_to_versioned_hash(commitment) != versioned_hash:
54
        raise KZGProofError
55
56
    # Verify KZG proof with z and y in big endian format
57
    try:
58
        kzg_proof_verification = verify_kzg_proof(commitment, z, y, proof)
59
    except Exception as e:
60
        raise KZGProofError from e
61
62
    if not kzg_proof_verification:
63
        raise KZGProofError
64
65
    # Return FIELD_ELEMENTS_PER_BLOB and BLS_MODULUS as padded
66
    # 32 byte big endian values
67
    evm.output = Bytes(
68
        U256(FIELD_ELEMENTS_PER_BLOB).to_be_bytes32()
69
        + U256(BLS_MODULUS).to_be_bytes32()
70
    )