compute

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 21 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 CircuitNotRunningError added in v0.2.0

type CircuitNotRunningError struct {
	CircuitID sessions.CircuitID
}

func (CircuitNotRunningError) Error added in v0.2.0

func (e CircuitNotRunningError) Error() string

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 Coordinator added in v0.2.0

type Coordinator coordinator.Coordinator[Event]

type Encoder added in v0.2.0

type Encoder interface {
}

type Event added in v0.2.0

type Event struct {
	CircuitEvent  *circuits.Event
	ProtocolEvent *protocols.Event
}

type FHEProvider

type FHEProvider interface {
	GetParameters(ctx context.Context) (sessions.FHEParameters, error)
	GetEncoder(ctx context.Context) (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

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 OperandProvider added in v0.2.0

type OperandProvider interface {
	GetOperand(circuits.OperandLabel) (*circuits.Operand, bool)
	PutOperand(circuits.OperandLabel, *circuits.Operand) error
}

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 Service

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

Service represents a compute service instance.

func NewComputeService

func NewComputeService(ownID sessions.NodeID, sessProv sessions.Provider, conf ServiceConfig, pkbk circuits.PublicKeyProvider) (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) EvalCircuit added in v0.2.0

func (s *Service) EvalCircuit(ctx context.Context, cd circuits.Descriptor) error

func (*Service) GetCiphertext

func (s *Service) GetCiphertext(ctx context.Context, ctID sessions.CiphertextID) (*sessions.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) (enc Encoder, err 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) GetOperand added in v0.2.0

func (s *Service) GetOperand(opl circuits.OperandLabel) (*circuits.Operand, bool)

func (*Service) GetParameters added in v0.2.0

func (s *Service) GetParameters(ctx context.Context) (sessions.FHEParameters, error)

GetParameters returns the parameters of the context's session.

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) 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 sessions.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) PutOperand added in v0.2.0

func (s *Service) PutOperand(opl circuits.OperandLabel, op *circuits.Operand) error

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

func (s *Service) Run(ctx context.Context, ip InputProvider, or OutputReceiver, upstream Coordinator, trans Transport) error

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 sessions.Ciphertext) error

	// GetCiphertext requests a ciphertext from the transport.
	GetCiphertext(ctx context.Context, ctID sessions.CiphertextID) (*sessions.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.

type URL added in v0.2.0

type URL url.URL

URL defines a URL format to serve as ciphertext identifier for the Helium framwork.

func ParseURL added in v0.2.0

func ParseURL(s string) (*URL, error)

ParseURL parses a string into a helium URL.

func (*URL) CiphertextBaseID added in v0.2.0

func (u *URL) CiphertextBaseID() sessions.CiphertextID

func (*URL) CiphertextID added in v0.2.0

func (u *URL) CiphertextID() sessions.CiphertextID

func (*URL) CircuitID added in v0.2.0

func (u *URL) CircuitID() string

CircuitID returns the circuit id part of the URL, if any. Returns the empty string if no circuit id is present.

func (*URL) NodeID added in v0.2.0

func (u *URL) NodeID() sessions.NodeID

NodeID returns the host part of the URL as a NodeID.

func (*URL) String added in v0.2.0

func (u *URL) String() string

String returns the string representation of the URL.

Jump to

Keyboard shortcuts

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