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

Changes required for Keystone firmware support #1666

Merged
merged 12 commits into from
Jan 29, 2025
Merged

Changes required for Keystone firmware support #1666

merged 12 commits into from
Jan 29, 2025

Conversation

nuttycom
Copy link
Contributor

@nuttycom nuttycom commented Dec 17, 2024

This is a feature branch depended on by the downstream Keystone firmware; do not rebase it.

nuttycom and others added 2 commits December 17, 2024 05:11
This depends upon an updated fork or `bip32` maintained by `KeystoneHQ`
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 8.95522% with 61 lines in your changes missing coverage. Please review.

Project coverage is 51.89%. Comparing base (2ec38ba) to head (6dab605).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
pczt/src/common.rs 0.00% 27 Missing ⚠️
pczt/src/roles/low_level_signer/mod.rs 0.00% 24 Missing ⚠️
devtools/src/bin/inspect/transaction.rs 0.00% 2 Missing ⚠️
zcash_client_sqlite/src/wallet/sapling.rs 33.33% 2 Missing ⚠️
zcash_transparent/src/builder.rs 0.00% 2 Missing ⚠️
components/zcash_protocol/src/consensus.rs 0.00% 1 Missing ⚠️
pczt/src/roles/tx_extractor/mod.rs 0.00% 1 Missing ⚠️
zcash_client_backend/src/data_api/testing.rs 50.00% 1 Missing ⚠️
zcash_transparent/src/pczt/signer.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1666      +/-   ##
==========================================
- Coverage   52.23%   51.89%   -0.34%     
==========================================
  Files         179      180       +1     
  Lines       21351    21169     -182     
==========================================
- Hits        11152    10986     -166     
+ Misses      10199    10183      -16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@str4d str4d changed the title Changes required for keystone support that require dependency updates beyond what we can currently do. Changes required for Keystone firmware support Jan 28, 2025
@str4d str4d marked this pull request as ready for review January 28, 2025 04:24
Instead the PCZT is parsed into its protocol-specific types, and getters
on those are used.

The remaining getters are used for sighash derivation, the one part of
the stack that is not currently modular.
"unicode-normalization",
"zeroize",
]

[[package]]
name = "bip32"
version = "0.5.1"
version = "0.6.0-pre.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the preview version? I was unable to find any documentation of what changed in the preview here: https://github.com/iqlusioninc/crates/blob/bip32/v0.6.0-pre.1/bip32/CHANGELOG.md (or in corresponding files for the RustCrypto dependencies).

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, it's to get iqlusioninc/crates#1254

Copy link
Contributor

@daira daira Jan 28, 2025

Choose a reason for hiding this comment

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

Depending on all of these previews and rcs does not seem ideal.

  • hmac 0.13.0-pre.4
  • ripemd 0.2.0-pre.4
  • sha2 0.11.0-pre.4
  • digest 0.11.0-pre.9
  • block-buffer 0.11.0-rc.3
  • crypto-common 0.2.0-rc.1

I realize it's only temporary, and that you asked @tony-iqlusion for a backport here. (I guess a bip32 0.6.0 release would do as well given that we've bitten the bullet of MSRV 1.81.0. But that would also require releases of the crates above iiuc.)

Choose a reason for hiding this comment

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

Here's a bip32 v0.5.3 backport release, however be aware it uses an older version of the secp256k1 crate (v0.27) to retain compatibility with other v0.5.x releases: https://github.com/iqlusioninc/crates/pull/1261/files

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd hoped that a backport might suffice, but it turned out to be necessary to use secp256k1 0.29 because the firmware already did, and duplicate C bindings would be a nightmare.

Choose a reason for hiding this comment

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

Note v0.30 is out and we'll bump to that (at least) before a final release

Copy link
Contributor

Choose a reason for hiding this comment

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

So maybe we should ask Keystone to bump the firmware to secp256k1 0.30?

@tony-iqlusion when you say "at least", is that just because there might be another release after 0.30 that you could opportunistically upgrade to, or might it be necessary? (At a glance, 0.30 was tagged only last week but there are some significant changes since that tag, basically updating from rustsecp256k1_v0_10_0_* to rustsecp256k1_v0_11_*.)

Choose a reason for hiding this comment

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

Ideally we'd bump to whatever the latest version is prior to a final release

Copy link
Contributor

@daira daira Feb 4, 2025

Choose a reason for hiding this comment

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

