Skip to content
Open
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
10 changes: 10 additions & 0 deletions lib/Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ library Impl {
result = IFHEVMCoprocessor(fhevmCoprocessorAdd).fheDiv(lhs, rhs, scalarByte);
}

function req(uint256 lhs, bool scalar) internal pure {
bytes1 scalarByte;
if (scalar) {
scalarByte = 0x01;
} else {
scalarByte = 0x00;
}
result = IFHEVMCoprocessor(fhevmCoprocessorAdd).fheReq(lhs, scalarByte);
}

function rem(uint256 lhs, uint256 rhs) internal returns (uint256 result) {
bytes1 scalarByte = 0x01;
result = IFHEVMCoprocessor(fhevmCoprocessorAdd).fheRem(lhs, rhs, scalarByte);
Expand Down
7 changes: 7 additions & 0 deletions lib/TFHE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,13 @@ library TFHE {
return euint4.wrap(Impl.div(euint4.unwrap(a), uint256(b), true));
}

function req(ebool a) internal returns (euint4) {
if (!isInitialized(a)) {
a = asEbool(0);
}
return ebool.wrap(Impl.req(ebool.unwrap(a), false));
}

// Evaluate rem(a, b) and return the result.
function rem(euint4 a, uint8 b) internal returns (euint4) {
if (!isInitialized(a)) {
Expand Down
9 changes: 9 additions & 0 deletions lib/TFHEExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ contract TFHEExecutor {
result = FhevmLib(address(EXT_TFHE_LIBRARY)).fheShr(lhs, rhs, scalarByte);
acl.allowTransient(result, msg.sender);
}
function fheReq(uint256 lhs, bytes1 scalarByte) pure {
require(acl.isAllowed(lhs, msg.sender));

if (scalarByte == 0x00) {
require(acl.isAllowed(rhs, msg.sender));
}

result = FhevmLib(address(EXT_TFHE_LIBRARY)).fheReq(lhs, scalarByte);
}
function fheRotl(uint256 lhs, uint256 rhs, bytes1 scalarByte) external returns (uint256 result) {
require(acl.isAllowed(lhs, msg.sender));

Expand Down