Add logup lookup circuit example with split-commitments#102
Add logup lookup circuit example with split-commitments#102
Conversation
Co-authored-by: srinathsetty <14947526+srinathsetty@users.noreply.github.com>
| let mut table = Vec::with_capacity(TABLE_SIZE); | ||
| for i in 0..TABLE_SIZE { | ||
| let val = E::Scalar::from(i as u64); | ||
| let allocated = AllocatedNum::alloc(cs.namespace(|| format!("table[{}]", i)), || Ok(val))?; |
There was a problem hiding this comment.
@copilot We need to enforce that that the variable holds the constant we expect it with an R1CS constraint.
There was a problem hiding this comment.
Added R1CS constraints to enforce table values are constants in commit 52ce870.
examples/logup_lookup.rs
Outdated
| let mut result = Vec::new(); | ||
|
|
||
| // Add a public input (table size) | ||
| let table_size_scalar = E::Scalar::from(TABLE_SIZE as u64); |
There was a problem hiding this comment.
This seems unnecessary.
There was a problem hiding this comment.
Removed in commit 52ce870 - now returning empty vector and relying on table_size public input to satisfy num_inputs > num_challenges.
Implements a circuit demonstrating: - Split commitments (shared and precommitted sections) - Logup-style lookup argument with table and counts - R1CS constraints for verifying lookup correctness Note: Currently uses a fixed challenge value instead of deriving it from the Fiat-Shamir transcript. Further investigation needed to properly integrate with Spartan's challenge mechanism for full correctness. The circuit compiles and generates a proof but verification currently fails at the PCS layer, indicating the need for additional debugging of the constraint formulation or witness generation. Co-authored-by: srinathsetty <14947526+srinathsetty@users.noreply.github.com>
examples/logup_lookup.rs
Outdated
| cs.namespace(|| "table_size_public"), | ||
| || Ok(table_size_scalar), | ||
| )?; | ||
| // Add a constraint to ensure it's the correct value |
There was a problem hiding this comment.
This seems unnecessary.
There was a problem hiding this comment.
Removed in commit 52ce870 - replaced with table_size public input that has proper constant check constraint.
examples/logup_lookup.rs
Outdated
| assert_eq!(counts.len(), TABLE_SIZE); | ||
|
|
||
| // Get the challenge value - use ZERO during setup | ||
| let challenge = challenges.and_then(|c| c.first().copied()).unwrap_or(E::Scalar::ZERO); |
There was a problem hiding this comment.
We need to allocate the challenge as a variable.
There was a problem hiding this comment.
Challenge is now allocated as a public input variable using alloc_input() in commit 52ce870, following the pattern from zk.rs.
examples/logup_lookup.rs
Outdated
| })?; | ||
|
|
||
| // Add constraint: hint * (table_val + challenge) = count | ||
| // Rewrite as: hint * table_val = count - hint * challenge |
There was a problem hiding this comment.
This requires two constraints to check each hint here since challenge needs to be an allocated variable.
There was a problem hiding this comment.
The hint verification now uses two constraints per hint: first constraint enforces val_plus_c = val + challenge, second constraint enforces hint * val_plus_c = target. This approach keeps challenge as a variable throughout. See commit 52ce870.
examples/logup_lookup.rs
Outdated
| .iter() | ||
| .try_fold(E::Scalar::ZERO, |acc, inv| { | ||
| inv.get_value().map(|v| acc + v) | ||
| }); |
There was a problem hiding this comment.
We can avoid computing lhs_sum and rhs_sum since R1CS allows arbitrary linear combinations.
There was a problem hiding this comment.
Eliminated lhs_sum and rhs_sum intermediate variables in commit 52ce870. The equality check now directly compares the sum of lhs_inverses with the sum of rhs_numerators using linear combinations.
Added comprehensive documentation explaining: - Circuit structure with shared and precommitted sections - Logup identity being verified - Implementation approach using intermediate variables - Known issues and debugging status The example demonstrates the key concepts of split-commitments and lookup arguments even though full verification is pending. Co-authored-by: srinathsetty <14947526+srinathsetty@users.noreply.github.com>
|
@copilot address comments. |
…imizations - Add R1CS constraints to enforce table values are constants - Remove unnecessary dummy public input (replaced with table_size) - Use num_challenges() = 1 for Fiat-Shamir challenge - Allocate challenge as public input variable (not auxiliary) - Eliminate intermediate sum variables, use direct linear combinations - Challenge now properly integrated with transcript Still investigating PCS verification failure. Co-authored-by: srinathsetty <14947526+srinathsetty@users.noreply.github.com>
Implements a circuit demonstrating split-commitments with a lookup table using the logup randomized check, as specified in the problem statement.
Circuit Structure
num_challenges()mechanismsum_i {1/(L[i] + c)} = sum_j {counts[j]/(T[j] + c)}Implementation
The circuit properly integrates with Spartan's challenge mechanism:
alloc_input(), enabling it to be used in R1CS constraintsval_plus_c = val + challenge(ensures correct sum computation)hint * val_plus_c = target(verifies the inverse)Known Issues
Circuit compiles and generates proofs but fails PCS verification. This requires further investigation of witness computation with zero challenge value during setup phase.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.