Skip to content

Commit

Permalink
refactor(excubiae): optimize check and pass
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjei committed Jun 14, 2024
1 parent 20e2c67 commit 1a0882a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
12 changes: 2 additions & 10 deletions packages/excubiae/contracts/Excubia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {IExcubia} from "./IExcubia.sol";

/// @title Excubia.
/// @notice Abstract base contract which can be extended to implement a specific excubia.
/// @dev Inherit from this contract and implement the `_check` and/or `_pass()` methods
/// to define the custom gatekeeping logic.
/// @dev Inherit from this contract and implement the `_check` method to define
/// the custom gatekeeping logic.
abstract contract Excubia is IExcubia, Ownable(msg.sender) {
/// @notice The excubia-protected contract address.
/// @dev The gate can be any contract address that requires a prior `_check`.
Expand Down Expand Up @@ -37,14 +37,6 @@ abstract contract Excubia is IExcubia, Ownable(msg.sender) {

/// @inheritdoc IExcubia
function pass(address passerby, bytes calldata data) public virtual onlyGate {
_pass(passerby, data);
}

/// @dev Internal method that performs the check and emits an event if the check is passed.
/// Can throw errors the {AccessDenied} error if the `_check` method returns false.
/// @param passerby The address of the entity attempting to pass the gate.
/// @param data Additional data required for the check.
function _pass(address passerby, bytes calldata data) internal virtual {
if (!_check(passerby, data)) revert AccessDenied();

emit GatePassed(passerby, gate);
Expand Down
2 changes: 1 addition & 1 deletion packages/excubiae/contracts/IExcubia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface IExcubia {
function setGate(address _gate) external;

/// @notice Initiates the excubia's check and triggers the associated action if the check is passed.
/// @dev Calls `_pass` to handle the logic of checking and passing the gate.
/// @dev Calls `_check` to handle the logic of checking for passing the gate.
/// @param passerby The address of the entity attempting to pass the gate.
/// @param data Additional data required for the check (e.g., encoded token identifier).
function pass(address passerby, bytes calldata data) external;
Expand Down
12 changes: 2 additions & 10 deletions packages/excubiae/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ yarn add @zk-kit/excubiae
To build your own Excubia:

1. Inherit from the [Excubia](./Excubia.sol) abstract contract that conforms to the [IExcubia](./IExcubia.sol) interface.
2. Implement the `_check()` method to define your own gatekeeping logic.
3. Implement the `_pass()` method to prevent unwanted access (sybils, double checks).
2. Implement the `_check()` method to define your own gatekeeping logic and to prevent unwanted access (sybils, double checks).

```solidity
// SPDX-License-Identifier: MIT
Expand All @@ -69,16 +68,9 @@ import { Excubia } from "excubiae/contracts/Excubia.sol";
contract MyExcubia is Excubia {
// ...
function _pass(address passerby, bytes calldata data) internal override {
if (!_check(passerby, data)) revert AccessDenied();
// Implement your logic to prevent unwanted access here.
emit GatePassed(passerby, gate);
}
function _check(address passerby, bytes calldata data) internal override returns (bool) {
// Implement custom access control logic here.
// Implement your logic to prevent unwanted access here.
return true;
}
Expand Down

0 comments on commit 1a0882a

Please sign in to comment.