Skip to content

Implement bundle burn validation and serialization (new)#38

Closed
dmidem wants to merge 11 commits intozsa1from
burn_read_write_validate_new
Closed

Implement bundle burn validation and serialization (new)#38
dmidem wants to merge 11 commits intozsa1from
burn_read_write_validate_new

Conversation

@dmidem
Copy link
Copy Markdown
Collaborator

@dmidem dmidem commented Jun 26, 2023

This pull request introduces handling of the 'burn' field of the bundle. The changes are split across two new modules: burn_validation and burn_serialization.

Burn Validation
The burn_validation module 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_serialization module is responsible for reading and writing assets and burns from/to a stream.

Additionally, I have made modifications to the arb_amount function in zcash_primitives/src/transaction/components/amount.rs to generate amounts from the 1..MAX_MONEY range instead of the -MAX_MONEY..MAX_MONEY range (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.

Copy link
Copy Markdown
Collaborator

@PaulLaux PaulLaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's inline this function, similar to two lines below.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +52 to +55
// FIXME: check for negative amounts?
if i64::from(amount) == 0 {
return Err(BurnError::ZeroAmount);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and change the error to NonPossitiveAmount

Copy link
Copy Markdown
Collaborator Author

@dmidem dmidem Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validates the burn values for a bundle by ensuring each asset is unique, non-native, and has a possitive value.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +29 to +30
/// 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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with

For burn, each asset is represented as a tuple of `AssetBase` and `Amount`.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

///
/// # Arguments
///
/// * `burns` - A vector of burns, where each burn is represented as a tuple of `AssetBase` and `Amount`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

burns is not a good word.

* `burn` - A vector of assets, where each asset is represented as a tuple of `AssetBase` and `Amount`.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

use super::super::burn_validation::BurnError;

#[test]
fn test_read_write_bundle_burn_success() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove test_ from all tests

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


AssetBase::derive(&IssuanceValidatingKey::from(&isk), asset_desc)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insert new work at the bottom of the file, not at the top. (the entire new function)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

#[cfg(feature = "zfuture")]
use super::components::tze;

pub fn create_test_asset(asset_desc: &str) -> orchard::note::AssetBase {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function will be better utilized if returns the burn tupple:

get_burn_tupple(asset_desc: &str, amount u64) -> (AssetBase, Amount) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment that the function is deterministic by using a static sk_iss.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


use super::Amount;

// FIXME: Consider making tuple (AssetBase, Amount) a new type.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think a tuple is simple enough for this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +90 to +91
// This test implementation covers only one failure case intentionally,
// as the other cases are already covered in the validate_bundle_burn tests.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either describe this test or not at all.
No need to discuss other tests.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - removed this comment.

@QED-it QED-it deleted a comment from what-the-diff Bot Jun 29, 2023
dmidem added 6 commits June 30, 2023 12:29
- 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.
…range 1..MAX_MONEY instead of -MAX_MONEY..MAX_MONEY, i.e. not generate negative or zero amount values
@PaulLaux PaulLaux closed this Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants