-
Notifications
You must be signed in to change notification settings - Fork 39
More verbose and stricter transcripts. #60
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
0c62284
Add transcript
recmo eb2306e
Remove TypeId
recmo 2a84c58
Every interaction is hierarchical
recmo f02da32
Example ZeroCopy
recmo d6de11b
Transcript to domain separator
recmo b85385d
Domain separators and labels
recmo 1600f55
ProverState and prover random
recmo 349ac7b
Implement ProverState traits
recmo 1b9fa68
New approach to traits
recmo b190f70
Fix build
recmo 4393621
Fix tests
recmo 7432a5a
Add back prover tests
recmo 21f04ab
Bytes traits
recmo f813524
Add zerocopy
recmo b25ad1f
Add ark_serialize hints
recmo c2b8192
Add field_bytes
recmo c8792f9
Add field_bytes
recmo 827f6f0
Challenge byte extraction
recmo c7a43b8
Test ark_serialize
recmo e1ccac2
Add Ark Field challenges
recmo b0c1ef3
Remove module name from zerocopy
recmo 16dea90
Remove module name from bytes
recmo a55e6fd
Remove module name from unit
recmo 5cccc14
Move unit to codecs
recmo f666944
Unit is associated type
recmo 02ce966
Explicit error types
recmo 1f8699c
Update zeropcopy traits
recmo 0d83306
Update arkworks::serialize traits
recmo 14d88e3
Update arkworks::field traits
recmo abd05ac
Update arkworks::field trait names
recmo 43abb51
Simplify VerifierError
recmo 3a5fd32
Pattern creation is infallible
recmo f9582c8
Interaction errors are bugs and therefore panic
recmo 70b8037
Remove interaction errors
recmo 9e97ff6
Simplify traits
recmo 39ea768
Static lables
recmo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,18 @@ pub mod arkworks_algebra; | |
| /// This plugin is experimental and has not yet been thoroughly tested. | ||
| pub mod zkcrypto_group; | ||
|
|
||
| #[cfg(feature = "zerocopy")] | ||
| /// Use [`zerocopy`] to convert types to/from bytes. | ||
| pub mod zerocopy; | ||
|
|
||
| #[cfg(feature = "ark-serialize")] | ||
| /// Use [`ark_serialize`] to convert types to/from bytes. | ||
| pub mod zerocopy; | ||
|
|
||
| // #[cfg(feature = "serde-postcard")] | ||
| // /// Use [`zerocopy`] to convert types to/from bytes. | ||
| // pub mod zerocopy; | ||
|
|
||
|
Comment on lines
+25
to
+28
Contributor
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. To be removed? |
||
| /// Bytes needed in order to obtain a uniformly distributed random element of `modulus_bits` | ||
| pub(super) const fn bytes_uniform_modp(modulus_bits: u32) -> usize { | ||
| (modulus_bits as usize + 128) / 8 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| //! [`zerocopy`] allows safe and efficient conversion to/from bytes for types that have | ||
| //! simple in-memory representations. | ||
|
|
||
| use zerocopy::{FromBytes, Immutable, IntoBytes}; | ||
|
|
||
| use crate::{ | ||
| traits::{ | ||
| BytesChallenge, BytesHintProver, BytesHintVerifier, BytesMessageProver, | ||
| BytesMessageVerifier, BytesPattern, | ||
| }, | ||
| transcript::{Label, Length, Transcript}, | ||
| }; | ||
|
|
||
| pub trait ZeroCopyPattern<T>: Transcript { | ||
| fn message(&mut self, label: Label) -> Result<(), Self::Error>; | ||
| fn hint(&mut self, label: Label) -> Result<(), Self::Error>; | ||
| fn challenge(&mut self, label: Label) -> Result<(), Self::Error>; | ||
| } | ||
|
|
||
| pub trait ZeroCopyMessageProver<T: Immutable + IntoBytes>: Transcript { | ||
| fn message(&mut self, label: Label, value: &T) -> Result<(), Self::Error>; | ||
| } | ||
|
|
||
| pub trait ZeroCopyMessageVerifier<T: IntoBytes + FromBytes>: Transcript { | ||
| fn message(&mut self, label: Label) -> Result<T, Self::Error>; | ||
| } | ||
|
|
||
| pub trait ZeroCopyHintProver<T: Immutable + IntoBytes>: Transcript { | ||
| fn hint(&mut self, label: Label, value: &T) -> Result<(), Self::Error>; | ||
| } | ||
|
|
||
| pub trait ZeroCopyHintVerifier<T: IntoBytes + FromBytes>: Transcript { | ||
| fn hint(&mut self, label: Label) -> Result<T, Self::Error>; | ||
| } | ||
|
|
||
| pub trait ZeroCopyChallenge<T: IntoBytes + FromBytes>: Transcript { | ||
| fn challenge(&mut self, label: Label) -> Result<T, Self::Error>; | ||
| } | ||
|
|
||
| impl<State, T> ZeroCopyPattern<T> for State | ||
| where | ||
| State: Transcript + BytesPattern, | ||
| { | ||
| fn message(&mut self, label: Label) -> Result<(), Self::Error> { | ||
| self.begin_message::<(Self, T)>(label.clone(), Length::Scalar)?; | ||
| self.add_bytes(size_of::<T>(), &label); | ||
| self.end_message::<(Self, T)>(label, Length::Scalar) | ||
| } | ||
|
|
||
| fn hint(&mut self, label: Label) -> Result<(), Self::Error> { | ||
| self.begin_hint::<(Self, T)>(label.clone(), Length::Scalar)?; | ||
| self.hint(&label); | ||
| self.end_hint::<(Self, T)>(label, Length::Scalar) | ||
| } | ||
|
|
||
| fn challenge(&mut self, label: Label) -> Result<(), Self::Error> { | ||
| self.begin_challenge::<(Self, T)>(label.clone(), Length::Scalar)?; | ||
| self.challenge_bytes(size_of::<T>(), &label); | ||
| self.end_challenge::<(Self, T)>(label, Length::Scalar) | ||
| } | ||
| } | ||
|
|
||
| impl<State, T> ZeroCopyMessageProver<T> for State | ||
| where | ||
| State: Transcript + BytesMessageProver, | ||
| T: Immutable + IntoBytes, | ||
| { | ||
| fn message(&mut self, label: Label, value: &T) -> Result<(), Self::Error> { | ||
| self.begin_message::<(Self, T)>(label.clone(), Length::Scalar)?; | ||
| self.message(value.as_bytes()).unwrap(); | ||
| self.end_message::<(Self, T)>(label, Length::Scalar) | ||
| } | ||
| } | ||
|
|
||
| impl<State, T> ZeroCopyMessageVerifier<T> for State | ||
| where | ||
| State: Transcript + BytesMessageVerifier, | ||
| T: IntoBytes + FromBytes, | ||
| { | ||
| fn message(&mut self, label: Label) -> Result<T, Self::Error> { | ||
| self.begin_message::<(Self, T)>(label.clone(), Length::Scalar)?; | ||
| let mut result = T::new_zeroed(); | ||
| self.message(result.as_mut_bytes()).unwrap(); | ||
| self.end_message::<(Self, T)>(label, Length::Scalar)?; | ||
| Ok(result) | ||
| } | ||
| } | ||
|
|
||
| impl<State, T> ZeroCopyHintProver<T> for State | ||
| where | ||
| State: Transcript + BytesHintProver, | ||
| T: Immutable + IntoBytes, | ||
| { | ||
| fn hint(&mut self, label: Label, value: &T) -> Result<(), Self::Error> { | ||
| self.begin_hint::<(Self, T)>(label.clone(), Length::Scalar)?; | ||
| self.hint(value.as_bytes()).unwrap(); | ||
| self.end_hint::<(Self, T)>(label, Length::Scalar) | ||
| } | ||
| } | ||
|
|
||
| impl<State, T> ZeroCopyHintVerifier<T> for State | ||
| where | ||
| State: Transcript + BytesHintVerifier, | ||
| T: FromBytes + IntoBytes, | ||
| { | ||
| fn hint(&mut self, label: Label) -> Result<T, Self::Error> { | ||
| self.begin_message::<(Self, T)>(label.clone(), Length::Scalar)?; | ||
| let mut result = T::new_zeroed(); | ||
| self.hint(result.as_mut_bytes()).unwrap(); | ||
| self.end_message::<(Self, T)>(label, Length::Scalar)?; | ||
| Ok(result) | ||
| } | ||
| } | ||
|
|
||
| impl<State, T> ZeroCopyChallenge<T> for State | ||
| where | ||
| State: Transcript + BytesChallenge, | ||
| T: FromBytes + IntoBytes, | ||
| { | ||
| fn challenge(&mut self, label: Label) -> Result<T, Self::Error> { | ||
| self.begin_challenge::<(Self, T)>(label.clone(), Length::Scalar)?; | ||
| let mut result = T::new_zeroed(); | ||
| self.challenge(result.as_mut_bytes()).unwrap(); | ||
| self.end_challenge::<(Self, T)>(label.clone(), Length::Scalar)?; | ||
| Ok(result) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This one should solve this no? arkworks-rs/std#60