Skip to content

Commit 01e5e2d

Browse files
committed
test(test-suite): delegate user decryption, happy path test
test from FHE.sol call to MultichanACL transaction
1 parent cd5a488 commit 01e5e2d

File tree

5 files changed

+125
-6
lines changed

5 files changed

+125
-6
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ jobs:
182182
run: |
183183
./fhevm-cli test public-decrypt-http-mixed
184184
185+
- name: Delegate User Decryption (partial test)
186+
working-directory: test-suite/fhevm
187+
run: |
188+
./fhevm-cli test delegate-user-decryption
189+
185190
- name: Show logs on test failure
186191
working-directory: test-suite/fhevm
187192
if: always()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: BSD-3-Clause-Clear
2+
3+
pragma solidity ^0.8.24;
4+
5+
import "@fhevm/solidity/lib/FHE.sol";
6+
import {E2ECoprocessorConfig} from "./E2ECoprocessorConfigLocal.sol";
7+
8+
9+
/// @notice Contract for demonstrating user decryption with delegation
10+
contract DelegateUserDecryptDelegate is E2ECoprocessorConfig {
11+
ebool public storedZBool;
12+
13+
function useBool(ebool xBool) public returns (ebool zBool) {
14+
ebool yBool = FHE.asEbool(true);
15+
zBool = FHE.and(xBool, yBool);
16+
FHE.allowThis(zBool);
17+
FHE.allow(zBool, msg.sender);
18+
storedZBool = zBool;
19+
}
20+
21+
function getResult() public view returns (ebool) {
22+
return storedZBool;
23+
}
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: BSD-3-Clause-Clear
2+
3+
pragma solidity ^0.8.24;
4+
5+
import "@fhevm/solidity/lib/FHE.sol";
6+
import {E2ECoprocessorConfig} from "./E2ECoprocessorConfigLocal.sol";
7+
8+
9+
/// @notice Contract for demonstrating user decryption with delegation
10+
contract DelegateUserDecryptDelegator is E2ECoprocessorConfig {
11+
/// @dev Encrypted boolean
12+
ebool public xBool;
13+
14+
/// @notice Constructor to initialize encrypted values and set permissions
15+
constructor() {
16+
xBool = FHE.asEbool(true);
17+
FHE.allowThis(xBool);
18+
FHE.allow(xBool, msg.sender);
19+
}
20+
21+
function delegate(address contract_delegate_address) public {
22+
FHE.delegateUserDecryption(msg.sender, contract_delegate_address, uint64(block.timestamp + 1 days));
23+
}
24+
25+
function revoke(address contract_delegate_address) public {
26+
FHE.revokeUserDecryptionDelegation(msg.sender, contract_delegate_address);
27+
}
28+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { expect } from 'chai';
2+
import { ethers } from 'hardhat';
3+
4+
import { createInstances } from '../instance';
5+
import { getSigners, initSigners } from '../signers';
6+
import { userDecryptSingleHandle } from '../utils';
7+
8+
describe('Delegate user decryption', function () {
9+
before(async function () {
10+
await initSigners(2);
11+
this.signers = await getSigners();
12+
this.instances = await createInstances(this.signers);
13+
const contractFactory = await ethers.getContractFactory('DelegateUserDecryptDelegator');
14+
15+
this.contract = await contractFactory.connect(this.signers.alice).deploy();
16+
await this.contract.waitForDeployment();
17+
this.contractAddress = await this.contract.getAddress();
18+
19+
const contractFactoryDelegate = await ethers.getContractFactory('DelegateUserDecryptDelegate');
20+
21+
this.contractDelegate = await contractFactoryDelegate.connect(this.signers.alice).deploy();
22+
await this.contractDelegate.waitForDeployment();
23+
this.contractDelegateAddress = await this.contractDelegate.getAddress();
24+
25+
this.instances = await createInstances(this.signers);
26+
});
27+
28+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
29+
it('test delegate user decrypt ebool', async function () {
30+
const block_time = 1000; // ms
31+
const { publicKey, privateKey } = this.instances.alice.generateKeypair();
32+
const handle1 = await this.contract.xBool();
33+
const tx_use_bool = await this.contractDelegate.useBool(handle1);
34+
await tx_use_bool.wait(1); // wait for 1 block
35+
const tx_handle2 = await this.contractDelegate.getResult();
36+
console.log("Handle2:", tx_handle2);
37+
const handle2 = tx_handle2;
38+
39+
const delegate = await this.contract.delegate(this.contractDelegateAddress);
40+
const delegate_result = await delegate.wait(1);
41+
expect(delegate_result.status).to.equal(1);
42+
43+
await sleep( 15 * block_time); // wait for 15 seconds to ensure delegation is active
44+
45+
const revoke = await this.contract.revoke(this.contractDelegateAddress);
46+
const revoke_result = await revoke.wait(1);
47+
expect(revoke_result.status).to.equal(1);
48+
await sleep( 15 * block_time); // wait for 15 seconds to ensure delegation is revoked
49+
50+
});
51+
});

test-suite/fhevm/fhevm-cli

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ export CONNECTOR_KMS_WORKER_VERSION=${CONNECTOR_KMS_WORKER_VERSION:-"b815aff"}
2323
export CONNECTOR_TX_SENDER_VERSION=${CONNECTOR_TX_SENDER_VERSION:-"b815aff"}
2424

2525
# Coprocessor services.
26-
export DB_MIGRATION_VERSION=${DB_MIGRATION_VERSION:-"v0.9.5"}
26+
export DB_MIGRATION_VERSION=${DB_MIGRATION_VERSION:-"22fa74e"}
2727
export GW_LISTENER_VERSION=${GW_LISTENER_VERSION:-"v0.9.5"}
28-
export HOST_LISTENER_VERSION=${HOST_LISTENER_VERSION:-"v0.9.5"}
29-
export TX_SENDER_VERSION=${TX_SENDER_VERSION:-"v0.9.5"}
28+
export HOST_LISTENER_VERSION=${HOST_LISTENER_VERSION:-"22fa74e"}
29+
export TX_SENDER_VERSION=${TX_SENDER_VERSION:-"22fa74e"}
3030
export TFHE_WORKER_VERSION=${TFHE_WORKER_VERSION:-"v0.9.5"}
3131
export SNS_WORKER_VERSION=${SNS_WORKER_VERSION:-"v0.9.5"}
3232
export ZKPROOF_WORKER_VERSION=${ZKPROOF_WORKER_VERSION:-"v0.9.5"}
3333

3434
# Gateway and Host contracts.
35-
export GATEWAY_VERSION=${GATEWAY_VERSION:-"b815aff"}
36-
export HOST_VERSION=${HOST_VERSION:-"5d96886"}
35+
export GATEWAY_VERSION=${GATEWAY_VERSION:-"22fa74e"}
36+
export HOST_VERSION=${HOST_VERSION:-"22fa74e"}
3737

3838
# Other services.
3939
export CORE_VERSION=${CORE_VERSION:-"v0.12.4"}
4040
export RELAYER_VERSION=${RELAYER_VERSION:-"v0.5.0-2"}
41-
export TEST_SUITE_VERSION=${TEST_SUITE_VERSION:-"v0.9.5"}
41+
export TEST_SUITE_VERSION=${TEST_SUITE_VERSION:-"22fa74e"}
4242

4343

4444
function print_logo() {
@@ -176,6 +176,17 @@ case $COMMAND in
176176
log_message="${LIGHT_BLUE}${BOLD}[TEST] USER DECRYPTION${RESET}"
177177
docker_args+=("-g" "test user decrypt")
178178
;;
179+
delegate-user-decryption)
180+
log_message="${LIGHT_BLUE}${BOLD}[TEST] USER DECRYPTION${RESET}"
181+
docker_args+=("-g" "test delegate user decrypt")
182+
echo -e "${log_message}"
183+
docker exec fhevm-test-suite-e2e-debug "${docker_args[@]}"
184+
echo Checking transaction-sender logs for DelegateUserDecryption
185+
./fhevm-cli logs coprocessor-transaction-sender | grep "DelegateUserDecryption txn succeeded"
186+
echo Checking transaction-sender logs for RevokeUserDecryptionDelegation
187+
./fhevm-cli logs coprocessor-transaction-sender | grep "RevokeUserDecryptionDelegation txn succeeded"
188+
exit 0 # the test has been called unlike other case branch
189+
;;
179190
public-decryption)
180191
log_message="${LIGHT_BLUE}${BOLD}[TEST] PUBLIC DECRYPTION${RESET}"
181192
docker_args+=("-g" "test async decrypt (uint.*|ebytes.* trivial|ebytes64 non-trivial|ebytes256 non-trivial with snapshot|addresses|several addresses)")

0 commit comments

Comments
 (0)