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

Make native Field in SnarkyJS configurable #25

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mitschabaude
Copy link
Contributor

No description provided.

Copy link
Member

@bkase bkase left a comment

Choose a reason for hiding this comment

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

High level looks good to me so far 👍


### Rust side: instantiating core Kimchi methods

TODO - does Rust enable us to dynamically instantiate traits (or whatever) as function return values?
Copy link
Member

Choose a reason for hiding this comment

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

https://doc.rust-lang.org/rust-by-example/trait/dyn.html , but it's "slow" since there is a few pointer jumps vs the static https://doc.rust-lang.org/rust-by-example/trait/impl_trait.html . I don't think it will be even remotely close to the bottleneck here though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But that example picks between 2 traits that both have been declared already, instead of creating a trait depending on a parameter like we can do in OCaml and JS

Copy link
Member

Choose a reason for hiding this comment

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

Ah okay I get it, typically I use a “record of closures” to get that to work in these kinds of languages though I haven’t tried it in Rust.

The idea is for all the functions of the trait you add closures to the struct and the implementations of the trait is just calling the closures. Then you can, at runtime, swap implementations. I don’t see a reason why it won’t work in rust if you wrap things in enough boxes, but I’m not a Rust expert.


It's work.

## Rationale and alternatives
Copy link
Member

Choose a reason for hiding this comment

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

Other alternatives at the API level (though I like your proposal a lot!)

  1. Add a type parameter to the Field class: ie. Field<Bn128> or Field<Pasta>
  2. Dynamically change the behavior of Field at runtime: Field.setBackendTo(Bn128())
  3. Statically instantiate the backends and tie that to the name of the class: FieldBn128 or the import import Field from 'lib/field_bn128' <-- we can consider the latter as a shorthand built on top of the more general system you're proposing.

Copy link
Contributor Author

@mitschabaude mitschabaude Aug 23, 2023

Choose a reason for hiding this comment

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

Yeah I considered 2) but it's not very nice. 3) without a generic e2e solution is a reasonable fallback in case we can't make fully generic work (parts of the logic would still be generic).
I don't think 1) fully specifies an API because types in TS don't affect the runtime, so there would still have to be some runtime step of picking the field

@Trivo25
Copy link
Member

Trivo25 commented Aug 25, 2023

Interesting - this only affects Kimchi proofs, right? Or will developers also be able to generate wrapper proofs with pickles?

@mitschabaude
Copy link
Contributor Author

mitschabaude commented Aug 25, 2023

Interesting - this only affects Kimchi proofs, right? Or will developers also be able to generate wrapper proofs with pickles?

Yes only Kimchi proofs

We might want to treat the Kimchi proof API with more love going forward

@Trivo25
Copy link
Member

Trivo25 commented Aug 25, 2023

We might want to treat the Kimchi proof API with more love going forward

I was about to say! I feel like this could be a nice opportunity to improve the kimchi API and making it generally more accessible. We have all the tools we need, but the Circuit API always felt a little odd. This is exciting

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.

3 participants