forked from zcash/orchard
-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance and cleanup ivk-to-bytes-visibility-downgrade branch #81
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
PaulLaux
merged 50 commits into
zsa1
from
ivk-to-bytes-visibility-downgrade-with-burn-valid
Oct 4, 2023
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
39b57e9
Use correct IK in proptest
alexeykoren f9b2124
Use correct IK in proptest
alexeykoren 86609c9
Remove signing from proptest bundle generation
alexeykoren a4c20ad
Rebase
alexeykoren 9525f32
Digest for empty issue bundle
alexeykoren 9fa37b3
Increase librustzcash version
alexeykoren e893453
test fix
alexeykoren 83fb98f
Rebase fixes
alexeykoren 3ba6146
Rebase
alexeykoren 089df65
fmt
alexeykoren 9067ca2
Validate burn of the Orchard bundles in BatchValidator
dmidem 5a16d93
Fix reference to zcash_note_encryption in Cargo.toml
dmidem 2f0f10a
Minor refinements in burn_validation.rs
dmidem 9ef1331
Add call of validate_bundle_burn to Orchard bundle batch validator
dmidem 5bc2dc4
Add BatchValidator for IssueBundle
dmidem 3958281
Pin rustix dependency version to 0.37.20 as 0.38 requires Rust v1.63
dmidem 1342673
Pin tempfile dependency version to 3.6.0 as 3.8.0 requires Rust v1.63
dmidem 1249764
Pin backtrace dependency version to 0.3.67 as newer ones require Rust…
dmidem 8977652
Pin flate2 dependency version to 1.0.26 as newer ones require newer R…
dmidem e4a76d5
Fix PartialOrd impl for VerificationKey id redpallas, to fix incorrec…
dmidem 6ac8c65
Sync Cargo.toml with PR #79 (except zcash_note_encryption)
dmidem 7a9e2de
Fix Cargo.toml for the previous commit
dmidem a027850
Fix Cargo.toml for the previous commit 2
dmidem 5cd3fa4
Pin backtrace dependency version to 0.3.67 as newer ones require Rust…
dmidem c1a41a9
Fix Cargo.toml to use zcash_note_encryption (librustzcash) from zsa-b…
dmidem 006d240
Merge branch 'zsa1' into ivk-to-bytes-visibility-downgrade-with-burn-…
PaulLaux 076fcb1
Update Rust version to 1.65 and remove old dependencies pins
dmidem 00ff727
Refine comments and minor code reordering
dmidem 2294f50
Replace tuples with meaningful variable names in issuance.rs
dmidem 9af7e9b
Pin dependencies blake2b_simd and anstyle to compile with Rust 1.65
dmidem 7dc77d5
Pin clap dependency version instead of anstyle, to compile with Rust …
dmidem fc1630c
Pin clap dependency to an older version
dmidem b849b87
Pin clap dependency to 4.2.7
dmidem a91f38b
Pin clap dependency to 4.2.0
dmidem 9b0839b
Upgrade to actions/checkout@v3 in CI config
dmidem 75a278d
Revert "Upgrade to actions/checkout@v3 in CI config"
dmidem bb2d38c
Fix clippy errors (use intead of )
dmidem 1a4755f
Address' cargo clippy' errors following the update to Rust 1.65
dmidem 06c3c08
Use zcash_note_encryption from zsa1-zebra branch of librustzcash
dmidem 922f9f9
Use 'if' instead of 'u8::from' as it was suggested by clippy to get f…
dmidem 31bb724
Upgrade dependencies according the changes in the latest Cargo.toml f…
dmidem 21c2632
Revert changes related to BatchValidators (both - orchard and issuanc…
dmidem eee181e
Remove extra empty line
dmidem a936be9
Remove extra empty line (2)
dmidem 76baed2
Remove issuance/batch.rs I created before
dmidem c01c83f
Remove reference to issuance/batch.rs as well
dmidem 48aebb1
Return burn_validation module back as it can be used not only for old…
dmidem 37cc4b8
Remove DynamicUsage trait impls from issuance.rs as DynamicUsage is n…
dmidem 4fe9882
Remove DynamicUsage trait impls from keys.rs note.rs as well (as Dyna…
dmidem 0a1287c
Return DynamicUsage impl for PreparedIncomingViewingKey in keys.rs as…
dmidem 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| [toolchain] | ||
| channel = "1.61.0" | ||
| channel = "1.65.0" | ||
| components = [ "clippy", "rustfmt" ] |
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,146 @@ | ||
| //! Validating burn operations on asset bundles. | ||
| //! | ||
| //! The module provides a function `validate_bundle_burn` that can be used to validate the burn values for the bundle. | ||
| //! | ||
| use std::fmt; | ||
|
|
||
| use crate::note::AssetBase; | ||
|
|
||
| /// Possible errors that can occur during bundle burn validation. | ||
| #[derive(Debug)] | ||
| #[cfg_attr(test, derive(PartialEq, Eq))] | ||
| pub enum BurnError { | ||
| /// Encountered a duplicate asset to burn. | ||
| DuplicateAsset, | ||
| /// Cannot burn a native asset. | ||
| NativeAsset, | ||
| /// Cannot burn an asset with a non-positive value. | ||
| NonPositiveAmount, | ||
| } | ||
|
|
||
| /// Validates burn for a bundle by ensuring each asset is unique, non-native, and has a positive value. | ||
| /// | ||
| /// Each burn element is represented as a tuple of `AssetBase` and `i64` (value for the burn). | ||
| /// | ||
| /// # Arguments | ||
| /// | ||
| /// * `burn` - A vector of assets, where each asset is represented as a tuple of `AssetBase` and `i64` (value the burn). | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns a `BurnError` if: | ||
| /// * Any asset in the `burn` vector is not unique (`BurnError::DuplicateAsset`). | ||
| /// * Any asset in the `burn` vector is native (`BurnError::NativeAsset`). | ||
| /// * Any asset in the `burn` vector has a non-positive value (`BurnError::NonPositiveAmount`). | ||
| pub fn validate_bundle_burn(bundle_burn: &Vec<(AssetBase, i64)>) -> Result<(), BurnError> { | ||
| let mut asset_set = std::collections::HashSet::<&AssetBase>::new(); | ||
|
|
||
| for (asset, value) in bundle_burn { | ||
| if !asset_set.insert(asset) { | ||
| return Err(BurnError::DuplicateAsset); | ||
| } | ||
| if asset.is_native().into() { | ||
| return Err(BurnError::NativeAsset); | ||
| } | ||
| if *value <= 0 { | ||
| return Err(BurnError::NonPositiveAmount); | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| impl fmt::Display for BurnError { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| match *self { | ||
| BurnError::DuplicateAsset => write!(f, "Encountered a duplicate asset to burn."), | ||
| BurnError::NativeAsset => write!(f, "Cannot burn a native asset."), | ||
| BurnError::NonPositiveAmount => { | ||
| write!(f, "Cannot burn an asset with a non-positive value.") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| /// Creates an item of bundle burn list for a given asset description and value. | ||
| /// | ||
| /// This function is deterministic and guarantees that each call with the same parameters | ||
| /// will return the same result. It achieves determinism by using a static `IssuanceKey`. | ||
| /// | ||
| /// # Arguments | ||
| /// | ||
| /// * `asset_desc` - The asset description string. | ||
| /// * `value` - The value for the burn. | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// A tuple `(AssetBase, Amount)` representing the burn list item. | ||
| /// | ||
| pub fn get_burn_tuple(asset_desc: &str, value: i64) -> (AssetBase, i64) { | ||
| use crate::keys::{IssuanceAuthorizingKey, IssuanceKey, IssuanceValidatingKey}; | ||
|
|
||
| let sk_iss = IssuanceKey::from_bytes([0u8; 32]).unwrap(); | ||
| let isk: IssuanceAuthorizingKey = (&sk_iss).into(); | ||
|
|
||
| ( | ||
| AssetBase::derive(&IssuanceValidatingKey::from(&isk), asset_desc), | ||
| value, | ||
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| fn validate_bundle_burn_success() { | ||
| let bundle_burn = vec![ | ||
| get_burn_tuple("Asset 1", 10), | ||
| get_burn_tuple("Asset 2", 20), | ||
| get_burn_tuple("Asset 3", 10), | ||
| ]; | ||
|
|
||
| let result = validate_bundle_burn(&bundle_burn); | ||
|
|
||
| assert!(result.is_ok()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn validate_bundle_burn_duplicate_asset() { | ||
| let bundle_burn = vec![ | ||
| get_burn_tuple("Asset 1", 10), | ||
| get_burn_tuple("Asset 1", 20), | ||
| get_burn_tuple("Asset 3", 10), | ||
| ]; | ||
|
|
||
| let result = validate_bundle_burn(&bundle_burn); | ||
|
|
||
| assert_eq!(result, Err(BurnError::DuplicateAsset)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn validate_bundle_burn_native_asset() { | ||
| let bundle_burn = vec![ | ||
| get_burn_tuple("Asset 1", 10), | ||
| (AssetBase::native(), 20), | ||
| get_burn_tuple("Asset 3", 10), | ||
| ]; | ||
|
|
||
| let result = validate_bundle_burn(&bundle_burn); | ||
|
|
||
| assert_eq!(result, Err(BurnError::NativeAsset)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn validate_bundle_burn_zero_value() { | ||
| let bundle_burn = vec![ | ||
| get_burn_tuple("Asset 1", 10), | ||
| get_burn_tuple("Asset 2", 0), | ||
| get_burn_tuple("Asset 3", 10), | ||
| ]; | ||
|
|
||
| let result = validate_bundle_burn(&bundle_burn); | ||
|
|
||
| assert_eq!(result, Err(BurnError::NonPositiveAmount)); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.