Skip to content

Commit

Permalink
depluralized package names: protocol and circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMct committed Apr 5, 2024
1 parent 1849df6 commit fce7111
Show file tree
Hide file tree
Showing 28 changed files with 341 additions and 341 deletions.
8 changes: 4 additions & 4 deletions circuits/circuits.go → circuit/circuit.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Package circuits provides the types and interfaces for defining, parsing and executing circuits.
package circuits
// Package circuit provides the types and interfaces for defining, parsing and executing circuits.
package circuit

import (
"context"
"fmt"

"github.com/ChristianMct/helium"
"github.com/ChristianMct/helium/protocols"
"github.com/ChristianMct/helium/protocol"
"github.com/ChristianMct/helium/session"
"github.com/ChristianMct/helium/utils"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
Expand Down Expand Up @@ -97,7 +97,7 @@ type Metadata struct {
Descriptor
InputSet, Ops, OutputSet utils.Set[OperandLabel]
InputsFor, OutputsFor map[helium.NodeID]utils.Set[OperandLabel]
KeySwitchOps map[string]protocols.Signature
KeySwitchOps map[string]protocol.Signature
NeedRlk bool
GaloisKeys utils.Set[uint64]
}
Expand Down
2 changes: 1 addition & 1 deletion circuits/operands.go → circuit/operand.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package circuits
package circuit

import (
"fmt"
Expand Down
16 changes: 8 additions & 8 deletions circuits/parsing.go → circuit/parsing.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package circuits
package circuit

import (
"encoding/json"
Expand All @@ -7,7 +7,7 @@ import (
"sync"

"github.com/ChristianMct/helium"
"github.com/ChristianMct/helium/protocols"
"github.com/ChristianMct/helium/protocol"
"github.com/ChristianMct/helium/session"
"github.com/ChristianMct/helium/utils"
"github.com/tuneinsight/lattigo/v5/he"
Expand Down Expand Up @@ -42,7 +42,7 @@ func newCircuitParserCtx(cd Descriptor, params session.FHEParameters) *circuitPa
OutputSet: utils.NewEmptySet[OperandLabel](),
InputsFor: make(map[helium.NodeID]utils.Set[OperandLabel]),
OutputsFor: make(map[helium.NodeID]utils.Set[OperandLabel]),
KeySwitchOps: make(map[string]protocols.Signature),
KeySwitchOps: make(map[string]protocol.Signature),
GaloisKeys: make(utils.Set[uint64]),
},
SubCtx: make(map[helium.CircuitID]*circuitParserContext, 0),
Expand Down Expand Up @@ -134,7 +134,7 @@ func (e *circuitParserContext) output(out Operand, to helium.NodeID) {
outset.Add(opl)
}

func (e *circuitParserContext) registerKeyOps(sig protocols.Signature) error {
func (e *circuitParserContext) registerKeyOps(sig protocol.Signature) error {

target, hasTarget := sig.Args["target"]
if !hasTarget {
Expand All @@ -155,13 +155,13 @@ func (e *circuitParserContext) registerKeyOps(sig protocols.Signature) error {
return nil
}

func GetProtocolSignature(t protocols.Type, in OperandLabel, params map[string]string) (pd protocols.Signature) {
func GetProtocolSignature(t protocol.Type, in OperandLabel, params map[string]string) (pd protocol.Signature) {
parm := make(map[string]string, len(params))
for k, v := range params {
parm[k] = v
}
parm["op"] = string(in)
return protocols.Signature{Type: t, Args: parm}
return protocol.Signature{Type: t, Args: parm}
}

func (e *circuitParserContext) DEC(in Operand, rec helium.NodeID, params map[string]string) (err error) {
Expand All @@ -176,7 +176,7 @@ func (e *circuitParserContext) DEC(in Operand, rec helium.NodeID, params map[str
pparams := maps.Clone(params)
pparams["target"] = string(rec)

pd := GetProtocolSignature(protocols.DEC, in.OperandLabel.ForCircuit(e.cd.CircuitID).ForMapping(e.cd.NodeMapping), pparams)
pd := GetProtocolSignature(protocol.DEC, in.OperandLabel.ForCircuit(e.cd.CircuitID).ForMapping(e.cd.NodeMapping), pparams)
if err = e.registerKeyOps(pd); err != nil {
return err
}
Expand All @@ -197,7 +197,7 @@ func (e *circuitParserContext) PCKS(in Operand, rec helium.NodeID, params map[st
pparams := maps.Clone(params)
pparams["target"] = string(rec)

pd := GetProtocolSignature(protocols.PCKS, in.OperandLabel.ForCircuit(e.cd.CircuitID).ForMapping(e.cd.NodeMapping), params)
pd := GetProtocolSignature(protocol.PCKS, in.OperandLabel.ForCircuit(e.cd.CircuitID).ForMapping(e.cd.NodeMapping), params)
if err = e.registerKeyOps(pd); err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion circuits/test_circuits.go → circuit/test_circuit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package circuits
package circuit

import (
"github.com/tuneinsight/lattigo/v5/he"
Expand Down
8 changes: 4 additions & 4 deletions coordinator/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ package coordinator
import (
"fmt"

"github.com/ChristianMct/helium/circuits"
"github.com/ChristianMct/helium/protocols"
"github.com/ChristianMct/helium/circuit"
"github.com/ChristianMct/helium/protocol"
)

// Event is a type for coordination events in the coordinator.
type Event struct {
ProtocolEvent *protocols.Event
CircuitEvent *circuits.Event // TODO refactor as setup and compute event wrapping protocol events ?
ProtocolEvent *protocol.Event
CircuitEvent *circuit.Event // TODO refactor as setup and compute event wrapping protocol events ?
}

// IsProtocolEvent whether the event contains a protocol-related event.
Expand Down
24 changes: 12 additions & 12 deletions examples/vec-mul/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"log"

"github.com/ChristianMct/helium"
"github.com/ChristianMct/helium/circuits"
"github.com/ChristianMct/helium/circuit"
"github.com/ChristianMct/helium/node"
"github.com/ChristianMct/helium/objectstore"
"github.com/ChristianMct/helium/protocols"
"github.com/ChristianMct/helium/protocol"
"github.com/ChristianMct/helium/services/compute"
"github.com/ChristianMct/helium/services/setup"
"github.com/ChristianMct/helium/session"
Expand Down Expand Up @@ -46,8 +46,8 @@ var (
SessionParameters: []session.Parameters{sessionParams},

// in this example, peer node can only participate in one protocol and one circuit at a time
SetupConfig: setup.ServiceConfig{Protocols: protocols.ExecutorConfig{MaxParticipation: 1}},
ComputeConfig: compute.ServiceConfig{MaxCircuitEvaluation: 1, Protocols: protocols.ExecutorConfig{MaxParticipation: 1}},
SetupConfig: setup.ServiceConfig{Protocols: protocol.ExecutorConfig{MaxParticipation: 1}},
ComputeConfig: compute.ServiceConfig{MaxCircuitEvaluation: 1, Protocols: protocol.ExecutorConfig{MaxParticipation: 1}},

ObjectStoreConfig: objectstore.Config{BackendName: "mem"}, // use a volatile in-memory store for state
TLSConfig: centralized.TLSConfig{InsecureChannels: true}, // no TLS for simplicity
Expand All @@ -61,8 +61,8 @@ var (
SessionParameters: []session.Parameters{sessionParams},

// allows 16 parallel protocol aggregation and each node is not chosen as participant for more than one protocol at the time.
SetupConfig: setup.ServiceConfig{Protocols: protocols.ExecutorConfig{MaxAggregation: 16, MaxProtoPerNode: 1}},
ComputeConfig: compute.ServiceConfig{MaxCircuitEvaluation: 16, Protocols: protocols.ExecutorConfig{MaxAggregation: 16, MaxProtoPerNode: 1}},
SetupConfig: setup.ServiceConfig{Protocols: protocol.ExecutorConfig{MaxAggregation: 16, MaxProtoPerNode: 1}},
ComputeConfig: compute.ServiceConfig{MaxCircuitEvaluation: 16, Protocols: protocol.ExecutorConfig{MaxAggregation: 16, MaxProtoPerNode: 1}},
ObjectStoreConfig: objectstore.Config{BackendName: "mem"},
TLSConfig: centralized.TLSConfig{InsecureChannels: true},
}
Expand All @@ -81,9 +81,9 @@ var (
Rlk: true, // the circuit requires the relinearization key (for homomorphic multiplication)
Gks: []uint64{}, // the circuit does not require any galois keys (for homomorphic rotation)
},
Circuits: map[circuits.Name]circuits.Circuit{
Circuits: map[circuit.Name]circuit.Circuit{
// defines a circuit named "mul-4-dec" that multiplies 4 inputs and decrypts the result
"mul-4-dec": func(rt circuits.Runtime) error {
"mul-4-dec": func(rt circuit.Runtime) error {

// reads the inputs from the parties. The node ids can be place-holders and the mapping actual ids are provided
// when querying for a circuit's execution.
Expand Down Expand Up @@ -163,7 +163,7 @@ func main() {
if nodeID == helperID {
ip = compute.NoInput // the cloud has no input, the compute.NoInput InputProvider is used
} else {
ip = func(ctx context.Context, _ helium.CircuitID, ol circuits.OperandLabel, sess session.Session) (any, error) {
ip = func(ctx context.Context, _ helium.CircuitID, ol circuit.OperandLabel, sess session.Session) (any, error) {
bgvParams := sess.Params.(bgv.Parameters)
in := make([]uint64, bgvParams.MaxSlots())
// the session nodes create their input by replicating the user-provided input for each slot
Expand All @@ -183,9 +183,9 @@ func main() {

// the helper node starts the computation by sending a circuit description to the cdescs channel
if nodeID == helperID {
cdescs <- circuits.Descriptor{
Signature: circuits.Signature{Name: circuits.Name("mul-4-dec")}, // the name of the circuit to be evaluated
CircuitID: "mul-4-dec-0", // a unique, user-defined id for the circuit
cdescs <- circuit.Descriptor{
Signature: circuit.Signature{Name: circuit.Name("mul-4-dec")}, // the name of the circuit to be evaluated
CircuitID: "mul-4-dec-0", // a unique, user-defined id for the circuit
NodeMapping: map[string]helium.NodeID{ // the mapping from node ids in the circuit to actual node ids
"p0": "node-1",
"p1": "node-2",
Expand Down
4 changes: 2 additions & 2 deletions node/app.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package node

import (
"github.com/ChristianMct/helium/circuits"
"github.com/ChristianMct/helium/circuit"
"github.com/ChristianMct/helium/services/setup"
)

// App represents an Helium application. It specifes the setup phase
// and declares the circuits that can be executed by the nodes.
type App struct {
SetupDescription *setup.Description
Circuits map[circuits.Name]circuits.Circuit
Circuits map[circuit.Name]circuit.Circuit
}
52 changes: 26 additions & 26 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"slices"

"github.com/ChristianMct/helium"
"github.com/ChristianMct/helium/circuits"
"github.com/ChristianMct/helium/circuit"
"github.com/ChristianMct/helium/coordinator"
"github.com/ChristianMct/helium/objectstore"
"github.com/ChristianMct/helium/protocols"
"github.com/ChristianMct/helium/protocol"
"github.com/ChristianMct/helium/services/compute"
"github.com/ChristianMct/helium/services/setup"
"github.com/ChristianMct/helium/session"
Expand Down Expand Up @@ -48,7 +48,7 @@ type Node struct {
// transport
srv *centralized.HeliumServer
cli *centralized.HeliumClient
outgoingShares chan protocols.Share
outgoingShares chan protocol.Share
setupTransport *protocolTransport
computeTransport *computeTransport

Expand Down Expand Up @@ -99,15 +99,15 @@ func New(config Config, nodeList helium.NodesList) (node *Node, err error) {
node.cli = centralized.NewHeliumClient(node.id, node.helperID, node.nodeList.AddressOf(node.helperID))
}

node.outgoingShares = make(chan protocols.Share)
node.outgoingShares = make(chan protocol.Share)
node.setupTransport = &protocolTransport{
outshares: node.outgoingShares,
inshares: make(chan protocols.Share),
inshares: make(chan protocol.Share),
getAggregationOutput: node.GetAggregationOutput}
node.computeTransport = &computeTransport{
protocolTransport: protocolTransport{
outshares: node.outgoingShares,
inshares: make(chan protocols.Share),
inshares: make(chan protocol.Share),
getAggregationOutput: node.GetAggregationOutput},
putCiphertext: node.PutCiphertext,
getCiphertext: node.GetCiphertext}
Expand All @@ -132,7 +132,7 @@ func New(config Config, nodeList helium.NodesList) (node *Node, err error) {
}

// RunNew creates a new Helium node from the provided config and node list, and runs the node with the provided app under the given context.
func RunNew(ctx context.Context, config Config, nodeList helium.NodesList, app App, ip compute.InputProvider) (node *Node, cdescs chan<- circuits.Descriptor, outs <-chan circuits.Output, err error) {
func RunNew(ctx context.Context, config Config, nodeList helium.NodesList, app App, ip compute.InputProvider) (node *Node, cdescs chan<- circuit.Descriptor, outs <-chan circuit.Output, err error) {
node, err = New(config, nodeList)
if err != nil {
return nil, nil, nil, err
Expand Down Expand Up @@ -179,7 +179,7 @@ func (node *Node) Connect(ctx context.Context) error {
// - the method runs the setup and compute phases sequentially.
// - only the helper node can issue circuit descriptors.
// - loading and verification of the state from persistent storage is not implemented.
func (node *Node) Run(ctx context.Context, app App, ip compute.InputProvider) (cdescs chan<- circuits.Descriptor, outs <-chan circuits.Output, err error) {
func (node *Node) Run(ctx context.Context, app App, ip compute.InputProvider) (cdescs chan<- circuit.Descriptor, outs <-chan circuit.Output, err error) {

// recovers the session
sess, exists := node.GetSessionFromContext(ctx)
Expand All @@ -201,13 +201,13 @@ func (node *Node) Run(ctx context.Context, app App, ip compute.InputProvider) (c

sigList := setup.DescriptionToSignatureList(*app.SetupDescription)

cds := make(chan circuits.Descriptor)
or := make(chan circuits.Output)
cds := make(chan circuit.Descriptor)
or := make(chan circuit.Output)

// runs the setup phase
if node.IsHelperNode() {

setupCoord := &protocolCoordinator{make(chan protocols.Event), make(chan protocols.Event)}
setupCoord := &protocolCoordinator{make(chan protocol.Event), make(chan protocol.Event)}

downstreamDone := make(chan struct{})
go func() {
Expand Down Expand Up @@ -263,7 +263,7 @@ func (node *Node) Run(ctx context.Context, app App, ip compute.InputProvider) (c
<-node.setupDone
for cd := range cds {
node.Logf("new circuit descriptor: %s", cd)
cev := coordinator.Event{CircuitEvent: &circuits.Event{EventType: circuits.Started, Descriptor: cd}}
cev := coordinator.Event{CircuitEvent: &circuit.Event{EventType: circuit.Started, Descriptor: cd}}
computeCoord.incoming <- cev
}
node.Logf("user closed circuit discription channel, closing downstream")
Expand Down Expand Up @@ -297,7 +297,7 @@ func (node *Node) Run(ctx context.Context, app App, ip compute.InputProvider) (c

go node.sendShares(ctx)

setupCoord := &protocolCoordinator{make(chan protocols.Event), make(chan protocols.Event)}
setupCoord := &protocolCoordinator{make(chan protocol.Event), make(chan protocol.Event)}
go func() {
err := node.setup.Run(ctx, setupCoord)
if err != nil {
Expand Down Expand Up @@ -350,7 +350,7 @@ func (node *Node) Close() error {
// Transport interface implementation

// PutShare is called by the transport upon receiving a new share.
func (node *Node) PutShare(ctx context.Context, s protocols.Share) error {
func (node *Node) PutShare(ctx context.Context, s protocol.Share) error {
switch {
case s.ProtocolType.IsSetup():
node.setupTransport.inshares <- s
Expand All @@ -365,7 +365,7 @@ func (node *Node) PutShare(ctx context.Context, s protocols.Share) error {
// GetAggregationOutput returns the aggregation output for a given protocol descriptor.
// If this node is the helper node, the method retrieves the output from the services.
// If this node is a peer node, the method retrieves the output from the helper node.
func (node *Node) GetAggregationOutput(ctx context.Context, pd protocols.Descriptor) (*protocols.AggregationOutput, error) {
func (node *Node) GetAggregationOutput(ctx context.Context, pd protocol.Descriptor) (*protocol.AggregationOutput, error) {
if node.id == node.helperID {
switch {
case pd.Signature.Type.IsSetup():
Expand Down Expand Up @@ -579,34 +579,34 @@ func (node *Node) sendShares(ctx context.Context) {
}
}

func recoverPresentState(events <-chan coordinator.Event, present int) (completedProto, runningProto []protocols.Descriptor, completedCirc, runningCirc []circuits.Descriptor, err error) {
func recoverPresentState(events <-chan coordinator.Event, present int) (completedProto, runningProto []protocol.Descriptor, completedCirc, runningCirc []circuit.Descriptor, err error) {

if present == 0 {
return
}

var current int
runProto := make(map[protocols.ID]protocols.Descriptor)
runCircuit := make(map[helium.CircuitID]circuits.Descriptor)
runProto := make(map[protocol.ID]protocol.Descriptor)
runCircuit := make(map[helium.CircuitID]circuit.Descriptor)
for ev := range events {

if ev.IsComputeEvent() {
cid := ev.CircuitEvent.CircuitID
switch ev.CircuitEvent.EventType {
case circuits.Started:
case circuit.Started:
runCircuit[cid] = ev.CircuitEvent.Descriptor
case circuits.Executing:
case circuit.Executing:
if _, has := runCircuit[cid]; !has {
err = fmt.Errorf("inconsisted state, circuit %s execution event before start", cid)
return
}
case circuits.Completed, circuits.Failed:
case circuit.Completed, circuit.Failed:
if _, has := runCircuit[cid]; !has {
err = fmt.Errorf("inconsisted state, circuit %s termination event before start", cid)
return
}
delete(runCircuit, cid)
if ev.CircuitEvent.EventType == circuits.Completed {
if ev.CircuitEvent.EventType == circuit.Completed {
completedCirc = append(completedCirc, ev.CircuitEvent.Descriptor)
}
}
Expand All @@ -615,20 +615,20 @@ func recoverPresentState(events <-chan coordinator.Event, present int) (complete
if ev.IsProtocolEvent() {
pid := ev.ProtocolEvent.ID()
switch ev.ProtocolEvent.EventType {
case protocols.Started:
case protocol.Started:
runProto[pid] = ev.ProtocolEvent.Descriptor
case protocols.Executing:
case protocol.Executing:
if _, has := runProto[pid]; !has {
err = fmt.Errorf("inconsisted state, protocol %s execution event before start", ev.ProtocolEvent.HID())
return
}
case protocols.Completed, protocols.Failed:
case protocol.Completed, protocol.Failed:
if _, has := runProto[pid]; !has {
err = fmt.Errorf("inconsisted state, protocol %s termination event before start", ev.ProtocolEvent.HID())
return
}
delete(runProto, pid)
if ev.ProtocolEvent.EventType == protocols.Completed {
if ev.ProtocolEvent.EventType == protocol.Completed {
completedProto = append(completedProto, ev.ProtocolEvent.Descriptor)
}
}
Expand Down
Loading

0 comments on commit fce7111

Please sign in to comment.