@inco/lightning 0.6.8 → 0.6.9
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 +29 -2
- package/manifest.yaml +0 -42
- package/package.json +5 -2
- package/src/CreateXHelper.sol +3 -1
- package/src/DeployUtils.sol +36 -71
- package/src/Errors.sol +1 -1
- package/src/IIncoLightning.sol +2 -0
- package/src/IncoLightning.sol +5 -17
- package/src/IncoVerifier.sol +12 -18
- package/src/Lib.template.sol +40 -159
- package/src/Types.sol +233 -97
- package/src/interfaces/IIncoLightning.sol +2 -0
- package/src/interfaces/IIncoVerifier.sol +7 -12
- package/src/interfaces/automata-interfaces/BELE.sol +2 -0
- package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +9 -11
- package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +3 -3
- package/src/interfaces/automata-interfaces/IPCCSRouter.sol +13 -47
- package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +2 -0
- package/src/interfaces/automata-interfaces/IPcsDao.sol +6 -11
- package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +4 -7
- package/src/interfaces/automata-interfaces/Types.sol +7 -6
- package/src/libs/incoLightning_devnet_v1_887305889.sol +5 -3
- package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +41 -75
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +31 -62
- package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +8 -15
- package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +5 -12
- package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +42 -83
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +2 -0
- package/src/lightning-parts/DecryptionAttester.sol +14 -28
- package/src/lightning-parts/EncryptedInput.sol +23 -52
- package/src/lightning-parts/EncryptedOperations.sol +93 -440
- package/src/lightning-parts/Fee.sol +3 -1
- package/src/lightning-parts/TEELifecycle.sol +95 -225
- package/src/lightning-parts/TEELifecycle.types.sol +4 -3
- package/src/lightning-parts/TrivialEncryption.sol +6 -20
- package/src/lightning-parts/interfaces/IDecryptionAttester.sol +7 -2
- package/src/lightning-parts/interfaces/IEncryptedInput.sol +5 -12
- package/src/lightning-parts/interfaces/IEncryptedOperations.sol +17 -61
- package/src/lightning-parts/interfaces/ITEELifecycle.sol +7 -11
- package/src/lightning-parts/interfaces/ITrivialEncryption.sol +2 -0
- package/src/lightning-parts/primitives/EventCounter.sol +7 -8
- package/src/lightning-parts/primitives/HandleGeneration.sol +20 -32
- package/src/lightning-parts/primitives/HandleMetadata.sol +7 -17
- package/src/lightning-parts/primitives/LightningAddressGetter.sol +3 -0
- package/src/lightning-parts/primitives/SignatureVerifier.sol +91 -27
- package/src/lightning-parts/primitives/VerifierAddressGetter.sol +3 -0
- package/src/lightning-parts/primitives/interfaces/IEventCounter.sol +2 -0
- package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +10 -2
- package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +4 -2
- package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +2 -0
- package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +838 -0
- package/src/lightning-parts/test/Fee.t.sol +6 -6
- package/src/lightning-parts/test/HandleMetadata.t.sol +21 -76
- package/src/lightning-parts/test/InputsFee.t.sol +7 -28
- package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +16 -48
- package/src/pasted-dependencies/CreateX.sol +146 -419
- package/src/pasted-dependencies/ICreateX.sol +58 -102
- package/src/periphery/SessionVerifier.sol +5 -7
- package/src/shared/IOwnable.sol +3 -0
- package/src/shared/IUUPSUpgradable.sol +5 -1
- package/src/shared/JsonUtils.sol +3 -5
- package/src/shared/TestUtils.sol +14 -13
- package/src/test/AddTwo.sol +9 -7
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
- package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -118
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +31 -48
- package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +4 -7
- package/src/test/FakeIncoInfra/KVStore.sol +2 -0
- package/src/test/FakeIncoInfra/MockOpHandler.sol +9 -31
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +44 -21
- package/src/test/IncoTest.sol +15 -9
- package/src/test/OpsTest.sol +429 -0
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +58 -104
- package/src/test/TestAddTwo.t.sol +4 -3
- package/src/test/TestDeploy.t.sol +5 -6
- package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -14
- package/src/test/TestFakeInfra.t.sol +15 -38
- package/src/test/TestUpgrade.t.sol +40 -135
- package/src/test/TestVersion.t.sol +6 -5
- package/src/version/IncoLightningConfig.sol +1 -1
- package/src/version/Version.sol +48 -51
- package/src/version/interfaces/IVersion.sol +6 -0
|
@@ -7,6 +7,7 @@ pragma solidity ^0.8.4;
|
|
|
7
7
|
* @custom:coauthor Matt Solomon (https://web.archive.org/web/20230921103335/https://mattsolomon.dev/)
|
|
8
8
|
*/
|
|
9
9
|
interface ICreateX {
|
|
10
|
+
|
|
10
11
|
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
11
12
|
/* TYPES */
|
|
12
13
|
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
@@ -22,10 +23,7 @@ interface ICreateX {
|
|
|
22
23
|
|
|
23
24
|
event ContractCreation(address indexed newContract, bytes32 indexed salt);
|
|
24
25
|
event ContractCreation(address indexed newContract);
|
|
25
|
-
event Create3ProxyContractCreation(
|
|
26
|
-
address indexed newContract,
|
|
27
|
-
bytes32 indexed salt
|
|
28
|
-
);
|
|
26
|
+
event Create3ProxyContractCreation(address indexed newContract, bytes32 indexed salt);
|
|
29
27
|
|
|
30
28
|
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
31
29
|
/* CUSTOM ERRORS */
|
|
@@ -41,49 +39,31 @@ interface ICreateX {
|
|
|
41
39
|
/* CREATE */
|
|
42
40
|
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
43
41
|
|
|
44
|
-
function deployCreate(
|
|
45
|
-
bytes memory initCode
|
|
46
|
-
) external payable returns (address newContract);
|
|
42
|
+
function deployCreate(bytes memory initCode) external payable returns (address newContract);
|
|
47
43
|
|
|
48
|
-
function deployCreateAndInit(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
address refundAddress
|
|
53
|
-
) external payable returns (address newContract);
|
|
44
|
+
function deployCreateAndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
|
|
45
|
+
external
|
|
46
|
+
payable
|
|
47
|
+
returns (address newContract);
|
|
54
48
|
|
|
55
|
-
function deployCreateAndInit(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
) external payable returns (address newContract);
|
|
49
|
+
function deployCreateAndInit(bytes memory initCode, bytes memory data, Values memory values)
|
|
50
|
+
external
|
|
51
|
+
payable
|
|
52
|
+
returns (address newContract);
|
|
60
53
|
|
|
61
|
-
function deployCreateClone(
|
|
62
|
-
address implementation,
|
|
63
|
-
bytes memory data
|
|
64
|
-
) external payable returns (address proxy);
|
|
54
|
+
function deployCreateClone(address implementation, bytes memory data) external payable returns (address proxy);
|
|
65
55
|
|
|
66
|
-
function computeCreateAddress(
|
|
67
|
-
address deployer,
|
|
68
|
-
uint256 nonce
|
|
69
|
-
) external view returns (address computedAddress);
|
|
56
|
+
function computeCreateAddress(address deployer, uint256 nonce) external view returns (address computedAddress);
|
|
70
57
|
|
|
71
|
-
function computeCreateAddress(
|
|
72
|
-
uint256 nonce
|
|
73
|
-
) external view returns (address computedAddress);
|
|
58
|
+
function computeCreateAddress(uint256 nonce) external view returns (address computedAddress);
|
|
74
59
|
|
|
75
60
|
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
76
61
|
/* CREATE2 */
|
|
77
62
|
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
78
63
|
|
|
79
|
-
function deployCreate2(
|
|
80
|
-
bytes32 salt,
|
|
81
|
-
bytes memory initCode
|
|
82
|
-
) external payable returns (address newContract);
|
|
64
|
+
function deployCreate2(bytes32 salt, bytes memory initCode) external payable returns (address newContract);
|
|
83
65
|
|
|
84
|
-
function deployCreate2(
|
|
85
|
-
bytes memory initCode
|
|
86
|
-
) external payable returns (address newContract);
|
|
66
|
+
function deployCreate2(bytes memory initCode) external payable returns (address newContract);
|
|
87
67
|
|
|
88
68
|
function deployCreate2AndInit(
|
|
89
69
|
bytes32 salt,
|
|
@@ -93,60 +73,45 @@ interface ICreateX {
|
|
|
93
73
|
address refundAddress
|
|
94
74
|
) external payable returns (address newContract);
|
|
95
75
|
|
|
96
|
-
function deployCreate2AndInit(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
Values memory values
|
|
101
|
-
) external payable returns (address newContract);
|
|
76
|
+
function deployCreate2AndInit(bytes32 salt, bytes memory initCode, bytes memory data, Values memory values)
|
|
77
|
+
external
|
|
78
|
+
payable
|
|
79
|
+
returns (address newContract);
|
|
102
80
|
|
|
103
|
-
function deployCreate2AndInit(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
address refundAddress
|
|
108
|
-
) external payable returns (address newContract);
|
|
81
|
+
function deployCreate2AndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
|
|
82
|
+
external
|
|
83
|
+
payable
|
|
84
|
+
returns (address newContract);
|
|
109
85
|
|
|
110
|
-
function deployCreate2AndInit(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
) external payable returns (address newContract);
|
|
86
|
+
function deployCreate2AndInit(bytes memory initCode, bytes memory data, Values memory values)
|
|
87
|
+
external
|
|
88
|
+
payable
|
|
89
|
+
returns (address newContract);
|
|
115
90
|
|
|
116
|
-
function deployCreate2Clone(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
) external payable returns (address proxy);
|
|
91
|
+
function deployCreate2Clone(bytes32 salt, address implementation, bytes memory data)
|
|
92
|
+
external
|
|
93
|
+
payable
|
|
94
|
+
returns (address proxy);
|
|
121
95
|
|
|
122
|
-
function deployCreate2Clone(
|
|
123
|
-
address implementation,
|
|
124
|
-
bytes memory data
|
|
125
|
-
) external payable returns (address proxy);
|
|
96
|
+
function deployCreate2Clone(address implementation, bytes memory data) external payable returns (address proxy);
|
|
126
97
|
|
|
127
|
-
function computeCreate2Address(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
address
|
|
131
|
-
) external pure returns (address computedAddress);
|
|
98
|
+
function computeCreate2Address(bytes32 salt, bytes32 initCodeHash, address deployer)
|
|
99
|
+
external
|
|
100
|
+
pure
|
|
101
|
+
returns (address computedAddress);
|
|
132
102
|
|
|
133
|
-
function computeCreate2Address(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
103
|
+
function computeCreate2Address(bytes32 salt, bytes32 initCodeHash)
|
|
104
|
+
external
|
|
105
|
+
view
|
|
106
|
+
returns (address computedAddress);
|
|
137
107
|
|
|
138
108
|
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
139
109
|
/* CREATE3 */
|
|
140
110
|
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
141
111
|
|
|
142
|
-
function deployCreate3(
|
|
143
|
-
bytes32 salt,
|
|
144
|
-
bytes memory initCode
|
|
145
|
-
) external payable returns (address newContract);
|
|
112
|
+
function deployCreate3(bytes32 salt, bytes memory initCode) external payable returns (address newContract);
|
|
146
113
|
|
|
147
|
-
function deployCreate3(
|
|
148
|
-
bytes memory initCode
|
|
149
|
-
) external payable returns (address newContract);
|
|
114
|
+
function deployCreate3(bytes memory initCode) external payable returns (address newContract);
|
|
150
115
|
|
|
151
116
|
function deployCreate3AndInit(
|
|
152
117
|
bytes32 salt,
|
|
@@ -156,32 +121,23 @@ interface ICreateX {
|
|
|
156
121
|
address refundAddress
|
|
157
122
|
) external payable returns (address newContract);
|
|
158
123
|
|
|
159
|
-
function deployCreate3AndInit(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
Values memory values
|
|
164
|
-
) external payable returns (address newContract);
|
|
124
|
+
function deployCreate3AndInit(bytes32 salt, bytes memory initCode, bytes memory data, Values memory values)
|
|
125
|
+
external
|
|
126
|
+
payable
|
|
127
|
+
returns (address newContract);
|
|
165
128
|
|
|
166
|
-
function deployCreate3AndInit(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
address refundAddress
|
|
171
|
-
) external payable returns (address newContract);
|
|
129
|
+
function deployCreate3AndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
|
|
130
|
+
external
|
|
131
|
+
payable
|
|
132
|
+
returns (address newContract);
|
|
172
133
|
|
|
173
|
-
function deployCreate3AndInit(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
) external payable returns (address newContract);
|
|
134
|
+
function deployCreate3AndInit(bytes memory initCode, bytes memory data, Values memory values)
|
|
135
|
+
external
|
|
136
|
+
payable
|
|
137
|
+
returns (address newContract);
|
|
178
138
|
|
|
179
|
-
function computeCreate3Address(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
) external pure returns (address computedAddress);
|
|
139
|
+
function computeCreate3Address(bytes32 salt, address deployer) external pure returns (address computedAddress);
|
|
140
|
+
|
|
141
|
+
function computeCreate3Address(bytes32 salt) external view returns (address computedAddress);
|
|
183
142
|
|
|
184
|
-
function computeCreate3Address(
|
|
185
|
-
bytes32 salt
|
|
186
|
-
) external view returns (address computedAddress);
|
|
187
143
|
}
|
|
@@ -23,9 +23,8 @@ struct Session {
|
|
|
23
23
|
/// the sharer to one decrypter for a limited time.
|
|
24
24
|
/// @dev define the selector of canUseSession in the voucher to use this verifier
|
|
25
25
|
contract SessionVerifier is UUPSUpgradeable, OwnableUpgradeable, Version {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
26
|
+
|
|
27
|
+
constructor(bytes32 salt)
|
|
29
28
|
Version(
|
|
30
29
|
SESSION_VERIFIER_MAJOR_VERSION,
|
|
31
30
|
SESSION_VERIFIER_MINOR_VERSION,
|
|
@@ -37,15 +36,13 @@ contract SessionVerifier is UUPSUpgradeable, OwnableUpgradeable, Version {
|
|
|
37
36
|
|
|
38
37
|
// todo add text mention of what is being signed
|
|
39
38
|
function canUseSession(
|
|
40
|
-
bytes32 /* handle
|
|
39
|
+
bytes32, /* handle */
|
|
41
40
|
address account,
|
|
42
41
|
bytes memory sharerArgData,
|
|
43
42
|
bytes memory /* requesterArgData */
|
|
44
43
|
) external view returns (bytes32) {
|
|
45
44
|
Session memory session = abi.decode(sharerArgData, (Session));
|
|
46
|
-
if (
|
|
47
|
-
session.expiresAt >= block.timestamp && session.decrypter == account
|
|
48
|
-
) {
|
|
45
|
+
if (session.expiresAt >= block.timestamp && session.decrypter == account) {
|
|
49
46
|
return ALLOWANCE_GRANTED_MAGIC_VALUE;
|
|
50
47
|
}
|
|
51
48
|
return bytes32(0);
|
|
@@ -60,4 +57,5 @@ contract SessionVerifier is UUPSUpgradeable, OwnableUpgradeable, Version {
|
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
fallback() external {} // must be included for createX deploy
|
|
60
|
+
|
|
63
61
|
}
|
package/src/shared/IOwnable.sol
CHANGED
|
@@ -4,7 +4,10 @@ pragma solidity ^0.8.0;
|
|
|
4
4
|
// OpenZeppelin doesn't export any interfaces for ownable so we define our own
|
|
5
5
|
|
|
6
6
|
interface IOwnable {
|
|
7
|
+
|
|
7
8
|
function owner() external view returns (address);
|
|
8
9
|
function transferOwnership(address newOwner) external;
|
|
10
|
+
|
|
9
11
|
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
|
|
12
|
+
|
|
10
13
|
}
|
|
@@ -4,7 +4,11 @@ pragma solidity ^0.8.0;
|
|
|
4
4
|
// OpenZeppelin doesn't export any interfaces for uupsUpgradeable so we define our own
|
|
5
5
|
|
|
6
6
|
interface IUUPSUpgradable {
|
|
7
|
+
|
|
8
|
+
// forge-lint: disable-next-line(mixed-case-function)
|
|
7
9
|
function proxiableUUID() external view returns (bytes32);
|
|
10
|
+
// forge-lint: disable-next-line(mixed-case-function)
|
|
8
11
|
function UPGRADE_INTERFACE_VERSION() external view returns (string memory);
|
|
9
12
|
function upgradeToAndCall(address newImplementation, bytes memory data) external payable;
|
|
10
|
-
|
|
13
|
+
|
|
14
|
+
}
|
package/src/shared/JsonUtils.sol
CHANGED
|
@@ -4,13 +4,11 @@ pragma solidity ^0.8;
|
|
|
4
4
|
import {Script} from "forge-std/Script.sol";
|
|
5
5
|
|
|
6
6
|
contract JsonUtils is Script {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
string memory addressName,
|
|
10
|
-
string memory destFile
|
|
11
|
-
) public {
|
|
7
|
+
|
|
8
|
+
function writeAddressToJson(address toWrite, string memory addressName, string memory destFile) public {
|
|
12
9
|
string memory jsonObj = "";
|
|
13
10
|
jsonObj = vm.serializeAddress(jsonObj, addressName, toWrite);
|
|
14
11
|
vm.writeJson(jsonObj, destFile);
|
|
15
12
|
}
|
|
13
|
+
|
|
16
14
|
}
|
package/src/shared/TestUtils.sol
CHANGED
|
@@ -4,6 +4,10 @@ pragma solidity ^0.8;
|
|
|
4
4
|
import {Test} from "forge-std/Test.sol";
|
|
5
5
|
|
|
6
6
|
contract TestUtils is Test {
|
|
7
|
+
|
|
8
|
+
address private constant ANVIL_ZEROTH_ADDRESS = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
|
|
9
|
+
uint256 private constant ANVIL_ZEROTH_PRIV_KEY = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;
|
|
10
|
+
|
|
7
11
|
uint256 internal alicePrivKey;
|
|
8
12
|
address internal immutable alice;
|
|
9
13
|
uint256 internal bobPrivKey;
|
|
@@ -15,36 +19,33 @@ contract TestUtils is Test {
|
|
|
15
19
|
uint256 internal evePrivKey;
|
|
16
20
|
address internal immutable eve;
|
|
17
21
|
|
|
22
|
+
// it is convenient for e2e tests to use these well-known addresses for the TEE
|
|
23
|
+
address internal constant teeEOA = ANVIL_ZEROTH_ADDRESS;
|
|
24
|
+
uint256 internal constant teePrivKey = ANVIL_ZEROTH_PRIV_KEY;
|
|
25
|
+
|
|
18
26
|
constructor() {
|
|
19
27
|
(alicePrivKey, alice) = getLabeledKeyPair("alice");
|
|
20
28
|
(bobPrivKey, bob) = getLabeledKeyPair("bob");
|
|
21
29
|
(carolPrivKey, carol) = getLabeledKeyPair("carol");
|
|
22
30
|
(davePrivKey, dave) = getLabeledKeyPair("dave");
|
|
23
31
|
(evePrivKey, eve) = getLabeledKeyPair("eve");
|
|
32
|
+
vm.label(teeEOA, "tee");
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
function getLabeledAddress(
|
|
27
|
-
|
|
28
|
-
) internal returns (address hashGenerated) {
|
|
29
|
-
hashGenerated = address(
|
|
30
|
-
uint160(uint256(keccak256(abi.encodePacked(input))))
|
|
31
|
-
);
|
|
35
|
+
function getLabeledAddress(string memory input) internal returns (address hashGenerated) {
|
|
36
|
+
hashGenerated = address(uint160(uint256(keccak256(abi.encodePacked(input)))));
|
|
32
37
|
vm.label(hashGenerated, input);
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
function getLabeledKeyPair(
|
|
36
|
-
string memory input
|
|
37
|
-
) internal returns (uint256 privKey, address accountAddress) {
|
|
40
|
+
function getLabeledKeyPair(string memory input) internal returns (uint256 privKey, address accountAddress) {
|
|
38
41
|
privKey = uint256(keccak256(abi.encodePacked(input)));
|
|
39
42
|
accountAddress = vm.addr(privKey);
|
|
40
43
|
vm.label(accountAddress, input);
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
function getSignatureForDigest(
|
|
44
|
-
bytes32 digest,
|
|
45
|
-
uint256 privKey
|
|
46
|
-
) internal pure returns (bytes memory signature) {
|
|
46
|
+
function getSignatureForDigest(bytes32 digest, uint256 privKey) internal pure returns (bytes memory signature) {
|
|
47
47
|
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privKey, digest);
|
|
48
48
|
signature = bytes.concat(r, s, bytes1(v));
|
|
49
49
|
}
|
|
50
|
+
|
|
50
51
|
}
|
package/src/test/AddTwo.sol
CHANGED
|
@@ -8,6 +8,7 @@ import {Fee} from "../lightning-parts/Fee.sol";
|
|
|
8
8
|
// To implement such a contract, we would normally import e form Lib.sol. For test purposes, we take inco as
|
|
9
9
|
// a constructor argument instead, so we can test it from other deployment addresses.
|
|
10
10
|
contract AddTwo is Fee {
|
|
11
|
+
|
|
11
12
|
IncoLightning inco;
|
|
12
13
|
|
|
13
14
|
constructor(IncoLightning _inco) {
|
|
@@ -28,13 +29,13 @@ contract AddTwo is Fee {
|
|
|
28
29
|
return inco.eAdd(a, inco.eAdd(one, one));
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
);
|
|
32
|
+
function addTwoEoa(bytes memory uint256EInput)
|
|
33
|
+
external
|
|
34
|
+
payable
|
|
35
|
+
refundUnspent
|
|
36
|
+
returns (euint256 result, euint256 resultRevealed)
|
|
37
|
+
{
|
|
38
|
+
euint256 value = inco.newEuint256{value: getFee()}(uint256EInput, msg.sender);
|
|
38
39
|
result = addTwo(value);
|
|
39
40
|
|
|
40
41
|
inco.allow(euint256.unwrap(result), address(this));
|
|
@@ -55,4 +56,5 @@ contract AddTwo is Fee {
|
|
|
55
56
|
receive() external payable {
|
|
56
57
|
// Accept ETH payments
|
|
57
58
|
}
|
|
59
|
+
|
|
58
60
|
}
|
|
@@ -5,11 +5,8 @@ import {EOps, ETypes} from "../../Types.sol";
|
|
|
5
5
|
import {asBytes32} from "../../shared/TypeUtils.sol";
|
|
6
6
|
|
|
7
7
|
contract FakeComputeServer {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
uint256 rhs,
|
|
11
|
-
EOps op
|
|
12
|
-
) internal pure returns (uint256) {
|
|
8
|
+
|
|
9
|
+
function computeBinaryUintOp(uint256 lhs, uint256 rhs, EOps op) internal pure returns (uint256) {
|
|
13
10
|
if (op == EOps.Add) {
|
|
14
11
|
return lhs + rhs;
|
|
15
12
|
} else if (op == EOps.Sub) {
|
|
@@ -43,11 +40,7 @@ contract FakeComputeServer {
|
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
function computeBinaryUintToBoolOp(
|
|
47
|
-
uint256 lhs,
|
|
48
|
-
uint256 rhs,
|
|
49
|
-
EOps op
|
|
50
|
-
) internal pure returns (bool) {
|
|
43
|
+
function computeBinaryUintToBoolOp(uint256 lhs, uint256 rhs, EOps op) internal pure returns (bool) {
|
|
51
44
|
if (op == EOps.Eq) {
|
|
52
45
|
return lhs == rhs;
|
|
53
46
|
} else if (op == EOps.Ne) {
|
|
@@ -66,31 +59,13 @@ contract FakeComputeServer {
|
|
|
66
59
|
}
|
|
67
60
|
|
|
68
61
|
function isBinaryUintToUintOp(EOps op) internal pure returns (bool) {
|
|
69
|
-
return
|
|
70
|
-
op == EOps.
|
|
71
|
-
op == EOps.
|
|
72
|
-
op == EOps.Mul ||
|
|
73
|
-
op == EOps.Div ||
|
|
74
|
-
op == EOps.Rem ||
|
|
75
|
-
op == EOps.Min ||
|
|
76
|
-
op == EOps.Max ||
|
|
77
|
-
op == EOps.BitAnd ||
|
|
78
|
-
op == EOps.BitOr ||
|
|
79
|
-
op == EOps.BitXor ||
|
|
80
|
-
op == EOps.Shl ||
|
|
81
|
-
op == EOps.Shr ||
|
|
82
|
-
op == EOps.Rotl ||
|
|
83
|
-
op == EOps.Rotr;
|
|
62
|
+
return op == EOps.Add || op == EOps.Sub || op == EOps.Mul || op == EOps.Div || op == EOps.Rem || op == EOps.Min
|
|
63
|
+
|| op == EOps.Max || op == EOps.BitAnd || op == EOps.BitOr || op == EOps.BitXor || op == EOps.Shl
|
|
64
|
+
|| op == EOps.Shr || op == EOps.Rotl || op == EOps.Rotr;
|
|
84
65
|
}
|
|
85
66
|
|
|
86
67
|
function isBinaryUintToBoolOp(EOps op) internal pure returns (bool) {
|
|
87
|
-
return
|
|
88
|
-
op == EOps.Eq ||
|
|
89
|
-
op == EOps.Ne ||
|
|
90
|
-
op == EOps.Ge ||
|
|
91
|
-
op == EOps.Gt ||
|
|
92
|
-
op == EOps.Le ||
|
|
93
|
-
op == EOps.Lt;
|
|
68
|
+
return op == EOps.Eq || op == EOps.Ne || op == EOps.Ge || op == EOps.Gt || op == EOps.Le || op == EOps.Lt;
|
|
94
69
|
}
|
|
95
70
|
|
|
96
71
|
function opToResultType(EOps op) internal pure returns (ETypes) {
|
|
@@ -107,31 +82,14 @@ contract FakeComputeServer {
|
|
|
107
82
|
return isBinaryUintToUintOp(op) || isBinaryUintToBoolOp(op);
|
|
108
83
|
}
|
|
109
84
|
|
|
110
|
-
function computeBinaryOp(
|
|
111
|
-
bytes32 encodedLhs,
|
|
112
|
-
bytes32 encodedRhs,
|
|
113
|
-
EOps op
|
|
114
|
-
) internal pure returns (bytes32) {
|
|
85
|
+
function computeBinaryOp(bytes32 encodedLhs, bytes32 encodedRhs, EOps op) internal pure returns (bytes32) {
|
|
115
86
|
if (isBinaryUintToUintOp(op)) {
|
|
116
|
-
return
|
|
117
|
-
bytes32(
|
|
118
|
-
computeBinaryUintOp(
|
|
119
|
-
uint256(encodedLhs),
|
|
120
|
-
uint256(encodedRhs),
|
|
121
|
-
op
|
|
122
|
-
)
|
|
123
|
-
);
|
|
87
|
+
return bytes32(computeBinaryUintOp(uint256(encodedLhs), uint256(encodedRhs), op));
|
|
124
88
|
} else if (isBinaryUintToBoolOp(op)) {
|
|
125
|
-
return
|
|
126
|
-
asBytes32(
|
|
127
|
-
computeBinaryUintToBoolOp(
|
|
128
|
-
uint256(encodedLhs),
|
|
129
|
-
uint256(encodedRhs),
|
|
130
|
-
op
|
|
131
|
-
)
|
|
132
|
-
);
|
|
89
|
+
return asBytes32(computeBinaryUintToBoolOp(uint256(encodedLhs), uint256(encodedRhs), op));
|
|
133
90
|
} else {
|
|
134
91
|
revert("computeBinaryOp Invalid binary op");
|
|
135
92
|
}
|
|
136
93
|
}
|
|
94
|
+
|
|
137
95
|
}
|