From 8868658f69b73b6f28682b781bb75f2e7cdbd42c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Bouy=C3=A9?= Date: Fri, 13 Oct 2023 00:14:52 +0200 Subject: [PATCH] Typo fixes on v5 pass --- CHANGELOG.md | 2 +- bfv/README.md | 10 +-- bfv/bfv.go | 2 +- bgv/README.md | 2 +- bgv/encoder.go | 2 +- circuits/blindrotation/evaluator.go | 56 +++++++-------- circuits/blindrotation/keys.go | 16 ++--- circuits/float/bootstrapper/bootstrapper.go | 4 +- .../float/bootstrapper/bootstrapper_test.go | 4 +- .../bootstrapping/bootstrapper.go | 4 +- .../bootstrapping/bootstrapping.go | 2 +- .../bootstrapper/bootstrapping/parameters.go | 14 ++-- .../bootstrapping/parameters_literal.go | 4 +- circuits/float/bootstrapper/keys.go | 6 +- circuits/float/bootstrapper/parameters.go | 4 +- circuits/float/comparisons.go | 6 +- circuits/float/dft.go | 6 +- circuits/float/float.go | 2 +- circuits/float/inverse.go | 6 +- .../float/minimax_composite_polynomial.go | 22 +++--- .../minimax_composite_polynomial_evaluator.go | 8 +-- circuits/float/polynomial_evaluator.go | 10 +-- .../float/polynomial_evaluator_simulator.go | 24 +++---- circuits/integer/integer.go | 2 +- circuits/integer/poly_eval_sim.go | 2 +- circuits/integer/polynomial_evaluator.go | 4 +- circuits/linear_transformation.go | 2 +- circuits/polynomial.go | 2 +- circuits/polynomial_evaluator.go | 4 +- circuits/power_basis.go | 4 +- ckks/evaluator.go | 17 ++--- ckks/params.go | 8 +-- drlwe/keygen_evk.go | 4 +- examples/bfv/main.go | 2 +- .../ckks/advanced/scheme_switching/main.go | 8 +-- examples/ckks/bootstrapping/basic/main.go | 8 +-- examples/ckks/ckks_tutorial/main.go | 10 +-- rgsw/elements.go | 2 +- rlwe/evaluator_evaluationkey.go | 2 +- rlwe/example_parameters.go | 2 +- rlwe/gadgetciphertext.go | 2 +- rlwe/inner_sum.go | 2 +- rlwe/operand.go | 2 +- rlwe/ringqp/poly.go | 2 +- rlwe/security.go | 4 +- utils/bignum/minimax_approximation.go | 70 +++++++++---------- utils/sampling/sampling.go | 2 +- utils/slices.go | 2 +- utils/structs/map.go | 2 +- utils/structs/matrix.go | 4 +- utils/structs/vector.go | 2 +- 51 files changed, 197 insertions(+), 196 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 731ea30a..e36d165b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,7 +89,7 @@ All notable changes to this library are documented in this file. - Changes to the `Parameters`: - Replaced the default parameters by a single example parameter. - - Renamed the field `LogScale` of the `ParametrsLiteralStruct` to `LogPlaintextScale`. + - Renamed the field `LogScale` of the `ParametersLiteralStruct` to `LogPlaintextScale`. - Changes to the tests: - Test do not use the default parameters anymore but specific and optimized test parameters. diff --git a/bfv/README.md b/bfv/README.md index ec27c076..7ab36666 100644 --- a/bfv/README.md +++ b/bfv/README.md @@ -6,19 +6,19 @@ The BFV package provides an RNS-accelerated implementation of the Fan-Vercautere ## Implementation Notes -The proposed implementation is not standard and is built as a wrapper over the `bgv` package, which implements a unified variant of the BFV and BGV schemes. The only practical difference with the textbook BFV is that the plaintext modulus must be coprime with the ciphertext modulus. This is both required for correctness ($T^{-1}\mod Q$) must be defined) and for security reasons (if $T|Q$ then the BGV scheme is not IND-CPA secure anymore). +The proposed implementation is built as a wrapper over the `bgv` package, which implements a unified variant of the BFV and BGV schemes. The only practical difference with the standard BFV is that the plaintext modulus must be coprime with the ciphertext modulus. This is both required for correctness ($T^{-1}\mod Q$ must be defined) and for security reasons (if $T|Q$ then the BGV scheme is not IND-CPA secure anymore). -For additional information, see the `README.md` in the `bgv` package. +For additional information, see the [`README.md`](../bgv/README.md) in the `bgv` package. ## Noise Growth -The only modification proposed in the implementation that could affect the noise is the multiplication, but in theory the noise should behave the same between the two impementations. +The only modification proposed in the implementation that could affect the noise is the multiplication, but in theory the noise should behave the same between the two implementations. The experiment that follows empirically verifies the above statement. We instantiated both version of the schemes `BFV_OLD` (textbook BFV) and `BFV_NEW` (wrapper of the generalized BGV) with the following parameters: -``` +```go ParametersLiteral{ LogN: 14, Q: []uint64{0x3fffffa8001, 0x1000090001, 0x10000c8001, 0x10000f0001, 0xffff00001}, @@ -35,4 +35,4 @@ BFV_OLD | 41.3617 | 26.7891 | 43.4034 BFV_NEW | 40.7618 | 26.2434 | 42.8023 ``` -We observe that `BFV_NEW` has on average `0.5` bit less noise, but this is due to a fix in the `ring` package were the `ModDown` operation (RNS division by `P`) changing the division from floored to rounded. +We observe that `BFV_NEW` has on average `0.5` bit less noise, but this is due to a fix in the `ring` package where the `ModDown` operation (RNS division by `P`) changing the division from floored to rounded. diff --git a/bfv/bfv.go b/bfv/bfv.go index c694da4f..23440fd6 100644 --- a/bfv/bfv.go +++ b/bfv/bfv.go @@ -27,7 +27,7 @@ func NewPlaintext(params Parameters, level ...int) (pt *rlwe.Plaintext) { } // NewCiphertext allocates a new rlwe.Ciphertext from the BFV parameters, -// at the specified level and ciphertex degree. If the level argument is not +// at the specified level and ciphertext degree. If the level argument is not // provided, the ciphertext is initialized at level params.MaxLevelQ(). // // To create a ciphertext for encrypting a new message, the ciphertext should be diff --git a/bgv/README.md b/bgv/README.md index 1950d4cc..2ef0bc6b 100644 --- a/bgv/README.md +++ b/bgv/README.md @@ -5,7 +5,7 @@ The BGV package provides a unified RNS-accelerated variant of the Fan-Vercautere ## Implementation Notes -The proposed implementation is not standard and provides all the functionalities of the BFV and BGV schemes under a unfied scheme. +The proposed implementation is not standard and provides all the functionalities of the BFV and BGV schemes under a unified scheme. This enabled by the equivalency between the LSB and MSB encoding when T is coprime to Q (Appendix A of ). ### Intuition diff --git a/bgv/encoder.go b/bgv/encoder.go index 564cd9f9..bcb145d1 100644 --- a/bgv/encoder.go +++ b/bgv/encoder.go @@ -114,7 +114,7 @@ func permuteMatrix(logN int) (perm []uint64) { return perm } -// GetRLWEParameters returns the underlying rlwe.Parametrs of the target object. +// GetRLWEParameters returns the underlying rlwe.Parameters of the target object. func (ecd Encoder) GetRLWEParameters() *rlwe.Parameters { return &ecd.parameters.Parameters } diff --git a/circuits/blindrotation/evaluator.go b/circuits/blindrotation/evaluator.go index 9f960945..83dc5d98 100644 --- a/circuits/blindrotation/evaluator.go +++ b/circuits/blindrotation/evaluator.go @@ -21,10 +21,10 @@ type Evaluator struct { accumulator *rlwe.Ciphertext - galoisGenDiscretLog map[uint64]int + galoisGenDiscreteLog map[uint64]int } -// NewEvaluator instaniates a new Evaluator. +// NewEvaluator instantiates a new Evaluator. func NewEvaluator(paramsBR, paramsLWE rlwe.Parameters) (eval *Evaluator) { eval = new(Evaluator) eval.Evaluator = rgsw.NewEvaluator(paramsBR, nil) @@ -35,9 +35,9 @@ func NewEvaluator(paramsBR, paramsLWE rlwe.Parameters) (eval *Evaluator) { eval.accumulator = rlwe.NewCiphertext(paramsBR, 1, paramsBR.MaxLevel()) eval.accumulator.IsNTT = true // This flag is always true - // Generates a map for the discret log of (+/- 1) * GaloisGen^k for 0 <= k < N-1. - // galoisGenDiscretLog: map[+/-G^{k} mod 2N] = k - eval.galoisGenDiscretLog = getGaloisElementInverseMap(ring.GaloisGen, paramsBR.N()) + // Generates a map for the discrete log of (+/- 1) * GaloisGen^k for 0 <= k < N-1. + // galoisGenDiscreteLog: map[+/-G^{k} mod 2N] = k + eval.galoisGenDiscreteLog = getGaloisElementInverseMap(ring.GaloisGen, paramsBR.N()) return } @@ -45,7 +45,7 @@ func NewEvaluator(paramsBR, paramsLWE rlwe.Parameters) (eval *Evaluator) { // EvaluateAndRepack extracts on the fly LWE samples, evaluates the provided blind rotations on the LWE and repacks everything into a single rlwe.Ciphertext. // testPolyWithSlotIndex : a map with [slot_index] -> blind rotation // repackIndex : a map with [slot_index_have] -> slot_index_want -func (eval *Evaluator) EvaluateAndRepack(ct *rlwe.Ciphertext, testPolyWithSlotIndex map[int]*ring.Poly, repackIndex map[int]int, key BlindRotatationEvaluationKeySet, repackKey rlwe.EvaluationKeySet) (res *rlwe.Ciphertext, err error) { +func (eval *Evaluator) EvaluateAndRepack(ct *rlwe.Ciphertext, testPolyWithSlotIndex map[int]*ring.Poly, repackIndex map[int]int, key BlindRotationEvaluationKeySet, repackKey rlwe.EvaluationKeySet) (res *rlwe.Ciphertext, err error) { cts, err := eval.Evaluate(ct, testPolyWithSlotIndex, key) if err != nil { @@ -66,7 +66,7 @@ func (eval *Evaluator) EvaluateAndRepack(ct *rlwe.Ciphertext, testPolyWithSlotIn // Evaluate extracts on the fly LWE samples and evaluates the provided blind rotation on the LWE. // testPolyWithSlotIndex : a map with [slot_index] -> blind rotation // Returns a map[slot_index] -> BlindRotate(ct[slot_index]) -func (eval *Evaluator) Evaluate(ct *rlwe.Ciphertext, testPolyWithSlotIndex map[int]*ring.Poly, key BlindRotatationEvaluationKeySet) (res map[int]*rlwe.Ciphertext, err error) { +func (eval *Evaluator) Evaluate(ct *rlwe.Ciphertext, testPolyWithSlotIndex map[int]*ring.Poly, key BlindRotationEvaluationKeySet) (res map[int]*rlwe.Ciphertext, err error) { evk, err := key.GetEvaluationKeySet() @@ -158,13 +158,13 @@ func (eval *Evaluator) Evaluate(ct *rlwe.Ciphertext, testPolyWithSlotIndex map[i } // BlindRotateCore implements Algorithm 3 of https://eprint.iacr.org/2022/198 -func (eval *Evaluator) BlindRotateCore(a []uint64, acc *rlwe.Ciphertext, evk BlindRotatationEvaluationKeySet) (err error) { +func (eval *Evaluator) BlindRotateCore(a []uint64, acc *rlwe.Ciphertext, evk BlindRotationEvaluationKeySet) (err error) { // GaloisElement(k) = GaloisGen^{k} mod 2N GaloisElement := eval.paramsBR.GaloisElement // Maps a[i] to (+/-) g^{k} mod 2N - discretLogSets := eval.getDiscretLogSets(a) + discreteLogSets := eval.getDiscreteLogSets(a) Nhalf := eval.paramsBR.N() >> 1 @@ -172,13 +172,13 @@ func (eval *Evaluator) BlindRotateCore(a []uint64, acc *rlwe.Ciphertext, evk Bli var v int // Lines 3 to 9 (negative set of a[i] = -g^{k} mod 2N) for i := Nhalf - 1; i > 0; i-- { - if v, err = eval.evaluateFromDiscretLogSets(GaloisElement, discretLogSets, -i, v, acc, evk); err != nil { + if v, err = eval.evaluateFromDiscreteLogSets(GaloisElement, discreteLogSets, -i, v, acc, evk); err != nil { return } } // Line 10 (0 in the negative set is 2N) - if _, err = eval.evaluateFromDiscretLogSets(GaloisElement, discretLogSets, eval.paramsBR.N()<<1, 0, acc, evk); err != nil { + if _, err = eval.evaluateFromDiscreteLogSets(GaloisElement, discreteLogSets, eval.paramsBR.N()<<1, 0, acc, evk); err != nil { return } @@ -190,23 +190,23 @@ func (eval *Evaluator) BlindRotateCore(a []uint64, acc *rlwe.Ciphertext, evk Bli // Lines 13 - 19 (positive set of a[i] = g^{k} mod 2N) for i := Nhalf - 1; i > 0; i-- { - if v, err = eval.evaluateFromDiscretLogSets(GaloisElement, discretLogSets, i, v, acc, evk); err != nil { + if v, err = eval.evaluateFromDiscreteLogSets(GaloisElement, discreteLogSets, i, v, acc, evk); err != nil { return } } // Lines 20 - 21 (0 in the positive set is 0) - if _, err = eval.evaluateFromDiscretLogSets(GaloisElement, discretLogSets, 0, 0, acc, evk); err != nil { + if _, err = eval.evaluateFromDiscreteLogSets(GaloisElement, discreteLogSets, 0, 0, acc, evk); err != nil { return } return } -// evaluateFromDiscretLogSets loops of Algorithm 3 of https://eprint.iacr.org/2022/198 -func (eval *Evaluator) evaluateFromDiscretLogSets(GaloisElement func(k int) (galEl uint64), sets map[int][]int, k, v int, acc *rlwe.Ciphertext, evk BlindRotatationEvaluationKeySet) (int, error) { +// evaluateFromDiscreteLogSets loops of Algorithm 3 of https://eprint.iacr.org/2022/198 +func (eval *Evaluator) evaluateFromDiscreteLogSets(GaloisElement func(k int) (galEl uint64), sets map[int][]int, k, v int, acc *rlwe.Ciphertext, evk BlindRotationEvaluationKeySet) (int, error) { - // Checks if k is in the discret log sets + // Checks if k is in the discrete log sets if set, ok := sets[k]; ok { // First condition of line 7 or 17 @@ -247,18 +247,18 @@ func (eval *Evaluator) evaluateFromDiscretLogSets(GaloisElement func(k int) (gal } // getGaloisElementInverseMap generates a map [(+/-) g^{k} mod 2N] = +/- k -func getGaloisElementInverseMap(GaloisGen uint64, N int) (GaloisGenDiscretLog map[uint64]int) { +func getGaloisElementInverseMap(GaloisGen uint64, N int) (GaloisGenDiscreteLog map[uint64]int) { twoN := N << 1 NHalf := N >> 1 mask := uint64(twoN - 1) - GaloisGenDiscretLog = map[uint64]int{} + GaloisGenDiscreteLog = map[uint64]int{} var pow uint64 = 1 for i := 0; i < NHalf; i++ { - GaloisGenDiscretLog[pow] = i - GaloisGenDiscretLog[uint64(twoN)-pow] = -i + GaloisGenDiscreteLog[pow] = i + GaloisGenDiscreteLog[uint64(twoN)-pow] = -i pow *= GaloisGen pow &= mask } @@ -266,21 +266,21 @@ func getGaloisElementInverseMap(GaloisGen uint64, N int) (GaloisGenDiscretLog ma return } -// getDiscretLogSets returns map[+/-k] = [i...] for a[0 <= i < N] = {(+/-) g^{k} mod 2N for +/- k} -func (eval *Evaluator) getDiscretLogSets(a []uint64) (discretLogSets map[int][]int) { +// getDiscreteLogSets returns map[+/-k] = [i...] for a[0 <= i < N] = {(+/-) g^{k} mod 2N for +/- k} +func (eval *Evaluator) getDiscreteLogSets(a []uint64) (discreteLogSets map[int][]int) { - GaloisGenDiscretLog := eval.galoisGenDiscretLog + GaloisGenDiscreteLog := eval.galoisGenDiscreteLog // Maps (2*N*a[i]/QLWE) to -N/2 < k <= N/2 for a[i] = (+/- 1) * g^{k} - discretLogSets = map[int][]int{} + discreteLogSets = map[int][]int{} for i, ai := range a { - dlog := GaloisGenDiscretLog[ai] + dlog := GaloisGenDiscreteLog[ai] - if _, ok := discretLogSets[dlog]; !ok { - discretLogSets[dlog] = []int{i} + if _, ok := discreteLogSets[dlog]; !ok { + discreteLogSets[dlog] = []int{i} } else { - discretLogSets[dlog] = append(discretLogSets[dlog], i) + discreteLogSets[dlog] = append(discreteLogSets[dlog], i) } } diff --git a/circuits/blindrotation/keys.go b/circuits/blindrotation/keys.go index 820336af..03dd0a6b 100644 --- a/circuits/blindrotation/keys.go +++ b/circuits/blindrotation/keys.go @@ -14,11 +14,11 @@ const ( windowSize = 10 ) -// BlindRotatationEvaluationKeySet is a interface implementing methods +// BlindRotationEvaluationKeySet is a interface implementing methods // to load the blind rotation keys (RGSW) and automorphism keys // (via the rlwe.EvaluationKeySet interface). // Implementation of this interface must be safe for concurrent use. -type BlindRotatationEvaluationKeySet interface { +type BlindRotationEvaluationKeySet interface { // GetBlindRotationKey should return RGSW(X^{s[i]}) GetBlindRotationKey(i int) (brk *rgsw.Ciphertext, err error) @@ -28,22 +28,22 @@ type BlindRotatationEvaluationKeySet interface { GetEvaluationKeySet() (evk rlwe.EvaluationKeySet, err error) } -// MemBlindRotatationEvaluationKeySet is a basic in-memory implementation of the BlindRotatationEvaluationKeySet interface. -type MemBlindRotatationEvaluationKeySet struct { +// MemBlindRotationEvaluationKeySet is a basic in-memory implementation of the BlindRotationEvaluationKeySet interface. +type MemBlindRotationEvaluationKeySet struct { BlindRotationKeys []*rgsw.Ciphertext AutomorphismKeys []*rlwe.GaloisKey } -func (evk MemBlindRotatationEvaluationKeySet) GetBlindRotationKey(i int) (*rgsw.Ciphertext, error) { +func (evk MemBlindRotationEvaluationKeySet) GetBlindRotationKey(i int) (*rgsw.Ciphertext, error) { return evk.BlindRotationKeys[i], nil } -func (evk MemBlindRotatationEvaluationKeySet) GetEvaluationKeySet() (rlwe.EvaluationKeySet, error) { +func (evk MemBlindRotationEvaluationKeySet) GetEvaluationKeySet() (rlwe.EvaluationKeySet, error) { return rlwe.NewMemEvaluationKeySet(nil, evk.AutomorphismKeys...), nil } // GenEvaluationKeyNew generates a new Blind Rotation evaluation key -func GenEvaluationKeyNew(paramsRLWE rlwe.Parameters, skRLWE *rlwe.SecretKey, paramsLWE rlwe.Parameters, skLWE *rlwe.SecretKey, evkParams ...rlwe.EvaluationKeyParameters) (key MemBlindRotatationEvaluationKeySet) { +func GenEvaluationKeyNew(paramsRLWE rlwe.Parameters, skRLWE *rlwe.SecretKey, paramsLWE rlwe.Parameters, skLWE *rlwe.SecretKey, evkParams ...rlwe.EvaluationKeyParameters) (key MemBlindRotationEvaluationKeySet) { skLWECopy := skLWE.CopyNew() paramsLWE.RingQ().AtLevel(0).INTT(skLWECopy.Value.Q, skLWECopy.Value.Q) @@ -99,5 +99,5 @@ func GenEvaluationKeyNew(paramsRLWE rlwe.Parameters, skRLWE *rlwe.SecretKey, par BaseTwoDecomposition: utils.Pointy(BaseTwoDecomposition), }) - return MemBlindRotatationEvaluationKeySet{BlindRotationKeys: skiRGSW, AutomorphismKeys: gks} + return MemBlindRotationEvaluationKeySet{BlindRotationKeys: skiRGSW, AutomorphismKeys: gks} } diff --git a/circuits/float/bootstrapper/bootstrapper.go b/circuits/float/bootstrapper/bootstrapper.go index 7c4b5123..52c4071d 100644 --- a/circuits/float/bootstrapper/bootstrapper.go +++ b/circuits/float/bootstrapper/bootstrapper.go @@ -81,7 +81,7 @@ func NewBootstrapper(btpParams Parameters, evk *BootstrappingKeys) (*Bootstrappe return b, nil } -// Depth returns the multiplicative depth (number of levels consummed) of the bootstrapping circuit. +// Depth returns the multiplicative depth (number of levels consumed) of the bootstrapping circuit. func (b Bootstrapper) Depth() int { return b.Parameters.Parameters.MaxLevel() - b.ResidualParameters.MaxLevel() } @@ -94,7 +94,7 @@ func (b Bootstrapper) OutputLevel() int { // MinimumInputLevel returns the minimum level at which a ciphertext must be to be // bootstrapped. func (b Bootstrapper) MinimumInputLevel() int { - return b.LevelsConsummedPerRescaling() + return b.LevelsConsumedPerRescaling() } // Bootstrap bootstraps a single ciphertext and returns the bootstrapped ciphertext. diff --git a/circuits/float/bootstrapper/bootstrapper_test.go b/circuits/float/bootstrapper/bootstrapper_test.go index 8da40a7f..c7b094e5 100644 --- a/circuits/float/bootstrapper/bootstrapper_test.go +++ b/circuits/float/bootstrapper/bootstrapper_test.go @@ -29,7 +29,7 @@ func TestBootstrapping(t *testing.T) { // Check that the bootstrapper complies to the rlwe.Bootstrapper interface var _ circuits.Bootstrapper[rlwe.Ciphertext] = (*Bootstrapper)(nil) - t.Run("BootstrapingWithoutRingDegreeSwitch", func(t *testing.T) { + t.Run("BootstrappingWithoutRingDegreeSwitch", func(t *testing.T) { schemeParamsLit := testPrec45 btpParamsLit := ParametersLiteral{} @@ -339,7 +339,7 @@ func TestBootstrapping(t *testing.T) { require.True(t, ctLeftQ0.Level() == 0) require.True(t, ctRightQ0.Level() == 0) - // Bootstrapps the ciphertext + // Bootstraps the ciphertext ctLeftQL, ctRightQL, err := bootstrapper.refreshConjugateInvariant(ctLeftQ0, ctRightQ0) require.NoError(t, err) diff --git a/circuits/float/bootstrapper/bootstrapping/bootstrapper.go b/circuits/float/bootstrapper/bootstrapping/bootstrapper.go index a4634524..16b3182d 100644 --- a/circuits/float/bootstrapper/bootstrapping/bootstrapper.go +++ b/circuits/float/bootstrapper/bootstrapping/bootstrapper.go @@ -46,7 +46,7 @@ type EvaluationKeySet struct { func NewBootstrapper(btpParams Parameters, btpKeys *EvaluationKeySet) (btp *Bootstrapper, err error) { if btpParams.Mod1ParametersLiteral.Mod1Type == float.SinContinuous && btpParams.Mod1ParametersLiteral.DoubleAngle != 0 { - return nil, fmt.Errorf("cannot use double angle formul for Mod1Type = Sin -> must use Mod1Type = Cos") + return nil, fmt.Errorf("cannot use double angle formula for Mod1Type = Sin -> must use Mod1Type = Cos") } if btpParams.Mod1ParametersLiteral.Mod1Type == float.CosDiscrete && btpParams.Mod1ParametersLiteral.SineDegree < 2*(btpParams.Mod1ParametersLiteral.K-1) { @@ -249,7 +249,7 @@ func newBootstrapperBase(params ckks.Parameters, btpParams Parameters, btpKey *E return } - encoder = nil + encoder = nil // For the GC return } diff --git a/circuits/float/bootstrapper/bootstrapping/bootstrapping.go b/circuits/float/bootstrapper/bootstrapping/bootstrapping.go index 89365f9b..1367c1e9 100644 --- a/circuits/float/bootstrapper/bootstrapping/bootstrapping.go +++ b/circuits/float/bootstrapper/bootstrapping/bootstrapping.go @@ -11,7 +11,7 @@ import ( ) func (btp Bootstrapper) MinimumInputLevel() int { - return btp.params.LevelsConsummedPerRescaling() + return btp.params.LevelsConsumedPerRescaling() } func (btp Bootstrapper) OutputLevel() int { diff --git a/circuits/float/bootstrapper/bootstrapping/parameters.go b/circuits/float/bootstrapper/bootstrapping/parameters.go index 1fdcb355..c4600d98 100644 --- a/circuits/float/bootstrapper/bootstrapping/parameters.go +++ b/circuits/float/bootstrapper/bootstrapping/parameters.go @@ -27,7 +27,7 @@ type Parameters struct { // a bootstrapping.ParametersLiteral struct. // // The residualParameters corresponds to the ckks.Parameters that are left after the bootstrapping circuit is evaluated. -// These are entirely independant of the bootstrapping parameters with one exception: the ciphertext primes Qi must be +// These are entirely independent of the bootstrapping parameters with one exception: the ciphertext primes Qi must be // congruent to 1 mod 2N of the bootstrapping parameters (note that the auxiliary primes Pi do not need to be). // This is required because the primes Qi of the residual parameters and the bootstrapping parameters are the same between // the two sets of parameters. @@ -44,7 +44,7 @@ func NewParametersFromLiteral(residualParameters ckks.Parameters, btpLit Paramet // Retrieve the LogN of the bootstrapping circuit LogN := btpLit.GetLogN() - // Retrive the NthRoot + // Retrieve the NthRoot var NthRoot uint64 switch residualParameters.RingType() { case ring.ConjugateInvariant: @@ -55,7 +55,7 @@ func NewParametersFromLiteral(residualParameters ckks.Parameters, btpLit Paramet return Parameters{}, fmt.Errorf("cannot NewParametersFromLiteral: LogN of bootstrapping parameters must be greater than LogN of residual parameters if ringtype is ConjugateInvariant") } - // Takes the greatest NthRoot between the residualParameters NthRoot and the bootstrapphg NthRoot + // Takes the greatest NthRoot between the residualParameters NthRoot and the bootstrapping NthRoot NthRoot = utils.Max(uint64(residualParameters.N()<<2), uint64(2< Y^slots rotations diff --git a/circuits/float/bootstrapper/bootstrapping/parameters_literal.go b/circuits/float/bootstrapper/bootstrapping/parameters_literal.go index d23929f6..6976c5b6 100644 --- a/circuits/float/bootstrapper/bootstrapping/parameters_literal.go +++ b/circuits/float/bootstrapper/bootstrapping/parameters_literal.go @@ -57,7 +57,7 @@ import ( // Be aware that doing so will impact the security, precision, and failure probability of the bootstrapping circuit. // See https://eprint.iacr.org/2022/024 for more information. // -// IterationsParamters : by treating the bootstrapping as a blackbox with precision logprec, we can construct a bootstrapping of precision ~k*logprec by iteration (see https://eprint.iacr.org/2022/1167). +// IterationsParameters : by treating the bootstrapping as a black box with precision logprec, we can construct a bootstrapping of precision ~k*logprec by iteration (see https://eprint.iacr.org/2022/1167). // - BootstrappingPrecision: []float64, the list of iterations (after the initial bootstrapping) given by the expected precision of each previous iteration. // - ReservedPrimeBitSize: the size of the reserved prime for the scaling after the initial bootstrapping. // @@ -320,7 +320,7 @@ func (p ParametersLiteral) GetEvalMod1LogScale() (EvalModLogScale int, err error return } -// GetIterationsParameters returns the IterationsParmaeters field of the target ParametersLiteral. +// GetIterationsParameters returns the IterationsParameters field of the target ParametersLiteral. // The default value is nil. func (p ParametersLiteral) GetIterationsParameters() (Iterations *IterationsParameters, err error) { diff --git a/circuits/float/bootstrapper/keys.go b/circuits/float/bootstrapper/keys.go index 12089b30..bad696b9 100644 --- a/circuits/float/bootstrapper/keys.go +++ b/circuits/float/bootstrapper/keys.go @@ -13,10 +13,10 @@ import ( // evaluation keys required by the bootstrapper. type BootstrappingKeys struct { // EvkN1ToN2 is an evaluation key to switch from the residual parameters' - // ring degree (N1) to the bootstrapping parameters' ring degre (N2) + // ring degree (N1) to the bootstrapping parameters' ring degree (N2) EvkN1ToN2 *rlwe.EvaluationKey // EvkN2ToN1 is an evaluation key to switch from the bootstrapping parameters' - // ring degre (N2) to the residual parameters' ring degree (N1) + // ring degree (N2) to the residual parameters' ring degree (N1) EvkN2ToN1 *rlwe.EvaluationKey // EvkRealToCmplx is an evaluation key to switch from the standard ring to the // conjugate invariant ring. @@ -24,7 +24,7 @@ type BootstrappingKeys struct { // EvkCmplxToReal is an evaluation key to switch from the conjugate invariant // ring to the standard ring. EvkCmplxToReal *rlwe.EvaluationKey - // EvkBootstrapping is a set of evaluation keys for the bootstraping circuit. + // EvkBootstrapping is a set of evaluation keys for the bootstrapping circuit. EvkBootstrapping *bootstrapping.EvaluationKeySet } diff --git a/circuits/float/bootstrapper/parameters.go b/circuits/float/bootstrapper/parameters.go index ce2f4e29..8223ff37 100644 --- a/circuits/float/bootstrapper/parameters.go +++ b/circuits/float/bootstrapper/parameters.go @@ -23,9 +23,9 @@ type Parameters struct { // The bootstrapping parameters use their own and independent cryptographic parameters (i.e. ckks.Parameters) // which are instantiated based on the option specified in `paramsBootstrapping` (and the default values of // bootstrapping.Parameters). -// It is user's responsibility to ensure that these scheme parameters meet the target security and to tweak them +// It is the user's responsibility to ensure that these scheme parameters meet the target security and to tweak them // if necessary. -// It is possible to access informations about these cryptographic parameters directly through the +// It is possible to access information about these cryptographic parameters directly through the // instantiated bootstrapper.Parameters struct which supports and API an identical to the ckks.Parameters. func NewParametersFromLiteral(paramsResidual ckks.Parameters, paramsBootstrapping ParametersLiteral) (Parameters, error) { params, err := bootstrapping.NewParametersFromLiteral(paramsResidual, bootstrapping.ParametersLiteral(paramsBootstrapping)) diff --git a/circuits/float/comparisons.go b/circuits/float/comparisons.go index 95f89416..a9adb65e 100644 --- a/circuits/float/comparisons.go +++ b/circuits/float/comparisons.go @@ -147,7 +147,7 @@ func (eval ComparisonEvaluator) stepdiff(op0, op1 *rlwe.Ciphertext) (stepdiff *r } // Required for the scale matching before the last multiplication. - if diff.Level() < params.LevelsConsummedPerRescaling()*2 { + if diff.Level() < params.LevelsConsumedPerRescaling()*2 { if diff, err = eval.Bootstrap(diff); err != nil { return } @@ -160,7 +160,7 @@ func (eval ComparisonEvaluator) stepdiff(op0, op1 *rlwe.Ciphertext) (stepdiff *r } // Required for the following multiplication - if step.Level() < params.LevelsConsummedPerRescaling() { + if step.Level() < params.LevelsConsumedPerRescaling() { if step, err = eval.Bootstrap(step); err != nil { return } @@ -170,7 +170,7 @@ func (eval ComparisonEvaluator) stepdiff(op0, op1 *rlwe.Ciphertext) (stepdiff *r level := utils.Min(diff.Level(), step.Level()) ratio := rlwe.NewScale(1) - for i := 0; i < params.LevelsConsummedPerRescaling(); i++ { + for i := 0; i < params.LevelsConsumedPerRescaling(); i++ { ratio = ratio.Mul(rlwe.NewScale(params.Q()[level-i])) } diff --git a/circuits/float/dft.go b/circuits/float/dft.go index ae3c3c65..e5d36876 100644 --- a/circuits/float/dft.go +++ b/circuits/float/dft.go @@ -154,7 +154,7 @@ func NewDFTMatrixFromLiteral(params ckks.Parameters, d DFTMatrixLiteral, encoder matrices := []LinearTransformation{} pVecDFT := d.GenMatrices(params.LogN(), params.EncodingPrecision()) - nbModuliPerRescale := params.LevelsConsummedPerRescaling() + nbModuliPerRescale := params.LevelsConsumedPerRescaling() level := d.LevelStart var idx int @@ -622,7 +622,7 @@ func nextLevelfftIndexMap(vec map[int]bool, logL, N, nextLevel int, ltType DFTTy return } -// GenMatrices returns the ordered list of factors of the non-zero diagonales of the IDFT (encoding) or DFT (decoding) matrix. +// GenMatrices returns the ordered list of factors of the non-zero diagonals of the IDFT (encoding) or DFT (decoding) matrix. func (d DFTMatrixLiteral) GenMatrices(LogN int, prec uint) (plainVector []Diagonals[*bignum.Complex]) { logSlots := d.LogSlots @@ -736,7 +736,7 @@ func (d DFTMatrixLiteral) GenMatrices(LogN int, prec uint) (plainVector []Diagon } } - // Spreads the scale accross the matrices + // Spreads the scale across the matrices scaling = bignum.Pow(scaling, new(big.Float).Quo(new(big.Float).SetPrec(prec).SetFloat64(1), new(big.Float).SetPrec(prec).SetFloat64(float64(d.Depth(false))))) for j := range plainVector { diff --git a/circuits/float/float.go b/circuits/float/float.go index 6d327a9e..e0c39778 100644 --- a/circuits/float/float.go +++ b/circuits/float/float.go @@ -1,4 +1,4 @@ -// Package float implements advanced homomorphic circuit for encrypted arithmetic over floating point numbers. +// Package float implements advanced homomorphic circuits for encrypted arithmetic over floating point numbers. package float import ( diff --git a/circuits/float/inverse.go b/circuits/float/inverse.go index 9d2a286e..f5c45f28 100644 --- a/circuits/float/inverse.go +++ b/circuits/float/inverse.go @@ -99,7 +99,7 @@ func (eval InverseEvaluator) evaluateNew(ct *rlwe.Ciphertext, log2min, log2max f params := eval.Parameters - levelsPerRescaling := params.LevelsConsummedPerRescaling() + levelsPerRescaling := params.LevelsConsumedPerRescaling() btp := eval.Bootstrapper @@ -237,7 +237,7 @@ func (eval InverseEvaluator) GoldschmidtDivisionNew(ct *rlwe.Ciphertext, log2min // This minimum is set in the case where log2min is close to 0. iters = utils.Max(iters, 3) - levelsPerRescaling := params.LevelsConsummedPerRescaling() + levelsPerRescaling := params.LevelsConsumedPerRescaling() if depth := iters * levelsPerRescaling; btp == nil && depth > ct.Level() { return nil, fmt.Errorf("cannot GoldschmidtDivisionNew: ct.Level()=%d < depth=%d and rlwe.Bootstrapper is nil", ct.Level(), depth) @@ -324,7 +324,7 @@ func (eval InverseEvaluator) IntervalNormalization(ct *rlwe.Ciphertext, log2Max ctNorm = ct.CopyNew() - levelsPerRescaling := eval.Parameters.LevelsConsummedPerRescaling() + levelsPerRescaling := eval.Parameters.LevelsConsumedPerRescaling() L := 2.45 // Compression factor (experimental) diff --git a/circuits/float/minimax_composite_polynomial.go b/circuits/float/minimax_composite_polynomial.go index 9089559d..2d91c95d 100644 --- a/circuits/float/minimax_composite_polynomial.go +++ b/circuits/float/minimax_composite_polynomial.go @@ -56,7 +56,7 @@ func (mcp MinimaxCompositePolynomial) Evaluate(x interface{}) (y *bignum.Complex // CoeffsSignX2Cheby (from https://eprint.iacr.org/2019/1234.pdf) are the coefficients // of 1.5*x - 0.5*x^3 in Chebyshev basis. // Evaluating this polynomial on values already close to -1, or 1 ~doubles the number of -// of correct digigts. +// of correct digits. // For example, if x = -0.9993209 then p(x) = -0.999999308 // This polynomial can be composed after the minimax composite polynomial to double the // output precision (up to the scheme precision) each time it is evaluated. @@ -65,20 +65,20 @@ var CoeffsSignX2Cheby = []string{"0", "1.125", "0", "-0.125"} // CoeffsSignX4Cheby (from https://eprint.iacr.org/2019/1234.pdf) are the coefficients // of 35/16 * x - 35/16 * x^3 + 21/16 * x^5 - 5/16 * x^7 in Chebyshev basis. // Evaluating this polynomial on values already close to -1, or 1 ~quadruples the number of -// of correct digigts. +// of correct digits. // For example, if x = -0.9993209 then p(x) = -0.9999999999990705 // This polynomial can be composed after the minimax composite polynomial to quadruple the // output precision (up to the scheme precision) each time it is evaluated. var CoeffsSignX4Cheby = []string{"0", "1.1962890625", "0", "-0.2392578125", "0", "0.0478515625", "0", "-0.0048828125"} // GenMinimaxCompositePolynomialForSign generates the minimax composite polynomial -// P(x) = pk(x) o pk-1(x) o ... o p1(x) o p0(x) of the sign function in ther interval +// P(x) = pk(x) o pk-1(x) o ... o p1(x) o p0(x) of the sign function in their interval // [min-err, -2^{-alpha}] U [2^{-alpha}, max+err] where alpha is the desired distinguishing // precision between two values and err an upperbound on the scheme error. // // The sign function is defined as: -1 if -1 <= x < 0, 0 if x = 0, 1 if 0 < x <= 1. // -// See GenMinimaxCompositePolynomial for informations about how to instantiate and +// See GenMinimaxCompositePolynomial for information about how to instantiate and // parameterize each input value of the algorithm. func GenMinimaxCompositePolynomialForSign(prec uint, logalpha, logerr int, deg []int) { @@ -96,14 +96,14 @@ func GenMinimaxCompositePolynomialForSign(prec uint, logalpha, logerr int, deg [ // GenMinimaxCompositePolynomial generates the minimax composite polynomial // P(x) = pk(x) o pk-1(x) o ... o p1(x) o p0(x) for the provided function in the interval -// in ther interval [min-err, -2^{-alpha}] U [2^{-alpha}, max+err] where alpha is +// in their interval [min-err, -2^{-alpha}] U [2^{-alpha}, max+err] where alpha is // the desired distinguishing precision between two values and err an upperbound on // the scheme error. // // The user must provide the following inputs: // - prec: the bit precision of the big.Float values used by the algorithm to compute the polynomials. // This will impact the speed of the algorithm. -// A too low precision canprevent convergence or induce a slope zero during the zero finding. +// A too low precision can prevent convergence or induce a slope zero during the zero finding. // A sign that the precision is too low is when the iteration continue without the error getting smaller. // - logalpha: log2(alpha) // - logerr: log2(err), the upperbound on the scheme precision. Usually this value should be smaller or equal to logalpha. @@ -111,8 +111,8 @@ func GenMinimaxCompositePolynomialForSign(prec uint, logalpha, logerr int, deg [ // (i.e. smaller than -1-e or greater than 1+e), then the values will explode during the evaluation. // Note that it is not required to apply change of interval [-1, 1] -> [-1-e, 1+e] because the function to evaluate // is the sign (i.e. it will evaluate to the same value). -// - deg: the degree of each polynomial, orderd as follow [deg(p0(x)), deg(p1(x)), ..., deg(pk(x))]. -// It is highly recommanded that deg(p0) <= deg(p1) <= ... <= deg(pk) for optimal approximation. +// - deg: the degree of each polynomial, ordered as follow [deg(p0(x)), deg(p1(x)), ..., deg(pk(x))]. +// It is highly recommended that deg(p0) <= deg(p1) <= ... <= deg(pk) for optimal approximation. // // The polynomials are returned in the Chebyshev basis and pre-scaled for // the interval [-1, 1] (no further scaling is required on the ciphertext). @@ -125,7 +125,7 @@ func GenMinimaxCompositePolynomialForSign(prec uint, logalpha, logerr int, deg [ func GenMinimaxCompositePolynomial(prec uint, logalpha, logerr int, deg []int, f func(*big.Float) *big.Float) (coeffs [][]*big.Float) { decimals := int(float64(logalpha)/math.Log2(10)+0.5) + 10 - // Precision of the output value of the sign polynmial + // Precision of the output value of the sign polynomial alpha := math.Exp2(-float64(logalpha)) // Expected upperbound scheme error @@ -233,9 +233,9 @@ func GenMinimaxCompositePolynomial(prec uint, logalpha, logerr int, deg []int, f return coeffs } -// PrettyPrintCoefficients prints the coefficients formated. +// PrettyPrintCoefficients prints the coefficients formatted. // If odd = true, even coefficients are zeroed. -// If even = true, odd coefficnets are zeroed. +// If even = true, odd coefficients are zeroed. func PrettyPrintCoefficients(decimals int, coeffs []*big.Float, odd, even, first bool) { fmt.Printf("{") for i, c := range coeffs { diff --git a/circuits/float/minimax_composite_polynomial_evaluator.go b/circuits/float/minimax_composite_polynomial_evaluator.go index f4331861..674f9d76 100644 --- a/circuits/float/minimax_composite_polynomial_evaluator.go +++ b/circuits/float/minimax_composite_polynomial_evaluator.go @@ -38,10 +38,10 @@ func (eval MinimaxCompositePolynomialEvaluator) Evaluate(ct *rlwe.Ciphertext, mc btp := eval.Bootstrapper - levelsConsummedPerRescaling := params.LevelsConsummedPerRescaling() + levelsConsumedPerRescaling := params.LevelsConsumedPerRescaling() // Checks that the number of levels available after the bootstrapping is enough to evaluate all polynomials - if maxDepth := mcp.MaxDepth() * levelsConsummedPerRescaling; params.MaxLevel() < maxDepth+btp.MinimumInputLevel() { + if maxDepth := mcp.MaxDepth() * levelsConsumedPerRescaling; params.MaxLevel() < maxDepth+btp.MinimumInputLevel() { return nil, fmt.Errorf("parameters do not enable the evaluation of the minimax composite polynomial, required levels is %d but parameters only provide %d levels", maxDepth+btp.MinimumInputLevel(), params.MaxLevel()) } @@ -50,7 +50,7 @@ func (eval MinimaxCompositePolynomialEvaluator) Evaluate(ct *rlwe.Ciphertext, mc for _, poly := range mcp { // Checks that res has enough level to evaluate the next polynomial, else bootstrap - if res.Level() < poly.Depth()*params.LevelsConsummedPerRescaling()+btp.MinimumInputLevel() { + if res.Level() < poly.Depth()*params.LevelsConsumedPerRescaling()+btp.MinimumInputLevel() { if res, err = btp.Bootstrap(res); err != nil { return } @@ -88,7 +88,7 @@ func (eval MinimaxCompositePolynomialEvaluator) Evaluate(ct *rlwe.Ciphertext, mc } } - // Avoides float errors + // Avoids float errors res.Scale = ct.Scale return diff --git a/circuits/float/polynomial_evaluator.go b/circuits/float/polynomial_evaluator.go index 72d904c0..94129c9c 100644 --- a/circuits/float/polynomial_evaluator.go +++ b/circuits/float/polynomial_evaluator.go @@ -54,14 +54,14 @@ func (eval PolynomialEvaluator) Evaluate(ct *rlwe.Ciphertext, p interface{}, tar pcircuits = p } - levelsConsummedPerRescaling := eval.Parameters.LevelsConsummedPerRescaling() + levelsConsumedPerRescaling := eval.Parameters.LevelsConsumedPerRescaling() - return circuits.EvaluatePolynomial(eval, ct, pcircuits, targetScale, levelsConsummedPerRescaling, &simEvaluator{eval.Parameters, levelsConsummedPerRescaling}) + return circuits.EvaluatePolynomial(eval, ct, pcircuits, targetScale, levelsConsumedPerRescaling, &simEvaluator{eval.Parameters, levelsConsumedPerRescaling}) } // EvaluateFromPowerBasis evaluates a polynomial using the provided PowerBasis, holding pre-computed powers of X. // This method is the same as Evaluate except that the encrypted input is a PowerBasis. -// See Evaluate for additional informations. +// See Evaluate for additional information. func (eval PolynomialEvaluator) EvaluateFromPowerBasis(pb circuits.PowerBasis, p interface{}, targetScale rlwe.Scale) (opOut *rlwe.Ciphertext, err error) { var pcircuits interface{} @@ -74,13 +74,13 @@ func (eval PolynomialEvaluator) EvaluateFromPowerBasis(pb circuits.PowerBasis, p pcircuits = p } - levelsConsummedPerRescaling := eval.Parameters.LevelsConsummedPerRescaling() + levelsConsumedPerRescaling := eval.Parameters.LevelsConsumedPerRescaling() if _, ok := pb.Value[1]; !ok { return nil, fmt.Errorf("cannot EvaluateFromPowerBasis: X^{1} is nil") } - return circuits.EvaluatePolynomial(eval, pb, pcircuits, targetScale, levelsConsummedPerRescaling, &simEvaluator{eval.Parameters, levelsConsummedPerRescaling}) + return circuits.EvaluatePolynomial(eval, pb, pcircuits, targetScale, levelsConsumedPerRescaling, &simEvaluator{eval.Parameters, levelsConsumedPerRescaling}) } type CoefficientGetter struct { diff --git a/circuits/float/polynomial_evaluator_simulator.go b/circuits/float/polynomial_evaluator_simulator.go index 87b7d0e8..13b8cc43 100644 --- a/circuits/float/polynomial_evaluator_simulator.go +++ b/circuits/float/polynomial_evaluator_simulator.go @@ -12,23 +12,23 @@ import ( ) type simEvaluator struct { - params ckks.Parameters - levelsConsummedPerRescaling int + params ckks.Parameters + levelsConsumedPerRescaling int } func (d simEvaluator) PolynomialDepth(degree int) int { - return d.levelsConsummedPerRescaling * (bits.Len64(uint64(degree)) - 1) + return d.levelsConsumedPerRescaling * (bits.Len64(uint64(degree)) - 1) } // Rescale rescales the target circuits.SimOperand n times and returns it. func (d simEvaluator) Rescale(op0 *circuits.SimOperand) { - for i := 0; i < d.levelsConsummedPerRescaling; i++ { + for i := 0; i < d.levelsConsumedPerRescaling; i++ { op0.Scale = op0.Scale.Div(rlwe.NewScale(d.params.Q()[op0.Level])) op0.Level-- } } -// Mul multiplies two circuits.SimOperand, stores the result the taret circuits.SimOperand and returns the result. +// Mul multiplies two circuits.SimOperand, stores the result the target circuits.SimOperand and returns the result. func (d simEvaluator) MulNew(op0, op1 *circuits.SimOperand) (opOut *circuits.SimOperand) { opOut = new(circuits.SimOperand) opOut.Level = utils.Min(op0.Level, op1.Level) @@ -42,7 +42,7 @@ func (d simEvaluator) UpdateLevelAndScaleBabyStep(lead bool, tLevelOld int, tSca tScaleNew = tScaleOld if lead { - for i := 0; i < d.levelsConsummedPerRescaling; i++ { + for i := 0; i < d.levelsConsumedPerRescaling; i++ { tScaleNew = tScaleNew.Mul(rlwe.NewScale(d.params.Q()[tLevelNew-i])) } } @@ -57,17 +57,17 @@ func (d simEvaluator) UpdateLevelAndScaleGiantStep(lead bool, tLevelOld int, tSc var qi *big.Int if lead { qi = bignum.NewInt(Q[tLevelOld]) - for i := 1; i < d.levelsConsummedPerRescaling; i++ { + for i := 1; i < d.levelsConsumedPerRescaling; i++ { qi.Mul(qi, bignum.NewInt(Q[tLevelOld-i])) } } else { - qi = bignum.NewInt(Q[tLevelOld+d.levelsConsummedPerRescaling]) - for i := 1; i < d.levelsConsummedPerRescaling; i++ { - qi.Mul(qi, bignum.NewInt(Q[tLevelOld+d.levelsConsummedPerRescaling-i])) + qi = bignum.NewInt(Q[tLevelOld+d.levelsConsumedPerRescaling]) + for i := 1; i < d.levelsConsumedPerRescaling; i++ { + qi.Mul(qi, bignum.NewInt(Q[tLevelOld+d.levelsConsumedPerRescaling-i])) } } - tLevelNew = tLevelOld + d.levelsConsummedPerRescaling + tLevelNew = tLevelOld + d.levelsConsumedPerRescaling tScaleNew = tScaleOld.Mul(rlwe.NewScale(qi)) tScaleNew = tScaleNew.Div(xPowScale) @@ -75,5 +75,5 @@ func (d simEvaluator) UpdateLevelAndScaleGiantStep(lead bool, tLevelOld int, tSc } func (d simEvaluator) GetPolynmialDepth(degree int) int { - return d.levelsConsummedPerRescaling * (bits.Len64(uint64(degree)) - 1) + return d.levelsConsumedPerRescaling * (bits.Len64(uint64(degree)) - 1) } diff --git a/circuits/integer/integer.go b/circuits/integer/integer.go index 7b7eb7fa..049fe0cf 100644 --- a/circuits/integer/integer.go +++ b/circuits/integer/integer.go @@ -1,4 +1,4 @@ -// Package integer implements advanced homomorphic circuit for encrypted arithmetic modular arithmetic with integers. +// Package integer implements advanced homomorphic circuits for encrypted arithmetic modular arithmetic with integers. package integer import ( diff --git a/circuits/integer/poly_eval_sim.go b/circuits/integer/poly_eval_sim.go index ff1eabdb..ba9ace19 100644 --- a/circuits/integer/poly_eval_sim.go +++ b/circuits/integer/poly_eval_sim.go @@ -30,7 +30,7 @@ func (d simIntegerPolynomialEvaluator) Rescale(op0 *circuits.SimOperand) { } } -// Mul multiplies two circuits.SimOperand, stores the result the taret circuits.SimOperand and returns the result. +// Mul multiplies two circuits.SimOperand, stores the result the target circuits.SimOperand and returns the result. func (d simIntegerPolynomialEvaluator) MulNew(op0, op1 *circuits.SimOperand) (opOut *circuits.SimOperand) { opOut = new(circuits.SimOperand) opOut.Level = utils.Min(op0.Level, op1.Level) diff --git a/circuits/integer/polynomial_evaluator.go b/circuits/integer/polynomial_evaluator.go index 1ae58d65..8b5f818b 100644 --- a/circuits/integer/polynomial_evaluator.go +++ b/circuits/integer/polynomial_evaluator.go @@ -28,7 +28,7 @@ func NewPowerBasis(ct *rlwe.Ciphertext) circuits.PowerBasis { // NewPolynomialEvaluator instantiates a new PolynomialEvaluator from a circuit.Evaluator. // The default *bgv.Evaluator is compliant to the circuit.Evaluator interface. -// InvariantTensoring is a boolean that specifies if the evaluator performes the invariant tensoring (BFV-style) or +// InvariantTensoring is a boolean that specifies if the evaluator performed the invariant tensoring (BFV-style) or // the regular tensoring (BGB-style). func NewPolynomialEvaluator(params bgv.Parameters, eval circuits.Evaluator, InvariantTensoring bool) *PolynomialEvaluator { @@ -83,7 +83,7 @@ func (eval PolynomialEvaluator) Evaluate(ct *rlwe.Ciphertext, p interface{}, tar // EvaluateFromPowerBasis evaluates a polynomial using the provided PowerBasis, holding pre-computed powers of X. // This method is the same as Evaluate except that the encrypted input is a PowerBasis. -// See Evaluate for additional informations. +// See Evaluate for additional information. func (eval PolynomialEvaluator) EvaluateFromPowerBasis(pb circuits.PowerBasis, p interface{}, targetScale rlwe.Scale) (opOut *rlwe.Ciphertext, err error) { var pcircuits interface{} diff --git a/circuits/linear_transformation.go b/circuits/linear_transformation.go index a672ce04..e65a00ab 100644 --- a/circuits/linear_transformation.go +++ b/circuits/linear_transformation.go @@ -135,7 +135,7 @@ func (lt LinearTransformation) BSGSIndex() (index map[int][]int, n1, n2 []int) { return BSGSIndex(utils.GetKeys(lt.Vec), 1< cannot evaluate poly", level, depth) } diff --git a/circuits/power_basis.go b/circuits/power_basis.go index c2b79fa2..fbf4213f 100644 --- a/circuits/power_basis.go +++ b/circuits/power_basis.go @@ -19,7 +19,7 @@ type PowerBasis struct { } // NewPowerBasis creates a new PowerBasis. It takes as input a ciphertext -// and a basistype. The struct treats the input ciphertext as a monomial X and +// and a basis type. The struct treats the input ciphertext as a monomial X and // can be used to generates power of this monomial X^{n} in the given BasisType. func NewPowerBasis(ct *rlwe.Ciphertext, basis bignum.Basis) (p PowerBasis) { return PowerBasis{ @@ -28,7 +28,7 @@ func NewPowerBasis(ct *rlwe.Ciphertext, basis bignum.Basis) (p PowerBasis) { } } -// SplitDegree returns a * b = n such that |a-b| is minmized +// SplitDegree returns a * b = n such that |a-b| is minimized // with a and/or b odd if possible. func SplitDegree(n int) (a, b int) { diff --git a/ckks/evaluator.go b/ckks/evaluator.go index ddb6bf86..f0413a80 100644 --- a/ckks/evaluator.go +++ b/ckks/evaluator.go @@ -474,10 +474,11 @@ func (eval Evaluator) DropLevel(op0 *rlwe.Ciphertext, levels int) { } // Rescale divides op0 by the last prime of the moduli chain and repeats this procedure -// params.LevelsConsummedPerRescaling() times. +// params.LevelsConsumedPerRescaling() times. +// // Returns an error if: -// - Either op0 or opOut MetaData are nil -// - The level of op0 is too low to enable a rescale +// - Either op0 or opOut MetaData are nil +// - The level of op0 is too low to enable a rescale func (eval Evaluator) Rescale(op0, opOut *rlwe.Ciphertext) (err error) { if op0.MetaData == nil || opOut.MetaData == nil { @@ -486,7 +487,7 @@ func (eval Evaluator) Rescale(op0, opOut *rlwe.Ciphertext) (err error) { params := eval.GetParameters() - nbRescales := params.LevelsConsummedPerRescaling() + nbRescales := params.LevelsConsumedPerRescaling() if op0.Level() <= nbRescales-1 { return fmt.Errorf("cannot Rescale: input Ciphertext level is too low") @@ -647,7 +648,7 @@ func (eval Evaluator) Mul(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ci // If DefaultScalingFactor > 2^60, then multiple moduli are used per single rescale // thus continues multiplying the scale with the appropriate number of moduli - for i := 1; i < eval.GetParameters().LevelsConsummedPerRescaling(); i++ { + for i := 1; i < eval.GetParameters().LevelsConsumedPerRescaling(); i++ { scale = scale.Mul(rlwe.NewScale(ringQ.SubRings[level-i].Modulus)) } } @@ -686,7 +687,7 @@ func (eval Evaluator) Mul(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut *rlwe.Ci // If DefaultScalingFactor > 2^60, then multiple moduli are used per single rescale // thus continues multiplying the scale with the appropriate number of moduli - for i := 1; i < eval.GetParameters().LevelsConsummedPerRescaling(); i++ { + for i := 1; i < eval.GetParameters().LevelsConsumedPerRescaling(); i++ { pt.Scale = pt.Scale.Mul(rlwe.NewScale(ringQ.SubRings[level-i].Modulus)) } @@ -939,7 +940,7 @@ func (eval Evaluator) MulThenAdd(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut * } else { scaleRLWE = rlwe.NewScale(ringQ.SubRings[level].Modulus) - for i := 1; i < eval.GetParameters().LevelsConsummedPerRescaling(); i++ { + for i := 1; i < eval.GetParameters().LevelsConsumedPerRescaling(); i++ { scaleRLWE = scaleRLWE.Mul(rlwe.NewScale(ringQ.SubRings[level-i].Modulus)) } @@ -979,7 +980,7 @@ func (eval Evaluator) MulThenAdd(op0 *rlwe.Ciphertext, op1 rlwe.Operand, opOut * scaleRLWE = rlwe.NewScale(ringQ.SubRings[level].Modulus) - for i := 1; i < eval.GetParameters().LevelsConsummedPerRescaling(); i++ { + for i := 1; i < eval.GetParameters().LevelsConsumedPerRescaling(); i++ { scaleRLWE = scaleRLWE.Mul(rlwe.NewScale(ringQ.SubRings[level-i].Modulus)) } diff --git a/ckks/params.go b/ckks/params.go index c4be98bb..efda52c3 100644 --- a/ckks/params.go +++ b/ckks/params.go @@ -205,10 +205,10 @@ func (p Parameters) PrecisionMode() PrecisionMode { return p.precisionMode } -// LevelsConsummedPerRescaling returns the number of levels (i.e. primes) +// LevelsConsumedPerRescaling returns the number of levels (i.e. primes) // consumed per rescaling. This value is 1 if the precision mode is PREC64 // and is 2 if the precision mode is PREC128. -func (p Parameters) LevelsConsummedPerRescaling() int { +func (p Parameters) LevelsConsumedPerRescaling() int { switch p.precisionMode { case PREC128: return 2 @@ -218,9 +218,9 @@ func (p Parameters) LevelsConsummedPerRescaling() int { } // MaxDepth returns the maximum depth enabled by the parameters, -// which is obtained as p.MaxLevel() / p.LevelsConsummedPerRescaling(). +// which is obtained as p.MaxLevel() / p.LevelsConsumedPerRescaling(). func (p Parameters) MaxDepth() int { - return p.MaxLevel() / p.LevelsConsummedPerRescaling() + return p.MaxLevel() / p.LevelsConsumedPerRescaling() } // LogQLvl returns the size of the modulus Q in bits at a specific level diff --git a/drlwe/keygen_evk.go b/drlwe/keygen_evk.go index ee944c81..89f15ed3 100644 --- a/drlwe/keygen_evk.go +++ b/drlwe/keygen_evk.go @@ -117,11 +117,11 @@ func (evkg EvaluationKeyGenProtocol) GenShare(skIn, skOut *rlwe.SecretKey, crp E } if shareOut.BaseRNSDecompositionVectorSize() != crp.BaseRNSDecompositionVectorSize() { - return fmt.Errorf("cannot GenSahre: crp.BaseRNSDecompositionVectorSize() != shareOut.BaseRNSDecompositionVectorSize()") + return fmt.Errorf("cannot GenShare: crp.BaseRNSDecompositionVectorSize() != shareOut.BaseRNSDecompositionVectorSize()") } if !utils.EqualSlice(shareOut.BaseTwoDecompositionVectorSize(), crp.BaseTwoDecompositionVectorSize()) { - return fmt.Errorf("cannot GenSahre: crp.BaseTwoDecompositionVectorSize() != shareOut.BaseTwoDecompositionVectorSize()") + return fmt.Errorf("cannot GenShare: crp.BaseTwoDecompositionVectorSize() != shareOut.BaseTwoDecompositionVectorSize()") } ringQP := evkg.params.RingQP().AtLevel(levelQ, levelP) diff --git a/examples/bfv/main.go b/examples/bfv/main.go index d1dfdec1..e8c4d9f1 100644 --- a/examples/bfv/main.go +++ b/examples/bfv/main.go @@ -27,7 +27,7 @@ func obliviousRiding() { // 26th USENIX Security Symposium, Vancouver, BC, Canada, August 2017. // // Each area is represented as a rectangular grid where each driver - // anyonymously signs in (i.e. the server only knows the driver is located + // anonymously signs in (i.e. the server only knows the driver is located // in the area). // // First, the rider generates an ephemeral key pair (riderSk, riderPk), which she diff --git a/examples/ckks/advanced/scheme_switching/main.go b/examples/ckks/advanced/scheme_switching/main.go index 296e767a..b56ea2cc 100644 --- a/examples/ckks/advanced/scheme_switching/main.go +++ b/examples/ckks/advanced/scheme_switching/main.go @@ -15,10 +15,10 @@ import ( ) // This example showcases how lookup tables can complement the CKKS scheme to compute non-linear functions -// such as sign. The example starts by homomorphically decoding the CKKS ciphertext from the canonical embeding -// to the coefficient embeding. It then evaluates the Look-Up-Table (BlindRotation) on each coefficient and repacks the +// such as sign. The example starts by homomorphically decoding the CKKS ciphertext from the canonical embedding +// to the coefficient embedding. It then evaluates the Look-Up-Table (BlindRotation) on each coefficient and repacks the // outputs of each Blind Rotation in a single RLWE ciphertext. Finally, it homomorphically encodes the RLWE ciphertext back -// to the canonical embeding of the CKKS scheme. +// to the canonical embedding of the CKKS scheme. // ======================================== // Functions to evaluate with BlindRotation @@ -58,7 +58,7 @@ func main() { // Starting RLWE params, size of these params // determine the complexity of the BlindRotation: - // each BlindRotation takes ~N RGSW ciphertext-ciphetext mul. + // each BlindRotation takes ~N RGSW ciphertext-ciphertext mul. // LogN = 12 & LogQP = ~103 -> >128-bit secure. var paramsN12 ckks.Parameters if paramsN12, err = ckks.NewParametersFromLiteral(ckks.ParametersLiteral{ diff --git a/examples/ckks/bootstrapping/basic/main.go b/examples/ckks/bootstrapping/basic/main.go index 3b103db3..68015da6 100644 --- a/examples/ckks/bootstrapping/basic/main.go +++ b/examples/ckks/bootstrapping/basic/main.go @@ -39,7 +39,7 @@ func main() { // First we must define the residual parameters. // The residual parameters are the parameters used outside of the bootstrapping circuit. // For this example, we have a LogN=16, logQ = 55 + 10*40 and logP = 3*61, so LogQP = 638. - // With LogN=16, LogQP=638 and H=192, these paramters achieve well over 128-bit of security. + // With LogN=16, LogQP=638 and H=192, these parameters achieve well over 128-bit of security. params, err := ckks.NewParametersFromLiteral(ckks.ParametersLiteral{ LogN: LogN, // Log2 of the ringdegree LogQ: []int{55, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40}, // Log2 of the ciphertext prime moduli @@ -57,13 +57,13 @@ func main() { //========================================== // The bootstrapping circuit use its own Parameters which will be automatically - // instantiated given the residual parameters and the bootsrappping parameters. + // instantiated given the residual parameters and the bootstrapping parameters. // !WARNING! The bootstrapping ckks parameters are not ensure to be 128-bit secure, it is the - // responsability of the user to check that the meet the security requirement and tweak them if necessary. + // responsibility of the user to check that the meet the security requirement and tweak them if necessary. // Note that the default bootstrapping parameters use LogN=16 and a ternary secret with H=192 non-zero coefficients - // which provides parmaeters which are at least 128-bit if their LogQP <= 1550. + // which provides parameters which are at least 128-bit if their LogQP <= 1550. // For this first example, we do not specify any circuit specific optional field in the bootstrapping parameters literal. // Thus we expect the bootstrapping to give a precision of 27.25 bits with H=192 (and 23.8 with H=N/2) diff --git a/examples/ckks/ckks_tutorial/main.go b/examples/ckks/ckks_tutorial/main.go index d2c7a309..10920b8d 100644 --- a/examples/ckks/ckks_tutorial/main.go +++ b/examples/ckks/ckks_tutorial/main.go @@ -652,12 +652,12 @@ func main() { // - 2: [3, 3, 3, 3] // - nonZeroDiagonales := []int{-15, -4, -1, 0, 1, 2, 3, 4, 15} + nonZeroDiagonals := []int{-15, -4, -1, 0, 1, 2, 3, 4, 15} - // We allocate the non-zero diagonales and populate them + // We allocate the non-zero diagonals and populate them diagonals := make(float.Diagonals[complex128]) - for _, i := range nonZeroDiagonales { + for _, i := range nonZeroDiagonals { tmp := make([]complex128, Slots) for j := range tmp { @@ -726,7 +726,7 @@ func main() { // See `examples/ckks/bootstrapping` // ========== - // CONCURENCY + // CONCURRENCY // ========== // // Lattigo does not implement low level concurrency yet. @@ -741,7 +741,7 @@ func main() { // EvaluateLinearTransform evaluates a linear transform (i.e. matrix) on the input vector. // values: the input vector -// diags: the non-zero diagonales of the linear transform +// diags: the non-zero diagonals of the linear transform func EvaluateLinearTransform(values []complex128, diags map[int][]complex128) (res []complex128) { slots := len(values) diff --git a/rgsw/elements.go b/rgsw/elements.go index 9d1225a3..b80b6271 100644 --- a/rgsw/elements.go +++ b/rgsw/elements.go @@ -112,7 +112,7 @@ func (ct *Ciphertext) UnmarshalBinary(p []byte) (err error) { type Plaintext rlwe.GadgetPlaintext // NewPlaintext creates a new RGSW plaintext from value, which can be either uint64, int64 or *ring.Poly. -// Plaintext is returned in the NTT and Mongtomery domain. +// Plaintext is returned in the NTT and Montgomery domain. func NewPlaintext(params rlwe.Parameters, value interface{}, levelQ, levelP, BaseTwoDecomposition int) (*Plaintext, error) { gct, err := rlwe.NewGadgetPlaintext(params, value, levelQ, levelP, BaseTwoDecomposition) return &Plaintext{Value: gct.Value}, err diff --git a/rlwe/evaluator_evaluationkey.go b/rlwe/evaluator_evaluationkey.go index 8db1415b..426824d8 100644 --- a/rlwe/evaluator_evaluationkey.go +++ b/rlwe/evaluator_evaluationkey.go @@ -12,7 +12,7 @@ import ( // a homomorphic circuit to provide additional functionalities, like relinearization // or rotations. // -// In a nutshell, an Evalutionkey encrypts a secret skIn under a secret skOut and +// In a nutshell, an Evaluationkey encrypts a secret skIn under a secret skOut and // enables the public and non interactive re-encryption of any ciphertext encrypted // under skIn to a new ciphertext encrypted under skOut. // diff --git a/rlwe/example_parameters.go b/rlwe/example_parameters.go index 3d3a4720..55320f7f 100644 --- a/rlwe/example_parameters.go +++ b/rlwe/example_parameters.go @@ -1,7 +1,7 @@ package rlwe var ( - // ExmpleParameterLogN14LogQP438 is an example parameters set with logN=14 and logQP=438 + // ExampleParameterLogN14LogQP438 is an example parameters set with logN=14 and logQP=438 // offering 128-bit of security. ExampleParametersLogN14LogQP438 = ParametersLiteral{ LogN: 14, diff --git a/rlwe/gadgetciphertext.go b/rlwe/gadgetciphertext.go index 91c7b290..19c310e1 100644 --- a/rlwe/gadgetciphertext.go +++ b/rlwe/gadgetciphertext.go @@ -240,7 +240,7 @@ type GadgetPlaintext struct { } // NewGadgetPlaintext creates a new gadget plaintext from value, which can be either uint64, int64 or *ring.Poly. -// Plaintext is returned in the NTT and Mongtomery domain. +// Plaintext is returned in the NTT and Montgomery domain. func NewGadgetPlaintext(params Parameters, value interface{}, levelQ, levelP, baseTwoDecomposition int) (pt *GadgetPlaintext, err error) { ringQ := params.RingQP().RingQ.AtLevel(levelQ) diff --git a/rlwe/inner_sum.go b/rlwe/inner_sum.go index 2daed2ef..497523cf 100644 --- a/rlwe/inner_sum.go +++ b/rlwe/inner_sum.go @@ -166,7 +166,7 @@ func (eval Evaluator) InnerSum(ctIn *Ciphertext, batchSize, n int, opOut *Cipher // The operation assumes that `ctIn` encrypts Slots/`batchSize` sub-vectors of size `batchSize` and will add them together (in parallel) in groups of `n`. // It outputs in opOut a Ciphertext for which the "leftmost" sub-vector of each group is equal to the pair-wise recursive evaluation of function over the group. // -// The inner funcion is computed in a tree fashion. Example for batchSize=2 & n=4 (garbage slots are marked by 'x'): +// The inner function is computed in a tree fashion. Example for batchSize=2 & n=4 (garbage slots are marked by 'x'): // // 1) [{a, b}, {c, d}, {e, f}, {g, h}, {a, b}, {c, d}, {e, f}, {g, h}] // diff --git a/rlwe/operand.go b/rlwe/operand.go index cd1c1f4f..5c1d6f7d 100644 --- a/rlwe/operand.go +++ b/rlwe/operand.go @@ -4,7 +4,7 @@ package rlwe // providing an anchor for documentation. // // This interface is deliberately left empty -// for backward and forward compatibililty. +// for backward and forward compatibility. // It aims at representing all types of operands // that can be passed as argument to homomorphic // evaluators. diff --git a/rlwe/ringqp/poly.go b/rlwe/ringqp/poly.go index da27621a..46f276ec 100644 --- a/rlwe/ringqp/poly.go +++ b/rlwe/ringqp/poly.go @@ -79,7 +79,7 @@ func (p Poly) CopyNew() *Poly { // Resize resizes the levels of the target polynomial to the provided levels. // If the provided level is larger than the current level, then allocates zero // coefficients, otherwise dereferences the coefficients above the provided level. -// Nil polynmials are unafected. +// Nil polynomials are unaffected. func (p *Poly) Resize(levelQ, levelP int) { p.Q.Resize(levelQ) p.P.Resize(levelP) diff --git a/rlwe/security.go b/rlwe/security.go index 554e87b0..c6ba7acf 100644 --- a/rlwe/security.go +++ b/rlwe/security.go @@ -9,11 +9,11 @@ const ( // DefaultNoise is the default standard deviation of the error DefaultNoise = 3.2 - // DefaultNoiseBound is the default bound (in number of standar deviation) of the noise bound + // DefaultNoiseBound is the default bound (in number of standard deviation) of the noise bound DefaultNoiseBound = 19.2 // 6*3.2 ) -// DefaultXe is the default discret Gaussian distribution. +// DefaultXe is the default discrete Gaussian distribution. var DefaultXe = ring.DiscreteGaussian{Sigma: DefaultNoise, Bound: DefaultNoiseBound} var DefaultXs = ring.Ternary{P: 2 / 3.0} diff --git a/utils/bignum/minimax_approximation.go b/utils/bignum/minimax_approximation.go index dfb5ddb2..b005add4 100644 --- a/utils/bignum/minimax_approximation.go +++ b/utils/bignum/minimax_approximation.go @@ -16,9 +16,9 @@ type Remez struct { RemezParameters Degree int - extrempoints []point - localExtrempoints []point - nbextrempoints int + extremePoints []point + localExtremePoints []point + nbExtremePoints int MaxErr, MinErr *big.Float @@ -87,17 +87,17 @@ func NewRemez(p RemezParameters) (r *Remez) { r.Coeffs[i] = new(big.Float) } - r.extrempoints = make([]point, 3*r.Degree) + r.extremePoints = make([]point, 3*r.Degree) - for i := range r.extrempoints { - r.extrempoints[i].x = new(big.Float) - r.extrempoints[i].y = new(big.Float) + for i := range r.extremePoints { + r.extremePoints[i].x = new(big.Float) + r.extremePoints[i].y = new(big.Float) } - r.localExtrempoints = make([]point, 3*r.Degree) - for i := range r.localExtrempoints { - r.localExtrempoints[i].x = new(big.Float) - r.localExtrempoints[i].y = new(big.Float) + r.localExtremePoints = make([]point, 3*r.Degree) + for i := range r.localExtremePoints { + r.localExtremePoints[i].x = new(big.Float) + r.localExtremePoints[i].y = new(big.Float) } r.Matrix = make([][]*big.Float, r.Degree+2) @@ -134,7 +134,7 @@ func (r *Remez) Approximate(maxIter int, threshold float64) { r.getCoefficients() // Finds the extreme points of p(x) - f(x) (where the absolute error is max) - r.findextrempoints() + r.findExtremePoints() // Choose the new nodes based on the set of extreme points r.chooseNewNodes() @@ -271,9 +271,9 @@ func (r *Remez) getCoefficients() { } } -func (r *Remez) findextrempoints() { +func (r *Remez) findExtremePoints() { - r.nbextrempoints = 0 + r.nbExtremePoints = 0 // e = p(x) - f(x) over [a, b] fErr := func(x *big.Float) (y *big.Float) { @@ -284,17 +284,17 @@ func (r *Remez) findextrempoints() { points := r.findLocalExtrempointsWithSlope(fErr, r.Intervals[j]) - for i, j := r.nbextrempoints, 0; i < r.nbextrempoints+len(points); i, j = i+1, j+1 { - r.extrempoints[i].x.Set(points[j].x) - r.extrempoints[i].y.Set(points[j].y) - r.extrempoints[i].slopesign = points[j].slopesign + for i, j := r.nbExtremePoints, 0; i < r.nbExtremePoints+len(points); i, j = i+1, j+1 { + r.extremePoints[i].x.Set(points[j].x) + r.extremePoints[i].y.Set(points[j].y) + r.extremePoints[i].slopesign = points[j].slopesign } - r.nbextrempoints += len(points) + r.nbExtremePoints += len(points) } // show error message - if r.nbextrempoints < r.Degree+2 { + if r.nbExtremePoints < r.Degree+2 { panic("number of extrem points is smaller than deg + 2, some points have been missed, consider reducing the size of the initial scan step or the approximation degree") } } @@ -310,7 +310,7 @@ func (r *Remez) chooseNewNodes() { newNodes := []point{} // Retrieve the list of extrem points - extrempoints := r.extrempoints + extremePoints := r.extremePoints // Resets max and min error r.MaxErr.SetFloat64(0) @@ -338,7 +338,7 @@ func (r *Remez) chooseNewNodes() { // Tracks the total number of extreme points iterated on ind := 0 - for ind < r.nbextrempoints { + for ind < r.nbExtremePoints { // If idxAdjSameSlope is empty then adds the next point if len(idxAdjSameSlope) == 0 { @@ -348,8 +348,8 @@ func (r *Remez) chooseNewNodes() { // If the slope of two consecutive extreme points is not alternating in sign // then adds the point index to the temporary array - if extrempoints[ind-1].slopesign*extrempoints[ind].slopesign == 1 { - mid := new(big.Float).Add(extrempoints[ind-1].x, extrempoints[ind].x) + if extremePoints[ind-1].slopesign*extremePoints[ind].slopesign == 1 { + mid := new(big.Float).Add(extremePoints[ind-1].x, extremePoints[ind].x) mid.Quo(mid, new(big.Float).SetInt64(2)) idxAdjSameSlope = append(idxAdjSameSlope, ind) ind++ @@ -362,15 +362,15 @@ func (r *Remez) chooseNewNodes() { // absolute value maxIdx := 0 for i := range idxAdjSameSlope { - if maxpoint.Cmp(new(big.Float).Abs(extrempoints[idxAdjSameSlope[i]].y)) == -1 { - maxpoint.Abs(extrempoints[idxAdjSameSlope[i]].y) + if maxpoint.Cmp(new(big.Float).Abs(extremePoints[idxAdjSameSlope[i]].y)) == -1 { + maxpoint.Abs(extremePoints[idxAdjSameSlope[i]].y) maxIdx = idxAdjSameSlope[i] } } // Adds to the new nodes the extreme points whose absolute value is the largest // between all consecutive extreme points with the same slope sign - newNodes = append(newNodes, extrempoints[maxIdx]) + newNodes = append(newNodes, extremePoints[maxIdx]) idxAdjSameSlope = []int{} } } @@ -381,16 +381,16 @@ func (r *Remez) chooseNewNodes() { maxpoint.SetInt64(0) maxIdx := 0 for i := range idxAdjSameSlope { - if maxpoint.Cmp(new(big.Float).Abs(extrempoints[idxAdjSameSlope[i]].y)) == -1 { - maxpoint.Abs(extrempoints[idxAdjSameSlope[i]].y) + if maxpoint.Cmp(new(big.Float).Abs(extremePoints[idxAdjSameSlope[i]].y)) == -1 { + maxpoint.Abs(extremePoints[idxAdjSameSlope[i]].y) maxIdx = idxAdjSameSlope[i] } } - newNodes = append(newNodes, extrempoints[maxIdx]) + newNodes = append(newNodes, extremePoints[maxIdx]) if len(newNodes) < r.Degree+2 { - panic("number of alternating extrem points is less than deg+2, some points have been missed, consider reducing the size of the initial scan step or the approximation degree") + panic("number of alternating extreme points is less than deg+2, some points have been missed, consider reducing the size of the initial scan step or the approximation degree") } //========================= @@ -497,7 +497,7 @@ func (r *Remez) chooseNewNodes() { // https://github.com/snu-ccl/FHE-MP-CNN/blob/main-3.6.6/cnn_ckks/common/MinicompFunc.cpp func (r *Remez) findLocalExtrempointsWithSlope(fErr func(*big.Float) (y *big.Float), interval Interval) []point { - extrempoints := r.localExtrempoints + extrempoints := r.localExtremePoints prec := r.Prec scan := r.ScanStep @@ -530,7 +530,7 @@ func (r *Remez) findLocalExtrempointsWithSlope(fErr func(*big.Float) (y *big.Flo fErrRight.Set(fErr(scanRight)) if slopeRight = fErrRight.Cmp(fErrLeft); slopeRight == 0 { - panic("slope 0 occured: consider increasing the precision") + panic("slope 0 occurred: consider increasing the precision") } for { @@ -581,14 +581,14 @@ func (r *Remez) findLocalExtrempointsWithSlope(fErr func(*big.Float) (y *big.Flo fErrRight.Set(fErr(scanRight)) if slopeRight = fErrRight.Cmp(fErrLeft); slopeRight == 0 { - panic("slope 0 occured: consider increasing the precision") + panic("slope 0 occurred: consider increasing the precision") } // Positive and negative slope (concave) if slopeLeft == 1 && slopeRight == -1 { findLocalMaximum(fErr, scanLeft, scanRight, prec, &extrempoints[nbextrempoints]) nbextrempoints++ - // Negative and positive slope (convexe) + // Negative and positive slope (convex) } else if slopeLeft == -1 && slopeRight == 1 { findLocalMinimum(fErr, scanLeft, scanRight, prec, &extrempoints[nbextrempoints]) nbextrempoints++ diff --git a/utils/sampling/sampling.go b/utils/sampling/sampling.go index b8e0fb5c..64c92cf9 100644 --- a/utils/sampling/sampling.go +++ b/utils/sampling/sampling.go @@ -1,4 +1,4 @@ -// Package sampling implements secure sanmpling bytes and integers. +// Package sampling implements secure sampling of bytes and integers. package sampling import ( diff --git a/utils/slices.go b/utils/slices.go index 6e042a22..1d60d0d3 100644 --- a/utils/slices.go +++ b/utils/slices.go @@ -35,7 +35,7 @@ func MaxSlice[V constraints.Ordered](slice []V) (max V) { return } -// MinSlice returns the mininum value in the slice. +// MinSlice returns the minimum value in the slice. func MinSlice[V constraints.Ordered](slice []V) (min V) { for _, c := range slice { min = Min(min, c) diff --git a/utils/structs/map.go b/utils/structs/map.go index 900246cb..1357b39c 100644 --- a/utils/structs/map.go +++ b/utils/structs/map.go @@ -14,7 +14,7 @@ import ( // The size of the map is limited to 2^32. type Map[K constraints.Integer, T any] map[K]*T -// CopyNew creates a copy of the oject. +// CopyNew creates a copy of the object. func (m Map[K, T]) CopyNew() *Map[K, T] { if c, isCopiable := any(new(T)).(CopyNewer[T]); !isCopiable { diff --git a/utils/structs/matrix.go b/utils/structs/matrix.go index e5b9ad7a..2bb011a2 100644 --- a/utils/structs/matrix.go +++ b/utils/structs/matrix.go @@ -9,7 +9,7 @@ import ( "github.com/tuneinsight/lattigo/v4/utils/buffer" ) -// Matrix is a struct wrapping a doube slice of components of type T. +// Matrix is a struct wrapping a double slice of components of type T. // T can be: // - uint, uint64, uint32, uint16, uint8/byte, int, int64, int32, int16, int8, float64, float32. // - Or any object that implements CopyNewer, CopyNewer, BinarySizer, io.WriterTo or io.ReaderFrom @@ -33,7 +33,7 @@ func (m Matrix[T]) CopyNew() (mcpy Matrix[T]) { } default: - if _, isCopiable := any(t).(CopyNewer[T]); !isCopiable { + if _, isCopyable := any(t).(CopyNewer[T]); !isCopyable { panic(fmt.Errorf("matrix component of type %T does not comply to %T", t, new(CopyNewer[T]))) } diff --git a/utils/structs/vector.go b/utils/structs/vector.go index 2672b2d7..2a8c4611 100644 --- a/utils/structs/vector.go +++ b/utils/structs/vector.go @@ -96,7 +96,7 @@ func (v Vector[T]) WriteTo(w io.Writer) (n int64, err error) { case uint, uint64, int, int64, float64: if inc, err = buffer.WriteAsUint64Slice[T](w, v); err != nil { - return n + inc, fmt.Errorf("buffer.WriteasUint64Slice[%T]: %w", t, err) + return n + inc, fmt.Errorf("buffer.WriteAsUint64Slice[%T]: %w", t, err) } n += inc