Skip to content

Commit f10bd6d

Browse files
committed
refactor(excubiae): improve methods signature and comments
1 parent 3230396 commit f10bd6d

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

packages/excubiae/contracts/Excubia.sol

+17-12
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ import {IExcubia} from "./IExcubia.sol";
66

77
/// @title Excubia.
88
/// @notice Abstract base contract which can be extended to implement a specific excubia.
9-
/// @dev Inherit from this contract and implement the `_check` method to define the custom gatekeeping logic.
9+
/// @dev Inherit from this contract and implement the `_check` and/or `_pass()` methods
10+
/// to define the custom gatekeeping logic.
1011
abstract contract Excubia is IExcubia, Ownable(msg.sender) {
1112
/// @notice The excubia-protected contract address.
1213
/// @dev The gate can be any contract address that requires a prior `_check`.
13-
/// For example, the gate is a semaphore group that requires the passerby
14+
/// For example, the gate is a Semaphore group that requires the passerby
1415
/// to meet certain criteria before joining.
1516
address public gate;
1617

18+
/// @dev Modifier to restrict function calls to only from the gate address.
19+
modifier onlyGate() {
20+
if (msg.sender == gate) revert GateOnly();
21+
_;
22+
}
23+
1724
/// @inheritdoc IExcubia
1825
function setGate(address _gate) public virtual onlyOwner {
1926
if (gate != address(0)) revert GateAlreadySet();
@@ -28,25 +35,23 @@ abstract contract Excubia is IExcubia, Ownable(msg.sender) {
2835
}
2936

3037
/// @inheritdoc IExcubia
31-
function pass(bytes memory data, address passerby) public virtual {
32-
_pass(data, passerby);
38+
function pass(address passerby, bytes calldata data) public virtual onlyGate {
39+
_pass(passerby, data);
3340
}
3441

3542
/// @dev Internal method that performs the check and emits an event if the check is passed.
36-
/// Can throw errors as {GateNotSet} if the gate address has not been set or.
37-
/// {AccessDenied} if the `_check` method returns false.
38-
/// @param data Additional data required for the check.
43+
/// Can throw errors the {AccessDenied} error if the `_check` method returns false.
3944
/// @param passerby The address of the entity attempting to pass the gate.
40-
function _pass(bytes memory data, address passerby) internal virtual {
41-
if (gate == address(0)) revert GateNotSet();
42-
if (!_check(data, passerby)) revert AccessDenied();
45+
/// @param data Additional data required for the check.
46+
function _pass(address passerby, bytes calldata data) internal virtual {
47+
if (!_check(passerby, data)) revert AccessDenied();
4348

4449
emit GatePassed(passerby, gate);
4550
}
4651

4752
/// @dev Abstract internal function to be implemented with custom logic to check if the passerby can pass the gate.
48-
/// @param data Additional data that may be required for the check.
4953
/// @param passerby The address of the entity attempting to pass the gate.
54+
/// @param data Additional data that may be required for the check.
5055
/// @return True if the passerby passes the check, false otherwise.
51-
function _check(bytes memory data, address passerby) internal virtual returns (bool);
56+
function _check(address passerby, bytes calldata data) internal virtual returns (bool);
5257
}

packages/excubiae/contracts/IExcubia.sol

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ interface IExcubia {
1212
/// @notice Error thrown when the gate address is not set.
1313
error GateNotSet();
1414

15+
/// @notice Error thrown when the callee is not the gate contract.
16+
error GateOnly();
17+
1518
/// @notice Error thrown when the gate address has been already set.
1619
error GateAlreadySet();
1720

@@ -25,7 +28,7 @@ interface IExcubia {
2528

2629
/// @notice Initiates the excubia's check and triggers the associated action if the check is passed.
2730
/// @dev Calls `_pass` to handle the logic of checking and passing the gate.
28-
/// @param data Additional data required for the check (e.g., encoded token identifier).
2931
/// @param passerby The address of the entity attempting to pass the gate.
30-
function pass(bytes memory data, address passerby) external;
32+
/// @param data Additional data required for the check (e.g., encoded token identifier).
33+
function pass(address passerby, bytes calldata data) external;
3134
}

0 commit comments

Comments
 (0)