Skip to content

Commit 891da82

Browse files
authored
feat(gateway-contracts): introduce the generic bytes metadata
1 parent 38bb31b commit 891da82

26 files changed

+3551
-1690
lines changed

gateway-contracts/contracts/Decryption.sol

Lines changed: 92 additions & 49 deletions
Large diffs are not rendered by default.

gateway-contracts/contracts/InputVerification.sol

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ contract InputVerification is
3838
address contractAddress;
3939
/// @notice The host chain's chain ID of the contract requiring the ZK Proof verification.
4040
uint256 contractChainId;
41+
/// @notice Generic bytes metadata for versioned payloads. First byte is for the version.
42+
bytes extraData;
4143
}
4244

4345
/// @notice The stored structure for the received ZK Proof verification request inputs.
@@ -55,7 +57,7 @@ contract InputVerification is
5557

5658
/// @notice The definition of the CiphertextVerification structure typed data.
5759
string private constant EIP712_ZKPOK_TYPE =
58-
"CiphertextVerification(bytes32[] ctHandles,address userAddress,address contractAddress,uint256 contractChainId)";
60+
"CiphertextVerification(bytes32[] ctHandles,address userAddress,address contractAddress,uint256 contractChainId,bytes extraData)";
5961

6062
/// @notice The hash of the CiphertextVerification structure typed data definition used for signature validation.
6163
bytes32 private constant EIP712_ZKPOK_TYPE_HASH = keccak256(bytes(EIP712_ZKPOK_TYPE));
@@ -124,7 +126,8 @@ contract InputVerification is
124126
uint256 contractChainId,
125127
address contractAddress,
126128
address userAddress,
127-
bytes calldata ciphertextWithZKProof
129+
bytes calldata ciphertextWithZKProof,
130+
bytes calldata extraData
128131
) external virtual onlyRegisteredHostChain(contractChainId) whenNotPaused {
129132
InputVerificationStorage storage $ = _getInputVerificationStorage();
130133

@@ -134,7 +137,14 @@ contract InputVerification is
134137
/// @dev The following stored inputs are used during response calls for the EIP712 signature validation.
135138
$._zkProofInputs[zkProofId] = ZKProofInput(contractChainId, contractAddress, userAddress);
136139

137-
emit VerifyProofRequest(zkProofId, contractChainId, contractAddress, userAddress, ciphertextWithZKProof);
140+
emit VerifyProofRequest(
141+
zkProofId,
142+
contractChainId,
143+
contractAddress,
144+
userAddress,
145+
ciphertextWithZKProof,
146+
extraData
147+
);
138148
}
139149

