Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

IntrinsicReturnsLowers to
evm::ecrecover(hash, v, r, s)addressecrecover(...) (address(0) on bad signature)
evm::keccak256Packed(a, b, ...)bytes32keccak256(abi.encodePacked(a, b, ...))
evm::sha256(data)bytes32sha256 precompile
evm::ripemd160(data)bytes20ripemd160 precompile

Impure intrinsics

Read live account or block context — not allowed inside pure fn (V4):

IntrinsicReturnsLowers to
evm::balance(addr)u256addr.balance
evm::blockhash(n)bytes32blockhash(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.