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