From 404a4ef258d98afa82df0766a406da307fef2397 Mon Sep 17 00:00:00 2001 From: Auryn Macmillan Date: Tue, 4 Jun 2024 16:17:47 +1000 Subject: [PATCH] CypherNode --> Cyphernode --- packages/evm/contracts/Enclave.sol | 28 ++++++------ ...deRegistry.sol => ICyphernodeRegistry.sol} | 2 +- .../evm/contracts/interfaces/IEnclave.sol | 6 +-- ...egistry.sol => MockCyphernodeRegistry.sol} | 4 +- packages/evm/test/Enclave.spec.ts | 44 +++++++++---------- .../MockCypherNodeRegistry.fixture.ts | 8 ++-- 6 files changed, 46 insertions(+), 46 deletions(-) rename packages/evm/contracts/interfaces/{ICypherNodeRegistry.sol => ICyphernodeRegistry.sol} (98%) rename packages/evm/contracts/test/{MockCypherNodeRegistry.sol => MockCyphernodeRegistry.sol} (79%) diff --git a/packages/evm/contracts/Enclave.sol b/packages/evm/contracts/Enclave.sol index a38fde40..acc6e678 100644 --- a/packages/evm/contracts/Enclave.sol +++ b/packages/evm/contracts/Enclave.sol @@ -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"; @@ -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. @@ -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(); @@ -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); } @@ -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); @@ -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. @@ -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) { diff --git a/packages/evm/contracts/interfaces/ICypherNodeRegistry.sol b/packages/evm/contracts/interfaces/ICyphernodeRegistry.sol similarity index 98% rename from packages/evm/contracts/interfaces/ICypherNodeRegistry.sol rename to packages/evm/contracts/interfaces/ICyphernodeRegistry.sol index 4a865abf..6a99ba46 100644 --- a/packages/evm/contracts/interfaces/ICypherNodeRegistry.sol +++ b/packages/evm/contracts/interfaces/ICyphernodeRegistry.sol @@ -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. diff --git a/packages/evm/contracts/interfaces/IEnclave.sol b/packages/evm/contracts/interfaces/IEnclave.sol index d9ec4d1b..40b3c237 100644 --- a/packages/evm/contracts/interfaces/IEnclave.sol +++ b/packages/evm/contracts/interfaces/IEnclave.sol @@ -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. diff --git a/packages/evm/contracts/test/MockCypherNodeRegistry.sol b/packages/evm/contracts/test/MockCyphernodeRegistry.sol similarity index 79% rename from packages/evm/contracts/test/MockCypherNodeRegistry.sol rename to packages/evm/contracts/test/MockCyphernodeRegistry.sol index d2692ad8..44151eac 100644 --- a/packages/evm/contracts/test/MockCypherNodeRegistry.sol +++ b/packages/evm/contracts/test/MockCyphernodeRegistry.sol @@ -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; diff --git a/packages/evm/test/Enclave.spec.ts b/packages/evm/test/Enclave.spec.ts index 34eab536..f4323ed9 100644 --- a/packages/evm/test/Enclave.spec.ts +++ b/packages/evm/test/Enclave.spec.ts @@ -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"; @@ -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(); @@ -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 () { @@ -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); }); }); @@ -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"); diff --git a/packages/evm/test/fixtures/MockCypherNodeRegistry.fixture.ts b/packages/evm/test/fixtures/MockCypherNodeRegistry.fixture.ts index 8dab767c..cd1a588b 100644 --- a/packages/evm/test/fixtures/MockCypherNodeRegistry.fixture.ts +++ b/packages/evm/test/fixtures/MockCypherNodeRegistry.fixture.ts @@ -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()); }