Skip to content

Commit

Permalink
add e3 specific tasks, some file cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
samepant committed Sep 17, 2024
1 parent 9e149e1 commit c689935
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 131 deletions.
9 changes: 1 addition & 8 deletions packages/evm/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { NetworkUserConfig } from "hardhat/types";

import "./tasks/accounts";
import "./tasks/ciphernode";
import "./tasks/committee";
import "./tasks/enclave";

dotenv.config();

Expand Down Expand Up @@ -90,13 +90,6 @@ const config: HardhatUserConfig = {
chainId: chainIds.hardhat,
allowUnlimitedContractSize: true,
},
ganache: {
accounts: {
mnemonic,
},
chainId: chainIds.ganache,
url: "http://localhost:8545",
},
arbitrum: getChainConfig("arbitrum-mainnet"),
avalanche: getChainConfig("avalanche"),
bsc: getChainConfig("bsc"),
Expand Down
123 changes: 0 additions & 123 deletions packages/evm/tasks/committee.ts

This file was deleted.

245 changes: 245 additions & 0 deletions packages/evm/tasks/enclave.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
import { task, types } from "hardhat/config";
import type { TaskArguments } from "hardhat/types";

task(
"committee:new",
"Request a new ciphernode committee, will use E3 mock contracts by default",
)
.addOptionalParam(
"filter",
"address of filter contract to use",
undefined,
types.string,
)
.addOptionalParam(
"thresholdQuorum",
"threshold quorum for committee",
2,
types.int,
)
.addOptionalParam(
"thresholdTotal",
"threshold total for committee",
2,
types.int,
)
.addOptionalParam(
"windowStart",
"timestamp start of window for the E3 (default: now)",
Math.floor(Date.now() / 1000),
types.int,
)
.addOptionalParam(
"windowEnd",
"timestamp end of window for the E3 (default: now + 1 day)",
Math.floor(Date.now() / 1000) + 86400,
types.int,
)
.addOptionalParam(
"duration",
"duration in seconds of the E3 (default: 1 day)",
86400,
types.int,
)
.addOptionalParam(
"e3Address",
"address of the E3 program",
undefined,
types.string,
)
.addOptionalParam(
"e3Params",
"parameters for the E3 program",
"0x0000000000000000000000009f3ebc4f6be495901a29bba2ae5a45fb870cdc14",
types.string,
)
.addOptionalParam(
"computeParams",
"parameters for the compute provider",
"0x000000000000000000000000404af1c0780a9269e4d3308a0812fb87bf5fc490",
types.string,
)
.setAction(async function (taskArguments: TaskArguments, hre) {
const enclave = await hre.deployments.get("Enclave");

const enclaveContract = await hre.ethers.getContractAt(
"Enclave",
enclave.address,
);

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) {
console.log("E3 program enabling failed, probably already enabled: ", e);
}

const tx = await enclaveContract.request(
filterAddress,
[taskArguments.thresholdQuorum, taskArguments.thresholdTotal],
[taskArguments.windowStart, taskArguments.windowEnd],
taskArguments.duration,
e3Address,
taskArguments.e3Params,
taskArguments.computeParams,
// 1 ETH
{ value: "1000000000000000000" },
);

console.log("Reequesting committee... ", tx.hash);
await tx.wait();

console.log(`Committee requested`);
});

task("committee:publish", "Publish the publickey of the committee")
.addOptionalParam(
"filter",
"address of filter contract to use (defaults to NaiveRegistryFilter)",
)
.addParam("e3Id", "Id of the E3 program", undefined, types.int)
.addParam(
"nodes",
"list of node address in the committee, comma separated",
undefined,
types.string,
)
.addParam("publicKey", "public key of the committee", undefined, types.string)
.setAction(async function (taskArguments: TaskArguments, hre) {
let filterAddress = taskArguments.filter;
if (!taskArguments.filter) {
filterAddress = (await hre.deployments.get("NaiveRegistryFilter"))
.address;

if (!filterAddress) {
throw new Error("NaiveRegistryFilter not deployed");
}
}

const filterContract = await hre.ethers.getContractAt(
"NaiveRegistryFilter",
filterAddress,
);

const nodes = taskArguments.nodes.split(",");

if (!Array.isArray(nodes)) {
throw new Error(
"Could not parse nodes: Nodes must be input as comma separated list",
);
}

const tx = await filterContract.publishCommittee(
taskArguments.e3Id,
nodes,
taskArguments.publicKey,
);

console.log("Publishing committee... ", tx.hash);
await tx.wait();
console.log(`Committee public key published`);
});

task("e3:activate", "Activate an E3 program")
.addParam("e3Id", "Id of the E3 program")
.setAction(async function (taskArguments: TaskArguments, hre) {
const enclave = await hre.deployments.get("Enclave");

const enclaveContract = await hre.ethers.getContractAt(
"Enclave",
enclave.address,
);

const tx = await enclaveContract.activate(taskArguments.e3Id);

console.log("Activating E3 program... ", tx.hash);
await tx.wait();

console.log(`E3 program activated`);
});

task("e3:publishInput", "Publish input for an E3 program")
.addParam("e3Id", "Id of the E3 program")
.addParam("data", "data to publish")
.setAction(async function (taskArguments: TaskArguments, hre) {
const enclave = await hre.deployments.get("Enclave");

const enclaveContract = await hre.ethers.getContractAt(
"Enclave",
enclave.address,
);

const tx = await enclaveContract.publishInput(
taskArguments.e3Id,
taskArguments.data,
);

console.log("Publishing input... ", tx.hash);
await tx.wait();

console.log(`Input published`);
});

task("e3:publishCiphertext", "Publish ciphertext output for an E3 program")
.addParam("e3Id", "Id of the E3 program")
.addParam("data", "data to publish")
.setAction(async function (taskArguments: TaskArguments, hre) {
const enclave = await hre.deployments.get("Enclave");

const enclaveContract = await hre.ethers.getContractAt(
"Enclave",
enclave.address,
);

const tx = await enclaveContract.publishCiphertextOutput(
taskArguments.e3Id,
taskArguments.data,
);

console.log("Publishing ciphertext... ", tx.hash);
await tx.wait();

console.log(`Ciphertext published`);
});

task("e3:publishPlaintext", "Publish plaintext output for an E3 program")
.addParam("e3Id", "Id of the E3 program")
.addParam("data", "data to publish")
.setAction(async function (taskArguments: TaskArguments, hre) {
const enclave = await hre.deployments.get("Enclave");

const enclaveContract = await hre.ethers.getContractAt(
"Enclave",
enclave.address,
);

const tx = await enclaveContract.publishPlaintextOutput(
taskArguments.e3Id,
taskArguments.data,
);

console.log("Publishing ciphertext... ", tx.hash);
await tx.wait();

console.log(`Ciphertext published`);
});

0 comments on commit c689935

Please sign in to comment.