소스 검색

Dump the outputs of bitrep_scalars_vartime and compute_bitrep to debug wasm range ZKPs

Ian Goldberg 5 달 전
부모
커밋
dd1291c13a
1개의 변경된 파일7개의 추가작업 그리고 2개의 파일을 삭제
  1. 7 2
      src/rangeutils.rs

+ 7 - 2
src/rangeutils.rs

@@ -83,7 +83,7 @@ pub fn bitrep_scalars_vartime<S: PrimeField>(upper: S) -> Result<Vec<S>, Error>
 
 
     // Make the vector of Scalars containing the represented value of
     // Make the vector of Scalars containing the represented value of
     // the bits
     // the bits
-    Ok((0..nbits)
+    let res = Ok((0..nbits)
         .map(|i| {
         .map(|i| {
             if i < nbits - 1 {
             if i < nbits - 1 {
                 S::from_u128(1u128 << i)
                 S::from_u128(1u128 << i)
@@ -92,7 +92,10 @@ pub fn bitrep_scalars_vartime<S: PrimeField>(upper: S) -> Result<Vec<S>, Error>
                 S::from_u128(upper_val - (1u128 << (nbits - 1)))
                 S::from_u128(upper_val - (1u128 << (nbits - 1)))
             }
             }
         })
         })
-        .collect())
+        .collect());
+    super::dumper::dump(&format!("res = {res:?}\n"));
+
+    res
 }
 }
 
 
 /// Given a vector of [`Scalar`]s as output by
 /// Given a vector of [`Scalar`]s as output by
@@ -113,6 +116,7 @@ pub fn compute_bitrep<S: PrimeField>(mut x: S, bitrep_scalars: &[S]) -> Vec<Choi
     // Decompose `x` as a normal `nbit`-bit vector.  This only looks at
     // Decompose `x` as a normal `nbit`-bit vector.  This only looks at
     // the low `nbits` bits of `x`, so the resulting bit vector forces
     // the low `nbits` bits of `x`, so the resulting bit vector forces
     // `x < 2^{nbits}`.
     // `x < 2^{nbits}`.
+    super::dumper::dump(&format!("x = {x:?}\n"));
     let x_raw_bits = bit_decomp(x, nbits);
     let x_raw_bits = bit_decomp(x, nbits);
     let high_bit = x_raw_bits[(nbits as usize) - 1];
     let high_bit = x_raw_bits[(nbits as usize) - 1];
 
 
@@ -130,6 +134,7 @@ pub fn compute_bitrep<S: PrimeField>(mut x: S, bitrep_scalars: &[S]) -> Vec<Choi
     // and tack on the high bit
     // and tack on the high bit
     x_bits.push(high_bit);
     x_bits.push(high_bit);
 
 
+    super::dumper::dump(&format!("x_bits = {x_bits:?}\n"));
     x_bits
     x_bits
 }
 }