Check at compile time that the packing moduli are odd

Open Beginner friendly
#46 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
cryptography

Research direction

Read the modulus constants in src/rings.rs and the existing compile time assertions in src/cs.rs. Add oddness assertions for CS_MODULUS and KAHE_MODULUS in src/rings.rs, plus HVC_MODULUS in src/cs.rs; done when all three checks compile and reject an even modulus with the stated message.

Written by the indexing model from the issue text.

Description

Since #24, polynomials are packed as centered representatives in [-(m-1)/2, (m-1)/2], and poly_packed_len/poly_packed_len64 compute the bound as modulus / 2. Both are only exact for an odd modulus, as their doc comments say, but nothing checks it.

With an even modulus, packing still round-trips, but every coefficient takes ⌈log₂(m+1)⌉ bits, which is one bit more than needed when m is a power of two. The tests would catch that for the real moduli. A compile-time check next to the constants in src/rings.rs would document the precondition and reject such a change with a clear message:

const _: () = assert!(CS_MODULUS % 2 == 1, "centered packing needs an odd modulus");
const _: () = assert!(KAHE_MODULUS % 2 == 1, "centered packing needs an odd modulus");

plus the same for HVC_MODULUS, which comes from chipmunk_code, in src/cs.rs.

Related checks:

  • src/cs.rs already asserts at compile time that CS_MODULUS and HVC_MODULUS are prime, for the batch soundness argument. That rules out every even modulus except 2, but it says nothing about packing and doesn't cover KAHE_MODULUS.
  • #41 adds a compile-time check that KAHE_MODULUS fits the 56-bit packers. The oddness check could go next to it.
  • #45, making items pub(crate), would keep outside callers from passing other moduli to poly_packed_len. This one is about the crate's own constants.

Prompt:

report an issue to add the const _: () = assert!(CS_MODULUS % 2 == 1) check

Created together with Claude Opus 5.5 🧮✅

Dominant language
Rust
Stars
1
Forks
2
Avg merge
6d 14h
Merged PRs (30d)
11

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from flashbots/panetiere

All issues in flashbots/panetiere

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.