Skip to content
Merged
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
3 changes: 0 additions & 3 deletions host-contracts/test/coprocessorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ const NumBits = {
6: 128n, //euint128
7: 160n, //eaddress
8: 256n, //euint256
9: 512n, //ebytes64
10: 1024n, //ebytes128
11: 2048n, //ebytes256
};

export function numberToEvenHexString(num: number) {
Expand Down
372 changes: 0 additions & 372 deletions host-contracts/test/fhevmOperations/manual.ts

Large diffs are not rendered by default.

45 changes: 0 additions & 45 deletions host-contracts/test/fhevmjsMocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ enum Types {
euint128 = 6,
eaddress = 7,
euint256 = 8,
ebytes64 = 9,
ebytes128 = 10,
ebytes256 = 11,
}

const sum = (arr: number[]) => arr.reduce((acc, val) => acc + val, 0);
Expand Down Expand Up @@ -106,18 +103,6 @@ function createUintToUint8ArrayFunction(numBits: number) {
byteBuffer = Buffer.from([Types.euint256]);
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
break;
case 512:
byteBuffer = Buffer.from([Types.ebytes64]);
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
break;
case 1024:
byteBuffer = Buffer.from([Types.ebytes128]);
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
break;
case 2048:
byteBuffer = Buffer.from([Types.ebytes256]);
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
break;
default:
throw Error('Non-supported numBits');
}
Expand Down Expand Up @@ -303,36 +288,6 @@ export const createEncryptedInputMocked = (contractAddress: string, userAddress:
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
return this;
},
addBytes64(value: Uint8Array) {
if (value.length !== 64) throw Error('Uncorrect length of input Uint8Array, should be 64 for an ebytes64');
const bigIntValue = bytesToBigInt(value);
checkEncryptedValue(bigIntValue, 512);
values.push(bigIntValue);
bits.push(512);
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
return this;
},
addBytes128(value: Uint8Array) {
if (value.length !== 128) throw Error('Uncorrect length of input Uint8Array, should be 128 for an ebytes128');
const bigIntValue = bytesToBigInt(value);
checkEncryptedValue(bigIntValue, 1024);
values.push(bigIntValue);
bits.push(1024);
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
return this;
},
addBytes256(value: Uint8Array) {
if (value.length !== 256) throw Error('Uncorrect length of input Uint8Array, should be 256 for an ebytes256');
const bigIntValue = bytesToBigInt(value);
checkEncryptedValue(bigIntValue, 2048);
values.push(bigIntValue);
bits.push(2048);
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
return this;
},
getValues() {
return values;
},
Expand Down
26 changes: 18 additions & 8 deletions host-contracts/test/fhevmjsTest/fhevmjsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ describe('Testing fhevmjs/fhevmjsMocked', function () {
expect(() => input.add64(1n)).to.throw('Packing more than 2048 bits in a single input ciphertext is unsupported');
});

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

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

it('should be able to pack up to 2048 bits but not more', async function () {
const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
input.addBytes128(bigIntToBytes128(797979n));
input.addBytes64(bigIntToBytes64(797979n));
input.add256(797979n);
input.add256(797978n);
input.add256(797977n);
input.add256(797976n);
input.add256(797975n);
input.add256(797974n);
input.add256(6887n);
input.add128(6887n);
input.add64(6887n);
input.add64(6887n);
let bits = input.getBits();
let total = 0;
for (let i = 0; i < bits.length; ++i) {
total += bits[i];
}
expect(total).to.eq(2048);
expect(() => input.addBool(false)).to.throw(
'Packing more than 2048 bits in a single input ciphertext is unsupported',
);
Expand Down
67 changes: 8 additions & 59 deletions host-contracts/test/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const getDecryptor = () => {
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @param {bigint} handle handle to decrypt
* @returns {bool}
*/
export const decryptBool = async (handle: string): Promise<boolean> => {
Expand All @@ -127,7 +127,7 @@ export const decryptBool = async (handle: string): Promise<boolean> => {
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @param {bigint} handle handle to decrypt
* @returns {bigint}
*/
export const decrypt8 = async (handle: string): Promise<bigint> => {
Expand All @@ -144,7 +144,7 @@ export const decrypt8 = async (handle: string): Promise<bigint> => {
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @param {bigint} handle handle to decrypt
* @returns {bigint}
*/
export const decrypt16 = async (handle: string): Promise<bigint> => {
Expand All @@ -161,7 +161,7 @@ export const decrypt16 = async (handle: string): Promise<bigint> => {
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @param {bigint} handle handle to decrypt
* @returns {bigint}
*/
export const decrypt32 = async (handle: string): Promise<bigint> => {
Expand All @@ -178,7 +178,7 @@ export const decrypt32 = async (handle: string): Promise<bigint> => {
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @param {bigint} handle handle to decrypt
* @returns {bigint}
*/
export const decrypt64 = async (handle: string): Promise<bigint> => {
Expand All @@ -195,7 +195,7 @@ export const decrypt64 = async (handle: string): Promise<bigint> => {
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @param {bigint} handle handle to decrypt
* @returns {bigint}
*/
export const decrypt128 = async (handle: string): Promise<bigint> => {
Expand All @@ -212,7 +212,7 @@ export const decrypt128 = async (handle: string): Promise<bigint> => {
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @param {bigint} handle handle to decrypt
* @returns {bigint}
*/
export const decrypt256 = async (handle: string): Promise<bigint> => {
Expand All @@ -229,7 +229,7 @@ export const decrypt256 = async (handle: string): Promise<bigint> => {
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @param {bigint} handle handle to decrypt
* @returns {string}
*/
export const decryptAddress = async (handle: string): Promise<string> => {
Expand All @@ -242,54 +242,3 @@ export const decryptAddress = async (handle: string): Promise<string> => {
return getDecryptor().decryptAddress(await getCiphertext(handle, ethers));
}
};

/**
* @debug
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @returns {bigint}
*/
export const decryptEbytes64 = async (handle: string): Promise<bigint> => {
if (network.name === 'hardhat') {
await awaitCoprocessor();
return BigInt(await getClearText(handle));
} else {
return getDecryptor().decryptEbytes64(await getCiphertext(handle, ethers));
}
};

/**
* @debug
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @returns {bigint}
*/
export const decryptEbytes128 = async (handle: string): Promise<bigint> => {
if (network.name === 'hardhat') {
await awaitCoprocessor();
return BigInt(await getClearText(handle));
} else {
return getDecryptor().decryptEbytes128(await getCiphertext(handle, ethers));
}
};

/**
* @debug
* This function is intended for debugging purposes only.
* It cannot be used in production code, since it requires the FHE private key for decryption.
*
* @param {bigint} a handle to decrypt
* @returns {bigint}
*/
export const decryptEbytes256 = async (handle: string): Promise<bigint> => {
if (network.name === 'hardhat') {
await awaitCoprocessor();
return BigInt(await getClearText(handle));
} else {
return getDecryptor().decryptEbytes256(await getCiphertext(handle, ethers));
}
};
3 changes: 0 additions & 3 deletions host-contracts/test/rand/Rand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import {
decrypt128,
decrypt256,
decryptBool,
decryptEbytes64,
decryptEbytes128,
decryptEbytes256,
} from '../instance';
import { getSigners, initSigners } from '../signers';
import { deployRandFixture } from './Rand.fixture';
Expand Down
2 changes: 1 addition & 1 deletion library-solidity/codegen/src/testgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function generateSolidityOverloadTestFiles(operators: Operator[], fheType
generateOverloadsForTFHEUnaryOperators(fheType, operators, signatures),
);

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

Expand Down
3 changes: 0 additions & 3 deletions library-solidity/test/coprocessorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ const NumBits = {
6: 128n, //euint128
7: 160n, //eaddress
8: 256n, //euint256
9: 512n, //ebytes64
10: 1024n, //ebytes128
11: 2048n, //ebytes256
};

export function numberToEvenHexString(num: number) {
Expand Down
45 changes: 0 additions & 45 deletions library-solidity/test/fhevmjsMocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ enum Types {
euint128 = 6,
eaddress = 7,
euint256 = 8,
ebytes64 = 9,
ebytes128 = 10,
ebytes256 = 11,
}

const sum = (arr: number[]) => arr.reduce((acc, val) => acc + val, 0);
Expand Down Expand Up @@ -105,18 +102,6 @@ function createUintToUint8ArrayFunction(numBits: number) {
byteBuffer = Buffer.from([Types.euint256]);
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
break;
case 512:
byteBuffer = Buffer.from([Types.ebytes64]);
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
break;
case 1024:
byteBuffer = Buffer.from([Types.ebytes128]);
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
break;
case 2048:
byteBuffer = Buffer.from([Types.ebytes256]);
totalBuffer = Buffer.concat([byteBuffer, combinedBuffer]);
break;
default:
throw Error('Non-supported numBits');
}
Expand Down Expand Up @@ -302,36 +287,6 @@ export const createEncryptedInputMocked = (contractAddress: string, userAddress:
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
return this;
},
addBytes64(value: Uint8Array) {
if (value.length !== 64) throw Error('Uncorrect length of input Uint8Array, should be 64 for an ebytes64');
const bigIntValue = bytesToBigInt(value);
checkEncryptedValue(bigIntValue, 512);
values.push(bigIntValue);
bits.push(512);
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
return this;
},
addBytes128(value: Uint8Array) {
if (value.length !== 128) throw Error('Uncorrect length of input Uint8Array, should be 128 for an ebytes128');
const bigIntValue = bytesToBigInt(value);
checkEncryptedValue(bigIntValue, 1024);
values.push(bigIntValue);
bits.push(1024);
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
return this;
},
addBytes256(value: Uint8Array) {
if (value.length !== 256) throw Error('Uncorrect length of input Uint8Array, should be 256 for an ebytes256');
const bigIntValue = bytesToBigInt(value);
checkEncryptedValue(bigIntValue, 2048);
values.push(bigIntValue);
bits.push(2048);
if (sum(bits) > 2048) throw Error('Packing more than 2048 bits in a single input ciphertext is unsupported');
if (bits.length > 256) throw Error('Packing more than 256 variables in a single input ciphertext is unsupported');
return this;
},
getValues() {
return values;
},
Expand Down
Loading
Loading