Ethereum Virtual Machine (EVM) Blake2 PRECOMPILED CONTRACT

Introduction

Implementation of the Blake2 precompiled contract.

Module Contents

Functions

blake2f

Writes the Blake2 hash to output.

Module Details

blake2f

blake2f(evm: ethereum.berlin.vm.Evm)None

Writes the Blake2 hash to output.

Parameters

evm – The current EVM frame.

def blake2f(evm: Evm) -> None:
    data = evm.message.data

    # GAS
    ensure(len(data) == 213, InvalidParameter)

    blake2b = Blake2b()
    rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data)

    charge_gas(evm, GAS_BLAKE2_PER_ROUND * rounds)

    # OPERATION
    ensure(f in [0, 1], InvalidParameter)

    evm.output = blake2b.compress(rounds, h, m, t_0, t_1, f)