@inco/lightning 0.6.1 → 0.6.4
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/package.json +1 -1
- package/src/DeployUtils.sol +1 -1
- package/src/Errors.sol +1 -1
- package/src/Lib.alphanet.sol +24 -3
- package/src/Lib.demonet.sol +24 -3
- package/src/Lib.devnet.sol +24 -3
- package/src/Lib.sol +24 -3
- package/src/Lib.template.sol +97 -20
- package/src/Lib.testnet.sol +24 -3
- package/src/libs/incoLightning_alphanet_v0_297966649.sol +24 -3
- package/src/libs/incoLightning_alphanet_v1_725458969.sol +24 -3
- package/src/libs/incoLightning_demonet_v0_863421733.sol +24 -3
- package/src/libs/incoLightning_devnet_v0_340846814.sol +24 -3
- package/src/libs/incoLightning_devnet_v1_904635675.sol +24 -3
- package/src/libs/incoLightning_testnet_v0_183408998.sol +24 -3
- package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +1 -1
- package/src/lightning-parts/EncryptedInput.sol +52 -16
- package/src/lightning-parts/EncryptedOperations.sol +86 -90
- package/src/lightning-parts/TEELifecycle.sol +153 -66
- package/src/lightning-parts/TEELifecycle.types.sol +7 -0
- package/src/lightning-parts/interfaces/ITEELifecycle.sol +13 -2
- package/src/lightning-parts/primitives/HandleGeneration.sol +23 -57
- package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +3 -34
- package/src/lightning-parts/test/HandleMetadata.t.sol +41 -4
- package/src/lightning-parts/test/InputsFee.t.sol +14 -21
- package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +6 -2
- package/src/shared/IOwnable.sol +10 -0
- package/src/shared/IUUPSUpgradable.sol +10 -0
- package/src/shared/JsonUtils.sol +16 -0
- package/src/shared/TestUtils.sol +50 -0
- package/src/shared/TypeUtils.sol +12 -0
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +1 -1
- package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +36 -34
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +33 -18
- package/src/test/FakeIncoInfra/KVStore.sol +1 -1
- package/src/test/FakeIncoInfra/MockOpHandler.sol +5 -5
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +1 -1
- package/src/test/IncoTest.sol +1 -1
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +73 -20
- package/src/test/TestAddTwo.t.sol +1 -1
- package/src/test/TestFakeInfra.t.sol +13 -3
- package/src/version/Version.sol +4 -0
- package/src/version/interfaces/IVersion.sol +1 -0
package/src/Lib.testnet.sol
CHANGED
|
@@ -388,17 +388,38 @@ library e {
|
|
|
388
388
|
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
/// @
|
|
391
|
+
/// @notice Creates a new encrypted uint256 assuming msg.sender is the user
|
|
392
|
+
/// @dev costs the inco fee
|
|
393
|
+
function newEuint256(bytes memory ciphertext) internal returns (euint256) {
|
|
394
|
+
return newEuint256(ciphertext, msg.sender);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// @notice Creates a new encrypted uint256 for the given user.
|
|
398
|
+
/// @dev costs the inco fee
|
|
392
399
|
function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
|
|
393
400
|
return inco.newEuint256{value: inco.getFee()}(ciphertext, user);
|
|
394
401
|
}
|
|
395
402
|
|
|
396
|
-
/// @
|
|
403
|
+
/// @notice Creates a new encrypted bool assuming msg.sender is the user
|
|
404
|
+
/// @dev costs the inco fee
|
|
405
|
+
function newEbool(bytes memory ciphertext) internal returns (ebool) {
|
|
406
|
+
return newEbool(ciphertext, msg.sender);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/// @notice Creates a new encrypted bool for the given user.
|
|
410
|
+
/// @dev costs the inco fee
|
|
397
411
|
function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
|
|
398
412
|
return inco.newEbool{value: inco.getFee()}(ciphertext, user);
|
|
399
413
|
}
|
|
400
414
|
|
|
401
|
-
/// @
|
|
415
|
+
/// @notice Creates a new encrypted address assuming msg.sender is the user
|
|
416
|
+
/// @dev costs the inco fee
|
|
417
|
+
function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
|
|
418
|
+
return newEaddress(ciphertext, msg.sender);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/// @notice Creates a new encrypted address for the given user.
|
|
422
|
+
/// @dev costs the inco fee
|
|
402
423
|
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
403
424
|
return inco.newEaddress{value: inco.getFee()}(ciphertext, user);
|
|
404
425
|
}
|
|
@@ -388,17 +388,38 @@ library e {
|
|
|
388
388
|
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
/// @
|
|
391
|
+
/// @notice Creates a new encrypted uint256 assuming msg.sender is the user
|
|
392
|
+
/// @dev costs the inco fee
|
|
393
|
+
function newEuint256(bytes memory ciphertext) internal returns (euint256) {
|
|
394
|
+
return newEuint256(ciphertext, msg.sender);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// @notice Creates a new encrypted uint256 for the given user.
|
|
398
|
+
/// @dev costs the inco fee
|
|
392
399
|
function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
|
|
393
400
|
return inco.newEuint256{value: inco.getFee()}(ciphertext, user);
|
|
394
401
|
}
|
|
395
402
|
|
|
396
|
-
/// @
|
|
403
|
+
/// @notice Creates a new encrypted bool assuming msg.sender is the user
|
|
404
|
+
/// @dev costs the inco fee
|
|
405
|
+
function newEbool(bytes memory ciphertext) internal returns (ebool) {
|
|
406
|
+
return newEbool(ciphertext, msg.sender);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/// @notice Creates a new encrypted bool for the given user.
|
|
410
|
+
/// @dev costs the inco fee
|
|
397
411
|
function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
|
|
398
412
|
return inco.newEbool{value: inco.getFee()}(ciphertext, user);
|
|
399
413
|
}
|
|
400
414
|
|
|
401
|
-
/// @
|
|
415
|
+
/// @notice Creates a new encrypted address assuming msg.sender is the user
|
|
416
|
+
/// @dev costs the inco fee
|
|
417
|
+
function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
|
|
418
|
+
return newEaddress(ciphertext, msg.sender);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/// @notice Creates a new encrypted address for the given user.
|
|
422
|
+
/// @dev costs the inco fee
|
|
402
423
|
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
403
424
|
return inco.newEaddress{value: inco.getFee()}(ciphertext, user);
|
|
404
425
|
}
|
|
@@ -388,17 +388,38 @@ library e {
|
|
|
388
388
|
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
/// @
|
|
391
|
+
/// @notice Creates a new encrypted uint256 assuming msg.sender is the user
|
|
392
|
+
/// @dev costs the inco fee
|
|
393
|
+
function newEuint256(bytes memory ciphertext) internal returns (euint256) {
|
|
394
|
+
return newEuint256(ciphertext, msg.sender);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// @notice Creates a new encrypted uint256 for the given user.
|
|
398
|
+
/// @dev costs the inco fee
|
|
392
399
|
function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
|
|
393
400
|
return inco.newEuint256{value: inco.getFee()}(ciphertext, user);
|
|
394
401
|
}
|
|
395
402
|
|
|
396
|
-
/// @
|
|
403
|
+
/// @notice Creates a new encrypted bool assuming msg.sender is the user
|
|
404
|
+
/// @dev costs the inco fee
|
|
405
|
+
function newEbool(bytes memory ciphertext) internal returns (ebool) {
|
|
406
|
+
return newEbool(ciphertext, msg.sender);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/// @notice Creates a new encrypted bool for the given user.
|
|
410
|
+
/// @dev costs the inco fee
|
|
397
411
|
function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
|
|
398
412
|
return inco.newEbool{value: inco.getFee()}(ciphertext, user);
|
|
399
413
|
}
|
|
400
414
|
|
|
401
|
-
/// @
|
|
415
|
+
/// @notice Creates a new encrypted address assuming msg.sender is the user
|
|
416
|
+
/// @dev costs the inco fee
|
|
417
|
+
function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
|
|
418
|
+
return newEaddress(ciphertext, msg.sender);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/// @notice Creates a new encrypted address for the given user.
|
|
422
|
+
/// @dev costs the inco fee
|
|
402
423
|
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
403
424
|
return inco.newEaddress{value: inco.getFee()}(ciphertext, user);
|
|
404
425
|
}
|
|
@@ -388,17 +388,38 @@ library e {
|
|
|
388
388
|
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
/// @
|
|
391
|
+
/// @notice Creates a new encrypted uint256 assuming msg.sender is the user
|
|
392
|
+
/// @dev costs the inco fee
|
|
393
|
+
function newEuint256(bytes memory ciphertext) internal returns (euint256) {
|
|
394
|
+
return newEuint256(ciphertext, msg.sender);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// @notice Creates a new encrypted uint256 for the given user.
|
|
398
|
+
/// @dev costs the inco fee
|
|
392
399
|
function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
|
|
393
400
|
return inco.newEuint256{value: inco.getFee()}(ciphertext, user);
|
|
394
401
|
}
|
|
395
402
|
|
|
396
|
-
/// @
|
|
403
|
+
/// @notice Creates a new encrypted bool assuming msg.sender is the user
|
|
404
|
+
/// @dev costs the inco fee
|
|
405
|
+
function newEbool(bytes memory ciphertext) internal returns (ebool) {
|
|
406
|
+
return newEbool(ciphertext, msg.sender);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/// @notice Creates a new encrypted bool for the given user.
|
|
410
|
+
/// @dev costs the inco fee
|
|
397
411
|
function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
|
|
398
412
|
return inco.newEbool{value: inco.getFee()}(ciphertext, user);
|
|
399
413
|
}
|
|
400
414
|
|
|
401
|
-
/// @
|
|
415
|
+
/// @notice Creates a new encrypted address assuming msg.sender is the user
|
|
416
|
+
/// @dev costs the inco fee
|
|
417
|
+
function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
|
|
418
|
+
return newEaddress(ciphertext, msg.sender);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/// @notice Creates a new encrypted address for the given user.
|
|
422
|
+
/// @dev costs the inco fee
|
|
402
423
|
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
403
424
|
return inco.newEaddress{value: inco.getFee()}(ciphertext, user);
|
|
404
425
|
}
|
|
@@ -388,17 +388,38 @@ library e {
|
|
|
388
388
|
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
/// @
|
|
391
|
+
/// @notice Creates a new encrypted uint256 assuming msg.sender is the user
|
|
392
|
+
/// @dev costs the inco fee
|
|
393
|
+
function newEuint256(bytes memory ciphertext) internal returns (euint256) {
|
|
394
|
+
return newEuint256(ciphertext, msg.sender);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// @notice Creates a new encrypted uint256 for the given user.
|
|
398
|
+
/// @dev costs the inco fee
|
|
392
399
|
function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
|
|
393
400
|
return inco.newEuint256{value: inco.getFee()}(ciphertext, user);
|
|
394
401
|
}
|
|
395
402
|
|
|
396
|
-
/// @
|
|
403
|
+
/// @notice Creates a new encrypted bool assuming msg.sender is the user
|
|
404
|
+
/// @dev costs the inco fee
|
|
405
|
+
function newEbool(bytes memory ciphertext) internal returns (ebool) {
|
|
406
|
+
return newEbool(ciphertext, msg.sender);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/// @notice Creates a new encrypted bool for the given user.
|
|
410
|
+
/// @dev costs the inco fee
|
|
397
411
|
function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
|
|
398
412
|
return inco.newEbool{value: inco.getFee()}(ciphertext, user);
|
|
399
413
|
}
|
|
400
414
|
|
|
401
|
-
/// @
|
|
415
|
+
/// @notice Creates a new encrypted address assuming msg.sender is the user
|
|
416
|
+
/// @dev costs the inco fee
|
|
417
|
+
function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
|
|
418
|
+
return newEaddress(ciphertext, msg.sender);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/// @notice Creates a new encrypted address for the given user.
|
|
422
|
+
/// @dev costs the inco fee
|
|
402
423
|
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
403
424
|
return inco.newEaddress{value: inco.getFee()}(ciphertext, user);
|
|
404
425
|
}
|
|
@@ -388,17 +388,38 @@ library e {
|
|
|
388
388
|
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
/// @
|
|
391
|
+
/// @notice Creates a new encrypted uint256 assuming msg.sender is the user
|
|
392
|
+
/// @dev costs the inco fee
|
|
393
|
+
function newEuint256(bytes memory ciphertext) internal returns (euint256) {
|
|
394
|
+
return newEuint256(ciphertext, msg.sender);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// @notice Creates a new encrypted uint256 for the given user.
|
|
398
|
+
/// @dev costs the inco fee
|
|
392
399
|
function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
|
|
393
400
|
return inco.newEuint256{value: inco.getFee()}(ciphertext, user);
|
|
394
401
|
}
|
|
395
402
|
|
|
396
|
-
/// @
|
|
403
|
+
/// @notice Creates a new encrypted bool assuming msg.sender is the user
|
|
404
|
+
/// @dev costs the inco fee
|
|
405
|
+
function newEbool(bytes memory ciphertext) internal returns (ebool) {
|
|
406
|
+
return newEbool(ciphertext, msg.sender);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/// @notice Creates a new encrypted bool for the given user.
|
|
410
|
+
/// @dev costs the inco fee
|
|
397
411
|
function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
|
|
398
412
|
return inco.newEbool{value: inco.getFee()}(ciphertext, user);
|
|
399
413
|
}
|
|
400
414
|
|
|
401
|
-
/// @
|
|
415
|
+
/// @notice Creates a new encrypted address assuming msg.sender is the user
|
|
416
|
+
/// @dev costs the inco fee
|
|
417
|
+
function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
|
|
418
|
+
return newEaddress(ciphertext, msg.sender);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/// @notice Creates a new encrypted address for the given user.
|
|
422
|
+
/// @dev costs the inco fee
|
|
402
423
|
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
403
424
|
return inco.newEaddress{value: inco.getFee()}(ciphertext, user);
|
|
404
425
|
}
|
|
@@ -388,17 +388,38 @@ library e {
|
|
|
388
388
|
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
/// @
|
|
391
|
+
/// @notice Creates a new encrypted uint256 assuming msg.sender is the user
|
|
392
|
+
/// @dev costs the inco fee
|
|
393
|
+
function newEuint256(bytes memory ciphertext) internal returns (euint256) {
|
|
394
|
+
return newEuint256(ciphertext, msg.sender);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// @notice Creates a new encrypted uint256 for the given user.
|
|
398
|
+
/// @dev costs the inco fee
|
|
392
399
|
function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
|
|
393
400
|
return inco.newEuint256{value: inco.getFee()}(ciphertext, user);
|
|
394
401
|
}
|
|
395
402
|
|
|
396
|
-
/// @
|
|
403
|
+
/// @notice Creates a new encrypted bool assuming msg.sender is the user
|
|
404
|
+
/// @dev costs the inco fee
|
|
405
|
+
function newEbool(bytes memory ciphertext) internal returns (ebool) {
|
|
406
|
+
return newEbool(ciphertext, msg.sender);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/// @notice Creates a new encrypted bool for the given user.
|
|
410
|
+
/// @dev costs the inco fee
|
|
397
411
|
function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
|
|
398
412
|
return inco.newEbool{value: inco.getFee()}(ciphertext, user);
|
|
399
413
|
}
|
|
400
414
|
|
|
401
|
-
/// @
|
|
415
|
+
/// @notice Creates a new encrypted address assuming msg.sender is the user
|
|
416
|
+
/// @dev costs the inco fee
|
|
417
|
+
function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
|
|
418
|
+
return newEaddress(ciphertext, msg.sender);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/// @notice Creates a new encrypted address for the given user.
|
|
422
|
+
/// @dev costs the inco fee
|
|
402
423
|
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
403
424
|
return inco.newEaddress{value: inco.getFee()}(ciphertext, user);
|
|
404
425
|
}
|
|
@@ -74,7 +74,7 @@ contract TestAdvancedAccessControl is IncoTest {
|
|
|
74
74
|
super.setUp();
|
|
75
75
|
someContract = new SomeContractWithConfidentialData();
|
|
76
76
|
vm.deal(address(someContract), 100 ether);
|
|
77
|
-
bytes memory secretCt = fakePrepareEuint256Ciphertext(42);
|
|
77
|
+
bytes memory secretCt = fakePrepareEuint256Ciphertext(42, alice, address(someContract));
|
|
78
78
|
vm.prank(alice);
|
|
79
79
|
someContract.saveAPersonalSecret(secretCt);
|
|
80
80
|
secretHandle = euint256.unwrap(someContract.secret());
|
|
@@ -8,6 +8,18 @@ import {IEncryptedInput} from "./interfaces/IEncryptedInput.sol";
|
|
|
8
8
|
import {HandleAlreadyExists} from "../Errors.sol";
|
|
9
9
|
import {Fee} from "./Fee.sol";
|
|
10
10
|
|
|
11
|
+
// This error ordinarily indicates an unintentional mismatch between the client-side context and the ambient on-chain
|
|
12
|
+
// context
|
|
13
|
+
error ExternalHandleDoesNotMatchComputedHandle(
|
|
14
|
+
bytes32 externalHandle,
|
|
15
|
+
bytes32 computedHandle,
|
|
16
|
+
// These values are provided to help the caller debug a mismatch, they are the inputs to the context of computedHandle
|
|
17
|
+
uint256 chainId,
|
|
18
|
+
address aclAddress,
|
|
19
|
+
address userAddress,
|
|
20
|
+
address contractAddress
|
|
21
|
+
);
|
|
22
|
+
|
|
11
23
|
abstract contract EncryptedInput is
|
|
12
24
|
IEncryptedInput,
|
|
13
25
|
BaseAccessControlList,
|
|
@@ -18,33 +30,32 @@ abstract contract EncryptedInput is
|
|
|
18
30
|
bytes32 indexed result,
|
|
19
31
|
address indexed contractAddress,
|
|
20
32
|
address indexed user,
|
|
21
|
-
ETypes inputType,
|
|
22
33
|
bytes ciphertext,
|
|
23
34
|
uint256 eventId
|
|
24
35
|
);
|
|
25
36
|
|
|
26
37
|
function newEuint256(
|
|
27
|
-
bytes memory
|
|
38
|
+
bytes memory input,
|
|
28
39
|
address user
|
|
29
40
|
) external payable returns (euint256 newValue) {
|
|
30
|
-
return euint256.wrap(newInput(
|
|
41
|
+
return euint256.wrap(newInput(input, user, ETypes.Uint256));
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
function newEbool(
|
|
34
|
-
bytes memory
|
|
45
|
+
bytes memory input,
|
|
35
46
|
address user
|
|
36
47
|
) external payable returns (ebool newValue) {
|
|
37
|
-
return ebool.wrap(newInput(
|
|
48
|
+
return ebool.wrap(newInput(input, user, ETypes.Bool));
|
|
38
49
|
}
|
|
39
50
|
|
|
40
51
|
function newEaddress(
|
|
41
|
-
bytes memory
|
|
52
|
+
bytes memory input,
|
|
42
53
|
address user
|
|
43
54
|
) external payable returns (eaddress newValue) {
|
|
44
55
|
return
|
|
45
56
|
eaddress.wrap(
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
newInput(input, user, ETypes.AddressOrUint160OrBytes20)
|
|
58
|
+
);
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
function newInput(
|
|
@@ -63,20 +74,45 @@ abstract contract EncryptedInput is
|
|
|
63
74
|
newHandle = _newInput(ciphertext, user, inputType);
|
|
64
75
|
}
|
|
65
76
|
|
|
77
|
+
/// @notice Creates a new input with a prepended handle as a checksum.
|
|
78
|
+
/// @param input The input that contains the handle prepended to the ciphertext.
|
|
79
|
+
/// @param user The user address associated with the input.
|
|
66
80
|
function _newInput(
|
|
67
|
-
bytes memory
|
|
81
|
+
bytes memory input,
|
|
68
82
|
address user,
|
|
69
83
|
ETypes inputType
|
|
70
|
-
) private returns (bytes32
|
|
71
|
-
|
|
84
|
+
) private returns (bytes32 handle) {
|
|
85
|
+
// Since there is no sensible way to handle abi.decode errors (https://github.com/argotorg/solidity/issues/10381)
|
|
86
|
+
// at least fail early on a conservative minimum length
|
|
87
|
+
require(input.length >= 64, "Input too short, should be at least 64 bytes");
|
|
88
|
+
// Remove external handle prepended to input as a checksum
|
|
89
|
+
(bytes32 externalHandle, bytes memory ciphertext) = abi.decode(input, (bytes32, bytes));
|
|
90
|
+
handle = getInputHandle(ciphertext, user, msg.sender, inputType);
|
|
91
|
+
require(
|
|
92
|
+
handle == externalHandle,
|
|
93
|
+
ExternalHandleDoesNotMatchComputedHandle({
|
|
94
|
+
externalHandle: externalHandle,
|
|
95
|
+
computedHandle: handle,
|
|
96
|
+
chainId: block.chainid,
|
|
97
|
+
aclAddress: address(this),
|
|
98
|
+
userAddress: user,
|
|
99
|
+
contractAddress: msg.sender
|
|
100
|
+
})
|
|
101
|
+
);
|
|
72
102
|
// We assume that providing the same handle (which via HADU implies same plaintext, same context, and same
|
|
73
103
|
// instance of encryption)
|
|
74
|
-
require(!isAllowed(
|
|
104
|
+
require(!isAllowed(handle, user), HandleAlreadyExists(handle));
|
|
75
105
|
// We allow to user since this is harmless and it is convenient to use the allow mapping to track existing
|
|
76
|
-
allowInternal(
|
|
77
|
-
allowTransientInternal(
|
|
106
|
+
allowInternal(handle, user);
|
|
107
|
+
allowTransientInternal(handle, msg.sender);
|
|
78
108
|
uint256 id = getNextEventId();
|
|
79
|
-
emit NewInput(
|
|
80
|
-
|
|
109
|
+
emit NewInput({
|
|
110
|
+
result: handle,
|
|
111
|
+
contractAddress: msg.sender,
|
|
112
|
+
user: user,
|
|
113
|
+
ciphertext: ciphertext,
|
|
114
|
+
eventId: id
|
|
115
|
+
});
|
|
116
|
+
setDigest(abi.encodePacked(handle, id));
|
|
81
117
|
}
|
|
82
118
|
}
|