@cofhe/mock-contracts 0.5.1 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @cofhe/mock-contracts Changelog
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 566f126: Remove the legacy `TestBed` mock surface and stop auto-deploying `SimpleTest` through the Hardhat plugins. Core mock contracts still deploy automatically, while tests that need `SimpleTest` should deploy it explicitly from their own artifacts.
8
+
9
+ This also removes `TEST_BED_ADDRESS` and cleans up duplicate `SimpleTest` exports from `@cofhe/mock-contracts`.
10
+
11
+ ## 0.5.2
12
+
3
13
  ## 0.5.1
4
14
 
5
15
  ### Patch Changes
package/README.md CHANGED
@@ -112,11 +112,11 @@ In `cofhe-mock-contracts` the symbolic execution is preserved. In the case of th
112
112
 
113
113
  During the execution of a mock FHE operation, say `FHE.add(euint8 ctHashA, euint8 ctHashB) -> euint8 ctHashC`, rather than being performed off-chain by the FHE computation engine, the input `ctHashes` are mapped to their plaintext value, and the operation performed as plaintext math on-chain. The result is inserted into the symbolic value position of `ctHashC`.
114
114
 
115
- ### On-chain Decryption
115
+ ### Decryption for On-chain Use
116
116
 
117
- CoFHE coprocessor handles on-chain decryption requests asynchronously. Once the decryption is requested with `FHE.decrypt(...)` the decryption will be performed off-chain by CoFHE, and the result posted on-chain in the `PlaintextStorage` module of `TaskManager`. The decryption result can then checked using either `FHE.getDecryptResult(...)` or `FHE.getDecryptResultSafe(...)`.
117
+ For tx-oriented decryption, the consumer calls the Threshold Network decrypt endpoint and receives the plaintext together with a signature binding that plaintext to the `ctHash`. Contracts can then use that signature with `FHE.publishDecryptResult(...)` or `FHE.verifyDecryptResult(...)`.
118
118
 
119
- When a mock decryption is requested, a random number between 1 and 10 is generated to determine how many seconds the mock decryption async duration. Though the decryption result is available immediately within the mock contracts, the async duration is added to mimic the off-chain decryption and posting time.
119
+ When working with the mocks, the equivalent result is produced by the mock contracts. A random number between 1 and 10 is generated to simulate async delay, but the flow still resolves to the same kind of tx-ready decrypt result.
120
120
 
121
121
  ### ZkVerifying
122
122
 
@@ -131,11 +131,11 @@ The `MockZkVerifier` contract handles the on-chain storage of encrypted inputs.
131
131
 
132
132
  ### Off-chain Decryption / Sealing
133
133
 
134
- Off-chain decryption is performed by calling the `cofheClient.decryptHandle` function with a valid `ctHash` and a valid `permit` [todo link].
134
+ For view-oriented decryption, use the SDK flow `cofheClient.decryptForView(...)` (also exposed as `decryptHandle(...)`) with a valid `ctHash`, the matching FHE type, and a valid `permit` when required.
135
135
 
136
- When interacting with CoFHE this request is routed to the Threshold Network, which will perform the decryption operation, ultimately returning a decrypted result.
136
+ When interacting with CoFHE this request is routed to the Threshold Network, which returns the plaintext to the consumer for local use.
137
137
 
138
- When working with the mocks, the `cofheClient` will instead query the `MockThresholdNetwork` contract, which will verify the request `permit`, and return the decrypted result.
138
+ When working with the mocks, the `cofheClient` instead queries the `MockThresholdNetwork` contract, which verifies the request `permit` and returns the decrypted result.
139
139
 
140
140
  ### Using Foundry
141
141
 
@@ -145,16 +145,18 @@ CoFheTest also exposes useful test methods such as
145
145
 
146
146
  - `assertHashValue(euint, uint)` - asserting an encrypted value is equal to an expected plaintext value
147
147
  - `createInEuint..(number, user)` - for creating encrypted inputs (8-256bits) for a given user
148
+ - `createInEuint*_asHashPlusProof(number, user)` - for creating encrypted inputs in the hash plus proof format
148
149
 
149
- see `contracts/TestBed.sol` for the original contract
150
+ Example:
150
151
 
151
152
  ```solidity
152
153
  import {Test} from "forge-std/Test.sol";
153
154
  import {CoFheTest} from "@fhenixprotocol/cofhe-contracts/FHE.sol";
155
+ import {MyFheContract} from "./MyFheContract.sol";
154
156
  ...
155
- contract TestBed is Test, CoFheTest {
157
+ contract MyFheContractExample is Test, CoFheTest {
156
158
 
157
- TestBed private testbed;
159
+ MyFheContract private target;
158
160
 
159
161
  address private user = makeAddr("user");
160
162
 
@@ -162,19 +164,19 @@ contract TestBed is Test, CoFheTest {
162
164
  // optional ... enable verbose logging for fhe mocks
163
165
  // setLog(true);
164
166
 
165
- testbed = new TestBed();
167
+ target = new MyFheContract();
166
168
  }
167
169
 
168
- function testSetNumber() public {
170
+ function testSetValue() public {
169
171
  uint32 n = 10;
170
172
  InEuint32 memory number = createInEuint32(n, user);
171
173
 
172
174
  //must be the user who sends transaction
173
175
  //or else invalid permissions from fhe allow
174
176
  vm.prank(user);
175
- testbed.setNumber(number);
177
+ target.setValue(number);
176
178
 
177
- assertHashValue(testbed.eNumber(), n);
179
+ assertHashValue(target.getValue(), n);
178
180
  }
179
181
  }
180
182
  ```
package/dist/index.d.mts CHANGED
@@ -2005,243 +2005,6 @@ declare const MockThresholdNetworkArtifact: {
2005
2005
  }];
2006
2006
  };
2007
2007
 
2008
- declare const TestBedArtifact: {
2009
- readonly contractName: "TestBed";
2010
- readonly isFixed: true;
2011
- readonly fixedAddress: "0x0000000000000000000000000000000000005003";
2012
- readonly abi: readonly [{
2013
- readonly type: "function";
2014
- readonly name: "add";
2015
- readonly inputs: readonly [{
2016
- readonly name: "inNumber";
2017
- readonly type: "tuple";
2018
- readonly internalType: "struct InEuint32";
2019
- readonly components: readonly [{
2020
- readonly name: "ctHash";
2021
- readonly type: "uint256";
2022
- readonly internalType: "uint256";
2023
- }, {
2024
- readonly name: "securityZone";
2025
- readonly type: "uint8";
2026
- readonly internalType: "uint8";
2027
- }, {
2028
- readonly name: "utype";
2029
- readonly type: "uint8";
2030
- readonly internalType: "uint8";
2031
- }, {
2032
- readonly name: "signature";
2033
- readonly type: "bytes";
2034
- readonly internalType: "bytes";
2035
- }];
2036
- }];
2037
- readonly outputs: readonly [];
2038
- readonly stateMutability: "nonpayable";
2039
- }, {
2040
- readonly type: "function";
2041
- readonly name: "decrypt";
2042
- readonly inputs: readonly [];
2043
- readonly outputs: readonly [];
2044
- readonly stateMutability: "nonpayable";
2045
- }, {
2046
- readonly type: "function";
2047
- readonly name: "eNumber";
2048
- readonly inputs: readonly [];
2049
- readonly outputs: readonly [{
2050
- readonly name: "";
2051
- readonly type: "bytes32";
2052
- readonly internalType: "euint32";
2053
- }];
2054
- readonly stateMutability: "view";
2055
- }, {
2056
- readonly type: "function";
2057
- readonly name: "exists";
2058
- readonly inputs: readonly [];
2059
- readonly outputs: readonly [{
2060
- readonly name: "";
2061
- readonly type: "bool";
2062
- readonly internalType: "bool";
2063
- }];
2064
- readonly stateMutability: "pure";
2065
- }, {
2066
- readonly type: "function";
2067
- readonly name: "getDecryptResult";
2068
- readonly inputs: readonly [{
2069
- readonly name: "input1";
2070
- readonly type: "bytes32";
2071
- readonly internalType: "euint32";
2072
- }];
2073
- readonly outputs: readonly [{
2074
- readonly name: "";
2075
- readonly type: "uint32";
2076
- readonly internalType: "uint32";
2077
- }];
2078
- readonly stateMutability: "view";
2079
- }, {
2080
- readonly type: "function";
2081
- readonly name: "getDecryptResultSafe";
2082
- readonly inputs: readonly [{
2083
- readonly name: "input1";
2084
- readonly type: "bytes32";
2085
- readonly internalType: "euint32";
2086
- }];
2087
- readonly outputs: readonly [{
2088
- readonly name: "value";
2089
- readonly type: "uint32";
2090
- readonly internalType: "uint32";
2091
- }, {
2092
- readonly name: "decrypted";
2093
- readonly type: "bool";
2094
- readonly internalType: "bool";
2095
- }];
2096
- readonly stateMutability: "view";
2097
- }, {
2098
- readonly type: "function";
2099
- readonly name: "increment";
2100
- readonly inputs: readonly [];
2101
- readonly outputs: readonly [];
2102
- readonly stateMutability: "nonpayable";
2103
- }, {
2104
- readonly type: "function";
2105
- readonly name: "mul";
2106
- readonly inputs: readonly [{
2107
- readonly name: "inNumber";
2108
- readonly type: "tuple";
2109
- readonly internalType: "struct InEuint32";
2110
- readonly components: readonly [{
2111
- readonly name: "ctHash";
2112
- readonly type: "uint256";
2113
- readonly internalType: "uint256";
2114
- }, {
2115
- readonly name: "securityZone";
2116
- readonly type: "uint8";
2117
- readonly internalType: "uint8";
2118
- }, {
2119
- readonly name: "utype";
2120
- readonly type: "uint8";
2121
- readonly internalType: "uint8";
2122
- }, {
2123
- readonly name: "signature";
2124
- readonly type: "bytes";
2125
- readonly internalType: "bytes";
2126
- }];
2127
- }];
2128
- readonly outputs: readonly [];
2129
- readonly stateMutability: "nonpayable";
2130
- }, {
2131
- readonly type: "function";
2132
- readonly name: "numberHash";
2133
- readonly inputs: readonly [];
2134
- readonly outputs: readonly [{
2135
- readonly name: "";
2136
- readonly type: "bytes32";
2137
- readonly internalType: "bytes32";
2138
- }];
2139
- readonly stateMutability: "view";
2140
- }, {
2141
- readonly type: "function";
2142
- readonly name: "publishDecryptResult";
2143
- readonly inputs: readonly [{
2144
- readonly name: "input";
2145
- readonly type: "bytes32";
2146
- readonly internalType: "euint32";
2147
- }, {
2148
- readonly name: "result";
2149
- readonly type: "uint32";
2150
- readonly internalType: "uint32";
2151
- }, {
2152
- readonly name: "signature";
2153
- readonly type: "bytes";
2154
- readonly internalType: "bytes";
2155
- }];
2156
- readonly outputs: readonly [];
2157
- readonly stateMutability: "nonpayable";
2158
- }, {
2159
- readonly type: "function";
2160
- readonly name: "setNumber";
2161
- readonly inputs: readonly [{
2162
- readonly name: "inNumber";
2163
- readonly type: "tuple";
2164
- readonly internalType: "struct InEuint32";
2165
- readonly components: readonly [{
2166
- readonly name: "ctHash";
2167
- readonly type: "uint256";
2168
- readonly internalType: "uint256";
2169
- }, {
2170
- readonly name: "securityZone";
2171
- readonly type: "uint8";
2172
- readonly internalType: "uint8";
2173
- }, {
2174
- readonly name: "utype";
2175
- readonly type: "uint8";
2176
- readonly internalType: "uint8";
2177
- }, {
2178
- readonly name: "signature";
2179
- readonly type: "bytes";
2180
- readonly internalType: "bytes";
2181
- }];
2182
- }];
2183
- readonly outputs: readonly [];
2184
- readonly stateMutability: "nonpayable";
2185
- }, {
2186
- readonly type: "function";
2187
- readonly name: "setNumberTrivial";
2188
- readonly inputs: readonly [{
2189
- readonly name: "inNumber";
2190
- readonly type: "uint32";
2191
- readonly internalType: "uint32";
2192
- }];
2193
- readonly outputs: readonly [];
2194
- readonly stateMutability: "nonpayable";
2195
- }, {
2196
- readonly type: "function";
2197
- readonly name: "sub";
2198
- readonly inputs: readonly [{
2199
- readonly name: "inNumber";
2200
- readonly type: "tuple";
2201
- readonly internalType: "struct InEuint32";
2202
- readonly components: readonly [{
2203
- readonly name: "ctHash";
2204
- readonly type: "uint256";
2205
- readonly internalType: "uint256";
2206
- }, {
2207
- readonly name: "securityZone";
2208
- readonly type: "uint8";
2209
- readonly internalType: "uint8";
2210
- }, {
2211
- readonly name: "utype";
2212
- readonly type: "uint8";
2213
- readonly internalType: "uint8";
2214
- }, {
2215
- readonly name: "signature";
2216
- readonly type: "bytes";
2217
- readonly internalType: "bytes";
2218
- }];
2219
- }];
2220
- readonly outputs: readonly [];
2221
- readonly stateMutability: "nonpayable";
2222
- }, {
2223
- readonly type: "error";
2224
- readonly name: "InvalidEncryptedInput";
2225
- readonly inputs: readonly [{
2226
- readonly name: "got";
2227
- readonly type: "uint8";
2228
- readonly internalType: "uint8";
2229
- }, {
2230
- readonly name: "expected";
2231
- readonly type: "uint8";
2232
- readonly internalType: "uint8";
2233
- }];
2234
- }, {
2235
- readonly type: "error";
2236
- readonly name: "SecurityZoneOutOfBounds";
2237
- readonly inputs: readonly [{
2238
- readonly name: "value";
2239
- readonly type: "int32";
2240
- readonly internalType: "int32";
2241
- }];
2242
- }];
2243
- };
2244
-
2245
2008
  interface TypedDeferredTopicFilter<_TCEvent extends TypedContractEvent> extends DeferredTopicFilter {
2246
2009
  }
