Skip to content
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

Convert descriptions anchor validation #2248

Merged
merged 24 commits into from
Dec 29, 2023

Conversation

grarco
Copy link
Collaborator

@grarco grarco commented Dec 6, 2023

Describe your changes

Closes #1373.

Modifies update_allowed_conversions to update the anchor in storage at every epoch.
Updates the masp vp to check the validity of the convert descriptions' anchors and improves how the masp vp validates the changed keys.
Also updates the VP to run stricter checks on the sapling bundle composition (addressing #2244 (comment))

Indicate on which release or other PRs this topic is based on

#2244

Checklist before merging to draft

  • I have added a changelog
  • Git history is in acceptable state

@grarco grarco force-pushed the grarco/convert-description-validation branch from cf53ba9 to 463bfc8 Compare December 7, 2023 13:33
@grarco grarco marked this pull request as ready for review December 7, 2023 16:08
@grarco grarco requested a review from murisi December 7, 2023 16:08
This was referenced Dec 11, 2023
@grarco grarco requested a review from batconjurer December 15, 2023 17:16
@grarco grarco mentioned this pull request Dec 18, 2023
.expect("Cannot obtain a storage key");
wl_storage.write(
&anchor_key,
crate::types::hash::Hash(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can abstract all of this out into a hash function on the tree type, perhaps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah the FrozenCommitmentTree is imported from the masp crate but we can probably refactor this part of the code in other ways

let current_tx_key = Key::from(masp_addr.to_db_key())
.push(&(TX_KEY_PREFIX.to_owned() + &current_tx_idx.to_string()))
.expect("Cannot obtain a storage key");
// Save the Transfer object and its location within the blockchain
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really need to store the entire transaction data? Seems wasteful. Also, can't this be queried from Tendermint?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't need this data in protocol but we need it for the clients to scan transactions and generate a valid internal state to produce future transactions. I agree with you that this could bloat the storage pretty quick (together with the nullifier set), but I think there are a few concerns with querying this data from comet:

  • I'm not sure we can assume that the blocks will be always available (in case of a chain restart for example if we decided to prune history)
  • Requesting blocks from full nodes could take a long time/bandwidth
  • The time to process the blocks filtering out only masp transactions could be long

Still we might prefer this solution over writing to storage. Wdyt? Alternatively we could think about a way to prune transactions from storage when they are not useful anymore (e.g. all the output descriptions have been spent)

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should be able to use the indexer to pre-filter for MASP transaction data so that clients need only download and scan that. It's true that we need to keep around data after chain upgrades, but this doesn't seem too difficult.

let head_tx_key = Key::from(masp_addr.to_db_key())
.push(&HEAD_TX_KEY.to_owned())
.expect("Cannot obtain a storage key");
let current_tx_idx: u64 =
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we are going to write transactions to storage like this, all of this incrementing current tx index logic should be abstracted into a common function.

brentstone added a commit that referenced this pull request Dec 29, 2023
* origin/grarco/convert-description-validation:
  Stricter checks on sapling bundle components
  Changelog #2248
  Fixes masp key validation
  Fixes conversion anchor handling
  Removes redundant masp dependency from bench crate
  Improves masp vp keys verification
  Masp VP verifies the anchors of convert descriptions
  `update_allowed_conversions` to publish the updated convert anchor
@brentstone brentstone merged commit 7f492ce into main Dec 29, 2023
12 of 14 checks passed
@brentstone brentstone deleted the grarco/convert-description-validation branch December 29, 2023 19:37
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.

Missing MASP Transaction Validation
4 participants