From fe5daa8710da22da117b7fb8f3f98dcc37ef9aba Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 13 Nov 2025 17:28:49 +0000 Subject: [PATCH 1/5] feat: automatically config enclave.config.yaml --- examples/CRISP/package.json | 3 + .../packages/crisp-contracts/deploy/crisp.ts | 5 +- .../packages/crisp-contracts/deploy/deploy.ts | 25 +++++- .../packages/crisp-contracts/package.json | 4 +- packages/enclave-contracts/package.json | 2 + packages/enclave-contracts/scripts/utils.ts | 88 +++++++++++++++++++ pnpm-lock.yaml | 26 +++--- 7 files changed, 139 insertions(+), 14 deletions(-) diff --git a/examples/CRISP/package.json b/examples/CRISP/package.json index 17f49d50d7..6aac9aacaf 100644 --- a/examples/CRISP/package.json +++ b/examples/CRISP/package.json @@ -18,6 +18,9 @@ "ciphernode:add": "pnpm -C packages/crisp-contracts ciphernode:add", "ciphernode:mint:tokens": "pnpm -C packages/crisp-contracts ciphernode:mint:tokens", "ciphernode:add:self": "pnpm -C packages/crisp-contracts ciphernode:add:self", + "deploy:contracts:full:mock": "pnpm -C packages/crisp-contracts deploy:contracts:full:mock", + "deploy:contracts:mock": "pnpm -C packages/crisp-contracts deploy:contracts:mock", + "deploy:contracts": "pnpm -C packages/crisp-contracts deploy:contracts", "test": "pnpm test:e2e", "test:circuits:inputs": "node --test test/governanceCircuit.test.ts", "test:circuits": "cd circuits && nargo test", diff --git a/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts b/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts index 4284f8e8aa..cc76a44837 100644 --- a/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts +++ b/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts @@ -10,7 +10,10 @@ import { } from "@enclave-e3/contracts/scripts"; import { Enclave__factory as EnclaveFactory } from "@enclave-e3/contracts/types"; -import { execSync } from "child_process"; +import path from "path"; +import fs from "fs"; + +import yaml from "js-yaml"; import hre from "hardhat"; const IMAGE_ID = diff --git a/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts b/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts index ce50ec1651..f5efc10d53 100644 --- a/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts +++ b/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts @@ -3,19 +3,42 @@ // This file is provided WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -import { deployEnclave } from "@enclave-e3/contracts/scripts"; +import { deployEnclave, updateE3Config } from "@enclave-e3/contracts/scripts"; import { deployCRISPContracts } from "./crisp"; +import path from "path"; + +import hre from "hardhat"; +import { fileURLToPath } from "url"; + +// Map contract names to config keys +const contractMapping: Record = { + CRISPProgram: "e3_program", + Enclave: "enclave", + CiphernodeRegistryOwnable: "ciphernode_registry", + BondingRegistry: "bonding_registry", + MockUSDC: "fee_token", +}; + +// Get __dirname equivalent in ES modules +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); /** * Deploys the Enclave and CRISP contracts */ export const deploy = async () => { + const chain = hre.globalOptions.network; + const shouldDeployEnclave = Boolean(process.env.DEPLOY_ENCLAVE) ?? false; if (shouldDeployEnclave) { await deployEnclave(true); } await deployCRISPContracts(); + + // this expects you to run it from CRISP's root + console.log("path:", path.join(__dirname, "..", "..", "..", "enclave.config.yaml")); + updateE3Config(chain, path.join(__dirname, "..", "..", "..", "enclave.config.yaml"), contractMapping); } deploy().catch((err => { diff --git a/examples/CRISP/packages/crisp-contracts/package.json b/examples/CRISP/packages/crisp-contracts/package.json index 55c1af5281..4fc5c49aec 100644 --- a/examples/CRISP/packages/crisp-contracts/package.json +++ b/examples/CRISP/packages/crisp-contracts/package.json @@ -46,6 +46,8 @@ "solady": "^0.1.13" }, "devDependencies": { + "@crisp-e3/sdk": "workspace:^", + "@crisp-e3/zk-inputs": "workspace:^", "@nomicfoundation/hardhat-ethers": "4", "@nomicfoundation/hardhat-ethers-chai-matchers": "^3.0.0", "@nomicfoundation/hardhat-network-helpers": "3", @@ -60,8 +62,6 @@ "@types/mocha": ">=9.1.0", "@types/node": "^22.18.0", "chai": "^6.2.0", - "@crisp-e3/sdk": "workspace:^", - "@crisp-e3/zk-inputs": "workspace:^", "dotenv": "^16.4.5", "ethers": "^6.15.0", "forge-std": "github:foundry-rs/forge-std#v1.9.4", diff --git a/packages/enclave-contracts/package.json b/packages/enclave-contracts/package.json index 605933bf97..2540fccc76 100644 --- a/packages/enclave-contracts/package.json +++ b/packages/enclave-contracts/package.json @@ -88,6 +88,7 @@ "@types/chai": "^4.3.20", "@types/chai-as-promised": "^8.0.2", "@types/fs-extra": "^11.0.4", + "@types/js-yaml": "^4.0.9", "@types/mocha": "^10.0.10", "@types/node": "^22.18.0", "@typescript-eslint/eslint-plugin": "^7.11.0", @@ -173,6 +174,7 @@ "dependencies": { "@openzeppelin/contracts-upgradeable": "^5.0.2", "@zk-kit/lean-imt.sol": "2.0.1", + "js-yaml": "^4.1.1", "poseidon-solidity": "0.0.5" }, "packageManager": "pnpm@10.7.1+sha512.2d92c86b7928dc8284f53494fb4201f983da65f0fb4f0d40baafa5cf628fa31dae3e5968f12466f17df7e97310e30f343a648baea1b9b350685dafafffdf5808" diff --git a/packages/enclave-contracts/scripts/utils.ts b/packages/enclave-contracts/scripts/utils.ts index 857dfd79ae..6df8cc0f13 100644 --- a/packages/enclave-contracts/scripts/utils.ts +++ b/packages/enclave-contracts/scripts/utils.ts @@ -4,6 +4,7 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. import fs from "fs"; +import yaml from "js-yaml"; import path from "path"; export const deploymentsFile = path.join("deployed_contracts.json"); @@ -26,6 +27,26 @@ export interface Deployments { [chainName: string]: ChainDeployments; } +/** + * Defines the Enclave.config.yaml structure + */ +export interface EnclaveConfig { + chains: Array<{ + name: string; + rpc_url: string; + contracts: { + e3_program?: { address: string; deploy_block: number }; + enclave?: { address: string; deploy_block: number }; + ciphernode_registry?: { address: string; deploy_block: number }; + bonding_registry?: { address: string; deploy_block: number }; + fee_token?: { address: string; deploy_block: number }; + }; + }>; + // we don't care about the below fields + program: unknown; + nodes: unknown; +} + /** * Store the deployment arguments for a given contract and chain * @param args - The deployment arguments to store @@ -140,3 +161,70 @@ export function areArraysEqual(arr1: T[], arr2: T[]): boolean { return true; } + +/** + * The function to update the encalve.config.yaml file with the deployed contract addresses + * @param chainToConfig - The chain name to update in the config + * @param pathToConfigFile - The path to the enclave.config.yaml file + * @param contractMapping - A mapping of contract names to config keys + */ +export const updateE3Config = ( + chainToConfig: string, + pathToConfigFile: string, + contractMapping: Record, + rpcUrl?: string, +): void => { + const fileContent = fs.readFileSync(pathToConfigFile, "utf8"); + const config = yaml.load(fileContent) as EnclaveConfig; + + // Find the hardhat chain config + // Find the chain config or create it + let configChain = config.chains.find((chain) => chain.name === chainToConfig); + + if (!configChain) { + console.log( + `Chain "${chainToConfig}" not found in config. Creating new entry...`, + ); + + if (!rpcUrl) { + console.warn( + "Warning: No RPC URL provided. You'll need to update it manually in the config.", + ); + } + + configChain = { + name: chainToConfig, + rpc_url: rpcUrl || `ws://localhost:8545`, + contracts: {}, + }; + + config.chains.push(configChain); + console.log(`āœ“ Created new chain entry for "${chainToConfig}"`); + } + + console.log(`\nUpdating contracts for chain: ${chainToConfig}`); + + // Update contract addresses and deploy blocks + for (const [contractName, configKey] of Object.entries(contractMapping)) { + const deployment = readDeploymentArgs(contractName, chainToConfig); + + if (deployment) { + configChain.contracts[configKey as keyof typeof configChain.contracts] = { + address: deployment.address, + deploy_block: deployment.blockNumber ?? 1, + }; + console.log( + `āœ“ Updated ${configKey}: ${deployment.address} (block ${deployment.blockNumber ?? 1})`, + ); + } + } + + // Write updated config back to file + const yamlStr = yaml.dump(config, { + indent: 2, + lineWidth: -1, // Don't wrap lines + }); + + fs.writeFileSync(pathToConfigFile, yamlStr, "utf8"); + console.log("\nāœ“ enclave.config.yaml updated successfully!"); +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3530c00ffc..1578f1f6c1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -409,6 +409,9 @@ importers: '@zk-kit/lean-imt.sol': specifier: 2.0.1 version: 2.0.1 + js-yaml: + specifier: ^4.1.1 + version: 4.1.1 poseidon-solidity: specifier: 0.0.5 version: 0.0.5 @@ -458,6 +461,9 @@ importers: '@types/fs-extra': specifier: ^11.0.4 version: 11.0.4 + '@types/js-yaml': + specifier: ^4.0.9 + version: 4.0.9 '@types/mocha': specifier: ^10.0.10 version: 10.0.10 @@ -6760,8 +6766,8 @@ packages: resolution: {integrity: sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==} hasBin: true - js-yaml@4.1.0: - resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==} + js-yaml@4.1.1: + resolution: {integrity: sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==} hasBin: true jsesc@2.5.2: @@ -11282,7 +11288,7 @@ snapshots: globals: 13.24.0 ignore: 5.3.2 import-fresh: 3.3.1 - js-yaml: 4.1.0 + js-yaml: 4.1.1 minimatch: 3.1.2 strip-json-comments: 3.1.1 transitivePeerDependencies: @@ -15958,7 +15964,7 @@ snapshots: cosmiconfig@8.3.6(typescript@5.8.3): dependencies: import-fresh: 3.3.1 - js-yaml: 4.1.0 + js-yaml: 4.1.1 parse-json: 5.2.0 path-type: 4.0.0 optionalDependencies: @@ -16684,7 +16690,7 @@ snapshots: imurmurhash: 0.1.4 is-glob: 4.0.3 is-path-inside: 3.0.3 - js-yaml: 4.1.0 + js-yaml: 4.1.1 json-stable-stringify-without-jsonify: 1.0.1 levn: 0.4.1 lodash.merge: 4.6.2 @@ -18078,7 +18084,7 @@ snapshots: argparse: 1.0.10 esprima: 4.0.1 - js-yaml@4.1.0: + js-yaml@4.1.1: dependencies: argparse: 2.0.1 @@ -19125,7 +19131,7 @@ snapshots: find-up: 5.0.0 glob: 8.1.0 he: 1.2.0 - js-yaml: 4.1.0 + js-yaml: 4.1.1 log-symbols: 4.1.0 minimatch: 5.1.6 ms: 2.1.3 @@ -19148,7 +19154,7 @@ snapshots: glob: 10.4.5 he: 1.2.0 is-path-inside: 3.0.3 - js-yaml: 4.1.0 + js-yaml: 4.1.1 log-symbols: 4.1.0 minimatch: 9.0.5 ms: 2.1.3 @@ -20667,7 +20673,7 @@ snapshots: fs-extra: 11.3.2 glob: 8.1.0 ignore: 5.3.2 - js-yaml: 4.1.0 + js-yaml: 4.1.1 latest-version: 7.0.0 lodash: 4.17.21 pluralize: 8.0.0 @@ -21527,7 +21533,7 @@ snapshots: dependencies: '@types/js-yaml': 4.0.9 is-buffer: 2.0.5 - js-yaml: 4.1.0 + js-yaml: 4.1.1 vfile-message@3.1.4: dependencies: From 69aa077b7f913ac1eacc465e32b9ac2649129e2b Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 13 Nov 2025 17:33:13 +0000 Subject: [PATCH 2/5] chore: remove redundant code --- examples/CRISP/packages/crisp-contracts/deploy/crisp.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts b/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts index cc76a44837..fcb2ef147b 100644 --- a/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts +++ b/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts @@ -10,10 +10,6 @@ import { } from "@enclave-e3/contracts/scripts"; import { Enclave__factory as EnclaveFactory } from "@enclave-e3/contracts/types"; -import path from "path"; -import fs from "fs"; - -import yaml from "js-yaml"; import hre from "hardhat"; const IMAGE_ID = From bb945c46529f691f7c618e68cb7f62a0185d7761 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 13 Nov 2025 17:40:46 +0000 Subject: [PATCH 3/5] chore: typo --- packages/enclave-contracts/scripts/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/enclave-contracts/scripts/utils.ts b/packages/enclave-contracts/scripts/utils.ts index 6df8cc0f13..5744f1ff3f 100644 --- a/packages/enclave-contracts/scripts/utils.ts +++ b/packages/enclave-contracts/scripts/utils.ts @@ -163,7 +163,7 @@ export function areArraysEqual(arr1: T[], arr2: T[]): boolean { } /** - * The function to update the encalve.config.yaml file with the deployed contract addresses + * The function to update the enclave.config.yaml file with the deployed contract addresses * @param chainToConfig - The chain name to update in the config * @param pathToConfigFile - The path to the enclave.config.yaml file * @param contractMapping - A mapping of contract names to config keys From abd4fcef2f20f05b5f9d5496b8bdbddf24932dec Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 13 Nov 2025 21:14:00 +0100 Subject: [PATCH 4/5] chore: remove console log --- examples/CRISP/packages/crisp-contracts/deploy/deploy.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts b/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts index f5efc10d53..2e4e5c7f1d 100644 --- a/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts +++ b/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts @@ -37,7 +37,6 @@ export const deploy = async () => { await deployCRISPContracts(); // this expects you to run it from CRISP's root - console.log("path:", path.join(__dirname, "..", "..", "..", "enclave.config.yaml")); updateE3Config(chain, path.join(__dirname, "..", "..", "..", "enclave.config.yaml"), contractMapping); } From 27ab50476d0d610ef0ed74ce9ea85a9385384933 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 13 Nov 2025 21:27:39 +0100 Subject: [PATCH 5/5] chore: add newline at end of yaml --- packages/enclave-contracts/scripts/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/enclave-contracts/scripts/utils.ts b/packages/enclave-contracts/scripts/utils.ts index 5744f1ff3f..d5af556ec7 100644 --- a/packages/enclave-contracts/scripts/utils.ts +++ b/packages/enclave-contracts/scripts/utils.ts @@ -225,6 +225,6 @@ export const updateE3Config = ( lineWidth: -1, // Don't wrap lines }); - fs.writeFileSync(pathToConfigFile, yamlStr, "utf8"); + fs.writeFileSync(pathToConfigFile, yamlStr + "\n", "utf8"); console.log("\nāœ“ enclave.config.yaml updated successfully!"); };