generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add e3 specific tasks, some file cleanup
- Loading branch information
Showing
3 changed files
with
246 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}); |