Skip to content

Commit

Permalink
CypherNode --> Cyphernode
Browse files Browse the repository at this point in the history
  • Loading branch information
auryn-macmillan committed Jun 4, 2024
1 parent c4a7623 commit 404a4ef
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
28 changes: 14 additions & 14 deletions packages/evm/contracts/Enclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.8.26;

import { IEnclave, E3, IComputationModule, IExecutionModule } from "./interfaces/IEnclave.sol";
import { ICypherNodeRegistry } from "./interfaces/ICypherNodeRegistry.sol";
import { ICyphernodeRegistry } from "./interfaces/ICyphernodeRegistry.sol";
import { IInputValidator } from "./interfaces/IInputValidator.sol";
import { IOutputVerifier } from "./interfaces/IOutputVerifier.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
Expand All @@ -14,7 +14,7 @@ contract Enclave is IEnclave, OwnableUpgradeable {
// //
////////////////////////////////////////////////////////////

ICypherNodeRegistry public cypherNodeRegistry; // TODO: add a setter function.
ICyphernodeRegistry public cyphernodeRegistry; // TODO: add a setter function.
uint256 public maxDuration; // TODO: add a setter function.
uint256 public nexte3Id; // ID of the next E3.
uint256 public requests; // total number of requests made to Enclave.
Expand Down Expand Up @@ -47,7 +47,7 @@ contract Enclave is IEnclave, OwnableUpgradeable {
error InputDeadlineNotPassed(uint256 e3Id, uint256 expiration);
error InvalidComputation();
error InvalidExecutionModuleSetup();
error InvalidCypherNodeRegistry(ICypherNodeRegistry cypherNodeRegistry);
error InvalidCyphernodeRegistry(ICyphernodeRegistry cyphernodeRegistry);
error InvalidInput();
error InvalidDuration(uint256 duration);
error InvalidOutput();
Expand All @@ -65,20 +65,20 @@ contract Enclave is IEnclave, OwnableUpgradeable {

/// @param _owner The owner of this contract
/// @param _maxDuration The maximum duration of a computation in seconds
constructor(address _owner, ICypherNodeRegistry _cypherNodeRegistry, uint256 _maxDuration) {
initialize(_owner, _cypherNodeRegistry, _maxDuration);
constructor(address _owner, ICyphernodeRegistry _cyphernodeRegistry, uint256 _maxDuration) {
initialize(_owner, _cyphernodeRegistry, _maxDuration);
}

/// @param _owner The owner of this contract
/// @param _maxDuration The maximum duration of a computation in seconds
function initialize(
address _owner,
ICypherNodeRegistry _cypherNodeRegistry,
ICyphernodeRegistry _cyphernodeRegistry,
uint256 _maxDuration
) public initializer {
__Ownable_init(msg.sender);
setMaxDuration(_maxDuration);
setCypherNodeRegistry(_cypherNodeRegistry);
setCyphernodeRegistry(_cyphernodeRegistry);
if (_owner != owner()) transferOwnership(_owner);
}

Expand Down Expand Up @@ -130,7 +130,7 @@ contract Enclave is IEnclave, OwnableUpgradeable {
});
e3s[e3Id] = e3;

require(cypherNodeRegistry.selectCommittee(e3Id, pool, threshold), CommitteeSelectionFailed());
require(cyphernodeRegistry.selectCommittee(e3Id, pool, threshold), CommitteeSelectionFailed());
// TODO: validate that the selected pool accepts both the computation and execution modules.

emit E3Requested(e3Id, e3s[e3Id], pool, computationModule, executionModule);
Expand All @@ -142,7 +142,7 @@ contract Enclave is IEnclave, OwnableUpgradeable {
E3 memory e3 = getE3(e3Id);
require(e3.expiration == 0, E3AlreadyActivated(e3Id));

bytes memory committeePublicKey = cypherNodeRegistry.getCommitteePublicKey(e3Id);
bytes memory committeePublicKey = cyphernodeRegistry.getCommitteePublicKey(e3Id);
require(committeePublicKey.length > 0, CommitteeSelectionFailed());

e3s[e3Id].expiration = block.timestamp + maxDuration; // TODO: this should be based on the duration requested, not the current max duration.
Expand Down Expand Up @@ -199,14 +199,14 @@ contract Enclave is IEnclave, OwnableUpgradeable {
emit MaxDurationSet(_maxDuration);
}

function setCypherNodeRegistry(ICypherNodeRegistry _cypherNodeRegistry) public onlyOwner returns (bool success) {
function setCyphernodeRegistry(ICyphernodeRegistry _cyphernodeRegistry) public onlyOwner returns (bool success) {
require(
address(_cypherNodeRegistry) != address(0) && _cypherNodeRegistry != cypherNodeRegistry,
InvalidCypherNodeRegistry(_cypherNodeRegistry)
address(_cyphernodeRegistry) != address(0) && _cyphernodeRegistry != cyphernodeRegistry,
InvalidCyphernodeRegistry(_cyphernodeRegistry)
);
cypherNodeRegistry = _cypherNodeRegistry;
cyphernodeRegistry = _cyphernodeRegistry;
success = true;
emit CypherNodeRegistrySet(address(_cypherNodeRegistry));
emit CyphernodeRegistrySet(address(_cyphernodeRegistry));
}

function enableComputationModule(IComputationModule computationModule) public onlyOwner returns (bool success) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.26;

interface ICypherNodeRegistry {
interface ICyphernodeRegistry {
/// @notice This event MUST be emitted when a node is added to the registry.
/// @param nodeId ID of the node.
/// @param node Address of the node.
Expand Down
6 changes: 3 additions & 3 deletions packages/evm/contracts/interfaces/IEnclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ interface IEnclave {
/// @param maxDuration The maximum duration of a computation in seconds.
event MaxDurationSet(uint256 maxDuration);

/// @notice This event MUST be emitted any time the CypherNodeRegistry is set.
/// @param cypherNodeRegistry The address of the CypherNodeRegistry contract.
event CypherNodeRegistrySet(address cypherNodeRegistry);
/// @notice This event MUST be emitted any time the CyphernodeRegistry is set.
/// @param cyphernodeRegistry The address of the CyphernodeRegistry contract.
event CyphernodeRegistrySet(address cyphernodeRegistry);

/// @notice This event MUST be emitted any time a computation module is enabled.
/// @param computationModule The address of the computation module.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.26;

import { ICypherNodeRegistry } from "../interfaces/ICypherNodeRegistry.sol";
import { ICyphernodeRegistry } from "../interfaces/ICyphernodeRegistry.sol";

contract MockCypherNodeRegistry is ICypherNodeRegistry {
contract MockCyphernodeRegistry is ICyphernodeRegistry {
function selectCommittee(uint256, address pool, uint32[2] calldata) external pure returns (bool success) {
if (pool == address(2)) {
success = false;
Expand Down
44 changes: 22 additions & 22 deletions packages/evm/test/Enclave.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ethers } from "hardhat";

import { deployEnclaveFixture } from "./fixtures/Enclave.fixture";
import { deployComputationModuleFixture } from "./fixtures/MockComputationModule.fixture";
import { deployCypherNodeRegistryFixture } from "./fixtures/MockCypherNodeRegistry.fixture";
import { deployCyphernodeRegistryFixture } from "./fixtures/MockCyphernodeRegistry.fixture";
import { deployExecutionModuleFixture } from "./fixtures/MockExecutionModule.fixture";
import { deployInputValidatorFixture } from "./fixtures/MockInputValidator.fixture";
import { deployOutputVerifierFixture } from "./fixtures/MockOutputVerifier.fixture";
Expand All @@ -17,7 +17,7 @@ describe("Enclave", function () {
async function setup() {
const [owner, notTheOwner] = await ethers.getSigners();

const registry = await deployCypherNodeRegistryFixture();
const registry = await deployCyphernodeRegistryFixture();
const computationModule = await deployComputationModuleFixture();
const outputVerifier = await deployOutputVerifierFixture();
const executionModule = await deployExecutionModuleFixture();
Expand Down Expand Up @@ -49,13 +49,13 @@ describe("Enclave", function () {
it("correctly sets owner", async function () {
const [, , , someSigner] = await ethers.getSigners();
const enclave = await deployEnclaveFixture({ owner: someSigner, registry: AddressTwo });
expect(await enclave.cypherNodeRegistry()).to.equal(AddressTwo);
expect(await enclave.cyphernodeRegistry()).to.equal(AddressTwo);
});

it("correctly sets cypherNodeRegistry address", async function () {
it("correctly sets cyphernodeRegistry address", async function () {
const [aSigner] = await ethers.getSigners();
const enclave = await deployEnclaveFixture({ owner: aSigner, registry: AddressTwo });
expect(await enclave.cypherNodeRegistry()).to.equal(AddressTwo);
expect(await enclave.cyphernodeRegistry()).to.equal(AddressTwo);
});

it("correctly sets max duration", async function () {
Expand Down Expand Up @@ -88,47 +88,47 @@ describe("Enclave", function () {
});
});

describe("setCypherNodeRegistry()", function () {
describe("setCyphernodeRegistry()", function () {
it("reverts if not called by owner", async function () {
const { enclave, notTheOwner } = await loadFixture(setup);

await expect(enclave.connect(notTheOwner).setCypherNodeRegistry(AddressTwo))
await expect(enclave.connect(notTheOwner).setCyphernodeRegistry(AddressTwo))
.to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount")
.withArgs(notTheOwner);
});
it("reverts if given address(0)", async function () {
const { enclave } = await loadFixture(setup);
await expect(enclave.setCypherNodeRegistry(ethers.ZeroAddress))
.to.be.revertedWithCustomError(enclave, "InvalidCypherNodeRegistry")
await expect(enclave.setCyphernodeRegistry(ethers.ZeroAddress))
.to.be.revertedWithCustomError(enclave, "InvalidCyphernodeRegistry")
.withArgs(ethers.ZeroAddress);
});
it("reverts if given address is the same as the current cypherNodeRegistry", async function () {
it("reverts if given address is the same as the current cyphernodeRegistry", async function () {
const {
enclave,
mocks: { registry },
} = await loadFixture(setup);
await expect(enclave.setCypherNodeRegistry(registry))
.to.be.revertedWithCustomError(enclave, "InvalidCypherNodeRegistry")
await expect(enclave.setCyphernodeRegistry(registry))
.to.be.revertedWithCustomError(enclave, "InvalidCyphernodeRegistry")
.withArgs(registry);
});
it("sets cypherNodeRegistry correctly", async function () {
it("sets cyphernodeRegistry correctly", async function () {
const { enclave } = await loadFixture(setup);

expect(await enclave.cypherNodeRegistry()).to.not.equal(AddressTwo);
await enclave.setCypherNodeRegistry(AddressTwo);
expect(await enclave.cypherNodeRegistry()).to.equal(AddressTwo);
expect(await enclave.cyphernodeRegistry()).to.not.equal(AddressTwo);
await enclave.setCyphernodeRegistry(AddressTwo);
expect(await enclave.cyphernodeRegistry()).to.equal(AddressTwo);
});
it("returns true if cypherNodeRegistry is set successfully", async function () {
it("returns true if cyphernodeRegistry is set successfully", async function () {
const { enclave } = await loadFixture(setup);

const result = await enclave.setCypherNodeRegistry.staticCall(AddressTwo);
const result = await enclave.setCyphernodeRegistry.staticCall(AddressTwo);
expect(result).to.be.true;
});
it("emits CypherNodeRegistrySet event", async function () {
it("emits CyphernodeRegistrySet event", async function () {
const { enclave } = await loadFixture(setup);

await expect(enclave.setCypherNodeRegistry(AddressTwo))
.to.emit(enclave, "CypherNodeRegistrySet")
await expect(enclave.setCyphernodeRegistry(AddressTwo))
.to.emit(enclave, "CyphernodeRegistrySet")
.withArgs(AddressTwo);
});
});
Expand Down Expand Up @@ -565,7 +565,7 @@ describe("Enclave", function () {
await expect(enclave.activate(0)).to.not.be.reverted;
await expect(enclave.activate(0)).to.be.revertedWithCustomError(enclave, "E3AlreadyActivated").withArgs(0);
});
it("reverts if cypherNodeRegistry does not return a public key");
it("reverts if cyphernodeRegistry does not return a public key");
it("sets committeePublicKey correctly");
it("returns true if E3 is activated successfully");
it("emits E3Activated event");
Expand Down
8 changes: 4 additions & 4 deletions packages/evm/test/fixtures/MockCypherNodeRegistry.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ethers } from "hardhat";

import { MockCypherNodeRegistry__factory } from "../../types/factories/contracts/test/MockCypherNodeRegistry__factory";
import { MockCyphernodeRegistry__factory } from "../../types/factories/contracts/test/MockCyphernodeRegistry__factory";

export async function deployCypherNodeRegistryFixture() {
const deployment = await (await ethers.getContractFactory("MockCypherNodeRegistry")).deploy();
export async function deployCyphernodeRegistryFixture() {
const deployment = await (await ethers.getContractFactory("MockCyphernodeRegistry")).deploy();

return MockCypherNodeRegistry__factory.connect(await deployment.getAddress());
return MockCyphernodeRegistry__factory.connect(await deployment.getAddress());
}

0 comments on commit 404a4ef

Please sign in to comment.