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

24. Access control: the owner pattern

Restricting sensitive functions without modifiers.

Vyper has no modifiers, so access control is expressed as an explicit `assert` at the top of each sensitive function — slightly more verbose than Solidity, but nothing is hidden behind a name you have to look up.

owner: public(address)

@deploy
def __init__():
    self.owner = msg.sender

@external
def set_rate(new_rate: uint256):
    assert msg.sender == self.owner, "not owner"
    self.rate = new_rate

For multi-role systems, a `HashMap[address, bool]` of admins (or a role-based `HashMap[address, HashMap[bytes32, bool]]`) generalises this pattern beyond a single owner.

Check your understanding

  1. 1. How does Vyper express an 'only owner' check, lacking modifiers?

  2. 2. How could you support multiple admins?

  3. 3. Why might some see explicit asserts as an advantage?