From 7ae874acdeae5b13aa1602dad9a61018ab2f0ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3v=C3=A3o=20Honorato?= Date: Thu, 6 Jun 2024 13:41:38 +0200 Subject: [PATCH] Use prettier default print width --- packages/evm/.prettierrc.yml | 1 - packages/evm/contracts/Enclave.sol | 106 ++++++++++++++---- .../interfaces/IComputationModule.sol | 4 +- .../interfaces/ICyphernodeRegistry.sol | 10 +- .../evm/contracts/interfaces/IEnclave.sol | 20 +++- .../contracts/interfaces/IExecutionModule.sol | 4 +- .../registry/CyphernodeRegistryOwnable.sol | 13 ++- .../contracts/test/MockComputationModule.sol | 9 +- .../contracts/test/MockCyphernodeRegistry.sol | 8 +- .../contracts/test/MockExecutionModule.sol | 9 +- packages/evm/tasks/lock.ts | 4 +- packages/evm/test/Enclave.spec.ts | 93 ++++++++++----- .../fixtures/MockComputationModule.fixture.ts | 4 +- .../MockCyphernodeRegistry.fixture.ts | 5 +- .../fixtures/MockExecutionModule.fixture.ts | 4 +- .../fixtures/MockInputValidator.fixture.ts | 4 +- .../fixtures/MockOutputVerifier.fixture.ts | 4 +- 17 files changed, 230 insertions(+), 72 deletions(-) diff --git a/packages/evm/.prettierrc.yml b/packages/evm/.prettierrc.yml index 1383775b..17aefc74 100644 --- a/packages/evm/.prettierrc.yml +++ b/packages/evm/.prettierrc.yml @@ -2,7 +2,6 @@ bracketSpacing: true plugins: - "@trivago/prettier-plugin-sort-imports" - "prettier-plugin-solidity" -printWidth: 100 proseWrap: "always" singleQuote: false tabWidth: 2 diff --git a/packages/evm/contracts/Enclave.sol b/packages/evm/contracts/Enclave.sol index 13d3eaba..644cc14b 100644 --- a/packages/evm/contracts/Enclave.sol +++ b/packages/evm/contracts/Enclave.sol @@ -1,7 +1,12 @@ // SPDX-License-Identifier: LGPL-3.0-only pragma solidity >=0.8.26; -import { IEnclave, E3, IComputationModule, IExecutionModule } from "./interfaces/IEnclave.sol"; +import { + IEnclave, + E3, + IComputationModule, + IExecutionModule +} from "./interfaces/IEnclave.sol"; import { ICyphernodeRegistry } from "./interfaces/ICyphernodeRegistry.sol"; import { IInputValidator } from "./interfaces/IInputValidator.sol"; import { IOutputVerifier } from "./interfaces/IOutputVerifier.sol"; @@ -28,10 +33,12 @@ contract Enclave is IEnclave, OwnableUpgradeable { // This would reduce the governance overhead for Enclave. // Mapping of allowed computation modules. - mapping(IComputationModule computationModule => bool allowed) public computationModules; + mapping(IComputationModule computationModule => bool allowed) + public computationModules; // Mapping of allowed execution modules. - mapping(IExecutionModule executionModule => bool allowed) public executionModules; + mapping(IExecutionModule executionModule => bool allowed) + public executionModules; // Mapping of E3s. mapping(uint256 id => E3 e3) public e3s; @@ -71,7 +78,11 @@ 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) { + constructor( + address _owner, + ICyphernodeRegistry _cyphernodeRegistry, + uint256 _maxDuration + ) { initialize(_owner, _cyphernodeRegistry, _maxDuration); } @@ -110,25 +121,39 @@ contract Enclave is IEnclave, OwnableUpgradeable { // TODO: should payment checks be somewhere else? Perhaps in the computation module or cyphernode registry? require(msg.value > 0, PaymentRequired(msg.value)); - require(threshold[1] >= threshold[0] && threshold[0] > 0, InvalidThreshold(threshold)); + require( + threshold[1] >= threshold[0] && threshold[0] > 0, + InvalidThreshold(threshold) + ); // TODO: should 0 be a magic number for infinite duration? - require(duration > 0 && duration <= maxDuration, InvalidDuration(duration)); + require( + duration > 0 && duration <= maxDuration, + InvalidDuration(duration) + ); require( computationModules[computationModule], ComputationModuleNotAllowed(computationModule) ); - require(executionModules[executionModule], ModuleNotEnabled(address(executionModule))); + require( + executionModules[executionModule], + ModuleNotEnabled(address(executionModule)) + ); // TODO: should IDs be incremental or produced deterministic? e3Id = nexte3Id; nexte3Id++; - IInputValidator inputValidator = computationModule.validate(computationParams); + IInputValidator inputValidator = computationModule.validate( + computationParams + ); require(address(inputValidator) != address(0), InvalidComputation()); // TODO: validate that the requested computation can be performed by the given execution module. IOutputVerifier outputVerifier = executionModule.validate(emParams); - require(address(outputVerifier) != address(0), InvalidExecutionModuleSetup()); + require( + address(outputVerifier) != address(0), + InvalidExecutionModuleSetup() + ); e3 = E3({ threshold: threshold, @@ -149,7 +174,13 @@ contract Enclave is IEnclave, OwnableUpgradeable { ); // TODO: validate that the selected pool accepts both the computation and execution modules. - emit E3Requested(e3Id, e3s[e3Id], pools, computationModule, executionModule); + emit E3Requested( + e3Id, + e3s[e3Id], + pools, + computationModule, + executionModule + ); } function activate(uint256 e3Id) external returns (bool success) { @@ -158,7 +189,8 @@ 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); // Note: This check feels weird require(committeePublicKey.length > 0, CommitteeSelectionFailed()); @@ -171,13 +203,19 @@ contract Enclave is IEnclave, OwnableUpgradeable { return true; } - function publishInput(uint256 e3Id, bytes memory data) external returns (bool success) { + function publishInput( + uint256 e3Id, + bytes memory data + ) external returns (bool success) { E3 memory e3 = getE3(e3Id); // Note: if we make 0 a no expiration, this has to be refactored require(e3.expiration > 0, E3NotActivated(e3Id)); // TODO: should we have an input window, including both a start and end timestamp? - require(e3.expiration > block.timestamp, InputDeadlinePassed(e3Id, e3.expiration)); + require( + e3.expiration > block.timestamp, + InputDeadlinePassed(e3Id, e3.expiration) + ); bytes memory input; (input, success) = e3.inputValidator.validate(msg.sender, data); require(success, InvalidInput()); @@ -190,10 +228,16 @@ contract Enclave is IEnclave, OwnableUpgradeable { bytes memory data ) external returns (bool success) { E3 memory e3 = getE3(e3Id); - require(e3.expiration <= block.timestamp, InputDeadlineNotPassed(e3Id, e3.expiration)); + require( + e3.expiration <= block.timestamp, + InputDeadlineNotPassed(e3Id, e3.expiration) + ); // TODO: should the output verifier be able to change its mind? //i.e. should we be able to call this multiple times? - require(e3.ciphertextOutput.length == 0, CiphertextOutputAlreadyPublished(e3Id)); + require( + e3.ciphertextOutput.length == 0, + CiphertextOutputAlreadyPublished(e3Id) + ); bytes memory output; (output, success) = e3.outputVerifier.verify(e3Id, data); require(success, InvalidOutput()); @@ -207,8 +251,14 @@ contract Enclave is IEnclave, OwnableUpgradeable { bytes memory data ) external returns (bool success) { E3 memory e3 = getE3(e3Id); - require(e3.ciphertextOutput.length > 0, CiphertextOutputNotPublished(e3Id)); - require(e3.plaintextOutput.length == 0, PlaintextOutputAlreadyPublished(e3Id)); + require( + e3.ciphertextOutput.length > 0, + CiphertextOutputNotPublished(e3Id) + ); + require( + e3.plaintextOutput.length == 0, + PlaintextOutputAlreadyPublished(e3Id) + ); bytes memory output; (output, success) = e3.computationModule.verify(e3Id, data); require(success, InvalidOutput()); @@ -223,7 +273,9 @@ contract Enclave is IEnclave, OwnableUpgradeable { // // //////////////////////////////////////////////////////////// - function setMaxDuration(uint256 _maxDuration) public onlyOwner returns (bool success) { + function setMaxDuration( + uint256 _maxDuration + ) public onlyOwner returns (bool success) { maxDuration = _maxDuration; success = true; emit MaxDurationSet(_maxDuration); @@ -233,7 +285,8 @@ contract Enclave is IEnclave, OwnableUpgradeable { ICyphernodeRegistry _cyphernodeRegistry ) public onlyOwner returns (bool success) { require( - address(_cyphernodeRegistry) != address(0) && _cyphernodeRegistry != cyphernodeRegistry, + address(_cyphernodeRegistry) != address(0) && + _cyphernodeRegistry != cyphernodeRegistry, InvalidCyphernodeRegistry(_cyphernodeRegistry) ); cyphernodeRegistry = _cyphernodeRegistry; @@ -256,7 +309,10 @@ contract Enclave is IEnclave, OwnableUpgradeable { function enableExecutionModule( IExecutionModule executionModule ) public onlyOwner returns (bool success) { - require(!executionModules[executionModule], ModuleAlreadyEnabled(address(executionModule))); + require( + !executionModules[executionModule], + ModuleAlreadyEnabled(address(executionModule)) + ); executionModules[executionModule] = true; success = true; emit ExecutionModuleEnabled(executionModule); @@ -277,7 +333,10 @@ contract Enclave is IEnclave, OwnableUpgradeable { function disableExecutionModule( IExecutionModule executionModule ) public onlyOwner returns (bool success) { - require(executionModules[executionModule], ModuleNotEnabled(address(executionModule))); + require( + executionModules[executionModule], + ModuleNotEnabled(address(executionModule)) + ); delete executionModules[executionModule]; success = true; emit ExecutionModuleDisabled(executionModule); @@ -291,6 +350,9 @@ contract Enclave is IEnclave, OwnableUpgradeable { function getE3(uint256 e3Id) public view returns (E3 memory e3) { e3 = e3s[e3Id]; - require(e3.computationModule != IComputationModule(address(0)), E3DoesNotExist(e3Id)); + require( + e3.computationModule != IComputationModule(address(0)), + E3DoesNotExist(e3Id) + ); } } diff --git a/packages/evm/contracts/interfaces/IComputationModule.sol b/packages/evm/contracts/interfaces/IComputationModule.sol index a5b6258c..3a48423a 100644 --- a/packages/evm/contracts/interfaces/IComputationModule.sol +++ b/packages/evm/contracts/interfaces/IComputationModule.sol @@ -7,7 +7,9 @@ interface IComputationModule { /// @notice This function should be called by the Enclave contract to validate the computation parameters. /// @param params ABI encoded computation parameters. /// @return inputValidator The input validator to be used for the computation. - function validate(bytes calldata params) external returns (IInputValidator inputValidator); + function validate( + bytes calldata params + ) external returns (IInputValidator inputValidator); /// @notice This function should be called by the Enclave contract to verify the decrypted output of an E3. /// @param e3Id ID of the E3. diff --git a/packages/evm/contracts/interfaces/ICyphernodeRegistry.sol b/packages/evm/contracts/interfaces/ICyphernodeRegistry.sol index 1c6077f1..f69a1d28 100644 --- a/packages/evm/contracts/interfaces/ICyphernodeRegistry.sol +++ b/packages/evm/contracts/interfaces/ICyphernodeRegistry.sol @@ -6,7 +6,11 @@ interface ICyphernodeRegistry { /// @param e3Id ID of the E3 for which the committee was selected. /// @param pools Addresses of the pools of nodes from which the committee was selected. /// @param threshold The M/N threshold for the committee. - event CommitteeRequested(uint256 indexed e3Id, address[] pools, uint32[2] threshold); + event CommitteeRequested( + uint256 indexed e3Id, + address[] pools, + uint32[2] threshold + ); /// @notice This event MUST be emitted when a committee is selected for an E3. /// @param e3Id ID of the E3 for which the committee was selected. @@ -50,5 +54,7 @@ interface ICyphernodeRegistry { /// @dev This function MUST revert if the committee has not yet published a public key. /// @param e3Id ID of the E3 for which to get the committee public key. /// @return publicKey The public key of the committee. - function getCommitteePublicKey(uint256 e3Id) external view returns (bytes memory publicKey); + function getCommitteePublicKey( + uint256 e3Id + ) external view returns (bytes memory publicKey); } diff --git a/packages/evm/contracts/interfaces/IEnclave.sol b/packages/evm/contracts/interfaces/IEnclave.sol index fe745b13..bf7e4f5e 100644 --- a/packages/evm/contracts/interfaces/IEnclave.sol +++ b/packages/evm/contracts/interfaces/IEnclave.sol @@ -28,7 +28,11 @@ interface IEnclave { /// @param e3Id ID of the E3. /// @param expiration Timestamp when committee duties expire. /// @param committeePublicKey Public key of the committee. - event E3Activated(uint256 e3Id, uint256 expiration, bytes committeePublicKey); + event E3Activated( + uint256 e3Id, + uint256 expiration, + bytes committeePublicKey + ); /// @notice This event MUST be emitted when an input to an Encrypted Execution Environment (E3) is /// successfully published. @@ -46,7 +50,10 @@ interface IEnclave { /// is successfully published. /// @param e3Id ID of the E3. /// @param ciphertextOutput ABI encoded ciphertext output. - event CiphertextOutputPublished(uint256 indexed e3Id, bytes ciphertextOutput); + event CiphertextOutputPublished( + uint256 indexed e3Id, + bytes ciphertextOutput + ); /// @notice This event MUST be emitted any time the `maxDuration` is set. /// @param maxDuration The maximum duration of a computation in seconds. @@ -113,7 +120,10 @@ interface IEnclave { /// @param e3Id ID of the E3. /// @param data ABI encoded input data to publish. /// @return success True if the input was successfully published. - function publishInput(uint256 e3Id, bytes calldata data) external returns (bool success); + function publishInput( + uint256 e3Id, + bytes calldata data + ) external returns (bool success); /// @notice This function should be called to publish output data for an Encrypted Execution Environment (E3). /// @dev This function MUST emit the CiphertextOutputPublished event. @@ -145,7 +155,9 @@ interface IEnclave { /// @notice This function should be called to set the maximum duration of requested computations. /// @param _maxDuration The maximum duration of a computation in seconds. /// @return success True if the max duration was successfully set. - function setMaxDuration(uint256 _maxDuration) external returns (bool success); + function setMaxDuration( + uint256 _maxDuration + ) external returns (bool success); //////////////////////////////////////////////////////////// // // diff --git a/packages/evm/contracts/interfaces/IExecutionModule.sol b/packages/evm/contracts/interfaces/IExecutionModule.sol index 64ef17a4..e6d6e9cf 100644 --- a/packages/evm/contracts/interfaces/IExecutionModule.sol +++ b/packages/evm/contracts/interfaces/IExecutionModule.sol @@ -6,5 +6,7 @@ import { IOutputVerifier } from "./IOutputVerifier.sol"; interface IExecutionModule { /// @notice This function should be called by the Enclave contract to validate the execution module parameters. /// @param params ABI encoded execution module parameters. - function validate(bytes calldata params) external returns (IOutputVerifier outputVerifier); + function validate( + bytes calldata params + ) external returns (IOutputVerifier outputVerifier); } diff --git a/packages/evm/contracts/registry/CyphernodeRegistryOwnable.sol b/packages/evm/contracts/registry/CyphernodeRegistryOwnable.sol index 1057c2b2..69a6ec24 100644 --- a/packages/evm/contracts/registry/CyphernodeRegistryOwnable.sol +++ b/packages/evm/contracts/registry/CyphernodeRegistryOwnable.sol @@ -99,7 +99,10 @@ contract CyphernodeRegistryOwnable is ICyphernodeRegistry, OwnableUpgradeable { bytes memory publicKey ) external onlyOwner { Committee storage committee = committees[e3Id]; - require(keccak256(committee.publicKey) == keccak256(hex""), CommitteeAlreadyPublished()); + require( + keccak256(committee.publicKey) == keccak256(hex""), + CommitteeAlreadyPublished() + ); committee.nodes = _nodes; committee.merkleRoots = merkleRoots; committee.publicKey = publicKey; @@ -124,12 +127,16 @@ contract CyphernodeRegistryOwnable is ICyphernodeRegistry, OwnableUpgradeable { // // //////////////////////////////////////////////////////////// - function getCommitteePublicKey(uint256 e3Id) external view returns (bytes memory publicKey) { + function getCommitteePublicKey( + uint256 e3Id + ) external view returns (bytes memory publicKey) { publicKey = committees[e3Id].publicKey; require(publicKey.length > 0, NoPublicKeyPublished()); } - function getCommittee(uint256 e3Id) external view returns (Committee memory committee) { + function getCommittee( + uint256 e3Id + ) external view returns (Committee memory committee) { committee = committees[e3Id]; require(committees[e3Id].threshold.length > 0, CommitteeDoesNotExist()); } diff --git a/packages/evm/contracts/test/MockComputationModule.sol b/packages/evm/contracts/test/MockComputationModule.sol index 059da32d..65db9031 100644 --- a/packages/evm/contracts/test/MockComputationModule.sol +++ b/packages/evm/contracts/test/MockComputationModule.sol @@ -1,12 +1,17 @@ // SPDX-License-Identifier: LGPL-3.0-only pragma solidity >=0.8.26; -import { IComputationModule, IInputValidator } from "../interfaces/IComputationModule.sol"; +import { + IComputationModule, + IInputValidator +} from "../interfaces/IComputationModule.sol"; contract MockComputationModule is IComputationModule { error invalidParams(bytes params); - function validate(bytes memory params) external pure returns (IInputValidator inputValidator) { + function validate( + bytes memory params + ) external pure returns (IInputValidator inputValidator) { require(params.length == 32, "invalid params"); // solhint-disable no-inline-assembly assembly { diff --git a/packages/evm/contracts/test/MockCyphernodeRegistry.sol b/packages/evm/contracts/test/MockCyphernodeRegistry.sol index 49726fab..484eae7e 100644 --- a/packages/evm/contracts/test/MockCyphernodeRegistry.sol +++ b/packages/evm/contracts/test/MockCyphernodeRegistry.sol @@ -16,7 +16,9 @@ contract MockCyphernodeRegistry is ICyphernodeRegistry { } } - function getCommitteePublicKey(uint256 e3Id) external pure returns (bytes memory) { + function getCommitteePublicKey( + uint256 e3Id + ) external pure returns (bytes memory) { if (e3Id == type(uint256).max) { return hex""; } else { @@ -38,7 +40,9 @@ contract MockCyphernodeRegistryEmptyKey is ICyphernodeRegistry { } } - function getCommitteePublicKey(uint256) external pure returns (bytes memory) { + function getCommitteePublicKey( + uint256 + ) external pure returns (bytes memory) { return hex""; } } diff --git a/packages/evm/contracts/test/MockExecutionModule.sol b/packages/evm/contracts/test/MockExecutionModule.sol index 18d180dc..87ce5c52 100644 --- a/packages/evm/contracts/test/MockExecutionModule.sol +++ b/packages/evm/contracts/test/MockExecutionModule.sol @@ -1,12 +1,17 @@ // SPDX-License-Identifier: LGPL-3.0-only pragma solidity >=0.8.26; -import { IExecutionModule, IOutputVerifier } from "../interfaces/IExecutionModule.sol"; +import { + IExecutionModule, + IOutputVerifier +} from "../interfaces/IExecutionModule.sol"; contract MockExecutionModule is IExecutionModule { error invalidParams(); - function validate(bytes memory params) external pure returns (IOutputVerifier outputVerifier) { + function validate( + bytes memory params + ) external pure returns (IOutputVerifier outputVerifier) { require(params.length == 32, invalidParams()); // solhint-disable no-inline-assembly assembly { diff --git a/packages/evm/tasks/lock.ts b/packages/evm/tasks/lock.ts index d2af2f67..bb2b55b2 100644 --- a/packages/evm/tasks/lock.ts +++ b/packages/evm/tasks/lock.ts @@ -7,7 +7,9 @@ task("task:deployEnclave", "Deploys Enclave contract") const signers = await ethers.getSigners(); const enclaveFactory = await ethers.getContractFactory("Enclave"); console.log(`Deploying Enclave...`); - const enclave = await enclaveFactory.connect(signers[0]).deploy(taskArguments.maxDuration); + const enclave = await enclaveFactory + .connect(signers[0]) + .deploy(taskArguments.maxDuration); await enclave.waitForDeployment(); console.log("Enclave deployed to: ", await enclave.getAddress()); }); diff --git a/packages/evm/test/Enclave.spec.ts b/packages/evm/test/Enclave.spec.ts index 66f6f893..a98838c9 100644 --- a/packages/evm/test/Enclave.spec.ts +++ b/packages/evm/test/Enclave.spec.ts @@ -1,4 +1,8 @@ -import { loadFixture, mine, time } from "@nomicfoundation/hardhat-network-helpers"; +import { + loadFixture, + mine, + time, +} from "@nomicfoundation/hardhat-network-helpers"; import { expect } from "chai"; import { ZeroHash } from "ethers"; import { ethers } from "hardhat"; @@ -47,9 +51,15 @@ describe("Enclave", function () { threshold: [2, 2] as [number, number], duration: time.duration.days(30), computationModule: await computationModule.getAddress(), - cMParams: abiCoder.encode(["address"], [await inputValidator.getAddress()]), + cMParams: abiCoder.encode( + ["address"], + [await inputValidator.getAddress()], + ), executionModule: await executionModule.getAddress(), - eMParams: abiCoder.encode(["address"], [await outputVerifier.getAddress()]), + eMParams: abiCoder.encode( + ["address"], + [await outputVerifier.getAddress()], + ), }, }; } @@ -103,7 +113,9 @@ describe("Enclave", function () { }); it("emits MaxDurationSet event", async function () { const { enclave } = await loadFixture(setup); - await expect(enclave.setMaxDuration(1)).to.emit(enclave, "MaxDurationSet").withArgs(1); + await expect(enclave.setMaxDuration(1)) + .to.emit(enclave, "MaxDurationSet") + .withArgs(1); }); }); @@ -111,7 +123,9 @@ describe("Enclave", 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); }); @@ -177,9 +191,13 @@ describe("Enclave", function () { expect(e3.threshold).to.deep.equal(request.threshold); expect(e3.expiration).to.equal(0n); expect(e3.computationModule).to.equal(request.computationModule); - expect(e3.inputValidator).to.equal(abiCoder.decode(["address"], request.cMParams)[0]); + expect(e3.inputValidator).to.equal( + abiCoder.decode(["address"], request.cMParams)[0], + ); expect(e3.executionModule).to.equal(request.executionModule); - expect(e3.outputVerifier).to.equal(abiCoder.decode(["address"], request.eMParams)[0]); + expect(e3.outputVerifier).to.equal( + abiCoder.decode(["address"], request.eMParams)[0], + ); expect(e3.committeePublicKey).to.equal("0x"); expect(e3.ciphertextOutput).to.equal("0x"); expect(e3.plaintextOutput).to.equal("0x"); @@ -194,7 +212,9 @@ describe("Enclave", function () { mocks: { computationModule }, } = await loadFixture(setup); - await expect(enclave.connect(notTheOwner).enableComputationModule(computationModule)) + await expect( + enclave.connect(notTheOwner).enableComputationModule(computationModule), + ) .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); @@ -218,7 +238,8 @@ describe("Enclave", function () { }); it("returns true if computation module is enabled successfully", async function () { const { enclave } = await loadFixture(setup); - const result = await enclave.enableComputationModule.staticCall(AddressTwo); + const result = + await enclave.enableComputationModule.staticCall(AddressTwo); expect(result).to.be.true; }); it("emits ComputationModuleEnabled event", async function () { @@ -236,7 +257,11 @@ describe("Enclave", function () { enclave, mocks: { computationModule }, } = await loadFixture(setup); - await expect(enclave.connect(notTheOwner).disableComputationModule(computationModule)) + await expect( + enclave + .connect(notTheOwner) + .disableComputationModule(computationModule), + ) .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); @@ -261,7 +286,8 @@ describe("Enclave", function () { enclave, mocks: { computationModule }, } = await loadFixture(setup); - const result = await enclave.disableComputationModule.staticCall(computationModule); + const result = + await enclave.disableComputationModule.staticCall(computationModule); expect(result).to.be.true; }); @@ -279,7 +305,9 @@ describe("Enclave", function () { describe("enableExecutionModule()", function () { it("reverts if not called by owner", async function () { const { notTheOwner, enclave } = await loadFixture(setup); - await expect(enclave.connect(notTheOwner).enableExecutionModule(AddressTwo)) + await expect( + enclave.connect(notTheOwner).enableExecutionModule(AddressTwo), + ) .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner.address); }); @@ -322,7 +350,9 @@ describe("Enclave", function () { mocks: { executionModule }, } = await loadFixture(setup); - await expect(enclave.connect(notTheOwner).disableExecutionModule(executionModule)) + await expect( + enclave.connect(notTheOwner).disableExecutionModule(executionModule), + ) .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); @@ -347,7 +377,8 @@ describe("Enclave", function () { enclave, mocks: { executionModule }, } = await loadFixture(setup); - const result = await enclave.disableExecutionModule.staticCall(executionModule); + const result = + await enclave.disableExecutionModule.staticCall(executionModule); expect(result).to.be.true; }); @@ -535,9 +566,13 @@ describe("Enclave", function () { expect(e3.threshold).to.deep.equal(request.threshold); expect(e3.expiration).to.equal(0n); expect(e3.computationModule).to.equal(request.computationModule); - expect(e3.inputValidator).to.equal(abiCoder.decode(["address"], request.cMParams)[0]); + expect(e3.inputValidator).to.equal( + abiCoder.decode(["address"], request.cMParams)[0], + ); expect(e3.executionModule).to.equal(request.executionModule); - expect(e3.outputVerifier).to.equal(abiCoder.decode(["address"], request.eMParams)[0]); + expect(e3.outputVerifier).to.equal( + abiCoder.decode(["address"], request.eMParams)[0], + ); expect(e3.committeePublicKey).to.equal("0x"); expect(e3.ciphertextOutput).to.equal("0x"); expect(e3.plaintextOutput).to.equal("0x"); @@ -558,7 +593,13 @@ describe("Enclave", function () { await expect(tx) .to.emit(enclave, "E3Requested") - .withArgs(0, e3, request.pool, request.computationModule, request.executionModule); + .withArgs( + 0, + e3, + request.pool, + request.computationModule, + request.executionModule, + ); }); }); @@ -605,7 +646,9 @@ describe("Enclave", function () { ); const prevRegistry = await enclave.cyphernodeRegistry(); - const nextRegistry = await deployCyphernodeRegistryFixture("MockCyphernodeRegistryEmptyKey"); + const nextRegistry = await deployCyphernodeRegistryFixture( + "MockCyphernodeRegistryEmptyKey", + ); await enclave.setCyphernodeRegistry(nextRegistry); await expect(enclave.activate(0)).to.be.revertedWithCustomError( @@ -738,10 +781,9 @@ describe("Enclave", function () { const inputData = abiCoder.encode(["bytes"], ["0xaabbcc"]); await enclave.activate(0); - await expect(enclave.publishInput(0, inputData)).to.be.revertedWithCustomError( - enclave, - "InvalidInput", - ); + await expect( + enclave.publishInput(0, inputData), + ).to.be.revertedWithCustomError(enclave, "InvalidInput"); }); it("reverts if outside of input window", async function () { @@ -765,10 +807,9 @@ describe("Enclave", function () { await mine(2, { interval: request.duration }); - await expect(enclave.publishInput(0, inputData)).to.be.revertedWithCustomError( - enclave, - "InputDeadlinePassed", - ); + await expect( + enclave.publishInput(0, inputData), + ).to.be.revertedWithCustomError(enclave, "InputDeadlinePassed"); }); it("sets ciphertextInput correctly"); it("returns true if input is published successfully"); diff --git a/packages/evm/test/fixtures/MockComputationModule.fixture.ts b/packages/evm/test/fixtures/MockComputationModule.fixture.ts index 69dc901d..9eba3fb9 100644 --- a/packages/evm/test/fixtures/MockComputationModule.fixture.ts +++ b/packages/evm/test/fixtures/MockComputationModule.fixture.ts @@ -3,7 +3,9 @@ import { ethers } from "hardhat"; import { MockComputationModule__factory } from "../../types/factories/contracts/test/MockComputationModule__factory"; export async function deployComputationModuleFixture() { - const deployment = await (await ethers.getContractFactory("MockComputationModule")).deploy(); + const deployment = await ( + await ethers.getContractFactory("MockComputationModule") + ).deploy(); return MockComputationModule__factory.connect(await deployment.getAddress()); } diff --git a/packages/evm/test/fixtures/MockCyphernodeRegistry.fixture.ts b/packages/evm/test/fixtures/MockCyphernodeRegistry.fixture.ts index 258ce6c1..eecc554c 100644 --- a/packages/evm/test/fixtures/MockCyphernodeRegistry.fixture.ts +++ b/packages/evm/test/fixtures/MockCyphernodeRegistry.fixture.ts @@ -8,5 +8,8 @@ export async function deployCyphernodeRegistryFixture(name?: string) { await ethers.getContractFactory(name || "MockCyphernodeRegistry") ).deploy(); - return MockCyphernodeRegistry__factory.connect(await deployment.getAddress(), signer.provider); + return MockCyphernodeRegistry__factory.connect( + await deployment.getAddress(), + signer.provider, + ); } diff --git a/packages/evm/test/fixtures/MockExecutionModule.fixture.ts b/packages/evm/test/fixtures/MockExecutionModule.fixture.ts index 56793f64..0b8d6582 100644 --- a/packages/evm/test/fixtures/MockExecutionModule.fixture.ts +++ b/packages/evm/test/fixtures/MockExecutionModule.fixture.ts @@ -3,7 +3,9 @@ import { ethers } from "hardhat"; import { MockExecutionModule__factory } from "../../types/factories/contracts/test/MockExecutionModule__factory"; export async function deployExecutionModuleFixture() { - const deployment = await (await ethers.getContractFactory("MockExecutionModule")).deploy(); + const deployment = await ( + await ethers.getContractFactory("MockExecutionModule") + ).deploy(); return MockExecutionModule__factory.connect(await deployment.getAddress()); } diff --git a/packages/evm/test/fixtures/MockInputValidator.fixture.ts b/packages/evm/test/fixtures/MockInputValidator.fixture.ts index 21e8f70c..29122917 100644 --- a/packages/evm/test/fixtures/MockInputValidator.fixture.ts +++ b/packages/evm/test/fixtures/MockInputValidator.fixture.ts @@ -3,6 +3,8 @@ import { ethers } from "hardhat"; import { MockInputValidator__factory } from "../../types/factories/contracts/test/MockInputValidator__factory"; export async function deployInputValidatorFixture() { - const deployment = await (await ethers.getContractFactory("MockInputValidator")).deploy(); + const deployment = await ( + await ethers.getContractFactory("MockInputValidator") + ).deploy(); return MockInputValidator__factory.connect(await deployment.getAddress()); } diff --git a/packages/evm/test/fixtures/MockOutputVerifier.fixture.ts b/packages/evm/test/fixtures/MockOutputVerifier.fixture.ts index 267c9555..a4ffa7aa 100644 --- a/packages/evm/test/fixtures/MockOutputVerifier.fixture.ts +++ b/packages/evm/test/fixtures/MockOutputVerifier.fixture.ts @@ -3,6 +3,8 @@ import { ethers } from "hardhat"; import { MockOutputVerifier__factory } from "../../types/factories/contracts/test/MockOutputVerifier__factory"; export async function deployOutputVerifierFixture() { - const deployment = await (await ethers.getContractFactory("MockComputationModule")).deploy(); + const deployment = await ( + await ethers.getContractFactory("MockComputationModule") + ).deploy(); return MockOutputVerifier__factory.connect(await deployment.getAddress()); }