EVM Intrinsics (evm::)
The evm:: namespace exposes EVM-specific primitives. It is always in scope on
EVM-domain targets. Using evm::* off the EVM domain is rejected (E12).
Pure intrinsics
Usable inside pure fn bodies as well as routes:
| Intrinsic | Returns | Lowers to |
|---|---|---|
evm::ecrecover(hash, v, r, s) | address | ecrecover(...) (address(0) on bad signature) |
evm::keccak256Packed(a, b, ...) | bytes32 | keccak256(abi.encodePacked(a, b, ...)) |
evm::sha256(data) | bytes32 | sha256 precompile |
evm::ripemd160(data) | bytes20 | ripemd160 precompile |
Impure intrinsics
Read live account or block context — not allowed inside pure fn (V4):
| Intrinsic | Returns | Lowers to |
|---|---|---|
evm::balance(addr) | u256 | addr.balance |
evm::blockhash(n) | bytes32 | blockhash(n) |
Example (EIP-2612 style)
routes {
permit(
owner: address,
spender: address,
value: U256,
deadline: U256,
v: u8,
r: bytes32,
s: bytes32
)
where sys::timestamp <= deadline : throw Expired()
=> [
let digest = evm::keccak256Packed(/* EIP-712 fields… */);
let recovered = evm::ecrecover(digest, v, r, s);
// … compare recovered to owner, update allowance …
]
}
Portable digests
Prefer std::crypto::sha256 when the same source should stay meaningful across
targets. Use evm::sha256 when you specifically want the EVM precompile at the
call site.