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

27
FIELD_ELEMENTS_PER_BLOB = 4096

BLS_MODULUS

28
BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513

VERSIONED_HASH_VERSION_KZG

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