Skip to content

Commit

Permalink
bump to lattigo v5.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMct committed Mar 18, 2024
1 parent 7752471 commit 3475db4
Show file tree
Hide file tree
Showing 26 changed files with 152 additions and 141 deletions.
22 changes: 11 additions & 11 deletions circuits/circuits.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"github.com/ChristianMct/helium"
"github.com/ChristianMct/helium/protocols"
"github.com/ChristianMct/helium/utils"
"github.com/tuneinsight/lattigo/v4/bgv"
"github.com/tuneinsight/lattigo/v4/ring"
"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v4/rlwe/ringqp"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
"github.com/tuneinsight/lattigo/v5/ring"
"github.com/tuneinsight/lattigo/v5/ring/ringqp"
"github.com/tuneinsight/lattigo/v5/schemes/bgv"
)

// Circuit is a type for representing circuits, which are Go functions interacting with
Expand Down Expand Up @@ -127,13 +127,13 @@ type Output struct {

// Evaluator is an interface that is directly supported by circuit runtimes.
type Evaluator interface {
Add(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error)
Sub(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error)
Mul(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error)
MulNew(op0 *rlwe.Ciphertext, op1 interface{}) (opOut *rlwe.Ciphertext, err error)
MulRelin(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error)
MulRelinNew(op0 *rlwe.Ciphertext, op1 interface{}) (opOut *rlwe.Ciphertext, err error)
MulThenAdd(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error)
Add(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error)
Sub(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error)
Mul(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error)
MulNew(op0 *rlwe.Ciphertext, op1 rlwe.Operand) (opOut *rlwe.Ciphertext, err error)
MulRelin(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error)
MulRelinNew(op0 *rlwe.Ciphertext, op1 rlwe.Operand) (opOut *rlwe.Ciphertext, err error)
MulThenAdd(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error)
Relinearize(op0, op1 *rlwe.Ciphertext) (err error)
Rescale(op0, op1 *rlwe.Ciphertext) (err error)
InnerSum(ctIn *rlwe.Ciphertext, batchSize, n int, opOut *rlwe.Ciphertext) (err error)
Expand Down
2 changes: 1 addition & 1 deletion circuits/operands.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

"github.com/ChristianMct/helium"
"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
)

// Operand is a type for representing circuit operands.
Expand Down
26 changes: 13 additions & 13 deletions circuits/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/ChristianMct/helium"
"github.com/ChristianMct/helium/protocols"
"github.com/ChristianMct/helium/utils"
"github.com/tuneinsight/lattigo/v4/bgv"
"github.com/tuneinsight/lattigo/v4/ring"
"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v4/rlwe/ringqp"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
"github.com/tuneinsight/lattigo/v5/ring"
"github.com/tuneinsight/lattigo/v5/ring/ringqp"
"github.com/tuneinsight/lattigo/v5/schemes/bgv"
)

// Parse parses a circuit and returns its metadata.
Expand Down Expand Up @@ -214,14 +214,14 @@ func (e *circuitParserContext) Parameters() bgv.Parameters {
return e.params
}

func (e *circuitParserContext) MulRelin(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error) {
func (e *circuitParserContext) MulRelin(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error) {
e.l.Lock()
defer e.l.Unlock()
e.md.NeedRlk = true
return nil
}

func (e *circuitParserContext) MulRelinNew(op0 *rlwe.Ciphertext, op1 interface{}) (opOut *rlwe.Ciphertext, err error) {
func (e *circuitParserContext) MulRelinNew(op0 *rlwe.Ciphertext, op1 rlwe.Operand) (opOut *rlwe.Ciphertext, err error) {
e.l.Lock()
defer e.l.Unlock()
e.md.NeedRlk = true
Expand Down Expand Up @@ -251,35 +251,35 @@ func (e *circuitParserContext) AutomorphismHoisted(level int, ctIn *rlwe.Ciphert

type dummyEvaluator struct{ ctx *circuitParserContext }

func (de *dummyEvaluator) Add(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error) {
func (de *dummyEvaluator) Add(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error) {
return nil
}

func (de *dummyEvaluator) Sub(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error) {
func (de *dummyEvaluator) Sub(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error) {
return nil
}

func (de *dummyEvaluator) Mul(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error) {
func (de *dummyEvaluator) Mul(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error) {
return nil
}

func (de *dummyEvaluator) MulNew(op0 *rlwe.Ciphertext, op1 interface{}) (opOut *rlwe.Ciphertext, err error) {
func (de *dummyEvaluator) MulNew(op0 *rlwe.Ciphertext, op1 rlwe.Operand) (opOut *rlwe.Ciphertext, err error) {
return nil, nil
}

func (de *dummyEvaluator) MulRelin(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error) {
func (de *dummyEvaluator) MulRelin(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error) {
return nil
}

func (de *dummyEvaluator) MulRelinNew(op0 *rlwe.Ciphertext, op1 interface{}) (opOut *rlwe.Ciphertext, err error) {
func (de *dummyEvaluator) MulRelinNew(op0 *rlwe.Ciphertext, op1 rlwe.Operand) (opOut *rlwe.Ciphertext, err error) {
return nil, nil
}

func (de *dummyEvaluator) Relinearize(op0 *rlwe.Ciphertext, op1 *rlwe.Ciphertext) (err error) {
return nil
}

func (de *dummyEvaluator) MulThenAdd(op0 *rlwe.Ciphertext, op1 interface{}, opOut *rlwe.Ciphertext) (err error) {
func (de *dummyEvaluator) MulThenAdd(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ciphertext) (err error) {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion circuits/test_circuits.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package circuits

import (
"github.com/tuneinsight/lattigo/v4/bgv"
"github.com/tuneinsight/lattigo/v5/schemes/bgv"
)

// TestCircuits contains a set of test circuits for the helium framework.
Expand Down
27 changes: 16 additions & 11 deletions examples/vec-mul/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"github.com/ChristianMct/helium/services/setup"
"github.com/ChristianMct/helium/session"
"github.com/ChristianMct/helium/transport/centralized"
"github.com/tuneinsight/lattigo/v4/bgv"
"github.com/tuneinsight/lattigo/v4/drlwe"
"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
drlwe "github.com/tuneinsight/lattigo/v5/mhe"
"github.com/tuneinsight/lattigo/v5/schemes/bgv"
)

var (
Expand All @@ -26,10 +26,10 @@ var (
ID: "example-session", // the id of the session must be unique
Nodes: []helium.NodeID{"node-1", "node-2", "node-3", "node-4"}, // the nodes that will participate in the session
RLWEParams: bgv.ParametersLiteral{ // the FHE parameters
T: 79873,
LogN: 14,
LogQ: []int{56, 55, 55, 54, 54, 54},
LogP: []int{55, 55},
PlaintextModulus: 79873,
LogN: 14,
LogQ: []int{56, 55, 55, 54, 54, 54},
LogP: []int{55, 55},
},
Threshold: 3, // the number of honest nodes assumed by the system.
ShamirPks: map[helium.NodeID]drlwe.ShamirPublicPoint{"node-1": 1, "node-2": 2, "node-3": 3, "node-4": 4}, // the shamir public-key of the nodes for the t-out-of-n-threshold scheme.
Expand Down Expand Up @@ -148,9 +148,9 @@ func main() {

// creates an InputProvider function from the node's private input
ip := func(ctx context.Context, _ helium.CircuitID, ol circuits.OperandLabel, sess session.Session) (any, error) {
in := make([]uint64, sess.Params.PlaintextSlots())
in := make([]uint64, sess.Params.MaxSlots())
for i := range in {
in[i] = input % sess.RLWEParams.T
in[i] = input % sess.RLWEParams.PlaintextModulus
}
return in, nil
}
Expand Down Expand Up @@ -179,6 +179,11 @@ func main() {
}
close(cdescs) // when no more circuits evaluation are required, the user closes the cdesc channel

params, err := n.GetParameters(ctx)
if err != nil {
log.Fatalf("%s | [main] error getting session parameters: %v\n", nodeID, err)
}

encoder, err := n.GetEncoder(ctx)
if err != nil {
log.Fatalf("%s | [main] error getting session encoder: %v\n", nodeID, err)
Expand All @@ -190,8 +195,8 @@ func main() {
n.Close()

if hasOut {
pt := &rlwe.Plaintext{Operand: out.Ciphertext.Operand, Value: out.Ciphertext.Value[0]}
res := make([]uint64, encoder.Parameters().PlaintextSlots())
pt := &rlwe.Plaintext{Element: out.Ciphertext.Element, Value: out.Ciphertext.Value[0]}
res := make([]uint64, params.MaxSlots())
encoder.Decode(pt, res)
fmt.Printf("%v\n", res)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/dgraph-io/badger/v4 v4.2.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
github.com/tuneinsight/lattigo/v4 v4.1.1-0.20230803090432-a075cdfe3249
github.com/tuneinsight/lattigo/v5 v5.0.2
golang.org/x/crypto v0.21.0
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f
golang.org/x/net v0.22.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tuneinsight/lattigo/v4 v4.1.1-0.20230803090432-a075cdfe3249 h1:m7vfkHH0a3spmSZmul8dGj3tjlavvo8X4l0bJexAEZU=
github.com/tuneinsight/lattigo/v4 v4.1.1-0.20230803090432-a075cdfe3249/go.mod h1:yae8oTneunVzIl//RaMlY/25N/JjefiTRf7bfzsyb8U=
github.com/tuneinsight/lattigo/v5 v5.0.2 h1:g+WmQK0G04nldAPnthgBFsfMtCJRLcfwME+cR9hLuIg=
github.com/tuneinsight/lattigo/v5 v5.0.2/go.mod h1:mmynIHGOeVRGYzuHRdZNbDLJWe8WHDYCgYkl9WZrHN0=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
Expand Down
2 changes: 1 addition & 1 deletion helium.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path"
"strings"

"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
)

// NodeID is the unique identifier of a node.
Expand Down
8 changes: 4 additions & 4 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"sync"

"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
)

// PublicKeyProvider is an interface for retrieving public keys.
Expand Down Expand Up @@ -148,15 +148,15 @@ func NewTestKeyBackend(params rlwe.Parameters, skIdeal *rlwe.SecretKey) *TestKey

// GetCollectivePublicKey returns the collective public key for the session in ctx.
func (tkb *TestKeyProvider) GetCollectivePublicKey(ctx context.Context) (*rlwe.PublicKey, error) {
return tkb.keygen.GenPublicKeyNew(tkb.skIdeal)
return tkb.keygen.GenPublicKeyNew(tkb.skIdeal), nil
}

// GetGaloisKey returns the galois key for the session in ctx and the given Galois element.
func (tkb *TestKeyProvider) GetGaloisKey(ctx context.Context, galEl uint64) (*rlwe.GaloisKey, error) {
return tkb.keygen.GenGaloisKeyNew(galEl, tkb.skIdeal)
return tkb.keygen.GenGaloisKeyNew(galEl, tkb.skIdeal), nil
}

// GetRelinearizationKey returns the relinearization key for the session in ctx.
func (tkb *TestKeyProvider) GetRelinearizationKey(ctx context.Context) (*rlwe.RelinearizationKey, error) {
return tkb.keygen.GenRelinearizationKeyNew(tkb.skIdeal)
return tkb.keygen.GenRelinearizationKeyNew(tkb.skIdeal), nil
}
4 changes: 2 additions & 2 deletions node/localtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/ChristianMct/helium"
"github.com/ChristianMct/helium/session"
"github.com/ChristianMct/helium/transport/centralized"
"github.com/tuneinsight/lattigo/v4/bgv"
"github.com/tuneinsight/lattigo/v4/drlwe"
drlwe "github.com/tuneinsight/lattigo/v5/mhe"
"github.com/tuneinsight/lattigo/v5/schemes/bgv"
"golang.org/x/net/context"
"google.golang.org/grpc/test/bufconn"
)
Expand Down
9 changes: 7 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/ChristianMct/helium/services/setup"
"github.com/ChristianMct/helium/session"
"github.com/ChristianMct/helium/transport/centralized"
"github.com/tuneinsight/lattigo/v4/bgv"
"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
"github.com/tuneinsight/lattigo/v5/schemes/bgv"
"golang.org/x/net/context"
)

Expand Down Expand Up @@ -541,6 +541,11 @@ func (node *Node) Unregister(peer helium.NodeID) error {

// FHEProvider interface implementation

// GetParameters returns the parameters from the context's session.
func (node *Node) GetParameters(ctx context.Context) (*bgv.Parameters, error) {
return node.compute.GetParameters(ctx)
}

// GetEncoder returns a lattigo encoder from the context's session.
func (node *Node) GetEncoder(ctx context.Context) (*bgv.Encoder, error) {
return node.compute.GetEncoder(ctx)
Expand Down
14 changes: 7 additions & 7 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/ChristianMct/helium/services/setup"
"github.com/ChristianMct/helium/session"
"github.com/stretchr/testify/require"
"github.com/tuneinsight/lattigo/v4/bgv"
"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
"github.com/tuneinsight/lattigo/v5/schemes/bgv"
"golang.org/x/net/context"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestNodeSetup(t *testing.T) {
t.Run(fmt.Sprintf("NParty=%d/T=%d/rec=%s/rep=%d", ts.N, ts.T, ts.Reciever, ts.Rep), func(t *testing.T) {

//params, err := bgv.NewParametersFromLiteral(bgv.ParametersLiteral{T: 79873, LogN: 13, LogQ: []int{54, 54, 54}, LogP: []int{55}}) // vecmul
params, err := bgv.NewParametersFromLiteral(bgv.ParametersLiteral{T: 79873, LogN: 12, LogQ: []int{45, 45}, LogP: []int{19}}) // matmul
params, err := bgv.NewParametersFromLiteral(bgv.ParametersLiteral{PlaintextModulus: 79873, LogN: 12, LogQ: []int{45, 45}, LogP: []int{19}}) // matmul
require.Nil(t, err)
sessParams := session.Parameters{
ID: "test-session",
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestNodeCompute(t *testing.T) {
t.Run(fmt.Sprintf("NParty=%d/T=%d/rec=%s/rep=%d", ts.N, ts.T, ts.Reciever, ts.Rep), func(t *testing.T) {

//params, err := bgv.NewParametersFromLiteral(bgv.ParametersLiteral{T: 79873, LogN: 13, LogQ: []int{54, 54, 54}, LogP: []int{55}}) // vecmul
params, err := bgv.NewParametersFromLiteral(bgv.ParametersLiteral{T: 79873, LogN: 12, LogQ: []int{45, 45}, LogP: []int{19}}) // matmul
params, err := bgv.NewParametersFromLiteral(bgv.ParametersLiteral{PlaintextModulus: 79873, LogN: 12, LogQ: []int{45, 45}, LogP: []int{19}}) // matmul
require.Nil(t, err)
sessParams := session.Parameters{
ID: "test-session",
Expand All @@ -185,7 +185,7 @@ func TestNodeCompute(t *testing.T) {
all, clients, cloud := NewTestNodes(lt)

for _, cli := range clients {
pt := rlwe.NewPlaintext(testSess.RlweParams, testSess.RlweParams.MaxLevel())
pt := bgv.NewPlaintext(testSess.RlweParams, testSess.RlweParams.MaxLevel())
testSess.Encoder.Encode(NodeIDtoTestInput(string(cli.id)), pt)
cli.InputProvider = func(ctx context.Context, _ helium.CircuitID, ol circuits.OperandLabel, _ session.Session) (any, error) {
return pt, nil
Expand Down Expand Up @@ -249,8 +249,8 @@ func TestNodeCompute(t *testing.T) {
out, has := rec.Outputs[cid]
require.True(t, has, "reciever should have an output")
delete(rec.Outputs, cid)
pt := &rlwe.Plaintext{Operand: out.Ciphertext.Operand, Value: out.Ciphertext.Value[0]}
res := make([]uint64, testSess.RlweParams.PlaintextSlots())
pt := &rlwe.Plaintext{Element: out.Ciphertext.Element, Value: out.Ciphertext.Value[0]}
res := make([]uint64, testSess.RlweParams.MaxSlots())
testSess.Encoder.Decode(pt, res)
//fmt.Println(out.OperandLabel, res[:10])
require.Equal(t, expRes, res[0])
Expand Down
6 changes: 3 additions & 3 deletions protocols/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"strconv"

"github.com/tuneinsight/lattigo/v4/drlwe"
"github.com/tuneinsight/lattigo/v4/ring"
"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
drlwe "github.com/tuneinsight/lattigo/v5/mhe"
"github.com/tuneinsight/lattigo/v5/ring"
)

// The types and function in this file are a wrapper around the lattigo library.
Expand Down
2 changes: 1 addition & 1 deletion protocols/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ChristianMct/helium/session"
"github.com/ChristianMct/helium/utils"
"github.com/stretchr/testify/require"
"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
"golang.org/x/sync/errgroup"
)

Expand Down
4 changes: 2 additions & 2 deletions protocols/protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/ChristianMct/helium"
"github.com/ChristianMct/helium/session"
"github.com/ChristianMct/helium/utils"
"github.com/tuneinsight/lattigo/v4/drlwe"
"github.com/tuneinsight/lattigo/v4/rlwe"
"github.com/tuneinsight/lattigo/v5/core/rlwe"
drlwe "github.com/tuneinsight/lattigo/v5/mhe"
"golang.org/x/crypto/blake2b"
)

Expand Down
Loading

0 comments on commit 3475db4

Please sign in to comment.