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