@inco/lightning 0.1.20
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 +39 -0
- package/README.md +69 -0
- package/dumps/incoLightning_0_1_23__547622051.dump.json +1 -0
- package/dumps/incoLightning_0_1_23__547622051.env +15 -0
- package/dumps/incoLightning_0_1_23__830342853.dump.json +1 -0
- package/dumps/incoLightning_0_1_23__830342853.env +15 -0
- package/dumps/incoLightning_0_1_24__266705097.dump.json +1 -0
- package/dumps/incoLightning_0_1_24__266705097.env +15 -0
- package/dumps/incoLightning_0_1_25__986372984.dump.json +1 -0
- package/dumps/incoLightning_0_1_25__986372984.env +15 -0
- package/foundry.toml +20 -0
- package/package.json +27 -0
- package/remappings.txt +4 -0
- package/src/DeployUtils.sol +109 -0
- package/src/IncoLightning.sol +45 -0
- package/src/Lib.sol +389 -0
- package/src/Lib.template.sol +464 -0
- package/src/Types.sol +74 -0
- package/src/libs/incoLightning_0_1_22__761766708.sol +389 -0
- package/src/libs/incoLightning_0_1_23__547622051.sol +389 -0
- package/src/libs/incoLightning_0_1_23__830342853.sol +389 -0
- package/src/libs/incoLightning_0_1_24__266705097.sol +389 -0
- package/src/libs/incoLightning_0_1_25__986372984.sol +389 -0
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +105 -0
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +12 -0
- package/src/lightning-parts/DecryptionHandler.sol +164 -0
- package/src/lightning-parts/EncryptedInput.sol +61 -0
- package/src/lightning-parts/EncryptedOperations.sol +610 -0
- package/src/lightning-parts/TrivialEncryption.sol +43 -0
- package/src/lightning-parts/primitives/EventCounter.sol +32 -0
- package/src/lightning-parts/primitives/HandleGeneration.sol +107 -0
- package/src/lightning-parts/primitives/HandleMetadata.sol +38 -0
- package/src/lightning-parts/primitives/SignatureVerifier.sol +47 -0
- package/src/lightning-parts/test/HandleMetadata.t.sol +87 -0
- package/src/pasted-dependencies/CreateX.sol +1293 -0
- package/src/pasted-dependencies/ICreateX.sol +187 -0
- package/src/test/AddTwo.sol +48 -0
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +137 -0
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +77 -0
- package/src/test/FakeIncoInfra/KVStore.sol +35 -0
- package/src/test/FakeIncoInfra/MockOpHandler.sol +140 -0
- package/src/test/FakeIncoInfra/getOpForSelector.sol +71 -0
- package/src/test/IncoTest.sol +48 -0
- package/src/test/TestAddTwo.t.sol +31 -0
- package/src/test/TestDeploy.t.sol +39 -0
- package/src/test/TestExtractDataOfEventTooLarge.t.sol +43 -0
- package/src/test/TestFakeInfra.t.sol +301 -0
- package/src/test/TestVersion.t.sol +36 -0
- package/src/version/IncoLightningConfig.sol +13 -0
- package/src/version/Version.sol +76 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {MockOpHandler} from "./FakeIncoInfra/MockOpHandler.sol";
|
|
5
|
+
import {IncoLightning} from "../IncoLightning.sol";
|
|
6
|
+
import {inco} from "../Lib.sol";
|
|
7
|
+
import {DeployUtils} from "../DeployUtils.sol";
|
|
8
|
+
import {deployedBy} from "../Lib.sol";
|
|
9
|
+
import {console} from "forge-std/console.sol";
|
|
10
|
+
|
|
11
|
+
contract IncoTest is MockOpHandler, DeployUtils {
|
|
12
|
+
address immutable owner;
|
|
13
|
+
address immutable testDeployer;
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
owner = getLabeledAddress("owner");
|
|
17
|
+
// extracted from the deploy script running as bare simulation with:
|
|
18
|
+
// forge script src/script/Deploy.s.sol:Deploy
|
|
19
|
+
testDeployer = deployedBy;
|
|
20
|
+
vm.label(testDeployer, "testDeployer");
|
|
21
|
+
vm.label(address(this), "testRunner");
|
|
22
|
+
vm.label(address(inco), "inco");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function setUp() public virtual {
|
|
26
|
+
deployCreateX();
|
|
27
|
+
vm.startPrank(testDeployer);
|
|
28
|
+
IncoLightning proxy = deployIncoLightningUsingConfig({
|
|
29
|
+
deployer: testDeployer,
|
|
30
|
+
pepper: ""
|
|
31
|
+
});
|
|
32
|
+
proxy.transferOwnership(owner);
|
|
33
|
+
vm.stopPrank();
|
|
34
|
+
console.log(
|
|
35
|
+
"Deployed %s (proxy) to: %s",
|
|
36
|
+
proxy.getName(),
|
|
37
|
+
address(proxy)
|
|
38
|
+
);
|
|
39
|
+
console.log("Generated inco address: %s", address(inco));
|
|
40
|
+
require(
|
|
41
|
+
address(proxy) == address(inco),
|
|
42
|
+
"hardcoded inco address does not match proxy deployed in test setup"
|
|
43
|
+
);
|
|
44
|
+
vm.prank(owner);
|
|
45
|
+
inco.editPubkeyAddress(teePubkeyAddress);
|
|
46
|
+
vm.recordLogs();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {e, euint256} from "../Lib.sol";
|
|
5
|
+
import {IncoTest} from "./IncoTest.sol";
|
|
6
|
+
import {AddTwo} from "./AddTwo.sol";
|
|
7
|
+
|
|
8
|
+
contract TestAddTwo is IncoTest {
|
|
9
|
+
using e for euint256;
|
|
10
|
+
using e for uint256;
|
|
11
|
+
|
|
12
|
+
function testAddTwo() public {
|
|
13
|
+
AddTwo addTwo = new AddTwo();
|
|
14
|
+
vm.label(address(addTwo), "addTwo");
|
|
15
|
+
euint256 a = e.asEuint256(3);
|
|
16
|
+
a.allow(address(addTwo));
|
|
17
|
+
euint256 b = addTwo.addTwo(a);
|
|
18
|
+
processAllOperations();
|
|
19
|
+
assertEq(getUint256Value(b), 5);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function testAddTwoScalar() public {
|
|
23
|
+
AddTwo addTwo = new AddTwo();
|
|
24
|
+
vm.label(address(addTwo), "addTwoScalar");
|
|
25
|
+
euint256 a = e.asEuint256(3);
|
|
26
|
+
a.allow(address(addTwo));
|
|
27
|
+
euint256 b = addTwo.addTwoScalar(a);
|
|
28
|
+
processAllOperations();
|
|
29
|
+
assertEq(getUint256Value(b), 5);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {Test} from "forge-std/Test.sol";
|
|
5
|
+
import {TrivialEncryption} from "../lightning-parts/TrivialEncryption.sol";
|
|
6
|
+
import {ETypes} from "../Types.sol";
|
|
7
|
+
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
|
|
8
|
+
import {inco} from "../Lib.sol";
|
|
9
|
+
import {IncoTest} from "./IncoTest.sol";
|
|
10
|
+
|
|
11
|
+
contract ReturnTwo is UUPSUpgradeable {
|
|
12
|
+
function getTwo() external pure returns (uint256) {
|
|
13
|
+
return 2;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function _authorizeUpgrade(address) internal override {}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
contract TestDeploy is Test, IncoTest {
|
|
20
|
+
// todo test that inco gets deployed at the predicted address
|
|
21
|
+
|
|
22
|
+
function testDeployedCorrectly() public {
|
|
23
|
+
vm.expectEmit(false, false, true, false, address(inco));
|
|
24
|
+
emit TrivialEncryption.TrivialEncrypt(
|
|
25
|
+
bytes32(uint256(1)),
|
|
26
|
+
bytes32(uint256(1)),
|
|
27
|
+
ETypes.Bool,
|
|
28
|
+
0
|
|
29
|
+
);
|
|
30
|
+
inco.asEbool(true);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function testUpgrade() public {
|
|
34
|
+
ReturnTwo newImplem = new ReturnTwo();
|
|
35
|
+
vm.prank(owner);
|
|
36
|
+
inco.upgradeToAndCall(address(newImplem), "");
|
|
37
|
+
assertEq(ReturnTwo(address(inco)).getTwo(), 2);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {Test, Vm, console} from "forge-std/Test.sol";
|
|
5
|
+
|
|
6
|
+
event EventTooLarge(
|
|
7
|
+
bytes32 control, // can't index >3 fields
|
|
8
|
+
bytes32 indexed ifTrue,
|
|
9
|
+
bytes32 indexed ifFalse,
|
|
10
|
+
bytes32 indexed result,
|
|
11
|
+
uint256 eventId
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
contract Emitter {
|
|
15
|
+
function emitEventTooLarge() external {
|
|
16
|
+
emit EventTooLarge(
|
|
17
|
+
bytes32(uint256(1)),
|
|
18
|
+
bytes32(uint256(2)),
|
|
19
|
+
bytes32(uint256(3)),
|
|
20
|
+
bytes32(uint256(4)),
|
|
21
|
+
5
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
contract TestExtractDataOfEventTooLarge is Test {
|
|
27
|
+
function testEmit() public {
|
|
28
|
+
Emitter emitter = new Emitter();
|
|
29
|
+
vm.recordLogs();
|
|
30
|
+
emitter.emitEventTooLarge();
|
|
31
|
+
Vm.Log[] memory logs = vm.getRecordedLogs();
|
|
32
|
+
console.logBytes(logs[0].data);
|
|
33
|
+
bytes32 first32Bytes;
|
|
34
|
+
bytes32 second32Bytes;
|
|
35
|
+
bytes memory logData = logs[0].data;
|
|
36
|
+
assembly {
|
|
37
|
+
first32Bytes := mload(add(logData, 0x20))
|
|
38
|
+
second32Bytes := mload(add(logData, 0x40))
|
|
39
|
+
}
|
|
40
|
+
assertEq(first32Bytes, bytes32(uint256(1)));
|
|
41
|
+
assertEq(second32Bytes, bytes32(uint256(5)));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {IncoTest} from "./IncoTest.sol";
|
|
5
|
+
import {e, euint256, ebool} from "../Lib.sol";
|
|
6
|
+
import {SenderNotAllowedForHandle} from "../Types.sol";
|
|
7
|
+
|
|
8
|
+
contract TakesEInput {
|
|
9
|
+
using e for bytes;
|
|
10
|
+
using e for euint256;
|
|
11
|
+
|
|
12
|
+
euint256 public a;
|
|
13
|
+
ebool public b;
|
|
14
|
+
uint256 public decryptedA;
|
|
15
|
+
|
|
16
|
+
function setA(bytes memory uint256EInput) external {
|
|
17
|
+
a = uint256EInput.newEuint256(msg.sender);
|
|
18
|
+
a.allowThis();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function setB(bytes memory boolEInput) external {
|
|
22
|
+
b = boolEInput.newEbool(msg.sender);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function decryptA() external {
|
|
26
|
+
a.requestDecryption(this.aDecryptionCallback.selector, "");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function aDecryptionCallback(
|
|
30
|
+
uint256,
|
|
31
|
+
uint256 _decryptedA,
|
|
32
|
+
bytes memory
|
|
33
|
+
) external {
|
|
34
|
+
decryptedA = _decryptedA;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// its meta: this is testing correct behavior of our testing infrastructure
|
|
39
|
+
contract TestFakeInfra is IncoTest {
|
|
40
|
+
using e for euint256;
|
|
41
|
+
using e for ebool;
|
|
42
|
+
using e for uint256;
|
|
43
|
+
using e for bool;
|
|
44
|
+
|
|
45
|
+
function testTrivialEncrypt() public {
|
|
46
|
+
euint256 a = e.asEuint256(3);
|
|
47
|
+
assertEq(getUint256Value(a), 0); // operations not processed yet
|
|
48
|
+
processAllOperations();
|
|
49
|
+
assertEq(getUint256Value(a), 3);
|
|
50
|
+
ebool b = e.asEbool(true);
|
|
51
|
+
processAllOperations();
|
|
52
|
+
assertEq(getBoolValue(b), true);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function testEAdd() public {
|
|
56
|
+
euint256 a = e.asEuint256(3);
|
|
57
|
+
euint256 b = e.asEuint256(4);
|
|
58
|
+
euint256 c = a.add(b);
|
|
59
|
+
processAllOperations();
|
|
60
|
+
assertEq(getUint256Value(c), 7);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function testEAddScalar() public {
|
|
64
|
+
euint256 a = e.asEuint256(3);
|
|
65
|
+
euint256 c = a.add(uint256(4));
|
|
66
|
+
euint256 c256 = uint256(4).add(a);
|
|
67
|
+
processAllOperations();
|
|
68
|
+
assertEq(getUint256Value(c), 7);
|
|
69
|
+
assertEq(getUint256Value(c256), 7);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function testESub() public {
|
|
73
|
+
euint256 a = e.asEuint256(10);
|
|
74
|
+
euint256 b = e.asEuint256(4);
|
|
75
|
+
euint256 c = a.sub(b);
|
|
76
|
+
processAllOperations();
|
|
77
|
+
assertEq(getUint256Value(c), 6);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function testEMul() public {
|
|
81
|
+
euint256 a = e.asEuint256(10);
|
|
82
|
+
euint256 b = e.asEuint256(4);
|
|
83
|
+
euint256 c = a.mul(b);
|
|
84
|
+
processAllOperations();
|
|
85
|
+
assertEq(getUint256Value(c), 40);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function testEDiv() public {
|
|
89
|
+
euint256 a = e.asEuint256(10);
|
|
90
|
+
euint256 b = e.asEuint256(4);
|
|
91
|
+
euint256 c = a.div(b);
|
|
92
|
+
processAllOperations();
|
|
93
|
+
assertEq(getUint256Value(c), 2);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function testERem() public {
|
|
97
|
+
euint256 a = e.asEuint256(10);
|
|
98
|
+
euint256 b = e.asEuint256(4);
|
|
99
|
+
euint256 c = a.rem(b);
|
|
100
|
+
processAllOperations();
|
|
101
|
+
assertEq(getUint256Value(c), 2);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function testEAnd() public {
|
|
105
|
+
euint256 a = e.asEuint256(10);
|
|
106
|
+
euint256 b = e.asEuint256(4);
|
|
107
|
+
euint256 c = a.and(b);
|
|
108
|
+
processAllOperations();
|
|
109
|
+
assertEq(getUint256Value(c), 0);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function testEOr() public {
|
|
113
|
+
euint256 a = e.asEuint256(10);
|
|
114
|
+
euint256 b = e.asEuint256(4);
|
|
115
|
+
euint256 c = a.or(b);
|
|
116
|
+
processAllOperations();
|
|
117
|
+
assertEq(getUint256Value(c), 14);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function testEXor() public {
|
|
121
|
+
euint256 a = e.asEuint256(10);
|
|
122
|
+
euint256 b = e.asEuint256(4);
|
|
123
|
+
euint256 c = a.xor(b);
|
|
124
|
+
processAllOperations();
|
|
125
|
+
assertEq(getUint256Value(c), 14);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function testEShl() public {
|
|
129
|
+
euint256 a = e.asEuint256(10);
|
|
130
|
+
euint256 b = e.asEuint256(4);
|
|
131
|
+
euint256 c = a.shl(b);
|
|
132
|
+
processAllOperations();
|
|
133
|
+
assertEq(getUint256Value(c), 160);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function testEShr() public {
|
|
137
|
+
euint256 a = e.asEuint256(10);
|
|
138
|
+
euint256 b = e.asEuint256(4);
|
|
139
|
+
euint256 c = a.xor(b);
|
|
140
|
+
processAllOperations();
|
|
141
|
+
assertEq(getUint256Value(c), 14);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function testERotl() public {
|
|
145
|
+
euint256 a = e.asEuint256(10);
|
|
146
|
+
euint256 b = e.asEuint256(4);
|
|
147
|
+
euint256 c = a.rotl(b);
|
|
148
|
+
processAllOperations();
|
|
149
|
+
assertEq(getUint256Value(c), 160);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function testERotr() public {
|
|
153
|
+
euint256 a = e.asEuint256(10);
|
|
154
|
+
euint256 b = e.asEuint256(4);
|
|
155
|
+
euint256 c = a.rotr(b);
|
|
156
|
+
processAllOperations();
|
|
157
|
+
assertEq(
|
|
158
|
+
getUint256Value(c),
|
|
159
|
+
72370055773322622139731865630429942408293740416025352524660990004945706024960
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function testEEq() public {
|
|
164
|
+
euint256 a = e.asEuint256(10);
|
|
165
|
+
euint256 b = e.asEuint256(4);
|
|
166
|
+
ebool c = a.eq(b);
|
|
167
|
+
processAllOperations();
|
|
168
|
+
assertEq(getBoolValue(c), false);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function testENe() public {
|
|
172
|
+
euint256 a = e.asEuint256(10);
|
|
173
|
+
euint256 b = e.asEuint256(4);
|
|
174
|
+
ebool c = a.ne(b);
|
|
175
|
+
processAllOperations();
|
|
176
|
+
assertEq(getBoolValue(c), true);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function testEGe() public {
|
|
180
|
+
euint256 a = e.asEuint256(10);
|
|
181
|
+
euint256 b = e.asEuint256(4);
|
|
182
|
+
ebool c = a.ge(b);
|
|
183
|
+
processAllOperations();
|
|
184
|
+
assertEq(getBoolValue(c), true);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function testEGt() public {
|
|
188
|
+
euint256 a = e.asEuint256(10);
|
|
189
|
+
euint256 b = e.asEuint256(4);
|
|
190
|
+
ebool c = a.gt(b);
|
|
191
|
+
processAllOperations();
|
|
192
|
+
assertEq(getBoolValue(c), true);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function testELe() public {
|
|
196
|
+
euint256 a = e.asEuint256(10);
|
|
197
|
+
euint256 b = e.asEuint256(4);
|
|
198
|
+
ebool c = a.le(b);
|
|
199
|
+
processAllOperations();
|
|
200
|
+
assertEq(getBoolValue(c), false);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function testELt() public {
|
|
204
|
+
euint256 a = e.asEuint256(10);
|
|
205
|
+
euint256 b = e.asEuint256(4);
|
|
206
|
+
ebool c = a.lt(b);
|
|
207
|
+
processAllOperations();
|
|
208
|
+
assertEq(getBoolValue(c), false);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function testEMin() public {
|
|
212
|
+
euint256 a = e.asEuint256(10);
|
|
213
|
+
euint256 b = e.asEuint256(4);
|
|
214
|
+
euint256 c = a.min(b);
|
|
215
|
+
processAllOperations();
|
|
216
|
+
assertEq(getUint256Value(c), 4);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function testEMax() public {
|
|
220
|
+
euint256 a = e.asEuint256(10);
|
|
221
|
+
euint256 b = e.asEuint256(4);
|
|
222
|
+
euint256 c = a.max(b);
|
|
223
|
+
processAllOperations();
|
|
224
|
+
assertEq(getUint256Value(c), 10);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function testENot() public {
|
|
228
|
+
ebool a = e.asEbool(true);
|
|
229
|
+
ebool b = a.not();
|
|
230
|
+
processAllOperations();
|
|
231
|
+
assertEq(getBoolValue(b), false);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function testERand() public {
|
|
235
|
+
euint256 a = e.rand();
|
|
236
|
+
processAllOperations();
|
|
237
|
+
assertEq(getUint256Value(a), 1);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function testERandBounded() public {
|
|
241
|
+
euint256 a = e.randBounded(10);
|
|
242
|
+
processAllOperations();
|
|
243
|
+
assertEq(getUint256Value(a), 1);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function testEIfThenElse() public {
|
|
247
|
+
ebool controlA = e.asEbool(true);
|
|
248
|
+
ebool controlB = e.asEbool(false);
|
|
249
|
+
euint256 a = e.asEuint256(10);
|
|
250
|
+
euint256 b = e.asEuint256(4);
|
|
251
|
+
euint256 resA = controlA.select(a, b);
|
|
252
|
+
euint256 resB = controlB.select(a, b);
|
|
253
|
+
processAllOperations();
|
|
254
|
+
assertEq(getUint256Value(resA), 10);
|
|
255
|
+
assertEq(getUint256Value(resB), 4);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function testECastToEBool() public {
|
|
259
|
+
euint256 a = e.asEuint256(1);
|
|
260
|
+
ebool b = a.asEbool();
|
|
261
|
+
processAllOperations();
|
|
262
|
+
assertEq(getBoolValue(b), true);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function testECastToFromEBool() public {
|
|
266
|
+
ebool a = e.asEbool(true);
|
|
267
|
+
euint256 b = a.asEuint256();
|
|
268
|
+
processAllOperations();
|
|
269
|
+
assertEq(getUint256Value(b), 1);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function testEInput() public {
|
|
273
|
+
TakesEInput inputContract = new TakesEInput();
|
|
274
|
+
inputContract.setA(fakePrepareEuint256Ciphertext(12));
|
|
275
|
+
inputContract.setB(fakePrepareEboolCiphertext(true));
|
|
276
|
+
processAllOperations();
|
|
277
|
+
assertEq(getUint256Value(inputContract.a()), 12);
|
|
278
|
+
assertEq(getBoolValue(inputContract.b()), true);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function testDecryption() public {
|
|
282
|
+
TakesEInput inputContract = new TakesEInput();
|
|
283
|
+
inputContract.setA(fakePrepareEuint256Ciphertext(37));
|
|
284
|
+
inputContract.decryptA();
|
|
285
|
+
processAllOperations();
|
|
286
|
+
assertEq(inputContract.decryptedA(), 37);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function testUninitializedHandleIsDisallowed() public {
|
|
290
|
+
bytes32 randomHandle = keccak256("random handle");
|
|
291
|
+
euint256 a = e.asEuint256(12);
|
|
292
|
+
vm.expectRevert(
|
|
293
|
+
abi.encodeWithSelector(
|
|
294
|
+
SenderNotAllowedForHandle.selector,
|
|
295
|
+
randomHandle,
|
|
296
|
+
address(this)
|
|
297
|
+
)
|
|
298
|
+
);
|
|
299
|
+
a.add(euint256.wrap(randomHandle));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {Test} from "forge-std/Test.sol";
|
|
5
|
+
import {Version} from "../version/Version.sol";
|
|
6
|
+
|
|
7
|
+
contract SomeContract is Version {
|
|
8
|
+
constructor() Version(1, 2, 3, bytes32(uint(12345678)), "SomeContract") {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
contract TestVersion is Test {
|
|
12
|
+
SomeContract someContract;
|
|
13
|
+
|
|
14
|
+
function setUp() public {
|
|
15
|
+
someContract = new SomeContract();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function testVersion() public view {
|
|
19
|
+
assertEq(someContract.majorVersion(), 1);
|
|
20
|
+
assertEq(someContract.minorVersion(), 2);
|
|
21
|
+
assertEq(someContract.patchVersion(), 3);
|
|
22
|
+
assertEq(someContract.getName(), "SomeContract");
|
|
23
|
+
assertEq(someContract.getVersion(), "1_2_3");
|
|
24
|
+
assertEq(
|
|
25
|
+
someContract.getVersionedName(),
|
|
26
|
+
"SomeContract_1_2_3__12345678"
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function testVersionEip712() public view {
|
|
31
|
+
(, string memory name, string memory version, , , , ) = someContract
|
|
32
|
+
.eip712Domain();
|
|
33
|
+
assertEq(name, "SomeContract");
|
|
34
|
+
assertEq(version, "1_2_3");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
// Change these constants for new contracts
|
|
5
|
+
// Since this file only contains these constants, it could be generated reacting to cli inputs
|
|
6
|
+
|
|
7
|
+
// IMPORTANT if you are changing this file, run `make update_config` afterwards for it to take effect
|
|
8
|
+
// UPDATE the CHANGELOG on new versions
|
|
9
|
+
|
|
10
|
+
string constant CONTRACT_NAME = "incoLightning";
|
|
11
|
+
uint8 constant MAJOR_VERSION = 0;
|
|
12
|
+
uint8 constant MINOR_VERSION = 1;
|
|
13
|
+
uint8 constant PATCH_VERSION = 25;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
|
|
5
|
+
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
|
|
6
|
+
import {ShortStrings, ShortString} from "@openzeppelin/contracts/utils/ShortStrings.sol";
|
|
7
|
+
|
|
8
|
+
contract Version is EIP712 {
|
|
9
|
+
using ShortStrings for ShortString;
|
|
10
|
+
using ShortStrings for string;
|
|
11
|
+
|
|
12
|
+
uint8 public immutable majorVersion;
|
|
13
|
+
uint8 public immutable minorVersion;
|
|
14
|
+
uint8 public immutable patchVersion;
|
|
15
|
+
bytes32 public immutable salt;
|
|
16
|
+
ShortString private immutable name;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
uint8 _majorVersion,
|
|
20
|
+
uint8 _minorVersion,
|
|
21
|
+
uint8 _patchVersion,
|
|
22
|
+
bytes32 _salt,
|
|
23
|
+
string memory _name
|
|
24
|
+
)
|
|
25
|
+
EIP712(
|
|
26
|
+
_name,
|
|
27
|
+
versionString(_majorVersion, _minorVersion, _patchVersion)
|
|
28
|
+
)
|
|
29
|
+
{
|
|
30
|
+
majorVersion = _majorVersion;
|
|
31
|
+
minorVersion = _minorVersion;
|
|
32
|
+
patchVersion = _patchVersion;
|
|
33
|
+
salt = _salt;
|
|
34
|
+
name = _name.toShortString();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getVersionedName() public view virtual returns (string memory) {
|
|
38
|
+
uint256 shortSalt = uint256(salt) % 10e8;
|
|
39
|
+
return
|
|
40
|
+
string(
|
|
41
|
+
abi.encodePacked(
|
|
42
|
+
getName(),
|
|
43
|
+
"_",
|
|
44
|
+
getVersion(),
|
|
45
|
+
"__",
|
|
46
|
+
// avoids name collision for deployments of the same version
|
|
47
|
+
Strings.toString(shortSalt)
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getVersion() public view virtual returns (string memory) {
|
|
53
|
+
return versionString(majorVersion, minorVersion, patchVersion);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function versionString(
|
|
57
|
+
uint8 major,
|
|
58
|
+
uint8 minor,
|
|
59
|
+
uint8 patch
|
|
60
|
+
) internal pure returns (string memory) {
|
|
61
|
+
return
|
|
62
|
+
string(
|
|
63
|
+
abi.encodePacked(
|
|
64
|
+
Strings.toString(major),
|
|
65
|
+
"_",
|
|
66
|
+
Strings.toString(minor),
|
|
67
|
+
"_",
|
|
68
|
+
Strings.toString(patch)
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getName() public view virtual returns (string memory) {
|
|
74
|
+
return name.toString();
|
|
75
|
+
}
|
|
76
|
+
}
|