refactor: update crisp vk hashes#1506
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughCanonicalizes BigInt JSON output to BN254 field representatives for Noir witnesses; replaces a single fold expected key-hash with insecure/secure constants and OR-based check in the Noir circuit; updates the CRISP Solidity verifier VK_HASH and many G1Point coordinate literals. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/zk-helpers/src/utils.rs (1)
309-319: Consider adding edge-case coverage.The test correctly verifies the no-negative invariant, but could be strengthened with additional boundary cases:
💡 Optional: Add edge cases for more robust coverage
#[test] fn bigint_to_json_value_never_emits_negative_for_field_witness() { - let neg = BigInt::from(-13449214110323435_i64); - let v = bigint_to_json_value(&neg); - let as_text = match v { + let test_cases = vec![ + BigInt::from(-1), + BigInt::from(-13449214110323435_i64), + -get_zkp_modulus() + BigInt::from(1), // near modulus boundary + ]; + for neg in test_cases { + let v = bigint_to_json_value(&neg); + let as_text = match v { - serde_json::Value::Number(n) => n.to_string(), - serde_json::Value::String(s) => s, - _ => panic!("expected number or string"), - }; - assert!(!as_text.starts_with('-')); + serde_json::Value::Number(n) => n.to_string(), + serde_json::Value::String(s) => s, + _ => panic!("expected number or string"), + }; + assert!(!as_text.starts_with('-'), "negative output for input: {}", neg); + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/zk-helpers/src/utils.rs` around lines 309 - 319, The test bigint_to_json_value_never_emits_negative_for_field_witness should be extended to cover edge cases: add assertions for BigInt values 0 and -1, a small negative (e.g., -123), a very large negative number beyond i64 (construct via string to test arbitrary precision), and a large positive value to ensure formatting stays non-negative; use the same extraction logic (match on serde_json::Value::Number/String) and assert the resulting string does not start with '-' for all these BigInt inputs when calling bigint_to_json_value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@examples/CRISP/circuits/bin/fold/src/main.nr`:
- Around line 71-75: The current OR-based assertion in main.nr (compute_vk_hash
-> chain_key_hash compared against CRISP_FOLD_EXPECTED_KEY_HASH_INSECURE |
CRISP_FOLD_EXPECTED_KEY_HASH_SECURE) allows insecure keys to be accepted; change
this to enforce a single expected hash selected at build/deploy time: introduce
a compile-time or configuration-driven selector (e.g., a feature flag or
lib::configs::default) that resolves to either
CRISP_FOLD_EXPECTED_KEY_HASH_SECURE or the insecure constant, and replace the OR
assertion with a strict equality check (chain_key_hash ==
SELECTED_EXPECTED_KEY_HASH) in the compute_vk_hash/assert block so production
builds use the secure-only hash by default.
---
Nitpick comments:
In `@crates/zk-helpers/src/utils.rs`:
- Around line 309-319: The test
bigint_to_json_value_never_emits_negative_for_field_witness should be extended
to cover edge cases: add assertions for BigInt values 0 and -1, a small negative
(e.g., -123), a very large negative number beyond i64 (construct via string to
test arbitrary precision), and a large positive value to ensure formatting stays
non-negative; use the same extraction logic (match on
serde_json::Value::Number/String) and assert the resulting string does not start
with '-' for all these BigInt inputs when calling bigint_to_json_value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 65d31f58-05cf-43fb-84b9-97a7496adb2a
📒 Files selected for processing (3)
crates/zk-helpers/src/utils.rsexamples/CRISP/circuits/bin/fold/src/main.nrexamples/CRISP/packages/crisp-contracts/contracts/CRISPVerifier.sol
793237e to
045cb11
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/zk-helpers/src/utils.rs (1)
309-319: Test validates the key invariant correctly.The test appropriately verifies that negative inputs produce non-negative JSON output.
Consider adding a few more edge cases for completeness (optional):
🧪 Suggested additional test cases
#[test] fn bigint_to_json_value_never_emits_negative_for_field_witness() { - let neg = BigInt::from(-13449214110323435_i64); - let v = bigint_to_json_value(&neg); - let as_text = match v { + let test_cases = vec![ + BigInt::from(-1), + BigInt::from(-13449214110323435_i64), + -get_zkp_modulus() + BigInt::from(1), // near -p + ]; + for neg in test_cases { + let v = bigint_to_json_value(&neg); + let as_text = match v { - serde_json::Value::Number(n) => n.to_string(), - serde_json::Value::String(s) => s, - _ => panic!("expected number or string"), - }; - assert!(!as_text.starts_with('-')); + serde_json::Value::Number(n) => n.to_string(), + serde_json::Value::String(s) => s, + _ => panic!("expected number or string"), + }; + assert!(!as_text.starts_with('-'), "negative output for {:?}", neg); + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/zk-helpers/src/utils.rs` around lines 309 - 319, Add additional edge-case tests for bigint_to_json_value to strengthen coverage: include BigInt values such as zero (0), -1, the smallest/ largest values you expect (e.g., i64::MIN and i64::MAX or equivalent BigInt extremes used in your codebase), and a very large magnitude negative and positive BigInt to ensure the output never starts with '-' and is represented as expected; add these as new #[test] functions (or table-driven cases) alongside bigint_to_json_value_never_emits_negative_for_field_witness so failures reference bigint_to_json_value directly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@examples/CRISP/packages/crisp-contracts/contracts/CRISPVerifier.sol`:
- Line 11: VK_HASH in CRISPVerifier.sol (symbol VK_HASH) doesn't match the two
allowed fold-circuit constants (CRISP_FOLD_EXPECTED_KEY_HASH_INSECURE /
CRISP_FOLD_EXPECTED_KEY_HASH_SECURE) and so verify() will feed an unexpected
$VK_HASH into the Fiat–Shamir transcript causing the fold circuit's
chain_key_hash assertion to fail; fix by either regenerating the fold circuit
constants (CRISP_FOLD_EXPECTED_KEY_HASH_INSECURE and
CRISP_FOLD_EXPECTED_KEY_HASH_SECURE in
examples/CRISP/circuits/bin/fold/src/main.nr) from the same build/artifact that
produced this verifier so they match VK_HASH, or revert VK_HASH to one of the
permitted hashes the fold circuit currently accepts, and ensure verify()'s
VK_HASH and the fold circuit's chain_key_hash assertion use the identical
artifact-derived value.
---
Nitpick comments:
In `@crates/zk-helpers/src/utils.rs`:
- Around line 309-319: Add additional edge-case tests for bigint_to_json_value
to strengthen coverage: include BigInt values such as zero (0), -1, the
smallest/ largest values you expect (e.g., i64::MIN and i64::MAX or equivalent
BigInt extremes used in your codebase), and a very large magnitude negative and
positive BigInt to ensure the output never starts with '-' and is represented as
expected; add these as new #[test] functions (or table-driven cases) alongside
bigint_to_json_value_never_emits_negative_for_field_witness so failures
reference bigint_to_json_value directly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7dafdaed-5bf1-434b-9045-132ac6fcf1ec
📒 Files selected for processing (3)
crates/zk-helpers/src/utils.rsexamples/CRISP/circuits/bin/fold/src/main.nrexamples/CRISP/packages/crisp-contracts/contracts/CRISPVerifier.sol
🚧 Files skipped from review as they are similar to previous changes (1)
- examples/CRISP/circuits/bin/fold/src/main.nr
045cb11 to
bdfba25
Compare
Summary by CodeRabbit
Bug Fixes
New Features
Updates
Chores