> ## Documentation Index
> Fetch the complete documentation index at: https://cofhe-docs.fhenix.zone/llms.txt
> Use this file to discover all available pages before exploring further.

# Gas per Operation

> The expected gas of every FHE.sol operation

Every value is measured on the deployed contracts and rounded to the nearest 100 gas.

<Note>
  **The values are for the first FHE call in a transaction. Every later FHE call in the same transaction costs about 20,000 gas less.**
</Note>

`X` stands for the encrypted type: `asEuint32`, `asEbool`, `shareEuint64`, and so on. The seven encrypted types are `ebool`, `euint8` through `euint128`, and `eaddress`; "All" means all seven. The type barely changes the price, so each value is the highest across the supported types.

## Arithmetic

| Operation | Gas | Types |
| - | - | - |
| `add` | 51,600 | `euint8` to `euint128` |
| `sub` | 51,500 | `euint8` to `euint128` |
| `mul` | 52,600 | `euint8` to `euint128` |
| `div` | 52,300 | `euint8` to `euint128` |
| `rem` | 52,500 | `euint8` to `euint128` |
| `square` | 48,900 | `euint8` to `euint128` |
| `min` | 53,600 | `euint8` to `euint128` |
| `max` | 53,800 | `euint8` to `euint128` |

## Comparison

| Operation | Gas | Types |
| - | - | - |
| `eq` | 52,700 | All |
| `ne` | 53,000 | All |
| `lt` | 53,000 | `euint8` to `euint128` |
| `lte` | 52,800 | `euint8` to `euint128` |
| `gt` | 53,300 | `euint8` to `euint128` |
| `gte` | 52,800 | `euint8` to `euint128` |

## Bitwise and shift

| Operation | Gas | Types |
| - | - | - |
| `and` | 51,700 | `ebool`, `euint8` to `euint128` |
| `or` | 51,900 | `ebool`, `euint8` to `euint128` |
| `xor` | 51,500 | `ebool`, `euint8` to `euint128` |
| `not` | 45,700 | `ebool`, `euint8` to `euint128` |
| `shl` | 52,800 | `euint8` to `euint128` |
| `shr` | 52,900 | `euint8` to `euint128` |
| `rol` | 54,500 | `euint8` to `euint128` |
| `ror` | 54,600 | `euint8` to `euint128` |

## Select

| Operation | Gas | Types |
| - | - | - |
| `select` | 55,900 | All |

## Encrypt: create a ciphertext

| Operation | Gas | Types |
| - | - | - |
| [Trivial encrypt](/fhe-library/core-concepts/trivial-encryption) `asX(plaintext)` | 45,400 | All |
| Encrypted input `asX(InEuintX)` | 39,800 | All |
| Encrypted input from bytes `asX(bytes)` | 40,400 | All |
| Random `randomX()` | 40,900 | `euint8` to `euint128` |

## Cast between encrypted types

| Operation | Gas | Types |
| - | - | - |
| Cast `asX(eY)`, target not `ebool` | 45,900 | Any to `euint8` to `euint128` |
| Cast to `ebool`, `asEbool(eY)` | 75,800 | Numeric types and `eaddress` to `ebool` |

A cast to `ebool` costs more because `FHE.sol` implements it as `ne(value, asX(0))`: two TaskManager tasks instead of one.

## Access control

All access-control operations support all seven types and cost the same for each. The two `is*` functions are `view`; they cost gas only when a contract calls them inside a transaction.

| Operation | Gas |
| - | - |
| `allow` | 44,700 |
| `allowThis` | 26,300 |
| `allowSender` | 44,700 |
| <code style={{ whiteSpace: "nowrap" }}>allowTransient</code> | 23,000 |
| `allowGlobal` | 44,100 |
| `allowPublic` | 44,100 |
| `isAllowed` | 22,200 |
| <code style={{ whiteSpace: "nowrap" }}>isPubliclyAllowed</code> | 21,900 |

## Sharing

| Operation | Gas |
| - | - |
| `shareX` | 25,900 |
| <code style={{ whiteSpace: "nowrap" }}>receiveXParam</code> | 6,300 |
| <code style={{ whiteSpace: "nowrap" }}>receiveXFromCall</code> | 6,300 |

## Decryption results

The four `verify*` and `get*` functions are `view`; they cost gas only when a contract calls them inside a transaction.

| Operation | Gas |
| - | - |
| <code style={{ whiteSpace: "nowrap" }}>publishDecryptResult</code> | 71,400 |
| <code style={{ whiteSpace: "nowrap" }}>verifyDecryptResult</code> | 15,100 |
| <code style={{ whiteSpace: "nowrap" }}>verifyDecryptResultSafe</code> | 15,700 |
| <code style={{ whiteSpace: "nowrap" }}>getDecryptResult</code> | 24,300 |
| <code style={{ whiteSpace: "nowrap" }}>getDecryptResultSafe</code> | 23,200 |
