Gas estimation
FHE operations are typically more computationally expensive than classical operations due to their inherent complexity. As a reference, here is an approximation of the gas cost associated with each operation.
ebool
Function name | Gas |
---|---|
| 26,000 |
| 30,000 |
| 500,000 |
euint4
function name | Gas |
---|---|
| 65,000 |
| 65,000 |
| 150,000 |
| 88,000 |
| 139,000 |
| 286,000 |
| 32,000 |
| 116,000 |
| 35,000 |
| 116,000 |
| 35,000 |
| 51,000 |
| 70,000 |
| 121,000 |
| 121,000 |
| 60,000 |
| 33,000 |
| 45,000 |
| 500,000 |
euint8
Function name | Gas |
---|---|
| 94,000 |
| 94,000 |
| 197,000 |
| 159,000 |
| 238,000 |
| 460,000 |
| 34,000 |
| 133,000 |
| 35,000 |
| 133,000 |
| 35,000 |
| 53,000 |
| 82,000 |
| 128,000 |
| 128,000 |
| 95,000 |
| 34,000 |
| 47,000 |
| 500,000 |
| 100,000 |
euint16
function name | euint16 |
---|---|
| 133,000 |
| 133,000 |
| 262,000 |
| 208,000 |
| 314,000 |
| 622,000 |
| 34,000 |
| 153,000 |
| 35,000 |
| 153,000 |
| 35,000 |
| 54,000 |
| 105,000 |
| 153,000 |
| 150,000 |
| 131,000 |
| 35,000 |
| 47,000 |
| 500,000 |
| 100,000 |
euint32
Function name | Gas fee |
---|---|
| 162,000 |
| 162,000 |
| 359,000 |
| 264,000 |
| 398,000 |
| 805,000 |
| 35,000 |
| 183,000 |
| 35,000 |
| 183,000 |
| 35,000 |
| 82,000 |
| 128,000 |
| 183,000 |
| 164,000 |
| 160,000 |
| 36,000 |
| 50,000 |
| 500,000 |
| 100,000 |
euint64
Function name | Gas fee |
---|---|
| 188,000 |
| 188,000 |
| 641,000 |
| 356,000 |
| 584,000 |
| 1,095,000 |
| 38,000 |
| 227,000 |
| 38,000 |
| 227,000 |
| 38,000 |
| 86,000 |
| 156,000 |
| 210,000 |
| 192,000 |
| 199,000 |
| 37,000 |
| 53,000 |
| 500,000 |
| 100,000 |
eaddress
Function name | Gas fee |
---|---|
| 90,000 |
Estimate gas
When you call estimate gas method, we can’t determine accurately the gas usage if your function uses TFHE.decrypt
. During gas estimation, all TFHE.decrypt()
will return 1
.
What does it mean?
require(TFHE.decrypt(ebool));
will be ok butrequire(!TFHE.decrypt(ebool));
will fail during estimation (revert transaction)A loop, where you expect a decrypt to be false to break, will never end in gas estimate method (and fails), since the decrypt will always return
1
(true)On the other hand, if your loop should last 2 or 3 cycles, until the value is 1, the estimation will be below.
If you have branches (if/else) based on a decryption, the estimation will use the branch running when the decryption is
1
While it’s challenging to accurately estimate gas consumption when using TFHE.decrypt
, we strongly encourage you to take this into consideration.
What can I do?
A possible solution is to overestimate your gas estimation. You can take this function (with ethers.js) as an example where we multiply the gas limit by 1.2
.
Gas limit
The current devnet has a gas limit of 10,000,000. If you send a transaction exceeding this limit, it won't be executed. Consequently, your wallet won't be able to emit a new transaction. To address this, emit a new transaction with the same nonce but the correct gas limit. In Metamask, you can enforce the use of a specific nonce by enabling the feature in 'Advanced Settings'.
Last updated