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:
29
    <snip>
38
    data = evm.call_data
39
40
    # GAS
41
    word_count = ceil32(ulen(data)) // Uint(32)
42
    charge_gas(
43
        evm,
44
        ExecutionGas(
45
            GasCosts.PRECOMPILE_SHA256_BASE
46
            + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count
47
        ),
48
    )
49
50
    # OPERATION
51
    evm.output = hashlib.sha256(data).digest()