-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathAllowedMethodsEnforcer.sol
27 lines (25 loc) · 1 KB
/
AllowedMethodsEnforcer.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import "../CaveatEnforcer.sol";
contract AllowedMethodsEnforcer is CaveatEnforcer {
/**
* @notice Allows the delegator to limit what methods the delegate may call.
* @param terms - A series of 4byte method identifiers, representing the methods that the delegate is allowed to call.
* @param transaction - The transaction the delegate might try to perform.
* @param delegationHash - The hash of the delegation being operated on.
*/
function enforceCaveat(
bytes calldata terms,
Transaction calldata transaction,
bytes32 delegationHash
) public pure override returns (bool) {
bytes4 targetSig = bytes4(transaction.data[0:4]);
for (uint256 i = 0; i < terms.length; i += 4) {
bytes4 allowedSig = bytes4(terms[i:i + 4]);
if (allowedSig == targetSig) {
return true;
}
}
revert("AllowedMethodsEnforcer:method-not-allowed");
}
}