Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpolation function of the ML sumcheck verifier corrected #75

Merged
merged 5 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
- [\#55](https://github.com/arkworks-rs/sumcheck/pull/55) Improve the interpolation performance and avoid unnecessary state clones.

### Bug fixes

- [\#75](https://github.com/arkworks-rs/sumcheck/pull/75) Correct interpolation function in the verifier

## v0.4.0
- Change dependency to version `0.4.0` of other arkworks-rs crates.

Expand Down
33 changes: 27 additions & 6 deletions src/ml_sumcheck/protocol/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ impl<F: Field> IPForMLSumcheck<F> {
}
}

/// interpolate a uni-variate degree-`p_i.len()-1` polynomial and evaluate this
/// polynomial at `eval_at`:
/// \sum_{i=0}^len p_i * (\prod_{j!=i} (eval_at - j)/(i-j))
/// interpolate the *unique* univariate polynomial of degree *at most*
/// p_i.len()-1 passing through the y-values in p_i at x = 0,..., p_i.len()-1
/// and evaluate this polynomial at `eval_at`. In other words, efficiently compute
/// \sum_{i=0}^{len p_i - 1} p_i[i] * (\prod_{j!=i} (eval_at - j)/(i-j))
Comment on lines +136 to +138
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// p_i.len()-1 passing through the y-values in p_i at x = 0,..., p_i.len()-1
/// and evaluate this polynomial at `eval_at`. In other words, efficiently compute
/// \sum_{i=0}^{len p_i - 1} p_i[i] * (\prod_{j!=i} (eval_at - j)/(i-j))
/// `p_i.len()-1` passing through the y-values in p_i at x = `0`, ..., `p_i.len()-1`
/// and evaluate this polynomial at `eval_at`. In other words, efficiently compute
/// \sum_{i=0}^{len p_i - 1} p_i[i] * (\prod_{j!=i} (eval_at - j)/(i-j))

pub(crate) fn interpolate_uni_poly<F: Field>(p_i: &[F], eval_at: F) -> F {
let len = p_i.len();

Expand All @@ -143,12 +144,24 @@ pub(crate) fn interpolate_uni_poly<F: Field>(p_i: &[F], eval_at: F) -> F {
let mut prod = eval_at;
evals.push(eval_at);

// `prod = \prod_{j} (eval_at - j)`
for e in 1..len {
let tmp = eval_at - F::from(e as u64);
//`prod = \prod_{j} (eval_at - j)`
// we return early if 0 <= eval_at < len, i.e. if the desired value has been passed
let mut check = F::zero();
for i in 1..len {
if eval_at == check {
return p_i[i - 1];
}
check += F::one();

let tmp = eval_at - check;
evals.push(tmp);
prod *= tmp;
}

if eval_at == check {
return p_i[len - 1];
}

let mut res = F::zero();
// we want to compute \prod (j!=i) (i-j) for a given i
//
Expand Down Expand Up @@ -308,5 +321,13 @@ mod test {
let query = F::rand(&mut prng);

assert_eq!(poly.evaluate(&query), interpolate_uni_poly(&evals, query));

// test interpolation when we ask for the value at an x-cordinate
// we are already passing, i.e. in the range 0 <= x < len(values) - 1
let evals = vec![0, 1, 4, 9]
.into_iter()
.map(|i| F::from(i))
.collect::<Vec<F>>();
assert_eq!(interpolate_uni_poly(&evals, F::from(3)), F::from(9));
}
}