@inco/lightning-preview 0.8.0-devnet-8 → 0.8.0-devnet-10
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/IIncoLightningPreview.sol +0 -7
- package/src/IncoLightningPreview.sol +0 -98
- package/src/Preview.Lib.sol +0 -316
- package/src/PreviewDeployUtils.sol +0 -75
- package/src/TypesPreview.sol +0 -18
- package/src/lightning-parts/EList.sol +0 -322
- package/src/lightning-parts/IEList.sol +0 -33
- package/src/lightning-parts/primitives/EListHandleGeneration.sol +0 -63
- package/src/lightning-parts/primitives/EListHandleMetadata.sol +0 -60
- package/src/lightning-parts/primitives/interfaces/IEListHandleMetadata.sol +0 -8
- package/src/lightning-parts/test/Elist.t.sol +0 -66
- package/src/misc/ABIHelper.sol +0 -15
- package/src/test/EListTester.sol +0 -148
- package/src/test/PreviewIncoTest.sol +0 -32
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {IIncoLightning} from "@inco/lightning/src/interfaces/IIncoLightning.sol";
|
|
5
|
-
import {IEList} from "./lightning-parts/IEList.sol";
|
|
6
|
-
|
|
7
|
-
interface IIncoLightningPreview is IIncoLightning, IEList {}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {IncoLightning} from "@inco/lightning/src/IncoLightning.sol";
|
|
5
|
-
import {
|
|
6
|
-
CONTRACT_NAME,
|
|
7
|
-
MAJOR_VERSION,
|
|
8
|
-
MINOR_VERSION,
|
|
9
|
-
PATCH_VERSION
|
|
10
|
-
} from "@inco/lightning/src/version/IncoLightningConfig.sol";
|
|
11
|
-
import {Version} from "@inco/lightning/src/version/Version.sol";
|
|
12
|
-
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
|
|
13
|
-
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
14
|
-
import {EList} from "./lightning-parts/EList.sol";
|
|
15
|
-
import {VerifierAddressGetter} from "@inco/lightning/src/lightning-parts/primitives/VerifierAddressGetter.sol";
|
|
16
|
-
|
|
17
|
-
/// @title IncoLightningPreview
|
|
18
|
-
/// @notice Extended version of IncoLightning with preview/experimental features
|
|
19
|
-
/// @dev This contract extends the core IncoLightning functionality with additional features
|
|
20
|
-
/// that are still in preview/experimental stage. It uses a diamond-like delegation pattern:
|
|
21
|
-
///
|
|
22
|
-
/// Architecture:
|
|
23
|
-
/// - Inherits EList for encrypted list operations (preview feature)
|
|
24
|
-
/// - Delegates all other calls to the core IncoLightning contract via fallback
|
|
25
|
-
/// - Shares the same version and salt as the base IncoLightning for consistency
|
|
26
|
-
///
|
|
27
|
-
/// Call flow:
|
|
28
|
-
/// 1. If the function exists in IncoLightningPreview or EList, it's executed directly
|
|
29
|
-
/// 2. Otherwise, the fallback delegatecalls to IncoLightning for core functionality
|
|
30
|
-
///
|
|
31
|
-
/// This pattern allows adding new features without modifying the audited core contract.
|
|
32
|
-
contract IncoLightningPreview is EList, UUPSUpgradeable, Version, OwnableUpgradeable {
|
|
33
|
-
|
|
34
|
-
/// @notice Reference to the core IncoLightning contract for delegation
|
|
35
|
-
IncoLightning private immutable LIGHTNING;
|
|
36
|
-
|
|
37
|
-
/// @notice Initializes the preview contract with references to core infrastructure
|
|
38
|
-
/// @dev Uses address type instead of IncoLightning to avoid remapping issues during deployment.
|
|
39
|
-
/// Inherits the same version/salt as the base contract with "Preview" suffix appended.
|
|
40
|
-
/// @param _lightningAddress The deployed IncoLightning contract address
|
|
41
|
-
/// @param _verifierAddress The IncoVerifier contract address for attestation validation
|
|
42
|
-
constructor(address _lightningAddress, address _verifierAddress)
|
|
43
|
-
VerifierAddressGetter(_verifierAddress)
|
|
44
|
-
Version(
|
|
45
|
-
MAJOR_VERSION,
|
|
46
|
-
MINOR_VERSION,
|
|
47
|
-
PATCH_VERSION,
|
|
48
|
-
IncoLightning(_lightningAddress).salt(),
|
|
49
|
-
string(abi.encodePacked(CONTRACT_NAME, "Preview"))
|
|
50
|
-
)
|
|
51
|
-
{
|
|
52
|
-
LIGHTNING = IncoLightning(_lightningAddress);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/// @notice Indicates this contract includes experimental preview features
|
|
56
|
-
/// @dev Can be used by clients to detect if preview features are available
|
|
57
|
-
/// @return Always returns true for IncoLightningPreview
|
|
58
|
-
function includesPreviewFeatures() public pure returns (bool) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/// @notice Authorizes contract upgrades (restricted to owner only)
|
|
63
|
-
/// @dev Required by UUPSUpgradeable. Only the contract owner can authorize upgrades.
|
|
64
|
-
function _authorizeUpgrade(address) internal view override {
|
|
65
|
-
require(msg.sender == owner());
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/// @notice Initializes the proxy with an owner address
|
|
69
|
-
/// @dev Must be called immediately after proxy deployment. Can only be called once.
|
|
70
|
-
/// @param owner The address that will own this contract and can authorize upgrades
|
|
71
|
-
function initialize(address owner) public initializer {
|
|
72
|
-
__Ownable_init(owner);
|
|
73
|
-
_setAcceptedVersion(2, true);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/// @notice Delegates unhandled calls to the core IncoLightning contract
|
|
77
|
-
/// @dev Uses assembly delegatecall for gas efficiency and to properly forward all data.
|
|
78
|
-
/// Any function not defined in IncoLightningPreview or its parents will be
|
|
79
|
-
/// executed on IncoLightning in the context of this contract's storage.
|
|
80
|
-
fallback() external {
|
|
81
|
-
// get facet from function selector
|
|
82
|
-
address logic = address(LIGHTNING);
|
|
83
|
-
// Execute external calls using delegatecall on core and return any value.
|
|
84
|
-
assembly {
|
|
85
|
-
// copy function selector and any arguments
|
|
86
|
-
calldatacopy(0, 0, calldatasize())
|
|
87
|
-
// execute function call using the facet
|
|
88
|
-
let result := delegatecall(gas(), logic, 0, calldatasize(), 0, 0)
|
|
89
|
-
// get any return value
|
|
90
|
-
returndatacopy(0, 0, returndatasize())
|
|
91
|
-
// return any return value or error back to the caller
|
|
92
|
-
switch result
|
|
93
|
-
case 0 { revert(0, returndatasize()) }
|
|
94
|
-
default { return(0, returndatasize()) }
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}
|
package/src/Preview.Lib.sol
DELETED
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {IIncoLightningPreview} from "./IIncoLightningPreview.sol";
|
|
5
|
-
import {inco, ebool, euint256, e} from "@inco/lightning/src/Lib.sol";
|
|
6
|
-
import {ETypes} from "@inco/lightning/src/Types.sol";
|
|
7
|
-
import {elist, IndexOutOfRange, InvalidRange, SliceOutOfRange, UnsupportedListType} from "./TypesPreview.sol";
|
|
8
|
-
|
|
9
|
-
// forge-lint: disable-next-line(screaming-snake-case-const)
|
|
10
|
-
IIncoLightningPreview constant incoPreview = IIncoLightningPreview(address(inco));
|
|
11
|
-
|
|
12
|
-
/// @title Inco Lightning Preview Library
|
|
13
|
-
/// @author Inco
|
|
14
|
-
/// @notice You can use this library to try out experimental features before they get released
|
|
15
|
-
/// @dev If some library functions should be in preview, declare an ePreview lib here
|
|
16
|
-
/// @custom:experimental This library contains experimental features, and API may change or support can be dropped. Use at your own risk.
|
|
17
|
-
library ePreview {
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @notice Returns the type of the elements contained within the list. This is a pure function that does not require any gas to call.
|
|
21
|
-
* @param handle EList handle to read contrainer type from.
|
|
22
|
-
* @return ret Type of each element in the list.
|
|
23
|
-
*/
|
|
24
|
-
function listTypeOf(elist handle) internal pure returns (ETypes ret) {
|
|
25
|
-
return ETypes(uint8(uint256(elist.unwrap(handle)) >> 16));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @notice Creates a new empty list and returns a new elist handle. Type must be specified ahead of time and can not be changed.
|
|
30
|
-
* @param listType Type of each element in the list. This can not be changed
|
|
31
|
-
* @return ret A new elist handle
|
|
32
|
-
*/
|
|
33
|
-
function newEList(ETypes listType) internal returns (elist ret) {
|
|
34
|
-
return incoPreview.newEList(new bytes32[](0), listType);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @notice Creates a new list from existing array of handles and returns a new elist handle. Type must be specified ahead of time and can not be changed. The handle's type must match the type of the list inner type, otherwise it will revert.
|
|
39
|
-
* @param handles An array of handles to create a new list from
|
|
40
|
-
* @param listType Type of each element in the list. This can not be changed and must match the type of each handle in the array.
|
|
41
|
-
* @return ret A new elist handle
|
|
42
|
-
*/
|
|
43
|
-
function newEList(bytes32[] memory handles, ETypes listType) internal returns (elist ret) {
|
|
44
|
-
return incoPreview.newEList(handles, listType);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @notice Takes an array of user encrypted ciphertexts and returns a new elist handle. Expected type must be specified ahead of time and can not be changed. The ciphertext's type must match the type of the list inner type, otherwise it will revert.
|
|
49
|
-
* @param ciphertexts An array of encrypted user inputs to create a new list from
|
|
50
|
-
* @param listType Expected type of each element in the list. This can not be changed and must match the type of each ciphertext in the array.
|
|
51
|
-
* @param user Address of the user encrypting the ciphertexts.
|
|
52
|
-
* @return ret A new elist handle
|
|
53
|
-
* @dev each ciphertext costs the inco fee
|
|
54
|
-
*/
|
|
55
|
-
function newEList(bytes[] memory ciphertexts, ETypes listType, address user) internal returns (elist ret) {
|
|
56
|
-
return incoPreview.newEList{value: inco.getFee() * ciphertexts.length}(ciphertexts, listType, user);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @notice Appends an element of type ETypes.Bool at the end of a list, returning a new modified list handle.
|
|
61
|
-
* @param a An elist handle to append to. Must contain values of type ETypes.Bool.
|
|
62
|
-
* @param b Element value to be appended to the list. Must match the elist's inner type ETypes.Bool.
|
|
63
|
-
* @return ret A new elist handle. The new list will have a length of len(a)+1.
|
|
64
|
-
*/
|
|
65
|
-
function append(elist a, ebool b) internal returns (elist ret) {
|
|
66
|
-
return incoPreview.listAppend(a, ebool.unwrap(e.s(b)));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @notice Appends an element of type ETypes.Uint256 at the end of a list, returning a new modified list handle.
|
|
71
|
-
* @param a An elist handle to append to. Must contain values of type ETypes.Uint256.
|
|
72
|
-
* @param b Element value to be appended to the list. Must match the elist's inner type ETypes.Uint256.
|
|
73
|
-
* @return ret A new elist handle. The new list will have a length of len(a)+1.
|
|
74
|
-
*/
|
|
75
|
-
function append(elist a, euint256 b) internal returns (elist ret) {
|
|
76
|
-
return incoPreview.listAppend(a, euint256.unwrap(e.s(b)));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @notice Replaces an element at some hidden index "i" and returns a new modified list.
|
|
81
|
-
* @param a EList handle to modify element in.
|
|
82
|
-
* @param i Hidden index position of an element to modify.
|
|
83
|
-
* @param b Element value to be changed if the index is within range. Will return the original list if the index is out of range. Must match the elist's inner type of type ETypes.Bool
|
|
84
|
-
* @return ret A new elist handle
|
|
85
|
-
*/
|
|
86
|
-
function set(elist a, euint256 i, ebool b) internal returns (elist ret) {
|
|
87
|
-
return incoPreview.listSet(a, euint256.unwrap(e.s(i)), ebool.unwrap(e.s(b)));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* @notice Replaces an element at some hidden index "i" and returns a new modified list.
|
|
92
|
-
* @param a EList handle to modify element in.
|
|
93
|
-
* @param i Hidden index position of an element to modify.
|
|
94
|
-
* @param b Element value to be changed if the index is within range. Will return the original list if the index is out of range. Must match the elist's inner type of type ETypes.Uint256
|
|
95
|
-
* @return ret A new elist handle
|
|
96
|
-
*/
|
|
97
|
-
function set(elist a, euint256 i, euint256 b) internal returns (elist ret) {
|
|
98
|
-
return incoPreview.listSet(a, euint256.unwrap(e.s(i)), euint256.unwrap(e.s(b)));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @notice Replaces an element at index "i" and returns a new modified list.
|
|
103
|
-
* @param a EList handle to modify element in.
|
|
104
|
-
* @param i Index position of element to modify.
|
|
105
|
-
* @param b Element value to be changed if the index is within range. Will revert if the index is out of range. Must match the elist's inner type of type ETypes.Bool
|
|
106
|
-
* @return ret A new elist handle
|
|
107
|
-
*/
|
|
108
|
-
function set(elist a, uint16 i, ebool b) internal returns (elist ret) {
|
|
109
|
-
require(i < length(a), IndexOutOfRange(i, length(a)));
|
|
110
|
-
return incoPreview.listSet(a, euint256.unwrap(e.asEuint256(uint256(i))), ebool.unwrap(e.s(b)));
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* @notice Replaces an element at index "i" and returns a new modified list.
|
|
114
|
-
* @param a EList handle to modify element in.
|
|
115
|
-
* @param i Index position of element to modify.
|
|
116
|
-
* @param b Element value to be changed if the index is within range. Will revert if the index is out of range. Must match the elist's inner type of type ETypes.Bool
|
|
117
|
-
* @return ret A new elist handle
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
function set(elist a, uint16 i, euint256 b) internal returns (elist ret) {
|
|
121
|
-
require(i < length(a), IndexOutOfRange(i, length(a)));
|
|
122
|
-
return incoPreview.listSet(a, euint256.unwrap(e.asEuint256(uint256(i))), euint256.unwrap(e.s(b)));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @notice Return hidden element at some hidden position. Returns a handle to the hidden element if the index is within range, otherwise returns the default value.
|
|
127
|
-
* @param a EList handle to get element from.
|
|
128
|
-
* @param i Hidden index position to get element at.
|
|
129
|
-
* @param defaultValue A default element value to be returned if index is out of range. Must match the elist's inner type of type ETypes.Bool.
|
|
130
|
-
* @return ret A new handle for the element or the defaultValue
|
|
131
|
-
*/
|
|
132
|
-
function getOr(elist a, euint256 i, ebool defaultValue) internal returns (ebool ret) {
|
|
133
|
-
return ebool.wrap(incoPreview.listGetOr(a, euint256.unwrap(e.s(i)), ebool.unwrap(e.s(defaultValue))));
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* @notice Return hidden element at some hidden position. Returns a handle to the hidden element if the index is within range, otherwise returns the default value.
|
|
137
|
-
* @param a EList handle to get element from.
|
|
138
|
-
* @param i Hidden index position to get element at.
|
|
139
|
-
* @param defaultValue A default element value to be returned if index is out of range. Must match the elist's inner type of type ETypes.Uint256.
|
|
140
|
-
* @return ret A new handle for the element or the defaultValue
|
|
141
|
-
*/
|
|
142
|
-
|
|
143
|
-
function getOr(elist a, euint256 i, euint256 defaultValue) internal returns (euint256 ret) {
|
|
144
|
-
return euint256.wrap(incoPreview.listGetOr(a, euint256.unwrap(e.s(i)), euint256.unwrap(e.s(defaultValue))));
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* @notice Return hidden element at a known position. Returns a handle to the hidden ETypes.Bool element if the index is within range, otherwise reverts.
|
|
148
|
-
* @param a EList handle to get element from.
|
|
149
|
-
* @param i Index position to get element at.
|
|
150
|
-
* @return ret Returns a handle for the element of type ETypes.Bool.
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
|
-
function getEbool(elist a, uint16 i) internal returns (ebool ret) {
|
|
154
|
-
return ebool.wrap(incoPreview.listGet(a, i));
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* @notice Return hidden element at a known position. Returns a handle to the hidden ETypes.Uint256 element if the index is within range, otherwise reverts.
|
|
158
|
-
* @param a EList handle to get element from.
|
|
159
|
-
* @param i Index position to get element at.
|
|
160
|
-
* @return ret Returns a handle for the element of type ETypes.Uint256.
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
function getEuint256(elist a, uint16 i) internal returns (euint256 ret) {
|
|
164
|
-
return euint256.wrap(incoPreview.listGet(a, i));
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* @notice Inserts a hidden element at a desired hidden position, returns a new modified list.
|
|
169
|
-
* @param a An elist handle to insert into.
|
|
170
|
-
* @param i Hidden index position to insert at. If the index is out of range, the element will be appended to the end of the list.
|
|
171
|
-
* @param b Element value to be inserted to the list. Must match the elist's inner type of type ETypes.Bool.
|
|
172
|
-
* @return ret A new elist handle. The new list will have a length of len(a)+1.
|
|
173
|
-
*/
|
|
174
|
-
function insert(elist a, euint256 i, ebool b) internal returns (elist ret) {
|
|
175
|
-
return incoPreview.listInsert(a, euint256.unwrap(e.s(i)), ebool.unwrap(e.s(b)));
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* @notice Inserts a hidden element at a desired position, returns a new modified list.
|
|
179
|
-
* @param a An elist handle to insert into.
|
|
180
|
-
* @param i Index position to insert at. If the index is out of range, it will revert.
|
|
181
|
-
* @param b Element value to be inserted to the list. Must match the elist's inner type of type ETypes.Bool.
|
|
182
|
-
* @return ret A new elist handle. The new list will have a length of len(a)+1.
|
|
183
|
-
*/
|
|
184
|
-
|
|
185
|
-
function insert(elist a, uint16 i, ebool b) internal returns (elist ret) {
|
|
186
|
-
require(i < length(a), IndexOutOfRange(i, length(a)));
|
|
187
|
-
return incoPreview.listInsert(a, euint256.unwrap(e.asEuint256(uint256(i))), ebool.unwrap(e.s(b)));
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* @notice Inserts a hidden element at a desired hidden position, returns a new modified list.
|
|
191
|
-
* @param a An elist handle to insert into.
|
|
192
|
-
* @param i Hidden index position to insert at. If the index is out of range, the element will be appended to the end of the list.
|
|
193
|
-
* @param b Element value to be inserted to the list. Must match the elist's inner type of type ETypes.Uint256.
|
|
194
|
-
* @return ret A new elist handle. The new list will have a length of len(a)+1.
|
|
195
|
-
*/
|
|
196
|
-
|
|
197
|
-
function insert(elist a, euint256 i, euint256 b) internal returns (elist ret) {
|
|
198
|
-
return incoPreview.listInsert(a, euint256.unwrap(e.s(i)), euint256.unwrap(e.s(b)));
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* @notice Inserts a hidden element at a desired position, returns a new modified list.
|
|
202
|
-
* @param a An elist handle to insert into.
|
|
203
|
-
* @param i Index position to insert at. If the index is out of range, it will revert.
|
|
204
|
-
* @param b Element value to be inserted to the list. Must match the elist's inner type of type ETypes.Uint256.
|
|
205
|
-
* @return ret A new elist handle. The new list will have a length of len(a)+1.
|
|
206
|
-
*/
|
|
207
|
-
|
|
208
|
-
function insert(elist a, uint16 i, euint256 b) internal returns (elist ret) {
|
|
209
|
-
require(i < length(a), IndexOutOfRange(i, length(a)));
|
|
210
|
-
return incoPreview.listInsert(a, euint256.unwrap(e.asEuint256(uint256(i))), euint256.unwrap(e.s(b)));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* @notice Concatenates two elists into one, returns a new concatenated elist. Both lists must have the same inner type. The length of the new list will be length(list1)+length(list2)
|
|
215
|
-
* @param a EList handle to be prepended
|
|
216
|
-
* @param b EList handle to be appended
|
|
217
|
-
* @return ret A new elist handle containing elements from both A and B with length of len(list1)+len(list2).
|
|
218
|
-
*/
|
|
219
|
-
function concat(elist a, elist b) internal returns (elist ret) {
|
|
220
|
-
return incoPreview.listConcat(a, b);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* @notice Takes in start and end positions both in plaintext. Returns a new sliced list of length “end-start”. If start or end are out of bounds, it will revert. The end index must be greater or equal the start index.
|
|
225
|
-
* @param a EList handle to be sliced
|
|
226
|
-
* @param start Starting index of the slice, in plaintext. Start is inclusive, meaning if start is 0, the first element will be included in the new slice.
|
|
227
|
-
* @param end End index of the slice, in plaintext. End is exclusive and must be greater or equal start and within the bounds of the list length.
|
|
228
|
-
* @return ret A new sliced list with a new length of “end-start”.
|
|
229
|
-
*/
|
|
230
|
-
function slice(elist a, uint16 start, uint16 end) internal returns (elist ret) {
|
|
231
|
-
require(end >= start, InvalidRange(start, end));
|
|
232
|
-
require(end <= length(a), SliceOutOfRange(start, end, length(a)));
|
|
233
|
-
require(start < length(a), SliceOutOfRange(start, end, length(a)));
|
|
234
|
-
bytes32 defaultValue;
|
|
235
|
-
if (ETypes.Uint256 == listTypeOf(a)) {
|
|
236
|
-
defaultValue = euint256.unwrap(e.asEuint256(0));
|
|
237
|
-
} else if (ETypes.Bool == listTypeOf(a)) {
|
|
238
|
-
defaultValue = ebool.unwrap(e.asEbool(false));
|
|
239
|
-
} else {
|
|
240
|
-
revert UnsupportedListType(listTypeOf(a));
|
|
241
|
-
}
|
|
242
|
-
return incoPreview.listSlice(a, euint256.unwrap(e.asEuint256(start)), end - start, defaultValue);
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* @notice sliceLen() is a variant of slice() but allows to slice at some hidden index specifying a length instead of end position. Returns a new sliced list of length of “len”.
|
|
246
|
-
* @param a EList handle to be sliced, must be of type ETypes.Uint256.
|
|
247
|
-
* @param start Hidden starting index of the slice. Start is inclusive, meaning if start is 0, the first element will be included in the new slice. If start is out of bounds, all elements in the returned slice will be the default element.
|
|
248
|
-
* @param len Length of the desired slice. If the length is out of bounds, remaining elements will be filled with the provided default value.
|
|
249
|
-
* @param defaultValue Default value to fill the remaining elements of the slice if out of range.
|
|
250
|
-
* @return ret a new sliced list with a new length of "len".
|
|
251
|
-
*/
|
|
252
|
-
|
|
253
|
-
function sliceLen(elist a, euint256 start, uint16 len, euint256 defaultValue) internal returns (elist ret) {
|
|
254
|
-
return incoPreview.listSlice(a, euint256.unwrap(e.s(start)), len, euint256.unwrap(e.s(defaultValue)));
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* @notice sliceLen() is a variant of slice() but allows to slice at some hidden index specifying a length instead of end position. Returns a new sliced list of length of “len”.
|
|
258
|
-
* @param a EList handle to be sliced. List type must be of type ETypes.EBool.
|
|
259
|
-
* @param start Hidden starting index of the slice. Start is inclusive, meaning if start is 0, the first element will be included in the new slice.
|
|
260
|
-
* @param len Length of the desired slice. If the length is out of bounds, remaining elements will be filled with the provided default value.
|
|
261
|
-
* @param defaultValue Default value to fill the remaining elements of the slice if out of range.
|
|
262
|
-
* @return ret a new sliced list with a new length of "len".
|
|
263
|
-
*/
|
|
264
|
-
|
|
265
|
-
function sliceLen(elist a, euint256 start, uint16 len, ebool defaultValue) internal returns (elist ret) {
|
|
266
|
-
return incoPreview.listSlice(a, euint256.unwrap(e.s(start)), len, ebool.unwrap(e.s(defaultValue)));
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* @notice Creates a new list (or a “set”) and populates it with ordered values from within range. The length of the new list will be equal to “end-start”.
|
|
271
|
-
* @param start Start value of the range, inclusive.
|
|
272
|
-
* @param end End of the range, exclusive. Must be greater or equal start.
|
|
273
|
-
* @return ret A new elist handle containing a range of unique elements with the length of “end-start”
|
|
274
|
-
*/
|
|
275
|
-
function range(uint16 start, uint16 end) internal returns (elist ret) {
|
|
276
|
-
return incoPreview.listRange(start, end);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* @notice Deterministically shuffles elements within a list, returning a new shuffled list with the same length.
|
|
281
|
-
* @param a elist handle to be shuffled
|
|
282
|
-
* @return ret A new elist handle with elements shuffled where each element is equally likely to be in any position in the new list.
|
|
283
|
-
*/
|
|
284
|
-
function shuffle(elist a) internal returns (elist ret) {
|
|
285
|
-
return incoPreview.listShuffle{value: inco.getFee()}(a);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* @notice A convenience function equivalent to range() followed by shuffle(). It returns an elist containing the elements from start to end in a random order.
|
|
290
|
-
* @param start Start value of the range, inclusive.
|
|
291
|
-
* @param end End of the range, exclusive. Must be greater or equal start.
|
|
292
|
-
* @return ret A new elist handle containing a range of unique elements with the length of “end-start” in a random order.
|
|
293
|
-
*/
|
|
294
|
-
function shuffledRange(uint16 start, uint16 end) internal returns (elist ret) {
|
|
295
|
-
return incoPreview.listShuffle{value: inco.getFee()}(incoPreview.listRange(start, end));
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* @notice Reverses the order of elements in a list, first element becomes last, and so on.
|
|
300
|
-
* @param a Elist handle to be reversed
|
|
301
|
-
* @return ret A new elist handle with elements in reverse order
|
|
302
|
-
*/
|
|
303
|
-
function reverse(elist a) internal returns (elist ret) {
|
|
304
|
-
return incoPreview.listReverse(a);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* @notice Returns the length of the list in plaintext. It’s a pure function that doesn’t require any gas to call.
|
|
309
|
-
* @param a EList handle to read the length from
|
|
310
|
-
* @return len The length of the list in plaintext
|
|
311
|
-
*/
|
|
312
|
-
function length(elist a) internal pure returns (uint16 len) {
|
|
313
|
-
return incoPreview.lengthOf(elist.unwrap(a));
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {IncoLightningPreview} from "./IncoLightningPreview.sol";
|
|
5
|
-
import {IIncoLightningPreview} from "./IIncoLightningPreview.sol";
|
|
6
|
-
import {DeployUtils} from "@inco/lightning/src/DeployUtils.sol";
|
|
7
|
-
import {IncoLightning} from "@inco/lightning/src/IncoLightning.sol";
|
|
8
|
-
import {IIncoLightning} from "@inco/lightning/src/interfaces/IIncoLightning.sol";
|
|
9
|
-
import {IIncoVerifier} from "@inco/lightning/src/interfaces/IIncoVerifier.sol";
|
|
10
|
-
import {IQuoteVerifier} from "@inco/lightning/src/interfaces/automata-interfaces/IQuoteVerifier.sol";
|
|
11
|
-
import {console} from "forge-std/console.sol";
|
|
12
|
-
|
|
13
|
-
/// @title PreviewDeployUtils
|
|
14
|
-
/// @notice Deployment utilities for IncoLightningPreview and its dependencies
|
|
15
|
-
/// @dev Extends DeployUtils to add preview-specific deployment functions.
|
|
16
|
-
/// Uses CreateX for deterministic cross-chain deployments with computed addresses.
|
|
17
|
-
///
|
|
18
|
-
/// Deployment order:
|
|
19
|
-
/// 1. Deploy IncoLightning implementation (base contract)
|
|
20
|
-
/// 2. Deploy IncoLightningPreview implementation (extends base with preview features)
|
|
21
|
-
/// 3. Deploy proxy pointing to preview implementation
|
|
22
|
-
/// 4. Deploy IncoVerifier with reference to the proxy
|
|
23
|
-
contract PreviewDeployUtils is DeployUtils {
|
|
24
|
-
|
|
25
|
-
/// @notice Deploys IncoLightningPreview with all required infrastructure
|
|
26
|
-
/// @dev Creates the implementation contracts and proxy in a single transaction.
|
|
27
|
-
/// The verifier address is computed from salt for use before deployment.
|
|
28
|
-
/// @param lightningSalt Salt for deterministic deployment of lightning contracts
|
|
29
|
-
/// @param verifierSalt Salt for deterministic deployment of the verifier
|
|
30
|
-
/// @param deployer Address that will own the deployed proxy
|
|
31
|
-
/// @return lightningPreview The deployed proxy contract cast to IIncoLightningPreview
|
|
32
|
-
function deployLightningPreview(bytes32 lightningSalt, bytes32 verifierSalt, address deployer)
|
|
33
|
-
internal
|
|
34
|
-
returns (IIncoLightningPreview lightningPreview)
|
|
35
|
-
{
|
|
36
|
-
address verifierAddress = computeAddressFromSalt(verifierSalt);
|
|
37
|
-
IncoLightning lightningImplem = new IncoLightning(lightningSalt, IIncoVerifier(verifierAddress));
|
|
38
|
-
IncoLightningPreview lightningPreviewImplem =
|
|
39
|
-
new IncoLightningPreview(address(lightningImplem), address(lightningImplem.incoVerifier()));
|
|
40
|
-
lightningPreview = IIncoLightningPreview(
|
|
41
|
-
deployProxy({
|
|
42
|
-
salt: lightningSalt,
|
|
43
|
-
implem: address(lightningPreviewImplem),
|
|
44
|
-
initCall: abi.encodeWithSelector(
|
|
45
|
-
IIncoLightning.initialize.selector,
|
|
46
|
-
deployer // owner
|
|
47
|
-
)
|
|
48
|
-
})
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/// @notice Full deployment of IncoLightningPreview using configuration-based salts
|
|
53
|
-
/// @dev Computes salts from deployer and pepper, then deploys both lightning preview
|
|
54
|
-
/// and verifier contracts. Logs the deployment configuration for verification.
|
|
55
|
-
/// @param deployer Address that will own both deployed proxies
|
|
56
|
-
/// @param pepper String used to generate unique deployment salts
|
|
57
|
-
/// @param quoteVerifier The Automata quote verifier for TEE attestation validation
|
|
58
|
-
/// @return lightningPreviewProxy The deployed IncoLightningPreview proxy
|
|
59
|
-
/// @return verifierProxy The deployed IncoVerifier proxy
|
|
60
|
-
function deployIncoLightningPreviewUsingConfig(address deployer, string memory pepper, IQuoteVerifier quoteVerifier)
|
|
61
|
-
internal
|
|
62
|
-
returns (IIncoLightningPreview lightningPreviewProxy, IIncoVerifier verifierProxy)
|
|
63
|
-
{
|
|
64
|
-
(bytes32 lightningSalt, bytes32 verifierSalt) = getIncoSalts(deployer, pepper);
|
|
65
|
-
console.log(
|
|
66
|
-
"Deploying Inco with preview features with deployerAddress: %s, lightning salt: %s",
|
|
67
|
-
vm.toString(deployer),
|
|
68
|
-
vm.toString(lightningSalt)
|
|
69
|
-
);
|
|
70
|
-
lightningPreviewProxy = deployLightningPreview(lightningSalt, verifierSalt, deployer);
|
|
71
|
-
verifierProxy =
|
|
72
|
-
deployVerifier(verifierSalt, IIncoLightning(address(lightningPreviewProxy)), deployer, quoteVerifier);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
}
|
package/src/TypesPreview.sol
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {ETypes} from "@inco/lightning/src/Types.sol";
|
|
5
|
-
|
|
6
|
-
type elist is bytes32;
|
|
7
|
-
|
|
8
|
-
error IndexOutOfRange(uint16 i, uint16 len);
|
|
9
|
-
error SliceOutOfRange(uint16 start, uint16 end, uint16 len);
|
|
10
|
-
error ZeroLength();
|
|
11
|
-
error InvalidRange(uint16 start, uint16 end);
|
|
12
|
-
error ListTypeMismatch(ETypes lhs, ETypes rhs);
|
|
13
|
-
error UnsupportedListType(ETypes listType);
|
|
14
|
-
error UnsupportedType(ETypes actual);
|
|
15
|
-
|
|
16
|
-
function isEList(ETypes t) pure returns (bool) {
|
|
17
|
-
return t == ETypes.List;
|
|
18
|
-
}
|
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {ETypes, EOps, typeToBitMask, isTypeSupported} from "@inco/lightning/src/Types.sol";
|
|
5
|
-
import {IndexOutOfRange} from "../TypesPreview.sol";
|
|
6
|
-
import {AccessControlListStorage} from "@inco/lightning/src/lightning-parts/AccessControl/BaseAccessControlList.sol";
|
|
7
|
-
import {EncryptedOperations} from "@inco/lightning/src/lightning-parts/EncryptedOperations.sol";
|
|
8
|
-
import {EncryptedInput} from "@inco/lightning/src/lightning-parts/EncryptedInput.sol";
|
|
9
|
-
import {EListHandleGeneration} from "./primitives/EListHandleGeneration.sol";
|
|
10
|
-
import {IEList} from "./IEList.sol";
|
|
11
|
-
import {elist, ListTypeMismatch, InvalidRange} from "../TypesPreview.sol";
|
|
12
|
-
|
|
13
|
-
/// @title EList
|
|
14
|
-
/// @notice Provides operations for encrypted lists (elist) - ordered collections of encrypted values.
|
|
15
|
-
/// @dev Encrypted lists are immutable; all operations return new list handles rather than modifying in place.
|
|
16
|
-
/// Lists are homogeneous - all elements must be of the same encrypted type. Operations are processed
|
|
17
|
-
/// by the covalidator off-chain. This is a preview feature and may change in future versions.
|
|
18
|
-
abstract contract EList is
|
|
19
|
-
AccessControlListStorage,
|
|
20
|
-
EListHandleGeneration,
|
|
21
|
-
EncryptedOperations,
|
|
22
|
-
EncryptedInput,
|
|
23
|
-
IEList
|
|
24
|
-
{
|
|
25
|
-
|
|
26
|
-
event NewEList(bytes32 indexed result, ETypes listType, bytes32[] handles, uint256 eventId);
|
|
27
|
-
event EListAppend(elist indexed list, bytes32 indexed value, elist indexed result, uint256 eventId);
|
|
28
|
-
event EListGet(elist indexed list, uint16 indexed index, bytes32 indexed result, uint256 eventId);
|
|
29
|
-
event EListGetOr(
|
|
30
|
-
elist indexed list, bytes32 index, bytes32 indexed defaultValue, bytes32 indexed result, uint256 eventId
|
|
31
|
-
);
|
|
32
|
-
event EListSet(elist list, bytes32 indexed index, bytes32 indexed value, elist indexed result, uint256 eventId);
|
|
33
|
-
event EListInsert(elist list, bytes32 indexed index, bytes32 indexed value, elist indexed result, uint256 eventId);
|
|
34
|
-
event EListConcat(elist indexed list1, elist indexed list2, elist indexed result, uint256 eventId);
|
|
35
|
-
event EListSlice(
|
|
36
|
-
elist list,
|
|
37
|
-
bytes32 indexed start,
|
|
38
|
-
uint16 length,
|
|
39
|
-
bytes32 indexed defaultValue,
|
|
40
|
-
elist indexed result,
|
|
41
|
-
uint256 eventId
|
|
42
|
-
);
|
|
43
|
-
event EListRange(uint256 indexed start, uint256 indexed end, elist indexed result, uint256 eventId);
|
|
44
|
-
event EListShuffle(elist indexed list, uint256 indexed counter, elist indexed result, uint256 eventId);
|
|
45
|
-
event EListReverse(elist indexed list, elist indexed result, uint256 eventId);
|
|
46
|
-
|
|
47
|
-
/// @notice Creates a new encrypted list from client-encrypted inputs.
|
|
48
|
-
/// @dev Internal function that processes multiple encrypted inputs without individual payment.
|
|
49
|
-
/// Payment should be handled by the caller for the batch.
|
|
50
|
-
/// @param inputs Array of encrypted inputs with prepended handles.
|
|
51
|
-
/// @param listType The type of elements in the list.
|
|
52
|
-
/// @param user The user address that encrypted the values.
|
|
53
|
-
/// @return newList The new encrypted list handle.
|
|
54
|
-
function newEListFromInputs(bytes[] calldata inputs, ETypes listType, address user)
|
|
55
|
-
internal
|
|
56
|
-
returns (elist newList)
|
|
57
|
-
{
|
|
58
|
-
require(isTypeSupported(listType), UnsupportedType(listType));
|
|
59
|
-
|
|
60
|
-
// TODO: Add a new event to create new elist from inputs, can be done as an upgrade to optimize for gas and castore.
|
|
61
|
-
bytes32[] memory handles = new bytes32[](inputs.length);
|
|
62
|
-
for (uint256 i = 0; i < inputs.length; i++) {
|
|
63
|
-
// we check payment for multiple inputs ahead of this func
|
|
64
|
-
handles[i] = newInputNotPaying(inputs[i], user, listType);
|
|
65
|
-
}
|
|
66
|
-
return newEListFromHandles(handles, listType);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/// @notice Creates a new encrypted list from existing encrypted handles.
|
|
70
|
-
/// @dev Validates that all handles are of the expected type and caller has access.
|
|
71
|
-
/// @param handles Array of encrypted value handles to include in the list.
|
|
72
|
-
/// @param listType The type of elements in the list (must match handle types).
|
|
73
|
-
/// @return newList The new encrypted list handle.
|
|
74
|
-
function newEListFromHandles(bytes32[] memory handles, ETypes listType) internal returns (elist newList) {
|
|
75
|
-
require(isTypeSupported(listType), UnsupportedType(listType));
|
|
76
|
-
for (uint256 i = 0; i < handles.length; i++) {
|
|
77
|
-
checkInput(handles[i], typeToBitMask(listType));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
bytes32 newHandle = createListInputHandle(handles, listType);
|
|
81
|
-
|
|
82
|
-
allowTransientInternal(newHandle, msg.sender);
|
|
83
|
-
|
|
84
|
-
emit NewEList(newHandle, listType, handles, getNewEventId());
|
|
85
|
-
|
|
86
|
-
return elist.wrap(newHandle);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/// @notice Creates a new encrypted list from existing encrypted handles.
|
|
90
|
-
/// @dev External wrapper for newEListFromHandles.
|
|
91
|
-
/// @param handles Array of encrypted value handles to include in the list.
|
|
92
|
-
/// @param listType The type of elements in the list.
|
|
93
|
-
/// @return newList The new encrypted list handle.
|
|
94
|
-
function newEList(bytes32[] memory handles, ETypes listType) external returns (elist newList) {
|
|
95
|
-
return newEListFromHandles(handles, listType);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/// @notice Creates a new encrypted list from client-encrypted inputs.
|
|
99
|
-
/// @dev This is a paid operation. Payment scales with the number of inputs.
|
|
100
|
-
/// @param inputs Array of encrypted inputs with prepended handles.
|
|
101
|
-
/// @param listType The type of elements in the list.
|
|
102
|
-
/// @param user The user address that encrypted the values.
|
|
103
|
-
/// @return newList The new encrypted list handle.
|
|
104
|
-
function newEList(bytes[] calldata inputs, ETypes listType, address user)
|
|
105
|
-
external
|
|
106
|
-
payable
|
|
107
|
-
payingMultiple(inputs.length)
|
|
108
|
-
returns (elist newList)
|
|
109
|
-
{
|
|
110
|
-
return newEListFromInputs(inputs, listType, user);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/// @notice Returns the element type of an encrypted list handle.
|
|
114
|
-
/// @dev Extracts the type from the handle's metadata bytes.
|
|
115
|
-
/// @param handle The list handle to inspect.
|
|
116
|
-
/// @return The ETypes enum value representing the element type.
|
|
117
|
-
function elementTypeOf(bytes32 handle) internal pure returns (ETypes) {
|
|
118
|
-
return ETypes(uint8(uint256(handle) >> 16));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/// @notice Appends an encrypted value to the end of an encrypted list.
|
|
122
|
-
/// @dev Returns a new list with the value appended; original list is unchanged.
|
|
123
|
-
/// @param list The encrypted list to append to.
|
|
124
|
-
/// @param value The encrypted value to append (must match list element type).
|
|
125
|
-
/// @return result A new encrypted list with the value appended.
|
|
126
|
-
function listAppend(elist list, bytes32 value) external returns (elist result) {
|
|
127
|
-
checkInput(elist.unwrap(list), typeToBitMask(ETypes.List));
|
|
128
|
-
checkInput(value, typeToBitMask(listTypeOf(elist.unwrap(list))));
|
|
129
|
-
|
|
130
|
-
result = elist.wrap(
|
|
131
|
-
createListResultHandle(
|
|
132
|
-
EOps.EListAppend,
|
|
133
|
-
listTypeOf(elist.unwrap(list)),
|
|
134
|
-
lengthOf(elist.unwrap(list)) + 1,
|
|
135
|
-
abi.encodePacked(elist.unwrap(list), value)
|
|
136
|
-
)
|
|
137
|
-
);
|
|
138
|
-
allowTransientInternal(elist.unwrap(result), msg.sender);
|
|
139
|
-
emit EListAppend(list, value, result, getNewEventId());
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/// @notice Retrieves an encrypted element at a specific index.
|
|
143
|
-
/// @dev Reverts if the index is out of range. For safe access with a default, use listGetOr.
|
|
144
|
-
/// @param list The encrypted list to access.
|
|
145
|
-
/// @param i The index to retrieve (0-based).
|
|
146
|
-
/// @return result The encrypted element at the specified index.
|
|
147
|
-
function listGet(elist list, uint16 i) external returns (bytes32 result) {
|
|
148
|
-
require(i < lengthOf(elist.unwrap(list)), IndexOutOfRange(i, lengthOf(elist.unwrap(list))));
|
|
149
|
-
checkInput(elist.unwrap(list), typeToBitMask(ETypes.List));
|
|
150
|
-
|
|
151
|
-
result =
|
|
152
|
-
createResultHandle(EOps.EListGet, listTypeOf(elist.unwrap(list)), abi.encodePacked(elist.unwrap(list), i));
|
|
153
|
-
emit EListGet(list, i, result, getNewEventId());
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/// @notice Retrieves an encrypted element at an encrypted index, with a default value for out-of-range access.
|
|
157
|
-
/// @dev Returns the default value if the index is out of range. Index must be euint256.
|
|
158
|
-
/// @param list The encrypted list to access.
|
|
159
|
-
/// @param index The encrypted index to retrieve.
|
|
160
|
-
/// @param defaultValue The encrypted value to return if index is out of range.
|
|
161
|
-
/// @return result The encrypted element at the index, or defaultValue if out of range.
|
|
162
|
-
function listGetOr(elist list, bytes32 index, bytes32 defaultValue) external returns (bytes32 result) {
|
|
163
|
-
checkInput(elist.unwrap(list), typeToBitMask(ETypes.List));
|
|
164
|
-
checkInput(defaultValue, typeToBitMask(listTypeOf(elist.unwrap(list))));
|
|
165
|
-
checkInput(index, typeToBitMask(ETypes.Uint256)); //Currently we only support euint256 for index
|
|
166
|
-
|
|
167
|
-
result = createResultHandle(
|
|
168
|
-
EOps.EListGetOr, listTypeOf(elist.unwrap(list)), abi.encodePacked(elist.unwrap(list), index, defaultValue)
|
|
169
|
-
);
|
|
170
|
-
emit EListGetOr(list, index, defaultValue, result, getNewEventId());
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/// @notice Sets an encrypted element at an encrypted index.
|
|
174
|
-
/// @dev Returns a new list with the element replaced; original list is unchanged.
|
|
175
|
-
/// Index must be euint256. Out-of-range behavior is handled by the covalidator.
|
|
176
|
-
/// @param list The encrypted list to modify.
|
|
177
|
-
/// @param index The encrypted index to set.
|
|
178
|
-
/// @param value The new encrypted value (must match list element type).
|
|
179
|
-
/// @return result A new encrypted list with the element replaced.
|
|
180
|
-
function listSet(elist list, bytes32 index, bytes32 value) external returns (elist result) {
|
|
181
|
-
checkInput(elist.unwrap(list), typeToBitMask(ETypes.List));
|
|
182
|
-
checkInput(index, typeToBitMask(ETypes.Uint256)); //Currently we only support euint256 for index
|
|
183
|
-
checkInput(value, typeToBitMask(listTypeOf(elist.unwrap(list))));
|
|
184
|
-
|
|
185
|
-
result = elist.wrap(
|
|
186
|
-
createListResultHandle(
|
|
187
|
-
EOps.EListSet,
|
|
188
|
-
listTypeOf(elist.unwrap(list)),
|
|
189
|
-
lengthOf(elist.unwrap(list)),
|
|
190
|
-
abi.encodePacked(elist.unwrap(list), index, value)
|
|
191
|
-
)
|
|
192
|
-
);
|
|
193
|
-
allowTransientInternal(elist.unwrap(result), msg.sender);
|
|
194
|
-
emit EListSet(list, index, value, result, getNewEventId());
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/// @notice Inserts an encrypted element at an encrypted index, shifting subsequent elements.
|
|
198
|
-
/// @dev Returns a new list with one additional element. Index must be euint256.
|
|
199
|
-
/// @param list The encrypted list to modify.
|
|
200
|
-
/// @param index The encrypted index at which to insert.
|
|
201
|
-
/// @param value The encrypted value to insert (must match list element type).
|
|
202
|
-
/// @return result A new encrypted list with the element inserted.
|
|
203
|
-
function listInsert(elist list, bytes32 index, bytes32 value) external returns (elist result) {
|
|
204
|
-
checkInput(elist.unwrap(list), typeToBitMask(ETypes.List));
|
|
205
|
-
checkInput(index, typeToBitMask(ETypes.Uint256)); //Currently we only support euint256 for index
|
|
206
|
-
checkInput(value, typeToBitMask(listTypeOf(elist.unwrap(list))));
|
|
207
|
-
|
|
208
|
-
result = elist.wrap(
|
|
209
|
-
createListResultHandle(
|
|
210
|
-
EOps.EListInsert,
|
|
211
|
-
listTypeOf(elist.unwrap(list)),
|
|
212
|
-
lengthOf(elist.unwrap(list)) + 1,
|
|
213
|
-
abi.encodePacked(elist.unwrap(list), index, value)
|
|
214
|
-
)
|
|
215
|
-
);
|
|
216
|
-
allowTransientInternal(elist.unwrap(result), msg.sender);
|
|
217
|
-
emit EListInsert(list, index, value, result, getNewEventId());
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/// @notice Concatenates two encrypted lists into a new list.
|
|
221
|
-
/// @dev Both lists must have the same element type. Returns a new list with all elements.
|
|
222
|
-
/// @param lhs The first encrypted list.
|
|
223
|
-
/// @param rhs The second encrypted list (must have same element type as lhs).
|
|
224
|
-
/// @return result A new encrypted list containing all elements from both lists.
|
|
225
|
-
function listConcat(elist lhs, elist rhs) external returns (elist result) {
|
|
226
|
-
checkInput(elist.unwrap(lhs), typeToBitMask(ETypes.List));
|
|
227
|
-
checkInput(elist.unwrap(rhs), typeToBitMask(ETypes.List));
|
|
228
|
-
ETypes lhsType = listTypeOf(elist.unwrap(lhs));
|
|
229
|
-
ETypes rhsType = listTypeOf(elist.unwrap(rhs));
|
|
230
|
-
require(lhsType == rhsType, ListTypeMismatch(lhsType, rhsType));
|
|
231
|
-
|
|
232
|
-
result = elist.wrap(
|
|
233
|
-
createListResultHandle(
|
|
234
|
-
EOps.EListConcat,
|
|
235
|
-
listTypeOf(elist.unwrap(lhs)),
|
|
236
|
-
lengthOf(elist.unwrap(lhs)) + lengthOf(elist.unwrap(rhs)),
|
|
237
|
-
abi.encodePacked(elist.unwrap(lhs), elist.unwrap(rhs))
|
|
238
|
-
)
|
|
239
|
-
);
|
|
240
|
-
allowTransientInternal(elist.unwrap(result), msg.sender);
|
|
241
|
-
emit EListConcat(lhs, rhs, result, getNewEventId());
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/// @notice Extracts a slice from an encrypted list starting at an encrypted index.
|
|
245
|
-
/// @dev Returns a new list of the specified length. Uses defaultValue for out-of-range positions.
|
|
246
|
-
/// @param list The encrypted list to slice.
|
|
247
|
-
/// @param start The encrypted starting index.
|
|
248
|
-
/// @param len The number of elements to include in the slice.
|
|
249
|
-
/// @param defaultValue The encrypted value to use for out-of-range positions.
|
|
250
|
-
/// @return result A new encrypted list containing the slice.
|
|
251
|
-
function listSlice(elist list, bytes32 start, uint16 len, bytes32 defaultValue) external returns (elist result) {
|
|
252
|
-
checkInput(elist.unwrap(list), typeToBitMask(ETypes.List));
|
|
253
|
-
checkInput(defaultValue, typeToBitMask(listTypeOf(elist.unwrap(list))));
|
|
254
|
-
checkInput(start, typeToBitMask(ETypes.Uint256));
|
|
255
|
-
|
|
256
|
-
result = elist.wrap(
|
|
257
|
-
createListResultHandle(
|
|
258
|
-
EOps.EListSlice,
|
|
259
|
-
listTypeOf(elist.unwrap(list)),
|
|
260
|
-
len,
|
|
261
|
-
abi.encodePacked(elist.unwrap(list), start, defaultValue)
|
|
262
|
-
)
|
|
263
|
-
);
|
|
264
|
-
allowTransientInternal(elist.unwrap(result), msg.sender);
|
|
265
|
-
emit EListSlice(list, start, len, defaultValue, result, getNewEventId());
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/// @notice Creates an encrypted list containing a range of encrypted integers.
|
|
269
|
-
/// @dev Creates a list of euint256 values from start (inclusive) to end (exclusive).
|
|
270
|
-
/// @param start The starting value (inclusive).
|
|
271
|
-
/// @param end The ending value (exclusive). Must be >= start.
|
|
272
|
-
/// @return result A new encrypted list containing the range [start, end).
|
|
273
|
-
function listRange(uint16 start, uint16 end) external returns (elist result) {
|
|
274
|
-
require(start <= end, InvalidRange(start, end));
|
|
275
|
-
|
|
276
|
-
result = elist.wrap(
|
|
277
|
-
createListResultHandle(EOps.EListRange, ETypes.Uint256, end - start, abi.encodePacked(start, end))
|
|
278
|
-
);
|
|
279
|
-
allowTransientInternal(elist.unwrap(result), msg.sender);
|
|
280
|
-
emit EListRange(start, end, result, getNewEventId());
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/// @notice Randomly shuffles the elements of an encrypted list.
|
|
284
|
-
/// @dev This is a paid operation. Returns a new list with elements in random order.
|
|
285
|
-
/// The shuffle is cryptographically secure, computed by the covalidator.
|
|
286
|
-
/// @param list The encrypted list to shuffle.
|
|
287
|
-
/// @return result A new encrypted list with elements in random order.
|
|
288
|
-
function listShuffle(elist list) external payable paying returns (elist result) {
|
|
289
|
-
checkInput(elist.unwrap(list), typeToBitMask(ETypes.List));
|
|
290
|
-
randCounter++;
|
|
291
|
-
result = elist.wrap(
|
|
292
|
-
createListResultHandle(
|
|
293
|
-
EOps.EListShuffle,
|
|
294
|
-
listTypeOf(elist.unwrap(list)),
|
|
295
|
-
lengthOf(elist.unwrap(list)),
|
|
296
|
-
abi.encodePacked(elist.unwrap(list), bytes32(randCounter))
|
|
297
|
-
)
|
|
298
|
-
);
|
|
299
|
-
allowTransientInternal(elist.unwrap(result), msg.sender);
|
|
300
|
-
emit EListShuffle(list, randCounter, result, getNewEventId());
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/// @notice Reverses the order of elements in an encrypted list.
|
|
304
|
-
/// @dev Returns a new list with elements in reverse order; original list is unchanged.
|
|
305
|
-
/// @param list The encrypted list to reverse.
|
|
306
|
-
/// @return result A new encrypted list with elements in reverse order.
|
|
307
|
-
function listReverse(elist list) external returns (elist result) {
|
|
308
|
-
checkInput(elist.unwrap(list), typeToBitMask(ETypes.List));
|
|
309
|
-
|
|
310
|
-
result = elist.wrap(
|
|
311
|
-
createListResultHandle(
|
|
312
|
-
EOps.EListReverse,
|
|
313
|
-
listTypeOf(elist.unwrap(list)),
|
|
314
|
-
lengthOf(elist.unwrap(list)),
|
|
315
|
-
abi.encodePacked(elist.unwrap(list))
|
|
316
|
-
)
|
|
317
|
-
);
|
|
318
|
-
allowTransientInternal(elist.unwrap(result), msg.sender);
|
|
319
|
-
emit EListReverse(list, result, getNewEventId());
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {elist, ETypes} from "../TypesPreview.sol";
|
|
5
|
-
import {IEListHandleMetadata} from "./primitives/interfaces/IEListHandleMetadata.sol";
|
|
6
|
-
|
|
7
|
-
interface IEList is IEListHandleMetadata {
|
|
8
|
-
|
|
9
|
-
function newEList(bytes32[] memory handles, ETypes listType) external returns (elist newList);
|
|
10
|
-
|
|
11
|
-
function newEList(bytes[] calldata inputs, ETypes listType, address user) external payable returns (elist newList);
|
|
12
|
-
|
|
13
|
-
function listAppend(elist list, bytes32 value) external returns (elist result);
|
|
14
|
-
|
|
15
|
-
function listGet(elist list, uint16 i) external returns (bytes32 result);
|
|
16
|
-
|
|
17
|
-
function listGetOr(elist list, bytes32 i, bytes32 defaultValue) external returns (bytes32 result);
|
|
18
|
-
|
|
19
|
-
function listSet(elist list, bytes32 i, bytes32 value) external returns (elist result);
|
|
20
|
-
|
|
21
|
-
function listInsert(elist list, bytes32 i, bytes32 value) external returns (elist result);
|
|
22
|
-
|
|
23
|
-
function listConcat(elist lhs, elist rhs) external returns (elist result);
|
|
24
|
-
|
|
25
|
-
function listSlice(elist list, bytes32 start, uint16 len, bytes32 defaultValue) external returns (elist result);
|
|
26
|
-
|
|
27
|
-
function listRange(uint16 start, uint16 end) external returns (elist result);
|
|
28
|
-
|
|
29
|
-
function listShuffle(elist list) external payable returns (elist result);
|
|
30
|
-
|
|
31
|
-
function listReverse(elist list) external returns (elist result);
|
|
32
|
-
|
|
33
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {ETypes, EOps} from "@inco/lightning/src/Types.sol";
|
|
5
|
-
import {HandleGeneration} from "@inco/lightning/src/lightning-parts/primitives/HandleGeneration.sol";
|
|
6
|
-
import {EListHandleMetadata} from "./EListHandleMetadata.sol";
|
|
7
|
-
|
|
8
|
-
/// @title EListHandleGeneration
|
|
9
|
-
/// @notice Generates deterministic handles for encrypted list operations
|
|
10
|
-
/// @dev Extends the base HandleGeneration with list-specific handle creation.
|
|
11
|
-
/// List handles incorporate additional metadata:
|
|
12
|
-
/// - List length (number of elements)
|
|
13
|
-
/// - Element type (encrypted type of individual elements)
|
|
14
|
-
/// - List marker (ETypes.List to identify as a list)
|
|
15
|
-
///
|
|
16
|
-
/// The handle is derived from:
|
|
17
|
-
/// - The operation type (EOps.NewEList for list creation)
|
|
18
|
-
/// - The packed input handles (for lists created from existing handles)
|
|
19
|
-
contract EListHandleGeneration is HandleGeneration, EListHandleMetadata {
|
|
20
|
-
|
|
21
|
-
/// @notice Creates a handle for a list operation result
|
|
22
|
-
/// @dev Generates a deterministic handle by hashing the operation and inputs,
|
|
23
|
-
/// then embedding list metadata (length, element type, list marker, version).
|
|
24
|
-
/// @param op The operation that produced this list (e.g., NewEList, Slice)
|
|
25
|
-
/// @param listType The encrypted type of individual list elements (euint8, euint64, etc.)
|
|
26
|
-
/// @param len The number of elements in the resulting list
|
|
27
|
-
/// @param packedInputs ABI-packed representation of the input handles
|
|
28
|
-
/// @return result The deterministic handle for this list
|
|
29
|
-
function createListResultHandle(EOps op, ETypes listType, uint16 len, bytes memory packedInputs)
|
|
30
|
-
internal
|
|
31
|
-
pure
|
|
32
|
-
returns (bytes32 result)
|
|
33
|
-
{
|
|
34
|
-
bytes32 baseHandle = keccak256(abi.encodePacked(op, packedInputs));
|
|
35
|
-
baseHandle = embedListLength(baseHandle, len);
|
|
36
|
-
baseHandle = embedListType(baseHandle, listType);
|
|
37
|
-
result = embedTypeVersion(baseHandle, ETypes.List);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/// @notice Creates a handle for a new list composed from individual encrypted handles
|
|
41
|
-
/// @dev This is the primary entry point for creating lists from existing encrypted values.
|
|
42
|
-
/// The handle is deterministically derived from the input handles, ensuring the same
|
|
43
|
-
/// inputs always produce the same list handle.
|
|
44
|
-
/// @param handles Array of encrypted value handles to combine into a list
|
|
45
|
-
/// @param listType The encrypted type of all elements (must be uniform)
|
|
46
|
-
/// @return newHandle The deterministic handle for the new list
|
|
47
|
-
function createListInputHandle(bytes32[] memory handles, ETypes listType)
|
|
48
|
-
internal
|
|
49
|
-
pure
|
|
50
|
-
returns (bytes32 newHandle)
|
|
51
|
-
{
|
|
52
|
-
newHandle = createListResultHandle(
|
|
53
|
-
EOps.NewEList,
|
|
54
|
-
listType,
|
|
55
|
-
uint16(handles.length),
|
|
56
|
-
abi.encodePacked(
|
|
57
|
-
//Since we're only dealing with handles, it should be sufficient to treat this operation as an operand on handles.
|
|
58
|
-
handles
|
|
59
|
-
)
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {ETypes} from "@inco/lightning/src/Types.sol";
|
|
5
|
-
import {IEListHandleMetadata} from "./interfaces/IEListHandleMetadata.sol";
|
|
6
|
-
|
|
7
|
-
/// @title EListHandleMetadata
|
|
8
|
-
/// @notice Utilities for embedding and extracting metadata from encrypted list handles
|
|
9
|
-
/// @dev Encrypted lists have additional metadata compared to scalar handles:
|
|
10
|
-
/// Handle structure (32 bytes / 256 bits):
|
|
11
|
-
/// - Bytes 0-26: Handle-specific data (hash, counters, etc.)
|
|
12
|
-
/// - Bytes 27-28: List length (uint16, max 65535 elements)
|
|
13
|
-
/// - Byte 29: Element type (ETypes enum value for individual elements)
|
|
14
|
-
/// - Byte 30: List type marker (identifies this as a list handle)
|
|
15
|
-
/// - Byte 31: Handle version
|
|
16
|
-
///
|
|
17
|
-
/// This allows efficient extraction of list metadata without external calls.
|
|
18
|
-
contract EListHandleMetadata is IEListHandleMetadata {
|
|
19
|
-
|
|
20
|
-
/// @notice Embeds the list length into a list handle
|
|
21
|
-
/// @dev Sets bytes 27-28 of the handle to the list length.
|
|
22
|
-
/// Clears existing length bits before setting new value.
|
|
23
|
-
/// @param prehandle The 32-byte handle before length embedding
|
|
24
|
-
/// @param len The number of elements in the list (max 65535)
|
|
25
|
-
/// @return result The handle with embedded list length
|
|
26
|
-
function embedListLength(bytes32 prehandle, uint16 len) internal pure returns (bytes32 result) {
|
|
27
|
-
// 27 and 28 bits are used for the list length
|
|
28
|
-
result = prehandle & 0xffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ffffff;
|
|
29
|
-
result = bytes32(uint256(result) | (uint256(len) << 24)); // append length
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/// @notice Extracts the list length from a list handle
|
|
33
|
-
/// @dev Reads bytes 27-28 of the handle as a uint16
|
|
34
|
-
/// @param handle The encrypted list handle to inspect
|
|
35
|
-
/// @return The number of elements in the list
|
|
36
|
-
function lengthOf(bytes32 handle) public pure returns (uint16) {
|
|
37
|
-
return uint16(uint256(handle) >> 24);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/// @notice Embeds the element type into a list handle
|
|
41
|
-
/// @dev Sets byte 29 of the handle to the element type.
|
|
42
|
-
/// This indicates the encrypted type of individual elements (euint8, euint64, etc.).
|
|
43
|
-
/// @param prehandle The 32-byte handle before type embedding
|
|
44
|
-
/// @param listType The encrypted type of list elements
|
|
45
|
-
/// @return result The handle with embedded element type
|
|
46
|
-
function embedListType(bytes32 prehandle, ETypes listType) internal pure returns (bytes32 result) {
|
|
47
|
-
result = prehandle & 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ffff;
|
|
48
|
-
result = bytes32(uint256(result) | (uint256(listType) << 16)); // append element type
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/// @notice Extracts the element type from a list handle
|
|
52
|
-
/// @dev Reads byte 29 of the handle and casts to ETypes enum.
|
|
53
|
-
/// This is the type of individual elements, not the list container type.
|
|
54
|
-
/// @param handle The encrypted list handle to inspect
|
|
55
|
-
/// @return The encrypted type of list elements (euint8, euint64, etc.)
|
|
56
|
-
function listTypeOf(bytes32 handle) internal pure returns (ETypes) {
|
|
57
|
-
return ETypes(uint8(uint256(handle) >> 16));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {PreviewIncoTest} from "../../test/PreviewIncoTest.sol";
|
|
5
|
-
import {ElistTester} from "../../test/EListTester.sol";
|
|
6
|
-
import {incoPreview, ETypes, elist} from "../../Preview.Lib.sol";
|
|
7
|
-
import {FEE, Fee} from "@inco/lightning/src/lightning-parts/Fee.sol";
|
|
8
|
-
import {EList} from "../EList.sol";
|
|
9
|
-
import {VerifierAddressGetter} from "@inco/lightning/src/lightning-parts/primitives/VerifierAddressGetter.sol";
|
|
10
|
-
|
|
11
|
-
contract ElistFeeTester is EList {
|
|
12
|
-
|
|
13
|
-
constructor() VerifierAddressGetter(address(0)) {}
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
contract TestEList is PreviewIncoTest {
|
|
18
|
-
|
|
19
|
-
ElistTester tester;
|
|
20
|
-
ElistFeeTester feeTester;
|
|
21
|
-
|
|
22
|
-
function setUp() public virtual override {
|
|
23
|
-
super.setUp();
|
|
24
|
-
tester = new ElistTester(incoPreview);
|
|
25
|
-
vm.deal(address(tester), 1 ether);
|
|
26
|
-
feeTester = new ElistFeeTester();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function testNewElistFromInputs() public {
|
|
30
|
-
createList();
|
|
31
|
-
// todo test read the created list
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function testListAppend() public {
|
|
35
|
-
createList();
|
|
36
|
-
bytes memory ctValue = fakePrepareEuint256Ciphertext(40, address(this), address(tester));
|
|
37
|
-
tester.listAppend(ctValue);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function createList() internal returns (elist list) {
|
|
41
|
-
bytes[] memory inputs = new bytes[](3);
|
|
42
|
-
inputs[0] = fakePrepareEuint256Ciphertext(10, address(this), address(tester));
|
|
43
|
-
inputs[1] = fakePrepareEuint256Ciphertext(20, address(this), address(tester));
|
|
44
|
-
inputs[2] = fakePrepareEuint256Ciphertext(30, address(this), address(tester));
|
|
45
|
-
list = tester.newEList(inputs, ETypes.Uint256, address(this));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function testRevertsOnBadFeeAmount() public {
|
|
49
|
-
// should fail if no fee
|
|
50
|
-
vm.expectRevert(Fee.FeeNotPaid.selector);
|
|
51
|
-
feeTester.listShuffle(elist.wrap(bytes32(0)));
|
|
52
|
-
|
|
53
|
-
// should fail if not enough fee
|
|
54
|
-
vm.expectRevert(Fee.FeeNotPaid.selector);
|
|
55
|
-
feeTester.listShuffle{value: FEE - 1}(elist.wrap(bytes32(0)));
|
|
56
|
-
|
|
57
|
-
// should fail if too much fee
|
|
58
|
-
vm.expectRevert(Fee.FeeNotPaid.selector);
|
|
59
|
-
feeTester.listShuffle{value: FEE + 1}(elist.wrap(bytes32(0)));
|
|
60
|
-
|
|
61
|
-
vm.expectRevert(Fee.FeeNotPaid.selector);
|
|
62
|
-
bytes[] memory inputs = new bytes[](3);
|
|
63
|
-
feeTester.newEList{value: FEE * 2}(inputs, ETypes.Uint256, address(this));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
package/src/misc/ABIHelper.sol
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {Session} from "@inco/lightning/src/periphery/SessionVerifier.sol";
|
|
5
|
-
|
|
6
|
-
// @dev this contract is not used on-chain, it is only used to generate the
|
|
7
|
-
// ABI of some symbols that are not exposed directly by the IncoLightning or
|
|
8
|
-
// periphery contracts, but are needed for the JS SDK.
|
|
9
|
-
contract ABIHelper {
|
|
10
|
-
|
|
11
|
-
function getSession() public pure returns (Session memory) {
|
|
12
|
-
revert("This function exists only to include Session struct in ABI");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
}
|
package/src/test/EListTester.sol
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {IIncoLightningPreview} from "../IIncoLightningPreview.sol";
|
|
5
|
-
/// forge-lint: disable-next-line(unused-import)
|
|
6
|
-
import {ETypes, elist} from "../TypesPreview.sol";
|
|
7
|
-
import {euint256} from "@inco/lightning/src/Types.sol";
|
|
8
|
-
import {IncoUtils, FEE} from "@inco/lightning/src/periphery/IncoUtils.sol";
|
|
9
|
-
|
|
10
|
-
contract ElistTester is IncoUtils {
|
|
11
|
-
|
|
12
|
-
/// forge-lint: disable-next-line(screaming-snake-case-immutable)
|
|
13
|
-
IIncoLightningPreview immutable inco;
|
|
14
|
-
|
|
15
|
-
constructor(IIncoLightningPreview _inco) {
|
|
16
|
-
inco = _inco;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
elist public list;
|
|
20
|
-
elist public newRangeList;
|
|
21
|
-
|
|
22
|
-
function newEList(bytes[] memory inputs, ETypes listType, address user)
|
|
23
|
-
public
|
|
24
|
-
payable
|
|
25
|
-
refundUnspent
|
|
26
|
-
returns (elist)
|
|
27
|
-
{
|
|
28
|
-
list = inco.newEList{value: FEE * inputs.length}(inputs, listType, user);
|
|
29
|
-
inco.allow(elist.unwrap(list), address(this));
|
|
30
|
-
inco.allow(elist.unwrap(list), address(msg.sender));
|
|
31
|
-
return list;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function listAppend(bytes memory ctValue) public payable refundUnspent returns (elist) {
|
|
35
|
-
euint256 handle = inco.newEuint256{value: FEE}(ctValue, msg.sender);
|
|
36
|
-
inco.allow(euint256.unwrap(handle), address(this));
|
|
37
|
-
inco.allow(euint256.unwrap(handle), address(msg.sender));
|
|
38
|
-
list = inco.listAppend(list, euint256.unwrap(handle));
|
|
39
|
-
inco.allow(elist.unwrap(list), address(this));
|
|
40
|
-
inco.allow(elist.unwrap(list), address(msg.sender));
|
|
41
|
-
return list;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function listGet(uint16 index) public returns (bytes32) {
|
|
45
|
-
bytes32 res = inco.listGet(list, index);
|
|
46
|
-
inco.allow(res, msg.sender);
|
|
47
|
-
return res;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function newEList(bytes32[] memory handles, ETypes listType) public payable refundUnspent returns (elist) {
|
|
51
|
-
list = inco.newEList(handles, listType);
|
|
52
|
-
inco.allow(elist.unwrap(list), address(this));
|
|
53
|
-
inco.allow(elist.unwrap(list), address(msg.sender));
|
|
54
|
-
return list;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function listGetOr(bytes memory ctIndex, bytes memory ctDefaultValue)
|
|
58
|
-
public
|
|
59
|
-
payable
|
|
60
|
-
refundUnspent
|
|
61
|
-
returns (bytes32)
|
|
62
|
-
{
|
|
63
|
-
euint256 index = inco.newEuint256{value: FEE}(ctIndex, msg.sender);
|
|
64
|
-
euint256 defaultValue = inco.newEuint256{value: FEE}(ctDefaultValue, msg.sender);
|
|
65
|
-
bytes32 res = inco.listGetOr(list, euint256.unwrap(index), euint256.unwrap(defaultValue));
|
|
66
|
-
inco.allow(res, msg.sender);
|
|
67
|
-
return res;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function listSet(bytes memory ctIndex, bytes memory ctValue) public payable refundUnspent returns (elist) {
|
|
71
|
-
euint256 index = inco.newEuint256{value: FEE}(ctIndex, msg.sender);
|
|
72
|
-
euint256 value = inco.newEuint256{value: FEE}(ctValue, msg.sender);
|
|
73
|
-
list = inco.listSet(list, euint256.unwrap(index), euint256.unwrap(value));
|
|
74
|
-
inco.allow(elist.unwrap(list), address(this));
|
|
75
|
-
inco.allow(elist.unwrap(list), address(msg.sender));
|
|
76
|
-
return list;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function listInsert(bytes memory ctIndex, bytes memory ctValue) public payable refundUnspent returns (elist) {
|
|
80
|
-
euint256 index = inco.newEuint256{value: FEE}(ctIndex, msg.sender);
|
|
81
|
-
euint256 value = inco.newEuint256{value: FEE}(ctValue, msg.sender);
|
|
82
|
-
list = inco.listInsert(list, euint256.unwrap(index), euint256.unwrap(value));
|
|
83
|
-
inco.allow(elist.unwrap(list), address(this));
|
|
84
|
-
inco.allow(elist.unwrap(list), address(msg.sender));
|
|
85
|
-
return list;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function listConcat(bytes[] memory cts, ETypes listType, address user)
|
|
89
|
-
public
|
|
90
|
-
payable
|
|
91
|
-
refundUnspent
|
|
92
|
-
returns (elist)
|
|
93
|
-
{
|
|
94
|
-
elist rhs = inco.newEList{value: FEE * cts.length}(cts, listType, user);
|
|
95
|
-
inco.allow(elist.unwrap(rhs), address(this));
|
|
96
|
-
inco.allow(elist.unwrap(rhs), address(msg.sender));
|
|
97
|
-
list = inco.listConcat(list, rhs);
|
|
98
|
-
inco.allow(elist.unwrap(list), address(this));
|
|
99
|
-
inco.allow(elist.unwrap(list), address(msg.sender));
|
|
100
|
-
return list;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function listSlice(bytes memory ctStart, uint16 len, bytes memory ctDefaultValue)
|
|
104
|
-
public
|
|
105
|
-
payable
|
|
106
|
-
refundUnspent
|
|
107
|
-
returns (elist)
|
|
108
|
-
{
|
|
109
|
-
euint256 start = inco.newEuint256{value: FEE}(ctStart, msg.sender);
|
|
110
|
-
euint256 defaultValue = inco.newEuint256{value: FEE}(ctDefaultValue, msg.sender);
|
|
111
|
-
list = inco.listSlice(list, euint256.unwrap(start), len, euint256.unwrap(defaultValue));
|
|
112
|
-
inco.allow(elist.unwrap(list), address(this));
|
|
113
|
-
inco.allow(elist.unwrap(list), address(msg.sender));
|
|
114
|
-
return list;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function listRange(uint16 start, uint16 end) public returns (elist) {
|
|
118
|
-
newRangeList = inco.listRange(start, end);
|
|
119
|
-
inco.allow(elist.unwrap(newRangeList), address(this));
|
|
120
|
-
inco.allow(elist.unwrap(newRangeList), address(msg.sender));
|
|
121
|
-
return newRangeList;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function listGetRange(uint16 index) public returns (bytes32) {
|
|
125
|
-
bytes32 res = inco.listGet(newRangeList, index);
|
|
126
|
-
inco.allow(res, msg.sender);
|
|
127
|
-
return res;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function listShuffle() public payable refundUnspent returns (elist) {
|
|
131
|
-
list = inco.listShuffle{value: FEE}(list);
|
|
132
|
-
inco.allow(elist.unwrap(list), address(this));
|
|
133
|
-
inco.allow(elist.unwrap(list), address(msg.sender));
|
|
134
|
-
return list;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function listReverse() public returns (elist) {
|
|
138
|
-
list = inco.listReverse(list);
|
|
139
|
-
inco.allow(elist.unwrap(list), address(this));
|
|
140
|
-
inco.allow(elist.unwrap(list), address(msg.sender));
|
|
141
|
-
return list;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
receive() external payable {
|
|
145
|
-
// Allow contract to receive ETH
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: No License
|
|
2
|
-
pragma solidity ^0.8;
|
|
3
|
-
|
|
4
|
-
import {IncoTest} from "@inco/lightning/src/test/IncoTest.sol";
|
|
5
|
-
import {CONTRACT_NAME, MAJOR_VERSION} from "@inco/lightning/src/version/IncoLightningConfig.sol";
|
|
6
|
-
import {IncoLightningPreview} from "../IncoLightningPreview.sol";
|
|
7
|
-
import {inco} from "@inco/lightning/src/Lib.sol";
|
|
8
|
-
import {console} from "forge-std/console.sol";
|
|
9
|
-
import {IncoLightning} from "@inco/lightning/src/IncoLightning.sol";
|
|
10
|
-
|
|
11
|
-
contract PreviewIncoTest is IncoTest {
|
|
12
|
-
|
|
13
|
-
function setUp() public virtual override {
|
|
14
|
-
super.setUp();
|
|
15
|
-
bytes32 salt = getSalt(CONTRACT_NAME, MAJOR_VERSION, testDeployer, "");
|
|
16
|
-
|
|
17
|
-
IncoLightningPreview newImplem = new IncoLightningPreview(
|
|
18
|
-
// a new inco lightning instance is used a fallback implem for non preview features
|
|
19
|
-
address(new IncoLightning(salt, inco.incoVerifier())),
|
|
20
|
-
address(inco.incoVerifier())
|
|
21
|
-
);
|
|
22
|
-
vm.prank(owner);
|
|
23
|
-
inco.upgradeToAndCall(address(newImplem), "");
|
|
24
|
-
console.log("inco address is %s", vm.toString(address(inco)));
|
|
25
|
-
vm.getRecordedLogs(); // clear the upgrade log
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function testExample() public pure {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|