Keyring Cache

Description

You can read the Keyring Cache directly and create your own permissioning contracts. The Cache effectively operates as a dynamic whitelist.

None of the Keyring Guard safeguards are included in this model (like failsafe mechanisms).

In this model, the permissioning code is self-maintained by you.

Integration

Create an instance of IKeyringGuardAlone and call its isAuthorized method.

function isAuthorized(
  address from,
  address to,
  uint32 admissionPolicyId
) external returns (bool passed);

Now, you can either reuse the modifier mentioned in the previous section (Keyring Guard) or directly call Keyring's dynamic whitelist to use it how you see fit.

Integration Example

Let's assume we want to guard an ERC20 transfer function.

Firstly, define the Policy ID in the contract constructor with a pointer to the Keyring Cache.

uint32 public policy;
IKeyringGuardAlone public keyringGuard;

constructor(uint32 _policy, address _keyring) ERC20("my token", "MY TOKEN") {
  policy = _policy;
  keyringGuard = IKeyringGuardAlone(_keyring);
}

Then, override ERC20 _update hook to implement the direct cache lookup.

function _update(address from, address to, uint256 value) internal virtual {
    keyringGuard.isAuthorized(from, to, policy);
    // ... rest of the code ...
}

Make sure to properly address the mint case (where from is the null address 0x0000...) and the burncase (where the to is the null address), as the address(0)is always regarded as unauthorised.

Last updated