heir icon indicating copy to clipboard operation
heir copied to clipboard

CKKS pipeline fails on (scalar) integer types

Open AlexanderViand opened this issue 9 months ago • 2 comments

Using secret tensors of integer types work fine with the CKKS pipeline (e.g., simple_sum.mlir works fine). However, trying the same with scalar types does not work:

// heir-opt --mlir-to-ckks
func.func @test_scalar(%x: i32 {secret.secret}) -> i32 {
    %0 = arith.addi %x, %x : i32
    return %0 : i32
}

This fails in the compiler (cannot add client interface), while the same program but with arith.muli will heir-opt and even emit OpenFHE code fine (but then fail later, when trying to clang compile the OpenFHE helpers).

Initially, I was going to just submit a PR to add an explicit check to see if there's any secret integers and error if there are (like the "disallowFloat" check in --secret-to-bgv), but I think we might actually want to allow integer types in the CKKS long-term, so it might be the better fix this at the root.

Also, the difference in behaviour between add and mul indicates there's some management oddness factoring into this @ZenithalHourlyRate ?

AlexanderViand avatar May 12 '25 16:05 AlexanderViand

Also note that I am refactoring the client interface passes in https://github.com/google/heir/pull/1778

j2kun avatar May 12 '25 17:05 j2kun

In my testing both addi and muli works, and the client interface exists though it is wierd (ring_f64 encoding i32)

  func.func @test_scalar(%ct: !ct_L0) -> !ct_L0 {
    %ct_0 = ckks.add %ct, %ct : (!ct_L0, !ct_L0) -> !ct_L0
    return %ct_0 : !ct_L0
  }


  func.func @test_scalar__encrypt__arg0(%arg0: i32, %pk: !pkey_L0) -> !ct_L0 {
    %pt = lwe.rlwe_encode %arg0 {encoding = #inverse_canonical_encoding, ring = #ring_f64_1_x1024} : i32 -> !pt
    %ct = lwe.rlwe_encrypt %pt, %pk : (!pt, !pkey_L0) -> !ct_L0
    return %ct : !ct_L0
  }

ZenithalHourlyRate avatar May 12 '25 17:05 ZenithalHourlyRate