Skip to content

Allow to owned on coeff sumcheck prover#102

Merged
z-tech merged 1 commit into
mainfrom
z-tech/coeff_finalize_method
Apr 28, 2026
Merged

Allow to owned on coeff sumcheck prover#102
z-tech merged 1 commit into
mainfrom
z-tech/coeff_finalize_method

Conversation

@z-tech
Copy link
Copy Markdown
Collaborator

@z-tech z-tech commented Apr 28, 2026

Summary

Add finalize(self) -> (Vec<Vec<Vec<F>>>, Vec<Vec<F>>) to CoefficientProver and CoefficientProverLSB, alongside the existing borrow accessors. Lets downstream callers extract the post-sumcheck reduced state by move instead of cloning out of a borrow.

Before

CoefficientProver{,LSB} own their working buffers (tablewise: Vec<Vec<Vec<F>>>, pairwise: Vec<Vec<F>>) but expose them only behind &self accessors. Callers that have finished sumcheck and need the folded state — to feed a witness, embed in a transcript, hand to a downstream protocol — cannot take it. They must clone:

let reduced_tw = sc.tablewise();           // &[Vec<Vec<F>>] — borrow
let witness_a = reduced_tw[0][0].clone();  // clone, because we only have &
let witness_b = reduced_tw[1][0].clone();  // clone
// sc still alive, never used again

Each .clone() is a heap allocation plus k field-element copies (k = constraint arity). The pattern itself is a Rust API smell: a borrow returned solely so the caller can immediately clone it back to owned. The library knows the prover won't be used again. The caller knows. The type system can't express "transfer ownership of the post-fold buffers."

This isn't unique to one downstream — anyone composing CoefficientProverLSB into a larger proof system hits the identical shape (run sumcheck, extract reduced state, feed next phase, drop prover).

After

pub fn finalize(self) -> (Vec<Vec<Vec<F>>>, Vec<Vec<F>>) {
    (self.tablewise, self.pairwise)
}

Canonical Rust pattern: foo(&self) -> &T for inspection, consume-and-return for extraction. Single method returning both buffers in a tuple, so callers can't accidentally try to move out the same prover twice:

let (reduced_tw, _) = sc.finalize();   // by move, no clone, sc consumed

The &self accessors stay — they remain correct for inspection / asserts / debugging mid-sumcheck. Existing call sites compile unchanged.

@z-tech z-tech merged commit fe5c8da into main Apr 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant