@iexec-nox/nox-protocol-contracts 0.1.0 → 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/contracts/sdk/Nox.sol +1 -102
- package/contracts/shared/TypeUtils.sol +13 -0
- package/package.json +1 -1
package/contracts/sdk/Nox.sol
CHANGED
|
@@ -34,7 +34,7 @@ library Nox {
|
|
|
34
34
|
}
|
|
35
35
|
// Local development chain
|
|
36
36
|
if (block.chainid == 31337) {
|
|
37
|
-
return
|
|
37
|
+
return 0x44C00793aD4975617b3B5Fc27D4FB78E772c8236;
|
|
38
38
|
}
|
|
39
39
|
revert("Nox: Unsupported chain");
|
|
40
40
|
}
|
|
@@ -85,16 +85,6 @@ library Nox {
|
|
|
85
85
|
return ebool.unwrap(handle) != 0;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
/**
|
|
89
|
-
* @dev Checks if an encrypted address handle is initialized.
|
|
90
|
-
* This is a basic check and does not guarantee that the handle
|
|
91
|
-
* is valid or recognized by the ACL.
|
|
92
|
-
* @param handle encrypted address handle
|
|
93
|
-
*/
|
|
94
|
-
function isInitialized(eaddress handle) internal pure returns (bool) {
|
|
95
|
-
return eaddress.unwrap(handle) != 0;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
88
|
/**
|
|
99
89
|
* @dev Checks if an encrypted uint16 handle is initialized.
|
|
100
90
|
* This is a basic check and does not guarantee that the handle
|
|
@@ -204,15 +194,6 @@ library Nox {
|
|
|
204
194
|
return ebool.wrap(handle);
|
|
205
195
|
}
|
|
206
196
|
|
|
207
|
-
function fromExternal(
|
|
208
|
-
externalEaddress externalHandle,
|
|
209
|
-
bytes calldata handleProof
|
|
210
|
-
) internal returns (eaddress) {
|
|
211
|
-
bytes32 handle = externalEaddress.unwrap(externalHandle);
|
|
212
|
-
_noxComputeContract().validateInputProof(handle, msg.sender, handleProof, TEEType.Address);
|
|
213
|
-
return eaddress.wrap(handle);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
197
|
function fromExternal(
|
|
217
198
|
externalEuint16 externalHandle,
|
|
218
199
|
bytes calldata handleProof
|
|
@@ -902,14 +883,6 @@ library Nox {
|
|
|
902
883
|
_allowIfNotPublic(ebool.unwrap(value), account);
|
|
903
884
|
}
|
|
904
885
|
|
|
905
|
-
/**
|
|
906
|
-
* @dev Allows the use of value for the address account.
|
|
907
|
-
* Silently skips public handles (they are already accessible by everyone).
|
|
908
|
-
*/
|
|
909
|
-
function allow(eaddress value, address account) internal {
|
|
910
|
-
_allowIfNotPublic(eaddress.unwrap(value), account);
|
|
911
|
-
}
|
|
912
|
-
|
|
913
886
|
/**
|
|
914
887
|
* @dev Allows the use of value for the address account.
|
|
915
888
|
* Silently skips public handles (they are already accessible by everyone).
|
|
@@ -950,14 +923,6 @@ library Nox {
|
|
|
950
923
|
_allowIfNotPublic(ebool.unwrap(value), address(this));
|
|
951
924
|
}
|
|
952
925
|
|
|
953
|
-
/**
|
|
954
|
-
* @dev Allows the use of value for this address (address(this)).
|
|
955
|
-
* Silently skips public handles (they are already accessible by everyone).
|
|
956
|
-
*/
|
|
957
|
-
function allowThis(eaddress value) internal {
|
|
958
|
-
_allowIfNotPublic(eaddress.unwrap(value), address(this));
|
|
959
|
-
}
|
|
960
|
-
|
|
961
926
|
/**
|
|
962
927
|
* @dev Allows the use of value for this address (address(this)).
|
|
963
928
|
* Silently skips public handles (they are already accessible by everyone).
|
|
@@ -998,14 +963,6 @@ library Nox {
|
|
|
998
963
|
_allowTransientIfNotPublic(ebool.unwrap(value), account);
|
|
999
964
|
}
|
|
1000
965
|
|
|
1001
|
-
/**
|
|
1002
|
-
* @dev Allows the use of value by address account for this transaction.
|
|
1003
|
-
* Silently skips public handles (they are already accessible by everyone).
|
|
1004
|
-
*/
|
|
1005
|
-
function allowTransient(eaddress value, address account) internal {
|
|
1006
|
-
_allowTransientIfNotPublic(eaddress.unwrap(value), account);
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
966
|
/**
|
|
1010
967
|
* @dev Allows the use of value by address account for this transaction.
|
|
1011
968
|
* Silently skips public handles (they are already accessible by everyone).
|
|
@@ -1046,14 +1003,6 @@ library Nox {
|
|
|
1046
1003
|
_disallowTransientIfNotPublic(ebool.unwrap(value), account);
|
|
1047
1004
|
}
|
|
1048
1005
|
|
|
1049
|
-
/**
|
|
1050
|
-
* @dev Revokes transient access to value for address account within the current transaction.
|
|
1051
|
-
* Silently skips public handles (they are already accessible by everyone).
|
|
1052
|
-
*/
|
|
1053
|
-
function disallowTransient(eaddress value, address account) internal {
|
|
1054
|
-
_disallowTransientIfNotPublic(eaddress.unwrap(value), account);
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
1006
|
/**
|
|
1058
1007
|
* @dev Revokes transient access to value for address account within the current transaction.
|
|
1059
1008
|
* Silently skips public handles (they are already accessible by everyone).
|
|
@@ -1093,13 +1042,6 @@ library Nox {
|
|
|
1093
1042
|
return _noxComputeContract().isAllowed(ebool.unwrap(handle), account);
|
|
1094
1043
|
}
|
|
1095
1044
|
|
|
1096
|
-
/**
|
|
1097
|
-
* @dev Checks if the handle is allowed for the account.
|
|
1098
|
-
*/
|
|
1099
|
-
function isAllowed(eaddress handle, address account) internal view returns (bool) {
|
|
1100
|
-
return _noxComputeContract().isAllowed(eaddress.unwrap(handle), account);
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
1045
|
/**
|
|
1104
1046
|
* @dev Checks if the handle is allowed for the account.
|
|
1105
1047
|
*/
|
|
@@ -1137,13 +1079,6 @@ library Nox {
|
|
|
1137
1079
|
_noxComputeContract().addViewer(ebool.unwrap(value), viewer);
|
|
1138
1080
|
}
|
|
1139
1081
|
|
|
1140
|
-
/**
|
|
1141
|
-
* @dev Adds a viewer for an eaddress handle.
|
|
1142
|
-
*/
|
|
1143
|
-
function addViewer(eaddress value, address viewer) internal {
|
|
1144
|
-
_noxComputeContract().addViewer(eaddress.unwrap(value), viewer);
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
1082
|
/**
|
|
1148
1083
|
* @dev Adds a viewer for an euint16 handle.
|
|
1149
1084
|
*/
|
|
@@ -1179,13 +1114,6 @@ library Nox {
|
|
|
1179
1114
|
return _noxComputeContract().isViewer(ebool.unwrap(handle), viewer);
|
|
1180
1115
|
}
|
|
1181
1116
|
|
|
1182
|
-
/**
|
|
1183
|
-
* @dev Checks if the viewer can view the handle.
|
|
1184
|
-
*/
|
|
1185
|
-
function isViewer(eaddress handle, address viewer) internal view returns (bool) {
|
|
1186
|
-
return _noxComputeContract().isViewer(eaddress.unwrap(handle), viewer);
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
1117
|
/**
|
|
1190
1118
|
* @dev Checks if the viewer can view the handle.
|
|
1191
1119
|
*/
|
|
@@ -1223,13 +1151,6 @@ library Nox {
|
|
|
1223
1151
|
_noxComputeContract().allowPublicDecryption(ebool.unwrap(value));
|
|
1224
1152
|
}
|
|
1225
1153
|
|
|
1226
|
-
/**
|
|
1227
|
-
* @dev Marks an eaddress handle as publicly decryptable.
|
|
1228
|
-
*/
|
|
1229
|
-
function allowPublicDecryption(eaddress value) internal {
|
|
1230
|
-
_noxComputeContract().allowPublicDecryption(eaddress.unwrap(value));
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
1154
|
/**
|
|
1234
1155
|
* @dev Marks an euint16 handle as publicly decryptable.
|
|
1235
1156
|
*/
|
|
@@ -1265,13 +1186,6 @@ library Nox {
|
|
|
1265
1186
|
return _noxComputeContract().isPubliclyDecryptable(ebool.unwrap(handle));
|
|
1266
1187
|
}
|
|
1267
1188
|
|
|
1268
|
-
/**
|
|
1269
|
-
* @dev Checks if the handle is publicly decryptable.
|
|
1270
|
-
*/
|
|
1271
|
-
function isPubliclyDecryptable(eaddress handle) internal view returns (bool) {
|
|
1272
|
-
return _noxComputeContract().isPubliclyDecryptable(eaddress.unwrap(handle));
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
1189
|
/**
|
|
1276
1190
|
* @dev Checks if the handle is publicly decryptable.
|
|
1277
1191
|
*/
|
|
@@ -1318,21 +1232,6 @@ library Nox {
|
|
|
1318
1232
|
return result[0] != 0x00;
|
|
1319
1233
|
}
|
|
1320
1234
|
|
|
1321
|
-
/**
|
|
1322
|
-
* @dev Verifies a decryption proof and returns the decrypted address value.
|
|
1323
|
-
*/
|
|
1324
|
-
function publicDecrypt(
|
|
1325
|
-
eaddress handle,
|
|
1326
|
-
bytes calldata decryptionProof
|
|
1327
|
-
) internal view returns (address plaintextValue) {
|
|
1328
|
-
bytes memory result = _noxComputeContract().validateDecryptionProof(
|
|
1329
|
-
eaddress.unwrap(handle),
|
|
1330
|
-
decryptionProof
|
|
1331
|
-
);
|
|
1332
|
-
require(result.length == 20, MalformedDecryptedData(result));
|
|
1333
|
-
return address(bytes20(result));
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
1235
|
/**
|
|
1337
1236
|
* @dev Verifies a decryption proof and returns the decrypted uint16 value.
|
|
1338
1237
|
*/
|
|
@@ -116,6 +116,19 @@ error NonArithmeticType();
|
|
|
116
116
|
error UnsupportedArithmeticType();
|
|
117
117
|
|
|
118
118
|
library TypeUtils {
|
|
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
|
+
}
|
|
131
|
+
|
|
119
132
|
/**
|
|
120
133
|
* @notice Extracts the TEE type from a handle.
|
|
121
134
|
* The type is stored at byte position 5 in the handle.
|