-
Notifications
You must be signed in to change notification settings - Fork 277
Zk sdk #953
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
base: toccata
Are you sure you want to change the base?
Zk sdk #953
Changes from 23 commits
66922dc
b9dbe17
156ca8b
5ea0fb5
d25305c
d771435
f893dbd
260c9cb
1cdebb7
3209ce8
d235c6b
43f9657
1e005c7
786814a
e062651
88527d2
b1cadf6
41de812
3bad7a7
538eb42
5798082
373f780
0e11699
a136c51
10acbd7
b603891
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| mod error; | ||
| mod fields; | ||
| pub mod groth16; | ||
| mod points; | ||
| pub mod risc0; | ||
| pub mod tags; | ||
| pub mod tests; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| use thiserror::Error; | ||
|
|
||
| #[derive(Debug, Error)] | ||
| pub enum PointError { | ||
| #[error("Malformed G1 field element")] | ||
| MalformedG1, | ||
| #[error("Malformed G2 field element")] | ||
| MalformedG2, | ||
| #[error("Ark deserialization error: {0}")] | ||
| ArkDeserialization(#[from] ark_serialize::SerializationError), | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| mod error; | ||
| use ark_bn254::{G1Affine, G2Affine}; | ||
| use ark_serialize::CanonicalDeserialize; | ||
|
|
||
| pub trait PointFromBytes<'input>: Sized { | ||
| type Input: ?Sized; | ||
| fn from_r0_bytes(bytes: &'input Self::Input) -> Result<Self, PointError>; | ||
| } | ||
| pub use error::PointError; | ||
| pub struct G1(pub G1Affine); | ||
| pub struct G2(pub G2Affine); | ||
|
|
||
| impl<'input> PointFromBytes<'input> for G1 { | ||
| type Input = Vec<Vec<u8>>; | ||
|
|
||
| /// Deserialize an element over the G1 group from r0 bytes in big-endian format | ||
| fn from_r0_bytes(bytes: &Self::Input) -> Result<G1, PointError> { | ||
| if bytes.len() != 2 { | ||
| return Err(PointError::MalformedG1); | ||
| } | ||
| let g1_affine: Vec<u8> = bytes[0].iter().rev().chain(bytes[1].iter().rev()).cloned().collect(); | ||
|
Comment on lines
+14
to
+21
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why shout it be 2 dimensional reversed vectors?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. r0 stores in BE order whilst ark expects LE, but I agree here that the fn name should be more specific to r0, not generic |
||
|
|
||
| Ok(G1(G1Affine::deserialize_uncompressed(&*g1_affine)?)) | ||
| } | ||
| } | ||
|
|
||
| impl<'input> PointFromBytes<'input> for G2 { | ||
| type Input = Vec<Vec<Vec<u8>>>; | ||
|
|
||
| fn from_r0_bytes(bytes: &Self::Input) -> Result<G2, PointError> { | ||
| if bytes.len() != 2 || bytes[0].len() != 2 || bytes[1].len() != 2 { | ||
| return Err(PointError::MalformedG2); | ||
| } | ||
| let g2_affine: Vec<u8> = bytes[0][1] | ||
| .iter() | ||
| .rev() | ||
| .chain(bytes[0][0].iter().rev()) | ||
| .chain(bytes[1][1].iter().rev()) | ||
| .chain(bytes[1][0].iter().rev()) | ||
| .cloned() | ||
| .collect(); | ||
|
Comment on lines
+31
to
+41
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why shout it be 2 dimensional reversed vectors?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
|
|
||
| Ok(G2(G2Affine::deserialize_uncompressed(&*g2_affine)?)) | ||
| } | ||
| } | ||
|
|
||
| impl From<G1> for G1Affine { | ||
| fn from(g1: G1) -> G1Affine { | ||
| g1.0 | ||
| } | ||
| } | ||
|
|
||
| impl From<G2> for G2Affine { | ||
| fn from(g2: G2) -> G2Affine { | ||
| g2.0 | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| use crate::zk_precompiles::risc0::R0Error; | ||
|
|
||
| pub type Result<T> = std::result::Result<T, R0Error>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this intentional or a leftover? why does that path need special treatment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right must be a leftover, fixing.