Documentation
¶
Overview ¶
Package circuits provides the types and interfaces for defining, parsing and executing circuits.
Index ¶
- Variables
- func GetProtocolSignature(t protocols.Type, in OperandLabel, params map[string]string) (pd protocols.Signature)
- type Circuit
- type Descriptor
- type Evaluator
- type Event
- type EventType
- type FutureOperand
- type Metadata
- type Name
- type Operand
- type OperandLabel
- func (opl OperandLabel) CircuitID() helium.CircuitID
- func (opl OperandLabel) ForCircuit(cid helium.CircuitID) OperandLabel
- func (opl OperandLabel) ForMapping(nodeMapping map[string]helium.NodeID) OperandLabel
- func (opl OperandLabel) HasNode(id helium.NodeID) bool
- func (opl OperandLabel) NodeID() helium.NodeID
- type Output
- type Runtime
- type Signature
Constants ¶
This section is empty.
Variables ¶
var TestCircuits map[Name]Circuit = map[Name]Circuit{ "add-2-dec": func(ec Runtime) error { in1, in2 := ec.Input("//p1/in"), ec.Input("//p2/in") opRes := ec.NewOperand("//eval/sum") opRes.Ciphertext = bgv.NewCiphertext(ec.Parameters(), 1, ec.Parameters().MaxLevel()) ec.Add(in1.Get().Ciphertext, in2.Get().Ciphertext, opRes.Ciphertext) return ec.DEC(opRes, "rec", map[string]string{ "smudging": "40.0", }) }, "mul-2-dec": func(ec Runtime) error { in1, in2 := ec.Input("//p1/in"), ec.Input("//p2/in") opRes := ec.NewOperand("//eval/mul") opRes.Ciphertext = bgv.NewCiphertext(ec.Parameters(), 1, ec.Parameters().MaxLevel()) ec.MulRelin(in1.Get().Ciphertext, in2.Get().Ciphertext, opRes.Ciphertext) return ec.DEC(opRes, "rec", map[string]string{ "smudging": "40.0", }) }, }
TestCircuits contains a set of test circuits for the helium framework.
Functions ¶
func GetProtocolSignature ¶
Types ¶
type Circuit ¶
Circuit is a type for representing circuits, which are Go functions interacting with a provided evaluation runtime.
type Descriptor ¶
type Descriptor struct {
Signature
helium.CircuitID
NodeMapping map[string]helium.NodeID
Evaluator helium.NodeID
}
Descriptor is a struct for specifying a circuit execution. It holds the identification information for the circuit, as well as a concrete mapping from the node ids in the circuit definition.
type Evaluator ¶
type Evaluator interface {
Add(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error)
Sub(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error)
Mul(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error)
MulNew(op0 *rlwe.Ciphertext, op1 interface{}) (opOut *rlwe.Ciphertext, err error)
MulRelin(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error)
MulRelinNew(op0 *rlwe.Ciphertext, op1 interface{}) (opOut *rlwe.Ciphertext, err error)
MulThenAdd(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error)
Relinearize(op0, op1 *rlwe.Ciphertext) (err error)
Rescale(op0, op1 *rlwe.Ciphertext) (err error)
InnerSum(ctIn *rlwe.Ciphertext, batchSize, n int, opOut *rlwe.Ciphertext) (err error)
AutomorphismHoisted(level int, ctIn *rlwe.Ciphertext, c1DecompQP []ringqp.Poly, galEl uint64, opOut *rlwe.Ciphertext) (err error)
DecomposeNTT(levelQ, levelP, nbPi int, c2 ring.Poly, c2IsNTT bool, decompQP []ringqp.Poly)
NewDecompQPBuffer() []ringqp.Poly
}
Evaluator is an interface that is directly supported by circuit runtimes.
type EventType ¶
type EventType int8
EventType define the type of event (see circuits.Event)
const ( // Completed corresponds to then event of a circuit being completed. // It is emitted zero (failure) or one time per circuit instance. Completed EventType = iota // Started corresponds to then event of a circuit being started. // It is emitted once per circuit instance. Started // Executing is an event type for execution-related events. // This event tpe can be emitted multiple times per circuit instance, // for example, at each protocol Event. Executing // Failed corresponds to then event of a circuit failing to execute to completion. Failed )
type FutureOperand ¶
type FutureOperand struct {
Operand
// contains filtered or unexported fields
}
FutureOperand is a type for operands for which the actual ciphertext is not known yet and will be set later. It enables waiting on operands.
func NewDummyFutureOperand ¶
func NewDummyFutureOperand(opl OperandLabel) *FutureOperand
NewDummyFutureOperand creates a new future operand with the given label, but for which the ciphertext is immediatly set to nil. It is used in the context of circuit parsing.
func NewFutureOperand ¶
func NewFutureOperand(opl OperandLabel) *FutureOperand
NewFutureOperand creates a new future operand with the given label.
func (*FutureOperand) Get ¶
func (fo *FutureOperand) Get() Operand
Get returns the actual operand, waiting for the ciphertext to be set if necessary.
func (*FutureOperand) Set ¶
func (fo *FutureOperand) Set(op Operand)
Set sets the actual ciphertext for the future operand and unlocks the routines waiting in the Get method.
type Metadata ¶
type Metadata struct {
Descriptor
InputSet, Ops, OutputSet utils.Set[OperandLabel]
InputsFor, OutputsFor map[helium.NodeID]utils.Set[OperandLabel]
KeySwitchOps map[string]protocols.Signature
NeedRlk bool
GaloisKeys utils.Set[uint64]
}
Metadata is a type for gathering information about a circuit instance. It is obtained by parsing a circuit defintion (see circuits.Parse)
func Parse ¶
func Parse(c Circuit, cd Descriptor, params bgv.Parameters) (*Metadata, error)
Parse parses a circuit and returns its metadata. The parsing is done by symbolic execution of the circuit.
type Name ¶
type Name string
Name is a type for circuit names. A circuit name is a string that uniquely identifies a circuit within the framework. Multiple instances of the same circuit can exist within the system (see circuits.ID).
type Operand ¶
type Operand struct {
OperandLabel
*rlwe.Ciphertext
}
Operand is a type for representing circuit operands. Each operand within a circuit must have a unique label.
type OperandLabel ¶
type OperandLabel string
OperandLabel is a type operand labels. Operand labels have the following format:
//<node-id>/<circuit-id>/<ciphertext-id>
where:
- node-id is the id of the node that owns the operand,
- circuit-id is the id of the circuit in which this operand is used,
- ciphertext-id is the id of the ciphertext within the circuit.
The circuit-id part is optional and can be omitted (1) in the context of a circuit definition, where it will be automatically expanded by the framework and (2) in the context of a global ciphertext that is available session-wide.
func (OperandLabel) CircuitID ¶
func (opl OperandLabel) CircuitID() helium.CircuitID
CircuitID returns the circuit id part of the operand label.
func (OperandLabel) ForCircuit ¶
func (opl OperandLabel) ForCircuit(cid helium.CircuitID) OperandLabel
ForCircuit returns a new operand label for the given circuit id, with the circuit id part set to cid.
func (OperandLabel) ForMapping ¶
func (opl OperandLabel) ForMapping(nodeMapping map[string]helium.NodeID) OperandLabel
ForMapping returns a new operand label with the node id part replaced by the corresponding value in the provided mapping.
func (OperandLabel) HasNode ¶
func (opl OperandLabel) HasNode(id helium.NodeID) bool
HasNode returns true if the operand label has the given host id.
func (OperandLabel) NodeID ¶
func (opl OperandLabel) NodeID() helium.NodeID
NodeID returns the node id part of the operand label.
type Output ¶
Output is a type for circuit outputs. It associates the output operand with the ID of the circuit that has produced it.
type Runtime ¶
type Runtime interface {
// Input reads an input operand with the given label from the context.
// When specifying the label, the user:
// - can use a placeholder id for the node, the mapping for which is provided in the Signature.
// - can omit the session-id part as it wil be automatically resolved by the runtime.
Input(OperandLabel) *FutureOperand
// Load reads an existing ciphertext in the session
// When specifying the label, the user:
// - can use a placeholder id for the node, the mapping for which is provided in the Signature.
// - can omit the session-id part as it wil be automatically resolved by the runtime.
Load(OperandLabel) *Operand
// NewOperand creates a new operand with the given label.
// When specifying the label, the user:
// - can use a placeholder id for the node, the mapping for which is provided in the Signature.
// - can omit the session-id part as it wil be automatically resolved by the runtime.
NewOperand(OperandLabel) Operand
// DEC performes the decryption of in, with private output to rec.
// The decrypted operand is considered an output for the this circuit and the
// given reciever.
// It expect the users to provide the decryption parameters, including the level
// at which the operation is performed and the smudging parameter.
DEC(in Operand, rec helium.NodeID, params map[string]string) error
// PCKS performes the re-encryption of in to the public key of rec.
// The the re-encrypted operand is considered an output for the this circuit and the
// given reciever.
// It expect the users to provide the key-switch parameters, including the level
// at which the operation is performed and the smudging parameter.
PCKS(in Operand, rec helium.NodeID, params map[string]string) error
// Parameters returns the encryption parameters for the circuit.
Parameters() bgv.Parameters
// NewEvaluator returns a new evaluator to be used in this circuit.
NewEvaluator() Evaluator
Evaluator
}
Runtime defines the interface that is available to circuits to access their execution context.