compute

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package compute implements the MHE compute phase as a service. This service is responsible for evaluating circuits and running associated the protocols. It stats a protocol.Executor and acts as a coordinator for it.

Index

Constants

View Source
const (
	// DefaultCircQueueSize is the default size of the circuit execution queue.
	DefaultCircQueueSize = 512
	// DefaultMaxCircuitEvaluation is the default maximum number of circuits that can be evaluated concurrently.
	DefaultMaxCircuitEvaluation = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CircuitRuntime

type CircuitRuntime interface {
	// Init provides the circuit runtime with the circuit's metadata.
	Init(ctx context.Context, md circuits.Metadata) (err error)

	// Eval runs the circuit evaluation, given the circuit.
	Eval(ctx context.Context, c circuits.Circuit) (err error)

	// IncomingOperand provides the circuit runtime with an incoming operand.
	IncomingOperand(circuits.Operand) error

	// CompletedProtocol informs the circuit runtime that a protocol has been completed.
	CompletedProtocol(protocols.Descriptor) error

	// GetOperand returns the operand with the given label, if it exists.
	GetOperand(context.Context, circuits.OperandLabel) (*circuits.Operand, bool)

	// GetFutureOperand returns the future operand with the given label, if it exists.
	GetFutureOperand(context.Context, circuits.OperandLabel) (*circuits.FutureOperand, bool)

	// Wait blocks until the circuit executing in this runtime (including its related protocols) completes.
	Wait() error
}

CircuitRuntime is the interface of a circuit's execution environment. There are two notable instantiation of this interface:

  • evaluator: the node that evaluates the circuit
  • participant: the node that provides input to the circuit, participates in the protocols and recieve outputs.

type FHEProvider

type FHEProvider interface {
	GetEncoder(ctx context.Context) (*bgv.Encoder, error)
	GetEncryptor(ctx context.Context) (*rlwe.Encryptor, error)
	GetEvaluator(ctx context.Context, rlk bool, galEls []uint64) (*fheEvaluator, error)
	GetDecryptor(ctx context.Context) (*rlwe.Decryptor, error)
}

FHEProvider is an interface for requesting FHE-related objects as implemented in the Lattigo library.

type InputProvider

InputProvider is a type for providing input to a circuit. It is generally provided by the user, and lets the framework query for inputs to the circuit by their label. See circuits.OperandLabel for more information on operand labels. Input providers are expected to return one of the following types: - *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

var NoInput InputProvider = func(_ context.Context, _ helium.CircuitID, _ circuits.OperandLabel, _ session.Session) (any, error) {
	return nil, nil
}

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

type KeyOperationRunner

type KeyOperationRunner interface {
	RunKeyOperation(ctx context.Context, sig protocols.Signature) error
}

KeyOperationRunner is an interface for running key operations. It is used by the evaluatorRuntime to run key operations as they are requested by the circuit.

type OutputReceiver

type OutputReceiver chan<- circuits.Output

OutputReceiver is a type for receiving outputs from a circuit.

NoOutput is an output receiver that do not send any input

type PublicKeyProvider

type PublicKeyProvider interface {
	GetCollectivePublicKey(context.Context) (*rlwe.PublicKey, error)
	GetGaloisKey(ctx context.Context, galEl uint64) (*rlwe.GaloisKey, error)
	GetRelinearizationKey(context.Context) (*rlwe.RelinearizationKey, error)
}

PublicKeyProvider is an interface for querying public encryption- and evaluation-keys. The setup service is a notable implementation of this interface.

type Service

type Service struct {
	*protocols.Executor
	// contains filtered or unexported fields
}

Service represents a compute service instance.

func NewComputeService

func NewComputeService(ownID helium.NodeID, sessions session.SessionProvider, conf ServiceConfig, pkbk PublicKeyProvider, trans Transport) (s *Service, err error)

NewComputeService creates a new compute service instance.

func (*Service) AggregationOutputHandler

func (s *Service) AggregationOutputHandler(ctx context.Context, aggOut protocols.AggregationOutput) error

AggregationOutputHandler recieves the completed protocol aggregations from the executor.

func (*Service) GetCiphertext

func (s *Service) GetCiphertext(ctx context.Context, ctID helium.CiphertextID) (*helium.Ciphertext, error)

GetCiphertext retreives a ciphertext from the corresponding circuit runtime. The runtime is identified by the circuit ID part of the ciphertext ids.

func (*Service) GetDecryptor

func (s *Service) GetDecryptor(ctx context.Context) (*rlwe.Decryptor, error)

GetDecryptor returns a new decryptor from the context's session. The decryptor is inialized with a secret key of 0.

func (*Service) GetEncoder

func (s *Service) GetEncoder(ctx context.Context) (*bgv.Encoder, error)

GetEncoder returns a new encoder from the context's session.

func (*Service) GetEncryptor

func (s *Service) GetEncryptor(ctx context.Context) (*rlwe.Encryptor, error)

GetEncryptor returns a new encryptor from the context's session and the collective public key.

func (*Service) GetEvaluator

func (s *Service) GetEvaluator(ctx context.Context, relin bool, galEls []uint64) (*fheEvaluator, error)

GetEvaluator returns a new evaluator from the context's session and relevant evaluation keys.

func (*Service) GetProtocolInput

func (s *Service) GetProtocolInput(ctx context.Context, pd protocols.Descriptor) (in protocols.Input, err error)

GetProtocolInput returns the input for a protocol from the corresponding circuit runtime. The input is the ciphertext identified by the "op" protocol argument. The runtime is identified by the circuit ID part of the operand label.

func (*Service) Incoming

func (s *Service) Incoming() <-chan protocols.Event

Incoming returns the incoming event channel.

func (*Service) Init

func (s *Service) Init(ctx context.Context, complCd, runCd []circuits.Descriptor, complPd, runPd []protocols.Descriptor) error

Init initializes the compute service with the currently completed and running circuits and protocols. It queues running circuits and protocols for execution.

func (*Service) Logf

func (s *Service) Logf(msg string, v ...any)

func (*Service) Outgoing

func (s *Service) Outgoing() chan<- protocols.Event

Outgoing returns the outgoing event channel.

func (*Service) PutCiphertext

func (s *Service) PutCiphertext(ctx context.Context, ct helium.Ciphertext) error

PutCiphertext provides the ciphertext to the corresponding circuit runtime. The runtime is identified by the circuit ID part of the ciphertext ids.

func (*Service) RegisterCircuit

func (s *Service) RegisterCircuit(name circuits.Name, circ circuits.Circuit) error

RegisterCircuit registers a circuit to the service's library. It returns an error if the circuit is already registered.

func (*Service) RegisterCircuits

func (s *Service) RegisterCircuits(cs map[circuits.Name]circuits.Circuit) error

RegisterCircuits registers a set of circuits to the service's library. It returns an error if any of the circuits is already registered.

func (*Service) Run

Run runs the compute service. The service processes incoming events from the upstream coordinator and acts as a coordinator for the protocol executor. It also processes the circuit execution queue and fetches the output for completed circuits. The method returns when the upstream coordinator is done and all circuits are completed.

func (*Service) RunKeyOperation

func (s *Service) RunKeyOperation(ctx context.Context, sig protocols.Signature) (err error)

RunKeyOperation runs a key operation (e.g. key switching) on the service's executor.

type ServiceConfig

type ServiceConfig struct {
	// CircQueueSize is the size of the circuit execution queue.
	// Passed this size, attempting to queue circuit for execution will block.
	CircQueueSize int
	// MaxCircuitEvaluation is the maximum number of circuits that can be evaluated concurrently.
	MaxCircuitEvaluation int
	// Protocols is the configuration of the protocol executor.
	Protocols protocols.ExecutorConfig
}

ServiceConfig is the configuration of a compute service.

type Transport

type Transport interface {
	protocols.Transport

	// PutCiphertext registers a ciphertext within the transport
	PutCiphertext(ctx context.Context, ct helium.Ciphertext) error

	// GetCiphertext requests a ciphertext from the transport.
	GetCiphertext(ctx context.Context, ctID helium.CiphertextID) (*helium.Ciphertext, error)
}

Transport defines the transport interface necessary for the compute service. In the current implementation (helper-assisted setting), this corresponds to the helper interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL