EEVM.Precompiles.SHA256 (eevm v0.1.0)

Copy Markdown View Source

SHA-256 precompile — address 0x02.

Gas schedule (Yellow Paper §E.2)

ComponentCost
Base60
Per word12 (one word = 32 bytes, rounded up)

Output format

Always 32 bytes — the raw SHA-256 digest.

Summary

Functions

Executes the SHA-256 precompile.

Functions

execute(input, gas_limit)

@spec execute(binary(), non_neg_integer()) ::
  {:ok, binary(), non_neg_integer()} | {:error, :out_of_gas}

Executes the SHA-256 precompile.

Hashes input with SHA-256 and returns the 32-byte digest, charging 60 + 12 * ceil(byte_size(input) / 32) gas.

Examples

iex> {:ok, digest, _gas} = EEVM.Precompiles.SHA256.execute(<<>>, 1_000)
iex> byte_size(digest)
32

iex> EEVM.Precompiles.SHA256.execute(<<1::256>>, 5)
{:error, :out_of_gas}