Implement bundle burn validation and serialization (new)#38
Implement bundle burn validation and serialization (new)#38
Conversation
PaulLaux
left a comment
There was a problem hiding this comment.
Added some comments, plus we need a meaningful test vector in the python tests. QED-it/zcash-test-vectors#10 (comment)
|
|
||
| writer.write_all(&[bundle.flags().to_byte()])?; | ||
| writer.write_all(&bundle.value_balance().to_i64_le_bytes())?; | ||
| write_bundle_burn(&mut writer, bundle.burn())?; |
There was a problem hiding this comment.
Let's inline this function, similar to two lines below.
| // FIXME: check for negative amounts? | ||
| if i64::from(amount) == 0 { | ||
| return Err(BurnError::ZeroAmount); | ||
| } |
There was a problem hiding this comment.
Yes, and change the error to NonPossitiveAmount
There was a problem hiding this comment.
Done. Additionally, I have to modify arb_amount function to generate amount values from tests from range 1..MAX_MONEY instead of -MAX_MONEY..MAX_MONEY, i.e. not generate negative or zero amount values.
| } | ||
| } | ||
|
|
||
| /// Validates burns for a bundle by ensuring each asset is unique, non-native, and has a non-zero value. |
There was a problem hiding this comment.
Validates the burn values for a bundle by ensuring each asset is unique, non-native, and has a possitive value.
| /// Each burn element is represented as a tuple of `AssetBase` and `Amount`, where `AssetBase` identifies | ||
| /// the asset to be burned and `Amount` is the quantity to burn. |
There was a problem hiding this comment.
replace with
For burn, each asset is represented as a tuple of `AssetBase` and `Amount`.
| /// | ||
| /// # Arguments | ||
| /// | ||
| /// * `burns` - A vector of burns, where each burn is represented as a tuple of `AssetBase` and `Amount`. |
There was a problem hiding this comment.
burns is not a good word.
* `burn` - A vector of assets, where each asset is represented as a tuple of `AssetBase` and `Amount`.
| use super::super::burn_validation::BurnError; | ||
|
|
||
| #[test] | ||
| fn test_read_write_bundle_burn_success() { |
There was a problem hiding this comment.
remove test_ from all tests
|
|
||
| AssetBase::derive(&IssuanceValidatingKey::from(&isk), asset_desc) | ||
| } | ||
|
|
There was a problem hiding this comment.
Insert new work at the bottom of the file, not at the top. (the entire new function)
| #[cfg(feature = "zfuture")] | ||
| use super::components::tze; | ||
|
|
||
| pub fn create_test_asset(asset_desc: &str) -> orchard::note::AssetBase { |
There was a problem hiding this comment.
this function will be better utilized if returns the burn tupple:
get_burn_tupple(asset_desc: &str, amount u64) -> (AssetBase, Amount) {There was a problem hiding this comment.
please add a comment that the function is deterministic by using a static sk_iss.
|
|
||
| use super::Amount; | ||
|
|
||
| // FIXME: Consider making tuple (AssetBase, Amount) a new type. |
There was a problem hiding this comment.
Think a tuple is simple enough for this.
| // This test implementation covers only one failure case intentionally, | ||
| // as the other cases are already covered in the validate_bundle_burn tests. |
There was a problem hiding this comment.
Either describe this test or not at all.
No need to discuss other tests.
There was a problem hiding this comment.
Done - removed this comment.
- Fix comments. - Rename `create_test_asset` to `get_burn_tuple` and move it to the end of the file. - Inline `write_bundle_burn`. - Remove `test_` prefix for test functions.
…vity instead of non-zero
…range 1..MAX_MONEY instead of -MAX_MONEY..MAX_MONEY, i.e. not generate negative or zero amount values
This pull request introduces handling of the 'burn' field of the bundle. The changes are split across two new modules:
burn_validationandburn_serialization.Burn Validation
The
burn_validationmodule ensures the correctness of burn operations. Specifically, it validates that each asset to be burned is unique, non-native, and has a non-zero amount.Burn Serialization
The
burn_serializationmodule is responsible for reading and writing assets and burns from/to a stream.Additionally, I have made modifications to the
arb_amountfunction inzcash_primitives/src/transaction/components/amount.rsto generate amounts from the1..MAX_MONEYrange instead of the-MAX_MONEY..MAX_MONEYrange (to pass new validation checks for burn items, whch require amounts to be positive).Furthermore, I have updated the test vectors for zip_0244 to accommodate the changes in the transaction structure. I have included an empty burn field in the test vectors to ensure alignment with the updated transaction format.