ethereum.forks.london.vm.precompiled_contracts.sha256ethereum.forks.arrow_glacier.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 | """ |
|---|---|
| 30 | Writes the sha256 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(Uint(len(data))) // Uint(32) |
| 42 | charge_gas( |
| 43 | evm, |
| 44 | GAS_PRECOMPILE_SHA256_BASE |
| 45 | + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, |
| 46 | ) |
| 47 | |
| 48 | # OPERATION |
| 49 | evm.output = hashlib.sha256(data).digest() |