ethereum.forks.byzantium.vm.precompiled_contracts.sha256

Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT.

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

Introduction

Implementation of the SHA256 precompiled contract.

sha256

Writes the sha256 hash to output.

Parameters

evm : The current EVM frame.

def sha256(evm: Evm) -> None:
25
    """
26
    Writes the sha256 hash to output.
27
28
    Parameters
29
    ----------
30
    evm :
31
        The current EVM frame.
32
33
    """
34
    data = evm.message.data
35
36
    # GAS
37
    word_count = ceil32(ulen(data)) // Uint(32)
38
    charge_gas(
39
        evm,
40
        GasCosts.PRECOMPILE_SHA256_BASE
41
        + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count,
42
    )
43
44
    # OPERATION
45
    evm.output = hashlib.sha256(data).digest()