Skip to content

Commit 7ac3d75

Browse files
authored
chore(common): remove ebytesxxx (#1344)
* chore(common): remove ebytesxxx * chore(common): remove ebytesxxx in fhevmjsTest.ts
1 parent e708032 commit 7ac3d75

11 files changed

Lines changed: 53 additions & 606 deletions

File tree

host-contracts/test/coprocessorUtils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ const NumBits = {
7171
6: 128n, //euint128
7272
7: 160n, //eaddress
7373
8: 256n, //euint256
74-
9: 512n, //ebytes64
75-
10: 1024n, //ebytes128
76-
11: 2048n, //ebytes256
7774
};
7875

7976
export function numberToEvenHexString(num: number) {

host-contracts/test/fhevmOperations/manual.ts

Lines changed: 0 additions & 372 deletions
Large diffs are not rendered by default.

host-contracts/test/fhevmjsMocked.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ enum Types {
4545
euint128 = 6,
4646
eaddress = 7,
4747
euint256 = 8,
48-
ebytes64 = 9,
49-
ebytes128 = 10,
50-
ebytes256 = 11,
5148
}
5249

5350
const sum = (arr: number[]) => arr.reduce((acc, val) => acc + val, 0);
@@ -106,18 +103,6 @@ function createUintToUint8ArrayFunction(numBits: number) {
106103
byteBuffer = Buffer.from([Types.euint256]);
107104
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
108105
break;
109-
case 512:
110-
byteBuffer = Buffer.from([Types.ebytes64]);
111-
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
112-
break;
113-
case 1024:
114-
byteBuffer = Buffer.from([Types.ebytes128]);
115-
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
116-
break;
117-
case 2048:
118-
byteBuffer = Buffer.from([Types.ebytes256]);
119-
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
120-
break;
121106
default:
122107
throw Error('Non-supported numBits');
123108
}
@@ -303,36 +288,6 @@ export const createEncryptedInputMocked = (contractAddress: string, userAddress:
303288
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
304289
return this;
305290
},
306-
addBytes64(value: Uint8Array) {
307-
if (value.length !== 64) throw Error('Uncorrect length of input Uint8Array, should be 64 for an ebytes64');
308-
const bigIntValue = bytesToBigInt(value);
309-
checkEncryptedValue(bigIntValue, 512);
310-
values.push(bigIntValue);
311-
bits.push(512);
312-
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
313-
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
314-
return this;
315-
},
316-
addBytes128(value: Uint8Array) {
317-
if (value.length !== 128) throw Error('Uncorrect length of input Uint8Array, should be 128 for an ebytes128');
318-
const bigIntValue = bytesToBigInt(value);
319-
checkEncryptedValue(bigIntValue, 1024);
320-
values.push(bigIntValue);
321-
bits.push(1024);
322-
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
323-
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
324-
return this;
325-
},
326-
addBytes256(value: Uint8Array) {
327-
if (value.length !== 256) throw Error('Uncorrect length of input Uint8Array, should be 256 for an ebytes256');
328-
const bigIntValue = bytesToBigInt(value);
329-
checkEncryptedValue(bigIntValue, 2048);
330-
values.push(bigIntValue);
331-
bits.push(2048);
332-
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
333-
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
334-
return this;
335-
},
336291
getValues() {
337292
return values;
338293
},

host-contracts/test/fhevmjsTest/fhevmjsTest.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ describe('Testing fhevmjs/fhevmjsMocked', function () {
4646
expect(() => input.add64(1n)).to.throw('Packing more than 2048 bits in a single input ciphertext is unsupported');
4747
});
4848

49-
it('should be able to pack up to 2 euint128s', async function () {
49+
it('should be able to pack up to 8 euint256s', async function () {
5050
const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
51-
for (let i = 0; i < 2; i++) {
52-
input.addBytes128(bigIntToBytes128(797979n));
51+
for (let i = 0; i < 8; i++) {
52+
input.add256(797979n);
5353
}
5454
await input.encrypt();
5555
});
5656

57-
it('should be unable to pack more than 2 euint128s', async function () {
57+
it('should not be able to pack more than 8 euint256s', async function () {
5858
const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
59-
for (let i = 0; i < 2; i++) {
60-
input.addBytes128(bigIntToBytes128(797979n));
59+
for (let i = 0; i < 8; i++) {
60+
input.add256(797979n);
6161
}
6262
expect(() => input.addBool(false)).to.throw(
6363
'Packing more than 2048 bits in a single input ciphertext is unsupported',
@@ -66,12 +66,22 @@ describe('Testing fhevmjs/fhevmjsMocked', function () {
6666

6767
it('should be able to pack up to 2048 bits but not more', async function () {
6868
const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
69-
input.addBytes128(bigIntToBytes128(797979n));
70-
input.addBytes64(bigIntToBytes64(797979n));
69+
input.add256(797979n);
70+
input.add256(797978n);
71+
input.add256(797977n);
72+
input.add256(797976n);
73+
input.add256(797975n);
74+
input.add256(797974n);
7175
input.add256(6887n);
7276
input.add128(6887n);
7377
input.add64(6887n);
7478
input.add64(6887n);
79+
let bits = input.getBits();
80+
let total = 0;
81+
for (let i = 0; i < bits.length; ++i) {
82+
total += bits[i];
83+
}
84+
expect(total).to.eq(2048);
7585
expect(() => input.addBool(false)).to.throw(
7686
'Packing more than 2048 bits in a single input ciphertext is unsupported',
7787
);

host-contracts/test/instance.ts

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const getDecryptor = () => {
110110
* This function is intended for debugging purposes only.
111111
* It cannot be used in production code, since it requires the FHE private key for decryption.
112112
*
113-
* @param {bigint} a handle to decrypt
113+
* @param {bigint} handle handle to decrypt
114114
* @returns {bool}
115115
*/
116116
export const decryptBool = async (handle: string): Promise<boolean> => {
@@ -127,7 +127,7 @@ export const decryptBool = async (handle: string): Promise<boolean> => {
127127
* This function is intended for debugging purposes only.
128128
* It cannot be used in production code, since it requires the FHE private key for decryption.
129129
*
130-
* @param {bigint} a handle to decrypt
130+
* @param {bigint} handle handle to decrypt
131131
* @returns {bigint}
132132
*/
133133
export const decrypt8 = async (handle: string): Promise<bigint> => {
@@ -144,7 +144,7 @@ export const decrypt8 = async (handle: string): Promise<bigint> => {
144144
* This function is intended for debugging purposes only.
145145
* It cannot be used in production code, since it requires the FHE private key for decryption.
146146
*
147-
* @param {bigint} a handle to decrypt
147+
* @param {bigint} handle handle to decrypt
148148
* @returns {bigint}
149149
*/
150150
export const decrypt16 = async (handle: string): Promise<bigint> => {
@@ -161,7 +161,7 @@ export const decrypt16 = async (handle: string): Promise<bigint> => {
161161
* This function is intended for debugging purposes only.
162162
* It cannot be used in production code, since it requires the FHE private key for decryption.
163163
*
164-
* @param {bigint} a handle to decrypt
164+
* @param {bigint} handle handle to decrypt
165165
* @returns {bigint}
166166
*/
167167
export const decrypt32 = async (handle: string): Promise<bigint> => {
@@ -178,7 +178,7 @@ export const decrypt32 = async (handle: string): Promise<bigint> => {
178178
* This function is intended for debugging purposes only.
179179
* It cannot be used in production code, since it requires the FHE private key for decryption.
180180
*
181-
* @param {bigint} a handle to decrypt
181+
* @param {bigint} handle handle to decrypt
182182
* @returns {bigint}
183183
*/
184184
export const decrypt64 = async (handle: string): Promise<bigint> => {
@@ -195,7 +195,7 @@ export const decrypt64 = async (handle: string): Promise<bigint> => {
195195
* This function is intended for debugging purposes only.
196196
* It cannot be used in production code, since it requires the FHE private key for decryption.
197197
*
198-
* @param {bigint} a handle to decrypt
198+
* @param {bigint} handle handle to decrypt
199199
* @returns {bigint}
200200
*/
201201
export const decrypt128 = async (handle: string): Promise<bigint> => {
@@ -212,7 +212,7 @@ export const decrypt128 = async (handle: string): Promise<bigint> => {
212212
* This function is intended for debugging purposes only.
213213
* It cannot be used in production code, since it requires the FHE private key for decryption.
214214
*
215-
* @param {bigint} a handle to decrypt
215+
* @param {bigint} handle handle to decrypt
216216
* @returns {bigint}
217217
*/
218218
export const decrypt256 = async (handle: string): Promise<bigint> => {
@@ -229,7 +229,7 @@ export const decrypt256 = async (handle: string): Promise<bigint> => {
229229
* This function is intended for debugging purposes only.
230230
* It cannot be used in production code, since it requires the FHE private key for decryption.
231231
*
232-
* @param {bigint} a handle to decrypt
232+
* @param {bigint} handle handle to decrypt
233233
* @returns {string}
234234
*/
235235
export const decryptAddress = async (handle: string): Promise<string> => {
@@ -242,54 +242,3 @@ export const decryptAddress = async (handle: string): Promise<string> => {
242242
return getDecryptor().decryptAddress(await getCiphertext(handle, ethers));
243243
}
244244
};
245-
246-
/**
247-
* @debug
248-
* This function is intended for debugging purposes only.
249-
* It cannot be used in production code, since it requires the FHE private key for decryption.
250-
*
251-
* @param {bigint} a handle to decrypt
252-
* @returns {bigint}
253-
*/
254-
export const decryptEbytes64 = async (handle: string): Promise<bigint> => {
255-
if (network.name === 'hardhat') {
256-
await awaitCoprocessor();
257-
return BigInt(await getClearText(handle));
258-
} else {
259-
return getDecryptor().decryptEbytes64(await getCiphertext(handle, ethers));
260-
}
261-
};
262-
263-
/**
264-
* @debug
265-
* This function is intended for debugging purposes only.
266-
* It cannot be used in production code, since it requires the FHE private key for decryption.
267-
*
268-
* @param {bigint} a handle to decrypt
269-
* @returns {bigint}
270-
*/
271-
export const decryptEbytes128 = async (handle: string): Promise<bigint> => {
272-
if (network.name === 'hardhat') {
273-
await awaitCoprocessor();
274-
return BigInt(await getClearText(handle));
275-
} else {
276-
return getDecryptor().decryptEbytes128(await getCiphertext(handle, ethers));
277-
}
278-
};
279-
280-
/**
281-
* @debug
282-
* This function is intended for debugging purposes only.
283-
* It cannot be used in production code, since it requires the FHE private key for decryption.
284-
*
285-
* @param {bigint} a handle to decrypt
286-
* @returns {bigint}
287-
*/
288-
export const decryptEbytes256 = async (handle: string): Promise<bigint> => {
289-
if (network.name === 'hardhat') {
290-
await awaitCoprocessor();
291-
return BigInt(await getClearText(handle));
292-
} else {
293-
return getDecryptor().decryptEbytes256(await getCiphertext(handle, ethers));
294-
}
295-
};

host-contracts/test/rand/Rand.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import {
1010
decrypt128,
1111
decrypt256,
1212
decryptBool,
13-
decryptEbytes64,
14-
decryptEbytes128,
15-
decryptEbytes256,
1613
} from '../instance';
1714
import { getSigners, initSigners } from '../signers';
1815
import { deployRandFixture } from './Rand.fixture';

library-solidity/codegen/src/testgen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function generateSolidityOverloadTestFiles(operators: Operator[], fheType
4040
generateOverloadsForTFHEUnaryOperators(fheType, operators, signatures),
4141
);
4242

43-
// TODO Add tests for conversion from plaintext and externalEXXX to all supported types (e.g., externalEXXX --> ebool, bytes memory --> ebytes64, uint32 --> euint32)
43+
// TODO Add tests for conversion from plaintext and externalEXXX to all supported types (e.g., externalEXXX --> ebool, uint32 --> euint32)
4444
return signatures;
4545
}
4646

library-solidity/test/coprocessorUtils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ const NumBits = {
7272
6: 128n, //euint128
7373
7: 160n, //eaddress
7474
8: 256n, //euint256
75-
9: 512n, //ebytes64
76-
10: 1024n, //ebytes128
77-
11: 2048n, //ebytes256
7875
};
7976

8077
export function numberToEvenHexString(num: number) {

library-solidity/test/fhevmjsMocked.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ enum Types {
4444
euint128 = 6,
4545
eaddress = 7,
4646
euint256 = 8,
47-
ebytes64 = 9,
48-
ebytes128 = 10,
49-
ebytes256 = 11,
5047
}
5148

5249
const sum = (arr: number[]) => arr.reduce((acc, val) => acc + val, 0);
@@ -105,18 +102,6 @@ function createUintToUint8ArrayFunction(numBits: number) {
105102
byteBuffer = Buffer.from([Types.euint256]);
106103
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
107104
break;
108-
case 512:
109-
byteBuffer = Buffer.from([Types.ebytes64]);
110-
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
111-
break;
112-
case 1024:
113-
byteBuffer = Buffer.from([Types.ebytes128]);
114-
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
115-
break;
116-
case 2048:
117-
byteBuffer = Buffer.from([Types.ebytes256]);
118-
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
119-
break;
120105
default:
121106
throw Error('Non-supported numBits');
122107
}
@@ -302,36 +287,6 @@ export const createEncryptedInputMocked = (contractAddress: string, userAddress:
302287
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
303288
return this;
304289
},
305-
addBytes64(value: Uint8Array) {
306-
if (value.length !== 64) throw Error('Uncorrect length of input Uint8Array, should be 64 for an ebytes64');
307-
const bigIntValue = bytesToBigInt(value);
308-
checkEncryptedValue(bigIntValue, 512);
309-
values.push(bigIntValue);
310-
bits.push(512);
311-
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
312-
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
313-
return this;
314-
},
315-
addBytes128(value: Uint8Array) {
316-
if (value.length !== 128) throw Error('Uncorrect length of input Uint8Array, should be 128 for an ebytes128');
317-
const bigIntValue = bytesToBigInt(value);
318-
checkEncryptedValue(bigIntValue, 1024);
319-
values.push(bigIntValue);
320-
bits.push(1024);
321-
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
322-
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
323-
return this;
324-
},
325-
addBytes256(value: Uint8Array) {
326-
if (value.length !== 256) throw Error('Uncorrect length of input Uint8Array, should be 256 for an ebytes256');
327-
const bigIntValue = bytesToBigInt(value);
328-
checkEncryptedValue(bigIntValue, 2048);
329-
values.push(bigIntValue);
330-
bits.push(2048);
331-
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
332-
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
333-
return this;
334-
},
335290
getValues() {
336291
return values;
337292
},

0 commit comments

Comments
 (0)