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

Commit b009215

Browse files
committed
fix: randBounded euint8
1 parent 47f8a3c commit b009215

17 files changed

+10879
-10876
lines changed

contracts/codegen/overloads.json

Lines changed: 2609 additions & 2615 deletions
Large diffs are not rendered by default.

contracts/codegen/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const ALL_FHE_TYPES: FheType[] = [
6767
'not',
6868
'select',
6969
'rand',
70+
'randBounded',
7071
],
7172
bitLength: 8,
7273
clearMatchingType: 'uint8',

contracts/examples/TracingSubCalls.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ contract TracingSubCalls {
3030
contract SubContractCreate {
3131
/// @dev Constructor that encrypts the input
3232
/// @param input The value to be encrypted
33-
constructor(uint256 input) {
33+
constructor(uint64 input) {
3434
TFHE.asEuint64(input);
3535
}
3636
}
@@ -39,7 +39,7 @@ contract SubContractCreate {
3939
contract SubContractCreateFail {
4040
/// @dev Constructor that encrypts the input and then fails
4141
/// @param input The value to be encrypted before failing
42-
constructor(uint256 input) {
42+
constructor(uint64 input) {
4343
TFHE.asEuint64(input);
4444
require(false, "This constructor always fails");
4545
}
@@ -63,7 +63,7 @@ contract SubContract {
6363
/// @notice Internal function that fails with a custom input
6464
/// @dev Encrypts the input before failing
6565
/// @param input The value to be encrypted before failing
66-
function fail2(uint input) external {
66+
function fail2(uint64 input) external {
6767
TFHE.asEuint64(input);
6868
require(false, "This function always fails with custom input");
6969
}

contracts/lib/TFHE.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8690,6 +8690,14 @@ library TFHE {
86908690
return euint8.wrap(Impl.rand(uint8(FheType.Euint8)));
86918691
}
86928692

8693+
/**
8694+
* @dev Generates a random encrypted 8-bit unsigned integer in the [0, upperBound) range.
8695+
* The upperBound must be a power of 2.
8696+
*/
8697+
function randEuint8(uint8 upperBound) internal returns (euint8) {
8698+
return euint8.wrap(Impl.randBounded(upperBound, uint8(FheType.Euint8)));
8699+
}
8700+
86938701
/**
86948702
* @dev Generates a random encrypted value.
86958703
*/

0 commit comments

Comments
 (0)