ethereum.forks.amsterdam.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:
28
    """
29
    Writes the sha256 hash to output.
30
31
    Parameters
32
    ----------
33
    evm :
34
        The current EVM frame.
35
36
    """
37
    data = evm.message.data
38
39
    # GAS
40
    word_count = ceil32(ulen(data)) // Uint(32)
41
    charge_gas(
42
        evm,
43
        GasCosts.PRECOMPILE_SHA256_BASE
44
        + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count,
45
    )
46
47
    # OPERATION
48
    evm.output = hashlib.sha256(data).digest()