Skip to content

Commit ab21177

Browse files
authored
feat(test-suite): implement the delegated user decryption test cases (#1808)
* feat(test-suite): implement the delegated user decryption test cases * feat(test-suite): implement test cases for delegated user decryptions * refactor(test-suite): adjust paused gateway tests and e2e test ci workflow * refactor(test-suite): implement more realistic delegated user decryption test cases * refactor(test-suite): rename test contract for delegated user decryption and bump relayer-sdk * chore(test-suite): replace test-suite version * fix(test-suite): adjust expected error message * chore(test-suite): replace test-suite version * chore(test-suite): replace test-suite version
1 parent e3c8453 commit ab21177

File tree

14 files changed

+471
-178
lines changed

14 files changed

+471
-178
lines changed

.github/workflows/test-suite-e2e-tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ jobs:
190190
run: |
191191
./fhevm-cli test user-decryption
192192
193+
- name: Delegated User Decryption test
194+
working-directory: test-suite/fhevm
195+
run: |
196+
./fhevm-cli test delegated-user-decryption
197+
193198
- name: ERC20 test
194199
working-directory: test-suite/fhevm
195200
run: |
@@ -205,11 +210,6 @@ jobs:
205210
run: |
206211
./fhevm-cli test public-decrypt-http-mixed
207212
208-
- name: Delegate User Decryption (partial test)
209-
working-directory: test-suite/fhevm
210-
run: |
211-
./fhevm-cli test delegate-user-decryption
212-
213213
- name: Random operators test (subset)
214214
working-directory: test-suite/fhevm
215215
run: |

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-suite/e2e/contracts/DelegateUserDecryptDelegate.sol

Lines changed: 0 additions & 11 deletions
This file was deleted.

test-suite/e2e/contracts/DelegateUserDecryptDelegator.sol

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// SPDX-License-Identifier: BSD-3-Clause-Clear
2+
pragma solidity ^0.8.24;
3+
4+
import "@fhevm/solidity/lib/FHE.sol";
5+
import {E2ECoprocessorConfig} from "./E2ECoprocessorConfigLocal.sol";
6+
7+
/// @notice SmartWallet contract that supports delegated user decryption.
8+
contract SmartWalletWithDelegation is E2ECoprocessorConfig {
9+
struct Transaction {
10+
address target;
11+
bytes data;
12+
}
13+
14+
event ProposedTx(uint256 indexed txId, address target, bytes data);
15+
16+
uint256 public txCounter;
17+
address public owner;
18+
mapping(uint256 => Transaction) public transactions;
19+
mapping(uint256 => bool) public executed;
20+
21+
constructor(address _owner) {
22+
require(_owner != address(0), "Owner cannot be zero address");
23+
owner = _owner;
24+
}
25+
26+
modifier onlyOwner() {
27+
require(msg.sender == owner, "Sender is not the owner");
28+
_;
29+
}
30+
31+
/// @notice Propose a transaction and assume as approved (since there's only one owner).
32+
/// @param target The target contract address
33+
/// @param data The calldata to execute
34+
function proposeTx(address target, bytes calldata data) external onlyOwner returns (uint256) {
35+
txCounter++;
36+
uint256 txId = txCounter;
37+
transactions[txCounter] = Transaction({target: target, data: data});
38+
emit ProposedTx(txId, target, data);
39+
return txId;
40+
}
41+
42+
/// @notice Execute a previously proposed transaction.
43+
/// @param txId The transaction ID to execute.
44+
function executeTx(uint256 txId) external onlyOwner {
45+
require(txId != 0 && txId <= txCounter, "Invalid txId");
46+
require(!executed[txId], "tx has already been executed");
47+
Transaction memory transaction = transactions[txId];
48+
49+
(bool success, ) = (transaction.target).call(transaction.data);
50+
require(success, "tx reverted");
51+
executed[txId] = true;
52+
}
53+
54+
/// @notice Delegate user decryption for a specific contract.
55+
/// @dev This allows an EOA to decrypt confidential data owned by this smart wallet.
56+
/// @param delegate The address that will be able to user decrypt.
57+
/// @param delegateContractAddress The contract address for which delegation applies.
58+
/// @param expirationTimestamp When the delegation expires.
59+
function delegateUserDecryption(
60+
address delegate,
61+
address delegateContractAddress,
62+
uint64 expirationTimestamp
63+
) external onlyOwner {
64+
FHE.delegateUserDecryption(delegate, delegateContractAddress, expirationTimestamp);
65+
}
66+
67+
/// @notice Revoke a previously granted delegation.
68+
/// @param delegate The address to revoke delegation from.
69+
/// @param delegateContractAddress The contract address for which to revoke delegation.
70+
function revokeUserDecryptionDelegation(address delegate, address delegateContractAddress) external onlyOwner {
71+
FHE.revokeUserDecryptionDelegation(delegate, delegateContractAddress);
72+
}
73+
}

test-suite/e2e/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"dependencies": {
1717
"@fhevm/solidity": "*",
1818
"@openzeppelin/contracts": "^5.3.0",
19-
"@zama-fhe/relayer-sdk": "0.4.0-4",
19+
"@zama-fhe/relayer-sdk": "^0.4.0-5",
2020
"bigint-buffer": "^1.1.5",
2121
"dotenv": "^16.0.3",
2222
"encrypted-types": "^0.0.4"
2323
}
24-
}
24+
}

test-suite/e2e/test/delegateUserDecrypt/delegateUserDecryption.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)