diff --git a/.npmignore b/.npmignore index f0d76e5..56e2a23 100644 --- a/.npmignore +++ b/.npmignore @@ -1,7 +1,6 @@ * !lib/** -!gateway/GatewayContract.sol -!gateway/lib/Gateway.sol +!gateway/** !config/** !package.json !README.md diff --git a/docs/fundamentals/first_step/decrypt.md b/docs/fundamentals/first_step/decrypt.md index 03bbb53..a65e744 100644 --- a/docs/fundamentals/first_step/decrypt.md +++ b/docs/fundamentals/first_step/decrypt.md @@ -98,7 +98,7 @@ contract EncryptedCounter3 is MockZamaFHEVMConfig, MockZamaGatewayConfig, Gatewa uint8 public decryptedCounter; constructor() { - Gateway.setGateway(Gateway.defaultGatewayAddress()); + Gateway.setGateway(GatewayConfig.defaultGatewayContract()); // Initialize counter with an encrypted zero value counter = TFHE.asEuint8(0); diff --git a/examples/BlindAuction.sol b/examples/BlindAuction.sol index 89577b9..2c55486 100644 --- a/examples/BlindAuction.sol +++ b/examples/BlindAuction.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; import "../lib/TFHE.sol"; import "./FHEVMConfig.sol"; +import "./GatewayConfig.sol"; import "./EncryptedERC20.sol"; import "@openzeppelin/contracts/access/Ownable2Step.sol"; import "../gateway/GatewayCaller.sol"; @@ -75,7 +76,7 @@ contract BlindAuction is Ownable2Step, GatewayCaller { bool isStoppable ) Ownable(msg.sender) { TFHE.setFHEVM(FHEVMConfig.defaultConfig()); - Gateway.setGateway(Gateway.defaultGatewayAddress()); + Gateway.setGateway(GatewayConfig.defaultGatewayContract()); beneficiary = _beneficiary; tokenContract = _tokenContract; endTime = block.timestamp + biddingTime; diff --git a/examples/GatewayConfig.sol b/examples/GatewayConfig.sol new file mode 100644 index 0000000..842c206 --- /dev/null +++ b/examples/GatewayConfig.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +pragma solidity ^0.8.24; + +import "fhevm-core-contracts/addresses/GatewayContractAddress.sol"; + +/** + * @title FHEVMConfig + * @notice This library returns all addresses for the ACL, TFHEExecutor, FHEPayment, + * and KMSVerifier contracts. + */ +library GatewayConfig { + /** + * @notice This function returns a struct containing all contract addresses. + * @dev It returns an immutable struct. + */ + function defaultGatewayContract() internal pure returns (address) { + return GATEWAY_CONTRACT_PREDEPLOY_ADDRESS; + } +} diff --git a/examples/TestAsyncDecrypt.sol b/examples/TestAsyncDecrypt.sol index 3511dc5..7c55854 100644 --- a/examples/TestAsyncDecrypt.sol +++ b/examples/TestAsyncDecrypt.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; import "../lib/TFHE.sol"; import "./FHEVMConfig.sol"; +import "./GatewayConfig.sol"; import "../gateway/GatewayCaller.sol"; /// @notice Contract for testing asynchronous decryption using the Gateway @@ -45,7 +46,7 @@ contract TestAsyncDecrypt is GatewayCaller { /// @notice Constructor to initialize the contract and set up encrypted values constructor() { TFHE.setFHEVM(FHEVMConfig.defaultConfig()); - Gateway.setGateway(Gateway.defaultGatewayAddress()); + Gateway.setGateway(GatewayConfig.defaultGatewayContract()); /// @dev Initialize encrypted variables with sample values xBool = TFHE.asEbool(true); diff --git a/gateway/lib/Gateway.sol b/gateway/lib/Gateway.sol index ebaaa25..f2deed3 100644 --- a/gateway/lib/Gateway.sol +++ b/gateway/lib/Gateway.sol @@ -24,11 +24,11 @@ interface IGatewayContract { ) external returns (uint256); } -library Gateway { - struct GatewayConfigStruct { - address GatewayContractAddress; - } +struct GatewayConfigStruct { + address GatewayContractAddress; +} +library Gateway { // keccak256(abi.encode(uint256(keccak256("fhevm.storage.GatewayConfig")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant GatewayLocation = 0x93ab6e17f2c461cce6ea5d4ec117e51dda77a64affc2b2c05f8cd440def0e700; diff --git a/hardhat.config.ts b/hardhat.config.ts index 454501e..177b8a7 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -13,7 +13,6 @@ import * as path from 'path'; import CustomProvider from './CustomProvider'; // Adjust the import path as needed import './tasks/accounts'; -import './tasks/etherscanVerify'; import './tasks/getEthereumAddress'; import './tasks/taskDeploy'; import './tasks/taskGatewayRelayer'; diff --git a/package-lock.json b/package-lock.json index cbf2351..93a85e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fhevm", - "version": "0.6.0-5", + "version": "0.6.0-6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "fhevm", - "version": "0.6.0-5", + "version": "0.6.0-6", "license": "BSD-3-Clause-Clear", "dependencies": { "@openzeppelin/contracts": "^5.0.1", diff --git a/package.json b/package.json index 94d0aea..9097a68 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fhevm", "description": "A Solidity library for interacting with the Zama Blockchain", - "version": "0.6.0-5", + "version": "0.6.0-6", "engines": { "node": ">=20.0.0" }, diff --git a/tasks/etherscanVerify.ts b/tasks/etherscanVerify.ts deleted file mode 100644 index 0a8f8c5..0000000 --- a/tasks/etherscanVerify.ts +++ /dev/null @@ -1,93 +0,0 @@ -import dotenv from 'dotenv'; -import fs from 'fs'; -import { task } from 'hardhat/config'; - -task('task:verifyACL').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvACL = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.acl')); - const proxyACLAddress = parsedEnvACL.ACL_CONTRACT_ADDRESS; - const implementationACLAddress = await upgrades.erc1967.getImplementationAddress(proxyACLAddress); - await run('verify:verify', { - address: implementationACLAddress, - constructorArguments: [], - }); - await run('verify:verify', { - address: proxyACLAddress, - constructorArguments: [], - }); -}); - -task('task:verifyTFHEExecutor').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvTFHEExecutor = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.exec')); - const proxyTFHEExecutorAddress = parsedEnvTFHEExecutor.TFHE_EXECUTOR_CONTRACT_ADDRESS; - const implementationTFHEExecutorAddress = await upgrades.erc1967.getImplementationAddress(proxyTFHEExecutorAddress); - await run('verify:verify', { - address: implementationTFHEExecutorAddress, - constructorArguments: [], - }); - await run('verify:verify', { - address: proxyTFHEExecutorAddress, - constructorArguments: [], - }); -}); - -task('task:verifyKMSVerifier').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvKMSVerifier = dotenv.parse( - fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'), - ); - const proxyKMSVerifier = parsedEnvKMSVerifier.KMS_VERIFIER_CONTRACT_ADDRESS; - const implementationKMSVerifierAddress = await upgrades.erc1967.getImplementationAddress(proxyKMSVerifier); - await run('verify:verify', { - address: implementationKMSVerifierAddress, - constructorArguments: [], - }); - await run('verify:verify', { - address: proxyKMSVerifier, - constructorArguments: [], - }); -}); - -task('task:verifyInputVerifier').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvInputVerifier = dotenv.parse( - fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.inputverifier'), - ); - const proxyInputVerifier = parsedEnvInputVerifier.INPUT_VERIFIER_CONTRACT_ADDRESS; - const implementationInputVerifierAddress = await upgrades.erc1967.getImplementationAddress(proxyInputVerifier); - await run('verify:verify', { - address: implementationInputVerifierAddress, - constructorArguments: [], - }); - await run('verify:verify', { - address: proxyInputVerifier, - constructorArguments: [], - }); -}); - -task('task:verifyFHEPayment').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvFHEPayment = dotenv.parse( - fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.fhepayment'), - ); - const proxyFHEPayment = parsedEnvFHEPayment.FHE_PAYMENT_CONTRACT_ADDRESS; - const implementationFHEPaymentAddress = await upgrades.erc1967.getImplementationAddress(proxyFHEPayment); - await run('verify:verify', { - address: implementationFHEPaymentAddress, - constructorArguments: [], - }); - await run('verify:verify', { - address: proxyFHEPayment, - constructorArguments: [], - }); -}); - -task('task:verifyGatewayContract').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvGateway = dotenv.parse(fs.readFileSync('gateway/.env.gateway')); - const proxyGateway = parsedEnvGateway.GATEWAY_CONTRACT_PREDEPLOY_ADDRESS; - const implementationGatewayAddress = await upgrades.erc1967.getImplementationAddress(proxyGateway); - await run('verify:verify', { - address: implementationGatewayAddress, - constructorArguments: [], - }); - await run('verify:verify', { - address: proxyGateway, - constructorArguments: [], - }); -}); diff --git a/tasks/taskDeploy.ts b/tasks/taskDeploy.ts index 1d4b0a0..03029ff 100644 --- a/tasks/taskDeploy.ts +++ b/tasks/taskDeploy.ts @@ -17,7 +17,7 @@ task('task:deployGateway') }); await Gateway.waitForDeployment(); const GatewayContractAddress = await Gateway.getAddress(); - const envConfig = dotenv.parse(fs.readFileSync('gateway/.env.gateway')); + const envConfig = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.gateway')); if (GatewayContractAddress !== envConfig.GATEWAY_CONTRACT_PREDEPLOY_ADDRESS) { throw new Error( `The nonce of the deployer account is not null. Please use another deployer private key or relaunch a clean instance of the fhEVM`, diff --git a/tasks/taskGatewayRelayer.ts b/tasks/taskGatewayRelayer.ts index a2da8d2..b5ebe64 100644 --- a/tasks/taskGatewayRelayer.ts +++ b/tasks/taskGatewayRelayer.ts @@ -23,13 +23,15 @@ task('task:computeGatewayAddress') from: deployerAddress, nonce: 1, // deployer is supposed to have nonce 0 when deploying GatewayContract (0 nonce for implementation, +1 for UUPS) }); - const envFilePath = path.join(__dirname, '../gateway/.env.gateway'); + const envFilePath = path.join(__dirname, '../node_modules/fhevm-core-contracts/addresses/.env.gateway'); const content = `GATEWAY_CONTRACT_PREDEPLOY_ADDRESS=${gatewayContractAddressPrecomputed}`; try { fs.writeFileSync(envFilePath, content, { flag: 'w' }); - console.log('gatewayContractAddress written to gateway/.env.gateway successfully!'); + console.log( + 'gatewayContractAddress written to node_modules/fhevm-core-contracts/addresses/.env.gateway successfully!', + ); } catch (err) { - console.error('Failed to write to gateway/.env.gateway:', err); + console.error('Failed to write to node_modules/fhevm-core-contracts/addresses/.env.gateway:', err); } const solidityTemplate = `// SPDX-License-Identifier: BSD-3-Clause-Clear @@ -40,10 +42,15 @@ address constant GATEWAY_CONTRACT_PREDEPLOY_ADDRESS = ${gatewayContractAddressPr `; try { - fs.writeFileSync('./gateway/lib/GatewayContractAddress.sol', solidityTemplate, { encoding: 'utf8', flag: 'w' }); - console.log('gateway/lib/GatewayContractAddress.sol file has been generated successfully.'); + fs.writeFileSync('node_modules/fhevm-core-contracts/addresses/GatewayContractAddress.sol', solidityTemplate, { + encoding: 'utf8', + flag: 'w', + }); + console.log( + 'node_modules/fhevm-core-contracts/addresses/GatewayContractAddress.sol file has been generated successfully.', + ); } catch (error) { - console.error('Failed to write gateway/lib/GatewayContractAddress.sol', error); + console.error('Failed to write node_modules/fhevm-core-contracts/addresses/GatewayContractAddress.sol', error); } }); @@ -115,7 +122,7 @@ task('task:launchFhevm') } await hre.run('task:deployGateway', { privateKey: privKeyDeployer, ownerAddress: deployerAddress }); - const parsedEnv = dotenv.parse(fs.readFileSync('gateway/.env.gateway')); + const parsedEnv = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.gateway')); const gatewayContractAddress = parsedEnv.GATEWAY_CONTRACT_PREDEPLOY_ADDRESS; await hre.run('task:addRelayer', { diff --git a/test/asyncDecrypt.ts b/test/asyncDecrypt.ts index 092a01f..65e6696 100644 --- a/test/asyncDecrypt.ts +++ b/test/asyncDecrypt.ts @@ -32,7 +32,7 @@ const currentTime = (): string => { return now.toLocaleTimeString('en-US', { hour12: true, hour: 'numeric', minute: 'numeric', second: 'numeric' }); }; -const parsedEnv = dotenv.parse(fs.readFileSync('gateway/.env.gateway')); +const parsedEnv = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.gateway')); let relayer: Wallet; if (networkName === 'hardhat') { const privKeyRelayer = process.env.PRIVATE_KEY_GATEWAY_RELAYER;