pde

package module
v0.0.0-...-85779c5 Latest Latest
Warning

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

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

README

fhe-org-2024

Lattigo presentation for FHE.org 2024 Conference

The constructions used in this code are from a joint work with Malika Izabachène that will be soon accessible on ePrint.

How to run the code

  1. $ go test -v -run=PDE -timeout=0

Private Database Exploration Circuit

A scientist would like to conduct a nation-wide medical study requiring patients with very specific combinations of attributes, but to be funded, the scientist must first conduct a preliminary feasibility study to assess if there are enough patients available in the country's hospitals meeting the study criteria.

This code showcases how Lattigo can be used to perform a privacy-preserving functional database exploration over multiple parties with the following privacy constraints:

  • To protect the IP of the study and the privacy of the patients (with respect to hospitals), each hospitals should learn nothing about the selection criteria.
  • To protect the privacy of the patients (with respect to the scientist), the scientist should only learn a binary value (if there are enough patients meeting the selection criteria among all the hospitals).

Setup

This code requires ~22GB of RAM to run with 128-bit secure parameters.

To run with insecure parameters, change the values LogNPack and LogNEval in the file parameters.go.

The test will pring the LogN, LogQP and key distribution of each parameters

Client
  1. Parameters
  2. EvaluationKey
  3. A list of h' Private Scoring Functions [Enc(F[0](x)), Enc(F[1](x)), ..., Enc(F[h'-1](x))]
  4. Private threshold n°1: Enc(t0), Enc(1/sum(max(F[i]))
  5. Private threshold n°2: Enc(t1)
Server
  1. A database of P of dimension #Patients x #Attributs = p x h

Circuit

  1. The client sends {Parameters, EvaluationKey, [Enc(F[0](x)), Enc(F[1](x)), ..., Enc(F[h-1](x))], Enc(t0), Enc(1/sum(max(F[i])), Enc(t1)}
  2. The server evaluate RLWE[i](sum F[j](p[i][j])X^{0} + *X^{1} + ...) = sum_j X^{p[i][j]} * Enc(F[j](x))
  3. The server repacks the sparse RLWE ciphertexts into dense RLWE ciphertexts of dimension 2^LogNPack and merges them into ciphertexts of dimension 2^LogNEval
  4. The server evaluates Scheme-Switch which homomorphically encodes the packed RLWE ciphertexts into CKKS ciphertexts ct[i].
  5. For ct' = 0 and each RLWE ciphertext ct[i], the server evaluates ct' <- ct' + step((ct[i] - Enc(t0)) * Enc(1/sum(max(F[i])))
  6. The server evaluates ct' <- step((InnerSum(ct') - Enc(t1)) * (1/p) )
  7. The server sends ct' back to the client

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BootstrappingParametersLiteral = bootstrapping.ParametersLiteral{
	LogN: utils.Pointy(LogNEval),
	LogP: []int{61, 61, 61, 61, 61},
	Xs:   ring.Ternary{H: 192},
}
View Source
var DBSize = 1 << 14
View Source
var Features = 16
View Source
var LogNEval = 16
View Source
var LogNPack = 12
View Source
var LogScale = 45
View Source
var MinimaxCompositePolynomialForSignThreshold0 = [][]string{
	{"0", "0.667972070856", "0", "-0.223989523020", "0", "0.136121229346", "0", "-0.099160550898", "0", "0.079224867308", "0", "-0.067250088206", "0", "0.059852569462", "0", "-0.503955481350"},
	{"0", "0.955669291788", "0", "-0.317870998995", "0", "0.189953989728", "0", "-0.134924463410", "0", "0.104260767625", "0", "-0.084798113265", "0", "0.071534728674", "0", "-0.282024623439"},
	{"0", "1.254717353059", "0", "-0.371638622338", "0", "0.175181567419", "0", "-0.085946606966", "0", "0.039326533561", "0", "-0.015616729371", "0", "0.004903749402", "0", "-0.000987938705"},
}

MinimaxCompositePolynomialForSignThreshold0 is an example of composite minimax polynomial for the sign function that is able to distinguish between value with a delta of up to 2^{-alpha=8}, tolerates a scheme error of 2^{-12} and outputs a binary value (-1, or 1) of up to 14.0 bits of precision.

It was computed with hefloat.GenMinimaxCompositePolynomialForSign(256, 8, 12, []int{15, 15, 15}).

View Source
var MinimaxCompositePolynomialForSignThreshold1 = [][]string{
	{"0", "0.637268817143423", "0", "-0.213843858840010", "0", "0.130068019801244", "0", "-0.094901182442864", "0", "0.076054612814770", "0", "-0.064781641895431", "0", "0.057798688832330", "0", "-0.527470371234989"},
	{"0", "0.638695683522550", "0", "-0.214316818308012", "0", "0.130348567125999", "0", "-0.095098055756955", "0", "0.076204005701363", "0", "-0.064899954787194", "0", "0.057894713727750", "0", "-0.526392177258839"},
	{"0", "0.656606626265620", "0", "-0.220250173467088", "0", "0.133863750202729", "0", "-0.097560013608431", "0", "0.078066936262030", "0", "-0.066369507148038", "0", "0.059080919875980", "0", "-0.512846436037889"},
	{"0", "0.855861960962205", "0", "-0.285691381624270", "0", "0.171944105417797", "0", "-0.123469618435643", "0", "0.096847091991917", "0", "-0.080284982264950", "0", "0.069319087833638", "0", "-0.360370937154585"},
	{"0", "1.261257106681966", "0", "-0.389575144395675", "0", "0.200091626583035", "0", "-0.112254644903536", "0", "0.062146884728848", "0", "-0.032085565037577", "0", "0.014550986557278", "0", "-0.005542572455981"},
}

MinimaxCompositePolynomialForSignThreshold1 is an example of composite minimax polynomial for the sign function that is able to distinguish between value with a delta of up to 2^{-alpha=16}, tolerates a scheme error of 2^{-20} and outputs a binary value (-1, or 1) of up to 9.4 bits of precision.

It was computed with hefloat.GenMinimaxCompositePolynomialForSign(256, 16, 20, []int{15, 15, 15, 15, 15}).

View Source
var ParametersLiteralLogN16 = hefloat.ParametersLiteral{
	LogN:            LogNEval,
	LogQ:            []int{60, LogScale, LogScale, LogScale, LogScale, LogScale, LogScale, LogScale, LogScale},
	LogP:            []int{48, 55, 55},
	LogDefaultScale: LogScale,
	Xs:              ring.Ternary{H: 192},
}
View Source
var Scaling = 1 << 16

Functions

func GaloisElementsForPack

func GaloisElementsForPack(params rlwe.ParameterProvider, logGap int) (galEls []uint64)

GaloisElementsForPack returns the list of Galois elements required to perform the `Pack` operation.

func GenXPow2NTT

func GenXPow2NTT(r *ring.Ring, logN int, div bool) (xPow []ring.Poly)

GenXPow2NTT generates X^({-1 if div else 1} * {2^{0 <= i < LogN}}) in NTT.

func RunTimed

func RunTimed(msg string, f func() (err error)) (err error)

Types

type Bootstrapper

type Bootstrapper interface {
	he.Bootstrapper[rlwe.Ciphertext]
	SchemeSwitch(input *rlwe.Ciphertext) (output0, output1 *rlwe.Ciphertext, err error)
	GetEvaluator() *hefloat.Evaluator
}

func NewBootstrappingEvaluator

func NewBootstrappingEvaluator(r Request) (btp Bootstrapper, err error)

type BootstrappingEvaluator

type BootstrappingEvaluator struct {
	bootstrapping.Evaluator
}

func (BootstrappingEvaluator) GetEvaluator

func (eval BootstrappingEvaluator) GetEvaluator() *hefloat.Evaluator

func (BootstrappingEvaluator) SchemeSwitch

func (eval BootstrappingEvaluator) SchemeSwitch(input *rlwe.Ciphertext) (output0, output1 *rlwe.Ciphertext, err error)

SchemeSwitch takes Enc(m(X)) at modulus Q[0] and returns Enc(Encode(m(X))) at modulus Q[L].

type Client

type Client struct {
	Parameters map[int]*hefloat.Parameters
	Ski        map[int]*rlwe.SecretKey
}

func NewClient

func NewClient() (c Client)

func (Client) Decrypt

func (c Client) Decrypt(score *rlwe.Ciphertext) (v []complex128, err error)

func (Client) GenEncryptedFunction

func (c Client) GenEncryptedFunction(funcs []Func) (encFuncs TestVectors, err error)

func (Client) GenPrivateThreshold

func (c Client) GenPrivateThreshold(threshold float64, f []Func) (p PrivateThreshold, err error)

func (*Client) Init

func (c *Client) Init() (evk EvaluationKeys, err error)

type Database

type Database struct {
	*mat.Dense
}

func NewDatabase

func NewDatabase(p, h int) Database

func (Database) GetRow

func (d Database) GetRow(i int) []float64

func (Database) Size

func (db Database) Size() int

Size returns the number of rows in the DB.

type Func

type Func struct {
	F        func(x float64) (y float64)
	Interval [2]float64
	Max      float64
	Points   int
}

func NewScoringFunction

func NewScoringFunction(interval [2]float64, points int, scaling float64) Func

type PrivateThreshold

type PrivateThreshold struct {
	Threshold     *rlwe.Ciphertext
	Normalization *rlwe.Ciphertext
}

type RepackEvaluationKeySet

type RepackEvaluationKeySet struct {
	Parameters        map[int]*hefloat.Parameters
	RingSwitchingKeys map[int]map[int]*rlwe.EvaluationKey
	RepackKeys        map[int]rlwe.EvaluationKeySet
}

func (*RepackEvaluationKeySet) GenRepackEvaluationKeys

func (rpk *RepackEvaluationKeySet) GenRepackEvaluationKeys(params rlwe.ParameterProvider, sk *rlwe.SecretKey, evkParams rlwe.EvaluationKeyParameters)

GenRepackEvaluationKeys generates the set of params.LogN() [rlwe.EvaluationKey]s necessary to perform the repacking operation. See [RingPackingEvaluator.Repack] for additional information.

func (*RepackEvaluationKeySet) GenRingSwitchingKeys

func (rpk *RepackEvaluationKeySet) GenRingSwitchingKeys(p hefloat.Parameters, sk *rlwe.SecretKey, minLogN int, evkParams rlwe.EvaluationKeyParameters) (ski map[int]*rlwe.SecretKey, err error)

func (RepackEvaluationKeySet) MaxLogN

func (rpk RepackEvaluationKeySet) MaxLogN() (maxLogN int)

func (RepackEvaluationKeySet) MinLogN

func (rpk RepackEvaluationKeySet) MinLogN() (minLogN int)

type RepackEvaluator

type RepackEvaluator struct {
	*RepackEvaluationKeySet
	Evaluators map[int]*rlwe.Evaluator
	XPow2NTT   map[int][]ring.Poly
}

func NewRepackEvaluator

func NewRepackEvaluator(evk *RepackEvaluationKeySet) *RepackEvaluator

func (RepackEvaluator) Merge

func (eval RepackEvaluator) Merge(ctEvenNHalf, ctOddNHalf, ctN *rlwe.Ciphertext) (err error)

Merge merges two ciphertexts of degree N/2 into a ciphertext of degre N: ctN[X] = ctEvenNHalf[Y] + X * ctOddNHalf[Y] where Y = X^2.

func (RepackEvaluator) MergeNew

func (eval RepackEvaluator) MergeNew(ctEvenNHalf, ctOddNHalf *rlwe.Ciphertext) (ctN *rlwe.Ciphertext, err error)

MergeNew merges two ciphertexts of degree N/2 into a ciphertext of degre N: ctN[X] = ctEvenNHalf[Y] + X * ctOddNHalf[Y] where Y = X^2.

func (RepackEvaluator) Pack

func (eval RepackEvaluator) Pack(cts map[int]*rlwe.Ciphertext) (ct *rlwe.Ciphertext, err error)

type Request

type Request struct {
	*EvaluationKeys
	*TestVectors
	PrivateThreshold0 *PrivateThreshold
	PrivateThreshold1 *PrivateThreshold
}

type Server

type Server struct {
	SkDebug                map[int]*rlwe.SecretKey
	SecretKeyBootstrapping bool
	DecEval                *rlwe.Decryptor
	DecPack                *rlwe.Decryptor
	EcdEval                *hefloat.Encoder
	EcdPack                *hefloat.Encoder
	EvalRepack             *RepackEvaluator
	Bootstrapper
	ParamsPack hefloat.Parameters
	ParamsEval hefloat.Parameters
}

func NewServer

func NewServer() Server

func (Server) EncryptedLookupTablesAndRingPacking

func (s Server) EncryptedLookupTablesAndRingPacking(db *Database, fi *TestVectors) (res []*rlwe.Ciphertext, err error)

func (Server) GlobalThreshold

func (s Server) GlobalThreshold(input, t1 *rlwe.Ciphertext, rows int) (output *rlwe.Ciphertext, err error)

func (Server) LocalThreshold

func (s Server) LocalThreshold(input, t0, c *rlwe.Ciphertext, output *rlwe.Ciphertext) (err error)

func (Server) Merge

func (s Server) Merge(cts []*rlwe.Ciphertext, eval *RepackEvaluator) (ct *rlwe.Ciphertext, err error)

func (Server) PrintDebug

func (s Server) PrintDebug(msg string, input *rlwe.Ciphertext, scaling float64)

func (Server) ProcessRequest

func (s Server) ProcessRequest(r Request, db *Database, btp Bootstrapper) (score *rlwe.Ciphertext, err error)

func (Server) RingMerging

func (s Server) RingMerging(res []*rlwe.Ciphertext) (resMerged []*rlwe.Ciphertext, err error)

func (Server) SchemeSwitchingAndAggregatedLocalThreshold

func (s Server) SchemeSwitchingAndAggregatedLocalThreshold(resMerged []*rlwe.Ciphertext, t0, c *rlwe.Ciphertext) (score *rlwe.Ciphertext, err error)

type TestVector

type TestVector struct {
	Value    structs.Vector[rlwe.Ciphertext]
	Interval [2]float64
	Points   int
}

TestVector is a set of polynomials encoding a function f(x) = y.

func GenTestPolynomials

func GenTestPolynomials(params hefloat.Parameters, f Func, ecd *hefloat.Encoder, enc *rlwe.Encryptor) (TestVector, error)

GenTestPolynomials generates a TestPolynomial from a function.

type TestVectors

type TestVectors []TestVector

func (TestVectors) BinarySize

func (tv TestVectors) BinarySize() (size int)

func (TestVectors) Evaluate

func (tv TestVectors) Evaluate(params hefloat.Parameters, values []float64, buffPoly ring.Poly, buffCt *rlwe.Ciphertext) (err error)

Jump to

Keyboard shortcuts

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