Skip to content

Commit

Permalink
Merge pull request #144 from zama-ai/use-fhe-lib
Browse files Browse the repository at this point in the history
Use fheLib precompile for all internal functions
  • Loading branch information
david-zk authored Sep 21, 2023
2 parents 5f36be8 + 227b541 commit 71c5a9f
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 716 deletions.
4 changes: 4 additions & 0 deletions codegen/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Operator = {
leftScalarEncrypt?: boolean;
// disable left scalar operator
leftScalarDisable?: boolean;
fheLibName?: string;
};

export type Precompile = {
Expand Down Expand Up @@ -104,6 +105,7 @@ export const ALL_OPERATORS: Operator[] = [
hasEncrypted: true,
arguments: OperatorArguments.Binary,
returnType: ReturnType.Uint,
fheLibName: 'fheBitAnd',
},
{
name: 'or',
Expand All @@ -112,6 +114,7 @@ export const ALL_OPERATORS: Operator[] = [
hasEncrypted: true,
arguments: OperatorArguments.Binary,
returnType: ReturnType.Uint,
fheLibName: 'fheBitOr',
},
{
name: 'xor',
Expand All @@ -120,6 +123,7 @@ export const ALL_OPERATORS: Operator[] = [
hasEncrypted: true,
arguments: OperatorArguments.Binary,
returnType: ReturnType.Uint,
fheLibName: 'fheBitXor',
},
{
name: 'shl',
Expand Down
15 changes: 15 additions & 0 deletions codegen/overloadTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ type OverloadTest = {
};

export const overloadTests: { [methodName: string]: OverloadTest[] } = {
neg_euint8: [
{ inputs: [0x01], output: 0xff },
{ inputs: [0x02], output: 0xfe },
],
not_euint8: [{ inputs: [0x03], output: 0xfc }],
neg_euint16: [
{ inputs: [0x0001], output: 0xffff },
{ inputs: [0x0002], output: 0xfffe },
],
not_euint16: [{ inputs: [0x00f1], output: 0xff0e }],
neg_euint32: [
{ inputs: [0x00000001], output: 0xffffffff },
{ inputs: [0x00000002], output: 0xfffffffe },
],
not_euint32: [{ inputs: [0x0000fffe], output: 0xffff0001 }],
add_euint8_euint8: [{ inputs: [3, 4], output: 7 }],
sub_euint8_euint8: [{ inputs: [4, 3], output: 1 }],
mul_euint8_euint8: [{ inputs: [3, 4], output: 12 }],
Expand Down
Loading

0 comments on commit 71c5a9f

Please sign in to comment.