140150
/**
@@ -145,7 +155,8 @@ contract InputVerification is
145155
function verifyProofResponse(
146156
uint256 zkProofId,
147157
bytes32[] calldata ctHandles,
148-
bytes calldata signature
158+
bytes calldata signature,
159+
bytes calldata extraData
149160
) external virtual onlyCoprocessorTxSender {
150161
InputVerificationStorage storage $ = _getInputVerificationStorage();
151162

@@ -162,7 +173,8 @@ contract InputVerification is
162173
ctHandles,
163174
zkProofInput.userAddress,
164175
zkProofInput.contractAddress,
165-
zkProofInput.contractChainId
176+
zkProofInput.contractChainId,
177+
extraData
166178
);
167179

168180
/// @dev Compute the digest of the CiphertextVerification structure.
@@ -194,7 +206,10 @@ contract InputVerification is
194206
}
195207

196208
/// @dev See {IInputVerification-rejectProofResponse}.
197-
function rejectProofResponse(uint256 zkProofId) external virtual onlyCoprocessorTxSender {
209+
function rejectProofResponse(
210+
uint256 zkProofId,
211+
bytes calldata /* extraData */
212+
) external virtual onlyCoprocessorTxSender {
198213
InputVerificationStorage storage $ = _getInputVerificationStorage();
199214

200215
/**
@@ -302,7 +317,8 @@ contract InputVerification is
302317
keccak256(abi.encodePacked(ctVerification.ctHandles)),
303318
ctVerification.userAddress,
304319
ctVerification.contractAddress,
305-
ctVerification.contractChainId
320+
ctVerification.contractChainId,
321+
keccak256(abi.encodePacked(ctVerification.extraData))
306322
)
307323
)
308324
);

gateway-contracts/contracts/MultichainAcl.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ contract MultichainAcl is
100100

101101
/// @dev See {IMultichainAcl-allowPublicDecrypt}.
102102
function allowPublicDecrypt(
103-
bytes32 ctHandle
103+
bytes32 ctHandle,
104+
bytes calldata /* extraData */
104105
) external virtual onlyCoprocessorTxSender onlyHandleFromRegisteredHostChain(ctHandle) {
105106
MultichainAclStorage storage $ = _getMultichainAclStorage();
106107

@@ -127,7 +128,8 @@ contract MultichainAcl is
127128
/// @dev See {IMultichainAcl-allowAccount}.
128129
function allowAccount(
129130
bytes32 ctHandle,
130-
address accountAddress
131+
address accountAddress,
132+
bytes calldata /* extraData */
131133
) external virtual onlyCoprocessorTxSender onlyHandleFromRegisteredHostChain(ctHandle) {
132134
MultichainAclStorage storage $ = _getMultichainAclStorage();
133135

gateway-contracts/contracts/interfaces/IDecryption.sol

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import "../shared/Structs.sol";
99
* Both user decryption and public decryption are handled.
1010
*/
1111
interface IDecryption {
12+
/**
13+
* @notice A struct that specifies information about the contracts to be used in the decryption.
14+
*/
15+
struct ContractsInfo {
16+
/// @notice The chain ID of the contracts to be used in the decryption
17+
uint256 chainId;
18+
/// @notice The list of contract addresses to be used in the decryption
19+
address[] addresses;
20+
}
21+
1222
/**
1323
* @notice A struct that specifies the validity period of a request, starting at "startTimestamp"
1424
* and remaining valid for "durationDays".
@@ -27,38 +37,57 @@ interface IDecryption {
2737
* @notice Emitted when an public decryption request is made.
2838
* @param decryptionId The decryption request ID.
2939
* @param snsCtMaterials The handles, key IDs and SNS ciphertexts to decrypt.
40+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
3041
*/
31-
event PublicDecryptionRequest(uint256 indexed decryptionId, SnsCiphertextMaterial[] snsCtMaterials);
42+
event PublicDecryptionRequest(
43+
uint256 indexed decryptionId,
44+
SnsCiphertextMaterial[] snsCtMaterials,
45+
bytes extraData
46+
);
3247

3348
/**
3449
* @notice Emitted when an public decryption response is made.
3550
* @param decryptionId The decryption request ID associated with the response.
3651
* @param decryptedResult The decrypted result.
3752
* @param signatures The signatures of all the KMS connectors that responded.
53+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
3854
*/
39-
event PublicDecryptionResponse(uint256 indexed decryptionId, bytes decryptedResult, bytes[] signatures);
55+
event PublicDecryptionResponse(
56+
uint256 indexed decryptionId,
57+
bytes decryptedResult,
58+
bytes[] signatures,
59+
bytes extraData
60+
);
4061

4162
/**
4263
* @notice Emitted when a user decryption request is made.
4364
* @param decryptionId The decryption request ID.
4465
* @param snsCtMaterials The handles, key IDs and SNS ciphertexts to decrypt.
4566
* @param userAddress The user's address.
4667
* @param publicKey The user's public key for used reencryption.
68+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
4769
*/
4870
event UserDecryptionRequest(
4971
uint256 indexed decryptionId,
5072
SnsCiphertextMaterial[] snsCtMaterials,
5173
address userAddress,
52-
bytes publicKey
74+
bytes publicKey,
75+
bytes extraData
5376
);
5477

5578
/**
5679
* @notice Emitted when an public decryption response is made.
5780
* @param decryptionId The decryption request ID associated with the response.
5881
* @param userDecryptedShares The list of decryption shares reencrypted with the user's public key.
5982
* @param signatures The signatures of all the KMS connectors that responded.
83+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
6084
*/
61-
event UserDecryptionResponse(uint256 indexed decryptionId, bytes[] userDecryptedShares, bytes[] signatures);
85+
event UserDecryptionResponse(
86+
uint256 indexed decryptionId,
87+
bytes[] userDecryptedShares,
88+
bytes[] signatures,
89+
bytes extraData
90+
);
6291

6392
/// @notice Error indicating that the input list of handles is empty.
6493
error EmptyCtHandles();
@@ -172,87 +201,95 @@ interface IDecryption {
172201
/**
173202
* @notice Requests a public decryption.
174203
* @param ctHandles The handles of the ciphertexts to decrypt.
204+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
175205
*/
176-
function publicDecryptionRequest(bytes32[] calldata ctHandles) external;
206+
function publicDecryptionRequest(bytes32[] calldata ctHandles, bytes calldata extraData) external;
177207

178208
/**
179209
* @notice Responds to a public decryption request.
180210
* @param decryptionId The decryption request ID associated with the response.
181211
* @param decryptedResult The decrypted result.
182212
* @param signature The signature of the KMS connector that responded.
213+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
183214
*/
184215
function publicDecryptionResponse(
185216
uint256 decryptionId,
186217
bytes calldata decryptedResult,
187-
bytes calldata signature
218+
bytes calldata signature,
219+
bytes calldata extraData
188220
) external;
189221

190222
/**
191223
* @notice Requests a user decryption.
192224
* @param ctHandleContractPairs The ciphertexts to decrypt for associated contracts.
193225
* @param requestValidity The validity period of the user decryption request.
194-
* @param contractsChainId The chain ID of the given contract addresses figuring in the signed EIP-712 message.
195-
* @param contractAddresses The contract addresses figuring in the signed EIP-712 message.
226+
* @param contractsInfo The chain ID and contract addresses to be used in the decryption.
196227
* @param userAddress The user's address.
197228
* @param publicKey The user's public key to reencrypt the decryption shares.
198229
* @param signature The EIP712 signature to verify.
230+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
199231
*/
200232
function userDecryptionRequest(
201233
CtHandleContractPair[] calldata ctHandleContractPairs,
202234
RequestValidity calldata requestValidity,
203-
uint256 contractsChainId,
204-
address[] calldata contractAddresses,
235+
ContractsInfo calldata contractsInfo,
205236
address userAddress,
206237
bytes calldata publicKey,
207-
bytes calldata signature
238+
bytes calldata signature,
239+
bytes calldata extraData
208240
) external;
209241

210242
/**
211243
* @notice Requests a delegated user decryption.
212244
* @param ctHandleContractPairs The ciphertexts to decrypt for associated contracts.
213245
* @param requestValidity The validity period of the user decryption request.
214246
* @param delegationAccounts The user's address and the delegated account address for the user decryption.
215-
* @param contractsChainId The chain ID of the given contract addresses figuring in the signed EIP-712 message.
216-
* @param contractAddresses The contract addresses figuring in the signed EIP-712 message.
247+
* @param contractsInfo The chain ID and contract addresses to be used in the decryption.
217248
* @param publicKey The user's public key to reencrypt the decryption shares.
218249
* @param signature The EIP712 signature to verify.
250+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
219251
*/
220252
function delegatedUserDecryptionRequest(
221253
CtHandleContractPair[] calldata ctHandleContractPairs,
222254
RequestValidity calldata requestValidity,
223255
DelegationAccounts calldata delegationAccounts,
224-
uint256 contractsChainId,
225-
address[] calldata contractAddresses,
256+
ContractsInfo calldata contractsInfo,
226257
bytes calldata publicKey,
227-
bytes calldata signature
258+
bytes calldata signature,
259+
bytes calldata extraData
228260
) external;
229261

230262
/**
231263
* @notice Responds to a user decryption request.
232264
* @param decryptionId The decryption request ID associated with the response.
233265
* @param userDecryptedShare The partial decryption share reencrypted with the user's public key.
234266
* @param signature The signature of the KMS connector that responded.
267+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
235268
*/
236269
function userDecryptionResponse(
237270
uint256 decryptionId,
238271
bytes calldata userDecryptedShare,
239-
bytes calldata signature
272+
bytes calldata signature,
273+
bytes calldata extraData
240274
) external;
241275

242276
/**
243277
* @notice Checks if handles are ready to be decrypted publicly.
244278
* @param ctHandles The ciphertext handles.
279+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
245280
*/
246-
function checkPublicDecryptionReady(bytes32[] calldata ctHandles) external view;
281+
function checkPublicDecryptionReady(bytes32[] calldata ctHandles, bytes calldata extraData) external view;
247282

248283
/**
249284
* @notice Checks if handles are ready to be decrypted by a user.
250285
* @param userAddress The user's address.
251286
* @param ctHandleContractPairs The ciphertext handles with associated contract addresses.
287+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
252288
*/
253289
function checkUserDecryptionReady(
254290
address userAddress,
255-
CtHandleContractPair[] calldata ctHandleContractPairs
291+
CtHandleContractPair[] calldata ctHandleContractPairs,
292+
bytes calldata extraData
256293
) external view;
257294

258295
/**
@@ -261,12 +298,14 @@ interface IDecryption {
261298
* @param delegationAccounts The delegator and delegated address.
262299
* @param ctHandleContractPairs The ciphertext handles with associated contract addresses.
263300
* @param contractAddresses The contract addresses.
301+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
264302
*/
265303
function checkDelegatedUserDecryptionReady(
266304
uint256 contractsChainId,
267305
DelegationAccounts calldata delegationAccounts,
268306
CtHandleContractPair[] calldata ctHandleContractPairs,
269-
address[] calldata contractAddresses
307+
address[] calldata contractAddresses,
308+
bytes calldata extraData
270309
) external view;
271310

272311
/**

gateway-contracts/contracts/interfaces/IInputVerification.sol

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ interface IInputVerification {
1313
* @param contractAddress The address of the dapp requiring the ZK Proof verification.
1414
* @param userAddress The address of the user providing the input.
1515
* @param ciphertextWithZKProof The combination of the ciphertext (plain text signed with user PK) and the ZK Proof.
16+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
1617
*/
1718
event VerifyProofRequest(
1819
uint256 indexed zkProofId,
1920
uint256 indexed contractChainId,
2021
address contractAddress,
2122
address userAddress,
22-
bytes ciphertextWithZKProof
23+
bytes ciphertextWithZKProof,
24+
bytes extraData
2325
);
2426

2527
/**
@@ -76,21 +78,29 @@ interface IInputVerification {
7678
* @param contractAddress The address of the dapp the input is used for.
7779
* @param userAddress The address of the user providing the input.
7880
* @param ciphertextWithZKProof The combination of the ciphertext (plain text signed with user PK) and the ZK Proof.
81+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
7982
*/
8083
function verifyProofRequest(
8184
uint256 contractChainId,
8285
address contractAddress,
8386
address userAddress,
84-
bytes calldata ciphertextWithZKProof
87+
bytes calldata ciphertextWithZKProof,
88+
bytes calldata extraData
8589
) external;
8690

8791
/**
8892
* @notice Responds to a correct ZK Proof verification request.
8993
* @param zkProofId The ID of the requested ZK Proof.
9094
* @param ctHandles The coprocessor's computed ciphertext handles.
9195
* @param signature The coprocessor's signature.
96+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
9297
*/
93-
function verifyProofResponse(uint256 zkProofId, bytes32[] calldata ctHandles, bytes calldata signature) external;
98+
function verifyProofResponse(
99+
uint256 zkProofId,
100+
bytes32[] calldata ctHandles,
101+
bytes calldata signature,
102+
bytes calldata extraData
103+
) external;
94104

95105
/**
96106
* @notice Rejects an incorrect ZK Proof verification request.
@@ -99,8 +109,9 @@ interface IInputVerification {
99109
* easily verify the sender's identity through `msg.sender`.
100110
*
101111
* @param zkProofId The ID of the requested ZK Proof.
112+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
102113
*/
103-
function rejectProofResponse(uint256 zkProofId) external;
114+
function rejectProofResponse(uint256 zkProofId, bytes calldata extraData) external;
104115

105116
/**
106117
* @notice Checks that a ZK Proof has been verified.

gateway-contracts/contracts/interfaces/IMultichainAcl.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,17 @@ interface IMultichainAcl {
9292
/**
9393
* @notice Allows access to the ciphertext handle for public decryption.
9494
* @param ctHandle The ciphertext handle.
95+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
9596
*/
96-
function allowPublicDecrypt(bytes32 ctHandle) external;
97+
function allowPublicDecrypt(bytes32 ctHandle, bytes calldata extraData) external;
9798

9899
/**
99100
* @notice Allows an account to access a ciphertext handle.
100101
* @param ctHandle The handle of the ciphertext.
101102
* @param accountAddress The address of the account to allow.
103+
* @param extraData Generic bytes metadata for versioned payloads. First byte is for the version.
102104
*/
103-
function allowAccount(bytes32 ctHandle, address accountAddress) external;
105+
function allowAccount(bytes32 ctHandle, address accountAddress, bytes calldata extraData) external;
104106

105107
/**
106108
* @notice Delegates the access to the delegated and contract addresses.

0 commit comments

Comments
 (0)