-
Notifications
You must be signed in to change notification settings - Fork 0
/
zkConnectModule.sol
69 lines (59 loc) · 2.26 KB
/
zkConnectModule.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "zk-connect-onchain-verifier/src/libs/zk-connect/ZkConnectLib.sol";
contract Enum {
enum Operation {
Call,
DelegateCall
}
}
interface GnosisSafe {
/// @dev Allows a Module to execute a Safe transaction without any further confirmations.
/// @param to Destination address of module transaction.
/// @param value Ether value of module transaction.
/// @param data Data payload of module transaction.
/// @param operation Operation type of module transaction.
function execTransactionFromModule(
address to,
uint256 value,
bytes calldata data,
Enum.Operation operation
) external returns (bool success);
}
contract zkConnectModule is ZkConnect {
bytes16 public groupId;
GnosisSafe public safe;
//TODO make proxyable w/ initializer
constructor(address _safe, bytes16 _appId, bytes16 _groupId) ZkConnect(_appId) {
safe = GnosisSafe(_safe);
groupId = _groupId;
}
/// @dev Change group identifier
/// @param _groupId group identifier to check the claim
function setGroupId(bytes16 _groupId) public {
require(msg.sender == address(safe), "!safe");
groupId = _groupId;
}
/// @dev Exec tx using zkConnect proof
/// @param to Destination address of module transaction
/// @param value Ether value of module transaction
/// @param data Data payload of module transaction
/// @param operation Operation type of module transaction
function execTransactionFromModule(
address to,
uint256 value,
bytes calldata data,
Enum.Operation operation,
bytes memory zkConnectResponse
) public virtual returns (bool success) {
//TODO: should use a nonce to avoid replay
ZkConnectVerifiedResult memory zkConnectVerifiedResult = verify({
responseBytes: zkConnectResponse,
authRequest: buildAuth({ authType: AuthType.ANON }),
claimRequest: buildClaim({ groupId: groupId }),
messageSignatureRequest: abi.encode(to, value, data, operation)
});
require(safe.execTransactionFromModule(to, value, data, operation), "Module transaction failed");
return true;
}
}