|
1 | | -//! Implementation of the CycleFold-based IVC compiler. |
| 1 | +//! Implementation of the CycleFold-based IVC compiler as described in this |
| 2 | +//! [paper]. |
2 | 3 | //! |
3 | 4 | //! It turns any compatible folding scheme into a full IVC scheme by running the |
4 | 5 | //! primary circuit on one curve and a "CycleFold" circuit on the secondary |
5 | 6 | //! curve to handle emulated elliptic curve operations. |
| 7 | +//! |
| 8 | +//! [paper]: https://eprint.iacr.org/2023/1192.pdf |
6 | 9 |
|
7 | | -use ark_ff::Zero; |
| 10 | +use ark_ff::field_hashers::hash_to_field; |
8 | 11 | use ark_relations::gr1cs::{ConstraintSystem, SynthesisError}; |
9 | | -use ark_std::{borrow::Borrow, marker::PhantomData, rand::RngCore}; |
| 12 | +use ark_serialize::CanonicalSerialize; |
| 13 | +use ark_std::{ |
| 14 | + borrow::Borrow, |
| 15 | + io::{Error as IoError, Write}, |
| 16 | + marker::PhantomData, |
| 17 | + rand::RngCore, |
| 18 | +}; |
| 19 | +use sha3::{ |
| 20 | + Shake128, |
| 21 | + digest::{ExtendableOutput, Update}, |
| 22 | +}; |
10 | 23 | use sonobe_fs::{ |
11 | 24 | DeciderKey, FoldingInstance, FoldingSchemeDef, FoldingSchemeDefGadget, |
12 | 25 | FoldingSchemeFullVerifierGadget, FoldingSchemePartialVerifierGadget, |
@@ -214,7 +227,28 @@ where |
214 | 227 | let dk1 = FS1::generate_keys(pp1, arith1)?; |
215 | 228 | let dk2 = FS2::generate_keys(pp2, arith2)?; |
216 | 229 |
|
217 | | - let pp_hash = Zero::zero(); // TODO |
| 230 | + struct HashMarshaller<'a>(&'a mut Shake128); |
| 231 | + |
| 232 | + impl Write for HashMarshaller<'_> { |
| 233 | + #[inline] |
| 234 | + fn write(&mut self, buf: &[u8]) -> Result<usize, IoError> { |
| 235 | + self.0.update(buf); |
| 236 | + Ok(buf.len()) |
| 237 | + } |
| 238 | + |
| 239 | + #[inline] |
| 240 | + fn flush(&mut self) -> Result<(), IoError> { |
| 241 | + Ok(()) |
| 242 | + } |
| 243 | + } |
| 244 | + |
| 245 | + let pp_hash = { |
| 246 | + let mut shake = Shake128::default(); |
| 247 | + dk1.serialize_compressed(HashMarshaller(&mut shake))?; |
| 248 | + dk2.serialize_compressed(HashMarshaller(&mut shake))?; |
| 249 | + hash_config.serialize_compressed(HashMarshaller(&mut shake))?; |
| 250 | + hash_to_field::<_, _, 128>(&mut shake.finalize_xof()) |
| 251 | + }; |
218 | 252 |
|
219 | 253 | Ok(( |
220 | 254 | Key(dk1.clone(), dk2.clone(), (hash_config.clone(), pp_hash)), |
|
0 commit comments