@iexec-nox/nox-protocol-contracts 0.1.0-beta.5 → 0.1.0-beta.6

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.
@@ -110,6 +110,20 @@ interface INoxCompute {
110
110
  bytes32 success,
111
111
  bytes32 result
112
112
  );
113
+ event SafeMul(
114
+ address indexed caller,
115
+ bytes32 leftHandOperand,
116
+ bytes32 rightHandOperand,
117
+ bytes32 success,
118
+ bytes32 result
119
+ );
120
+ event SafeDiv(
121
+ address indexed caller,
122
+ bytes32 numerator,
123
+ bytes32 denominator,
124
+ bytes32 success,
125
+ bytes32 result
126
+ );
113
127
  event Select(
114
128
  address indexed caller,
115
129
  bytes32 condition,
@@ -153,6 +167,8 @@ interface INoxCompute {
153
167
  Div,
154
168
  SafeAdd,
155
169
  SafeSub,
170
+ SafeMul,
171
+ SafeDiv,
156
172
  Select,
157
173
  Eq,
158
174
  Ne,
@@ -341,7 +357,37 @@ interface INoxCompute {
341
357
  bytes32 rightHandOperand
342
358
  ) external returns (bytes32 success, bytes32 result);
343
359
 
344
- // TODO add safeMul and safeDiv
360
+ /**
361
+ * @notice Performs a multiplication between two encrypted values with overflow check.
362
+ * If the operation succeeds, the value of the success handle will be an encrypted
363
+ * `true` and the result handle's value will be the encrypted product.
364
+ * If the operation fails (e.g., due to overflow), the success handle will contain
365
+ * an encrypted `false` and the result handle will contain an encrypted `0`.
366
+ * @param leftHandOperand Left-hand side operand handle
367
+ * @param rightHandOperand Right-hand side operand handle
368
+ * @return success Whether the operation was successful
369
+ * @return result Result handle
370
+ */
371
+ function safeMul(
372
+ bytes32 leftHandOperand,
373
+ bytes32 rightHandOperand
374
+ ) external returns (bytes32 success, bytes32 result);
375
+
376
+ /**
377
+ * @notice Performs a division between two encrypted values with division-by-zero check.
378
+ * If the operation succeeds, the value of the success handle will be an encrypted
379
+ * `true` and the result handle's value will be the encrypted quotient.
380
+ * If the operation fails (e.g., due to division by zero), the success handle will contain
381
+ * an encrypted `false` and the result handle will contain an encrypted `0`.
382
+ * @param numerator Value to be divided
383
+ * @param denominator Value to divide by
384
+ * @return success Whether the operation was successful
385
+ * @return result Result handle
386
+ */
387
+ function safeDiv(
388
+ bytes32 numerator,
389
+ bytes32 denominator
390
+ ) external returns (bytes32 success, bytes32 result);
345
391
 
346
392
  /**
347
393
  * @notice Selects between two encrypted values based on a condition
@@ -21,7 +21,7 @@ library Nox {
21
21
  * Supports Arbitrum Mainnet (42161), Arbitrum Sepolia (421614), and local dev chains (31337),
22
22
  * including local forks of each network.
23
23
  */
24
- function noxComputeContract() public view returns (address) {
24
+ function noxComputeContract() internal view returns (address) {
25
25
  // Arbitrum mainnet or its fork
26
26
  if (block.chainid == 42161) {
27
27
  // TODO: Update after mainnet deployment.
@@ -33,12 +33,12 @@ library Nox {
33
33
  }
34
34
  // Local development chain
35
35
  if (block.chainid == 31337) {
36
- return 0x188D560Fd7F60f50e4c32a4484B1D0DC486714b3;
36
+ return 0x9cF45FFE48126380cFCC40215a1d6D7fffbffb05;
37
37
  }
38
38
  revert("Nox: Unsupported chain");
39
39
  }
40
40
 
41
- function _noxComputeContract() internal view returns (INoxCompute) {
41
+ function _noxComputeContract() private view returns (INoxCompute) {
42
42
  return INoxCompute(noxComputeContract());
43
43
  }
44
44
 
@@ -119,19 +119,6 @@ library Nox {
119
119
  );
120
120
  }
121
121
 
122
- /**
123
- * @dev Convert a plaintext address to an encrypted address.
124
- */
125
- function toEaddress(address value) internal returns (eaddress) {
126
- return
127
- eaddress.wrap(
128
- _noxComputeContract().plaintextToEncrypted(
129
- bytes32(uint256(uint160(value))),
130
- TEEType.Address
131
- )
132
- );
133
- }
134
-
135
122
  /**
136
123
  * @dev Convert a plaintext value to an encrypted euint16 integer.
137
124
  */
@@ -337,7 +324,45 @@ library Nox {
337
324
  return (ebool.wrap(success), eint256.wrap(result));
338
325
  }
339
326
 
340
- // TODO add safeMul and safeDiv.
327
+ function safeMul(euint16 a, euint16 b) internal returns (ebool, euint16) {
328
+ (bytes32 success, bytes32 result) = _safeMul(euint16.unwrap(a), euint16.unwrap(b));
329
+ return (ebool.wrap(success), euint16.wrap(result));
330
+ }
331
+
332
+ function safeMul(euint256 a, euint256 b) internal returns (ebool, euint256) {
333
+ (bytes32 success, bytes32 result) = _safeMul(euint256.unwrap(a), euint256.unwrap(b));
334
+ return (ebool.wrap(success), euint256.wrap(result));
335
+ }
336
+
337
+ function safeMul(eint16 a, eint16 b) internal returns (ebool, eint16) {
338
+ (bytes32 success, bytes32 result) = _safeMul(eint16.unwrap(a), eint16.unwrap(b));
339
+ return (ebool.wrap(success), eint16.wrap(result));
340
+ }
341
+
342
+ function safeMul(eint256 a, eint256 b) internal returns (ebool, eint256) {
343
+ (bytes32 success, bytes32 result) = _safeMul(eint256.unwrap(a), eint256.unwrap(b));
344
+ return (ebool.wrap(success), eint256.wrap(result));
345
+ }
346
+
347
+ function safeDiv(euint16 a, euint16 b) internal returns (ebool, euint16) {
348
+ (bytes32 success, bytes32 result) = _safeDiv(euint16.unwrap(a), euint16.unwrap(b));
349
+ return (ebool.wrap(success), euint16.wrap(result));
350
+ }
351
+
352
+ function safeDiv(euint256 a, euint256 b) internal returns (ebool, euint256) {
353
+ (bytes32 success, bytes32 result) = _safeDiv(euint256.unwrap(a), euint256.unwrap(b));
354
+ return (ebool.wrap(success), euint256.wrap(result));
355
+ }
356
+
357
+ function safeDiv(eint16 a, eint16 b) internal returns (ebool, eint16) {
358
+ (bytes32 success, bytes32 result) = _safeDiv(eint16.unwrap(a), eint16.unwrap(b));
359
+ return (ebool.wrap(success), eint16.wrap(result));
360
+ }
361
+
362
+ function safeDiv(eint256 a, eint256 b) internal returns (ebool, eint256) {
363
+ (bytes32 success, bytes32 result) = _safeDiv(eint256.unwrap(a), eint256.unwrap(b));
364
+ return (ebool.wrap(success), eint256.wrap(result));
365
+ }
341
366
 
342
367
  function select(ebool condition, euint16 ifTrue, euint16 ifFalse) internal returns (euint16) {
343
368
  return
@@ -913,6 +938,18 @@ library Nox {
913
938
  return _noxComputeContract().safeSub(a, b);
914
939
  }
915
940
 
941
+ function _safeMul(bytes32 a, bytes32 b) private returns (bytes32, bytes32) {
942
+ _assertInitialized(a);
943
+ _assertInitialized(b);
944
+ return _noxComputeContract().safeMul(a, b);
945
+ }
946
+
947
+ function _safeDiv(bytes32 a, bytes32 b) private returns (bytes32, bytes32) {
948
+ _assertInitialized(a);
949
+ _assertInitialized(b);
950
+ return _noxComputeContract().safeDiv(a, b);
951
+ }
952
+
916
953
  function _select(bytes32 condition, bytes32 ifTrue, bytes32 ifFalse) private returns (bytes32) {
917
954
  _assertInitialized(condition);
918
955
  _assertInitialized(ifTrue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iexec-nox/nox-protocol-contracts",
3
- "version": "0.1.0-beta.5",
3
+ "version": "0.1.0-beta.6",
4
4
  "description": "Nox protocol smart contracts",
5
5
  "keywords": [
6
6
  "Nox",
@@ -40,17 +40,17 @@
40
40
  "encrypted-types": "^0.0.4"
41
41
  },
42
42
  "devDependencies": {
43
- "@nomicfoundation/hardhat-ignition": "^3.0.6",
44
- "@nomicfoundation/hardhat-toolbox-viem": "^5.0.1",
45
- "@types/node": "^22.8.5",
43
+ "@nomicfoundation/hardhat-ignition": "^3.0.8",
44
+ "@nomicfoundation/hardhat-toolbox-viem": "^5.0.2",
45
+ "@types/node": "^22.19.13",
46
46
  "forge-std": "github:foundry-rs/forge-std#v1.9.4",
47
47
  "hardhat": "^3.1.10",
48
48
  "husky": "^9.1.7",
49
- "lint-staged": "^16.2.7",
50
- "prettier": "^3.7.4",
49
+ "lint-staged": "^16.3.1",
50
+ "prettier": "^3.8.1",
51
51
  "prettier-plugin-solidity": "^2.2.1",
52
- "typescript": "~5.8.0",
53
- "viem": "^2.30.0"
52
+ "typescript": "^5.9.3",
53
+ "viem": "^2.46.3"
54
54
  },
55
55
  "homepage": "https://github.com/iExec-Nox/nox-protocol-contracts#readme",
56
56
  "repository": {