Inco exposes mathematical and logical operations over encrypted data.
Note that for each operation that takes 2 arguments (i.e binary types below), you can use either an e-type or a regular
variable as the first or second argument. Each operation returns a single e-type as result.
Under the hood, all operations are performing a call to the Inco contract
singleton. The Inco contract checks access control rules and emits an event
for each operation
Example usage
euint256 a = e.asEuint256(2);
euint256 b = e.asEuint256(3);
euint256 c = a.add(b); // c = 5 (encrypted)
Supported math operations
All these operations return an euint256.
| Name | Function | Type |
|---|
| Addition | e.add | Binary |
| Subtraction | e.sub | Binary |
| Multiplication | e.mul | Binary |
| Division | e.div | Binary |
| Remainder | e.rem | Binary |
| BitAnd | e.and | Binary |
| BitOr | e.or | Binary |
| BitXor | e.xor | Binary |
| Shift Right | e.shr | Binary |
| Shift Left | e.shl | Binary |
| Rotate Right | e.rotr | Binary |
| Rotate Left | e.rotl | Binary |
Supported comparison operations
| Name | Function | Type | Returns |
|---|
| Equal | e.eq | Binary | ebool |
| Not equal | e.ne | Binary | ebool |
| Greater than or equal | e.ge | Binary | ebool |
| Greater than | e.gt | Binary | ebool |
| Less than or equal | e.le | Binary | ebool |
| Less than | e.lt | Binary | ebool |
| Min | e.min | Binary | euint256 |
| Max | e.max | Binary | euint256 |
| Not | e.not | Unary | ebool |
Random number generation
euint256 randomNumber = e.rand();
euint256 boundedRandom = e.randBounded(100); // Random number in [0, 100)
euint256 boundedRandomEncrypted = e.randBounded(encryptedUpperBound); // With encrypted upper bound
| Name | Function | Type | Returns |
|---|
| Random | e.rand() | Unary | euint256 |
| Random Bounded | e.randBounded(uint256 upperBound) | Unary | euint256 |
| Random Bounded | e.randBounded(euint256 upperBound) | Unary | euint256 |
Type conversion functions
Convert between regular types and encrypted types, or between different encrypted types.
euint256 a = e.asEuint256(42);
ebool b = e.asEbool(true);
eaddress c = e.asEaddress(0x123...);
ebool d = e.asEbool(encryptedUint); // Cast from euint256
euint256 e = e.asEuint256(encryptedBool); // Cast from ebool
| Name | Function | Type | Returns |
|---|
| Convert to euint256 | e.asEuint256(uint256 a) | Unary | euint256 |
| Convert to ebool | e.asEbool(bool a) | Unary | ebool |
| Convert to eaddress | e.asEaddress(address a) | Unary | eaddress |
| Cast euint256 to ebool | e.asEbool(euint256 a) | Unary | ebool |
| Cast ebool to euint256 | e.asEuint256(ebool a) | Unary | euint256 |
Reveal functions
Reveal encrypted values (decrypt and make public).
e.reveal(encryptedUint);
e.reveal(encryptedBool);
e.reveal(encryptedAddress);
| Name | Function | Type | Returns |
|---|
| Reveal | e.reveal(euint256 a) | Unary | void |
| Reveal | e.reveal(ebool a) | Unary | void |
| Reveal | e.reveal(eaddress a) | Unary | void |
Additional type support
Comparison operations (e.eq and e.ne) also support eaddress comparisons in addition to euint256.
Bitwise operations (e.and, e.or, e.xor) also support ebool operations in addition to euint256.