From 3cde5848d3eacba060c5eaa8aabd33b9a5b6d08c Mon Sep 17 00:00:00 2001 From: samepant Date: Tue, 17 Sep 2024 12:06:34 -0400 Subject: [PATCH 1/5] add mock deployment for testing --- packages/evm/deploy/{deploy.ts => enclave.ts} | 3 +- packages/evm/deploy/mocks.ts | 33 +++++++++++++ packages/evm/package.json | 3 +- packages/evm/tasks/committee.ts | 48 +++++++++++++------ 4 files changed, 69 insertions(+), 18 deletions(-) rename packages/evm/deploy/{deploy.ts => enclave.ts} (96%) create mode 100644 packages/evm/deploy/mocks.ts diff --git a/packages/evm/deploy/deploy.ts b/packages/evm/deploy/enclave.ts similarity index 96% rename from packages/evm/deploy/deploy.ts rename to packages/evm/deploy/enclave.ts index bde42ba0..207be341 100644 --- a/packages/evm/deploy/deploy.ts +++ b/packages/evm/deploy/enclave.ts @@ -94,5 +94,4 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { console.log(`Enclave contract updated with registry`); }; export default func; -func.id = "deploy_enclave"; // id required to prevent reexecution -func.tags = ["Enclave"]; +func.tags = ["enclave"]; diff --git a/packages/evm/deploy/mocks.ts b/packages/evm/deploy/mocks.ts new file mode 100644 index 00000000..623ebaf7 --- /dev/null +++ b/packages/evm/deploy/mocks.ts @@ -0,0 +1,33 @@ +import { DeployFunction } from "hardhat-deploy/types"; +import { HardhatRuntimeEnvironment } from "hardhat/types"; + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + const { deployer } = await hre.getNamedAccounts(); + const { deploy } = hre.deployments; + + await deploy("MockE3Program", { + from: deployer, + args: [], + log: true, + }); + + await deploy("MockComputeProvider", { + from: deployer, + args: [], + log: true, + }); + + await deploy("MockDecryptionVerifier", { + from: deployer, + args: [], + log: true, + }); + + await deploy("MockInputValidator", { + from: deployer, + args: [], + log: true, + }); +}; +export default func; +func.tags = ["mocks"]; diff --git a/packages/evm/package.json b/packages/evm/package.json index 6dae0e66..698ba42c 100644 --- a/packages/evm/package.json +++ b/packages/evm/package.json @@ -72,7 +72,8 @@ "clean": "rimraf ./artifacts ./cache ./coverage ./types ./coverage.json && yarn typechain", "compile": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile", "coverage": "hardhat coverage --solcoverjs ./.solcover.js --temp artifacts --testfiles \"test/**/*.ts\" && yarn typechain", - "deploy": "hardhat deploy", + "deploy": "hardhat deploy --tags enclave", + "deploy:mocks": "hardhat deploy --tags enclave,mocks", "ciphernode:add": "hardhat ciphernode:add", "ciphernode:remove": "hardhat ciphernode:remove", "lint": "yarn lint:sol && yarn lint:ts && yarn prettier:check", diff --git a/packages/evm/tasks/committee.ts b/packages/evm/tasks/committee.ts index f4f8eaad..77004568 100644 --- a/packages/evm/tasks/committee.ts +++ b/packages/evm/tasks/committee.ts @@ -1,11 +1,14 @@ import { task, types } from "hardhat/config"; import type { TaskArguments } from "hardhat/types"; -task("committee:new", "Request a new ciphernode committee") +task( + "committee:new", + "Request a new ciphernode committee, will use E3 mock contracts by default", +) .addOptionalParam( "filter", "address of filter contract to use", - "0x0000000000000000000000000000000000000006", + undefined, types.string, ) .addOptionalParam( @@ -41,7 +44,7 @@ task("committee:new", "Request a new ciphernode committee") .addOptionalParam( "e3Address", "address of the E3 program", - "0x95E366f13c16976A26339aBe7992a1AB523388f5", + undefined, types.string, ) .addOptionalParam( @@ -64,34 +67,49 @@ task("committee:new", "Request a new ciphernode committee") enclave.address, ); - try { - const enableE3Tx = await enclaveContract.enableE3Program( - taskArguments.e3Address, + let e3Address = taskArguments.e3Address; + if (!e3Address) { + const mockE3Program = await hre.deployments.get("MockE3Program"); + if (!mockE3Program) { + throw new Error("MockE3Program not deployed"); + } + e3Address = mockE3Program.address; + } + + let filterAddress = taskArguments.filter; + if (!filterAddress) { + const naiveRegistryFilter = await hre.deployments.get( + "NaiveRegistryFilter", ); + if (!naiveRegistryFilter) { + throw new Error("NaiveRegistryFilter not deployed"); + } + filterAddress = naiveRegistryFilter.address; + } + + try { + const enableE3Tx = await enclaveContract.enableE3Program(e3Address); await enableE3Tx.wait(); - } catch (e: unknown) { - console.log( - "E3 program enabling failed, probably already enabled: ", - e.message, - ); + } catch (e) { + console.log("E3 program enabling failed, probably already enabled: ", e); } console.log( "requesting committee...", - taskArguments.filter, + filterAddress, [taskArguments.thresholdQuorum, taskArguments.thresholdTotal], [taskArguments.windowStart, taskArguments.windowEnd], taskArguments.duration, - taskArguments.e3Address, + e3Address, taskArguments.e3Params, taskArguments.computeParams, ); const tx = await enclaveContract.request( - taskArguments.filter, + filterAddress, [taskArguments.thresholdQuorum, taskArguments.thresholdTotal], [taskArguments.windowStart, taskArguments.windowEnd], taskArguments.duration, - taskArguments.e3Address, + e3Address, taskArguments.e3Params, taskArguments.computeParams, // 1 ETH From 238460787e25c7cba8e8d5dab00ec1ecae295fdf Mon Sep 17 00:00:00 2001 From: samepant Date: Tue, 17 Sep 2024 12:10:49 -0400 Subject: [PATCH 2/5] fix threshold initialization check --- packages/evm/contracts/registry/NaiveRegistryFilter.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/evm/contracts/registry/NaiveRegistryFilter.sol b/packages/evm/contracts/registry/NaiveRegistryFilter.sol index 7d122e9e..b8113378 100644 --- a/packages/evm/contracts/registry/NaiveRegistryFilter.sol +++ b/packages/evm/contracts/registry/NaiveRegistryFilter.sol @@ -74,7 +74,7 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable { uint32[2] calldata threshold ) external onlyRegistry returns (bool success) { Committee storage committee = committees[e3Id]; - require(committee.threshold.length == 0, CommitteeAlreadyExists()); + require(committee.threshold[1] == 0, CommitteeAlreadyExists()); committee.threshold = threshold; success = true; } From da694c29e15a460546a3c0927384001a7be1b7ce Mon Sep 17 00:00:00 2001 From: samepant Date: Tue, 17 Sep 2024 12:13:03 -0400 Subject: [PATCH 3/5] more efficient committee initialization --- packages/evm/contracts/registry/NaiveRegistryFilter.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/evm/contracts/registry/NaiveRegistryFilter.sol b/packages/evm/contracts/registry/NaiveRegistryFilter.sol index b8113378..127b50e4 100644 --- a/packages/evm/contracts/registry/NaiveRegistryFilter.sol +++ b/packages/evm/contracts/registry/NaiveRegistryFilter.sol @@ -73,9 +73,8 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable { uint256 e3Id, uint32[2] calldata threshold ) external onlyRegistry returns (bool success) { - Committee storage committee = committees[e3Id]; - require(committee.threshold[1] == 0, CommitteeAlreadyExists()); - committee.threshold = threshold; + require(committees[e3Id].threshold[1] == 0, CommitteeAlreadyExists()); + committees[e3Id].threshold = threshold; success = true; } From 5af6ab5e4ef5f99614827132e75002a260a46584 Mon Sep 17 00:00:00 2001 From: samepant Date: Tue, 17 Sep 2024 12:13:29 -0400 Subject: [PATCH 4/5] remove broken task --- packages/evm/tasks/ciphernode.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/packages/evm/tasks/ciphernode.ts b/packages/evm/tasks/ciphernode.ts index c6b919bf..a66bb264 100644 --- a/packages/evm/tasks/ciphernode.ts +++ b/packages/evm/tasks/ciphernode.ts @@ -18,21 +18,3 @@ task("ciphernode:add", "Register a ciphernode to the registry") console.log(`Ciphernode ${taskArguments.ciphernodeAddress} registered`); }); - -task("ciphernode:remove", "Remove a ciphernode from the registry") - .addParam("ciphernodeAddress", "address of ciphernode to remove") - .setAction(async function (taskArguments: TaskArguments, hre) { - const registry = await hre.deployments.get("CiphernodeRegistryOwnable"); - - const registryContract = await hre.ethers.getContractAt( - "CiphernodeRegistryOwnable", - registry.address, - ); - - const tx = await registryContract.removeCiphernode( - taskArguments.ciphernodeAddress, - ); - await tx.wait(); - - console.log(`Ciphernode ${taskArguments.ciphernodeAddress} removed`); - }); From 5aaadcb154084ca0d0dcc80d4e50bce9a3f53b27 Mon Sep 17 00:00:00 2001 From: samepant Date: Tue, 17 Sep 2024 12:14:43 -0400 Subject: [PATCH 5/5] ignore localhost deployment files --- packages/evm/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/evm/.gitignore b/packages/evm/.gitignore index e812c153..2b590893 100644 --- a/packages/evm/.gitignore +++ b/packages/evm/.gitignore @@ -9,6 +9,7 @@ coverage dist node_modules types +deployments/localhost # files *.env