-
Notifications
You must be signed in to change notification settings - Fork 53
Add DKG and CDR contracts #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Spablob
wants to merge
15
commits into
piplabs:dev/dkg-cdr
Choose a base branch
from
Spablob:dkg-cdr
base: dev/dkg-cdr
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
95083ea
first draft
Spablob 696c516
lint fix
Spablob 6530e91
add setTcbEvaluationDataNumber
Spablob 3ee8fa0
remove EnclaveInstanceData from finalize
Spablob 277bd4c
remove enclaveAddr
Spablob 0cedcac
rename variable
Spablob 5fa688c
add codeCommitment in Register event
Spablob 7aabba0
remove verification tcbEvalNumber
Spablob 0f34726
add set dkg to generateAlloc
Spablob 6466a68
adjust interfaces
Spablob 0385200
add dkg to predeploys
Spablob 30b640e
change access to owner and add get functions
Spablob e5068b4
add upgradeability and get functions to SGX hook
Spablob c401834
add dkg unit test boilerplate
Spablob c480729
adjust register method and event
Spablob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-only | ||
| pragma solidity 0.8.23; | ||
|
|
||
| interface IAttestationReportValidator { | ||
| // validateReport accepts a remote attestation report (e.g. rawQuote for SGX) and validates a remote attestation report following these steps | ||
| // 1. validate the report | ||
| // 1.1 checks the report size and format | ||
| // 1.2 checks the signature included in the report | ||
| // 1.3 checks if the signature is from an authorized authority (e.g. valid certificate etc) | ||
| // 2. extracts the code commitment from the report (e.g. MRENCLAVE in SGX) and compares it with the expected value | ||
| // this ensures the code and init data for loading the enclave was correct and untamperred | ||
| // 3. extracts the data commitment from the report (e.g. first 32 bytes of the REPORT_DATA) and compares it with the expected value | ||
| // this ensures the data part is correct, this is instance specific for example this is hash of node info values. | ||
| function validateReport( | ||
| bytes32 expectedCodeCommitment, | ||
| bytes32 expectedDataCommitment, | ||
| bytes calldata enclaveReport, | ||
| bytes calldata validationContext | ||
| ) external returns (bool); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-only | ||
| pragma solidity 0.8.23; | ||
|
|
||
| interface IDKG { | ||
| /// @notice Struct for the enclave type data unique to each enclave type | ||
| /// @param codeCommitment The code commitment | ||
| /// @param validationHookAddr The address of the validation hook | ||
| struct EnclaveTypeData { | ||
| bytes32 codeCommitment; | ||
| address validationHookAddr; | ||
| } | ||
|
|
||
| /// @notice Struct for the enclave instance data unique to each instance | ||
| /// @param round The round | ||
| /// @param validatorAddr The address of the validator | ||
| /// @param enclaveType The type of the enclave | ||
| /// @param enclaveCommKey The communication key of the enclave | ||
| /// @param dkgPubKey The DKG public key | ||
| struct EnclaveInstanceData { | ||
| uint32 round; | ||
| address validatorAddr; | ||
| bytes32 enclaveType; | ||
| bytes enclaveCommKey; | ||
| bytes dkgPubKey; | ||
| } | ||
|
|
||
| /// @notice Emitted when the minimum required registered participants is set | ||
| /// @param newMinReqRegisteredParticipants The new minimum required registered participants | ||
| event MinReqRegisteredParticipantsSet(uint256 newMinReqRegisteredParticipants); | ||
|
|
||
| /// @notice Emitted when the minimum required finalized participants is set | ||
| /// @param newMinReqFinalizedParticipants The new minimum required finalized participants | ||
| event MinReqFinalizedParticipantsSet(uint256 newMinReqFinalizedParticipants); | ||
|
|
||
| /// @notice Emitted when the operational threshold is set | ||
| /// @param newOperationalThreshold The new operational threshold | ||
| event OperationalThresholdSet(uint256 newOperationalThreshold); | ||
|
|
||
| /// @notice Emitted when the fee is set | ||
| /// @param newFee The new fee | ||
| event FeeSet(uint256 newFee); | ||
|
|
||
| /// @notice Emitted when an enclave type is whitelisted | ||
| /// @param enclaveType The type of the enclave | ||
| /// @param codeCommitment The code commitment | ||
| /// @param validationHookAddr The address of the validation hook | ||
| /// @param isWhitelisted Whether the enclave type is whitelisted | ||
| event EnclaveTypeWhitelisted( | ||
| bytes32 enclaveType, | ||
| bytes32 codeCommitment, | ||
| address validationHookAddr, | ||
| bool isWhitelisted | ||
| ); | ||
|
|
||
| /// @notice Emitted when an enclave instance is registered | ||
| /// @param enclaveReport The enclave report | ||
| /// @param round The round | ||
| /// @param validatorAddr The address of the validator | ||
| /// @param enclaveType The type of the enclave | ||
| /// @param enclaveCommKey The communication key of the enclave | ||
| /// @param dkgPubKey The DKG public key | ||
| /// @param codeCommitment The code commitment | ||
| /// @param startBlockHeight The start block height | ||
| /// @param startBlockHash The start block hash | ||
| /// @param validationContext The validation context | ||
| event Registered( | ||
| bytes enclaveReport, | ||
| uint32 round, | ||
| address indexed validatorAddr, | ||
| bytes32 enclaveType, | ||
| bytes enclaveCommKey, | ||
| bytes dkgPubKey, | ||
| bytes32 codeCommitment, | ||
| uint256 startBlockHeight, | ||
| bytes32 startBlockHash, | ||
| bytes validationContext | ||
0xHansLee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| /// @notice Emitted when an enclave instance is finalized | ||
| /// @param round The round | ||
| /// @param validatorAddr The address of the validator | ||
| /// @param enclaveType The type of the enclave | ||
| /// @param codeCommitment The code commitment | ||
| /// @param participantsRoot The participants root | ||
| /// @param globalPubKey The global public key | ||
| /// @param publicCoeffs The public coefficients | ||
| /// @param signature The signature | ||
| event Finalized( | ||
| uint32 round, | ||
| address indexed validatorAddr, | ||
| bytes32 enclaveType, | ||
| bytes32 codeCommitment, | ||
| bytes32 participantsRoot, | ||
| bytes globalPubKey, | ||
| bytes[] publicCoeffs, | ||
| bytes signature | ||
| ); | ||
|
|
||
| /// @notice Sets the minimum number of participants needed to be registered for each round | ||
| /// @param newMinReqRegisteredParticipants The minimum number of participants needed to be registered for each round | ||
| function setMinReqRegisteredParticipants(uint256 newMinReqRegisteredParticipants) external; | ||
|
|
||
| /// @notice Sets the minimum number of participants needed to finish dkg for each round | ||
| /// @param newMinReqFinalizedParticipants The minimum number of participants needed to finish dkg for each round | ||
| function setMinReqFinalizedParticipants(uint256 newMinReqFinalizedParticipants) external; | ||
|
|
||
| /// @notice Sets the operational threshold | ||
| /// @param newOperationalThreshold The operational threshold | ||
| function setOperationalThreshold(uint256 newOperationalThreshold) external; | ||
|
|
||
| /// @notice Sets the fee paid to request DKG registration (register and finalize) | ||
| /// @param newFee The fee paid to request DKG registration (register and finalize) | ||
| function setFee(uint256 newFee) external; | ||
|
|
||
| /// @notice Whitelists an enclave type | ||
| /// @param enclaveType The type of the enclave | ||
| /// @param enclaveTypeData The data of the enclave type | ||
| /// @param isWhitelisted Whether the enclave type is whitelisted | ||
| function whitelistEnclaveType( | ||
| bytes32 enclaveType, | ||
| EnclaveTypeData memory enclaveTypeData, | ||
| bool isWhitelisted | ||
| ) external; | ||
|
|
||
| /// @notice Authenticates an enclave report | ||
| /// @param enclaveReport The enclave report | ||
| /// @param enclaveInstanceData The data of the enclave instance | ||
| /// @param validationContext The validation context | ||
| function authenticateEnclaveReport( | ||
| bytes calldata enclaveReport, | ||
| EnclaveInstanceData calldata enclaveInstanceData, | ||
| bytes calldata validationContext | ||
| ) external payable; | ||
|
|
||
| /// @notice Registers an enclave instance | ||
| /// @param enclaveReport The enclave report | ||
| /// @param enclaveInstanceData The data of the enclave instance | ||
| /// @param startBlockHeight The start block height | ||
| /// @param startBlockHash The start block hash | ||
| /// @param validationContext The validation context | ||
| function register( | ||
| bytes calldata enclaveReport, | ||
| EnclaveInstanceData calldata enclaveInstanceData, | ||
| uint256 startBlockHeight, | ||
| bytes32 startBlockHash, | ||
| bytes calldata validationContext | ||
| ) external payable; | ||
|
|
||
| /// @notice Finalizes an enclave instance | ||
| /// @param round The round | ||
| /// @param validatorAddr The address of the validator | ||
| /// @param enclaveType The type of the enclave | ||
| /// @param participantsRoot The participants root | ||
| /// @param globalPubKey The global public key | ||
| /// @param publicCoeffs The public coefficients | ||
| /// @param signature The signature | ||
| function finalize( | ||
| uint32 round, | ||
| address validatorAddr, | ||
| bytes32 enclaveType, | ||
| bytes32 participantsRoot, | ||
| bytes calldata globalPubKey, | ||
| bytes[] calldata publicCoeffs, | ||
| bytes calldata signature | ||
| ) external payable; | ||
|
|
||
| /// @notice Gets the minimum number of participants needed to be registered for each round | ||
| /// @return The minimum number of participants needed to be registered for each round | ||
| function minReqRegisteredParticipants() external view returns (uint256); | ||
|
|
||
| /// @notice Gets the minimum number of participants needed to finish dkg for each round | ||
| /// @return The minimum number of participants needed to finish dkg for each round | ||
| function minReqFinalizedParticipants() external view returns (uint256); | ||
|
|
||
| /// @notice Gets the operational threshold | ||
| /// @return The operational threshold | ||
| function operationalThreshold() external view returns (uint256); | ||
|
|
||
| /// @notice Gets the fee paid to request DKG registration (register and finalize) | ||
| /// @return The fee paid to request DKG registration (register and finalize) | ||
| function fee() external view returns (uint256); | ||
|
|
||
| /// @notice Gets the enclave type data | ||
| /// @param enclaveType The type of the enclave | ||
| function enclaveTypeData(bytes32 enclaveType) external view returns (EnclaveTypeData memory); | ||
|
|
||
| /// @notice Gets the is enclave type whitelisted | ||
| /// @param enclaveType The type of the enclave | ||
| function isEnclaveTypeWhitelisted(bytes32 enclaveType) external view returns (bool); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-only | ||
| pragma solidity 0.8.23; | ||
|
|
||
| import { IAttestationReportValidator } from "./IAttestationReportValidator.sol"; | ||
|
|
||
| interface ISGXValidationHook is IAttestationReportValidator { | ||
| /// @notice Sets the address of the automata validation contract | ||
| /// @param newAutomataValidationAddr The address of the automata validation contract | ||
| function setAutomataValidationAddr(address newAutomataValidationAddr) external; | ||
|
|
||
| /// @notice Sets the TCB evaluation data number | ||
| /// @param newTcbEvaluationDataNumber The TCB evaluation data number | ||
| function setTcbEvaluationDataNumber(uint32 newTcbEvaluationDataNumber) external; | ||
|
|
||
| /// @notice Gets the address of the automata validation contract | ||
| /// @return The address of the automata validation contract | ||
| function automataValidationAddr() external view returns (address); | ||
|
|
||
| /// @notice Gets the TCB evaluation data number | ||
| /// @return The TCB evaluation data number | ||
| function tcbEvaluationDataNumber() external view returns (uint32); | ||
| } |
9 changes: 9 additions & 0 deletions
9
contracts/src/interfaces/external/IAutomataDcapAttestationFee.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-only | ||
| pragma solidity 0.8.23; | ||
|
|
||
| interface IAutomataDcapAttestationFee { | ||
| function verifyAndAttestOnChain( | ||
| bytes calldata rawQuote, | ||
| uint32 tcbEvaluationDataNumber | ||
| ) external payable returns (bool success, bytes memory output); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-only | ||
| pragma solidity 0.8.23; | ||
|
|
||
| library BytesUtils { | ||
| /// @dev Copies a substring into a new byte string | ||
| /// @param self The byte string to copy from | ||
| /// @param offset The offset to start copying at | ||
| /// @param len The number of bytes to copy | ||
| /// @return The new byte string | ||
| function substring(bytes memory self, uint256 offset, uint256 len) internal pure returns (bytes memory) { | ||
| require(offset + len <= self.length); | ||
0xHansLee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| bytes memory ret = new bytes(len); | ||
| uint256 dest; | ||
| uint256 src; | ||
|
|
||
| assembly { | ||
| dest := add(ret, 32) | ||
| src := add(add(self, 32), offset) | ||
| } | ||
| memcpy(dest, src, len); | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| function memcpy(uint256 dest, uint256 src, uint256 len) private pure { | ||
| // Copy word-length chunks while possible | ||
| for (; len >= 32; len -= 32) { | ||
| assembly { | ||
| mstore(dest, mload(src)) | ||
| } | ||
| dest += 32; | ||
| src += 32; | ||
| } | ||
|
|
||
| // Copy remaining bytes | ||
| uint256 mask; | ||
| if (len == 0) { | ||
| mask = type(uint256).max; // Set to maximum value of uint256 | ||
| } else { | ||
| mask = 256 ** (32 - len) - 1; | ||
| } | ||
|
|
||
| assembly { | ||
| let srcpart := and(mload(src), not(mask)) | ||
| let destpart := and(mload(dest), mask) | ||
| mstore(dest, or(destpart, srcpart)) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is validation context? is it params needed for passing to automata?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's arbitrary data depending on each enclave type - for SGX is the
tbcEvalNumber. When not needed can pass empty