Vyper theorytheory 0/50 · 0%
Security patterns · medium

25. Custom error messages and revert reasons

Writing informative, gas-conscious revert strings.

Vyper doesn't support Solidity's typed custom errors; string messages attached to `assert`/`raise` are the whole mechanism. Keep them short — every character is calldata/bytecode you pay for — but specific enough to debug quickly.

@external
def transfer(to: address, amount: uint256):
    assert to != empty(address), "zero address"
    assert self.balances[msg.sender] >= amount, "insufficient balance"
    self.balances[msg.sender] -= amount
    self.balances[to] += amount

`empty(address)` produces the zero address in a readable way, and is the idiomatic Vyper equivalent of Solidity's `address(0)`.

Check your understanding

  1. 1. Does Vyper support Solidity-style custom error types (error Foo())?

  2. 2. What produces the zero address in Vyper?

  3. 3. Why keep revert strings short?