@iexec-nox/nox-protocol-contracts 0.1.0-beta.9 → 0.2.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 +102 -37
- package/contracts/sdk/Nox.sol +6 -106
- package/contracts/shared/HandleUtils.sol +35 -0
- package/contracts/shared/TypeUtils.sol +17 -32
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -1,63 +1,100 @@
|
|
|
1
|
-
# Nox
|
|
1
|
+
# Nox · nox-protocol-contracts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](./LICENSE)
|
|
4
|
+
[](https://docs.iex.ec)
|
|
5
|
+
[](https://discord.com/invite/5TewNUnJHN)
|
|
6
|
+
[](https://github.com/iExec-Nox/nox-protocol-contracts/releases)
|
|
7
|
+
[](https://www.npmjs.com/package/@iexec-nox/nox-protocol-contracts)
|
|
8
|
+
[](https://codecov.io/gh/iExec-Nox/nox-protocol-contracts)
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
> Solidity contracts for the Nox protocol: manage encrypted handles, validate proofs, and trigger confidential computations.
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
- `Nox` SDK library: convenience wrapper for app contracts that call `NoxCompute`.
|
|
12
|
+
## Table of Contents
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
- [Nox · nox-protocol-contracts](#nox--nox-protocol-contracts)
|
|
15
|
+
- [Table of Contents](#table-of-contents)
|
|
16
|
+
- [Overview](#overview)
|
|
17
|
+
- [Prerequisites](#prerequisites)
|
|
18
|
+
- [Getting Started](#getting-started)
|
|
19
|
+
- [Environment Variables](#environment-variables)
|
|
20
|
+
- [Testing](#testing)
|
|
21
|
+
- [Deployment](#deployment)
|
|
22
|
+
- [Verification](#verification)
|
|
23
|
+
- [Configuration notes](#configuration-notes)
|
|
24
|
+
- [Related Repositories](#related-repositories)
|
|
25
|
+
- [Contributing](#contributing)
|
|
26
|
+
- [Code style](#code-style)
|
|
27
|
+
- [License](#license)
|
|
11
28
|
|
|
12
|
-
|
|
13
|
-
- `pnpm` (see `packageManager` in `package.json`)
|
|
29
|
+
## Overview
|
|
14
30
|
|
|
15
|
-
|
|
31
|
+
**nox-protocol-contracts** is the Solidity layer of the Nox protocol. It provides:
|
|
32
|
+
|
|
33
|
+
- **NoxCompute**: the main UUPS-upgradeable contract that manages the Access Control List (ACL) for encrypted handles, validates handle proofs issued by a trusted gateway, facilitates plaintext-to-encrypted conversions, and triggers off-chain TEE computations through event emissions.
|
|
34
|
+
- **INoxCompute**: the public interface consumed by application contracts and off-chain services.
|
|
35
|
+
- **Nox SDK library** (`contracts/sdk/Nox.sol`): a convenience wrapper that resolves the NoxCompute proxy address per chain and exposes typed helper functions for application contracts.
|
|
36
|
+
|
|
37
|
+
## Prerequisites
|
|
38
|
+
|
|
39
|
+
- Node.js >= 24 (see `.nvmrc`)
|
|
40
|
+
- pnpm >= 10 (see `packageManager` in `package.json`)
|
|
41
|
+
- Hardhat >= 3
|
|
42
|
+
|
|
43
|
+
## Getting Started
|
|
16
44
|
|
|
17
45
|
```bash
|
|
46
|
+
git clone https://github.com/iExec-Nox/nox-protocol-contracts.git
|
|
47
|
+
cd nox-protocol-contracts
|
|
48
|
+
|
|
49
|
+
# Use the correct Node version
|
|
18
50
|
nvm install && nvm use
|
|
19
|
-
pnpm install
|
|
20
|
-
```
|
|
21
51
|
|
|
22
|
-
|
|
52
|
+
# Install dependencies
|
|
53
|
+
pnpm install
|
|
23
54
|
|
|
24
|
-
|
|
55
|
+
# Build contracts
|
|
25
56
|
pnpm run build
|
|
26
57
|
```
|
|
27
58
|
|
|
28
|
-
##
|
|
59
|
+
## Environment Variables
|
|
29
60
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
61
|
+
| Variable | Description | Required | Default |
|
|
62
|
+
| ------------------- | ---------------------------------------------- | ----------------- | ------- |
|
|
63
|
+
| `RPC_URL` | JSON-RPC endpoint for the target network | For remote deploy | - |
|
|
64
|
+
| `PRIVATE_KEY` | Deployer private key | For remote deploy | - |
|
|
65
|
+
| `ETHERSCAN_API_KEY` | API key for contract verification on Etherscan | For verification | - |
|
|
33
66
|
|
|
34
|
-
##
|
|
67
|
+
## Testing
|
|
35
68
|
|
|
36
69
|
```bash
|
|
37
|
-
|
|
38
|
-
|
|
70
|
+
# Run all tests (unit + integration)
|
|
71
|
+
pnpm run test
|
|
39
72
|
|
|
40
|
-
|
|
73
|
+
# Run tests with gas stats
|
|
74
|
+
pnpm run test:gas
|
|
41
75
|
|
|
42
|
-
|
|
43
|
-
pnpm run
|
|
44
|
-
pnpm run format:check
|
|
76
|
+
# Run coverage
|
|
77
|
+
pnpm run coverage
|
|
45
78
|
```
|
|
46
79
|
|
|
47
80
|
## Deployment
|
|
48
81
|
|
|
49
|
-
The default network is a local EDR simulation. For external networks,
|
|
50
|
-
|
|
51
|
-
- `RPC_URL`
|
|
52
|
-
- `PRIVATE_KEY`
|
|
82
|
+
The default network is a local EDR simulation. For external networks, set `RPC_URL` and `PRIVATE_KEY`:
|
|
53
83
|
|
|
54
84
|
```bash
|
|
85
|
+
# Local deploy
|
|
55
86
|
pnpm run deploy
|
|
87
|
+
|
|
88
|
+
# Production deploy (optimizer + viaIR)
|
|
89
|
+
pnpm run deploy:production
|
|
90
|
+
|
|
91
|
+
# Upgrade an existing proxy
|
|
92
|
+
pnpm run upgrade
|
|
56
93
|
```
|
|
57
94
|
|
|
58
|
-
##
|
|
95
|
+
## Verification
|
|
59
96
|
|
|
60
|
-
Verify deployed contracts on Etherscan. Requires `ETHERSCAN_API_KEY
|
|
97
|
+
Verify deployed contracts on Etherscan. Requires `ETHERSCAN_API_KEY`:
|
|
61
98
|
|
|
62
99
|
```bash
|
|
63
100
|
pnpm run verify arbitrumSepolia --network arbitrumSepolia
|
|
@@ -65,18 +102,46 @@ pnpm run verify arbitrumSepolia --network arbitrumSepolia
|
|
|
65
102
|
|
|
66
103
|
## Configuration notes
|
|
67
104
|
|
|
68
|
-
-
|
|
69
|
-
- Default owner addresses and KMS public keys per network are also defined in [config/config.ts](config/config.ts).
|
|
70
|
-
- The SDK constants in [contracts/sdk/Nox.sol](contracts/sdk/Nox.sol) must match the deployed proxy addresses.
|
|
105
|
+
- CREATE2 salt is defined in [`config/config.ts`](config/config.ts).
|
|
106
|
+
- Default owner addresses and KMS public keys per network are also defined in [`config/config.ts`](config/config.ts).
|
|
107
|
+
- The SDK constants in [`contracts/sdk/Nox.sol`](contracts/sdk/Nox.sol) must match the deployed proxy addresses.
|
|
108
|
+
- OpenZeppelin manifest files in `.openzeppelin/` track proxy deployments.
|
|
109
|
+
|
|
110
|
+
## Related Repositories
|
|
111
|
+
|
|
112
|
+
| Repository | Description |
|
|
113
|
+
| ------------------------------------------------------------------------------- | --------------------------------------------------- |
|
|
114
|
+
| [nox-handle-sdk](https://github.com/iExec-Nox/nox-handle-sdk) | TypeScript SDK for handle encryption/decryption |
|
|
115
|
+
| [nox-offchain-deployment](https://github.com/iExec-Nox/nox-offchain-deployment) | Off-chain services (gateway, KMS, runner, ingestor) |
|
|
116
|
+
|
|
117
|
+
## Contributing
|
|
118
|
+
|
|
119
|
+
Contributions are welcome. Please open an issue first to discuss your proposed changes.
|
|
120
|
+
|
|
121
|
+
1. Fork the repository
|
|
122
|
+
2. Create your feature branch (`git checkout -b feature/my-feature`)
|
|
123
|
+
3. Commit your changes
|
|
124
|
+
4. Push to the branch (`git push origin feature/my-feature`)
|
|
125
|
+
5. Open a Pull Request
|
|
126
|
+
|
|
127
|
+
### Code style
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Format all files
|
|
131
|
+
pnpm run format
|
|
132
|
+
|
|
133
|
+
# Check formatting
|
|
134
|
+
pnpm run format:check
|
|
135
|
+
```
|
|
71
136
|
|
|
72
137
|
## License
|
|
73
138
|
|
|
74
|
-
The Nox Protocol source code is released under the Business Source License 1.1 (BUSL-1.1).
|
|
139
|
+
The Nox Protocol source code is released under the [Business Source License 1.1 (BUSL-1.1)](./LICENSE).
|
|
75
140
|
|
|
76
141
|
The license will automatically convert to the MIT License under the conditions described in the LICENSE file.
|
|
77
142
|
|
|
78
|
-
The full text of the MIT License is provided in the LICENSE-MIT file.
|
|
143
|
+
The full text of the MIT License is provided in the [LICENSE-MIT](./LICENSE-MIT) file.
|
|
79
144
|
|
|
80
|
-
|
|
145
|
+
Some files are dual-licensed under MIT:
|
|
81
146
|
|
|
82
|
-
- All files in `contracts/interfaces/`, `contracts/shared/`, `contracts/sdk/` may also be licensed under
|
|
147
|
+
- All files in `contracts/interfaces/`, `contracts/shared/`, `contracts/sdk/` may also be licensed under MIT (as indicated in their SPDX headers).
|
package/contracts/sdk/Nox.sol
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.27;
|
|
3
3
|
|
|
4
|
+
import {HandleUtils} from "../shared/HandleUtils.sol";
|
|
4
5
|
import {TEEType, TypeUtils} from "../shared/TypeUtils.sol";
|
|
5
6
|
import {INoxCompute} from "../interfaces/INoxCompute.sol";
|
|
6
7
|
import "encrypted-types/EncryptedTypes.sol";
|
|
@@ -33,7 +34,7 @@ library Nox {
|
|
|
33
34
|
}
|
|
34
35
|
// Local development chain
|
|
35
36
|
if (block.chainid == 31337) {
|
|
36
|
-
return
|
|
37
|
+
return 0x44C00793aD4975617b3B5Fc27D4FB78E772c8236;
|
|
37
38
|
}
|
|
38
39
|
revert("Nox: Unsupported chain");
|
|
39
40
|
}
|
|
@@ -47,7 +48,7 @@ library Nox {
|
|
|
47
48
|
* Public handles are already accessible by everyone and don't need ACL.
|
|
48
49
|
*/
|
|
49
50
|
function _allowIfNotPublic(bytes32 handle, address account) private {
|
|
50
|
-
if (!
|
|
51
|
+
if (!HandleUtils.isPublicHandle(handle)) {
|
|
51
52
|
_noxComputeContract().allow(handle, account);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -57,7 +58,7 @@ library Nox {
|
|
|
57
58
|
* Public handles are already accessible by everyone and don't need ACL.
|
|
58
59
|
*/
|
|
59
60
|
function _allowTransientIfNotPublic(bytes32 handle, address account) private {
|
|
60
|
-
if (!
|
|
61
|
+
if (!HandleUtils.isPublicHandle(handle)) {
|
|
61
62
|
_noxComputeContract().allowTransient(handle, account);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
@@ -67,7 +68,7 @@ library Nox {
|
|
|
67
68
|
* Public handles are already accessible by everyone and don't need ACL.
|
|
68
69
|
*/
|
|
69
70
|
function _disallowTransientIfNotPublic(bytes32 handle, address account) private {
|
|
70
|
-
if (!
|
|
71
|
+
if (!HandleUtils.isPublicHandle(handle)) {
|
|
71
72
|
_noxComputeContract().disallowTransient(handle, account);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -84,16 +85,6 @@ library Nox {
|
|
|
84
85
|
return ebool.unwrap(handle) != 0;
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
/**
|
|
88
|
-
* @dev Checks if an encrypted address handle is initialized.
|
|
89
|
-
* This is a basic check and does not guarantee that the handle
|
|
90
|
-
* is valid or recognized by the ACL.
|
|
91
|
-
* @param handle encrypted address handle
|
|
92
|
-
*/
|
|
93
|
-
function isInitialized(eaddress handle) internal pure returns (bool) {
|
|
94
|
-
return eaddress.unwrap(handle) != 0;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
88
|
/**
|
|
98
89
|
* @dev Checks if an encrypted uint16 handle is initialized.
|
|
99
90
|
* This is a basic check and does not guarantee that the handle
|
|
@@ -203,15 +194,6 @@ library Nox {
|
|
|
203
194
|
return ebool.wrap(handle);
|
|
204
195
|
}
|
|
205
196
|
|
|
206
|
-
function fromExternal(
|
|
207
|
-
externalEaddress externalHandle,
|
|
208
|
-
bytes calldata handleProof
|
|
209
|
-
) internal returns (eaddress) {
|
|
210
|
-
bytes32 handle = externalEaddress.unwrap(externalHandle);
|
|
211
|
-
_noxComputeContract().validateInputProof(handle, msg.sender, handleProof, TEEType.Address);
|
|
212
|
-
return eaddress.wrap(handle);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
197
|
function fromExternal(
|
|
216
198
|
externalEuint16 externalHandle,
|
|
217
199
|
bytes calldata handleProof
|
|
@@ -901,14 +883,6 @@ library Nox {
|
|
|
901
883
|
_allowIfNotPublic(ebool.unwrap(value), account);
|
|
902
884
|
}
|
|
903
885
|
|
|
904
|
-
/**
|
|
905
|
-
* @dev Allows the use of value for the address account.
|
|
906
|
-
* Silently skips public handles (they are already accessible by everyone).
|
|
907
|
-
*/
|
|
908
|
-
function allow(eaddress value, address account) internal {
|
|
909
|
-
_allowIfNotPublic(eaddress.unwrap(value), account);
|
|
910
|
-
}
|
|
911
|
-
|
|
912
886
|
/**
|
|
913
887
|
* @dev Allows the use of value for the address account.
|
|
914
888
|
* Silently skips public handles (they are already accessible by everyone).
|
|
@@ -949,14 +923,6 @@ library Nox {
|
|
|
949
923
|
_allowIfNotPublic(ebool.unwrap(value), address(this));
|
|
950
924
|
}
|
|
951
925
|
|
|
952
|
-
/**
|
|
953
|
-
* @dev Allows the use of value for this address (address(this)).
|
|
954
|
-
* Silently skips public handles (they are already accessible by everyone).
|
|
955
|
-
*/
|
|
956
|
-
function allowThis(eaddress value) internal {
|
|
957
|
-
_allowIfNotPublic(eaddress.unwrap(value), address(this));
|
|
958
|
-
}
|
|
959
|
-
|
|
960
926
|
/**
|
|
961
927
|
* @dev Allows the use of value for this address (address(this)).
|
|
962
928
|
* Silently skips public handles (they are already accessible by everyone).
|
|
@@ -997,14 +963,6 @@ library Nox {
|
|
|
997
963
|
_allowTransientIfNotPublic(ebool.unwrap(value), account);
|
|
998
964
|
}
|
|
999
965
|
|
|
1000
|
-
/**
|
|
1001
|
-
* @dev Allows the use of value by address account for this transaction.
|
|
1002
|
-
* Silently skips public handles (they are already accessible by everyone).
|
|
1003
|
-
*/
|
|
1004
|
-
function allowTransient(eaddress value, address account) internal {
|
|
1005
|
-
_allowTransientIfNotPublic(eaddress.unwrap(value), account);
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
966
|
/**
|
|
1009
967
|
* @dev Allows the use of value by address account for this transaction.
|
|
1010
968
|
* Silently skips public handles (they are already accessible by everyone).
|
|
@@ -1045,14 +1003,6 @@ library Nox {
|
|
|
1045
1003
|
_disallowTransientIfNotPublic(ebool.unwrap(value), account);
|
|
1046
1004
|
}
|
|
1047
1005
|
|
|
1048
|
-
/**
|
|
1049
|
-
* @dev Revokes transient access to value for address account within the current transaction.
|
|
1050
|
-
* Silently skips public handles (they are already accessible by everyone).
|
|
1051
|
-
*/
|
|
1052
|
-
function disallowTransient(eaddress value, address account) internal {
|
|
1053
|
-
_disallowTransientIfNotPublic(eaddress.unwrap(value), account);
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
1006
|
/**
|
|
1057
1007
|
* @dev Revokes transient access to value for address account within the current transaction.
|
|
1058
1008
|
* Silently skips public handles (they are already accessible by everyone).
|
|
@@ -1092,13 +1042,6 @@ library Nox {
|
|
|
1092
1042
|
return _noxComputeContract().isAllowed(ebool.unwrap(handle), account);
|
|
1093
1043
|
}
|
|
1094
1044
|
|
|
1095
|
-
/**
|
|
1096
|
-
* @dev Checks if the handle is allowed for the account.
|
|
1097
|
-
*/
|
|
1098
|
-
function isAllowed(eaddress handle, address account) internal view returns (bool) {
|
|
1099
|
-
return _noxComputeContract().isAllowed(eaddress.unwrap(handle), account);
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
1045
|
/**
|
|
1103
1046
|
* @dev Checks if the handle is allowed for the account.
|
|
1104
1047
|
*/
|
|
@@ -1136,13 +1079,6 @@ library Nox {
|
|
|
1136
1079
|
_noxComputeContract().addViewer(ebool.unwrap(value), viewer);
|
|
1137
1080
|
}
|
|
1138
1081
|
|
|
1139
|
-
/**
|
|
1140
|
-
* @dev Adds a viewer for an eaddress handle.
|
|
1141
|
-
*/
|
|
1142
|
-
function addViewer(eaddress value, address viewer) internal {
|
|
1143
|
-
_noxComputeContract().addViewer(eaddress.unwrap(value), viewer);
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
1082
|
/**
|
|
1147
1083
|
* @dev Adds a viewer for an euint16 handle.
|
|
1148
1084
|
*/
|
|
@@ -1178,13 +1114,6 @@ library Nox {
|
|
|
1178
1114
|
return _noxComputeContract().isViewer(ebool.unwrap(handle), viewer);
|
|
1179
1115
|
}
|
|
1180
1116
|
|
|
1181
|
-
/**
|
|
1182
|
-
* @dev Checks if the viewer can view the handle.
|
|
1183
|
-
*/
|
|
1184
|
-
function isViewer(eaddress handle, address viewer) internal view returns (bool) {
|
|
1185
|
-
return _noxComputeContract().isViewer(eaddress.unwrap(handle), viewer);
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
1117
|
/**
|
|
1189
1118
|
* @dev Checks if the viewer can view the handle.
|
|
1190
1119
|
*/
|
|
@@ -1222,13 +1151,6 @@ library Nox {
|
|
|
1222
1151
|
_noxComputeContract().allowPublicDecryption(ebool.unwrap(value));
|
|
1223
1152
|
}
|
|
1224
1153
|
|
|
1225
|
-
/**
|
|
1226
|
-
* @dev Marks an eaddress handle as publicly decryptable.
|
|
1227
|
-
*/
|
|
1228
|
-
function allowPublicDecryption(eaddress value) internal {
|
|
1229
|
-
_noxComputeContract().allowPublicDecryption(eaddress.unwrap(value));
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
1154
|
/**
|
|
1233
1155
|
* @dev Marks an euint16 handle as publicly decryptable.
|
|
1234
1156
|
*/
|
|
@@ -1264,13 +1186,6 @@ library Nox {
|
|
|
1264
1186
|
return _noxComputeContract().isPubliclyDecryptable(ebool.unwrap(handle));
|
|
1265
1187
|
}
|
|
1266
1188
|
|
|
1267
|
-
/**
|
|
1268
|
-
* @dev Checks if the handle is publicly decryptable.
|
|
1269
|
-
*/
|
|
1270
|
-
function isPubliclyDecryptable(eaddress handle) internal view returns (bool) {
|
|
1271
|
-
return _noxComputeContract().isPubliclyDecryptable(eaddress.unwrap(handle));
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
1189
|
/**
|
|
1275
1190
|
* @dev Checks if the handle is publicly decryptable.
|
|
1276
1191
|
*/
|
|
@@ -1317,21 +1232,6 @@ library Nox {
|
|
|
1317
1232
|
return result[0] != 0x00;
|
|
1318
1233
|
}
|
|
1319
1234
|
|
|
1320
|
-
/**
|
|
1321
|
-
* @dev Verifies a decryption proof and returns the decrypted address value.
|
|
1322
|
-
*/
|
|
1323
|
-
function publicDecrypt(
|
|
1324
|
-
eaddress handle,
|
|
1325
|
-
bytes calldata decryptionProof
|
|
1326
|
-
) internal view returns (address plaintextValue) {
|
|
1327
|
-
bytes memory result = _noxComputeContract().validateDecryptionProof(
|
|
1328
|
-
eaddress.unwrap(handle),
|
|
1329
|
-
decryptionProof
|
|
1330
|
-
);
|
|
1331
|
-
require(result.length == 20, MalformedDecryptedData(result));
|
|
1332
|
-
return address(bytes20(result));
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
1235
|
/**
|
|
1336
1236
|
* @dev Verifies a decryption proof and returns the decrypted uint16 value.
|
|
1337
1237
|
*/
|
|
@@ -1402,6 +1302,6 @@ library Nox {
|
|
|
1402
1302
|
bytes32 handle,
|
|
1403
1303
|
TEEType teeType
|
|
1404
1304
|
) private view returns (bytes32) {
|
|
1405
|
-
return handle == bytes32(0) ?
|
|
1305
|
+
return handle == bytes32(0) ? HandleUtils.zeroHandle(teeType) : handle;
|
|
1406
1306
|
}
|
|
1407
1307
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.27;
|
|
3
|
+
|
|
4
|
+
import {TEEType} from "./TypeUtils.sol";
|
|
5
|
+
|
|
6
|
+
library HandleUtils {
|
|
7
|
+
/// @dev Bit 0 of the attrs byte. When set, the handle is guaranteed unique on-chain.
|
|
8
|
+
bytes1 internal constant ATTR_IS_UNIQUE_HANDLE = 0x01;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @notice Checks if a handle is a public handle (isUniqueHandle bit == 0).
|
|
12
|
+
* A public handle wraps a plaintext value known on-chain, has no ACL,
|
|
13
|
+
* and is accessible by everyone.
|
|
14
|
+
* @param handle The handle to check
|
|
15
|
+
* @return True if the handle is a public handle
|
|
16
|
+
*/
|
|
17
|
+
function isPublicHandle(bytes32 handle) internal pure returns (bool) {
|
|
18
|
+
return (handle[6] & ATTR_IS_UNIQUE_HANDLE) == 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @notice Returns the zero handle for the given TEE type on the current chain.
|
|
23
|
+
* The zero handle represents the default zero value for a given type and is a public handle.
|
|
24
|
+
* It follows the standard handle format but with a zeroed pre-handle:
|
|
25
|
+
* [0]=version(0x00) [1-4]=chainId [5]=teeType [6]=attrs(0x00) [7-31]=0x00..00
|
|
26
|
+
* @param teeType The TEE type to encode
|
|
27
|
+
* @return The typed null handle
|
|
28
|
+
*/
|
|
29
|
+
function zeroHandle(TEEType teeType) internal view returns (bytes32) {
|
|
30
|
+
return
|
|
31
|
+
// [0]=version is implicitly 0x00
|
|
32
|
+
(bytes32(bytes4(uint32(block.chainid))) >> (1 * 8)) |
|
|
33
|
+
(bytes32(bytes1(uint8(teeType))) >> (5 * 8));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -116,8 +116,18 @@ error NonArithmeticType();
|
|
|
116
116
|
error UnsupportedArithmeticType();
|
|
117
117
|
|
|
118
118
|
library TypeUtils {
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Returns the list of all currently supported TEE types.
|
|
121
|
+
* @dev Update this list when new types are supported.
|
|
122
|
+
*/
|
|
123
|
+
function allCurrentlySupportedTypes() internal pure returns (TEEType[] memory types) {
|
|
124
|
+
types = new TEEType[](5);
|
|
125
|
+
types[0] = TEEType.Bool;
|
|
126
|
+
types[1] = TEEType.Uint16;
|
|
127
|
+
types[2] = TEEType.Uint256;
|
|
128
|
+
types[3] = TEEType.Int16;
|
|
129
|
+
types[4] = TEEType.Int256;
|
|
130
|
+
}
|
|
121
131
|
|
|
122
132
|
/**
|
|
123
133
|
* @notice Extracts the TEE type from a handle.
|
|
@@ -129,17 +139,6 @@ library TypeUtils {
|
|
|
129
139
|
return TEEType(uint8(handle[5]));
|
|
130
140
|
}
|
|
131
141
|
|
|
132
|
-
/**
|
|
133
|
-
* @notice Checks if a handle is a public handle (isUniqueHandle bit == 0).
|
|
134
|
-
* A public handle wraps a plaintext value known on-chain, has no ACL,
|
|
135
|
-
* and is accessible by everyone.
|
|
136
|
-
* @param handle The handle to check
|
|
137
|
-
* @return True if the handle is a public handle
|
|
138
|
-
*/
|
|
139
|
-
function isPublicHandle(bytes32 handle) internal pure returns (bool) {
|
|
140
|
-
return (handle[6] & ATTR_IS_UNIQUE_HANDLE) == 0;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
142
|
/**
|
|
144
143
|
* @notice Validates that a TEE type is supported for arithmetic operations.
|
|
145
144
|
* Only the following arithmetic types are supported:
|
|
@@ -154,25 +153,11 @@ library TypeUtils {
|
|
|
154
153
|
function validateArithmeticType(TEEType teeType) internal pure {
|
|
155
154
|
uint8 t = uint8(teeType);
|
|
156
155
|
require(t >= uint8(TEEType.Uint8) && t <= uint8(TEEType.Int256), NonArithmeticType());
|
|
157
|
-
bool supportedType =
|
|
158
|
-
teeType == TEEType.
|
|
159
|
-
|
|
160
|
-
|
|
156
|
+
bool supportedType =
|
|
157
|
+
teeType == TEEType.Uint16 ||
|
|
158
|
+
teeType == TEEType.Uint256 ||
|
|
159
|
+
teeType == TEEType.Int16 ||
|
|
160
|
+
teeType == TEEType.Int256;
|
|
161
161
|
require(supportedType, UnsupportedArithmeticType());
|
|
162
162
|
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* @notice Returns the zero handle for the given TEE type on the current chain.
|
|
166
|
-
* The zero handle represents the default zero value for a given type.
|
|
167
|
-
* It follows the standard handle format but with a zeroed pre-handle:
|
|
168
|
-
* [0]=version(0x00) [1-4]=chainId [5]=teeType [6]=attrs(0x00) [7-31]=0x00..00
|
|
169
|
-
* @param teeType The TEE type to encode
|
|
170
|
-
* @return The typed null handle
|
|
171
|
-
*/
|
|
172
|
-
function zeroHandle(TEEType teeType) internal view returns (bytes32) {
|
|
173
|
-
return
|
|
174
|
-
// [0]=version is implicitly 0x00
|
|
175
|
-
(bytes32(bytes4(uint32(block.chainid))) >> (1 * 8)) |
|
|
176
|
-
(bytes32(bytes1(uint8(teeType))) >> (5 * 8));
|
|
177
|
-
}
|
|
178
163
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iexec-nox/nox-protocol-contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Nox protocol smart contracts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Nox",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"deploy:production": "pnpm hardhat run scripts/deploy.ts --build-profile production",
|
|
27
27
|
"set-gateway": "pnpm hardhat run scripts/set-gateway.ts",
|
|
28
28
|
"set-kms-public-key": "pnpm hardhat run scripts/set-kms-public-key.ts",
|
|
29
|
-
"upgrade": "
|
|
30
|
-
"upgrade:production": "
|
|
29
|
+
"upgrade": "bash scripts/upgrade.sh",
|
|
30
|
+
"upgrade:production": "bash scripts/upgrade.sh --build-profile production",
|
|
31
31
|
"verify": "pnpm hardhat ignition verify",
|
|
32
32
|
"format": "pnpm prettier --write .",
|
|
33
33
|
"format:check": "pnpm prettier --check ."
|
|
@@ -44,19 +44,19 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@nomicfoundation/hardhat-ethers": "^4.0.6",
|
|
47
|
-
"@nomicfoundation/hardhat-ignition": "^3.0
|
|
48
|
-
"@nomicfoundation/hardhat-toolbox-viem": "^5.0.
|
|
47
|
+
"@nomicfoundation/hardhat-ignition": "^3.1.0",
|
|
48
|
+
"@nomicfoundation/hardhat-toolbox-viem": "^5.0.3",
|
|
49
49
|
"@openzeppelin/hardhat-upgrades": "4.0.0-alpha.0",
|
|
50
|
-
"@types/node": "^
|
|
50
|
+
"@types/node": "^25.5.0",
|
|
51
51
|
"ethers": "^6.16.0",
|
|
52
52
|
"forge-std": "github:foundry-rs/forge-std#v1.15.0",
|
|
53
|
-
"hardhat": "^3.
|
|
53
|
+
"hardhat": "^3.2.0",
|
|
54
54
|
"husky": "^9.1.7",
|
|
55
|
-
"lint-staged": "^16.
|
|
55
|
+
"lint-staged": "^16.4.0",
|
|
56
56
|
"prettier": "^3.8.1",
|
|
57
|
-
"prettier-plugin-solidity": "^2.
|
|
58
|
-
"typescript": "^
|
|
59
|
-
"viem": "^2.
|
|
57
|
+
"prettier-plugin-solidity": "^2.3.1",
|
|
58
|
+
"typescript": "^6.0.2",
|
|
59
|
+
"viem": "^2.47.6"
|
|
60
60
|
},
|
|
61
61
|
"homepage": "https://github.com/iExec-Nox/nox-protocol-contracts#readme",
|
|
62
62
|
"repository": {
|