← Protocols
Huff
01Description

Low-level, EVM-assembly language with macros and named constants — gives byte-for-byte control over bytecode. Used for ultra-optimized contracts (Weierstrudel, Huffmate, Tstorish) where Solidity/Yul leave gas on the table.

02Best for
  • 01ultra-gas-optimized contracts
  • 02precompile-style libraries
  • 03math/crypto primitives
  • 04minimal proxy / dispatcher code
  • 05learning the EVM at the opcode level
03Install
  • curl -L get.huff.sh | bash && huffup
  • forge install huff-language/foundry-huff
05Prompt snippet
Use Huff only for tight, audited primitives where every gas matters. Install with `curl -L get.huff.sh | bash` then `huffup`; compile a contract with `huffc src/Token.huff --bytecode`. Integrate with Foundry via `foundry-huff` and the `HuffDeployer` cheat: `HuffDeployer.deploy("Token")` returns the deployed address for tests. Reuse audited macros from `huffmate` (ERC20, math, auth) instead of writing low-level dispatch from scratch. Always cross-check with a Solidity reference implementation and a differential fuzz test.
06Gotchas
  • Huff has no compiler-enforced types or stack checking — you manually push, dup, and swap items. A miscounted stack silently corrupts state and produces unrelated reverts; budget audit time accordingly.
  • Function selectors and dispatch are hand-written. Forgetting to include a selector branch makes a function uncallable on-chain with no compiler warning.
  • Two compilers exist (`huffc` v1 in TypeScript, `huff-rs`/`huff2` in Rust) with subtle differences in macro expansion and error messages — pin which one your repo targets.
  • No automatic reentrancy, overflow, or access-control guards: every check OZ/Solady gives you for free must be re-implemented as macros and audited.
  • ABI is not auto-generated from source — you maintain a parallel `interface IFoo` in Solidity for callers; drift between the two is a common source of integration bugs.
  • Tooling support (Slither, coverage, debuggers) is significantly thinner than Solidity — rely on Foundry traces and differential fuzzing against a reference Solidity contract.
07Alternatives