@@ -6,14 +6,21 @@ import {IExcubia} from "./IExcubia.sol";
6
6
7
7
/// @title Excubia.
8
8
/// @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.
10
11
abstract contract Excubia is IExcubia , Ownable (msg .sender ) {
11
12
/// @notice The excubia-protected contract address.
12
13
/// @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
14
15
/// to meet certain criteria before joining.
15
16
address public gate;
16
17
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
+
17
24
/// @inheritdoc IExcubia
18
25
function setGate (address _gate ) public virtual onlyOwner {
19
26
if (gate != address (0 )) revert GateAlreadySet ();
@@ -28,25 +35,23 @@ abstract contract Excubia is IExcubia, Ownable(msg.sender) {
28
35
}
29
36
30
37
/// @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 );
33
40
}
34
41
35
42
/// @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.
39
44
/// @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 ();
43
48
44
49
emit GatePassed (passerby, gate);
45
50
}
46
51
47
52
/// @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.
49
53
/// @param passerby The address of the entity attempting to pass the gate.
54
+ /// @param data Additional data that may be required for the check.
50
55
/// @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 );
52
57
}
0 commit comments