|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause-Clear |
| 2 | + |
| 3 | +pragma solidity ^0.8.24; |
| 4 | + |
| 5 | +import "../lib/FHE.sol"; |
| 6 | +import {CoprocessorSetup} from "../lib/CoprocessorSetup.sol"; |
| 7 | + |
| 8 | +/// @notice First contract for testing asynchronous decryption via multiple contracts |
| 9 | +contract TestAsyncDecryptA { |
| 10 | + euint64 xUint64; |
| 11 | + uint64 public yUint64; |
| 12 | + |
| 13 | + constructor() { |
| 14 | + FHE.setCoprocessor(CoprocessorSetup.defaultConfig()); |
| 15 | + xUint64 = FHE.asEuint64(424242); |
| 16 | + FHE.allowThis(xUint64); |
| 17 | + } |
| 18 | + |
| 19 | + function requestUint64() public { |
| 20 | + bytes32[] memory cts = new bytes32[](1); |
| 21 | + cts[0] = FHE.toBytes32(xUint64); |
| 22 | + FHE.requestDecryption(cts, this.callbackUint64.selector); |
| 23 | + } |
| 24 | + |
| 25 | + function callbackUint64(uint256 requestID, bytes memory cleartexts, bytes memory decryptionProof) public { |
| 26 | + FHE.checkSignatures(requestID, cleartexts, decryptionProof); |
| 27 | + uint64 decryptedInput = abi.decode(cleartexts, (uint64)); |
| 28 | + yUint64 = decryptedInput; |
| 29 | + revert(); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +/// @notice Second contract for testing asynchronous decryption via multiple contracts |
| 34 | +contract TestAsyncDecryptB { |
| 35 | + euint64 xUint64; |
| 36 | + uint64 public yUint64; |
| 37 | + |
| 38 | + constructor() { |
| 39 | + FHE.setCoprocessor(CoprocessorSetup.defaultConfig()); |
| 40 | + xUint64 = FHE.asEuint64(373737); |
| 41 | + FHE.allowThis(xUint64); |
| 42 | + } |
| 43 | + |
| 44 | + function requestUint64() public { |
| 45 | + bytes32[] memory cts = new bytes32[](1); |
| 46 | + cts[0] = FHE.toBytes32(xUint64); |
| 47 | + FHE.requestDecryption(cts, this.callbackUint64.selector); |
| 48 | + } |
| 49 | + |
| 50 | + function callbackUint64(uint256 requestID, bytes memory cleartexts, bytes memory decryptionProof) public { |
| 51 | + FHE.checkSignatures(requestID, cleartexts, decryptionProof); |
| 52 | + uint64 decryptedInput = abi.decode(cleartexts, (uint64)); |
| 53 | + yUint64 = decryptedInput; |
| 54 | + } |
| 55 | +} |
0 commit comments