@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
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
AllowanceProof,
|
|
6
|
-
AllowanceVoucher
|
|
7
|
-
} from "../AdvancedAccessControl.types.sol";
|
|
4
|
+
import {AllowanceProof, AllowanceVoucher} from "../AdvancedAccessControl.types.sol";
|
|
8
5
|
|
|
9
6
|
interface IVoucherEip712Checker {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
|
|
8
|
+
function allowanceVoucherDigest(AllowanceVoucher memory voucher) external view returns (bytes32);
|
|
9
|
+
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
interface IAdvancedAccessControl is IVoucherEip712Checker {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
AllowanceProof memory proof
|
|
20
|
-
) external returns (bool);
|
|
21
|
-
function getActiveVouchersSessionNonce(
|
|
22
|
-
address account
|
|
23
|
-
) external view returns (bytes32);
|
|
13
|
+
|
|
14
|
+
function isAllowedWithProof(bytes32 handle, address account, AllowanceProof memory proof) external returns (bool);
|
|
15
|
+
function getActiveVouchersSessionNonce(address account) external view returns (bytes32);
|
|
24
16
|
function updateActiveVouchersSessionNonce() external;
|
|
17
|
+
|
|
25
18
|
}
|
|
@@ -5,20 +5,13 @@ import {IVerifierAddressGetter} from "../../primitives/interfaces/IVerifierAddre
|
|
|
5
5
|
import {AllowanceProof} from "../AdvancedAccessControl.types.sol";
|
|
6
6
|
|
|
7
7
|
interface IBaseAccessControlList is IVerifierAddressGetter {
|
|
8
|
+
|
|
8
9
|
function allow(bytes32 handle, address account) external;
|
|
9
10
|
function allowTransient(bytes32 handle, address account) external;
|
|
10
|
-
function allowedTransient(
|
|
11
|
-
bytes32 handle,
|
|
12
|
-
address account
|
|
13
|
-
) external view returns (bool);
|
|
11
|
+
function allowedTransient(bytes32 handle, address account) external view returns (bool);
|
|
14
12
|
function cleanTransientStorage() external;
|
|
15
|
-
function persistAllowed(
|
|
16
|
-
|
|
17
|
-
address account
|
|
18
|
-
) external view returns (bool);
|
|
19
|
-
function isAllowed(
|
|
20
|
-
bytes32 handle,
|
|
21
|
-
address account
|
|
22
|
-
) external view returns (bool);
|
|
13
|
+
function persistAllowed(bytes32 handle, address account) external view returns (bool);
|
|
14
|
+
function isAllowed(bytes32 handle, address account) external view returns (bool);
|
|
23
15
|
function claimHandle(bytes32 handle, AllowanceProof memory proof) external;
|
|
16
|
+
|
|
24
17
|
}
|
|
@@ -11,6 +11,7 @@ import {ALLOWANCE_GRANTED_MAGIC_VALUE} from "../../../Types.sol";
|
|
|
11
11
|
import {IIncoVerifier} from "../../../interfaces/IIncoVerifier.sol";
|
|
12
12
|
|
|
13
13
|
contract SomeContractWithConfidentialData {
|
|
14
|
+
|
|
14
15
|
using e for bytes;
|
|
15
16
|
using e for euint256;
|
|
16
17
|
|
|
@@ -20,9 +21,11 @@ contract SomeContractWithConfidentialData {
|
|
|
20
21
|
secret = ciphertext.newEuint256(msg.sender);
|
|
21
22
|
secret.allow(msg.sender);
|
|
22
23
|
}
|
|
24
|
+
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
contract SomeVerifier {
|
|
28
|
+
|
|
26
29
|
struct SharerArg {
|
|
27
30
|
bytes32 handleShared;
|
|
28
31
|
address allowedAccount;
|
|
@@ -32,40 +35,39 @@ contract SomeVerifier {
|
|
|
32
35
|
bytes2 mustBeBeef;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
function someCheck(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
) public pure returns (bytes32) {
|
|
38
|
+
function someCheck(bytes32 handle, address account, bytes memory sharerArgData, bytes memory requesterArgData)
|
|
39
|
+
public
|
|
40
|
+
pure
|
|
41
|
+
returns (bytes32)
|
|
42
|
+
{
|
|
41
43
|
SharerArg memory sharerArg = abi.decode(sharerArgData, (SharerArg));
|
|
42
|
-
RequesterArg memory requesterArg = abi.decode(
|
|
43
|
-
requesterArgData,
|
|
44
|
-
(RequesterArg)
|
|
45
|
-
);
|
|
44
|
+
RequesterArg memory requesterArg = abi.decode(requesterArgData, (RequesterArg));
|
|
46
45
|
if (
|
|
47
|
-
requesterArg.mustBeBeef == bytes2(0xbeef) &&
|
|
48
|
-
|
|
49
|
-
sharerArg.allowedAccount == account
|
|
46
|
+
requesterArg.mustBeBeef == bytes2(0xbeef) && sharerArg.handleShared == handle
|
|
47
|
+
&& sharerArg.allowedAccount == account
|
|
50
48
|
) {
|
|
51
49
|
return ALLOWANCE_GRANTED_MAGIC_VALUE;
|
|
52
50
|
}
|
|
53
51
|
return bytes32(0);
|
|
54
52
|
}
|
|
53
|
+
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
contract DoesNotVerifyAnything {
|
|
57
|
+
|
|
58
58
|
function someCheck(
|
|
59
|
-
bytes32 /* handle
|
|
60
|
-
address /* account
|
|
61
|
-
bytes memory /* sharerArgData
|
|
59
|
+
bytes32, /* handle */
|
|
60
|
+
address, /* account */
|
|
61
|
+
bytes memory, /* sharerArgData */
|
|
62
62
|
bytes memory /* requesterArgData */
|
|
63
63
|
) public pure returns (bytes32) {
|
|
64
64
|
return ALLOWANCE_GRANTED_MAGIC_VALUE;
|
|
65
65
|
}
|
|
66
|
+
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
contract TestAdvancedAccessControl is IncoTest {
|
|
70
|
+
|
|
69
71
|
SomeContractWithConfidentialData someContract;
|
|
70
72
|
bytes32 secretHandle;
|
|
71
73
|
IIncoVerifier incoVerifier;
|
|
@@ -83,35 +85,21 @@ contract TestAdvancedAccessControl is IncoTest {
|
|
|
83
85
|
|
|
84
86
|
function testAdvancedSharingWithSession() public {
|
|
85
87
|
SessionVerifier sessionVerifier = new SessionVerifier("");
|
|
86
|
-
assertFalse(
|
|
87
|
-
|
|
88
|
-
"bob should't be allowed on secret yet"
|
|
89
|
-
);
|
|
90
|
-
assertTrue(
|
|
91
|
-
inco.isAllowed(secretHandle, alice),
|
|
92
|
-
"alice should be allowed on secret"
|
|
93
|
-
);
|
|
88
|
+
assertFalse(inco.isAllowed(secretHandle, bob), "bob should't be allowed on secret yet");
|
|
89
|
+
assertTrue(inco.isAllowed(secretHandle, alice), "alice should be allowed on secret");
|
|
94
90
|
AllowanceVoucher memory aliceSessionVoucherForBob = AllowanceVoucher({
|
|
95
91
|
sessionNonce: bytes32(0),
|
|
96
92
|
verifyingContract: address(sessionVerifier),
|
|
97
93
|
callFunction: SessionVerifier.canUseSession.selector,
|
|
98
|
-
sharerArgData: abi.encode(
|
|
99
|
-
Session({decrypter: bob, expiresAt: block.timestamp + 1 days})
|
|
100
|
-
)
|
|
94
|
+
sharerArgData: abi.encode(Session({decrypter: bob, expiresAt: block.timestamp + 1 days}))
|
|
101
95
|
});
|
|
102
|
-
AllowanceProof memory bobsProof = getBobsProof(
|
|
103
|
-
aliceSessionVoucherForBob
|
|
104
|
-
);
|
|
96
|
+
AllowanceProof memory bobsProof = getBobsProof(aliceSessionVoucherForBob);
|
|
105
97
|
assertTrue(
|
|
106
|
-
incoVerifier.isAllowedWithProof(secretHandle, bob, bobsProof),
|
|
107
|
-
"bob should be allowed on secret with proof"
|
|
98
|
+
incoVerifier.isAllowedWithProof(secretHandle, bob, bobsProof), "bob should be allowed on secret with proof"
|
|
108
99
|
);
|
|
109
100
|
vm.prank(bob);
|
|
110
101
|
inco.claimHandle(secretHandle, bobsProof);
|
|
111
|
-
assertTrue(
|
|
112
|
-
inco.persistAllowed(secretHandle, bob),
|
|
113
|
-
"bob should have claimed persistent allowance on secret"
|
|
114
|
-
);
|
|
102
|
+
assertTrue(inco.persistAllowed(secretHandle, bob), "bob should have claimed persistent allowance on secret");
|
|
115
103
|
}
|
|
116
104
|
|
|
117
105
|
function testVoucherSessionIdCheck() public {
|
|
@@ -137,24 +125,16 @@ contract TestAdvancedAccessControl is IncoTest {
|
|
|
137
125
|
AllowanceProof memory invalidBobProof = getBobsProof(voucher);
|
|
138
126
|
// the session nonce should be checked by inco
|
|
139
127
|
vm.expectRevert(
|
|
140
|
-
abi.encodeWithSelector(
|
|
141
|
-
AdvancedAccessControl.InvalidVoucherSessionNonce.selector,
|
|
142
|
-
madeUpNonce,
|
|
143
|
-
bytes32(0)
|
|
144
|
-
)
|
|
128
|
+
abi.encodeWithSelector(AdvancedAccessControl.InvalidVoucherSessionNonce.selector, madeUpNonce, bytes32(0))
|
|
145
129
|
);
|
|
146
130
|
incoVerifier.isAllowedWithProof(secretHandle, bob, invalidBobProof);
|
|
147
131
|
vm.prank(alice);
|
|
148
132
|
incoVerifier.updateActiveVouchersSessionNonce();
|
|
149
|
-
bytes32 alicesNewNonce = incoVerifier.getActiveVouchersSessionNonce(
|
|
150
|
-
alice
|
|
151
|
-
);
|
|
133
|
+
bytes32 alicesNewNonce = incoVerifier.getActiveVouchersSessionNonce(alice);
|
|
152
134
|
// previously valid voucher should now be invalid
|
|
153
135
|
vm.expectRevert(
|
|
154
136
|
abi.encodeWithSelector(
|
|
155
|
-
AdvancedAccessControl.InvalidVoucherSessionNonce.selector,
|
|
156
|
-
bytes32(0),
|
|
157
|
-
alicesNewNonce
|
|
137
|
+
AdvancedAccessControl.InvalidVoucherSessionNonce.selector, bytes32(0), alicesNewNonce
|
|
158
138
|
)
|
|
159
139
|
);
|
|
160
140
|
incoVerifier.isAllowedWithProof(secretHandle, bob, bobsFirstProof);
|
|
@@ -177,59 +157,38 @@ contract TestAdvancedAccessControl is IncoTest {
|
|
|
177
157
|
sessionNonce: bytes32(0),
|
|
178
158
|
verifyingContract: address(verifier),
|
|
179
159
|
callFunction: verifier.someCheck.selector,
|
|
180
|
-
sharerArgData: abi.encode(
|
|
181
|
-
SomeVerifier.SharerArg({
|
|
182
|
-
handleShared: secretHandle,
|
|
183
|
-
allowedAccount: bob
|
|
184
|
-
})
|
|
185
|
-
)
|
|
160
|
+
sharerArgData: abi.encode(SomeVerifier.SharerArg({handleShared: secretHandle, allowedAccount: bob}))
|
|
186
161
|
});
|
|
187
162
|
AllowanceProof memory bobsProof = AllowanceProof({
|
|
188
163
|
sharer: alice,
|
|
189
164
|
voucher: voucher,
|
|
190
165
|
voucherSignature: getAliceSig(voucher),
|
|
191
|
-
requesterArgData: abi.encode(
|
|
192
|
-
SomeVerifier.RequesterArg({mustBeBeef: bytes2(0xbeef)})
|
|
193
|
-
)
|
|
166
|
+
requesterArgData: abi.encode(SomeVerifier.RequesterArg({mustBeBeef: bytes2(0xbeef)}))
|
|
194
167
|
});
|
|
195
168
|
assertTrue(
|
|
196
|
-
incoVerifier.isAllowedWithProof(secretHandle, bob, bobsProof),
|
|
197
|
-
"bob should be allowed on secret with proof"
|
|
169
|
+
incoVerifier.isAllowedWithProof(secretHandle, bob, bobsProof), "bob should be allowed on secret with proof"
|
|
198
170
|
);
|
|
199
171
|
bobsProof = AllowanceProof({
|
|
200
172
|
sharer: alice,
|
|
201
173
|
voucher: voucher,
|
|
202
174
|
voucherSignature: getAliceSig(voucher),
|
|
203
|
-
requesterArgData: abi.encode(
|
|
204
|
-
SomeVerifier.RequesterArg({mustBeBeef: bytes2(0xbebe)})
|
|
205
|
-
)
|
|
175
|
+
requesterArgData: abi.encode(SomeVerifier.RequesterArg({mustBeBeef: bytes2(0xbebe)}))
|
|
206
176
|
});
|
|
207
|
-
assertFalse(
|
|
208
|
-
incoVerifier.isAllowedWithProof(secretHandle, bob, bobsProof),
|
|
209
|
-
"all parameters should be checked"
|
|
210
|
-
);
|
|
177
|
+
assertFalse(incoVerifier.isAllowedWithProof(secretHandle, bob, bobsProof), "all parameters should be checked");
|
|
211
178
|
}
|
|
212
179
|
|
|
213
|
-
function getBobsProof(
|
|
214
|
-
AllowanceVoucher memory alicesVoucher
|
|
215
|
-
) private view returns (AllowanceProof memory) {
|
|
180
|
+
function getBobsProof(AllowanceVoucher memory alicesVoucher) private view returns (AllowanceProof memory) {
|
|
216
181
|
bytes memory voucherSignature = getAliceSig(alicesVoucher);
|
|
217
|
-
return
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
});
|
|
182
|
+
return AllowanceProof({
|
|
183
|
+
sharer: alice,
|
|
184
|
+
voucher: alicesVoucher,
|
|
185
|
+
voucherSignature: voucherSignature,
|
|
186
|
+
requesterArgData: ""
|
|
187
|
+
});
|
|
224
188
|
}
|
|
225
189
|
|
|
226
|
-
function getAliceSig(
|
|
227
|
-
|
|
228
|
-
) private view returns (bytes memory) {
|
|
229
|
-
return
|
|
230
|
-
getSignatureForDigest(
|
|
231
|
-
incoVerifier.allowanceVoucherDigest(voucher),
|
|
232
|
-
alicePrivKey
|
|
233
|
-
);
|
|
190
|
+
function getAliceSig(AllowanceVoucher memory voucher) private view returns (bytes memory) {
|
|
191
|
+
return getSignatureForDigest(incoVerifier.allowanceVoucherDigest(voucher), alicePrivKey);
|
|
234
192
|
}
|
|
193
|
+
|
|
235
194
|
}
|
|
@@ -7,6 +7,7 @@ import {euint256, inco} from "../../../Lib.sol";
|
|
|
7
7
|
import {IncoTest} from "../../../test/IncoTest.sol";
|
|
8
8
|
|
|
9
9
|
contract TestBaseAccessControl is BaseAccessControlList, IncoTest {
|
|
10
|
+
|
|
10
11
|
constructor() VerifierAddressGetter(address(0)) {}
|
|
11
12
|
|
|
12
13
|
function testHandleZeroIsDisallowed() public view {
|
|
@@ -23,4 +24,5 @@ contract TestBaseAccessControl is BaseAccessControlList, IncoTest {
|
|
|
23
24
|
assert(inco.isAllowed(euint256.unwrap(secret), address(this)));
|
|
24
25
|
assert(inco.isAllowed(euint256.unwrap(secret), alice));
|
|
25
26
|
}
|
|
27
|
+
|
|
26
28
|
}
|
|
@@ -9,37 +9,23 @@ import {IDecryptionAttester} from "./interfaces/IDecryptionAttester.sol";
|
|
|
9
9
|
// todo pre charging transient decrypted values leads to a superior DevX
|
|
10
10
|
|
|
11
11
|
// todo #1032 add DecryptionAttester to IncoVerifier, will include signature verifier as well and fix #874
|
|
12
|
-
abstract contract DecryptionAttester is
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
EIP712Upgradeable
|
|
16
|
-
{
|
|
17
|
-
bytes32 constant DecryptionAttestationStructHash =
|
|
12
|
+
abstract contract DecryptionAttester is IDecryptionAttester, SignatureVerifier, EIP712Upgradeable {
|
|
13
|
+
|
|
14
|
+
bytes32 constant DECRYPTION_ATTESTATION_STRUCT_HASH =
|
|
18
15
|
keccak256("DecryptionAttestation(bytes32 handle,bytes32 value)");
|
|
19
16
|
|
|
20
|
-
function decryptionAttestationDigest(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_hashTypedDataV4(
|
|
25
|
-
keccak256(
|
|
26
|
-
abi.encode(
|
|
27
|
-
DecryptionAttestationStructHash,
|
|
28
|
-
decryption.handle,
|
|
29
|
-
decryption.value
|
|
30
|
-
)
|
|
31
|
-
)
|
|
32
|
-
);
|
|
17
|
+
function decryptionAttestationDigest(DecryptionAttestation memory decryption) public view returns (bytes32) {
|
|
18
|
+
return _hashTypedDataV4(
|
|
19
|
+
keccak256(abi.encode(DECRYPTION_ATTESTATION_STRUCT_HASH, decryption.handle, decryption.value))
|
|
20
|
+
);
|
|
33
21
|
}
|
|
34
22
|
|
|
35
|
-
function isValidDecryptionAttestation(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
decryptionAttestationDigest(decryption),
|
|
42
|
-
signature
|
|
43
|
-
);
|
|
23
|
+
function isValidDecryptionAttestation(DecryptionAttestation memory decryption, bytes[] memory signatures)
|
|
24
|
+
public
|
|
25
|
+
view
|
|
26
|
+
returns (bool)
|
|
27
|
+
{
|
|
28
|
+
return isValidSignature(decryptionAttestationDigest(decryption), signatures);
|
|
44
29
|
}
|
|
30
|
+
|
|
45
31
|
}
|
|
@@ -20,68 +20,43 @@ error ExternalHandleDoesNotMatchComputedHandle(
|
|
|
20
20
|
address contractAddress
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
-
abstract contract EncryptedInput is
|
|
24
|
-
|
|
25
|
-
BaseAccessControlList,
|
|
26
|
-
HandleGeneration,
|
|
27
|
-
Fee
|
|
28
|
-
{
|
|
23
|
+
abstract contract EncryptedInput is IEncryptedInput, BaseAccessControlList, HandleGeneration, Fee {
|
|
24
|
+
|
|
29
25
|
event NewInput(
|
|
30
|
-
bytes32 indexed result,
|
|
31
|
-
address indexed contractAddress,
|
|
32
|
-
address indexed user,
|
|
33
|
-
bytes ciphertext,
|
|
34
|
-
uint256 eventId
|
|
26
|
+
bytes32 indexed result, address indexed contractAddress, address indexed user, bytes ciphertext, uint256 eventId
|
|
35
27
|
);
|
|
36
28
|
|
|
37
|
-
function newEuint256(
|
|
38
|
-
bytes memory input,
|
|
39
|
-
address user
|
|
40
|
-
) external payable returns (euint256 newValue) {
|
|
29
|
+
function newEuint256(bytes memory input, address user) external payable returns (euint256 newValue) {
|
|
41
30
|
return euint256.wrap(newInput(input, user, ETypes.Uint256));
|
|
42
31
|
}
|
|
43
32
|
|
|
44
|
-
function newEbool(
|
|
45
|
-
bytes memory input,
|
|
46
|
-
address user
|
|
47
|
-
) external payable returns (ebool newValue) {
|
|
33
|
+
function newEbool(bytes memory input, address user) external payable returns (ebool newValue) {
|
|
48
34
|
return ebool.wrap(newInput(input, user, ETypes.Bool));
|
|
49
35
|
}
|
|
50
36
|
|
|
51
|
-
function newEaddress(
|
|
52
|
-
|
|
53
|
-
address user
|
|
54
|
-
) external payable returns (eaddress newValue) {
|
|
55
|
-
return
|
|
56
|
-
eaddress.wrap(
|
|
57
|
-
newInput(input, user, ETypes.AddressOrUint160OrBytes20)
|
|
58
|
-
);
|
|
37
|
+
function newEaddress(bytes memory input, address user) external payable returns (eaddress newValue) {
|
|
38
|
+
return eaddress.wrap(newInput(input, user, ETypes.AddressOrUint160OrBytes20));
|
|
59
39
|
}
|
|
60
40
|
|
|
61
|
-
function newInput(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
41
|
+
function newInput(bytes memory ciphertext, address user, ETypes inputType)
|
|
42
|
+
internal
|
|
43
|
+
paying
|
|
44
|
+
returns (bytes32 newHandle)
|
|
45
|
+
{
|
|
66
46
|
newHandle = _newInput(ciphertext, user, inputType);
|
|
67
47
|
}
|
|
68
48
|
|
|
69
|
-
function newInputNotPaying(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
) internal returns (bytes32 newHandle) {
|
|
49
|
+
function newInputNotPaying(bytes memory ciphertext, address user, ETypes inputType)
|
|
50
|
+
internal
|
|
51
|
+
returns (bytes32 newHandle)
|
|
52
|
+
{
|
|
74
53
|
newHandle = _newInput(ciphertext, user, inputType);
|
|
75
54
|
}
|
|
76
55
|
|
|
77
56
|
/// @notice Creates a new input with a prepended handle as a checksum.
|
|
78
57
|
/// @param input The input that contains the handle prepended to the ciphertext.
|
|
79
58
|
/// @param user The user address associated with the input.
|
|
80
|
-
function _newInput(
|
|
81
|
-
bytes memory input,
|
|
82
|
-
address user,
|
|
83
|
-
ETypes inputType
|
|
84
|
-
) private returns (bytes32 handle) {
|
|
59
|
+
function _newInput(bytes memory input, address user, ETypes inputType) private returns (bytes32 handle) {
|
|
85
60
|
// Since there is no sensible way to handle abi.decode errors (https://github.com/argotorg/solidity/issues/10381)
|
|
86
61
|
// at least fail early on a conservative minimum length
|
|
87
62
|
require(input.length >= 64, "Input too short, should be at least 64 bytes");
|
|
@@ -102,17 +77,13 @@ abstract contract EncryptedInput is
|
|
|
102
77
|
// We assume that providing the same handle (which via HADU implies same plaintext, same context, and same
|
|
103
78
|
// instance of encryption)
|
|
104
79
|
require(!isAllowed(handle, user), HandleAlreadyExists(handle));
|
|
105
|
-
// We allow to user since this is harmless and it is convenient to use the allow mapping to track existing
|
|
106
|
-
allowInternal(handle, user);
|
|
107
|
-
allowTransientInternal(handle, msg.sender);
|
|
108
80
|
uint256 id = getNextEventId();
|
|
109
|
-
emit NewInput({
|
|
110
|
-
result: handle,
|
|
111
|
-
contractAddress: msg.sender,
|
|
112
|
-
user: user,
|
|
113
|
-
ciphertext: ciphertext,
|
|
114
|
-
eventId: id
|
|
115
|
-
});
|
|
81
|
+
emit NewInput({result: handle, contractAddress: msg.sender, user: user, ciphertext: ciphertext, eventId: id});
|
|
116
82
|
setDigest(abi.encodePacked(handle, id));
|
|
83
|
+
// We allow to user since this is harmless and it is convenient to use the allow mapping to track inputs.
|
|
84
|
+
// NOTE: the allow must come after emitting the new input event, since allow emits its own event.
|
|
85
|
+
allowInternal(handle, user);
|
|
86
|
+
allowTransientInternal(handle, msg.sender);
|
|
117
87
|
}
|
|
88
|
+
|
|
118
89
|
}
|