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

Add ToFieldElements and FromFieldElements traits #312

Open
hackaugusto opened this issue Apr 30, 2024 · 0 comments
Open

Add ToFieldElements and FromFieldElements traits #312

hackaugusto opened this issue Apr 30, 2024 · 0 comments

Comments

@hackaugusto
Copy link
Contributor

Proposal

Allow to easily covert a type to from field elements. This is useful to convert values so that they can be hashed, and to pass/receive values from the VM.

Outline

pub trait ToFieldElements<E: FieldElement> {
    fn to_elements(&self) -> Vec<E>;
}

pub trait FromFieldElements<E: FieldElement> {
    fn from_elements(elements: &[E]) -> Self;
}

Alternatives

  • Have both to_elements and from_elements on the same trait
  • Implement this in winterfell's ToElements

Issues

It is unclear if the implementation should use the minimum number of field elements, or add padding as expected by the VM. I feel like this should be the minimum number of felts, and the VM crate should have another trait, say ToVMInput, which performs the encoding for the VM. The implementation for ToVMInput can be custom or be on top of ToFieldElements.

Related

https://discord.com/channels/893151281848406016/1148602449247080478/1234523004650917898

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

No branches or pull requests

1 participant