Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 5d21648

Browse files
committed
chore: add bitwise for euint256 in TFHEExecutor
1 parent 4b102f9 commit 5d21648

18 files changed

+10057
-9736
lines changed

contracts/codegen/overloads.json

Lines changed: 2338 additions & 2299 deletions
Large diffs are not rendered by default.

contracts/codegen/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export const ALL_FHE_TYPES: FheType[] = [
213213
{
214214
type: 'Euint256',
215215
value: 8,
216-
supportedOperators: ['eq', 'ne', 'rotr', 'rotr', 'select', 'rand', 'randBounded'],
216+
supportedOperators: ['eq', 'ne', 'rotr', 'rotr', 'shr', 'shl', 'select', 'rand', 'randBounded'],
217217
bitLength: 256,
218218
clearMatchingType: 'uint256',
219219
},

contracts/contracts/TFHEExecutorNoEvents.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ contract TFHEExecutorNoEvents is UUPSUpgradeable, Ownable2StepUpgradeable {
282282
* @return result Result.
283283
*/
284284
function fheShl(bytes32 lhs, bytes32 rhs, bytes1 scalarByte) public virtual returns (bytes32 result) {
285-
uint256 supportedTypes = (1 << 2) + (1 << 3) + (1 << 4) + (1 << 5) + (1 << 6);
285+
uint256 supportedTypes = (1 << 2) + (1 << 3) + (1 << 4) + (1 << 5) + (1 << 6) + (1 << 8);
286286
_requireType(lhs, supportedTypes);
287287
uint8 lhsType = _typeOf(lhs);
288288
bytes1 scalar = scalarByte & 0x01;
@@ -298,7 +298,7 @@ contract TFHEExecutorNoEvents is UUPSUpgradeable, Ownable2StepUpgradeable {
298298
* @return result Result.
299299
*/
300300
function fheShr(bytes32 lhs, bytes32 rhs, bytes1 scalarByte) public virtual returns (bytes32 result) {
301-
uint256 supportedTypes = (1 << 2) + (1 << 3) + (1 << 4) + (1 << 5) + (1 << 6);
301+
uint256 supportedTypes = (1 << 2) + (1 << 3) + (1 << 4) + (1 << 5) + (1 << 6) + (1 << 8);
302302
_requireType(lhs, supportedTypes);
303303
uint8 lhsType = _typeOf(lhs);
304304
bytes1 scalar = scalarByte & 0x01;

contracts/examples/tests/TFHETestSuite7.sol

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,34 @@ contract TFHETestSuite7 {
202202
TFHE.allowThis(result);
203203
resEuint128 = result;
204204
}
205+
function shl_euint256_euint8(einput a, einput b, bytes calldata inputProof) public {
206+
euint256 aProc = TFHE.asEuint256(a, inputProof);
207+
euint8 bProc = TFHE.asEuint8(b, inputProof);
208+
euint256 result = TFHE.shl(aProc, bProc);
209+
TFHE.allowThis(result);
210+
resEuint256 = result;
211+
}
212+
function shl_euint256_uint8(einput a, uint8 b, bytes calldata inputProof) public {
213+
euint256 aProc = TFHE.asEuint256(a, inputProof);
214+
uint8 bProc = b;
215+
euint256 result = TFHE.shl(aProc, bProc);
216+
TFHE.allowThis(result);
217+
resEuint256 = result;
218+
}
219+
function shr_euint256_euint8(einput a, einput b, bytes calldata inputProof) public {
220+
euint256 aProc = TFHE.asEuint256(a, inputProof);
221+
euint8 bProc = TFHE.asEuint8(b, inputProof);
222+
euint256 result = TFHE.shr(aProc, bProc);
223+
TFHE.allowThis(result);
224+
resEuint256 = result;
225+
}
226+
function shr_euint256_uint8(einput a, uint8 b, bytes calldata inputProof) public {
227+
euint256 aProc = TFHE.asEuint256(a, inputProof);
228+
uint8 bProc = b;
229+
euint256 result = TFHE.shr(aProc, bProc);
230+
TFHE.allowThis(result);
231+
resEuint256 = result;
232+
}
205233
function rotr_euint256_euint8(einput a, einput b, bytes calldata inputProof) public {
206234
euint256 aProc = TFHE.asEuint256(a, inputProof);
207235
euint8 bProc = TFHE.asEuint8(b, inputProof);

contracts/lib/TFHE.sol

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7481,6 +7481,52 @@ library TFHE {
74817481
return euint128.wrap(Impl.rotr(euint128.unwrap(a), bytes32(uint256(b)), true));
74827482
}
74837483

7484+
/**
7485+
* @dev Evaluates shl(euint256 a, euint8 b) and returns the result.
7486+
*/
7487+
function shl(euint256 a, euint8 b) internal returns (euint256) {
7488+
if (!isInitialized(a)) {
7489+
a = asEuint256(0);
7490+
}
7491+
if (!isInitialized(b)) {
7492+
b = asEuint8(0);
7493+
}
7494+
return euint256.wrap(Impl.shl(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false));
7495+
}
7496+
7497+
/**
7498+
* @dev Evaluates shl(euint256 a, uint8) and returns the result.
7499+
*/
7500+
function shl(euint256 a, uint8 b) internal returns (euint256) {
7501+
if (!isInitialized(a)) {
7502+
a = asEuint256(0);
7503+
}
7504+
return euint256.wrap(Impl.shl(euint256.unwrap(a), bytes32(uint256(b)), true));
7505+
}
7506+
7507+
/**
7508+
* @dev Evaluates shr(euint256 a, euint8 b) and returns the result.
7509+
*/
7510+
function shr(euint256 a, euint8 b) internal returns (euint256) {
7511+
if (!isInitialized(a)) {
7512+
a = asEuint256(0);
7513+
}
7514+
if (!isInitialized(b)) {
7515+
b = asEuint8(0);
7516+
}
7517+
return euint256.wrap(Impl.shr(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false));
7518+
}
7519+
7520+
/**
7521+
* @dev Evaluates shr(euint256 a, uint8) and returns the result.
7522+
*/
7523+
function shr(euint256 a, uint8 b) internal returns (euint256) {
7524+
if (!isInitialized(a)) {
7525+
a = asEuint256(0);
7526+
}
7527+
return euint256.wrap(Impl.shr(euint256.unwrap(a), bytes32(uint256(b)), true));
7528+
}
7529+
74847530
/**
74857531
* @dev Evaluates rotr(euint256 a, euint8 b) and returns the result.
74867532
*/

0 commit comments

Comments
 (0)