-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,058 additions
and
87 deletions.
There are no files selected for viewing
This file contains 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 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,166 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import "fhevm/lib/TFHE.sol"; | ||
import "fhevm/oracle/OracleCaller.sol"; | ||
|
||
contract TestAsyncDecrypt is OracleCaller { | ||
ebool xBool; | ||
euint4 xUint4; | ||
euint8 xUint8; | ||
euint16 xUint16; | ||
euint32 xUint32; | ||
euint64 xUint64; | ||
eaddress xAddress; | ||
|
||
bool public yBool; | ||
uint8 public yUint4; | ||
uint8 public yUint8; | ||
uint16 public yUint16; | ||
uint32 public yUint32; | ||
uint64 public yUint64; | ||
address public yAddress; | ||
|
||
constructor() { | ||
xBool = TFHE.asEbool(true); | ||
xUint4 = TFHE.asEuint4(4); | ||
xUint8 = TFHE.asEuint8(42); | ||
xUint16 = TFHE.asEuint16(16); | ||
xUint32 = TFHE.asEuint32(32); | ||
xUint64 = TFHE.asEuint64(64); | ||
xAddress = TFHE.asEaddress(0x8ba1f109551bD432803012645Ac136ddd64DBA72); | ||
} | ||
|
||
function requestBoolAboveDelay() public { | ||
// should revert | ||
ebool[] memory cts = new ebool[](1); | ||
cts[0] = xBool; | ||
Oracle.requestDecryption(cts, this.callbackBool.selector, 0, block.timestamp + 2 days); | ||
} | ||
|
||
function requestBool() public { | ||
ebool[] memory cts = new ebool[](1); | ||
cts[0] = xBool; | ||
Oracle.requestDecryption(cts, this.callbackBool.selector, 0, block.timestamp + 100); | ||
} | ||
|
||
function requestFakeBool() public { | ||
ebool[] memory cts = new ebool[](1); | ||
cts[0] = ebool.wrap(42); | ||
Oracle.requestDecryption(cts, this.callbackBool.selector, 0, block.timestamp + 100); // this should revert because previous ebool is not honestly obtained | ||
} | ||
|
||
function callbackBool(uint256 /*requestID*/, bool decryptedInput) public onlyOracle returns (bool) { | ||
yBool = decryptedInput; | ||
return yBool; | ||
} | ||
|
||
function requestUint4() public { | ||
euint4[] memory cts = new euint4[](1); | ||
cts[0] = xUint4; | ||
Oracle.requestDecryption(cts, this.callbackUint4.selector, 0, block.timestamp + 100); | ||
} | ||
|
||
function requestFakeUint4() public { | ||
euint4[] memory cts = new euint4[](1); | ||
cts[0] = euint4.wrap(42); | ||
Oracle.requestDecryption(cts, this.callbackUint4.selector, 0, block.timestamp + 100); // this should revert because previous ebool is not honestly obtained | ||
} | ||
|
||
function callbackUint4(uint256 /*requestID*/, uint8 decryptedInput) public onlyOracle returns (uint8) { | ||
yUint4 = decryptedInput; | ||
return decryptedInput; | ||
} | ||
|
||
function requestUint8() public { | ||
euint8[] memory cts = new euint8[](1); | ||
cts[0] = xUint8; | ||
Oracle.requestDecryption(cts, this.callbackUint8.selector, 0, block.timestamp + 100); | ||
} | ||
|
||
function requestFakeUint8() public { | ||
euint8[] memory cts = new euint8[](1); | ||
cts[0] = euint8.wrap(42); | ||
Oracle.requestDecryption(cts, this.callbackUint8.selector, 0, block.timestamp + 100); // this should revert because previous ebool is not honestly obtained | ||
} | ||
|
||
function callbackUint8(uint256 /*requestID*/, uint8 decryptedInput) public onlyOracle returns (uint8) { | ||
yUint8 = decryptedInput; | ||
return decryptedInput; | ||
} | ||
|
||
function requestUint16() public { | ||
euint16[] memory cts = new euint16[](1); | ||
cts[0] = xUint16; | ||
Oracle.requestDecryption(cts, this.callbackUint16.selector, 0, block.timestamp + 100); | ||
} | ||
|
||
function requestFakeUint16() public { | ||
euint16[] memory cts = new euint16[](1); | ||
cts[0] = euint16.wrap(42); | ||
Oracle.requestDecryption(cts, this.callbackUint16.selector, 0, block.timestamp + 100); // this should revert because previous ebool is not honestly obtained | ||
} | ||
|
||
function callbackUint16(uint256 /*requestID*/, uint16 decryptedInput) public onlyOracle returns (uint16) { | ||
yUint16 = decryptedInput; | ||
return decryptedInput; | ||
} | ||
|
||
function requestUint32(uint32 input1, uint32 input2) public { | ||
euint32[] memory cts = new euint32[](1); | ||
cts[0] = xUint32; | ||
uint256 requestID = Oracle.requestDecryption(cts, this.callbackUint32.selector, 0, block.timestamp + 100); | ||
addParamsUint(requestID, input1); | ||
addParamsUint(requestID, input2); | ||
} | ||
|
||
function requestFakeUint32() public { | ||
euint32[] memory cts = new euint32[](1); | ||
cts[0] = euint32.wrap(42); | ||
Oracle.requestDecryption(cts, this.callbackUint32.selector, 0, block.timestamp + 100); // this should revert because previous ebool is not honestly obtained | ||
} | ||
|
||
function callbackUint32(uint256 requestID, uint32 decryptedInput) public onlyOracle returns (uint32) { | ||
uint256[] memory params = getParamsUint(requestID); | ||
unchecked { | ||
uint32 result = uint32(params[0]) + uint32(params[1]) + decryptedInput; | ||
yUint32 = result; | ||
return result; | ||
} | ||
} | ||
|
||
function requestUint64() public { | ||
euint64[] memory cts = new euint64[](1); | ||
cts[0] = xUint64; | ||
Oracle.requestDecryption(cts, this.callbackUint64.selector, 0, block.timestamp + 100); | ||
} | ||
|
||
function requestFakeUint64() public { | ||
euint64[] memory cts = new euint64[](1); | ||
cts[0] = euint64.wrap(42); | ||
Oracle.requestDecryption(cts, this.callbackUint64.selector, 0, block.timestamp + 100); // this should revert because previous ebool is not honestly obtained | ||
} | ||
|
||
function callbackUint64(uint256 /*requestID*/, uint64 decryptedInput) public onlyOracle returns (uint64) { | ||
yUint64 = decryptedInput; | ||
return decryptedInput; | ||
} | ||
|
||
function requestAddress() public { | ||
eaddress[] memory cts = new eaddress[](1); | ||
cts[0] = xAddress; | ||
Oracle.requestDecryption(cts, this.callbackAddress.selector, 0, block.timestamp + 100); | ||
} | ||
|
||
function requestFakeAddress() public { | ||
eaddress[] memory cts = new eaddress[](1); | ||
cts[0] = eaddress.wrap(42); | ||
Oracle.requestDecryption(cts, this.callbackAddress.selector, 0, block.timestamp + 100); // this should revert because previous ebool is not honestly obtained | ||
} | ||
|
||
function callbackAddress(uint256 /*requestID*/, address decryptedInput) public onlyOracle returns (address) { | ||
yAddress = decryptedInput; | ||
return decryptedInput; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 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 @@ | ||
#!/bin/bash | ||
|
||
PRIVATE_KEY_ORACLE_DEPLOYER=$(grep PRIVATE_KEY_ORACLE_DEPLOYER .env | cut -d '"' -f 2) | ||
|
||
npx hardhat task:computePredeployAddress --private-key "$PRIVATE_KEY_ORACLE_DEPLOYER" | ||
|
||
PRIVATE_KEY_ORACLE_RELAYER=$(grep PRIVATE_KEY_ORACLE_RELAYER .env | cut -d '"' -f 2) | ||
|
||
ORACLE_CONTRACT_PREDEPLOY_ADDRESS=$(grep ORACLE_CONTRACT_PREDEPLOY_ADDRESS node_modules/fhevm/oracle/.env.oracle | cut -d '=' -f2) | ||
|
||
docker run -d -i -p 8545:8545 --rm --name fhevm \ | ||
-e PRIVATE_KEY_ORACLE_RELAYER="$PRIVATE_KEY_ORACLE_RELAYER" \ | ||
-e ORACLE_CONTRACT_PREDEPLOY_ADDRESS="$ORACLE_CONTRACT_PREDEPLOY_ADDRESS" \ | ||
ghcr.io/zama-ai/ethermint-dev-node:v0.4.2 | ||
|
||
sleep 10 | ||
|
||
npx hardhat compile | ||
|
||
npx hardhat task:launchFhevm | ||
|
||
docker attach fhevm |
This file contains 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.