> For the complete documentation index, see [llms.txt](https://docs.arcan.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.arcan.finance/solidity/operations.md).

# Operations

Operations on encrypted values return a new handle. They do not return a Solidity integer.

Functions that perform FHE work change state. They are not `view`.

## Arithmetic

Available on `euint*` values:

* `FHE.add`
* `FHE.sub`
* `FHE.mul`
* `FHE.min`
* `FHE.max`
* `FHE.neg`

`FHE.div` and `FHE.rem` require a plaintext divisor. Two ciphertexts cannot be divided.

A plaintext operand is allowed when it is no wider than the ciphertext. `FHE.add(encrypted, 10)` is valid. Mixing a wide plaintext into a narrow ciphertext is not.

Ciphertext-plaintext math is cheaper than ciphertext-ciphertext math, because one side is already known.

## Comparison

Comparisons return an `ebool`, not a Solidity `bool`.

* `FHE.eq`, `FHE.ne`
* `FHE.lt`, `FHE.gt`, `FHE.le`, `FHE.ge`

You can compare encrypted integers and encrypted addresses. You cannot feed the `ebool` into `require`. The chain would have to know the bit.

## Select

`FHE.select` is the branch.

```solidity
ebool enough = FHE.ge(balance, amount);
balance = FHE.select(enough, FHE.sub(balance, amount), balance);
```

If `enough` is an encryption of true, the result is the reduced balance. Otherwise the result is the old balance. Both branches are computed as handles. The chain does not learn which one was chosen.

## Bitwise

`FHE.and`, `FHE.or`, `FHE.xor`, `FHE.not`, `FHE.shl`, `FHE.shr`, `FHE.rotl`, and `FHE.rotr` operate on encrypted integers.

If you pass a plaintext to a bitwise function, the library encrypts that plaintext first. Shifts and rotates move bits inside the ciphertext.

## Random handles

`FHE.randEuint64` and the other `randEuint*` helpers draw an encrypted random integer during a transaction. The draw updates on-chain state, so it is not available in a read-only call. The plaintext of the draw is not published.

## After every write

Grant access on the new handle or the next call cannot use it.

```solidity
FHE.allowThis(nextBalance);
FHE.allow(nextBalance, msg.sender);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.arcan.finance/solidity/operations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
