Refactor issue/burn validation for Zebra asset state integration#199
Refactor issue/burn validation for Zebra asset state integration#199
Conversation
This change refactors Orchard issuance and burn validation so Zebra can reuse it for its issued_assets global state and checkpoint handling. - Add derives and a few new error variants for issuance and burn so Zebra can surface state-related failures explicitly. - Change state lookup callbacks to FnMut to allow caching on the Zebra side. - Split verify_issue_bundle into signature checking plus a verify_trusted_issue_bundle variant for checkpointed blocks. - Make burn validation state-aware and return updated AssetRecord values, symmetric to issuance.
…hout_sighash in issuance
PaulLaux
left a comment
There was a problem hiding this comment.
Overall good. Posted comments
| verify_trusted_issue_bundle(bundle, get_global_records, first_nullifier) | ||
| } | ||
|
|
||
| // FIXME: move it and add tests ... |
|
|
||
| /// Strips reference notes, keeping only amounts (reference notes contain | ||
| /// randomness and can't be compared directly). | ||
| fn strip_reference_notes( |
There was a problem hiding this comment.
let's call it remove_reference_notes()
There was a problem hiding this comment.
Fixed (renamed and updated the doc comment).
src/bundle/burn_validation.rs
Outdated
| /// Builds a BTreeMap of asset states from an array of (asset_desc, supply) tuples. | ||
| /// |
There was a problem hiding this comment.
Provide more context here. What is state in the context of orchard?
There was a problem hiding this comment.
Let's call it build_tree() and avoid the term state and the discussion around it as much as possible for orchard.
There was a problem hiding this comment.
Fixed. As we discussed, I renamed the build_state function to mock_issuance_records. I also replaced the remaining mentions of “state” in comments with “global issuance state”, following ZIP 0227’s terminology (Global Issuance State section).
src/bundle/burn_validation.rs
Outdated
| /// # Returns | ||
| /// | ||
| /// A `BTreeMap<AssetBase, AssetRecord>` containing the asset records. | ||
| fn build_state(data: &[(&[u8], u64)]) -> BTreeMap<AssetBase, AssetRecord> { |
There was a problem hiding this comment.
this untyped style data: &[(&[u8], u64)] does not work for Orchard. Please create a properly typed function signature.
There was a problem hiding this comment.
Fixed - replaced the tuple with a new struct:
struct AssetSupply {
asset: AssetBase,
supply: u64,
}
| use crate::keys::{FullViewingKey, Scope, SpendingKey}; | ||
| use rand::rngs::OsRng; | ||
|
|
||
| let mut rng = OsRng; |
There was a problem hiding this comment.
consider deterministic seed here
src/bundle/burn_validation.rs
Outdated
| write!(f, "Cannot burn an asset with a zero value.") | ||
| } | ||
| BurnError::AssetNotFoundInState => write!(f, "Asset not found in state."), | ||
| BurnError::InsufficientSupply => write!(f, "Insufficient supply for burn"), |
There was a problem hiding this comment.
This one does not end with period . but all the others does. Please check Orchard and align the style (I think we dont need . at the end)
There was a problem hiding this comment.
Fixed (removed trailing periods in the fmt::Display strings).
I checked Orchard’s style and it’s mixed, but doc comments on error enum variants usually include periods (for example BuildError, SpendError, and OutputError in [builder.rs](https://github.com/zcash/orchard/blob/main/src/builder.rs)). The fmt::Display messages are more inconsistent and use trailing periods less often. So I removed trailing periods from the error strings, and kept periods in the error enum variant doc comments.
| /// Asset not found in state | ||
| AssetNotFoundInState, | ||
| /// Insufficient supply for burn | ||
| InsufficientSupply, |
There was a problem hiding this comment.
align . usage in docstrings as in Orchard
There was a problem hiding this comment.
Fixed (added the missing trailing periods, see my previous comment).
| reference_note: current_record.reference_note, | ||
| }; | ||
|
|
||
| if new_records.insert(asset, new_record).is_some() { |
There was a problem hiding this comment.
In this new version, you check if the asset is duplicated at the end, after get_current_record(&asset). Consider checking for duplicates (without insert) early and avoid expensive operations on duplicated assets.
There was a problem hiding this comment.
Fixed - replaced with the following check before get_current_record(&asset):
if new_records.contains_key(&asset) {
return Err(BurnError::DuplicateAsset);
}
…0.115 requires MSRV 1.71" This reverts commit c8ba08c.
d67d5ca to
5bc85a4
Compare
This PR refactors Orchard’s issue/burn validation so Zebra can call it directly when maintaining its
issued_assetsstate and when processing checkpointed blocks.The changes:
FnMutso Zebra can keep a local cacheverify_issue_bundleto reuse core validation asverify_trusted_issue_bundle(no sighash/signature, for checkpoints)validate_bundle_burnto check burns against the asset state and return updatedAssetRecords, making it symmetric withverify_issue_bundle