refactor(fs): return named structs from fold APIs - #251
Conversation
| pub struct FoldStep<FS: FoldingSchemeDef + ?Sized, const M: usize, const N: usize> { | ||
| /// The next running witness after folding. | ||
| pub next_running_witness: FS::RW, | ||
| /// The next running instance after folding. | ||
| pub next_running_instance: FS::RU, | ||
| /// The proof artifact emitted by the folding step. | ||
| pub proof: FS::Proof<M, N>, | ||
| /// The challenge derived during the folding step. | ||
| pub challenge: FS::Challenge, | ||
| } |
There was a problem hiding this comment.
While I think your idea of replacing it with a struct FoldStep is very nice, I have some (nitpicky) concern about the semantics of the naming of its fields in different contexts.
The current naming makes perfect sense in IVC, where there is only a single chain of execution, so "next" is clearly defined here. But for other use cases this may not be very suitable, for example, when a blinding folding scheme is used to hide witness w, we generate (W', U') by folding (w, u) into a random satisfying (W, U) pair, where the resulting (W', U') is essentially a randomized version of (w, u), but not the "next" witness-instance pair.
Do you think you can use a typed alias instead, or replace "next" with "folded" or something similar?
There was a problem hiding this comment.
Hey @junbyjun1238, thank you a lot for your contribution and super sorry for the very late response!
I fully agree with you that having complex returning types is not a very elegant idea, and I have been thinking about solutions that can improve this ultimately, which leads to this PR.
Specifically, Challenges are now eliminated, thanks to the introduction of RecordingTranscript and ReplayTranscript, which allow us to save and replay challenges without passing them throughout the protocols: now (RW, RU, Proof, Challenge) becomes (RW, RU, Proof), and (RU, Challenge) becomes simply RU.
Since #261 will be merged to the staging branch, could you target staging instead of dev?
|
Thanks a lot for the detailed review. I agree that I'll close this one for now, and revisit the remaining tuple-return shape on top of |
This PR replaces tuple-returning fold outputs with named structs and updates the relevant CycleFold call sites to use the new named results.
This is a breaking API cleanup that makes fold artifacts explicit by name across the folding-scheme interfaces.
Note to reviewers: Because this replaces the signatures of the canonical folding traits, the migration necessarily updates the current fs implementations (Nova, HyperNova, Mova, Ova, and ProtoGalaxy) and the downstream CycleFold consumers. Most of the resulting churn is mechanical.
Why:
(RW, RU, Proof, Challenge)and(RU, Challenge)through some of its most complex code paths.What changes:
FoldingSchemeProver::prove(...)to returnFoldStepFoldingSchemePartialVerifierGadget::verify_hinted(...)to returnPartialVerifierStepTesting:
cargo test -p sonobe-fscargo test -p sonobe-ivcReferences:
provereturns the challenge explicitly for CycleFold:crates/fs/src/definitions/algorithms.rs#L33-L59
verify_hintedis intentionally a partial verifier:crates/fs/src/definitions/circuits.rs#L9-L35
crates/ivc/src/compilers/cyclefold/mod.rs#L248-L312
crates/ivc/src/compilers/cyclefold/circuits.rs#L118-L145