pad two IPA instances to the same size when folding (#103)
Srinath Setty srinath@microsoft.com
Wed, 27 Jul 2022 22:21:47 -0700
1 files changed,
27 insertions(+),
1 deletions(-)
jump to
M
src/spartan_with_ipa_pc/ipa.rs
→
src/spartan_with_ipa_pc/ipa.rs
@@ -2,7 +2,7 @@ #![allow(clippy::too_many_arguments)]
use crate::commitments::{CommitGens, CommitTrait, Commitment, CompressedCommitment}; use crate::errors::NovaError; use crate::traits::{AppendToTranscriptTrait, ChallengeTrait, Group}; -use core::iter; +use core::{cmp::max, iter}; use ff::Field; use merlin::Transcript; use rayon::prelude::*;@@ -35,6 +35,16 @@ b_vec: b_vec.to_vec(),
c: *c, } } + + pub fn pad(&self, n: usize) -> InnerProductInstance<G> { + let mut b_vec = self.b_vec.clone(); + b_vec.resize(n, G::Scalar::zero()); + InnerProductInstance { + comm_a_vec: self.comm_a_vec, + b_vec, + c: self.c, + } + } } pub struct InnerProductWitness<G: Group> {@@ -47,6 +57,12 @@ InnerProductWitness {
a_vec: a_vec.to_vec(), } } + + pub fn pad(&self, n: usize) -> InnerProductWitness<G> { + let mut a_vec = self.a_vec.clone(); + a_vec.resize(n, G::Scalar::zero()); + InnerProductWitness { a_vec } + } } /// A non-interactive folding scheme (NIFS) for inner product relations@@ -67,6 +83,12 @@ W2: &InnerProductWitness<G>,
transcript: &mut Transcript, ) -> (Self, InnerProductInstance<G>, InnerProductWitness<G>) { transcript.append_message(b"protocol-name", Self::protocol_name()); + + // pad the instances and witness so they are of the same length + let U1 = U1.pad(max(U1.b_vec.len(), U2.b_vec.len())); + let U2 = U2.pad(max(U1.b_vec.len(), U2.b_vec.len())); + let W1 = W1.pad(max(U1.b_vec.len(), U2.b_vec.len())); + let W2 = W2.pad(max(U1.b_vec.len(), U2.b_vec.len())); // add the two commitments and two public vectors to the transcript U1.comm_a_vec@@ -119,6 +141,10 @@ U2: &InnerProductInstance<G>,
transcript: &mut Transcript, ) -> InnerProductInstance<G> { transcript.append_message(b"protocol-name", Self::protocol_name()); + + // pad the instances so they are of the same length + let U1 = U1.pad(max(U1.b_vec.len(), U2.b_vec.len())); + let U2 = U2.pad(max(U1.b_vec.len(), U2.b_vec.len())); // add the two commitments and two public vectors to the transcript U1.comm_a_vec