ethereum.forks.amsterdam.vm.precompiled_contracts.ripemd160

Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT.

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

Introduction

Implementation of the RIPEMD160 precompiled contract.

ripemd160

Writes the ripemd160 hash to output.

Parameters

evm : The current EVM frame.

def ripemd160(evm: Evm) -> None:
30
    <snip>
39
    data = evm.call_data
40
41
    # GAS
42
    word_count = ceil32(ulen(data)) // Uint(32)
43
    charge_gas(
44
        evm,
45
        ExecutionGas(
46
            GasCosts.PRECOMPILE_RIPEMD160_BASE
47
            + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count
48
        ),
49
    )
50
51
    # OPERATION
52
    hash_bytes = hashlib.new("ripemd160", data).digest()
53
    padded_hash = left_pad_zero_bytes(hash_bytes, 32)
54
    evm.output = padded_hash