Auth
source code // tests
Auth implements a multi owner authorization pattern.
An owner is known as a ward of the contract. Wards can make other users wards by calling
rely(address usr), or they can demote other wards by calling deny(address usr).
A contract that inherits from Auth will have the auth modifier available, which will revert if
the caller is not a ward.
The constructor of Auth takes an address that will be made the initial ward.
Properties
- authed methods can only be called by wards
- wards can only be added and removed by other wards
- all changes to ward status are logged
Reference
Data
mapping (address => bool): wards status for every ethereum address
Methods
rely(address usr):
- makes
usra ward - logs a
Relyevent
deny(address usr):
- removes
usras a ward - logs a
Denyevent
Events
Rely(address usr):usris now a wardDeny(address usr):usris no longer a ward
Example
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.6;
import {Auth} from "dappsys-v2/auth.sol";
contract Set is Auth {
uint public value;
// note that we must call the constructor of Auth to specify the initial ward
constructor(uint v) Auth(msg.sender) {
value = v;
}
function set(uint v) external auth {
value = v;
}
}
contract UseSet {
function go() external {
Set set = new Set(10);
// we are a ward here since we deployed the contract
require(set.wards(address(this)));
// since we are a ward we can call `set`
set.set(11);
require(set.value() == 11);
// make vitalik a ward
set.rely(0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B);
// revoke our authority
set.deny(address(this));
// this fails now since we are no longer a ward
set.set(12);
}
}