@iexec-nox/nox-protocol-contracts 0.2.2 → 0.2.3

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.
@@ -1,8 +1,8 @@
1
1
  // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.27;
2
+ pragma solidity ^0.8.35;
3
3
 
4
- import {HandleUtils} from "../shared/HandleUtils.sol";
5
- import {TEEType, TypeUtils} from "../shared/TypeUtils.sol";
4
+ import {HandleUtils} from "../utils/HandleUtils.sol";
5
+ import {TEEType, TypeUtils} from "../utils/TypeUtils.sol";
6
6
  import {INoxCompute} from "../interfaces/INoxCompute.sol";
7
7
  import "encrypted-types/EncryptedTypes.sol";
8
8
 
@@ -19,60 +19,27 @@ library Nox {
19
19
 
20
20
  /**
21
21
  * @dev Returns the NoxCompute contract address for the current chain.
22
- * Supports Arbitrum Mainnet (42161), Arbitrum Sepolia (421614), and local dev chains (31337),
23
- * including local forks of each network.
22
+ * Supports:
23
+ * - Hardhat local development chain (31337)
24
+ * - Arbitrum Sepolia (421614)
25
+ * - Ethereum Sepolia (11155111)
24
26
  */
25
27
  function noxComputeContract() internal view returns (address) {
26
- // Arbitrum mainnet or its fork
27
- if (block.chainid == 42161) {
28
- // TODO: Update after mainnet deployment.
29
- return address(0);
28
+ // Hardhat local development chain
29
+ if (block.chainid == 31337) {
30
+ return 0x75C6AF4430cc474b1bb9b8540b7E46D6f8e1C685;
30
31
  }
31
- // Arbitrum Sepolia or its fork
32
+ // Arbitrum Sepolia
32
33
  if (block.chainid == 421614) {
33
34
  return 0xd464B198f06756a1d00be223634b85E0a731c229;
34
35
  }
35
- // Local development chain
36
- if (block.chainid == 31337) {
37
- return 0x44C00793aD4975617b3B5Fc27D4FB78E772c8236;
36
+ // Ethereum Sepolia
37
+ if (block.chainid == 11155111) {
38
+ return 0x24Ef36Ec5b626D7DCD09a98F3083c2758F0F77bF;
38
39
  }
39
40
  revert("Nox: Unsupported chain");
40
41
  }
41
42
 
42
- function _noxComputeContract() private view returns (INoxCompute) {
43
- return INoxCompute(noxComputeContract());
44
- }
45
-
46
- /**
47
- * @dev Calls allow on NoxCompute, silently skipping public handles.
48
- * Public handles are already accessible by everyone and don't need ACL.
49
- */
50
- function _allowIfNotPublic(bytes32 handle, address account) private {
51
- if (!HandleUtils.isPublicHandle(handle)) {
52
- _noxComputeContract().allow(handle, account);
53
- }
54
- }
55
-
56
- /**
57
- * @dev Calls allowTransient on NoxCompute, silently skipping public handles.
58
- * Public handles are already accessible by everyone and don't need ACL.
59
- */
60
- function _allowTransientIfNotPublic(bytes32 handle, address account) private {
61
- if (!HandleUtils.isPublicHandle(handle)) {
62
- _noxComputeContract().allowTransient(handle, account);
63
- }
64
- }
65
-
66
- /**
67
- * @dev Calls disallowTransient on NoxCompute, silently skipping public handles.
68
- * Public handles are already accessible by everyone and don't need ACL.
69
- */
70
- function _disallowTransientIfNotPublic(bytes32 handle, address account) private {
71
- if (!HandleUtils.isPublicHandle(handle)) {
72
- _noxComputeContract().disallowTransient(handle, account);
73
- }
74
- }
75
-
76
43
  // =========== Handle initialization checks ============
77
44
 
78
45
  /**
@@ -1294,6 +1261,10 @@ library Nox {
1294
1261
 
1295
1262
  // ============ Private helpers ============
1296
1263
 
1264
+ function _noxComputeContract() private view returns (INoxCompute) {
1265
+ return INoxCompute(noxComputeContract());
1266
+ }
1267
+
1297
1268
  /**
1298
1269
  * @dev Resolves an undefined (bytes32(0)) handle to the typed zero handle for the given type.
1299
1270
  * If the handle is already non-zero, returns it unchanged.
@@ -1304,4 +1275,34 @@ library Nox {
1304
1275
  ) private view returns (bytes32) {
1305
1276
  return handle == bytes32(0) ? HandleUtils.zeroHandle(teeType) : handle;
1306
1277
  }
1278
+
1279
+ /**
1280
+ * @dev Calls allow on NoxCompute, silently skipping public handles.
1281
+ * Public handles are already accessible by everyone and don't need ACL.
1282
+ */
1283
+ function _allowIfNotPublic(bytes32 handle, address account) private {
1284
+ if (!HandleUtils.isPublicHandle(handle)) {
1285
+ _noxComputeContract().allow(handle, account);
1286
+ }
1287
+ }
1288
+
1289
+ /**
1290
+ * @dev Calls allowTransient on NoxCompute, silently skipping public handles.
1291
+ * Public handles are already accessible by everyone and don't need ACL.
1292
+ */
1293
+ function _allowTransientIfNotPublic(bytes32 handle, address account) private {
1294
+ if (!HandleUtils.isPublicHandle(handle)) {
1295
+ _noxComputeContract().allowTransient(handle, account);
1296
+ }
1297
+ }
1298
+
1299
+ /**
1300
+ * @dev Calls disallowTransient on NoxCompute, silently skipping public handles.
1301
+ * Public handles are already accessible by everyone and don't need ACL.
1302
+ */
1303
+ function _disallowTransientIfNotPublic(bytes32 handle, address account) private {
1304
+ if (!HandleUtils.isPublicHandle(handle)) {
1305
+ _noxComputeContract().disallowTransient(handle, account);
1306
+ }
1307
+ }
1307
1308
  }
@@ -1,16 +1,28 @@
1
1
  // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.27;
2
+ pragma solidity ^0.8.35;
3
3
 
4
4
  import {TEEType} from "./TypeUtils.sol";
5
5
 
6
6
  library HandleUtils {
7
7
  /// @dev Bit 0 of the attrs byte. When set, the handle is guaranteed unique on-chain.
8
+ // TODO rename to IS_UNIQUE_HANDLE_ATTRIBUTE
8
9
  bytes1 internal constant ATTR_IS_UNIQUE_HANDLE = 0x01;
9
10
 
10
11
  /**
11
12
  * @notice Checks if a handle is a public handle (isUniqueHandle bit == 0).
12
13
  * A public handle wraps a plaintext value known on-chain, has no ACL,
13
14
  * and is accessible by everyone.
15
+ *
16
+ * @dev **Security invariant — public handles bypass all ACL checks.**
17
+ * Every access-control gate in the system short-circuits on this predicate:
18
+ * - `_isAllowed` → always returns true for public handles
19
+ * - `_allowTransient` → silently skips (no tstore needed)
20
+ * - `allow`, `addViewer`... → ACL mutations are blocked to prevent confusion
21
+ * - `isViewer` → always returns true for public handles
22
+ * - `isPubliclyDecryptable` → always returns true for public handles
23
+ * This is intentional: public handles contain no secret, their plaintext
24
+ * is deterministically derivable from the handle itself.
25
+ *
14
26
  * @param handle The handle to check
15
27
  * @return True if the handle is a public handle
16
28
  */
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.27;
2
+ pragma solidity ^0.8.35;
3
3
 
4
4
  /**
5
5
  * @notice Enum values MUST NOT be reordered or removed once deployed.
@@ -114,6 +114,7 @@ enum TEEType {
114
114
 
115
115
  error NonArithmeticType();
116
116
  error UnsupportedArithmeticType();
117
+ error IncompatibleTypes();
117
118
 
118
119
  library TypeUtils {
119
120
  /**
@@ -160,4 +161,27 @@ library TypeUtils {
160
161
  teeType == TEEType.Int256;
161
162
  require(supportedType, UnsupportedArithmeticType());
162
163
  }
164
+
165
+ /**
166
+ * Reverts if handle's TEEType doesn't match the expected type.
167
+ */
168
+ function requireType(bytes32 handle, TEEType expected) internal pure {
169
+ require(typeOf(handle) == expected, IncompatibleTypes());
170
+ }
171
+
172
+ /**
173
+ * Validates that first and second have the same supported arithmetic type.
174
+ */
175
+ function validateOperationTypes(bytes32 first, bytes32 second) internal pure {
176
+ validateArithmeticType(typeOf(first));
177
+ requireType(second, typeOf(first));
178
+ }
179
+
180
+ /**
181
+ * Validates that first, second, and third have the same supported arithmetic type.
182
+ */
183
+ function validateOperationTypes(bytes32 first, bytes32 second, bytes32 third) internal pure {
184
+ validateOperationTypes(first, second);
185
+ requireType(third, typeOf(first));
186
+ }
163
187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iexec-nox/nox-protocol-contracts",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Nox protocol smart contracts",
5
5
  "keywords": [
6
6
  "Nox",
@@ -11,11 +11,13 @@
11
11
  "packageManager": "pnpm@10.33.0",
12
12
  "type": "module",
13
13
  "files": [
14
- "/contracts/NoxCompute.sol",
15
- "/contracts/interfaces/",
16
- "/contracts/sdk/",
17
- "/contracts/shared/",
18
- "/ignition/deployments/arbitrumSepolia/artifacts/"
14
+ "/contracts/**/*.sol",
15
+ "/contracts/**/LICENSE",
16
+ "!/contracts/mock/**",
17
+ "/artifacts/contracts/**/*.json",
18
+ "!/artifacts/contracts/mock/**",
19
+ "/LICENSE-MIT",
20
+ "/DISCLAIMER"
19
21
  ],
20
22
  "scripts": {
21
23
  "prepare": "husky",
@@ -32,7 +34,8 @@
32
34
  "upgrade:production": "bash scripts/upgrade.sh --build-profile production",
33
35
  "verify": "pnpm hardhat ignition verify",
34
36
  "format": "pnpm prettier --write .",
35
- "format:check": "pnpm prettier --check ."
37
+ "format:check": "pnpm prettier --check .",
38
+ "update-local-proxy-address": "sh scripts/update-local-proxy-address.sh"
36
39
  },
37
40
  "lint-staged": {
38
41
  "*.{sol,js,ts,json,md,yml,yaml}": [