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

[NCC-E005955-MU2] zebra-consensus: Redundant Computation in Sapling and Orchard Note Validation #6392

Closed
mpguerra opened this issue Mar 23, 2023 · 7 comments
Assignees
Labels
A-dependencies Area: Dependency file updates A-rust Area: Updates to Rust code C-audit Category: Issues arising from audit findings C-cleanup Category: This is a cleanup C-enhancement Category: This is an improvement C-tech-debt Category: Code maintainability issues

Comments

@mpguerra
Copy link
Contributor

mpguerra commented Mar 23, 2023

Impact

During Sapling and Orchard output validation, one redundant elliptic curve scalar multiplication is performed. It may be considered for removal for efficiency purposes.

This is an issue in librustzcash:
zcash/librustzcash#802

Description

In order to verify that Sapling and Orchard outputs are decryptable and consistent with ZIP 212 rules, Zebra uses the zcash_primitives crate’s try_sapling_output_recovery function. This function is called, for example, when coinbase transaction outputs are validated to adhere to the rules specified in ZIP 212.

Once decrypted, an output’s note is parsed. An ephemeral key validation function is passed as a lambda:

Screenshot 2023-03-24 at 15 59 39

The check implemented by the highlighted lambda function is mandated by ZIP 212. A few lines below, the check_note_validity function is called:

Screenshot 2023-03-24 at 16 01 19

The validation highlighted in the first code snippet happens regardless of whether ZIP 212 is activated or not. This is also what the original Zcash client does; see zcash/Note.cpp.
The validation highlighted in the second code snippet aims to only validate the public key post-ZIP 212 and is likely meant to be a blanket end-of-function validation helper. This helper includes an ECC point multiplication and as such is not inexpensive.

Recommendation

It appears that the highlighted check inside the check_note_validity function overlaps with the previous validation, and, as such, may be removed.

@mpguerra mpguerra added this to Zebra Mar 23, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in Zebra Mar 23, 2023
@mpguerra mpguerra changed the title [NCC-E005955-MU2] zebra-consensus: Redundant Computation in Sapling and [NCC-E005955-MU2] zebra-consensus: Redundant Computation in Sapling and Orchard Note Validation Mar 23, 2023
@teor2345
Copy link
Contributor

@mpguerra this isn't a bug in Zebra, it's in an ECC dependency that is out of scope for the audit.

@mpguerra mpguerra added A-dependencies Area: Dependency file updates C-enhancement Category: This is an improvement C-cleanup Category: This is a cleanup S-needs-triage Status: A bug report needs triage C-audit Category: Issues arising from audit findings labels Mar 24, 2023
@mpguerra
Copy link
Contributor Author

@mpguerra this isn't a bug in Zebra, it's in an ECC dependency that is out of scope for the audit.

That's right. We want to track everything raised by the auditors and try to fix it if it makes sense.

@teor2345
Copy link
Contributor

@mpguerra this isn't a bug in Zebra, it's in an ECC dependency that is out of scope for the audit.

That's right. We want to track everything raised by the auditors and try to fix it if it makes sense.

@mpguerra is there an equivalent librustzcash issue?

@mpguerra
Copy link
Contributor Author

mpguerra commented Mar 31, 2023

@mpguerra is there an equivalent librustzcash issue?

There is now! zcash/librustzcash#802

@upbqdn
Copy link
Member

upbqdn commented Apr 24, 2023

The function check_note_validity, where the redundancy occurs, is also called in

The call stack above doesn't contain the epk check from parse_note_plaintext_without_memo_ovk mentioned in the finding; thus, removing the check from check_note_validity might cause unexpected errors.

It would be beneficial to separate the two call stacks and remove the redundancy from the affected one, but my estimate is that the effort required for the refactoring doesn't match the benefits. I, therefore, propose we close this issue without addressing it.

@upbqdn upbqdn closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2023
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in Zebra Apr 24, 2023
@upbqdn upbqdn added A-rust Area: Updates to Rust code C-tech-debt Category: Code maintainability issues and removed S-needs-triage Status: A bug report needs triage labels Apr 24, 2023
@mpguerra
Copy link
Contributor Author

@upbqdn can you please add a size for this issue based on how much effort it took to investigate and analyze this?

@upbqdn
Copy link
Member

upbqdn commented Apr 25, 2023

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dependencies Area: Dependency file updates A-rust Area: Updates to Rust code C-audit Category: Issues arising from audit findings C-cleanup Category: This is a cleanup C-enhancement Category: This is an improvement C-tech-debt Category: Code maintainability issues
Projects
Archived in project
Development

No branches or pull requests

3 participants