Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/evm-helpers/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment thread
hmzakhalid marked this conversation as resolved.
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,5 +940,5 @@
"deployedLinkReferences": {},
"immutableReferences": {},
"inputSourceName": "project/contracts/interfaces/IBondingRegistry.sol",
"buildInfoId": "solc-0_8_28-dbd94fb7bf5c147a4effe4d89ec8d62bae78112f"
"buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba"
}
Original file line number Diff line number Diff line change
Expand Up @@ -782,5 +782,5 @@
"deployedLinkReferences": {},
"immutableReferences": {},
"inputSourceName": "project/contracts/interfaces/ICiphernodeRegistry.sol",
"buildInfoId": "solc-0_8_28-dbd94fb7bf5c147a4effe4d89ec8d62bae78112f"
"buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1313,5 +1313,5 @@
"deployedLinkReferences": {},
"immutableReferences": {},
"inputSourceName": "project/contracts/interfaces/IEnclave.sol",
"buildInfoId": "solc-0_8_28-dbd94fb7bf5c147a4effe4d89ec8d62bae78112f"
"buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba"
}
Original file line number Diff line number Diff line change
Expand Up @@ -954,5 +954,5 @@
"deployedLinkReferences": {},
"immutableReferences": {},
"inputSourceName": "project/contracts/interfaces/ISlashingManager.sol",
"buildInfoId": "solc-0_8_28-dbd94fb7bf5c147a4effe4d89ec8d62bae78112f"
"buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba"
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
}
},
"immutableReferences": {
"17861": [
"33496": [
{
"length": 32,
"start": 91
Expand Down Expand Up @@ -152,13 +152,13 @@
"start": 11165
}
],
"17863": [
"33498": [
{
"length": 32,
"start": 398
}
],
"17865": [
"33500": [
{
"length": 32,
"start": 432
Expand All @@ -168,7 +168,7 @@
"start": 2303
}
],
"17867": [
"33502": [
{
"length": 32,
"start": 3156
Expand All @@ -184,5 +184,5 @@
]
},
"inputSourceName": "project/contracts/verifier/DkgPkVerifier.sol",
"buildInfoId": "solc-0_8_28-608af4cb791a4cb30d57991d993af95c6fcfa77a"
"buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba"
}
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,5 @@
"deployedLinkReferences": {},
"immutableReferences": {},
"inputSourceName": "project/contracts/verifier/DkgPkVerifier.sol",
"buildInfoId": "solc-0_8_28-608af4cb791a4cb30d57991d993af95c6fcfa77a"
"buildInfoId": "solc-0_8_28-d48586b5c515ad1b112178eeef9419e7799821ba"
}
47 changes: 19 additions & 28 deletions packages/enclave-contracts/contracts/Enclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Comment thread
hmzakhalid marked this conversation as resolved.
e3.seed = seed;
e3.committeeSize = requestParams.committeeSize;
e3.requestBlock = block.number;
Expand All @@ -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,
Expand All @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -466,6 +459,7 @@ contract Enclave is IEnclave, OwnableUpgradeable {
);

e3s[e3Id].plaintextOutput = plaintextOutput;
_e3Stages[e3Id] = E3Stage.Complete;

(success) = e3.decryptionVerifier.verify(
e3Id,
Expand All @@ -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);
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 0 additions & 11 deletions packages/enclave-contracts/test/Enclave.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading