@cofhe/foundry-plugin 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -7
- package/contracts/CofheClient.sol +1 -1
- package/contracts/CofheTest.sol +18 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -66,17 +66,27 @@ contract MyTest is CofheTest {
|
|
|
66
66
|
}
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
## Gas reporting
|
|
70
|
+
|
|
71
|
+
Mock FHE operations replicate the off-chain CoFHE work on-chain, which would normally inflate reported gas 2–3×. Under forge, `deployMocks()` excludes that mock-only work from gas metering by default (via `pauseGasMetering` cheatcodes), so `forge test --gas-report`, `forge snapshot`, and `gasleft()` measurements report numbers close to real-network costs.
|
|
72
|
+
|
|
73
|
+
- Requires forge ≥ 1.0 (older versions had unreliable `pauseGasMetering` behavior). On unsupported setups the shim silently falls back to normal metering — correctness is never affected.
|
|
74
|
+
- Opt out with `mockTaskManager.setMockGasExcluded(false)` to see raw mock gas.
|
|
75
|
+
- When exclusion is off (or on Hardhat), the mock task manager instead emits a `MockGasConsumed(uint256)` event per block of mock-only work, so the overhead remains measurable from receipts.
|
|
76
|
+
|
|
77
|
+
Note: upgrading to a version with this feature will lower existing `forge snapshot` numbers — the drop is the mock overhead disappearing from the report, not a change in your contracts.
|
|
78
|
+
|
|
69
79
|
## API
|
|
70
80
|
|
|
71
81
|
### `CofheTest` (abstract base)
|
|
72
82
|
|
|
73
|
-
| Function | Description
|
|
74
|
-
| -------------------------------- |
|
|
75
|
-
| `deployMocks()` | Deploys all mock contracts and wires them together
|
|
76
|
-
| `createCofheClient()` | Returns a new unconnected `CofheClient`
|
|
77
|
-
| `enableLogs()` / `disableLogs()` | Toggle plaintext operation logging
|
|
78
|
-
| `getPlaintext(ctHash)` | Returns the stored plaintext for a ciphertext handle
|
|
79
|
-
| `expectPlaintext(handle, value)` | Asserts the plaintext of an encrypted handle matches `value`
|
|
83
|
+
| Function | Description |
|
|
84
|
+
| -------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
85
|
+
| `deployMocks()` | Deploys all mock contracts and wires them together; enables mock-gas exclusion (see Gas reporting) |
|
|
86
|
+
| `createCofheClient()` | Returns a new unconnected `CofheClient` |
|
|
87
|
+
| `enableLogs()` / `disableLogs()` | Toggle plaintext operation logging |
|
|
88
|
+
| `getPlaintext(ctHash)` | Returns the stored plaintext for a ciphertext handle |
|
|
89
|
+
| `expectPlaintext(handle, value)` | Asserts the plaintext of an encrypted handle matches `value` |
|
|
80
90
|
|
|
81
91
|
`getPlaintext` and `expectPlaintext` have typed overloads for `ebool`, `euint8`, `euint16`, `euint32`, `euint64`, `euint128`, and `eaddress`.
|
|
82
92
|
|
|
@@ -50,7 +50,7 @@ contract CofheClient is Test {
|
|
|
50
50
|
bool private _connected;
|
|
51
51
|
|
|
52
52
|
constructor() {
|
|
53
|
-
mockTaskManager = MockTaskManager(
|
|
53
|
+
mockTaskManager = MockTaskManager(address(Common.tm()));
|
|
54
54
|
mockAcl = MockACL(address(mockTaskManager.acl()));
|
|
55
55
|
mockZkVerifier = MockZkVerifier(ZK_VERIFIER_ADDRESS);
|
|
56
56
|
mockZkVerifierSigner = MockZkVerifierSigner(ZK_VERIFIER_SIGNER_ADDRESS);
|
package/contracts/CofheTest.sol
CHANGED
|
@@ -3,6 +3,7 @@ pragma solidity ^0.8.13;
|
|
|
3
3
|
|
|
4
4
|
import { Test } from 'forge-std/Test.sol';
|
|
5
5
|
import '@fhenixprotocol/cofhe-contracts/FHE.sol';
|
|
6
|
+
import { MockCoFHEAddressBook } from '@cofhe/mock-contracts/contracts/MockCoFHEAddressBook.sol';
|
|
6
7
|
import { MockTaskManager } from '@cofhe/mock-contracts/contracts/MockTaskManager.sol';
|
|
7
8
|
import { MockACL } from '@cofhe/mock-contracts/contracts/MockACL.sol';
|
|
8
9
|
import { ACPTimestampRevoker } from '@cofhe/mock-contracts/contracts/ACPTimestampRevoker.sol';
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
/// @dev Inherit this contract and call `deployMocks()` in your `setUp()` function.
|
|
22
23
|
/// Use `createCofheClient()` to obtain a connected client instance.
|
|
23
24
|
abstract contract CofheTest is Test {
|
|
25
|
+
MockCoFHEAddressBook public mockAddressBook;
|
|
24
26
|
MockTaskManager public mockTaskManager;
|
|
25
27
|
MockACL public mockAcl;
|
|
26
28
|
ACPTimestampRevoker public acpRevoker;
|
|
@@ -31,6 +33,7 @@ abstract contract CofheTest is Test {
|
|
|
31
33
|
MockThresholdNetworkSigner public mockThresholdNetworkSigner;
|
|
32
34
|
|
|
33
35
|
// Keep in sync with `packages/sdk/core/consts.ts`
|
|
36
|
+
address constant MOCKS_TASK_MANAGER_ADDRESS = 0x0000000000000000000000000000000000005000;
|
|
34
37
|
address constant ZK_VERIFIER_ADDRESS = 0x0000000000000000000000000000000000005001;
|
|
35
38
|
address constant THRESHOLD_NETWORK_ADDRESS = 0x0000000000000000000000000000000000005002;
|
|
36
39
|
|
|
@@ -42,15 +45,27 @@ abstract contract CofheTest is Test {
|
|
|
42
45
|
|
|
43
46
|
/// @notice Deploys all mock contracts and wires them together, mirroring the Hardhat plugin's deployment order.
|
|
44
47
|
function deployMocks() public {
|
|
48
|
+
// 0. Address Book (FHE.sol resolves the Task Manager through it)
|
|
49
|
+
deployCodeTo('MockCoFHEAddressBook.sol:MockCoFHEAddressBook', COFHE_ADDRESS_BOOK);
|
|
50
|
+
mockAddressBook = MockCoFHEAddressBook(COFHE_ADDRESS_BOOK);
|
|
51
|
+
vm.label(address(mockAddressBook), 'MockCoFHEAddressBook');
|
|
52
|
+
|
|
45
53
|
// 1. Task Manager
|
|
46
|
-
deployCodeTo('MockTaskManager.sol:MockTaskManager',
|
|
47
|
-
mockTaskManager = MockTaskManager(
|
|
54
|
+
deployCodeTo('MockTaskManager.sol:MockTaskManager', MOCKS_TASK_MANAGER_ADDRESS);
|
|
55
|
+
mockTaskManager = MockTaskManager(MOCKS_TASK_MANAGER_ADDRESS);
|
|
56
|
+
mockAddressBook.setTm(TASK_MANAGER_ID, MOCKS_TASK_MANAGER_ADDRESS);
|
|
48
57
|
mockTaskManager.initialize(TM_ADMIN);
|
|
49
58
|
mockTaskManager.setLogOps(false);
|
|
59
|
+
// Exclude mock-only plaintext replication from gas metering so reported gas is closer
|
|
60
|
+
// to the real task manager. Requires cheatcode access, which etched contracts don't
|
|
61
|
+
// inherit from the test contract.
|
|
62
|
+
vm.allowCheatcodes(MOCKS_TASK_MANAGER_ADDRESS);
|
|
63
|
+
mockTaskManager.setMockGasExcluded(true);
|
|
50
64
|
vm.label(address(mockTaskManager), 'MockTaskManager');
|
|
51
65
|
|
|
52
66
|
// 2. ACL (non-fixed deploy so constructor runs and EIP712 domain is set)
|
|
53
67
|
mockAcl = new MockACL();
|
|
68
|
+
mockAcl.setTaskManager(address(mockTaskManager));
|
|
54
69
|
vm.label(address(mockAcl), 'MockACL');
|
|
55
70
|
|
|
56
71
|
// ACP (ACP V3): default revoker (verification inherited by the ACL)
|
|
@@ -88,7 +103,7 @@ abstract contract CofheTest is Test {
|
|
|
88
103
|
// 7. Threshold Network
|
|
89
104
|
deployCodeTo('MockThresholdNetwork.sol:MockThresholdNetwork', THRESHOLD_NETWORK_ADDRESS);
|
|
90
105
|
mockThresholdNetwork = MockThresholdNetwork(THRESHOLD_NETWORK_ADDRESS);
|
|
91
|
-
mockThresholdNetwork.initialize(
|
|
106
|
+
mockThresholdNetwork.initialize(address(mockTaskManager), address(mockAcl));
|
|
92
107
|
vm.label(address(mockThresholdNetwork), 'MockThresholdNetwork');
|
|
93
108
|
|
|
94
109
|
// 8. Threshold Network Signer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cofhe/foundry-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Foundry plugin for CoFHE — Write and test FHE enabled contracts",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"fhenix"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@fhenixprotocol/cofhe-contracts": "0.
|
|
27
|
+
"@fhenixprotocol/cofhe-contracts": "1.0.0",
|
|
28
28
|
"@openzeppelin/contracts": "5.4.0",
|
|
29
|
-
"@cofhe/mock-contracts": "0.
|
|
29
|
+
"@cofhe/mock-contracts": "0.8.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"forge-std": "github:foundry-rs/forge-std#c0f966cb111f621bfb283b2a388bc7be18953bba",
|