The problem we were having with this has apparently been resolved by zcash/zcash-devtool#78, so all good for now.

@@ -36,6 +39,7 @@ pub struct Global {
/// - If omitted, the fallback locktime is assumed to be 0.
pub(crate) fallback_lock_time: Option<u32>,
Copy link
Contributor

@daira daira Jan 28, 2025

Choose a reason for hiding this comment

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

Why doesn't this have #[getset(get = "pub")]? Similarly for coin_type, and for some other fields in orchard.rs and sapling.rs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that this is intended to be set only by the Constructor role.

pub(crate) value_sum: (u64, bool),

/// The Orchard anchor for this transaction.
///
/// Set by the Creator.
#[getset(get = "pub")]
pub(crate) anchor: [u8; 32],

/// The Orchard bundle proof.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should zkproof and bsk have #[getset(get = "pub")]?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not until we find a need for those getters in protocol-unaware code (maybe for deriving the Authorizing Data Commitment, but I don't yet see a need to do that for an in-progress transaction).

@@ -67,6 +70,7 @@ pub struct Action {
// These are required fields that are part of the final transaction, and are filled in
// by the Constructor when adding an output.
//
#[getset(get = "pub")]
pub(crate) cv_net: [u8; 32],
#[getset(get = "pub")]
pub(crate) spend: Spend,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should rcv have #[getset(get = "pub")]?

Copy link
Contributor

Choose a reason for hiding this comment

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

It was not necessary on the protocol-agnostic type for the sighash calculation (as it's private data, and useless for checking commitments without protocol awareness).

@@ -97,6 +101,7 @@ pub struct Spend {
//
#[getset(get = "pub")]
pub(crate) nullifier: [u8; 32],
#[getset(get = "pub")]
pub(crate) rk: [u8; 32],

/// The spend authorization signature.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should some of the fields below have #[getset(get = "pub")]?

pub(crate) enc_ciphertext: Vec<u8>,
/// The encrypted note plaintext for the output.
///
/// Encoded as a `Vec<u8>` because its length depends on the transaction version.
#[getset(get = "pub")]
pub(crate) out_ciphertext: Vec<u8>,

/// The [raw encoding] of the Orchard payment address that will receive the output.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should ock and zip32_derivation have #[getset(get = "pub")]?

pub(crate) value_sum: i128,

/// The Sapling anchor for this transaction.
///
/// Set by the Creator.
#[getset(get = "pub")]
pub(crate) anchor: [u8; 32],

/// The Sapling binding signature signing key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should bsk have #[getset(get = "pub")]?

pub(crate) nullifier: [u8; 32],
#[getset(get = "pub")]
pub(crate) rk: [u8; 32],

/// The Spend proof.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should some of the fields below have #[getset(get = "pub")]?

@@ -66,6 +67,7 @@ pub struct Input {
// needed for computing the binding signatures.
#[getset(get = "pub")]
pub(crate) value: u64,
#[getset(get = "pub")]
pub(crate) script_pubkey: Vec<u8>,

/// The script required to spend this output, if it is P2SH.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should some of the fields below have #[getset(get = "pub")]?

pub(crate) value: u64,
#[getset(get = "pub")]
pub(crate) script_pubkey: Vec<u8>,

/// The script required to spend this output, if it is P2SH.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should redeem_script and bip32_derivation have #[getset(get = "pub")]?

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.

utACK with comments.

Copy link
Contributor Author

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

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

utACK 6dab605 (I opened this PR and so can't give it an Approve review)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume that after these changes, we'll do the rest of the devtools removal (in favor of having this functionality in zcash-devtool?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct (it should have been done already, but not going to disturb this PR further).

@@ -36,6 +39,7 @@ pub struct Global {
/// - If omitted, the fallback locktime is assumed to be 0.
pub(crate) fallback_lock_time: Option<u32>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that this is intended to be set only by the Constructor role.

ripemd = { version = "0.1", default-features = false }
secp256k1 = { version = "0.27", default-features = false, features = ["alloc"] }
secp256k1 = { version = "0.29", default-features = false, features = ["alloc"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: secp256k1 and bip32 need to be mentioned in the changelogs. I'll do that in a follow-up PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@str4d str4d merged commit 9f5355c into main Jan 29, 2025
31 of 33 checks passed
@str4d str4d deleted the keystone_no_std branch January 29, 2025 09:40
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.

4 participants