@inco/lightning 0.1.30 → 0.1.31
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/CHANGELOG.md +4 -0
- package/manifest.yaml +23 -0
- package/package.json +5 -1
- package/src/CreateXHelper.sol +14 -0
- package/src/DeployUtils.sol +95 -19
- package/src/Lib.demonet.sol +389 -0
- package/src/Lib.devnet.sol +389 -0
- package/src/Lib.sol +37 -160
- package/src/Lib.testnet.sol +389 -0
- package/src/Types.sol +54 -52
- package/src/libs/incoLightning_0_1_29__863421733.sol +389 -0
- package/src/lightning-parts/DecryptionHandler.sol +208 -37
- package/src/lightning-parts/primitives/SignatureVerifier.sol +24 -9
- package/src/test/AddTwo.sol +15 -11
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +2 -1
- package/src/test/FibonacciDecrypt.sol +48 -0
- package/src/test/IncoTest.sol +6 -4
- package/src/test/TestAddTwo.t.sol +8 -10
- package/src/version/IncoLightningConfig.sol +2 -2
- package/dumps/incoLightning_0_1_23__547622051.dump.json +0 -1
- package/dumps/incoLightning_0_1_23__547622051.env +0 -15
- package/dumps/incoLightning_0_1_23__830342853.dump.json +0 -1
- package/dumps/incoLightning_0_1_23__830342853.env +0 -15
- package/dumps/incoLightning_0_1_24__266705097.dump.json +0 -1
- package/dumps/incoLightning_0_1_24__266705097.env +0 -15
- package/dumps/incoLightning_0_1_25__861473222.dump.json +0 -1
- package/dumps/incoLightning_0_1_25__861473222.env +0 -15
- package/dumps/incoLightning_0_1_25__986372984.dump.json +0 -1
- package/dumps/incoLightning_0_1_25__986372984.env +0 -15
- package/dumps/incoLightning_0_1_26__18043964.dump.json +0 -1
- package/dumps/incoLightning_0_1_26__18043964.env +0 -15
- package/dumps/incoLightning_0_1_26__444235330.dump.json +0 -1
- package/dumps/incoLightning_0_1_26__444235330.env +0 -15
- package/dumps/incoLightning_0_1_27__125335042.dump.json +0 -1
- package/dumps/incoLightning_0_1_27__125335042.env +0 -14
- package/dumps/incoLightning_0_1_27__558243565.dump.json +0 -1
- package/dumps/incoLightning_0_1_27__558243565.env +0 -14
- package/dumps/incoLightning_0_1_29__183408998.dump.json +0 -1
- package/dumps/incoLightning_0_1_29__183408998.env +0 -14
- package/dumps/incoLightning_0_1_29__340846814.dump.json +0 -1
- package/dumps/incoLightning_0_1_29__340846814.env +0 -14
|
@@ -6,11 +6,13 @@ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
|
6
6
|
|
|
7
7
|
contract SignatureVerifierStorage {
|
|
8
8
|
struct StorageForSigVerifier {
|
|
9
|
-
address
|
|
9
|
+
mapping(address => bool) isSigner;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
// State changelog:
|
|
13
|
+
// 0.2.0: Shifting state location to support multiple signers
|
|
12
14
|
bytes32 private constant SignatureVerifierStorageLocation =
|
|
13
|
-
keccak256("inco.storage.SignatureVerifier");
|
|
15
|
+
keccak256("inco.storage.SignatureVerifier.v0.2.0");
|
|
14
16
|
|
|
15
17
|
function getSigVerifierStorage()
|
|
16
18
|
internal
|
|
@@ -27,21 +29,34 @@ contract SignatureVerifierStorage {
|
|
|
27
29
|
contract SignatureVerifier is OwnableUpgradeable, SignatureVerifierStorage {
|
|
28
30
|
using ECDSA for bytes32;
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
error SignerNotFound(address signerAddress);
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
event AddedSignatureVerifier(address signerAddress);
|
|
35
|
+
event RemovedSignatureVerifier(address signerAddress);
|
|
36
|
+
|
|
37
|
+
function addSigner(address signerAddress) external onlyOwner {
|
|
38
|
+
getSigVerifierStorage().isSigner[signerAddress] = true;
|
|
39
|
+
emit AddedSignatureVerifier(signerAddress);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function removeSigner(address signerAddress) external onlyOwner {
|
|
43
|
+
require(
|
|
44
|
+
getSigVerifierStorage().isSigner[signerAddress],
|
|
45
|
+
SignerNotFound(signerAddress)
|
|
46
|
+
);
|
|
47
|
+
getSigVerifierStorage().isSigner[signerAddress] = false;
|
|
48
|
+
emit AddedSignatureVerifier(signerAddress);
|
|
35
49
|
}
|
|
36
50
|
|
|
37
|
-
function
|
|
38
|
-
return getSigVerifierStorage().
|
|
51
|
+
function isSigner(address signerAddress) public view returns (bool) {
|
|
52
|
+
return getSigVerifierStorage().isSigner[signerAddress];
|
|
39
53
|
}
|
|
40
54
|
|
|
41
55
|
function isValidSignature(
|
|
42
56
|
bytes32 hash,
|
|
43
57
|
bytes memory signature
|
|
44
58
|
) public view returns (bool) {
|
|
45
|
-
|
|
59
|
+
address signerAddress = hash.recover(signature);
|
|
60
|
+
return getSigVerifierStorage().isSigner[signerAddress];
|
|
46
61
|
}
|
|
47
62
|
}
|
package/src/test/AddTwo.sol
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {IncoLightning} from "../IncoLightning.sol";
|
|
5
|
+
import {euint256} from "../Types.sol";
|
|
5
6
|
|
|
6
7
|
contract AddTwo {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
IncoLightning immutable inco;
|
|
9
|
+
|
|
10
|
+
constructor(IncoLightning _inco) {
|
|
11
|
+
inco = _inco;
|
|
12
|
+
}
|
|
10
13
|
|
|
11
14
|
// Stores the result of the last callback.
|
|
12
15
|
uint256 public lastResult;
|
|
13
16
|
|
|
14
17
|
function addTwo(euint256 a) external returns (euint256) {
|
|
15
18
|
uint256 two = 2;
|
|
16
|
-
return
|
|
19
|
+
return inco.eAdd(a, inco.asEuint256(two));
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
function addTwoScalar(euint256 a) external returns (euint256) {
|
|
20
23
|
uint256 two = 2;
|
|
21
|
-
return a.
|
|
24
|
+
return inco.eAdd(a, inco.asEuint256(two));
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
// addTwoEOA is the equivalent of addTwo, but it allows an EOA to call it
|
|
@@ -26,13 +29,14 @@ contract AddTwo {
|
|
|
26
29
|
function addTwoEOA(
|
|
27
30
|
bytes memory uint256EInput
|
|
28
31
|
) external returns (uint256, euint256) {
|
|
29
|
-
euint256 value =
|
|
32
|
+
euint256 value = inco.newEuint256(uint256EInput, msg.sender);
|
|
30
33
|
euint256 result = this.addTwo(value);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
uint256 requestId =
|
|
34
|
-
result,
|
|
34
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
35
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
36
|
+
uint256 requestId = inco.requestDecryption(
|
|
35
37
|
this.callback.selector,
|
|
38
|
+
block.timestamp + 2 hours,
|
|
39
|
+
euint256.unwrap(result),
|
|
36
40
|
""
|
|
37
41
|
);
|
|
38
42
|
return (requestId, result);
|
|
@@ -25,7 +25,8 @@ contract FakeIncoInfraBase is TestUtils, KVStore {
|
|
|
25
25
|
) internal {
|
|
26
26
|
DecryptionResult memory result = DecryptionResult({
|
|
27
27
|
abiEncodedResult: get(handle),
|
|
28
|
-
requestId: requestId
|
|
28
|
+
requestId: requestId,
|
|
29
|
+
handle: handle
|
|
29
30
|
});
|
|
30
31
|
vm.prank(teePubkeyAddress);
|
|
31
32
|
inco.fulfillRequest(result, "");
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {IncoLightning} from "../IncoLightning.sol";
|
|
5
|
+
import {euint256} from "../Types.sol";
|
|
6
|
+
|
|
7
|
+
contract FibonacciDecrypt {
|
|
8
|
+
IncoLightning immutable inco;
|
|
9
|
+
|
|
10
|
+
constructor(IncoLightning _inco) {
|
|
11
|
+
inco = _inco;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Stores the result of the last callback.
|
|
15
|
+
uint256 public lastResult;
|
|
16
|
+
|
|
17
|
+
function fib(
|
|
18
|
+
uint256 n
|
|
19
|
+
) external returns (uint256 lastRequestId, euint256 nthTerm) {
|
|
20
|
+
euint256 prev = inco.asEuint256(0);
|
|
21
|
+
lastRequestId = emitTerm(prev);
|
|
22
|
+
nthTerm = inco.asEuint256(1);
|
|
23
|
+
lastRequestId = emitTerm(nthTerm);
|
|
24
|
+
for (uint256 i = 0; i < n-2; i++) {
|
|
25
|
+
euint256 temp = nthTerm;
|
|
26
|
+
nthTerm = inco.eAdd(prev, nthTerm);
|
|
27
|
+
prev = temp;
|
|
28
|
+
lastRequestId = emitTerm(nthTerm);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function emitTerm(euint256 term) internal returns (uint256 requestId) {
|
|
33
|
+
requestId = inco.requestDecryption(
|
|
34
|
+
this.callback.selector,
|
|
35
|
+
block.timestamp + 2 hours,
|
|
36
|
+
euint256.unwrap(term),
|
|
37
|
+
""
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function callback(
|
|
42
|
+
uint256 /* requestId */,
|
|
43
|
+
uint256 result,
|
|
44
|
+
bytes memory /* data */
|
|
45
|
+
) external {
|
|
46
|
+
lastResult = result;
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/test/IncoTest.sol
CHANGED
|
@@ -27,8 +27,10 @@ contract IncoTest is MockOpHandler, DeployUtils {
|
|
|
27
27
|
vm.startPrank(testDeployer);
|
|
28
28
|
IncoLightning proxy = deployIncoLightningUsingConfig({
|
|
29
29
|
deployer: testDeployer,
|
|
30
|
-
|
|
31
|
-
pepper: "testnet"
|
|
30
|
+
// The highest precedent deployment
|
|
31
|
+
pepper: "testnet",
|
|
32
|
+
minorVersionForSalt: 1,
|
|
33
|
+
patchVersionForSalt: 29
|
|
32
34
|
});
|
|
33
35
|
proxy.transferOwnership(owner);
|
|
34
36
|
vm.stopPrank();
|
|
@@ -40,10 +42,10 @@ contract IncoTest is MockOpHandler, DeployUtils {
|
|
|
40
42
|
console.log("Generated inco address: %s", address(inco));
|
|
41
43
|
require(
|
|
42
44
|
address(proxy) == address(inco),
|
|
43
|
-
"
|
|
45
|
+
"generated inco address in Lib.sol does not match address of inco deployed by IncoTest"
|
|
44
46
|
);
|
|
45
47
|
vm.prank(owner);
|
|
46
|
-
inco.
|
|
48
|
+
inco.addSigner(teePubkeyAddress);
|
|
47
49
|
vm.recordLogs();
|
|
48
50
|
}
|
|
49
51
|
}
|
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {inco} from "../Lib.sol";
|
|
5
|
+
import {euint256} from "../Types.sol";
|
|
5
6
|
import {IncoTest} from "./IncoTest.sol";
|
|
6
7
|
import {AddTwo} from "./AddTwo.sol";
|
|
7
8
|
|
|
8
9
|
contract TestAddTwo is IncoTest {
|
|
9
|
-
using e for euint256;
|
|
10
|
-
using e for uint256;
|
|
11
|
-
|
|
12
10
|
function testAddTwo() public {
|
|
13
|
-
AddTwo addTwo = new AddTwo();
|
|
11
|
+
AddTwo addTwo = new AddTwo(inco);
|
|
14
12
|
vm.label(address(addTwo), "addTwo");
|
|
15
|
-
euint256 a =
|
|
16
|
-
|
|
13
|
+
euint256 a = inco.asEuint256(3);
|
|
14
|
+
inco.allow(euint256.unwrap(a), address(addTwo));
|
|
17
15
|
euint256 b = addTwo.addTwo(a);
|
|
18
16
|
processAllOperations();
|
|
19
17
|
assertEq(getUint256Value(b), 5);
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
function testAddTwoScalar() public {
|
|
23
|
-
AddTwo addTwo = new AddTwo();
|
|
21
|
+
AddTwo addTwo = new AddTwo(inco);
|
|
24
22
|
vm.label(address(addTwo), "addTwoScalar");
|
|
25
|
-
euint256 a =
|
|
26
|
-
|
|
23
|
+
euint256 a = inco.asEuint256(3);
|
|
24
|
+
inco.allow(euint256.unwrap(a), address(addTwo));
|
|
27
25
|
euint256 b = addTwo.addTwoScalar(a);
|
|
28
26
|
processAllOperations();
|
|
29
27
|
assertEq(getUint256Value(b), 5);
|