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

Commit b139212

Browse files
committed
fix: fix
1 parent cdd8b1c commit b139212

17 files changed

+9413
-9407
lines changed

contracts/codegen/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export function validateFHETypes(fheTypes: FheType[]): void {
194194
throw new Error(`Invalid FHE type: ${JSON.stringify(fheType)}`);
195195
}
196196

197-
// TODO: Add more validation checks
197+
// TODO Add more validation checks
198198
});
199199
}
200200

contracts/codegen/generateOverloads.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const SUPPORTED_FUNCTIONS: SupportedFunctions = {
133133
const newIndex = Number(BigInt(index) + (rhsNumber % BigInt(lhs)));
134134
return newIndex >= bits.length ? '0' : bits[newIndex];
135135
});
136-
return BigInt(`0b${r.filter((bit) => bit === '0' || bit === '1').join('')}`);
136+
return BigInt(`0b${r.join('')}`);
137137
},
138138
},
139139
shr: {
@@ -144,7 +144,7 @@ export const SUPPORTED_FUNCTIONS: SupportedFunctions = {
144144
const newIndex = Number(BigInt(index) - (rhsNumber % BigInt(lhs)));
145145
return newIndex < 0 ? '0' : bits[newIndex];
146146
});
147-
return BigInt(`0b${r.filter((bit) => bit === '0' || bit === '1').join('')}`);
147+
return BigInt(`0b${r.join('')}`);
148148
},
149149
},
150150
rotl: {
@@ -156,7 +156,7 @@ export const SUPPORTED_FUNCTIONS: SupportedFunctions = {
156156
if (newIndex >= lhs) newIndex = newIndex % lhs;
157157
return bits[newIndex];
158158
});
159-
return BigInt(`0b${r.filter((bit) => bit === '0' || bit === '1').join('')}`);
159+
return BigInt(`0b${r.join('')}`);
160160
},
161161
},
162162
rotr: {
@@ -168,7 +168,7 @@ export const SUPPORTED_FUNCTIONS: SupportedFunctions = {
168168
if (newIndex < 0) newIndex = lhs + newIndex;
169169
return bits[newIndex];
170170
});
171-
return BigInt(`0b${r.filter((bit) => bit === '0' || bit === '1').join('')}`);
171+
return BigInt(`0b${r.join('')}`);
172172
},
173173
},
174174
max: {
@@ -247,9 +247,12 @@ export const generateOverloads = (fheTypes: FheType[]) => {
247247
const bitResults = Math.min(lhsFheType.bitLength, rhsFheType.bitLength);
248248
let lhsNumber = generateRandomNumber(lhsFheType.bitLength);
249249
let rhsNumber = generateRandomNumber(rhsFheType.bitLength);
250+
250251
if (test.limit === 'bits') {
251-
rhsNumber = BigInt(1 + Math.floor(Math.random() * (rhsFheType.bitLength - 1)));
252+
// @dev We set the floor as 5 to prevent underflows since tests would use smallest - 4n.
253+
rhsNumber = BigInt(5 + Math.floor(Math.random() * (rhsFheType.bitLength - 1)));
252254
}
255+
253256
const smallest = findMinimumValueInBigIntArray(lhsNumber, rhsNumber);
254257
const only8bits = test.limit === 'bits' && rhsFheType.bitLength === 8;
255258

contracts/codegen/overloads.json

Lines changed: 2144 additions & 2138 deletions
Large diffs are not rendered by default.

contracts/codegen/testgen.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,12 @@ export function generateSolidityOverloadTestFiles(operators: Operator[], fheType
4242
});
4343
});
4444

45-
// Generate overloads for ternary operator (i.e., select) for all supported types
46-
// TODO: test select
47-
4845
// Generate overloads unary operators for all supported types.
4946
adjustedFheTypes.forEach((fheType: FheType) =>
5047
generateOverloadsForTFHEUnaryOperators(fheType, operators, signatures),
5148
);
5249

53-
// Generate overloads for conversion from plaintext and einput to all supported types (e.g., einput --> ebool, bytes memory --> ebytes64, uint32 --> euint32)
54-
// TEST casting
55-
56-
// Generate overloads for rand/randBounded for all supported types
57-
// Test randomness
58-
50+
// TODO Add tests for conversion from plaintext and einput to all supported types (e.g., einput --> ebool, bytes memory --> ebytes64, uint32 --> euint32)
5951
return signatures;
6052
}
6153

contracts/codegen/utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ export const findMaximumValueInBigIntArray = (...args: bigint[]) => {
3333
* Generates a random number within a specified bit range.
3434
*
3535
* @param bits - The number of bits to determine the range of the generated number.
36-
* @returns A random BigInt number within the range defined by the number of bits.
36+
* @param minValue - The minimum value to return.
37+
* @returns A random BigInt number within the range defined by the number of bits and at least minValue.
3738
*/
38-
export const generateRandomNumber = (bits: number) => {
39+
export const generateRandomNumber = (bits: number, minValue: bigint = 10n) => {
3940
const power = BigInt(Math.pow(2, bits) - 1);
4041
const maxRange = findMinimumValueInBigIntArray(power, BigInt(Number.MAX_SAFE_INTEGER));
41-
const subtract = findMaximumValueInBigIntArray(BigInt(Math.floor(Math.random() * Number(maxRange))), 1n);
42-
return findMaximumValueInBigIntArray(power - subtract, 1n);
42+
const subtract = findMaximumValueInBigIntArray(BigInt(Math.floor(Math.random() * Number(maxRange))), minValue);
43+
return findMaximumValueInBigIntArray(power - subtract, minValue);
4344
};

0 commit comments

Comments
 (0)