Skip to content

Commit

Permalink
Merge branch 'main' into ry/123-datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
ryardley authored Oct 22, 2024
2 parents 655da02 + c30f1b4 commit f7cdeb8
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 108 deletions.
6 changes: 4 additions & 2 deletions packages/evm/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
MNEMONIC=
INFURA_KEY=
ETHERSCAN_API_KEY=

ETHERSCAN_API_KEY=
# only one of the following should be set
PRIVATE_KEY=
MNEMONIC=
1 change: 1 addition & 0 deletions packages/evm/contracts/Enclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ contract Enclave is IEnclave, OwnableUpgradeable {
e3 = E3({
seed: seed,
threshold: threshold,
requestBlock: block.number,
startWindow: startWindow,
duration: duration,
expiration: 0,
Expand Down
2 changes: 2 additions & 0 deletions packages/evm/contracts/interfaces/IE3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IDecryptionVerifier } from "./IDecryptionVerifier.sol";
/// @title E3 struct
/// @notice This struct represents an E3 computation.
/// @param threshold M/N threshold for the committee.
/// @param requestBlock Block number when the E3 was requested.
/// @param startWindow Start window for the computation: index zero is minimum, index 1 is the maxium.
/// @param duration Duration of the E3.
/// @param expiration Timestamp when committee duties expire.
Expand All @@ -21,6 +22,7 @@ import { IDecryptionVerifier } from "./IDecryptionVerifier.sol";
struct E3 {
uint256 seed;
uint32[2] threshold;
uint256 requestBlock;
uint256[2] startWindow;
uint256 duration;
uint256 expiration;
Expand Down
10 changes: 10 additions & 0 deletions packages/evm/contracts/registry/NaiveRegistryFilter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable {
error CommitteeAlreadyPublished();
error CommitteeDoesNotExist();
error CommitteeNotPublished();
error CiphernodeNotEnabled(address ciphernode);
error OnlyRegistry();

////////////////////////////////////////////////////////////
Expand All @@ -47,6 +48,15 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable {
_;
}

modifier onlyOwnerOrCiphernode() {
require(
msg.sender == owner() ||
ICiphernodeRegistry(registry).isCiphernodeEligible(msg.sender),
CiphernodeNotEnabled(msg.sender)
);
_;
}

////////////////////////////////////////////////////////////
// //
// Initialization //
Expand Down
66 changes: 33 additions & 33 deletions packages/evm/deployments/sepolia/CiphernodeRegistryOwnable.json

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions packages/evm/deployments/sepolia/Enclave.json

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions packages/evm/deployments/sepolia/NaiveRegistryFilter.json

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions packages/evm/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ import "./tasks/enclave";

dotenv.config();

const { INFURA_KEY, MNEMONIC, ETHERSCAN_API_KEY } = process.env;
const { INFURA_KEY, MNEMONIC, PRIVATE_KEY, ETHERSCAN_API_KEY } = process.env;

if (!INFURA_KEY || !MNEMONIC || !ETHERSCAN_API_KEY) {
console.error(
"Please set the INFURA_KEY, MNEMONIC, and ETHERSCAN_API_KEY environment variables",
if (!INFURA_KEY || !ETHERSCAN_API_KEY) {
console.warn(
"Please set the INFURA_KEY, and ETHERSCAN_API_KEY environment variables to deploy and verify contracts",
);
}

if (!MNEMONIC && !PRIVATE_KEY) {
console.warn(
"Please set a mnemonic or private key to deploy contracts. If you set neither, hardhat will use a default mnemonic",
);
}

Expand Down Expand Up @@ -49,12 +55,16 @@ function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {
default:
jsonRpcUrl = "https://" + chain + ".infura.io/v3/" + infuraApiKey;
}

let accounts;
if (PRIVATE_KEY) {
accounts = [PRIVATE_KEY];
} else {
accounts = { mnemonic };
}

return {
accounts: {
count: 10,
mnemonic,
path: "m/44'/60'/0'/0",
},
accounts,
chainId: chainIds[chain],
url: jsonRpcUrl,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,17 @@ describe("CiphernodeRegistryOwnable", function () {
.withArgs(notTheOwner.address);
});
it("removes the ciphernode from the registry", async function () {
const { registry, tree } = await loadFixture(setup);
const { registry } = await loadFixture(setup);
const tree = new LeanIMT(hash);
tree.insert(BigInt(AddressOne));
tree.insert(BigInt(AddressTwo));
const index = tree.indexOf(BigInt(AddressOne));
const proof = tree.generateProof(index);
tree.update(index, BigInt(0));
expect(await registry.isEnabled(AddressOne)).to.be.true;
expect(await registry.removeCiphernode(AddressOne, proof.siblings));
expect(await registry.isEnabled(AddressOne)).to.be.false;
expect(await registry.root()).to.equal(tree.root);
});
it("decrements numCiphernodes", async function () {
const { registry, tree } = await loadFixture(setup);
Expand Down
2 changes: 2 additions & 0 deletions packages/evm/test/Enclave.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,12 @@ describe("Enclave", function () {
{ value: 10 },
);
const e3 = await enclave.getE3(0);
const block = await ethers.provider.getBlock("latest").catch((e) => e);

expect(e3.threshold).to.deep.equal(request.threshold);
expect(e3.expiration).to.equal(0n);
expect(e3.e3Program).to.equal(request.e3Program);
expect(e3.requestBlock).to.equal(block.number);
expect(e3.inputValidator).to.equal(
await mocks.inputValidator.getAddress(),
);
Expand Down

0 comments on commit f7cdeb8

Please sign in to comment.