From 1a0882ac5fdef83446eba79a33841845d72e50f3 Mon Sep 17 00:00:00 2001 From: Jeeiii Date: Fri, 14 Jun 2024 11:30:06 +0200 Subject: [PATCH] refactor(excubiae): optimize check and pass --- packages/excubiae/contracts/Excubia.sol | 12 ++---------- packages/excubiae/contracts/IExcubia.sol | 2 +- packages/excubiae/contracts/README.md | 12 ++---------- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/packages/excubiae/contracts/Excubia.sol b/packages/excubiae/contracts/Excubia.sol index 9c70cf0..ff7be7a 100644 --- a/packages/excubiae/contracts/Excubia.sol +++ b/packages/excubiae/contracts/Excubia.sol @@ -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`. @@ -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); diff --git a/packages/excubiae/contracts/IExcubia.sol b/packages/excubiae/contracts/IExcubia.sol index 4c1f3e9..888c60d 100644 --- a/packages/excubiae/contracts/IExcubia.sol +++ b/packages/excubiae/contracts/IExcubia.sol @@ -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; diff --git a/packages/excubiae/contracts/README.md b/packages/excubiae/contracts/README.md index 884a23c..10f201b 100644 --- a/packages/excubiae/contracts/README.md +++ b/packages/excubiae/contracts/README.md @@ -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 @@ -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; }