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/Improve frontend (rust-interface) of sonobe #96

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

vuvoth
Copy link
Contributor

@vuvoth vuvoth commented May 13, 2024

Motivation

In current implement we are using trait FCircuit describe the folding circuit. This trait (interface) is straightforward but have a few limitation:

  • We can not naming the inputs/outputs of circuit and the meaning of variable only access via index. The constraint setup is facing with the same problem also.
  • User want to state_len when we update circuit inputs/outputs.

Proposal

Note: This proposal and PR is early proposal. We can discuss and improve it better!

We can build the derive macro help us auto convert vector to State and vice versa. This macro also auto crate Constraint State struct(check example for more details). We also compute number field in State struct and this equal state_len. We don't support nested data structure yet.

After I implemented the idea above. I realized the problem I want to solve is serialize data to vector and deserialize vector to data structure. Maybe serde is elegant solution for this problem.

This PR is prototype.

@vuvoth vuvoth marked this pull request as draft May 18, 2024 16:38
@vuvoth
Copy link
Contributor Author

vuvoth commented May 18, 2024

Convert to daft because we have better idea to cover this PR.

@vuvoth vuvoth marked this pull request as ready for review May 20, 2024 21:27
Copy link
Collaborator

@arnaucube arnaucube left a comment

Choose a reason for hiding this comment

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

This is a good idea! Did a first pass, I will try to check more in deep the macro, because ideally it would be nice to support vectors and nested structs.

frontend-macro/Cargo.toml Show resolved Hide resolved
}
}

impl #impl_generics From<Vec #ty_generics> for #iden #ty_generics {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are parts of the code that seem to work with vectors, but when I try to use for example

struct State<F: PrimeField> {
    a: F,
    b: F,
    c: Vec<F>, // vector
    d: (F, F), // tuple
}

it fails with an error for both cases (vector & tuple). Is it expected?

To put an example of usage, this is the Grapevine circuit (Circom, but taking it as a real-world sample), where they use mostly vectors for the external_inputs: https://github.com/Mach-34/grapevine-sonobe/blob/556d570e807d08557d7a2a233e4637b00ab4eafa/circom/grapevine.circom#L21

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will check it :D and update it soon

folding-schemes/Cargo.toml Outdated Show resolved Hide resolved
Comment on lines +18 to +20
println!("{:?}", State::<Fr>::state_number());
println!("{:?}", v);
println!("{:?}", State::from(v));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe instead of prints, this test can do assert_eq with the expected values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This only for compile macro. I added runable test for macro.

@arnaucube
Copy link
Collaborator

(Regarding the GithubActions CI complaining, the current errors are due a rust_toolchain file version, if you rebase this PR branch into the latest main branch of Sonobe repo, it will point to the v1.76.0 and the current errors in the CI should disappear.)

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 this pull request may close these issues.

2 participants