Skip to content

Commit

Permalink
squash linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
auryn-macmillan committed Jun 5, 2024
1 parent 50a9383 commit 72f187d
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 121 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@gnosisguild/enclave",
"description": "Enclave is an open-source protocol for Encrypted Execution Environments (E3).",
"version": "0.0.0",
"license": "LGPL-3.0-only",
"author": {
"name": "gnosisguild",
"url": "https://github.com/gnosisguild"
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extends:
- "prettier"
parser: "@typescript-eslint/parser"
parserOptions:
project: "packages/evm/tsconfig.json"
project: "tsconfig.json"
plugins:
- "@typescript-eslint"
root: true
Expand Down
4 changes: 3 additions & 1 deletion packages/evm/.solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"plugins": ["prettier"],
"rules": {
"code-complexity": ["error", 8],
"compiler-version": ["error", ">=0.8.4"],
"compiler-version": ["error", ">=0.8.26"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 120],
"named-parameters-mapping": "warn",
"no-console": "off",
"not-rely-on-time": "off",
"gas-custom-errors": "off",
"one-contract-per-file": "off",
"prettier/prettier": [
"error",
{
Expand Down
33 changes: 22 additions & 11 deletions packages/evm/contracts/Enclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ contract Enclave is IEnclave, OwnableUpgradeable {
// But perhaps this is one place where node pools might be utilized, allowing nodes to
// opt in to being selected for specific computations, along with the corresponding slashing conditions.
// This would reduce the governance overhead for Enclave.
// TODO: add setter function
mapping(IComputationModule => bool allowed) public computationModules; // Mapping of allowed computation modules.
// TODO: add setter function
mapping(IExecutionModule => bool allowed) public executionModules; // Mapping of allowed execution modules.

mapping(uint256 id => E3) public e3s; // Mapping of E3s.
// Mapping of allowed computation modules.
mapping(IComputationModule computationModule => bool allowed) public computationModules;

// Mapping of allowed execution modules.
mapping(IExecutionModule executionModule => bool allowed) public executionModules;

// Mapping of E3s.
mapping(uint256 id => E3 e3) public e3s;

////////////////////////////////////////////////////////////
// //
Expand Down Expand Up @@ -93,18 +96,22 @@ contract Enclave is IEnclave, OwnableUpgradeable {
function request(
address[] memory pools, // TODO: should we allow for multiple pools?
uint32[2] calldata threshold,
uint256 duration, // TODO: do we also need a start block/time? Would it be possible to have computations where inputs are published before the request is made? This kind of assumes the cypher nodes have already been selected and generated a shared secret.
// TODO: do we also need a start block/time? Would it be possible to have computations where inputs are
//published before the request is made? This kind of assumes the cypher nodes have already been selected
// and generated a shared secret.
uint256 duration,
IComputationModule computationModule,
bytes memory computationParams,
IExecutionModule executionModule,
bytes memory emParams
) external payable returns (uint256 e3Id, E3 memory e3) {
// TODO: allow for other payment methods or only native tokens?
// TODO: should payment checks be done somewhere else? Perhaps in the computation module or cypher node registry?
// 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(duration > 0 && duration <= maxDuration, InvalidDuration(duration)); // TODO: should 0 be a magic number for infinite duration?
// TODO: should 0 be a magic number for infinite duration?
require(duration > 0 && duration <= maxDuration, InvalidDuration(duration));
require(
computationModules[computationModule],
ComputationModuleNotAllowed(computationModule)
Expand Down Expand Up @@ -154,7 +161,8 @@ contract Enclave is IEnclave, OwnableUpgradeable {
// Note: This check feels weird
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.
// TODO: this should be based on the duration requested, not the current max duration.
e3s[e3Id].expiration = block.timestamp + maxDuration;
e3s[e3Id].committeePublicKey = committeePublicKey;

emit E3Activated(e3Id, e3.expiration, e3.committeePublicKey);
Expand All @@ -164,7 +172,8 @@ contract Enclave is IEnclave, OwnableUpgradeable {

function publishInput(uint256 e3Id, bytes memory data) external returns (bool success) {
E3 memory e3 = getE3(e3Id);
require(e3.expiration > block.timestamp, InputDeadlinePassed(e3Id, e3.expiration)); // TODO: should we have an input window, including both a start and end timestamp?
// TODO: should we have an input window, including both a start and end timestamp?
require(e3.expiration > block.timestamp, InputDeadlinePassed(e3Id, e3.expiration));
bytes memory input;
(input, success) = e3.inputValidator.validate(msg.sender, data);
require(success, InvalidInput());
Expand All @@ -178,7 +187,9 @@ contract Enclave is IEnclave, OwnableUpgradeable {
) external returns (bool success) {
E3 memory e3 = getE3(e3Id);
require(e3.expiration <= block.timestamp, InputDeadlineNotPassed(e3Id, e3.expiration));
require(e3.ciphertextOutput.length == 0, CiphertextOutputAlreadyPublished(e3Id)); // TODO: should the output verifier be able to change its mind? i.e. should we be able to call this multiple times?
// 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));
bytes memory output;
(output, success) = e3.outputVerifier.verify(e3Id, data);
require(success, InvalidOutput());
Expand Down
14 changes: 9 additions & 5 deletions packages/evm/contracts/interfaces/IEnclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ interface IEnclave {
/// @param committeePublicKey Public key of the committee.
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.
/// @notice This event MUST be emitted when an input to an Encrypted Execution Environment (E3) is
/// successfully published.
/// @param e3Id ID of the E3.
/// @param data ABI encoded input data.
event InputPublished(uint256 indexed e3Id, bytes data);

/// @notice This event MUST be emitted when the plaintext output of an Encrypted Execution Environment (E3) is successfully published.
/// @notice This event MUST be emitted when the plaintext output of an Encrypted Execution Environment (E3)
/// is successfully published.
/// @param e3Id ID of the E3.
/// @param plaintextOutput ABI encoded plaintext output.
event PlaintextOutputPublished(uint256 indexed e3Id, bytes plaintextOutput);

/// @notice This event MUST be emitted when the ciphertext output of an Encrypted Execution Environment (E3) is successfully published.
/// @notice This event MUST be emitted when the ciphertext output of an Encrypted Execution Environment (E3)
/// is successfully published.
/// @param e3Id ID of the E3.
/// @param ciphertextOutput ABI encoded ciphertext output.
event CiphertextOutputPublished(uint256 indexed e3Id, bytes ciphertextOutput);
Expand Down Expand Up @@ -96,7 +99,8 @@ interface IEnclave {
bytes memory emParams
) 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 initialized and is ready for input.
/// @notice This function should be called to activate an Encrypted Execution Environment (E3) once it has been
/// initialized and is ready for input.
/// @dev This function MUST emit the E3Activated event.
/// @dev This function MUST revert if the given E3 has not yet been requested.
/// @dev This function MUST revert if the selected node committee has not yet published a public key.
Expand All @@ -121,7 +125,7 @@ interface IEnclave {
bytes memory data
) external returns (bool success);

/// @notice This function should be called to publish the plaintext output of an Encrypted Execution Environment (E3).
/// @notice This function publishes the plaintext output of an Encrypted Execution Environment (E3).
/// @dev This function MUST revert if the output has not been published.
/// @dev This function MUST emit the PlaintextOutputPublished event.
/// @param e3Id ID of the E3.
Expand Down
1 change: 1 addition & 0 deletions packages/evm/contracts/test/MockComputationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ contract MockComputationModule is IComputationModule {

function validate(bytes memory params) external pure returns (IInputValidator inputValidator) {
require(params.length == 32, "invalid params");
// solhint-disable no-inline-assembly
assembly {
inputValidator := mload(add(params, 32))
}
Expand Down
6 changes: 5 additions & 1 deletion packages/evm/contracts/test/MockCyphernodeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ contract MockCyphernodeRegistry is ICyphernodeRegistry {
}

function getCommitteePublicKey(uint256 e3Id) external pure returns (bytes memory) {
return abi.encodePacked(keccak256(abi.encode(e3Id)));
if (e3Id == type(uint256).max) {
return hex"";
} else {
return abi.encodePacked(keccak256(abi.encode(e3Id)));
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/evm/contracts/test/MockExecutionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ contract MockExecutionModule is IExecutionModule {

function validate(bytes memory params) external pure returns (IOutputVerifier outputVerifier) {
require(params.length == 32, invalidParams());
// solhint-disable no-inline-assembly
assembly {
outputVerifier := mload(add(params, 32))
}
Expand Down
3 changes: 2 additions & 1 deletion packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@gnosisguild/enclave",
"description": "Enclave is an open-source protocol for Encrypted Execution Environments (E3).",
"version": "0.0.0",
"license": "LGPL-3.0-only",
"author": {
"name": "gnosisguild",
"url": "https://github.com/gnosisguild"
Expand All @@ -24,7 +25,7 @@
"@typescript-eslint/parser": "^7.11.0",
"chai": "^4.3.10",
"cross-env": "^7.0.3",
"eslint": "^9.4.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"ethers": "^6.9.0",
"fs-extra": "^11.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/test/Enclave.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ describe("Enclave", function () {
const e3Id = 0;
const e3 = await enclave.getE3(e3Id);

expect(await enclave.activate(e3Id))
await expect(enclave.activate(e3Id))
.to.emit(enclave, "E3Activated")
.withArgs(e3Id, e3.expiration, e3.committeePublicKey);
});
Expand Down
Loading

0 comments on commit 72f187d

Please sign in to comment.