-
Notifications
You must be signed in to change notification settings - Fork 1
feat(security): increase LWE noise sigma to 25.0 #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Update Rust generator to use secure entropy (OsRng) for LWE/Puzzle noise - Refactor to accept external RNG - Update Benchmark script to use separate noise seed with warning - Add task documentation for Issue #65 fix
- Increases standard deviation from 8.0 to 25.0 - Enhances resistance against lattice reduction attacks - Error margin (4*sigma = 100) is still well below threshold (16380) - No impact on gas costs or storage size
|
WalkthroughA cryptographic security fix decoupling noise generation from public seeds to prevent secret recovery. Changes include introducing independent entropy sources (noiseSeed parameter in Solidity, RNG parameter in Rust), externalizing RNG handling in the generator, and increasing the Gaussian noise standard deviation from 8.0 to 25.0 for hardened security. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5567b72dae
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /// Gaussian noise standard deviation (σ=25). | ||
| pub const NOISE_SIGMA: f64 = 25.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update estimator sigma to match new NOISE_SIGMA
With NOISE_SIGMA now set to 25, the security estimation helper estimate_main_lwe_security in src/security/lattice_estimator.rs still hardcodes stddev: 8.0, so anyone running the estimator for documentation or audit numbers will compute the old σ=8 security margin rather than the new σ=25 parameters. Consider wiring the estimator to NOISE_SIGMA (or updating the constant there) to keep security results accurate.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
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)
src/lwe.rs (1)
1-4: Update module documentation to reflect σ=25.The module-level doc comment on line 3 still references σ=8, but the actual
NOISE_SIGMAconstant has been changed to 25.0. This creates a documentation-code mismatch.Proposed fix
//! Layer 2: LWE encryption for control function hiding. //! -//! Uses standard LWE with Gaussian noise (n=384, q=65521, σ=8) providing +//! Uses standard LWE with Gaussian noise (n=384, q=65521, σ=25) providing //! ~2^112 post-quantum security against lattice attacks.scripts/BenchmarkTLOS.s.sol (1)
44-44: Update sigma value in log message.The console log still references
sigma=8, butNOISE_SIGMAinsrc/lwe.rshas been changed to 25.0 in this PR.Proposed fix
- console.log("LWE Dimension: n=384, sigma=8 (~2^112 PQ security)"); + console.log("LWE Dimension: n=384, sigma=25 (~2^112 PQ security)");
🧹 Nitpick comments (1)
docs/tasks/issue-65-secret-noise-fix.md (1)
29-49: Optional: Adjust nested list indentation to 2 spaces.Static analysis flagged inconsistent list indentation (4 spaces instead of the preferred 2 spaces per MD007). This is purely cosmetic and won't affect rendering.
Example fix for one section
### 1. Rust Generator (`src/`) - **`src/lwe.rs`**: - - Review `encrypt_bit` and `encrypt_bit_seeded`. - - Ensure that while `A` is derived from the seed, the `Rng` passed for noise generation is initialized with true entropy (or a secret), not the public circuit seed. + - Review `encrypt_bit` and `encrypt_bit_seeded`. + - Ensure that while `A` is derived from the seed, the `Rng` passed for noise generation is initialized with true entropy (or a secret), not the public circuit seed.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
docs/tasks/issue-65-secret-noise-fix.mdscripts/BenchmarkTLOS.s.solsrc/bin/generate_tlos.rssrc/generator.rssrc/lwe.rs
🧰 Additional context used
📓 Path-based instructions (5)
src/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Rust implementation must have modular structure: circuit.rs for topology layer mixing, lwe.rs for LWE encryption, wire_binding.rs for algebraic binding, and generator.rs for deployment data generation
Files:
src/generator.rssrc/lwe.rs
{**/*.sol,src/lwe.rs}
📄 CodeRabbit inference engine (AGENTS.md)
Production LWE layer must use parameters: n=384 dimension, σ=8 Gaussian noise, q=65521 modulus, achieving ~2^112 PQ security
Files:
src/lwe.rsscripts/BenchmarkTLOS.s.sol
**/*.sol
📄 CodeRabbit inference engine (AGENTS.md)
**/*.sol: Use Forge for building and testing Solidity contracts with commands:forge buildfor compilation andforge testfor running tests
Solidity contracts must use seed-derived a vectors with 11 bytes per gate for storage optimization
Files:
scripts/BenchmarkTLOS.s.sol
{**/*.sol,src/wire_binding.rs}
📄 CodeRabbit inference engine (AGENTS.md)
Layer 3 wire binding must implement full-rank 64x64 linear hash over Z_q for inter-gate algebraic consistency; do NOT claim collision resistance as the linear system is trivially solvable
Files:
scripts/BenchmarkTLOS.s.sol
scripts/Benchmark*.s.sol
📄 CodeRabbit inference engine (AGENTS.md)
Benchmark scripts must use Tenderly RPC by sourcing
~/.zsh_secretsand running:forge script scripts/BenchmarkTLOS.s.sol --rpc-url "$TENDERLY_RPC" --broadcast --unlocked -vvv
Files:
scripts/BenchmarkTLOS.s.sol
🧠 Learnings (10)
📓 Common learnings
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to {**/*.sol,src/lwe.rs} : Production LWE layer must use parameters: n=384 dimension, σ=8 Gaussian noise, q=65521 modulus, achieving ~2^112 PQ security
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to contracts/*.sol : Hash-PoW layer must provide commit-time randomness bound with configurable difficulty and default enabled state for Layer 5 security
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Five-layer security model must be implemented in order: (1) Topology layer - structural mixing, (2) LWE layer - control function hiding, (3) Wire binding layer - algebraic binding, (4) Planted LWE puzzle - 2^76 search space, (5) Hash-PoW - commit-time randomness (default enabled)
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to **/*.sol : Solidity contracts must use seed-derived a vectors with 11 bytes per gate for storage optimization
📚 Learning: 2026-01-13T11:05:17.527Z
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to src/*.rs : Rust implementation must have modular structure: circuit.rs for topology layer mixing, lwe.rs for LWE encryption, wire_binding.rs for algebraic binding, and generator.rs for deployment data generation
Applied to files:
src/generator.rs
📚 Learning: 2026-01-13T11:05:17.527Z
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to {**/*.sol,src/wire_binding.rs} : Layer 3 wire binding must implement full-rank 64x64 linear hash over Z_q for inter-gate algebraic consistency; do NOT claim collision resistance as the linear system is trivially solvable
Applied to files:
src/generator.rs
📚 Learning: 2026-01-13T11:05:17.527Z
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to {**/*.sol,src/lwe.rs} : Production LWE layer must use parameters: n=384 dimension, σ=8 Gaussian noise, q=65521 modulus, achieving ~2^112 PQ security
Applied to files:
src/generator.rsdocs/tasks/issue-65-secret-noise-fix.mdsrc/lwe.rs
📚 Learning: 2026-01-13T11:05:17.527Z
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Five-layer security model must be implemented in order: (1) Topology layer - structural mixing, (2) LWE layer - control function hiding, (3) Wire binding layer - algebraic binding, (4) Planted LWE puzzle - 2^76 search space, (5) Hash-PoW - commit-time randomness (default enabled)
Applied to files:
docs/tasks/issue-65-secret-noise-fix.mdscripts/BenchmarkTLOS.s.sol
📚 Learning: 2026-01-13T11:05:17.527Z
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to contracts/WeakLWEPuzzle*.sol : Testing puzzle variants must include WeakLWEPuzzleV5 (n=32, 2^51 security), WeakLWEPuzzleV6 (n=24, 2^38 security), and WeakLWEPuzzleV7 (n=48, 2^76 security) for parameter validation
Applied to files:
docs/tasks/issue-65-secret-noise-fix.mdscripts/BenchmarkTLOS.s.sol
📚 Learning: 2026-01-13T11:05:17.527Z
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to scripts/Benchmark*.s.sol : Benchmark scripts must use Tenderly RPC by sourcing `~/.zsh_secrets` and running: `forge script scripts/BenchmarkTLOS.s.sol --rpc-url "$TENDERLY_RPC" --broadcast --unlocked -vvv`
Applied to files:
scripts/BenchmarkTLOS.s.sol
📚 Learning: 2026-01-13T11:05:17.527Z
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to **/{WeakLWEPuzzleV7,*Puzzle*}.sol : Production Layer 4 puzzle (WeakLWEPuzzleV7) must use: n=48 secret dimension, m=72 samples, q=2039 modulus, error range {-2,-1,0,1,2}, threshold=300, ensuring 3^48 ≈ 2^76 search space
Applied to files:
scripts/BenchmarkTLOS.s.sol
📚 Learning: 2026-01-13T11:05:17.527Z
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to **/*.sol : Solidity contracts must use seed-derived a vectors with 11 bytes per gate for storage optimization
Applied to files:
scripts/BenchmarkTLOS.s.sol
📚 Learning: 2026-01-13T11:05:17.527Z
Learnt from: CR
Repo: igor53627/tlos PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-13T11:05:17.527Z
Learning: Applies to test/*.t.sol : Test contracts must include comprehensive layer-specific tests: production contract tests in TLOSWithPuzzleV5.t.sol (61 tests), isolated layer testing via TLOSWithPuzzleV5Harness.sol, and puzzle variant tests in PuzzleVariants.t.sol (12 tests covering V5/V6/V7)
Applied to files:
scripts/BenchmarkTLOS.s.sol
🧬 Code graph analysis (1)
src/bin/generate_tlos.rs (1)
src/generator.rs (1)
generate_tlos(28-81)
🪛 markdownlint-cli2 (0.18.1)
docs/tasks/issue-65-secret-noise-fix.md
31-31: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
32-32: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
34-34: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
35-35: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
39-39: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
40-40: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
41-41: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
42-42: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
43-43: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
48-48: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
49-49: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Cursor Bugbot
🔇 Additional comments (7)
src/lwe.rs (1)
28-29: Verify σ=25 against documented security parameters.This change increases
NOISE_SIGMAfrom 8.0 to 25.0. The PR objectives state this improves security margins while preserving correctness (4σ=100 << q/4≈16380).However, the coding guidelines specify: "Production LWE layer must use parameters: n=384 dimension, σ=8 Gaussian noise, q=65521 modulus, achieving ~2^112 PQ security."
Please confirm whether the coding guidelines should be updated to reflect this new parameter, or if there are considerations that require keeping σ=8 in certain contexts. Based on learnings, the documented spec requires σ=8.
src/bin/generate_tlos.rs (1)
29-30: LGTM! Secure RNG usage for noise generation.Using
thread_rng()(which wrapsOsRngfor cryptographic security) properly decouples noise generation from the publiccircuit_seed. This addresses the security vulnerability where deterministic noise from public seeds would allow secret recovery.scripts/BenchmarkTLOS.s.sol (2)
52-58: LGTM! Good security documentation and noise seed separation.The warning comment clearly documents that production must use true entropy, and the separate
noiseSeedproperly decouples noise generation from the puzzle seed. This prevents the algebraic attack vector described in issue#65.
120-154: LGTM! Correct noise/matrix seed separation.The implementation correctly:
- Derives
Amatrix coefficients from the publicseed(line 124, 129)- Derives error
efrom the separatenoiseSeed(line 142)This aligns with the security requirements: public seeds for reproducible
A, independent entropy for noisee.src/generator.rs (2)
22-32: LGTM! Well-designed RNG externalization.The generic
R: Rngparameter provides flexibility for both:
- Production: callers can pass
OsRngorthread_rng()for cryptographic security- Testing: callers can pass a seeded
ChaCha20Rngfor deterministic reproducibilityThe doc comment on line 27 appropriately emphasizes that the RNG MUST be cryptographically secure for production use.
141-156: LGTM! Good test coverage for deterministic generation.The test correctly verifies that identical RNG seeds produce identical outputs, confirming the externalized RNG approach enables reproducible generation when needed (e.g., for testing or debugging).
docs/tasks/issue-65-secret-noise-fix.md (1)
1-54: LGTM! Clear and thorough security documentation.This task document effectively:
- Explains the vulnerability (deterministic noise from public seeds enables secret recovery)
- Documents the required fix (decouple noise from public matrix generation)
- Provides implementation guidance for both Rust and Solidity components
- Lists clear acceptance criteria
The implementation changes in this PR align well with this documented plan.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
|
Confimred via local Forge simulation that increasing |
* feat(security): harden puzzle layer params (n=128, m=192) - Increase Layer 4 puzzle parameters: - Secret dimension: n=48 → n=128 - Samples: m=72 → m=192 - Threshold: 300 → 800 - Search space: 3^48 (~2^76) → 3^128 (~2^203 brute-force) - Update contracts: TLOSWithPuzzleV5.sol, WeakLWEPuzzleV7.sol - Update examples: TLOSDeadManSwitch, TLOSRecovery, TLOSSealedAuction, TLOSTreasureHunt - Update tests with int8[128] arrays and gas threshold assertions - Update docs: AGENTS.md, README.md, docs/layers/layer4-puzzle/ - Add build artifacts to .gitignore Gas: ~8.6M puzzle verification (14% of 60M block limit) All 157 tests passing. Closes #70 * Add Wycheproof-style vectors and test runner * docs: update Layer 4 security docs with GPU benchmark results - Add dictionary attack benchmarks (A100: 5.8M guesses/sec, 0.17µs/guess) - Remove misleading 'unless rate-limited' caveats (doesn't apply offline) - Add explicit attack cost formula: |Dictionary| × 0.17µs (GPU) - Clarify 3^128 floor applies to planted-solution recovery only - Recommend high-entropy secrets for offline security - Add modal_puzzle_benchmark.py for reproducible benchmarks - Add KANBAN.md for tracking Addresses reviewer concern in issue #65 comment 3753688226 Amp-Thread-ID: https://ampcode.com/threads/T-019bc5e7-3901-7776-9a43-4adb6762c244 Co-authored-by: Amp <amp@ampcode.com> * docs: clarify hash_solution comment for Solidity fixed-size array encoding * fix: address PR #74 review nits - update benchmark script, comments, and docs - scripts/BenchmarkTLOS.s.sol: Update puzzle params n=128, m=192 - examples/TLOSSealedAuction.sol: Fix comment int8[64] -> int8[128] - README.md: Fix lattice estimator stddev 8.0 -> 25.0 * fix: update lattice_estimator.rs stddev 8.0 -> 25.0 to match production params PR #69 increased NOISE_SIGMA from 8.0 to 25.0 but the estimator still hardcoded the old value. Fixes AI review nit from PR #69. * chore: stop tracking generated artifacts * docs: note PR description newline rule * docs: align security params and tidy markdown * docs: update Tenderly deploy costs * chore: set benchmark expiry to max * chore: ignore docs plans * chore: keep docs plans untracked --------- Co-authored-by: Igor <igor53627@users.noreply.github.com> Co-authored-by: Amp <amp@ampcode.com>
Closes #68
Increases the LWE noise standard deviation (
σ) from8.0to25.0to improve security margins against lattice attacks.Verification:
BenchmarkTLOS.s.sol).4σ ≈ 100) is negligible compared to the decryption threshold (q/4 ≈ 16380).Note
Strengthens LWE security by removing deterministic noise tied to public seeds and increasing noise variance.
generate_tlosnow accepts an injectedRngfor noise; removed seeding noise fromcircuit_seed. Updatedsrc/bin/generate_tlos.rsto usethread_rng, and tests to pass seededChaCha20Rng.lwe.rssetsNOISE_SIGMAto25.0and threads RNG throughencode_gate/encrypt_bit_seeded.BenchmarkTLOS.s.soladds a distinctnoiseSeedand updates_generateBVectorto takenoiseSeed, decouplingefrompuzzleSeedwith clear warnings.docs/tasks/issue-65-secret-noise-fix.mdoutlining the vulnerability and required decoupling ofefrom public seeds.Written by Cursor Bugbot for commit 5567b72. Configure here.
Summary by CodeRabbit
Bug Fixes
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.