-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathSmartWalletWithDelegation.sol
More file actions
73 lines (62 loc) · 2.87 KB
/
SmartWalletWithDelegation.sol
File metadata and controls
73 lines (62 loc) · 2.87 KB
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
70
71
72
73
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;
import "@fhevm/solidity/lib/FHE.sol";
import {E2ECoprocessorConfig} from "./E2ECoprocessorConfigLocal.sol";
/// @notice SmartWallet contract that supports delegated user decryption.
contract SmartWalletWithDelegation is E2ECoprocessorConfig {
struct Transaction {
address target;
bytes data;
}
event ProposedTx(uint256 indexed txId, address target, bytes data);
uint256 public txCounter;
address public owner;
mapping(uint256 => Transaction) public transactions;
mapping(uint256 => bool) public executed;
constructor(address _owner) {
require(_owner != address(0), "Owner cannot be zero address");
owner = _owner;
}
modifier onlyOwner() {
require(msg.sender == owner, "Sender is not the owner");
_;
}
/// @notice Propose a transaction and assume as approved (since there's only one owner).
/// @param target The target contract address
/// @param data The calldata to execute
function proposeTx(address target, bytes calldata data) external onlyOwner returns (uint256) {
txCounter++;
uint256 txId = txCounter;
transactions[txCounter] = Transaction({target: target, data: data});
emit ProposedTx(txId, target, data);
return txId;
}
/// @notice Execute a previously proposed transaction.
/// @param txId The transaction ID to execute.
function executeTx(uint256 txId) external onlyOwner {
require(txId != 0 && txId <= txCounter, "Invalid txId");
require(!executed[txId], "tx has already been executed");
Transaction memory transaction = transactions[txId];
(bool success, ) = (transaction.target).call(transaction.data);
require(success, "tx reverted");
executed[txId] = true;
}
/// @notice Delegate user decryption for a specific contract.
/// @dev This allows an EOA to decrypt confidential data owned by this smart wallet.
/// @param delegate The address that will be able to user decrypt.
/// @param delegateContractAddress The contract address for which delegation applies.
/// @param expirationTimestamp When the delegation expires.
function delegateUserDecryption(
address delegate,
address delegateContractAddress,
uint64 expirationTimestamp
) external onlyOwner {
FHE.delegateUserDecryption(delegate, delegateContractAddress, expirationTimestamp);
}
/// @notice Revoke a previously granted delegation.
/// @param delegate The address to revoke delegation from.
/// @param delegateContractAddress The contract address for which to revoke delegation.
function revokeUserDecryptionDelegation(address delegate, address delegateContractAddress) external onlyOwner {
FHE.revokeUserDecryptionDelegation(delegate, delegateContractAddress);
}
}