Comment on page

If...else

Branching and comparisons on FHE encrypted data are done using multiplexer logic. Here's an example of this in action, and how it compares to an if..else branch
function bid(bytes calldata encryptedValue) public onlyBeforeEnd {
...
// parse input
euint32 value = TFHE.asEuint32(encryptedValue);
// current value
euint32 existingBid = bids[msg.sender];
// isHigher = (existing < input)
// returns either 0 (false) or 1 (true) as an encrypted uint32
ebool isHigher = TFHE.lt(existingBid, value);
// if the input is greater than the existing value, set existing to input
// =>
// if (isHigher) {
// bids[msg.sender] = value;
// }
// else {
// bids[msg.sender] = existingBid;
// }
bids[msg.sender] = TFHE.cmux(isHigher, value, existingBid);
...
}