generated from scaffold-eth/scaffold-eth
-
Notifications
You must be signed in to change notification settings - Fork 13
/
RevocationEnforcer.sol
44 lines (39 loc) · 1.49 KB
/
RevocationEnforcer.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
pragma solidity ^0.8.13;
//SPDX-License-Identifier: MIT
import "./CaveatEnforcer.sol";
import "../Delegatable.sol";
contract RevocationEnforcer is CaveatEnforcer, Delegatable("CaveatEnforcer", "1") {
mapping(bytes32 => bool) isRevoked;
function enforceCaveat(
bytes calldata terms,
Transaction calldata transaction,
bytes32 delegationHash
) public override returns (bool) {
require(!isRevoked[delegationHash], "Delegation has been revoked");
return true;
}
function revokeDelegation(SignedDelegation calldata signedDelegation) public {
address signer = verifyDelegationSignature(signedDelegation);
address sender = _msgSender();
require(signer == sender, "Only the signer can revoke a delegation");
bytes32 delegationHash = GET_SIGNEDDELEGATION_PACKETHASH(signedDelegation);
isRevoked[delegationHash] = true;
}
/**
* This is boilerplate that must be added to any Delegatable contract if it also inherits
* from another class that also implements _msgSender().
*/
function _msgSender () internal view override(Delegatable) returns (address sender) {
if(msg.sender == address(this)) {
bytes memory array = msg.data;
uint256 index = msg.data.length;
assembly {
// Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those.
sender := and(mload(add(array, index)), 0xffffffffffffffffffffffffffffffffffffffff)
}
} else {
sender = msg.sender;
}
return sender;
}
}