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

Simplify code in assemble_shares #661

Closed
ggutoski opened this issue Aug 16, 2024 · 0 comments · Fixed by #657
Closed

Simplify code in assemble_shares #661

ggutoski opened this issue Aug 16, 2024 · 0 comments · Fixed by #657
Assignees
Labels

Comments

@ggutoski
Copy link
Contributor

In file vid/src/advz.rs in function assemble_shares we have the following code snippet:

jellyfish/vid/src/advz.rs

Lines 915 to 932 in 92714a4

let mut shares = Vec::with_capacity(self.num_storage_nodes as usize);
let mut evals = Vec::with_capacity(num_of_polys * self.multiplicity as usize);
let mut proofs = Vec::with_capacity(self.multiplicity as usize);
let mut index = 0;
for i in 0..code_word_size {
evals.extend(all_storage_node_evals[i].iter());
proofs.push(aggregate_proofs[i].clone());
if (i + 1) % self.multiplicity as usize == 0 {
shares.push(Share {
index,
evals: mem::take(&mut evals),
aggregate_proofs: mem::take(&mut proofs),
evals_proof: all_evals_commit // TODO: check MT lookup for each index
.lookup(KzgEvalsMerkleTreeIndex::<E, H>::from(index as u64))
.expect_ok()
.map_err(vid)?
.1,
});

Here evals, proofs are mutable Vecs and we use mem::take to initialize a Share struct. This seems unnecessarily complex and obfuscated to me.

We should be able to eliminate evals, proofs and simply move the relevant data directly into Share::evals, Share::evals_proof something like

evals: all_storage_node_evals[i],
evals_proof: aggregate_proofs[i],

Probably need to loop over a more idiomatic iterator instead of using i to index into these Vecs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants