Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lattigo: multiple encoding of same plaintext would result in duplicated variable name in emitter #1458

Open
ZenithalHourlyRate opened this issue Feb 24, 2025 · 0 comments

Comments

@ZenithalHourlyRate
Copy link
Collaborator

For the following mlir

  %c1 = arith.constant dense<1> : tensor<4xi16>
  %base0 = arith.addi %base, %c1 : tensor<4xi16>
  %base1 = arith.addi %base0, %c1 : tensor<4xi16>

It will be translated to

  v0 := []int64{1, 1, 1, 1}
  pt := bgv.NewPlaintext(param, param.MaxLevel())
  // v0_packed appearing for the first time
  v0_packed := make([]int64, param.MaxSlots())
  for i := range v0_packed {
    v0_packed[i] = int64(v0[i % len(v0)])
  }
  encoder.Encode(v0_packed, pt) 
  pt1 := pt
  ct2, err0 := evaluator.AddNew(ct, pt1)
  if err0 != nil {
    panic(err0)
  }
  pt2 := bgv.NewPlaintext(param, param.MaxLevel())
  // v0_packed appearing for the second time
  // GO would complain "no new variables on left side of :="
  v0_packed := make([]int64, param.MaxSlots())
  for i := range v0_packed {
    v0_packed[i] = int64(v0[i % len(v0)])
  }
  encoder.Encode(v0_packed, pt2)
  pt3 := pt2 
  ct3, err1 := evaluator.AddNew(ct2, pt3)
  if err1 != nil {
    panic(err1)
  }
  return ct3

Should be fixed by v0_pt_packed and v0_pt2_packed.

Or should be be fixed by CSE? but it seems like the following code could not be CSE, especially different plaintext could have different scale (ref to #1169)

    %cst = arith.constant dense<1> : tensor<4xi16>
    %pt = lattigo.bgv.new_plaintext %param : (!lattigo.bgv.parameter) -> !lattigo.rlwe.plaintext
    %pt_1 = lattigo.bgv.encode %encoder, %cst, %pt : (!lattigo.bgv.encoder, tensor<4xi16>, !lattigo.rlwe.plaintext) -> !lattigo.rlwe.plaintext
    %ct_2 = lattigo.bgv.add %evaluator, %ct, %pt_1 : (!lattigo.bgv.evaluator, !lattigo.rlwe.ciphertext, !lattigo.rlwe.plaintext) -> !lattigo.rlwe.ciphertext
    %pt_3 = lattigo.bgv.new_plaintext %param : (!lattigo.bgv.parameter) -> !lattigo.rlwe.plaintext
    %pt_4 = lattigo.bgv.encode %encoder, %cst, %pt_3 : (!lattigo.bgv.encoder, tensor<4xi16>, !lattigo.rlwe.plaintext) -> !lattigo.rlwe.plaintext
    %ct_5 = lattigo.bgv.add %evaluator, %ct_2, %pt_4 : (!lattigo.bgv.evaluator, !lattigo.rlwe.ciphertext, !lattigo.rlwe.plaintext) -> !lattigo.rlwe.ciphertext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant