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

feat: refactor inner-product prover #57

Merged
merged 6 commits into from Aug 24, 2023

Conversation

AaronFeickert
Copy link
Contributor

@AaronFeickert AaronFeickert commented Aug 7, 2023

The inner-product prover is a bit clunky, as it requires the range prover to set up a struct, perform iterative rounds, and then parse out the proof elements it needs. This also requires consistency checks that it would be nicer to avoid.

This PR moves the inner-product prover into the range prover, which simplifies things at the cost of a longer prover function.

It also fixes some vector allocations that were much bigger than necessary.

Closes #61. Closes #55. Supersedes #56.

Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

utACK

@AaronFeickert AaronFeickert changed the title chore: reduce reliance on vector indexing feat: refactor inner-product prover Aug 10, 2023
Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

Nice.

I would like one small change though to not hide the potential panic, so we can use a custom fn checked_split_at<T>(my_vec: &[T], n: usize) instead of pub const fn split_at(&self, mid: usize)

Comment on lines 329 to 333
// Split the vectors for folding
let (a_lo, a_hi) = a_li.split_at(n);
let (b_lo, b_hi) = a_ri.split_at(n);
let (gi_base_lo, gi_base_hi) = gi_base.split_at(n);
let (hi_base_lo, hi_base_hi) = hi_base.split_at(n);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Split the vectors for folding
let (a_lo, a_hi) = a_li.split_at(n);
let (b_lo, b_hi) = a_ri.split_at(n);
let (gi_base_lo, gi_base_hi) = gi_base.split_at(n);
let (hi_base_lo, hi_base_hi) = hi_base.split_at(n);
// Split the vectors for folding
fn checked_split_at<T>(my_vec: &[T], n: usize) -> Result<(&[T], &[T]), ProofError> {
if n <= my_vec.len() {
Ok(my_vec.split_at(n))
} else {
Err(ProofError::InvalidLength("Index out of bounds".to_string()))
}
}
let (a_lo, a_hi) = checked_split_at(&a_li, n)?;
let (b_lo, b_hi) = checked_split_at(&a_ri, n)?;
let (gi_base_lo, gi_base_hi) = checked_split_at(&gi_base, n)?;
let (hi_base_lo, hi_base_hi) = checked_split_at(&hi_base, n)?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't this basically treat the split the same as before from a panic perspective? The slice-based version has the same issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in a new commit.

Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

ACK

@SWvheerden SWvheerden merged commit aa7593f into tari-project:main Aug 24, 2023
5 checks passed
@AaronFeickert AaronFeickert deleted the nix-indexes branch August 24, 2023 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor inner-product prover Consider splitting inner-product vectors idiomatically
4 participants