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

MemoPlaintext string length enforced, TransactionPlan panic avoided #3585

Merged
merged 4 commits into from
Jan 8, 2024

Conversation

turbocrime
Copy link
Contributor

identified a panic when working on web transactions.

added checks to verify text length is under maximum when deserializing from pbt::MemoPlaintext or Vec<u8>, to prevent the creation of impossible memos. perhaps MemoPlaintext should use private fields and a constructor to enforce format limitations that cannot be specified by protobuf, but this is a smaller change.

ultimately the source of the panic was an expect used in TransactionPlan::effect_hash to unwrap a potential error, this is now bubbled as anyhow::Result

@turbocrime turbocrime marked this pull request as ready for review January 6, 2024 16:05
Comment on lines -71 to +74
let memo_hash = self
.memo
.as_ref()
.map(|memo_plan| {
memo_plan
.memo()
.expect("can compute memo ciphertext")
.effect_hash()
})
// If the memo is not present, use the all-zero hash to record its absence in
// the overall effect hash.
.unwrap_or_default();
let memo_hash = match self.memo {
Some(ref memo) => memo.memo()?.effect_hash(),
None => EffectHash::default(),
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a significant change in style compared to the previous implementation, not sure if that's appropriate

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the result of the change better, it's more succinct this way.

Copy link
Contributor

@cronokirby cronokirby left a comment

Choose a reason for hiding this comment

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

I like this a lot; I feel like it would be worth it to refactor MemoPlaintext to have a guarded constructor, but I'll take care of that in a separate PR.

@cronokirby cronokirby merged commit d7f075d into main Jan 8, 2024
7 checks passed
@cronokirby cronokirby deleted the memo-plaintext-length branch January 8, 2024 23:07
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