ethereum.forks.bogota.vm.precompiled_contracts.bls12_381.bls12_381_pairing

Ethereum Virtual Machine (EVM) BLS12 381 PAIRING PRE-COMPILE.

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

Introduction

Implementation of the BLS12 381 pairing pre-compile.

bls12_pairing

The bls12_381 pairing precompile.

Parameters

evm : The current EVM frame.

Raises

InvalidParameter If the input length is invalid or if the subgroup check fails.

def bls12_pairing(​evm: Evm​) -> None:
26
    <snip>
40
    data = evm.call_data
41
    if len(data) == 0 or len(data) % 384 != 0:
42
        raise InvalidParameter("Invalid Input Length")
43
44
    # GAS
45
    k = len(data) // 384
46
    gas_cost = ExecutionGas(Uint(32600 * k + 37700))
47
    charge_gas(evm, gas_cost)
48
49
    # OPERATION
50
    g1_points = []
51
    g2_points = []
52
    for i in range(k):
53
        g1_start = 384 * i
54
        g2_start = 384 * i + 128
55
56
        g1_points.append(unpad_g1(data[g1_start : g1_start + 128]))
57
        g2_points.append(unpad_g2(data[g2_start : g2_start + 256]))
58
59
    try:
60
        result = pairing_check(g1_points, g2_points)
61
    except InvalidInputError as e:
62
        raise InvalidParameter(str(e)) from e
63
64
    if result:
65
        evm.output = b"\x00" * 31 + b"\x01"
66
    else:
67
        evm.output = b"\x00" * 32