Skip to content

Commit

Permalink
added basic client submission of circuit descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMct committed Jul 23, 2024
1 parent 7ddec84 commit d302c73
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ lint: check_reqs fmt vet staticcheck tidy ## Run all the linters

## Protocol Buffers
gen-proto: ## Compile protobuf files
protoc --go_out=./transport/pb --go_opt=paths=source_relative --go-grpc_out=./transport/pb \
--go-grpc_opt=paths=source_relative --proto_path=./transport ./transport/*.proto
protoc --go_out=./api/pb --go_opt=paths=source_relative --go-grpc_out=./api/pb \
--go-grpc_opt=paths=source_relative --proto_path=./api ./api/*.proto

## Help:
help: ## Show this help.
Expand Down
3 changes: 3 additions & 0 deletions api/helium.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ service Helium {

/* PutCiphertext pushes the ciphertext to the callee */
rpc PutCiphertext(Ciphertext) returns (CiphertextID) {}

/* EvalCircuit requests the evaluation of the circuit described by the CircuitDescriptor */
rpc EvalCircuit(CircuitDescriptor) returns (Void) {}
}

/*
Expand Down
33 changes: 20 additions & 13 deletions api/pb/helium.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 39 additions & 1 deletion api/pb/helium_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ func (hc *HeliumClient) PutCiphertext(ctx context.Context, ct sessions.Ciphertex
return err
}

// EvalCircuit sends a circuit to the helium server for evaluation.
// TODO: clean the cdesc submission API (and the output one ?)
func (hc *HeliumClient) EvalCircuit(ctx context.Context, cd circuits.Descriptor) error {
_, err := hc.HeliumClient.EvalCircuit(hc.outgoingContext(ctx), api.GetCircuitDesc(cd))
return err
}

func (hc *HeliumClient) outgoingContext(ctx context.Context) context.Context {
ctx = sessions.ContextWithNodeID(ctx, hc.id) // TODO would be better to ensure that a node always has its id in a context
ctx, err := getOutgoingContext(ctx)
Expand Down
2 changes: 1 addition & 1 deletion examples/vec-mul/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#########################################
# Builder #
#########################################
FROM golang:latest as builder
FROM golang:latest AS builder

ARG APP=examples/vec-mul/

Expand Down
25 changes: 24 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type HeliumServer struct {
id sessions.NodeID
incomingShares chan protocols.Share

// channel for the EvalCircuit API method
cdescs chan circuits.Descriptor

// event log
events coordinator.Log[node.Event]
eventsClosed bool
Expand Down Expand Up @@ -89,6 +92,8 @@ func NewHeliumServer(helperNode *node.Node) *HeliumServer {

hsv.incomingShares = make(chan protocols.Share)

hsv.cdescs = make(chan circuits.Descriptor)

return hsv
}

Expand Down Expand Up @@ -169,7 +174,18 @@ func (hsv *HeliumServer) Run(ctx context.Context, app node.App, ip compute.Input
}
}

return hsv.helperNode.Run(ctx, app, ip, &nodeCoordinator{hsv}, &nodeTransport{s: hsv})
cdescs, outs, err = hsv.helperNode.Run(ctx, app, ip, &nodeCoordinator{hsv}, &nodeTransport{s: hsv})
if err != nil {
return nil, nil, err
}

go func() {
for cdesc := range hsv.cdescs {
cdescs <- cdesc
}
}()

return
}

// AppendEventToLog is called by the server side to append a new event to the log and send it to all connected peers.
Expand Down Expand Up @@ -376,6 +392,13 @@ func (hsv *HeliumServer) PutCiphertext(inctx context.Context, apict *pb.Cipherte
return &pb.CiphertextID{CiphertextId: string(ct.ID)}, nil
}

func (hsv *HeliumServer) EvalCircuit(ctx context.Context, apicd *pb.CircuitDescriptor) (*pb.Void, error) {
cd := api.ToCircuitDesc(apicd)
hsv.cdescs <- *cd
return &pb.Void{}, nil

}

func (hsv *HeliumServer) PutOperand(opl circuits.OperandLabel, op *circuits.Operand) error {
return hsv.helperNode.PutOperand(opl, op)
}
Expand Down
1 change: 1 addition & 0 deletions services/compute/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type CircuitRuntime interface {
// - *rlwe.Ciphertext: an encrypted input
// - *rlwe.Plaintext: a Lattigo plaintext input, which will be encrypted by the framework
// - []uint64: a Go plaintext input, which will be encoded and encrypted by the framework
// TODO: should query inputs for the whole circuit at once
type InputProvider func(context.Context, sessions.CircuitID, circuits.OperandLabel, sessions.Session) (any, error)

// NoInput is an input provider that returns nil for all inputs.
Expand Down

0 comments on commit d302c73

Please sign in to comment.