Skip to content
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

feat: new DecryptionOracle contract #217

Merged
merged 6 commits into from
Dec 26, 2024
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
4 changes: 2 additions & 2 deletions contracts/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export MNEMONIC="adapt mosquito move limb mobile illegal tree voyage juice mosquito burger raise father hope layer"
export PRIVATE_KEY_FHEVM_DEPLOYER="0c66d8cde71d2faa29d0cb6e3a567d31279b6eace67b0a9d9ba869c119843a5e"
export PRIVATE_KEY_GATEWAY_DEPLOYER="717fd99986df414889fd8b51069d4f90a50af72e542c58ee065f5883779099c6"
export PRIVATE_KEY_GATEWAY_RELAYER="7ec931411ad75a7c201469a385d6f18a325d4923f9f213bd882bbea87e160b67"
export PRIVATE_KEY_DECRYPTION_ORACLE_DEPLOYER="717fd99986df414889fd8b51069d4f90a50af72e542c58ee065f5883779099c6"
export PRIVATE_KEY_DECRYPTION_ORACLE_RELAYER="7ec931411ad75a7c201469a385d6f18a325d4923f9f213bd882bbea87e160b67"
export NUM_KMS_SIGNERS="1"
export PRIVATE_KEY_KMS_SIGNER_0="388b7680e4e1afa06efbfd45cdd1fe39f3c6af381df6555a19661f283b97de91"
export PRIVATE_KEY_KMS_SIGNER_1="bbaed91514fa4b7c86aa4f73becbabcf4bce0ae130240f0d6ac3f87e06812440"
Expand Down
4 changes: 2 additions & 2 deletions contracts/.env.example.deployment
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export PRIVATE_KEY_FHEVM_DEPLOYER="0c66d8cde71d2faa29d0cb6e3a567d31279b6eace67b0a9d9ba869c119843a5e"
export PRIVATE_KEY_GATEWAY_DEPLOYER="717fd99986df414889fd8b51069d4f90a50af72e542c58ee065f5883779099c6"
export ADDRESS_GATEWAY_RELAYER="0x97F272ccfef4026A1F3f0e0E879d514627B84E69"
export PRIVATE_KEY_DECRYPTION_ORACLE_DEPLOYER="717fd99986df414889fd8b51069d4f90a50af72e542c58ee065f5883779099c6"
export ADDRESS_DECRYPTION_ORACLE_RELAYER="0x97F272ccfef4026A1F3f0e0E879d514627B84E69"
export NUM_KMS_SIGNERS="4"
export ADDRESS_KMS_SIGNER_0="0x0971C80fF03B428fD2094dd5354600ab103201C5"
export ADDRESS_KMS_SIGNER_1="0xB68deCb047B5e6Cc82280502A7E2318c6b3E5eC6"
Expand Down
4 changes: 2 additions & 2 deletions contracts/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
!/artifacts/contracts/KMSVerifier.sol/KMSVerifier.json
!/artifacts/contracts/TFHEExecutor.sol/TFHEExecutor.json
!/artifacts/contracts/TFHEExecutorWithEvents.sol/TFHEExecutorWithEvents.json
!/artifacts/gateway/GatewayContract.sol/GatewayContract.json
!/artifacts/decryptionOracle/DecryptionOracle.sol/DecryptionOracle.json
!contracts/**
!gateway/**
!decryptionOracle/**
!package.json
!LICENSE
!README.md
1 change: 1 addition & 0 deletions contracts/addresses/.env.decryptionoracle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DECRYPTION_ORACLE_ADDRESS=0x33347831500F1e73f0ccCBb95c9f86B94d7b1123
2 changes: 1 addition & 1 deletion contracts/addresses/.env.fhegaslimit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FHE_PAYMENT_CONTRACT_ADDRESS=0xFb03BE574d14C256D56F09a198B586bdfc0A9de2
FHE_GASLIMIT_CONTRACT_ADDRESS=0xFb03BE574d14C256D56F09a198B586bdfc0A9de2
1 change: 0 additions & 1 deletion contracts/addresses/.env.gateway

This file was deleted.

5 changes: 5 additions & 0 deletions contracts/addresses/DecryptionOracleAddress.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear

pragma solidity ^0.8.24;

address constant DECRYPTION_ORACLE_ADDRESS = 0x33347831500F1e73f0ccCBb95c9f86B94d7b1123;
5 changes: 0 additions & 5 deletions contracts/addresses/GatewayContractAddress.sol

This file was deleted.

91 changes: 91 additions & 0 deletions contracts/decryptionOracle/DecryptionOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear

pragma solidity ^0.8.24;

import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

contract DecryptionOracle is UUPSUpgradeable, Ownable2StepUpgradeable {
/// @notice Name of the contract
string private constant CONTRACT_NAME = "DecryptionOracle";

/// @notice Major version of the contract.
uint256 private constant MAJOR_VERSION = 0;

/// @notice Minor version of the contract.
uint256 private constant MINOR_VERSION = 1;

/// @notice Patch version of the contract.
uint256 private constant PATCH_VERSION = 0;

event DecryptionRequest(uint256 indexed requestID, uint256[] cts, address contractCaller, bytes4 callbackSelector);

function _authorizeUpgrade(address _newImplementation) internal virtual override onlyOwner {}
jatZama marked this conversation as resolved.
Show resolved Hide resolved

/// @custom:storage-location erc7201:fhevm.storage.DecryptionOracle
struct DecryptionOracleStorage {
uint256 counter; // tracks the number of decryption requests, and used to compute the requestID by hashing it with the dApp address
}

function getCounter() external virtual returns (uint256) {
DecryptionOracleStorage storage $ = _getDecryptionOracleStorage();
return $.counter;
}

// keccak256(abi.encode(uint256(keccak256("fhevm.storage.DecryptionOracle")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant DecryptionOracleStorageLocation =
0xd86fa2a52e99634194c279afa011b5f5166614c3198dd09bbd002d5fb5c0bc00;

/**
* @dev Returns the DecryptionOracle storage location.
*/
function _getDecryptionOracleStorage() internal pure returns (DecryptionOracleStorage storage $) {
assembly {
$.slot := DecryptionOracleStorageLocation
}
}

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(address _decryptionOracleOwner) external initializer {
__Ownable_init(_decryptionOracleOwner);
}

/** @notice Requests the decryption of n ciphertexts `ctsHandles` with the result returned in a callback.
* @notice During callback, msg.sender is called with [callbackSelector,requestID,decrypt(ctsHandles[0]),decrypt(ctsHandles[1]),...,decrypt(ctsHandles[n-1]),signatures]
* @param ctsHandles is an array of uint256s handles.
* @param callbackSelector the callback selector to be called on msg.sender later during fulfilment
*/
function requestDecryption(
uint256[] calldata ctsHandles,
bytes4 callbackSelector
) external virtual returns (uint256 requestID) {
DecryptionOracleStorage storage $ = _getDecryptionOracleStorage();
requestID = uint256(keccak256(abi.encodePacked(msg.sender, $.counter)));
emit DecryptionRequest(requestID, ctsHandles, msg.sender, callbackSelector);
$.counter++;
}

/**
* @notice Getter for the name and version of the contract.
* @return string Name and the version of the contract.
*/
function getVersion() external pure virtual returns (string memory) {
return
string(
abi.encodePacked(
CONTRACT_NAME,
" v",
Strings.toString(MAJOR_VERSION),
".",
Strings.toString(MINOR_VERSION),
".",
Strings.toString(PATCH_VERSION)
)
);
}
}
Loading
Loading