Since Inco enables smart contracts to compute over private data without leaking any information, two common programming usages can’t be used.

  1. You can’t use an if/else statement with a condition depending on a private value. The flow that the program would take would leak information about the private value.

  2. For the same reason you can’t revert a transaction based on a condition depending on a private value.

To go around this, we use a pattern called the multiplexer design pattern.

Multiplexer Design Pattern

The inco equivalent of an if/else statement is the select statement. The select statement takes an encrypted boolean as first argument and two encrypted values as second and third arguments. The result of the select statement is the second argument if the first argument is true and the third argument otherwise.

Example usage from the confidential token contract:

function _transfer(address to, euint256 value) internal returns (ebool success) {
    // we check that the user has enough balance, and assign the result to the ebool success
    success = balanceOf[msg.sender].ge(value);
    // we use the select statement to assign the value to be transferred
    // if the the user has enough balance, we transfer the value
    // otherwise we assign 0 to the transferred value
    euint256 transferredValue = success.select(value, uint256(0).asEuint256());
    // ... rest of the transfer logic
}

In the confidential token example, instead of reverting if the user has insufficient balance, we transfer an amount of 0, which is equivalent to doing nothing. Expect this kind of logic in most confidential apps.