Code generation API¶
Warning
In this version of Oraqle, the API is still prone to changes. Paths and names can change between any version.
The easiest way is using:
arithmetic_circuit.generate_code()
Arithmetic instructions¶
If you want to extend the oraqle compiler, or implement your own code generation, you can use the following instructions to do so.
Abstract instruction
ArithmeticInstruction
¶
Bases: ABC
An abstract arithmetic instruction that computes an operation in an arithmetic circuit using a stack.
__init__(stack_index)
¶
Initialize an instruction that writes it output to the stack at stack_index
.
evaluate(stack, inputs)
abstractmethod
¶
Executes the instruction on plaintext inputs without using encryption, keeping track of the plaintext values in the stack.
generate_code(stack_initialized, decrypt_outputs)
abstractmethod
¶
Generates code for this instruction, keeping track of which places of the stack are already initialized.
InputInstruction
InputInstruction
¶
Bases: ArithmeticInstruction
Writes an input to the stack.
AdditionInstruction
AdditionInstruction
¶
Bases: ArithmeticInstruction
Reads two elements from the stack, adds them, and writes the result to the stack.
MultiplicationInstruction
MultiplicationInstruction
¶
Bases: ArithmeticInstruction
Reads two elements from the stack, multiplies them, and writes the result to the stack.
ConstantAdditionInstruction
ConstantAdditionInstruction
¶
Bases: ArithmeticInstruction
Reads an element from the stack, adds a constant to it it, and writes the result to the stack.
ConstantMultiplicationInstruction
ConstantMultiplicationInstruction
¶
Bases: ArithmeticInstruction
Reads an element from the stack, multiplies it with a constant, and writes the result to the stack.
OutputInstruction
OutputInstruction
¶
Bases: ArithmeticInstruction
Outputs an element from the stack.
Generating arithmetic programs¶
ArithmeticProgram
¶
An ArithmeticProgram represents an ordered set of arithmetic operations that compute an arithmetic circuit.
The easiest way to obtain an ArithmeticProgram
of an ArithmeticCircuit
is to call ArithmeticCircuit.generate_program()
.
__init__(instructions, stack_size, gf)
¶
Initialize an ArithmeticProgram
from a list of instructions
.
The user must specify an upper bound on the stack_size
required.
execute(inputs)
¶
Executes the arithmetic program on plaintext inputs without using encryption.
Raises:
-
Exception
–If there were no outputs in this program.
Returns: The first output in this program.
generate_code(decrypt_outputs)
¶
Generates HElib code for this program.
If decrypt_outputs
is true, then the generated code will decrypt the outputs at the end of the circuit.
Returns:
-
str
–The generated code as a string.
Generating code for HElib¶
...