2247
2010
  interface TypedContractEvent<InputTuple extends Array<any> = any, OutputTuple extends Array<any> = any, OutputObject = any> {
@@ -3165,98 +2928,4 @@ interface MockZkVerifier extends BaseContract {
3165
2928
  filters: {};
3166
2929
  }
3167
2930
 
3168
- type InEuint32Struct = {
3169
- ctHash: BigNumberish;
3170
- securityZone: BigNumberish;
3171
- utype: BigNumberish;
3172
- signature: BytesLike;
3173
- };
3174
- interface TestBedInterface extends Interface {
3175
- getFunction(nameOrSignature: 'add' | 'decrypt' | 'eNumber' | 'exists' | 'getDecryptResult' | 'getDecryptResultSafe' | 'increment' | 'mul' | 'numberHash' | 'publishDecryptResult' | 'setNumber' | 'setNumberTrivial' | 'sub'): FunctionFragment;
3176
- encodeFunctionData(functionFragment: 'add', values: [InEuint32Struct]): string;
3177
- encodeFunctionData(functionFragment: 'decrypt', values?: undefined): string;
3178
- encodeFunctionData(functionFragment: 'eNumber', values?: undefined): string;
3179
- encodeFunctionData(functionFragment: 'exists', values?: undefined): string;
3180
- encodeFunctionData(functionFragment: 'getDecryptResult', values: [BytesLike]): string;
3181
- encodeFunctionData(functionFragment: 'getDecryptResultSafe', values: [BytesLike]): string;
3182
- encodeFunctionData(functionFragment: 'increment', values?: undefined): string;
3183
- encodeFunctionData(functionFragment: 'mul', values: [InEuint32Struct]): string;
3184
- encodeFunctionData(functionFragment: 'numberHash', values?: undefined): string;
3185
- encodeFunctionData(functionFragment: 'publishDecryptResult', values: [BytesLike, BigNumberish, BytesLike]): string;
3186
- encodeFunctionData(functionFragment: 'setNumber', values: [InEuint32Struct]): string;
3187
- encodeFunctionData(functionFragment: 'setNumberTrivial', values: [BigNumberish]): string;
3188
- encodeFunctionData(functionFragment: 'sub', values: [InEuint32Struct]): string;
3189
- decodeFunctionResult(functionFragment: 'add', data: BytesLike): Result;
3190
- decodeFunctionResult(functionFragment: 'decrypt', data: BytesLike): Result;
3191
- decodeFunctionResult(functionFragment: 'eNumber', data: BytesLike): Result;
3192
- decodeFunctionResult(functionFragment: 'exists', data: BytesLike): Result;
3193
- decodeFunctionResult(functionFragment: 'getDecryptResult', data: BytesLike): Result;
3194
- decodeFunctionResult(functionFragment: 'getDecryptResultSafe', data: BytesLike): Result;
3195
- decodeFunctionResult(functionFragment: 'increment', data: BytesLike): Result;
3196
- decodeFunctionResult(functionFragment: 'mul', data: BytesLike): Result;
3197
- decodeFunctionResult(functionFragment: 'numberHash', data: BytesLike): Result;
3198
- decodeFunctionResult(functionFragment: 'publishDecryptResult', data: BytesLike): Result;
3199
- decodeFunctionResult(functionFragment: 'setNumber', data: BytesLike): Result;
3200
- decodeFunctionResult(functionFragment: 'setNumberTrivial', data: BytesLike): Result;
3201
- decodeFunctionResult(functionFragment: 'sub', data: BytesLike): Result;
3202
- }
3203
- interface TestBed extends BaseContract {
3204
- connect(runner?: ContractRunner | null): TestBed;
3205
- waitForDeployment(): Promise<this>;
3206
- interface: TestBedInterface;
3207
- queryFilter<TCEvent extends TypedContractEvent>(event: TCEvent, fromBlockOrBlockhash?: string | number | undefined, toBlock?: string | number | undefined): Promise<Array<TypedEventLog<TCEvent>>>;
3208
- queryFilter<TCEvent extends TypedContractEvent>(filter: TypedDeferredTopicFilter<TCEvent>, fromBlockOrBlockhash?: string | number | undefined, toBlock?: string | number | undefined): Promise<Array<TypedEventLog<TCEvent>>>;
3209
- on<TCEvent extends TypedContractEvent>(event: TCEvent, listener: TypedListener<TCEvent>): Promise<this>;
3210
- on<TCEvent extends TypedContractEvent>(filter: TypedDeferredTopicFilter<TCEvent>, listener: TypedListener<TCEvent>): Promise<this>;
3211
- once<TCEvent extends TypedContractEvent>(event: TCEvent, listener: TypedListener<TCEvent>): Promise<this>;
3212
- once<TCEvent extends TypedContractEvent>(filter: TypedDeferredTopicFilter<TCEvent>, listener: TypedListener<TCEvent>): Promise<this>;
3213
- listeners<TCEvent extends TypedContractEvent>(event: TCEvent): Promise<Array<TypedListener<TCEvent>>>;
3214
- listeners(eventName?: string): Promise<Array<Listener>>;
3215
- removeAllListeners<TCEvent extends TypedContractEvent>(event?: TCEvent): Promise<this>;
3216
- add: TypedContractMethod<[inNumber: InEuint32Struct], [void], 'nonpayable'>;
3217
- decrypt: TypedContractMethod<[], [void], 'nonpayable'>;
3218
- eNumber: TypedContractMethod<[], [string], 'view'>;
3219
- exists: TypedContractMethod<[], [boolean], 'view'>;
3220
- getDecryptResult: TypedContractMethod<[input1: BytesLike], [bigint], 'view'>;
3221
- getDecryptResultSafe: TypedContractMethod<[
3222
- input1: BytesLike
3223
- ], [
3224
- [bigint, boolean] & {
3225
- value: bigint;
3226
- decrypted: boolean;
3227
- }
3228
- ], 'view'>;
3229
- increment: TypedContractMethod<[], [void], 'nonpayable'>;
3230
- mul: TypedContractMethod<[inNumber: InEuint32Struct], [void], 'nonpayable'>;
3231
- numberHash: TypedContractMethod<[], [string], 'view'>;
3232
- publishDecryptResult: TypedContractMethod<[
3233
- input: BytesLike,
3234
- result: BigNumberish,
3235
- signature: BytesLike
3236
- ], [
3237
- void
3238
- ], 'nonpayable'>;
3239
- setNumber: TypedContractMethod<[inNumber: InEuint32Struct], [void], 'nonpayable'>;
3240
- setNumberTrivial: TypedContractMethod<[inNumber: BigNumberish], [void], 'nonpayable'>;
3241
- sub: TypedContractMethod<[inNumber: InEuint32Struct], [void], 'nonpayable'>;
3242
- getFunction<T extends ContractMethod = ContractMethod>(key: string | FunctionFragment): T;
3243
- getFunction(nameOrSignature: 'add'): TypedContractMethod<[inNumber: InEuint32Struct], [void], 'nonpayable'>;
3244
- getFunction(nameOrSignature: 'decrypt'): TypedContractMethod<[], [void], 'nonpayable'>;
3245
- getFunction(nameOrSignature: 'eNumber'): TypedContractMethod<[], [string], 'view'>;
3246
- getFunction(nameOrSignature: 'exists'): TypedContractMethod<[], [boolean], 'view'>;
3247
- getFunction(nameOrSignature: 'getDecryptResult'): TypedContractMethod<[input1: BytesLike], [bigint], 'view'>;
3248
- getFunction(nameOrSignature: 'getDecryptResultSafe'): TypedContractMethod<[input1: BytesLike], [[bigint, boolean] & {
3249
- value: bigint;
3250
- decrypted: boolean;
3251
- }], 'view'>;
3252
- getFunction(nameOrSignature: 'increment'): TypedContractMethod<[], [void], 'nonpayable'>;
3253
- getFunction(nameOrSignature: 'mul'): TypedContractMethod<[inNumber: InEuint32Struct], [void], 'nonpayable'>;
3254
- getFunction(nameOrSignature: 'numberHash'): TypedContractMethod<[], [string], 'view'>;
3255
- getFunction(nameOrSignature: 'publishDecryptResult'): TypedContractMethod<[input: BytesLike, result: BigNumberish, signature: BytesLike], [void], 'nonpayable'>;
3256
- getFunction(nameOrSignature: 'setNumber'): TypedContractMethod<[inNumber: InEuint32Struct], [void], 'nonpayable'>;
3257
- getFunction(nameOrSignature: 'setNumberTrivial'): TypedContractMethod<[inNumber: BigNumberish], [void], 'nonpayable'>;
3258
- getFunction(nameOrSignature: 'sub'): TypedContractMethod<[inNumber: InEuint32Struct], [void], 'nonpayable'>;
3259
- filters: {};
3260
- }
3261
-
3262
- export { type MockACL, MockACLArtifact, type MockArtifact, type MockTaskManager, MockTaskManagerArtifact, type MockThresholdNetwork, MockThresholdNetworkArtifact, type MockZkVerifier, MockZkVerifierArtifact, type TestBed, TestBedArtifact };
2931
+ export { type MockACL, MockACLArtifact, type MockArtifact, type MockTaskManager, MockTaskManagerArtifact, type MockThresholdNetwork, MockThresholdNetworkArtifact, type MockZkVerifier, MockZkVerifierArtifact };