Inconsistent results of two simple programs

Hi, I raised the issue 1293 in Concrete’s GitHub three weeks ago, but haven’t received any response :smiling_face_with_tear:.

While many other programs I run now work perfectly (Thank you very much for your great framework!), I still have questions about these two simple programs. The Concrete output differs from the plaintext output, and I’m unsure whether this stems from a feature, a bug, or simply an error on my part? (Maybe I missed some documentation explaining these situations?)

Program 1

from concrete import fhe

def foo(x):
    x = -97
    return x


if __name__ == "__main__":
    compiler = fhe.Compiler(foo, {"x": "encrypted"})

    inputset = fhe.inputset(fhe.int8)
    circuit = compiler.compile(inputset)
    circuit.keygen()
    encrypted_x = circuit.encrypt(1)
    encrypted_result = circuit.run(encrypted_x)
    result = circuit.decrypt(encrypted_result)

    print(circuit)
    print()
    print(f"plaintext result: {foo(1)}")
    print(f"concrete result: {result}")

Output of program 1:

%0 = -97        # ClearScalar<int8>        ∈ [-97, -97]
return %0

plaintext result: -97
concrete result: 415

Program 2:

from concrete import fhe

def foo(x):
    return 1, 2, 3


if __name__ == "__main__":
    compiler = fhe.Compiler(foo, {"x": "encrypted"})

    inputset = fhe.inputset(fhe.int8)
    circuit = compiler.compile(inputset)
    circuit.keygen()
    encrypted_x = circuit.encrypt(1)
    encrypted_result = circuit.run(encrypted_x)
    result = circuit.decrypt(encrypted_result)

    print(circuit)
    print()
    print(f"plaintext result: {foo(1)}")
    print(f"concrete result: {result}")

Output of program 2:

%0 = 1        # ClearScalar<uint1>        ∈ [1, 1]
%1 = 2        # ClearScalar<uint2>        ∈ [2, 2]
%2 = 3        # ClearScalar<uint2>        ∈ [3, 3]
return %0, %1, %2

plaintext result: (1, 2, 3)
concrete result: (1, 0, 0)

Hello @secpoint , thank you for reaching us on the community forum.

I take a quick look at your program, I don’t known what is excatly going wrong but that clearly an unexpected behavior.

But I think the bug occurs because you return a cleartext and those kind of circuit are clearly not tested or at least not heavily tested in our codebase, indeed we made the asumption that concrete is used for doing homomorphic computation not clear one :wink: .

i.e. this works better

def foo(x):
    c = -97
    return c + x

I’m curious of why you are doing this?

Thank you for quick reply! :smiley: (Sorry for my late reply. After clicking the “Solution” button, I found I need to wait 8 hours before I could reply.)

During the early stage of my project, I used some hard-coded values to test auxiliary functions and noticed some issues with the output. After further reducing the functions to identify the root cause, I got these two simple programs above.

I checked the Concrete circuit, and it seemed consistent with the plaintext output, but the actual decryption results were inconsistent. This confused me a lot, because I was worried about meeting similar issues in more complex programs, and now I’m happy to learn it was just due to the unexpected behavior of returning a cleartext. :wink: Thank you very much!

2 Likes