Encrypted values [from Discord]

Hi Zama team. Love what you’re building. I have a noob question, trying to wrap my head around fhevm (I don’t know much about FHE).

Here is some pseudocode:

euint32 a = encrypted(7)
euint32 b = encrypted(4)
euint32 c = encrypted(2)

x1 = FHEOps.sub(a,b)
x2 = FHEOps.sub(a,b)
y = FHEOps.sub(a,FHEOps.add(c,c))

When decrypted, x1, x2 and y will obviously be 3.

My question is about the encrypted values. Will the bytes for x1, x2 and y be different?
And if yes, where does the entropy come from? Thanks

(This Topic relates to the Discord conversation here)

This depends on what are the semantics of encrypt.
In the case of a solidity smart contract, calling the euint32 y = asEuint32(x: uint32) will “trivially encrypt” the value x. This is nothing more than formatting x such that y can be used as an operand in subsequent FHE operations (more info here: https://docs.zama.ai/fhevm/writing-contracts/functions#aseuint). In that case, unless I’m missing some trivial implementation detail, x1, x2 and y would have the same bytes.

If, however, the smart contract received the encrypted values from calldata (i.e., from the user), then the encryption is not trivial and the entropy comes from the user. You can find an example of this here: https://github.com/zama-ai/fhevm/blob/main/examples/EncryptedERC20.sol#L47.
In that case, bytes of different ciphertext encrypting the same plaintext will be different.

Does that answer your question?

Thank you Louis. It does :pray:

@Louis will y have the same bytes as x1 and x2?

In the first case described above, yes. Otherwise, no.