diff --git a/crates/evm-helpers/src/contracts.rs b/crates/evm-helpers/src/contracts.rs index bdb27f6e88..30b6e4e315 100644 --- a/crates/evm-helpers/src/contracts.rs +++ b/crates/evm-helpers/src/contracts.rs @@ -125,7 +125,7 @@ sol! { mapping(uint256 e3Id => bytes params) public e3Params; mapping(address e3Program => bool allowed) public e3Programs; function request(E3RequestParams calldata requestParams) external returns (uint256 e3Id, E3 memory e3); - function enableE3Program(address e3Program) public onlyOwner returns (bool success); + function enableE3Program(address e3Program) public returns (bool success); function publishCiphertextOutput(uint256 e3Id, bytes calldata ciphertextOutput, bytes calldata proof) external returns (bool success); function publishPlaintextOutput(uint256 e3Id, bytes calldata data, bytes calldata proof) external returns (bool success); function getE3(uint256 e3Id) external view returns (E3 memory e3); diff --git a/packages/enclave-contracts/artifacts/contracts/interfaces/IBondingRegistry.sol/IBondingRegistry.json b/packages/enclave-contracts/artifacts/contracts/interfaces/IBondingRegistry.sol/IBondingRegistry.json index 7f9de47db8..f5615b6386 100644 --- a/packages/enclave-contracts/artifacts/contracts/interfaces/IBondingRegistry.sol/IBondingRegistry.json +++ b/packages/enclave-contracts/artifacts/contracts/interfaces/IBondingRegistry.sol/IBondingRegistry.json @@ -940,5 +940,5 @@ "deployedLinkReferences": {}, "immutableReferences": {}, "inputSourceName": "project/contracts/interfaces/IBondingRegistry.sol", - "buildInfoId": "solc-0_8_28-dbd94fb7bf5c147a4effe4d89ec8d62bae78112f" + "buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba" } \ No newline at end of file diff --git a/packages/enclave-contracts/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.json b/packages/enclave-contracts/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.json index 6407b1521d..f9388e7df0 100644 --- a/packages/enclave-contracts/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.json +++ b/packages/enclave-contracts/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.json @@ -782,5 +782,5 @@ "deployedLinkReferences": {}, "immutableReferences": {}, "inputSourceName": "project/contracts/interfaces/ICiphernodeRegistry.sol", - "buildInfoId": "solc-0_8_28-dbd94fb7bf5c147a4effe4d89ec8d62bae78112f" + "buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba" } \ No newline at end of file diff --git a/packages/enclave-contracts/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.json b/packages/enclave-contracts/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.json index 5c5263a687..6d07ea3d4e 100644 --- a/packages/enclave-contracts/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.json +++ b/packages/enclave-contracts/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.json @@ -1313,5 +1313,5 @@ "deployedLinkReferences": {}, "immutableReferences": {}, "inputSourceName": "project/contracts/interfaces/IEnclave.sol", - "buildInfoId": "solc-0_8_28-dbd94fb7bf5c147a4effe4d89ec8d62bae78112f" + "buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba" } \ No newline at end of file diff --git a/packages/enclave-contracts/artifacts/contracts/interfaces/ISlashingManager.sol/ISlashingManager.json b/packages/enclave-contracts/artifacts/contracts/interfaces/ISlashingManager.sol/ISlashingManager.json index 48541a975b..17073c1290 100644 --- a/packages/enclave-contracts/artifacts/contracts/interfaces/ISlashingManager.sol/ISlashingManager.json +++ b/packages/enclave-contracts/artifacts/contracts/interfaces/ISlashingManager.sol/ISlashingManager.json @@ -954,5 +954,5 @@ "deployedLinkReferences": {}, "immutableReferences": {}, "inputSourceName": "project/contracts/interfaces/ISlashingManager.sol", - "buildInfoId": "solc-0_8_28-dbd94fb7bf5c147a4effe4d89ec8d62bae78112f" + "buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba" } \ No newline at end of file diff --git a/packages/enclave-contracts/artifacts/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier.json b/packages/enclave-contracts/artifacts/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier.json index 4f248bff8c..d1bc14ae2e 100644 --- a/packages/enclave-contracts/artifacts/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier.json +++ b/packages/enclave-contracts/artifacts/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier.json @@ -102,7 +102,7 @@ } }, "immutableReferences": { - "17861": [ + "33496": [ { "length": 32, "start": 91 @@ -152,13 +152,13 @@ "start": 11165 } ], - "17863": [ + "33498": [ { "length": 32, "start": 398 } ], - "17865": [ + "33500": [ { "length": 32, "start": 432 @@ -168,7 +168,7 @@ "start": 2303 } ], - "17867": [ + "33502": [ { "length": 32, "start": 3156 @@ -184,5 +184,5 @@ ] }, "inputSourceName": "project/contracts/verifier/DkgPkVerifier.sol", - "buildInfoId": "solc-0_8_28-608af4cb791a4cb30d57991d993af95c6fcfa77a" + "buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba" } \ No newline at end of file diff --git a/packages/enclave-contracts/artifacts/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib.json b/packages/enclave-contracts/artifacts/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib.json index 3aea254962..e066bbdadb 100644 --- a/packages/enclave-contracts/artifacts/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib.json +++ b/packages/enclave-contracts/artifacts/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib.json @@ -391,5 +391,5 @@ "deployedLinkReferences": {}, "immutableReferences": {}, "inputSourceName": "project/contracts/verifier/DkgPkVerifier.sol", - "buildInfoId": "solc-0_8_28-608af4cb791a4cb30d57991d993af95c6fcfa77a" + "buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba" } \ No newline at end of file diff --git a/packages/enclave-contracts/contracts/Enclave.sol b/packages/enclave-contracts/contracts/Enclave.sol index 743c8c3ba4..35874c4df9 100644 --- a/packages/enclave-contracts/contracts/Enclave.sol +++ b/packages/enclave-contracts/contracts/Enclave.sol @@ -299,9 +299,6 @@ contract Enclave is IEnclave, OwnableUpgradeable { // input start date should be in the future require( requestParams.inputWindow[0] >= block.timestamp, - // && - // requestParams.inputWindow[0] >= block.timestamp + - // _timeoutConfig.dkgWindow, InvalidInputDeadlineStart(requestParams.inputWindow[0]) ); // the end of the input window should be after the start @@ -329,6 +326,18 @@ contract Enclave is IEnclave, OwnableUpgradeable { nexte3Id++; uint256 seed = uint256(keccak256(abi.encode(block.prevrandao, e3Id))); + e3Payments[e3Id] = e3Fee; + _e3FeeTokens[e3Id] = feeToken; + + // Initialize E3 Lifecycle + _e3Stages[e3Id] = E3Stage.Requested; + _e3Requesters[e3Id] = msg.sender; + + // the compute deadline is end of input window + compute window + _e3Deadlines[e3Id].computeDeadline = + requestParams.inputWindow[1] + + _timeoutConfig.computeWindow; + e3.seed = seed; e3.committeeSize = requestParams.committeeSize; e3.requestBlock = block.number; @@ -341,6 +350,8 @@ contract Enclave is IEnclave, OwnableUpgradeable { e3.plaintextOutput = hex""; e3.requester = msg.sender; + feeToken.safeTransferFrom(msg.sender, address(this), e3Fee); + bytes32 encryptionSchemeId = requestParams.e3Program.validate( e3Id, seed, @@ -360,29 +371,13 @@ contract Enclave is IEnclave, OwnableUpgradeable { e3.encryptionSchemeId = encryptionSchemeId; e3.decryptionVerifier = decryptionVerifier; - e3s[e3Id] = e3; - e3Payments[e3Id] = e3Fee; - - feeToken.safeTransferFrom(msg.sender, address(this), e3Fee); - - // Store the fee token used for this E3 (survives global token rotations) - _e3FeeTokens[e3Id] = feeToken; require( ciphernodeRegistry.requestCommittee(e3Id, seed, threshold), CommitteeSelectionFailed() ); - // Initialize E3 lifecycle - _e3Stages[e3Id] = E3Stage.Requested; - _e3Requesters[e3Id] = msg.sender; - - // the compute deadline is end of input window + compute window - _e3Deadlines[e3Id].computeDeadline = - e3.inputWindow[1] + - _timeoutConfig.computeWindow; - emit E3Requested(e3Id, e3, requestParams.e3Program); emit E3StageChanged(e3Id, E3Stage.None, E3Stage.Requested); } @@ -423,16 +418,14 @@ contract Enclave is IEnclave, OwnableUpgradeable { bytes32 ciphertextOutputHash = keccak256(ciphertextOutput); e3s[e3Id].ciphertextOutput = ciphertextOutputHash; - - (success) = e3.e3Program.verify(e3Id, ciphertextOutputHash, proof); - require(success, InvalidOutput(ciphertextOutput)); - - // Update lifecycle stage _e3Stages[e3Id] = E3Stage.CiphertextReady; _e3Deadlines[e3Id].decryptionDeadline = block.timestamp + _timeoutConfig.decryptionWindow; + (success) = e3.e3Program.verify(e3Id, ciphertextOutputHash, proof); + require(success, InvalidOutput(ciphertextOutput)); + emit CiphertextOutputPublished(e3Id, ciphertextOutput); emit E3StageChanged( e3Id, @@ -466,6 +459,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { ); e3s[e3Id].plaintextOutput = plaintextOutput; + _e3Stages[e3Id] = E3Stage.Complete; (success) = e3.decryptionVerifier.verify( e3Id, @@ -474,9 +468,6 @@ contract Enclave is IEnclave, OwnableUpgradeable { ); require(success, InvalidOutput(plaintextOutput)); - // Update lifecycle stage to Complete - _e3Stages[e3Id] = E3Stage.Complete; - _distributeRewards(e3Id); emit PlaintextOutputPublished(e3Id, plaintextOutput); @@ -633,7 +624,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { } /// @inheritdoc IEnclave - function enableE3Program(IE3Program e3Program) public onlyOwner { + function enableE3Program(IE3Program e3Program) public { require( !e3Programs[e3Program], ModuleAlreadyEnabled(address(e3Program)) diff --git a/packages/enclave-contracts/test/Enclave.spec.ts b/packages/enclave-contracts/test/Enclave.spec.ts index 035f4e0154..158bf48aab 100644 --- a/packages/enclave-contracts/test/Enclave.spec.ts +++ b/packages/enclave-contracts/test/Enclave.spec.ts @@ -624,17 +624,6 @@ describe("Enclave", function () { }); describe("enableE3Program()", function () { - it("reverts if not called by owner", async function () { - const { - enclave, - mocks: { e3Program }, - notTheOwner, - } = await loadFixture(setup); - - 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,