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

Disallow Orchard ivk = 0 on IncomingViewingKey::from & SpendingKey generation #3962

Merged
merged 13 commits into from
Aug 1, 2022

Conversation

dconnolly
Copy link
Contributor

@dconnolly dconnolly commented Mar 25, 2022

Motivation

A change to the protocol spec for Orchard to reject scalar values in the Pallas scalar field of 0 for incoming viewing keys.

Specifications

if ivk ∈ {0, ⊥}, discard this key and repeat with a new sk.

https://zips.z.cash/protocol/protocol.pdf#orchardkeycomponents

image

Solution

Update impl From<FullViewingKey> for IncomingViewingKey to become a TryFrom, and return Result::Err if we get ⊥ or the possible pallas::Scalar value is 0 in the scalar field.

Update SpendingKey::new() to also check that a prospective sk doesn't lead to an invalid IncomingViewingKey.

Also implement TryFrom<[u8; 64]> for IncomingViewingKey to enforce that parsing of the raw encoding checks for and rejects the same values.

Closes #3869

Review

This is low priority because it is not an NU5 consensus rule, but an Orchard protocol check for keygen and ingesting of keys/addresses.

Reviewer Checklist

  • Code implements Specs and Designs
  • Tests for Expected Behaviour
  • Tests for Errors

Follow Up Work

@dconnolly dconnolly added A-rust Area: Updates to Rust code NU-5 Network Upgrade: NU5 specific tasks P-Low ❄️ labels Mar 25, 2022
@dconnolly dconnolly self-assigned this Mar 25, 2022
@dconnolly dconnolly requested review from a team as code owners March 25, 2022 05:09
@dconnolly dconnolly requested review from upbqdn and jvff and removed request for a team March 25, 2022 05:09
@teor2345 teor2345 added the do-not-merge Tells Mergify not to merge this PR label Mar 25, 2022
@teor2345
Copy link
Contributor

I'm marking this as "do not merge", until we work out how risky it is.
(Or until we've tagged the NU5 testnet rollback code.)

jvff
jvff previously approved these changes Mar 25, 2022
Copy link
Contributor

@jvff jvff left a comment

Choose a reason for hiding this comment

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

Looks good. I added some ideas, but they are optional.

zebra-chain/src/orchard/keys.rs Outdated Show resolved Hide resolved
zebra-chain/src/orchard/arbitrary.rs Show resolved Hide resolved
zebra-chain/src/orchard/keys.rs Outdated Show resolved Hide resolved
@dconnolly
Copy link
Contributor Author

dconnolly commented Mar 25, 2022

I'm marking this as "do not merge", until we work out how risky it is. (Or until we've tagged the NU5 testnet rollback code.)

All of our shielded key code beyond what is serialized/deserialized on chain/in P2P network messages is currently not being used beyond testing and conformance, until we use it for wallet functionality or whatever. That includes Orchard IncomingViewingKey and SpendingKey derivation. I would consider this a low-risk change.

image

@dconnolly
Copy link
Contributor Author

I'm marking this as "do not merge", until we work out how risky it is. (Or until we've tagged the NU5 testnet rollback code.)

Definitely willing to hold as :do-not-merge: until we tag as it is low priority

@teor2345 teor2345 added do-not-merge Tells Mergify not to merge this PR and removed do-not-merge Tells Mergify not to merge this PR labels Apr 4, 2022
@teor2345
Copy link
Contributor

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Apr 26, 2022

update

✅ Branch has been successfully updated

@dconnolly
Copy link
Contributor Author

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented May 11, 2022

update

✅ Branch has been successfully updated

@dconnolly
Copy link
Contributor Author

@mergify rebase

@mergify
Copy link
Contributor

mergify bot commented May 21, 2022

rebase

❌ Base branch update has failed

Git reported the following error:

Rebasing (1/3)
error: could not apply 8a7c96d1... Disallow Orchard ivk = 0 on IncomingViewingKey::from and SpendingKey generation
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 8a7c96d1... Disallow Orchard ivk = 0 on IncomingViewingKey::from and SpendingKey generation
Auto-merging zebra-chain/src/orchard/keys.rs
CONFLICT (content): Merge conflict in zebra-chain/src/orchard/keys.rs
Auto-merging zebra-chain/src/orchard/arbitrary.rs

err-code: E0F31

@teor2345
Copy link
Contributor

@dconnolly this PR hasn't changed in 2 months, can we consider turning it into a ticket as part of the Cryptography triage?

conradoplg
conradoplg previously approved these changes Jun 9, 2022
Copy link
Collaborator

@conradoplg conradoplg left a comment

Choose a reason for hiding this comment

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

Looks good

@dconnolly
Copy link
Contributor Author

https://github.com/Mergifyio update

Co-authored-by: Janito Vaqueiro Ferreira Filho <[email protected]>
@mergify
Copy link
Contributor

mergify bot commented Jun 16, 2022

update

✅ Branch has been successfully updated

@dconnolly
Copy link
Contributor Author

Mergifyio update

@teor2345
Copy link
Contributor

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Jun 28, 2022

update

✅ Branch has been successfully updated

Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Re-approving based on previous approvals

daira
daira previously approved these changes Jun 28, 2022
Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

Untested ACK.

mergify bot added a commit that referenced this pull request Jun 28, 2022
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

@teor2345 teor2345 assigned oxarbitrage and unassigned dconnolly Jun 28, 2022
Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

re-untested ACK

Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Thanks for these clippy fixes, sorry no-one reviewed this PR until now!

@teor2345
Copy link
Contributor

teor2345 commented Aug 1, 2022

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Aug 1, 2022

update

✅ Branch has been successfully updated

mergify bot added a commit that referenced this pull request Aug 1, 2022
@mergify mergify bot merged commit bdd2808 into main Aug 1, 2022
@mergify mergify bot deleted the check-commit-ivk-result branch August 1, 2022 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code NU-5 Network Upgrade: NU5 specific tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Orchard: ensure that ivk = 0 is rejected if that negligible case occurs
6 participants