Skip to content

Commit 8517b4c

Browse files
committed
feat(test-suite): add test for two public decrypt requests made in same block
1 parent b094bf8 commit 8517b4c

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

test-suite/e2e/contracts/TestAsyncDecrypt.sol

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ contract TestAsyncDecrypt is E2EFHEVMConfig {
1212
euint8 xUint8;
1313
euint16 xUint16;
1414
euint32 xUint32;
15+
euint32 xUint32_2;
16+
euint32 xUint32_3;
1517
euint64 xUint64;
1618
euint64 xUint64_2;
1719
euint64 xUint64_3;
@@ -25,6 +27,8 @@ contract TestAsyncDecrypt is E2EFHEVMConfig {
2527
uint8 public yUint8;
2628
uint16 public yUint16;
2729
uint32 public yUint32;
30+
uint32 public yUint32_2;
31+
uint32 public yUint32_3;
2832
uint64 public yUint64;
2933
uint64 public yUint64_2;
3034
uint64 public yUint64_3;
@@ -44,13 +48,16 @@ contract TestAsyncDecrypt is E2EFHEVMConfig {
4448
/// @dev Initialize encrypted variables with sample values
4549
xBool = FHE.asEbool(true);
4650
FHE.allowThis(xBool);
47-
4851
xUint8 = FHE.asEuint8(42);
4952
FHE.allowThis(xUint8);
5053
xUint16 = FHE.asEuint16(16);
5154
FHE.allowThis(xUint16);
5255
xUint32 = FHE.asEuint32(32);
5356
FHE.allowThis(xUint32);
57+
xUint32_2 = FHE.asEuint32(1000);
58+
FHE.allowThis(xUint32_2);
59+
xUint32_3 = FHE.asEuint32(2000);
60+
FHE.allowThis(xUint32_3);
5461
xUint64 = FHE.asEuint64(18446744073709551600);
5562
FHE.allowThis(xUint64);
5663
xUint64_2 = FHE.asEuint64(76575465786);
@@ -200,6 +207,38 @@ contract TestAsyncDecrypt is E2EFHEVMConfig {
200207
}
201208
}
202209

210+
/// @notice Request decryption of a 32-bit unsigned integer
211+
function requestUint32_2() public {
212+
bytes32[] memory cts = new bytes32[](1);
213+
cts[0] = FHE.toBytes32(xUint32_2);
214+
FHE.requestDecryption(cts, this.callbackUint32_2.selector);
215+
}
216+
217+
function callbackUint32_2(
218+
uint256 requestID,
219+
uint32 decryptedInput,
220+
bytes[] memory signatures
221+
) public {
222+
FHE.checkSignatures(requestID, signatures);
223+
yUint32_2 = decryptedInput;
224+
}
225+
226+
/// @notice Request decryption of a 32-bit unsigned integer
227+
function requestUint32_3() public {
228+
bytes32[] memory cts = new bytes32[](1);
229+
cts[0] = FHE.toBytes32(xUint32_3);
230+
FHE.requestDecryption(cts, this.callbackUint32_3.selector);
231+
}
232+
233+
function callbackUint32_3(
234+
uint256 requestID,
235+
uint32 decryptedInput,
236+
bytes[] memory signatures
237+
) public {
238+
FHE.checkSignatures(requestID, signatures);
239+
yUint32_3 = decryptedInput;
240+
}
241+
203242
/// @notice Request decryption of a 64-bit unsigned integer
204243
function requestUint64() public {
205244
bytes32[] memory cts = new bytes32[](1);

test-suite/e2e/test/gatewayDecrypt/testAsyncDecrypt.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,31 @@ describe('TestAsyncDecrypt', function () {
132132
expect(y).to.equal(52); // 5+15+32
133133
});
134134

135+
it('test async decrypt uint32 - two requests in same block', async function () {
136+
const pendingNonce = await ethers.provider.getTransactionCount(this.signers.alice.address, "pending");
137+
138+
const [txA, txB] = await Promise.all([
139+
this.contract.requestUint32_2({
140+
nonce: pendingNonce,
141+
}),
142+
this.contract.requestUint32_3({
143+
nonce: pendingNonce+1,
144+
}),
145+
]);
146+
147+
const [receiptA, receiptB] = await Promise.all([txA.wait(), txB.wait()]);
148+
149+
console.log("txA block:", receiptA.blockNumber);
150+
console.log("txB block:", receiptB.blockNumber);
151+
152+
await awaitAllDecryptionResults();
153+
154+
const y2 = await this.contract.yUint32_2();
155+
expect(y2).to.equal(1000);
156+
const y3 = await this.contract.yUint32_3();
157+
expect(y3).to.equal(2000);
158+
});
159+
135160
it.skip('test async decrypt FAKE uint32', async function () {
136161
if (network.name !== 'hardhat') {
137162
// only in fhevm mode

0 commit comments

Comments
 (0)