From 7472aff75c8cfe922d2bad1a22e8f02cebde0471 Mon Sep 17 00:00:00 2001 From: PacificYield <173040337+PacificYield@users.noreply.github.com> Date: Fri, 15 Nov 2024 16:32:56 +0100 Subject: [PATCH] feat: add default configs for Gateway and FHEVM --- config/ZamaFHEVMConfig.sol | 70 ++++++++++++++++++++++++++++++++++++ config/ZamaGatewayConfig.sol | 63 ++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 config/ZamaFHEVMConfig.sol create mode 100644 config/ZamaGatewayConfig.sol diff --git a/config/ZamaFHEVMConfig.sol b/config/ZamaFHEVMConfig.sol new file mode 100644 index 00000000..ee6ab592 --- /dev/null +++ b/config/ZamaFHEVMConfig.sol @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +pragma solidity ^0.8.24; + +import {FHEVMConfig, TFHE} from "../lib/TFHE.sol"; + +/** + * @title ZamaFHEVMConfig. + * @notice This library returns the TFHE config for different networks + * with the contract addresses for + * (1) ACL, (2) TFHEExecutor, (3) FHEPayment, (4) KMSVerifier, + * which are deployed & maintained by Zama. + */ +library ZamaFHEVMConfig { + function getMockConfig() internal pure returns (FHEVMConfig.FHEVMConfigStruct memory) { + return + FHEVMConfig.FHEVMConfigStruct({ + ACLAddress: 0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2, + TFHEExecutorAddress: 0x596E6682c72946AF006B27C131793F2b62527A4b, + FHEPaymentAddress: 0x6d5A11aC509C707c00bc3A0a113ACcC26c532547, + KMSVerifierAddress: 0x208De73316E44722e16f6dDFF40881A3e4F86104 + }); + } + + function getSepoliaConfig() internal pure returns (FHEVMConfig.FHEVMConfigStruct memory) { + /// TODO + } + + function getEthereumConfig() internal pure returns (FHEVMConfig.FHEVMConfigStruct memory) { + /// TODO + } +} + +/** + * @title MockZamaFHEVMConfig. + * @dev This contract can be inherited by a contract wishing to use these contracts on the mock + * environment provided by Zama. + * Other providers may offer similar contracts deployed at different addresses. + * If you wish to use them, you should rely on the instructions from these providers. + */ +contract MockZamaFHEVMConfig { + constructor() { + TFHE.setFHEVM(ZamaFHEVMConfig.getMockConfig()); + } +} + +/** + * @title SepoliaZamaFHEVMConfig. + * @dev This contract can be inherited by a contract wishing to use the FHEVM contracts provided by Zama + * on the Sepolia network (chainId = 11155111). + * Other providers may offer similar contracts deployed at different addresses. + * If you wish to use them, you should rely on the instructions from these providers. + */ +contract SepoliaZamaFHEVMConfig { + constructor() { + TFHE.setFHEVM(ZamaFHEVMConfig.getSepoliaConfig()); + } +} + +/** + * @title EthereumZamaFHEVMConfig. + * @dev This contract can be inherited by a contract wishing to use the FHEVM contracts provided by Zama + * on the Ethereum (mainnet) network (chainId = 1). + * Other providers may offer similar contracts deployed at different addresses. + * If you wish to use them, you should rely on the instructions from these providers. + */ +contract EthereumZamaFHEVMConfig { + constructor() { + TFHE.setFHEVM(ZamaFHEVMConfig.getEthereumConfig()); + } +} diff --git a/config/ZamaGatewayConfig.sol b/config/ZamaGatewayConfig.sol new file mode 100644 index 00000000..1657a64a --- /dev/null +++ b/config/ZamaGatewayConfig.sol @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +pragma solidity ^0.8.24; + +import {Gateway} from "../gateway/lib/Gateway.sol"; + +/** + * @title ZamaGatewayConfig. + * @notice This library returns the Gateway config for different networks + * with the address of the Gateway contract, which is + * deployed & maintained by Zama. + */ +library ZamaGatewayConfig { + function getMockConfig() internal pure returns (address) { + return 0x096b4679d45fB675d4e2c1E4565009Cec99A12B1; + } + + function getSepoliaConfig() internal pure returns (address) { + /// TODO + } + + function getEthereumConfig() internal pure returns (address) { + /// TODO + } +} + +/** + * @title MockZamaGatewayConfig + * @dev This contract can be inherited by a contract wishing to use the Gateway service + * on the mock environment provided by Zama. + * Other providers may offer other Gateways that are deployed at different addresses. + * If you wish to use them, you should rely on the instructions from these providers. + */ +contract MockZamaGatewayConfig { + constructor() { + Gateway.setGateway(ZamaGatewayConfig.getMockConfig()); + } +} + +/** + * @title SepoliaZamaGatewayConfig + * @dev This contract can be inherited by a contract wishing to use the Gateway service + * provided by Zama on the Sepolia network (chainId = 11155111). + * Other providers may offer other Gateways that are deployed at different addresses. + * If you wish to use them, you should rely on the instructions from these providers. + */ +contract SepoliaZamaGatewayConfig { + constructor() { + Gateway.setGateway(ZamaGatewayConfig.getSepoliaConfig()); + } +} + +/** + * @title EthereumZamaGatewayConfig + * @dev This contract can be inherited by a contract wishing to use the Gateway service + * provided by Zama on the Ethereum (mainnet) network (chainId = 1). + * Other providers may offer other Gateways that are deployed at different addresses. + * If you wish to use them, you should rely on the instructions from these providers. + */ +contract EthereumZamaGatewayConfig { + constructor() { + Gateway.setGateway(ZamaGatewayConfig.getEthereumConfig()); + } +}