Skip to content

Commit afd564f

Browse files
authored
fix(gateway-contracts): use contractsChainId in delegate request eip712 verification (#427)
1 parent 156b194 commit afd564f

16 files changed

Lines changed: 175 additions & 245 deletions

File tree

gateway-contracts/.github/ISSUE_TEMPLATE/contracts_bug_report.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ Include screenshots, relevant logs, or traces if available.
2020

2121
### **Smart Contract Code Snippet**
2222

23-
If applicable, provide a minimal reproducible example of the smart contract code highlighting the part where the issue
24-
occurs:
23+
If applicable, provide a minimal reproducible example of the smart contract code highlighting the part where the issue occurs:
2524

2625
<details><summary>Example</summary>
2726
<p>

gateway-contracts/.github/ISSUE_TEMPLATE/docs_bug_report.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ Please provide a link to the page where the issue is located:
1414

1515
### **Description**
1616

17-
Describe in detail what part of the documentation is unclear or provide a clear and detailed description of the bug.
18-
Include any inconsistencies, typos, broken links, or missing information.
17+
Describe in detail what part of the documentation is unclear or provide a clear and detailed description of the bug. Include any inconsistencies, typos, broken links, or missing information.
1918

2019
<details><summary>For example:</summary>
2120
<p>
@@ -69,5 +68,4 @@ Choose the impact of the bug on the documentation quality and user experience:
6968

7069
---
7170

72-
By including these details, we can ensure a faster and more accurate resolution for your issue. Thank you for helping
73-
improve the `fhevm Gateway's documentation`!
71+
By including these details, we can ensure a faster and more accurate resolution for your issue. Thank you for helping improve the `fhevm Gateway's documentation`!

gateway-contracts/.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ labels: enhancement
66
assignees: ""
77
---
88

9-
**Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem
10-
is. Ex. I'm always frustrated when [...]
9+
**Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
1110

1211
**Describe the solution you'd like** A clear and concise description of what you want to happen.
1312

gateway-contracts/README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
## Introduction
22

3-
The **FHEVM Gateway** is a set of smart contracts that enables decrypting FHE ciphertexts from different host chains. It
4-
acts as an intermediary between the chains, the Key Management Service (KMS) and the coprocessors found within the FHEVM
5-
protocol. These contracts are responsible for:
3+
The **FHEVM Gateway** is a set of smart contracts that enables decrypting FHE ciphertexts from different host chains. It acts as an intermediary between the chains, the Key Management Service (KMS) and the coprocessors found within the FHEVM protocol. These contracts are responsible for:
64

75
- Verifying the legitimacy of decryption requests
86
- Centralizing multi-chain ciphertexts access
@@ -11,14 +9,14 @@ protocol. These contracts are responsible for:
119

1210
## Main features
1311

14-
| Contract | Description | Features |
15-
| ------------------- | ----------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
16-
| `Decryption` | Decrypt FHE ciphertexts | - Request a public decryption<br>- Request a user decryption<br>- Request a delegated user decryption |
17-
| `InputVerification` | Verify an input's zero-knowledge proof of knowledge (ZKPoK) | - Verify a ZKPoK<br>- Reject a ZKPoK |
18-
| `MultichainAcl` | Centralize Access Control Lists (ACL) from all host chains | - Grant account access to ciphertexts<br>- Authorize public decryption of ciphertexts<br>- Delegate account access to ciphertexts |
19-
| `CiphertextCommits` | Store ciphertext commitments from all host chains | - Store regular ciphertext commitments<br>- Store Switch and Squash (SNS) ciphertext commitments |
20-
| `KmsManagement` | Orchestrate KMS-related materials | 🚧 _Not in use yet_ 🚧 |
21-
| `GatewayConfig` | Administer configuration settings | - Register KMS nodes, coprocessors and host chains. <br> - Update KMS nodes, coprocessors and host chains. |
12+
| Contract | Description | Features |
13+
| --- | --- | --- |
14+
| `Decryption` | Decrypt FHE ciphertexts | - Request a public decryption<br>- Request a user decryption<br>- Request a delegated user decryption |
15+
| `InputVerification` | Verify an input's zero-knowledge proof of knowledge (ZKPoK) | - Verify a ZKPoK<br>- Reject a ZKPoK |
16+
| `MultichainAcl` | Centralize Access Control Lists (ACL) from all host chains | - Grant account access to ciphertexts<br>- Authorize public decryption of ciphertexts<br>- Delegate account access to ciphertexts |
17+
| `CiphertextCommits` | Store ciphertext commitments from all host chains | - Store regular ciphertext commitments<br>- Store Switch and Squash (SNS) ciphertext commitments |
18+
| `KmsManagement` | Orchestrate KMS-related materials | 🚧 _Not in use yet_ 🚧 |
19+
| `GatewayConfig` | Administer configuration settings | - Register KMS nodes, coprocessors and host chains. <br> - Update KMS nodes, coprocessors and host chains. |
2220

2321
## Getting started
2422

@@ -34,7 +32,6 @@ Documentation can be found [here](./docs/SUMMARY.md).
3432
</picture>
3533
</a>
3634

37-
🌟 If you find this project helpful or interesting, please consider giving it a star on GitHub! Your support helps to
38-
grow the community and motivates further development.
35+
🌟 If you find this project helpful or interesting, please consider giving it a star on GitHub! Your support helps to grow the community and motivates further development.
3936

4037
[![GitHub stars](https://img.shields.io/github/stars/zama-ai/fhevm?style=social)](https://github.com/zama-ai/fhevm/)

gateway-contracts/contracts/Decryption.sol

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ contract Decryption is
150150
/// @dev they can still define their own private constants with the same name.
151151
string private constant CONTRACT_NAME = "Decryption";
152152
uint256 private constant MAJOR_VERSION = 0;
153-
uint256 private constant MINOR_VERSION = 2;
153+
uint256 private constant MINOR_VERSION = 3;
154154
uint256 private constant PATCH_VERSION = 0;
155155

156156
/// @notice The contract's variable storage struct (@dev see ERC-7201)
@@ -204,16 +204,16 @@ contract Decryption is
204204
/// @dev Contract name and version for EIP712 signature validation are defined here
205205
/// @dev This function needs to be public in order to be called by the UUPS proxy.
206206
/// @custom:oz-upgrades-validate-as-initializer
207-
function initializeFromEmptyProxy() public virtual onlyFromEmptyProxy reinitializer(4) {
207+
function initializeFromEmptyProxy() public virtual onlyFromEmptyProxy reinitializer(5) {
208208
__EIP712_init(CONTRACT_NAME, "1");
209209
__Ownable_init(owner());
210210
__Pausable_init();
211211
}
212212

213213
/**
214-
* @notice Re-initializes the contract from V1.
214+
* @notice Re-initializes the contract from V2.
215215
*/
216-
function reinitializeV2() public virtual reinitializer(4) {}
216+
function reinitializeV3() public virtual reinitializer(5) {}
217217

218218
/// @dev See {IDecryption-publicDecryptionRequest}.
219219
function publicDecryptionRequest(bytes32[] calldata ctHandles) external virtual whenNotPaused {
@@ -643,6 +643,20 @@ contract Decryption is
643643
);
644644
}
645645

646+
/// @notice Computes the hash of the hashed struct using a custom chain ID for the eip712 domain
647+
/// @param chainId The chain ID
648+
/// @param structHash The hash of the struct
649+
/// @dev This could be improved along https://github.com/zama-ai/fhevm/issues/424
650+
function _hashTypedDataV4CustomChainId(
651+
uint256 chainId,
652+
bytes32 structHash
653+
) internal view virtual returns (bytes32) {
654+
bytes32 domainSeparatorV4 = keccak256(
655+
abi.encode(DOMAIN_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash(), chainId, address(this))
656+
);
657+
return MessageHashUtils.toTypedDataHash(domainSeparatorV4, structHash);
658+
}
659+
646660
/// @notice Computes the hash of a given UserDecryptRequestVerification structured data.
647661
/// @param userDecryptRequestVerification The UserDecryptRequestVerification structure to hash.
648662
/// @return The hash of the UserDecryptRequestVerification structure.
@@ -659,16 +673,7 @@ contract Decryption is
659673
userDecryptRequestVerification.durationDays
660674
)
661675
);
662-
bytes32 domainSeparatorV4 = keccak256(
663-
abi.encode(
664-
DOMAIN_TYPE_HASH,
665-
_EIP712NameHash(),
666-
_EIP712VersionHash(),
667-
userDecryptRequestVerification.contractsChainId,
668-
address(this)
669-
)
670-
);
671-
return MessageHashUtils.toTypedDataHash(domainSeparatorV4, structHash);
676+
return _hashTypedDataV4CustomChainId(userDecryptRequestVerification.contractsChainId, structHash);
672677
}
673678

674679
/// @notice Computes the hash of a given DelegatedUserDecryptRequestVerification structured data.
@@ -677,20 +682,18 @@ contract Decryption is
677682
function _hashDelegatedUserDecryptRequestVerification(
678683
DelegatedUserDecryptRequestVerification memory delegatedUserDecryptRequestVerification
679684
) internal view virtual returns (bytes32) {
680-
return
681-
_hashTypedDataV4(
682-
keccak256(
683-
abi.encode(
684-
EIP712_DELEGATED_USER_DECRYPT_REQUEST_TYPE_HASH,
685-
keccak256(delegatedUserDecryptRequestVerification.publicKey),
686-
keccak256(abi.encodePacked(delegatedUserDecryptRequestVerification.contractAddresses)),
687-
delegatedUserDecryptRequestVerification.delegatorAddress,
688-
delegatedUserDecryptRequestVerification.contractsChainId,
689-
delegatedUserDecryptRequestVerification.startTimestamp,
690-
delegatedUserDecryptRequestVerification.durationDays
691-
)
692-
)
693-
);
685+
bytes32 structHash = keccak256(
686+
abi.encode(
687+
EIP712_DELEGATED_USER_DECRYPT_REQUEST_TYPE_HASH,
688+
keccak256(delegatedUserDecryptRequestVerification.publicKey),
689+
keccak256(abi.encodePacked(delegatedUserDecryptRequestVerification.contractAddresses)),
690+
delegatedUserDecryptRequestVerification.delegatorAddress,
691+
delegatedUserDecryptRequestVerification.contractsChainId,
692+
delegatedUserDecryptRequestVerification.startTimestamp,
693+
delegatedUserDecryptRequestVerification.durationDays
694+
)
695+
);
696+
return _hashTypedDataV4CustomChainId(delegatedUserDecryptRequestVerification.contractsChainId, structHash);
694697
}
695698

696699
/// @notice Computes the hash of a given UserDecryptResponseVerification structured data.

gateway-contracts/docs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
description: >-
33
The fhevm Gateway.
4+
5+
46
layout:
57
title:
68
visible: true
@@ -24,8 +26,7 @@ Learn the basics of fhevm Gateway, set it up, and make it run with ease.
2426

2527
### Supports
2628

27-
Ask technical questions and discuss with the community. Our team of experts usually answers within 24 hours in working
28-
days.
29+
Ask technical questions and discuss with the community. Our team of experts usually answers within 24 hours in working days.
2930

3031
- [Community forum](https://community.zama.ai/c/fhevm/15)
3132
- [Discord channel](https://discord.com/invite/fhe-org)
@@ -44,5 +45,4 @@ Collaborate with us to advance the FHE spaces and drive innovation together.
4445

4546
---
4647

47-
We value your feedback! [Take a 5-question developer survey](http://zama.ai/developer-survey) to improve the fhevm
48-
Gateway and the documentation and help other developers use FHE.
48+
We value your feedback! [Take a 5-question developer survey](http://zama.ai/developer-survey) to improve the fhevm Gateway and the documentation and help other developers use FHE.

0 commit comments

Comments
 (0)