diff --git a/README.md b/README.md index 46a52532..07519420 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ sequenceDiagram participant DecryptionVerifier Users->>Enclave: request(parameters) - Enclave->>E3Program: validate(computationParams) + Enclave->>E3Program: validate(e3ProgramParams) E3Program-->>Enclave: inputValidator Enclave->>ComputeProvider: validate(emParams) ComputeProvider-->>Enclave: decryptionVerifier diff --git a/packages/evm/contracts/Enclave.sol b/packages/evm/contracts/Enclave.sol index 9903b332..b8a41583 100644 --- a/packages/evm/contracts/Enclave.sol +++ b/packages/evm/contracts/Enclave.sol @@ -40,8 +40,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { // This would reduce the governance overhead for Enclave. // Mapping of allowed E3 Programs. - mapping(IE3Program computationModule => bool allowed) - public computationModules; + mapping(IE3Program e3Program => bool allowed) public e3Programs; // Mapping of allowed compute providers. mapping(IComputeProvider computeProvider => bool allowed) @@ -63,7 +62,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { //////////////////////////////////////////////////////////// error CommitteeSelectionFailed(); - error E3ProgramNotAllowed(IE3Program computationModule); + error E3ProgramNotAllowed(IE3Program e3Program); error E3AlreadyActivated(uint256 e3Id); error E3Expired(); error E3NotActivated(uint256 e3Id); @@ -126,8 +125,8 @@ contract Enclave is IEnclave, OwnableUpgradeable { uint32[2] calldata threshold, uint256[2] calldata startWindow, uint256 duration, - IE3Program computationModule, - bytes memory computationParams, + IE3Program e3Program, + bytes memory e3ProgramParams, IComputeProvider computeProvider, bytes memory emParams ) external payable returns (uint256 e3Id, E3 memory e3) { @@ -148,10 +147,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { duration > 0 && duration <= maxDuration, InvalidDuration(duration) ); - require( - computationModules[computationModule], - E3ProgramNotAllowed(computationModule) - ); + require(e3Programs[e3Program], E3ProgramNotAllowed(e3Program)); require( computeProviders[computeProvider], ModuleNotEnabled(address(computeProvider)) @@ -161,9 +157,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { e3Id = nexte3Id; nexte3Id++; - IInputValidator inputValidator = computationModule.validate( - computationParams - ); + IInputValidator inputValidator = e3Program.validate(e3ProgramParams); require(address(inputValidator) != address(0), InvalidComputation()); // TODO: validate that the requested computation can be performed by the given compute provider. @@ -181,7 +175,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { startWindow: startWindow, duration: duration, expiration: 0, - computationModule: computationModule, + e3Program: e3Program, computeProvider: computeProvider, inputValidator: inputValidator, decryptionVerifier: decryptionVerifier, @@ -196,13 +190,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { CommitteeSelectionFailed() ); - emit E3Requested( - e3Id, - e3s[e3Id], - filter, - computationModule, - computeProvider - ); + emit E3Requested(e3Id, e3s[e3Id], filter, e3Program, computeProvider); } function activate(uint256 e3Id) external returns (bool success) { @@ -270,7 +258,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { CiphertextOutputAlreadyPublished(e3Id) ); bytes memory output; - (output, success) = e3.computationModule.verify(e3Id, data); + (output, success) = e3.e3Program.verify(e3Id, data); require(success, InvalidOutput(output)); e3s[e3Id].ciphertextOutput = output; @@ -328,15 +316,15 @@ contract Enclave is IEnclave, OwnableUpgradeable { } function enableE3Program( - IE3Program computationModule + IE3Program e3Program ) public onlyOwner returns (bool success) { require( - !computationModules[computationModule], - ModuleAlreadyEnabled(address(computationModule)) + !e3Programs[e3Program], + ModuleAlreadyEnabled(address(e3Program)) ); - computationModules[computationModule] = true; + e3Programs[e3Program] = true; success = true; - emit E3ProgramEnabled(computationModule); + emit E3ProgramEnabled(e3Program); } function enableComputeProvider( @@ -352,15 +340,12 @@ contract Enclave is IEnclave, OwnableUpgradeable { } function disableE3Program( - IE3Program computationModule + IE3Program e3Program ) public onlyOwner returns (bool success) { - require( - computationModules[computationModule], - ModuleNotEnabled(address(computationModule)) - ); - delete computationModules[computationModule]; + require(e3Programs[e3Program], ModuleNotEnabled(address(e3Program))); + delete e3Programs[e3Program]; success = true; - emit E3ProgramDisabled(computationModule); + emit E3ProgramDisabled(e3Program); } function disableComputeProvider( @@ -383,15 +368,12 @@ contract Enclave is IEnclave, OwnableUpgradeable { function getE3(uint256 e3Id) public view returns (E3 memory e3) { e3 = e3s[e3Id]; - require( - e3.computationModule != IE3Program(address(0)), - E3DoesNotExist(e3Id) - ); + require(e3.e3Program != IE3Program(address(0)), E3DoesNotExist(e3Id)); } function getInputRoot(uint256 e3Id) public view returns (uint256) { require( - e3s[e3Id].computationModule != IE3Program(address(0)), + e3s[e3Id].e3Program != IE3Program(address(0)), E3DoesNotExist(e3Id) ); return InternalLeanIMT._root(inputs[e3Id]); diff --git a/packages/evm/contracts/interfaces/IE3.sol b/packages/evm/contracts/interfaces/IE3.sol index 64f47060..dcd42c91 100644 --- a/packages/evm/contracts/interfaces/IE3.sol +++ b/packages/evm/contracts/interfaces/IE3.sol @@ -12,7 +12,7 @@ import { IDecryptionVerifier } from "./IDecryptionVerifier.sol"; /// @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. -/// @param computationModule Address of the E3 Program contract. +/// @param e3Program Address of the E3 Program contract. /// @param computeProvider Address of the compute provider contract. /// @param inputValidator Address of the input validator contract. /// @param decryptionVerifier Address of the output verifier contract. @@ -24,7 +24,7 @@ struct E3 { uint256[2] startWindow; uint256 duration; uint256 expiration; - IE3Program computationModule; + IE3Program e3Program; IComputeProvider computeProvider; IInputValidator inputValidator; IDecryptionVerifier decryptionVerifier; diff --git a/packages/evm/contracts/interfaces/IEnclave.sol b/packages/evm/contracts/interfaces/IEnclave.sol index 33b72127..dc0e4b0b 100644 --- a/packages/evm/contracts/interfaces/IEnclave.sol +++ b/packages/evm/contracts/interfaces/IEnclave.sol @@ -14,13 +14,13 @@ interface IEnclave { /// @param e3Id ID of the E3. /// @param e3 Details of the E3. /// @param filter Address of the pool of nodes from which the Cipher Node committee was selected. - /// @param computationModule Address of the Computation module selected. + /// @param e3Program Address of the Computation module selected. /// @param computeProvider Address of the compute provider selected. event E3Requested( uint256 e3Id, E3 e3, address filter, - IE3Program indexed computationModule, + IE3Program indexed e3Program, IComputeProvider indexed computeProvider ); @@ -69,12 +69,12 @@ interface IEnclave { event CiphernodeRegistrySet(address ciphernodeRegistry); /// @notice This event MUST be emitted any time a E3 Program is enabled. - /// @param computationModule The address of the E3 Program. - event E3ProgramEnabled(IE3Program computationModule); + /// @param e3Program The address of the E3 Program. + event E3ProgramEnabled(IE3Program e3Program); /// @notice This event MUST be emitted any time a E3 Program is disabled. - /// @param computationModule The address of the E3 Program. - event E3ProgramDisabled(IE3Program computationModule); + /// @param e3Program The address of the E3 Program. + event E3ProgramDisabled(IE3Program e3Program); /// @notice This event MUST be emitted any time an compute provider is enabled. /// @param computeProvider The address of the compute provider. @@ -95,8 +95,8 @@ interface IEnclave { /// @param filter IDs of the pool of nodes from which to select the committee. /// @param threshold The M/N threshold for the committee. /// @param duration The duration of the computation in seconds. - /// @param computationModule Address of the E3 Program. - /// @param computationParams ABI encoded computation parameters. + /// @param e3Program Address of the E3 Program. + /// @param e3ProgramParams ABI encoded computation parameters. /// @param computeProvider Address of the compute provider. /// @param emParams ABI encoded compute provider parameters. /// @return e3Id ID of the E3. @@ -106,8 +106,8 @@ interface IEnclave { uint32[2] calldata threshold, uint256[2] calldata startWindow, uint256 duration, - IE3Program computationModule, - bytes memory computationParams, + IE3Program e3Program, + bytes memory e3ProgramParams, IComputeProvider computeProvider, bytes memory emParams ) external payable returns (uint256 e3Id, E3 memory e3); diff --git a/packages/evm/test/Enclave.spec.ts b/packages/evm/test/Enclave.spec.ts index 57f1d622..34bbc18d 100644 --- a/packages/evm/test/Enclave.spec.ts +++ b/packages/evm/test/Enclave.spec.ts @@ -31,7 +31,7 @@ describe("Enclave", function () { const [owner, notTheOwner] = await ethers.getSigners(); const registry = await deployCiphernodeRegistryFixture(); - const computationModule = await deployE3ProgramFixture(); + const e3Program = await deployE3ProgramFixture(); const decryptionVerifier = await deployDecryptionVerifierFixture(); const computeProvider = await deployComputeProviderFixture(); const inputValidator = await deployInputValidatorFixture(); @@ -41,7 +41,7 @@ describe("Enclave", function () { registry: await registry.getAddress(), }); - await enclave.enableE3Program(await computationModule.getAddress()); + await enclave.enableE3Program(await e3Program.getAddress()); await enclave.enableComputeProvider(await computeProvider.getAddress()); return { @@ -49,7 +49,7 @@ describe("Enclave", function () { notTheOwner, enclave, mocks: { - computationModule, + e3Program, decryptionVerifier, computeProvider, inputValidator, @@ -63,7 +63,7 @@ describe("Enclave", function () { number, ], duration: time.duration.days(30), - computationModule: await computationModule.getAddress(), + e3Program: await e3Program.getAddress(), cMParams: abiCoder.encode( ["address"], [await inputValidator.getAddress()], @@ -194,7 +194,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -204,7 +204,7 @@ 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.e3Program).to.equal(request.e3Program); expect(e3.inputValidator).to.equal( abiCoder.decode(["address"], request.cMParams)[0], ); @@ -223,31 +223,29 @@ describe("Enclave", function () { const { notTheOwner, enclave, - mocks: { computationModule }, + mocks: { e3Program }, } = await loadFixture(setup); - await expect( - enclave.connect(notTheOwner).enableE3Program(computationModule), - ) + await expect(enclave.connect(notTheOwner).enableE3Program(e3Program)) .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); it("reverts if E3 Program is already enabled", async function () { const { enclave, - mocks: { computationModule }, + mocks: { e3Program }, } = await loadFixture(setup); - await expect(enclave.enableE3Program(computationModule)) + await expect(enclave.enableE3Program(e3Program)) .to.be.revertedWithCustomError(enclave, "ModuleAlreadyEnabled") - .withArgs(computationModule); + .withArgs(e3Program); }); it("enables E3 Program correctly", async function () { const { enclave, - mocks: { computationModule }, + mocks: { e3Program }, } = await loadFixture(setup); - const enabled = await enclave.computationModules(computationModule); + const enabled = await enclave.e3Programs(e3Program); expect(enabled).to.be.true; }); it("returns true if E3 Program is enabled successfully", async function () { @@ -268,11 +266,9 @@ describe("Enclave", function () { const { notTheOwner, enclave, - mocks: { computationModule }, + mocks: { e3Program }, } = await loadFixture(setup); - await expect( - enclave.connect(notTheOwner).disableE3Program(computationModule), - ) + await expect(enclave.connect(notTheOwner).disableE3Program(e3Program)) .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); @@ -285,31 +281,30 @@ describe("Enclave", function () { it("disables E3 Program correctly", async function () { const { enclave, - mocks: { computationModule }, + mocks: { e3Program }, } = await loadFixture(setup); - await enclave.disableE3Program(computationModule); + await enclave.disableE3Program(e3Program); - const enabled = await enclave.computationModules(computationModule); + const enabled = await enclave.e3Programs(e3Program); expect(enabled).to.be.false; }); it("returns true if E3 Program is disabled successfully", async function () { const { enclave, - mocks: { computationModule }, + mocks: { e3Program }, } = await loadFixture(setup); - const result = - await enclave.disableE3Program.staticCall(computationModule); + const result = await enclave.disableE3Program.staticCall(e3Program); expect(result).to.be.true; }); it("emits E3ProgramDisabled event", async function () { const { enclave, - mocks: { computationModule }, + mocks: { e3Program }, } = await loadFixture(setup); - await expect(enclave.disableE3Program(computationModule)) + await expect(enclave.disableE3Program(e3Program)) .to.emit(enclave, "E3ProgramDisabled") - .withArgs(computationModule); + .withArgs(e3Program); }); }); @@ -414,7 +409,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -429,7 +424,7 @@ describe("Enclave", function () { [0, 2], request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -445,7 +440,7 @@ describe("Enclave", function () { [3, 2], request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -461,7 +456,7 @@ describe("Enclave", function () { request.threshold, request.startTime, 0, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -477,7 +472,7 @@ describe("Enclave", function () { request.threshold, request.startTime, time.duration.days(31), - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -511,7 +506,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, ethers.ZeroAddress, request.eMParams, @@ -530,7 +525,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, ZeroHash, request.computeProvider, request.eMParams, @@ -546,7 +541,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, ZeroHash, @@ -562,7 +557,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -577,7 +572,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -587,7 +582,7 @@ 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.e3Program).to.equal(request.e3Program); expect(e3.inputValidator).to.equal( abiCoder.decode(["address"], request.cMParams)[0], ); @@ -606,7 +601,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -620,7 +615,7 @@ describe("Enclave", function () { 0, e3, request.filter, - request.computationModule, + request.e3Program, request.computeProvider, ); }); @@ -642,7 +637,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -667,7 +662,7 @@ describe("Enclave", function () { request.threshold, startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -691,7 +686,7 @@ describe("Enclave", function () { request.threshold, startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -717,7 +712,7 @@ describe("Enclave", function () { request.threshold, startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -741,7 +736,7 @@ describe("Enclave", function () { request.threshold, startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -763,7 +758,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -796,7 +791,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -822,7 +817,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -841,7 +836,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -874,7 +869,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -899,7 +894,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -920,7 +915,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -944,7 +939,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -969,7 +964,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -998,7 +993,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1034,7 +1029,7 @@ describe("Enclave", function () { request.threshold, request.startTime, request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1051,7 +1046,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1077,7 +1072,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1102,7 +1097,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1123,7 +1118,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1144,7 +1139,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1165,7 +1160,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1197,7 +1192,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1216,7 +1211,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1236,7 +1231,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1262,7 +1257,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1284,7 +1279,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1307,7 +1302,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams, @@ -1329,7 +1324,7 @@ describe("Enclave", function () { request.threshold, [await time.latest(), (await time.latest()) + 100], request.duration, - request.computationModule, + request.e3Program, request.cMParams, request.computeProvider, request.eMParams,