Skip to content

feat: params crate [skip-line-limit]#1197

Merged
0xjei merged 20 commits into
mainfrom
crate/e3-fhe-params
Jan 26, 2026
Merged

feat: params crate [skip-line-limit]#1197
0xjei merged 20 commits into
mainfrom
crate/e3-fhe-params

Conversation

@0xjei

@0xjei 0xjei commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

closes #1204

Removed bfv-helpers by splitting functionality into focused crates:

  • BFV client ops (encrypt, verifiable encrypt, commitments, plaintext/bytes helpers) → crates/bfv-client
  • Greco conversions → crates/greco-helpers
  • Params/ABI encoding → crates/fhe-params
  • Rewired all callers (Rust + templates + CRISP) to the new crates and updated workspace/Cargo/Docker/init wiring
  • Cleaned up dependencies and eliminated unused BFV helper module surface

Summary by CodeRabbit

  • New Features

    • BFV presets and builders plus ABI encode/decode for BFV parameters; new BFV client utilities for encoding/decoding and plaintext/byte conversions.
  • Refactor

    • SDK, templates and examples now use preset-name based threshold BFV retrieval; new SDK method to fetch threshold BFV presets and updated encoding API.
  • Chores

    • Workspace reorganized: legacy helper removed, new client/params/greco helper packages added; manifests, examples and tests updated accordingly.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Replaces the single bfv-helpers crate with three new workspace crates (bfv-client, fhe-params, greco-helpers), updates workspace manifests/Dockerfiles/templates, migrates imports and tests to the new crates, and reworks the TypeScript SDK to use BFV preset semantics and new param encoding APIs.

Changes

Cohort / File(s) Summary
Workspace & build
Cargo.toml, crates/Dockerfile, templates/default/Cargo.toml, examples/*, templates/*
Removed crates/bfv-helpers; added crates/bfv-client, crates/fhe-params, crates/greco-helpers. Updated workspace.members, [workspace.dependencies], and Dockerfile COPYs to include new crates and expand the build graph.
New crate: fhe-params
crates/fhe-params/Cargo.toml, crates/fhe-params/src/{lib.rs,builder.rs,constants.rs,presets.rs,encoding.rs}
Adds BFV presets, constants, builders, preset→param conversions, and feature-gated ABI encode/decode (encode_bfv_params, decode_bfv_params, decode_bfv_params_arc).
New crate: bfv-client
crates/bfv-client/Cargo.toml, crates/bfv-client/src/{lib.rs,client.rs}
Exposes BFV client APIs (encrypt, verifiable encrypt, commitment helpers) and plaintext/byte encode-decode utilities, plus Error/Result aliases and re-exports.
New crate: greco-helpers
crates/greco-helpers/Cargo.toml, crates/greco-helpers/src/lib.rs
Adds GRECO helper crate manifest and updates test imports to consume new presets/helpers.
Removed crate: bfv-helpers
crates/bfv-helpers/src/lib.rs, crates/bfv-helpers/src/utils/mod.rs
Deleted large helpers module and utilities; functionality relocated into fhe-params and bfv-client.
Manifests & consumers
crates/*/Cargo.toml, examples/*/Cargo.toml, templates/*/Cargo.toml
Replaced e3-bfv-helpers with e3-bfv-client and/or e3-fhe-params across many manifests; added e3-greco-helpers where needed.
Call sites & tests
crates/*/src/**, crates/*/tests/**, examples/**, templates/**
Swapped imports: BfvParamSetsBfvPreset/BfvParamSet; moved build/encode/decode helpers to e3-fhe-params, client helpers to e3-bfv-client; several decode calls hardened with .expect("Failed to decode BFV params"); tests and fixtures updated (preset names, thresholds, sample values).
SDK & frontend
packages/enclave-sdk/src/{types.ts,index.ts,utils.ts,enclave-sdk.ts}, packages/enclave-react/*, templates/default/*
Reworked SDK surface: removed protocol abstraction, added thresholdBfvParamsPresetName, renamed ProtocolParamsBfvParams, added getThresholdBfvParamsSet, and updated encodeBfvParams to accept a params object; templates and client code updated to fetch presets.

Sequence Diagram(s)

sequenceDiagram
  actor UI
  participant SDK
  participant FHE_PARAMS as "fhe-params"
  participant ENCLAVE

  UI->>SDK: request computation
  SDK->>FHE_PARAMS: getThresholdBfvParamsSet()
  FHE_PARAMS-->>SDK: BfvParams (preset)
  SDK->>SDK: encodeBfvParams(BfvParams)
  SDK->>ENCLAVE: submit encoded params + payload
  ENCLAVE-->>SDK: ack / result
  SDK-->>UI: result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

crisp

Suggested reviewers

  • ryardley
  • cedoor
  • hmzakhalid

Poem

🐇 I hopped through crates and split one into three,
fhe-params, bfv-client, greco-helpers — whee!
Presets and encoders ordered neat and bright,
Imports refreshed, workspace trimmed tonight.
Carrot-coded commits — hop on, ship the byte!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: params crate' directly and clearly summarizes the main change—introducing a new e3-fhe-params crate to consolidate BFV parameter logic.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #1204: BfvPreset enum with from_name() method, PresetMetadata struct, build_pair() method, hardcoded parameters in the new e3-fhe-params crate, and updated all callers to use the new crate.
Out of Scope Changes check ✅ Passed All changes are within scope. The PR refactors bfv-helpers into three focused crates (bfv-client, greco-helpers, fhe-params), updates all dependent code, and adds supportive changes (template updates, environment config, test parameter updates) to maintain consistency.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel

vercel Bot commented Jan 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
crisp Ready Ready Preview, Comment Jan 26, 2026 4:51pm
enclave-docs Ready Ready Preview, Comment Jan 26, 2026 4:51pm

Request Review

@vercel vercel Bot temporarily deployed to Preview – crisp January 22, 2026 21:43 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 22, 2026 21:43 Inactive
@0xjei 0xjei changed the title feat: e3-fhe-params crate feat: e3-fhe-params crate [skip-line-limit] Jan 23, 2026
@0xjei 0xjei requested a review from cedoor January 23, 2026 16:43
@0xjei 0xjei marked this pull request as ready for review January 23, 2026 16:43

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
templates/default/client/src/utils/env-config.ts (1)

13-38: Avoid insecure default preset in production. Defaulting to INSECURE_THRESHOLD_BFV_512 risks silently shipping weak crypto if the env var is omitted. Consider requiring an explicit preset for production (or failing fast when an insecure preset is detected).

🔧 Suggested guard in validation
 export function validateEnvVars(): void {
   if (HAS_MISSING_ENV_VARS) {
     throw new Error(
       `Missing required environment variables: ${MISSING_ENV_VARS.join(', ')}\n` +
         'Please check your .env file and ensure all required variables are set.',
     )
   }
+  if (import.meta.env.PROD && THRESHOLD_BFV_PARAMS_PRESET_NAME.startsWith('INSECURE_')) {
+    throw new Error(
+      'THRESHOLD_BFV_PARAMS_PRESET_NAME must be a secure preset in production.',
+    )
+  }
 }
packages/enclave-react/src/useEnclaveSDK.ts (1)

99-121: Include thresholdBfvParamsPresetName in initializeSDK deps.

initializeSDK closes over config.thresholdBfvParamsPresetName but the dependency array omits it, so preset updates won’t be picked up (stale params). Add the missing dependency.

🔧 Suggested fix
-  }, [publicClient, walletClient, config.contracts, config.chainId])
+  }, [
+    publicClient,
+    walletClient,
+    config.contracts,
+    config.chainId,
+    config.thresholdBfvParamsPresetName,
+  ])

ctrlc03
ctrlc03 previously approved these changes Jan 26, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@crates/tests/tests/integration.rs`:
- Around line 126-127: The comment above the parameter construction incorrectly
states "128bits of security"; update it to accurately reflect that
BfvPreset::InsecureThresholdBfv512 is insecure (or indicate its actual security
level) so it doesn't contradict the lambda warning—locate the params_raw
creation (let params_raw =
BfvParamSet::from(BfvPreset::InsecureThresholdBfv512).build_arc()) and change
the comment to note that this preset is insecure (or remove the 128-bit claim).
🧹 Nitpick comments (1)
crates/tests/tests/integration.rs (1)

421-426: Good correctness fix for FHE modular arithmetic.

The addition of modulo plaintext_modulus ensures expected results correctly reflect FHE computation semantics.

Minor nit: the .clone() on line 422 is unnecessary since Arc<T> implements Deref<Target=T>, allowing direct method calls.

Suggested simplification
     // Show summation result (mod plaintext modulus)
-    let plaintext_modulus = params_raw.clone().plaintext();
+    let plaintext_modulus = params_raw.plaintext();

Comment thread crates/tests/tests/integration.rs
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 26, 2026 15:41 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp January 26, 2026 15:41 Inactive
@0xjei

0xjei commented Jan 26, 2026

Copy link
Copy Markdown
Contributor Author

we currently have the insecure parameters for threshold (TRBFV) to support 10 as plaintext mod. Therefore, I have updated all examples to use values that do not exceed 10 or just checking the result mod the plaintext. This workaround will be fixed when using prod params.

@vercel vercel Bot temporarily deployed to Preview – crisp January 26, 2026 15:46 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 26, 2026 15:46 Inactive
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.

extract parameters into a standalone crate (e3-fhe-params)

3 participants