forked from zcash/orchard
-
Notifications
You must be signed in to change notification settings - Fork 0
Added NoteType to Notes #2
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
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6ca2f9e
Added NoteType to Notes
PaulLaux 49cedd8
reformated file
PaulLaux da3c434
updated `derive` for NoteType
PaulLaux 69183ac
added note_type to value commit derivation
PaulLaux 56994a9
rustfmt
PaulLaux 393a60a
updated ci config
PaulLaux 6a82e1a
updated ci config
PaulLaux 0c5fe00
updated ci config
PaulLaux 4485158
updated derive for note_type
PaulLaux b25189e
added test for arb note_type
PaulLaux ca693fe
added test for `native` note type
PaulLaux 4b4b660
fixed clippy warrnings
PaulLaux 3e1020e
rustfmt
PaulLaux 12497af
updated note type derivation
PaulLaux 25d3c81
rustfmt
PaulLaux 99bd12d
fixed test
PaulLaux 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
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 |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| use group::GroupEncoding; | ||
| use halo2_proofs::arithmetic::CurveExt; | ||
| use pasta_curves::pallas; | ||
| use subtle::CtOption; | ||
|
|
||
| use crate::constants::fixed_bases::{VALUE_COMMITMENT_PERSONALIZATION, VALUE_COMMITMENT_V_BYTES}; | ||
| use crate::keys::IssuerValidatingKey; | ||
|
|
||
| /// Note type identifier. | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| pub struct NoteType(pub(crate) pallas::Point); | ||
|
|
||
| const MAX_ASSET_DESCRIPTION_SIZE: usize = 512; | ||
|
|
||
| // the hasher used to derive the assetID | ||
| #[allow(non_snake_case)] | ||
| fn assetID_hasher(msg: Vec<u8>) -> pallas::Point { | ||
| // TODO(zsa) replace personalization, will require circuit change? | ||
| pallas::Point::hash_to_curve(VALUE_COMMITMENT_PERSONALIZATION)(&msg) | ||
| } | ||
|
|
||
| impl NoteType { | ||
| /// Deserialize the note_type from a byte array. | ||
| pub fn from_bytes(bytes: &[u8; 32]) -> CtOption<Self> { | ||
| pallas::Point::from_bytes(bytes).map(NoteType) | ||
| } | ||
|
|
||
| /// Serialize the note_type to its canonical byte representation. | ||
| pub fn to_bytes(self) -> [u8; 32] { | ||
| self.0.to_bytes() | ||
| } | ||
|
|
||
| /// $DeriveNoteType$. | ||
| /// | ||
| /// Defined in [Zcash Protocol Spec § TBD: Note Types][notetypes]. | ||
| /// | ||
| /// [notetypes]: https://zips.z.cash/protocol/nu5.pdf#notetypes | ||
| #[allow(non_snake_case)] | ||
| pub fn derive(ik: &IssuerValidatingKey, assetDesc: Vec<u8>) -> Self { | ||
| assert!(assetDesc.len() < MAX_ASSET_DESCRIPTION_SIZE); | ||
|
|
||
| let mut s = vec![]; | ||
| s.extend(ik.to_bytes()); | ||
| s.extend(assetDesc); | ||
|
|
||
| NoteType(assetID_hasher(s)) | ||
| } | ||
|
|
||
| /// Note type for the "native" currency (zec), maintains backward compatibility with Orchard untyped notes. | ||
| pub fn native() -> Self { | ||
| NoteType(assetID_hasher(VALUE_COMMITMENT_V_BYTES.to_vec())) | ||
| } | ||
| } | ||
|
|
||
| /// Generators for property testing. | ||
| #[cfg(any(test, feature = "test-dependencies"))] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "test-dependencies")))] | ||
| pub mod testing { | ||
| use proptest::prelude::*; | ||
|
|
||
| use super::NoteType; | ||
|
|
||
| use crate::keys::{testing::arb_spending_key, IssuerAuthorizingKey, IssuerValidatingKey}; | ||
|
|
||
| prop_compose! { | ||
| /// Generate a uniformly distributed note type | ||
| pub fn arb_note_type()( | ||
| sk in arb_spending_key(), | ||
| bytes32a in prop::array::uniform32(prop::num::u8::ANY), | ||
| bytes32b in prop::array::uniform32(prop::num::u8::ANY), | ||
| ) -> NoteType { | ||
| let bytes64 = [bytes32a, bytes32b].concat(); | ||
| let isk = IssuerAuthorizingKey::from(&sk); | ||
| NoteType::derive(&IssuerValidatingKey::from(&isk), bytes64) | ||
| } | ||
| } | ||
| } | ||
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.
--> no