Skip to content

Commit dddecd7

Browse files
authored
chore: pin OZ confidential to v0.4.0 and simplify test helpers (#3)
Address review feedback: - Pin @openzeppelin-confidential-contracts to tagged release v0.4.0 instead of commit hash 6edd293. Add explicit @openzeppelin/contracts(-upgradeable)/ remappings, since v0.4.0 ships a lib/ folder with alias stubs that otherwise hijack forge's auto-remap fallback used by forge-fhevm. - Replace hardcoded ALICE_PK constant with forge-std's makeAccount("alice") helper, which returns an Account { addr, key } and labels the address. - Add a userDecryptAs(pk, handle, contract) helper that combines signUserDecrypt and userDecrypt into a single call site.
1 parent 25ae918 commit dddecd7

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ line_length = 120
2121
"@openzeppelin-contracts" = "5.1.0"
2222
"@openzeppelin-contracts-upgradeable" = "5.1.0"
2323
forge-std = "1.14.0"
24-
"@openzeppelin-confidential-contracts" = { version = "6edd293", git = "https://github.com/OpenZeppelin/openzeppelin-confidential-contracts.git", rev = "6edd293" }
24+
"@openzeppelin-confidential-contracts" = { version = "0.4.0", git = "https://github.com/OpenZeppelin/openzeppelin-confidential-contracts.git", rev = "v0.4.0" }
2525
"@encrypted-types" = "0.0.4"
2626
"@fhevm-solidity" = "0.11.1"
2727
forge-fhevm = { version = "eba2324", git = "https://github.com/zama-ai/forge-fhevm.git", rev = "eba2324" }

remappings.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
@fhevm/solidity/=dependencies/@fhevm-solidity-0.11.1/
33
@openzeppelin-contracts-upgradeable/=dependencies/@openzeppelin-contracts-upgradeable-5.1.0/
44
@openzeppelin-contracts/=dependencies/@openzeppelin-contracts-5.1.0/
5-
@openzeppelin/confidential-contracts/=dependencies/@openzeppelin-confidential-contracts-6edd293/contracts/
5+
@openzeppelin/contracts-upgradeable/=dependencies/@openzeppelin-contracts-upgradeable-5.1.0/
6+
@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-5.1.0/
7+
@openzeppelin/confidential-contracts/=dependencies/@openzeppelin-confidential-contracts-0.4.0/contracts/
68
encrypted-types/=dependencies/@encrypted-types-0.0.4/
79
forge-fhevm/=dependencies/forge-fhevm-eba2324/src/
810
forge-std/=dependencies/forge-std-1.14.0/src

soldeer.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ integrity = "67f415709d30b01d3876addb7e5bbaf3efc119cebe81dda10fb495163297b763"
1414

1515
[[dependencies]]
1616
name = "@openzeppelin-confidential-contracts"
17-
version = "6edd293"
17+
version = "0.4.0"
1818
git = "https://github.com/OpenZeppelin/openzeppelin-confidential-contracts.git"
19-
rev = "6edd293165d6dc1fd29fffaa391b370b1888a70d"
19+
rev = "v0.4.0"
2020

2121
[[dependencies]]
2222
name = "@openzeppelin-contracts"

test/FHECounter.t.sol

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ import {euint32, externalEuint32} from "encrypted-types/EncryptedTypes.sol";
88
contract FHECounterTest is FhevmTest {
99
FHECounter counter;
1010
address counterAddress;
11-
uint256 internal constant ALICE_PK = 0xA11CE;
12-
address alice;
11+
Account alice;
1312

1413
function setUp() public override {
1514
super.setUp();
1615
counter = new FHECounter();
1716
counterAddress = address(counter);
18-
alice = vm.addr(ALICE_PK);
17+
alice = makeAccount("alice");
18+
}
19+
20+
/// @dev Signs the user-decrypt request with `userPk` and decrypts `handle` in one step.
21+
function userDecryptAs(uint256 userPk, bytes32 handle, address contractAddress) internal returns (uint256) {
22+
bytes memory sig = signUserDecrypt(userPk, contractAddress);
23+
return userDecrypt(handle, vm.addr(userPk), contractAddress, sig);
1924
}
2025

2126
function test_encryptedCountShouldBeUninitializedAfterDeployment() public view {
@@ -31,35 +36,34 @@ contract FHECounterTest is FhevmTest {
3136

3237
// Encrypt constant 1 as a euint32
3338
uint32 clearOne = 1;
34-
(externalEuint32 encryptedOne, bytes memory inputProof) = encryptUint32(clearOne, alice, counterAddress);
39+
(externalEuint32 encryptedOne, bytes memory inputProof) = encryptUint32(clearOne, alice.addr, counterAddress);
3540

36-
vm.prank(alice);
41+
vm.prank(alice.addr);
3742
counter.increment(encryptedOne, inputProof);
3843

3944
euint32 encryptedCountAfterInc = counter.getCount();
40-
bytes memory sig = signUserDecrypt(ALICE_PK, counterAddress);
41-
uint256 clearCountAfterInc = userDecrypt(euint32.unwrap(encryptedCountAfterInc), alice, counterAddress, sig);
45+
uint256 clearCountAfterInc = userDecryptAs(alice.key, euint32.unwrap(encryptedCountAfterInc), counterAddress);
4246

4347
assertEq(clearCountAfterInc, clearCountBeforeInc + clearOne);
4448
}
4549

4650
function test_decrementTheCounterByOne() public {
4751
// Encrypt constant 1 as a euint32
4852
uint32 clearOne = 1;
49-
(externalEuint32 encryptedOne, bytes memory inputProof) = encryptUint32(clearOne, alice, counterAddress);
53+
(externalEuint32 encryptedOne, bytes memory inputProof) = encryptUint32(clearOne, alice.addr, counterAddress);
5054

5155
// First increment by 1, count becomes 1
52-
vm.prank(alice);
56+
vm.prank(alice.addr);
5357
counter.increment(encryptedOne, inputProof);
5458

5559
// Then decrement by 1, count goes back to 0
56-
(externalEuint32 encryptedOneDec, bytes memory inputProofDec) = encryptUint32(clearOne, alice, counterAddress);
57-
vm.prank(alice);
60+
(externalEuint32 encryptedOneDec, bytes memory inputProofDec) =
61+
encryptUint32(clearOne, alice.addr, counterAddress);
62+
vm.prank(alice.addr);
5863
counter.decrement(encryptedOneDec, inputProofDec);
5964

6065
euint32 encryptedCountAfterDec = counter.getCount();
61-
bytes memory sig = signUserDecrypt(ALICE_PK, counterAddress);
62-
uint256 clearCountAfterDec = userDecrypt(euint32.unwrap(encryptedCountAfterDec), alice, counterAddress, sig);
66+
uint256 clearCountAfterDec = userDecryptAs(alice.key, euint32.unwrap(encryptedCountAfterDec), counterAddress);
6367

6468
assertEq(clearCountAfterDec, 0);
6569
}

0 commit comments

Comments
 (0)