feat(sdk): expose recommended gas limits and helpers for FHE operations (#281) - #327
Open
Lesnak1 wants to merge 1 commit into
Open
feat(sdk): expose recommended gas limits and helpers for FHE operations (#281)#327Lesnak1 wants to merge 1 commit into
Lesnak1 wants to merge 1 commit into
Conversation
…ns (FhenixProtocol#281) - Expose FHE_GAS_LIMITS constants for COMPUTE (5M), PUBLISH_RESULT (500k), and VERIFY_INPUT (1M) - Add getRecommendedFheGasLimit utility helper to prevent out-of-gas reverts from eth_estimateGas - Add comprehensive unit tests and changeset
🦋 Changeset detectedLatest commit: f547fce The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses #281 by exposing recommended gas limits and helper utilities for FHE contract operations across
@cofhe/sdk.Context & Motivation
Standard RPC
eth_estimateGas(used by Viem'spublicClient.estimateGas, Wagmi, and Ethers) consistently underestimates execution costs for contract functions invoking CoFHE precompiles (e.g.FHE.asEuint*,FHE.add,FHE.select,FHE.eq). Even with generous buffers (+30%), write transactions often revert out-of-gas unless developers manually specify fixed gas limits.Changes
packages/sdk/core/consts.ts):FHE_GAS_LIMITS.COMPUTE:5_000_000n(for functions executing homomorphic computation)FHE_GAS_LIMITS.PUBLISH_RESULT:500_000n(for verifying threshold decryption signatures viaFHE.publishDecryptResult)FHE_GAS_LIMITS.VERIFY_INPUT:1_000_000n(for ZK input verification / TaskManager)packages/sdk/core/utils.ts):getRecommendedFheGasLimit(operation?: FheGasOperationType): bigintpackages/sdk/core/index.ts):FHE_GAS_LIMITS,FheGasOperationType, andgetRecommendedFheGasLimit.packages/sdk/core/test/gas.test.ts):.changeset/fhe-recommended-gas-limits.mdfor patch release.Verification