Skip to content

feat(sdk): expose recommended gas limits and helpers for FHE operations (#281) - #327

Open
Lesnak1 wants to merge 1 commit into
FhenixProtocol:masterfrom
Lesnak1:feat/sdk-fhe-gas-limits
Open

feat(sdk): expose recommended gas limits and helpers for FHE operations (#281)#327
Lesnak1 wants to merge 1 commit into
FhenixProtocol:masterfrom
Lesnak1:feat/sdk-fhe-gas-limits

Conversation

@Lesnak1

@Lesnak1 Lesnak1 commented Aug 17, 2026

Copy link
Copy Markdown

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's publicClient.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

  1. Gas Constants (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 via FHE.publishDecryptResult)
    • FHE_GAS_LIMITS.VERIFY_INPUT: 1_000_000n (for ZK input verification / TaskManager)
  2. Helper Function (packages/sdk/core/utils.ts):
    • getRecommendedFheGasLimit(operation?: FheGasOperationType): bigint
  3. Core Exports (packages/sdk/core/index.ts):
    • Cleanly re-exports FHE_GAS_LIMITS, FheGasOperationType, and getRecommendedFheGasLimit.
  4. Unit Tests (packages/sdk/core/test/gas.test.ts):
    • Added unit test suite validating all constants and default fallback behavior.
  5. Changeset:
    • Added .changeset/fhe-recommended-gas-limits.md for patch release.

Verification

  • Unit tests written and verified for all exported constants and helpers.
  • TypeScript types checked with zero compiler warnings.

…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

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@changeset-bot

changeset-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f547fce

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@cofhe/sdk Patch
@cofhe/abi Patch
@cofhe/hardhat-3-plugin Patch
@cofhe/hardhat-plugin Patch
@cofhe/mock-contracts Patch
@cofhe/react Patch
@cofhe/site Patch
@cofhe/example-react Patch
@cofhe/foundry-plugin Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant