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