From f6a01b20e69e4169afae79002e26cd47cc89f12d Mon Sep 17 00:00:00 2001 From: Auryn Macmillan Date: Thu, 5 Sep 2024 09:39:32 -0400 Subject: [PATCH] feat: add `e3Id` and `seed` to `validate()` calls to `IE3Program` and `IComputeProvider` --- README.md | 2 +- packages/evm/contracts/Enclave.sol | 15 +++++++++++---- .../evm/contracts/interfaces/IComputeProvider.sol | 2 ++ packages/evm/contracts/interfaces/IE3.sol | 2 +- packages/evm/contracts/interfaces/IE3Program.sol | 4 ++++ packages/evm/contracts/interfaces/IEnclave.sol | 4 ++-- .../evm/contracts/test/MockComputeProvider.sol | 2 ++ packages/evm/contracts/test/MockE3Program.sol | 2 ++ 8 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 07519420..79f4da0d 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ sequenceDiagram Users->>Enclave: request(parameters) Enclave->>E3Program: validate(e3ProgramParams) E3Program-->>Enclave: inputValidator - Enclave->>ComputeProvider: validate(emParams) + Enclave->>ComputeProvider: validate(computeProviderParams) ComputeProvider-->>Enclave: decryptionVerifier Enclave->>CiphernodeRegistry: requestCommittee(e3Id, filter, threshold) CiphernodeRegistry-->>Enclave: success diff --git a/packages/evm/contracts/Enclave.sol b/packages/evm/contracts/Enclave.sol index 5acc4c47..609825a6 100644 --- a/packages/evm/contracts/Enclave.sol +++ b/packages/evm/contracts/Enclave.sol @@ -128,7 +128,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { IE3Program e3Program, bytes memory e3ProgramParams, IComputeProvider computeProvider, - bytes memory emParams + bytes memory computeProviderParams ) external payable returns (uint256 e3Id, E3 memory e3) { // TODO: allow for other payment methods or only native tokens? // TODO: should payment checks be somewhere else? Perhaps in the E3 Program or ciphernode registry? @@ -156,14 +156,21 @@ contract Enclave is IEnclave, OwnableUpgradeable { // TODO: should IDs be incremental or produced deterministically? e3Id = nexte3Id; nexte3Id++; + uint256 seed = uint256(keccak256(abi.encode(block.prevrandao, e3Id))); - IInputValidator inputValidator = e3Program.validate(e3ProgramParams); + IInputValidator inputValidator = e3Program.validate( + e3Id, + seed, + e3ProgramParams + ); require(address(inputValidator) != address(0), InvalidComputation()); // TODO: validate that the requested computation can be performed by the given compute provider. // Perhaps the compute provider should be returned by the E3 Program? IDecryptionVerifier decryptionVerifier = computeProvider.validate( - emParams + e3Id, + seed, + computeProviderParams ); require( address(decryptionVerifier) != address(0), @@ -171,7 +178,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { ); e3 = E3({ - seed: keccak256(abi.encode(block.prevrandao, e3Id)), + seed: seed, threshold: threshold, startWindow: startWindow, duration: duration, diff --git a/packages/evm/contracts/interfaces/IComputeProvider.sol b/packages/evm/contracts/interfaces/IComputeProvider.sol index 2668ee1b..e997b180 100644 --- a/packages/evm/contracts/interfaces/IComputeProvider.sol +++ b/packages/evm/contracts/interfaces/IComputeProvider.sol @@ -7,6 +7,8 @@ interface IComputeProvider { /// @notice This function should be called by the Enclave contract to validate the compute provider parameters. /// @param params ABI encoded compute provider parameters. function validate( + uint256 e3Id, + uint256 seed, bytes calldata params ) external returns (IDecryptionVerifier decryptionVerifier); } diff --git a/packages/evm/contracts/interfaces/IE3.sol b/packages/evm/contracts/interfaces/IE3.sol index 6f4afcd1..66a78385 100644 --- a/packages/evm/contracts/interfaces/IE3.sol +++ b/packages/evm/contracts/interfaces/IE3.sol @@ -20,7 +20,7 @@ import { IDecryptionVerifier } from "./IDecryptionVerifier.sol"; /// @param ciphertextOutput Encrypted output data. /// @param plaintextOutput Decrypted output data. struct E3 { - bytes32 seed; + uint256 seed; uint32[2] threshold; uint256[2] startWindow; uint256 duration; diff --git a/packages/evm/contracts/interfaces/IE3Program.sol b/packages/evm/contracts/interfaces/IE3Program.sol index 7b32328e..506e1e94 100644 --- a/packages/evm/contracts/interfaces/IE3Program.sol +++ b/packages/evm/contracts/interfaces/IE3Program.sol @@ -5,9 +5,13 @@ import { IInputValidator } from "./IInputValidator.sol"; interface IE3Program { /// @notice This function should be called by the Enclave contract to validate the computation parameters. + /// @param e3Id ID of the E3. + /// @param seed Seed for the computation. /// @param params ABI encoded computation parameters. /// @return inputValidator The input validator to be used for the computation. function validate( + uint256 e3Id, + uint256 seed, bytes calldata params ) external returns (IInputValidator inputValidator); diff --git a/packages/evm/contracts/interfaces/IEnclave.sol b/packages/evm/contracts/interfaces/IEnclave.sol index dc0e4b0b..b22f03ed 100644 --- a/packages/evm/contracts/interfaces/IEnclave.sol +++ b/packages/evm/contracts/interfaces/IEnclave.sol @@ -98,7 +98,7 @@ interface IEnclave { /// @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. + /// @param computeProviderParams ABI encoded compute provider parameters. /// @return e3Id ID of the E3. /// @return e3 The E3 struct. function request( @@ -109,7 +109,7 @@ interface IEnclave { IE3Program e3Program, bytes memory e3ProgramParams, IComputeProvider computeProvider, - bytes memory emParams + bytes memory computeProviderParams ) external payable returns (uint256 e3Id, E3 memory e3); /// @notice This function should be called to activate an Encrypted Execution Environment (E3) once it has been diff --git a/packages/evm/contracts/test/MockComputeProvider.sol b/packages/evm/contracts/test/MockComputeProvider.sol index c846b951..9ddd2fba 100644 --- a/packages/evm/contracts/test/MockComputeProvider.sol +++ b/packages/evm/contracts/test/MockComputeProvider.sol @@ -10,6 +10,8 @@ contract MockComputeProvider is IComputeProvider { error invalidParams(); function validate( + uint256, + uint256, bytes memory params ) external pure returns (IDecryptionVerifier decryptionVerifier) { require(params.length == 32, invalidParams()); diff --git a/packages/evm/contracts/test/MockE3Program.sol b/packages/evm/contracts/test/MockE3Program.sol index 6b13761b..b92d6a84 100644 --- a/packages/evm/contracts/test/MockE3Program.sol +++ b/packages/evm/contracts/test/MockE3Program.sol @@ -7,6 +7,8 @@ contract MockE3Program is IE3Program { error invalidParams(bytes params); function validate( + uint256, + uint256, bytes memory params ) external pure returns (IInputValidator inputValidator) { require(params.length == 32, "invalid params");