generated from PaulRBerg/foundry-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFheHelper.sol
79 lines (61 loc) · 2.19 KB
/
FheHelper.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {
inEuint8,
inEuint16,
inEuint32,
inEuint64,
inEuint128,
inEuint256,
inEaddress,
inEbool
} from '@fhenixprotocol/contracts/FHE.sol';
import { Test } from "forge-std/src/Test.sol";
import { MockFheOps } from "@fhenixprotocol/contracts/utils/debug/MockFheOps.sol";
contract FheEnabled is Test {
function initializeFhe() public {
MockFheOps fheos = new MockFheOps();
bytes memory code = address(fheos).code;
vm.etch(address(128), code);
}
function unseal(address, string memory value) public pure returns (uint256) {
bytes memory bytesValue = bytes(value);
require(bytesValue.length == 32, "Invalid input length");
uint256 result;
assembly {
result := mload(add(bytesValue, 32))
}
return result;
}
function encrypt8(uint256 value) public pure returns (inEuint8 memory) {
return inEuint8(uint256ToBytes(value), 0);
}
function encrypt16(uint256 value) public pure returns (inEuint16 memory) {
return inEuint16(uint256ToBytes(value), 0);
}
function encrypt32(uint256 value) public pure returns (inEuint32 memory) {
return inEuint32(uint256ToBytes(value), 0);
}
function encrypt64(uint256 value) public pure returns (inEuint64 memory) {
return inEuint64(uint256ToBytes(value), 0);
}
function encrypt128(uint256 value) public pure returns (inEuint128 memory) {
return inEuint128(uint256ToBytes(value), 0);
}
function encrypt256(uint256 value) public pure returns (inEuint256 memory) {
return inEuint256(uint256ToBytes(value), 0);
}
function encryptAddress(uint256 value) public pure returns (inEaddress memory) {
return inEaddress(uint256ToBytes(value), 0);
}
function encryptBool(uint256 value) public pure returns (inEbool memory) {
return inEbool(uint256ToBytes(value), 0);
}
function uint256ToBytes(uint256 value) private pure returns (bytes memory) {
bytes memory result = new bytes(32);
assembly {
mstore(add(result, 32), value)
}
return result;
}
}