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

[WIP]Feat/zcash #1366

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft

[WIP]Feat/zcash #1366

wants to merge 28 commits into from

Conversation

soralit
Copy link
Contributor

@soralit soralit commented Sep 26, 2024

Keystone Zcash UR Registries

This protocol is based on the Uniform Resources. It describes the data schemas (UR Registries) used in Zcash integrations.

Introduction

Keystone's QR workflow involves two main steps: linking the wallet and signing data, broken down into three sub-steps:

  1. Wallet Linking: Keystone generates a QR code with public key info for the Watch-Only wallet to scan and import.
  2. Transaction Creation: The Watch-Only wallet creates a transaction and generates a QR code for Keystone to scan, parse, and display.
  3. Signing Authorization: Keystone signs the transaction, displays the result as a QR code for the Watch-Only wallet to scan and broadcast.

Two UR Registries are needed for these steps, utilizing the Partially Created Zcash Transaction structure.

Zcash Accounts

Unified Full Viewing Key (UFVK)

UFVK is a standard account expression format in Zcash as per ZIP-316. It consists of:

  1. Transparent
  2. Sprout
  3. Sapling
  4. Orchard

This protocol focuses on the Transparent and Orchard components.

CDDL for Zcash Accounts

The specification uses CDDL and includes crypto-hdkey and crypto-key-path specs defined in https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2020-007-hdkey.md.

zcash-accounts = {
    seed-fingerprint: bytes.32, ; the seed fingerprint specified by ZIP-32 to identify the wallet
    accounts: [+ zcash-ufvk],
    ? origin: text, ; source of data, e.g., Keystone
}

zcash-ufvk = {
    ? transparent: crypto-hdkey,
    orchard: zcash-fvk,
    ? name: text,
}

zcash-fvk = {
    key-path: crypto-key-path,
    key-data: bytes,
}

zcash-ufvk describes the UFVK of a Zcash account. Each seed has multiple accounts with different indexes. For index 0, zcash-ufvk should contain a BIP32 extended public key with path M/44'/133'/0' (transparent) and an Orchard FVK with path M_orchard/32'/133'/0' (Orchard).

CDDL for Zcash PCZT

zcash-pczt {
    data: bytes, ; Zcash PCZT, signatures inserted after signing.
}

@soralit soralit marked this pull request as draft September 26, 2024 02:15

```cddl
zcash-accounts = {
master-fingerprint: uint32, ; the master fingerprint to identify the wallet
Copy link

Choose a reason for hiding this comment

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

ZIP 32 specifies a 16-byte seed fingerprint: https://zips.z.cash/zip-0032#seed-fingerprints
It's a byte array so endian-independent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's good to use this seed fingerprint instead.

}
```

`zcash-ufvk` describes the UFVK of a Zcash account. Each seed has multiple accounts with different indexes. For index 0, `zcash-ufvk` should contain a BIP32 extended public key with path `M/44'/133'/0'` (transparent) and an Orchard FVK with path `M_orchard/32'/133'/0'` (Orchard).
Copy link

Choose a reason for hiding this comment

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

Specify that:

133' is for mainnet. Like other coins, we use 1' for testnet as specified in SLIP 44.

@soralit
Copy link
Contributor Author

soralit commented Oct 8, 2024

Latest protocol is updated in the code base.

@daira
Copy link

daira commented Oct 8, 2024

//is versionGroupId still needed?

The purpose of versionGroupId is to unambiguously identify the transaction format even if version numbers are reused across Zcash forks, and that's still relevant for PCZTs.

I think we'd want to include Sapling components even if it isn't supported for Keystone, because it is needed for other applications of PCZTs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a proto file. Also added the sapling definitions.

@soralit soralit force-pushed the feat/zcash branch 3 times, most recently from 9cda39e to 90596a9 Compare October 9, 2024 09:38
Copy link

Choose a reason for hiding this comment

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

I see that the barred Z is transparent. I think that's correct in that it should be white in light mode and black in dark mode (see "Horizontal logos" or "Vertical logos" at https://z.cash/press/ ).

Copy link

Choose a reason for hiding this comment

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

This is probably not going to work in light mode, because the Zashi logo and name are in white.

@soralit soralit force-pushed the feat/zcash branch 3 times, most recently from 13f57a2 to a809fdc Compare October 14, 2024 05:31
@soralit soralit force-pushed the feat/zcash branch 2 times, most recently from 515890a to ea142af Compare November 5, 2024 10:13
@soralit soralit force-pushed the feat/zcash branch 3 times, most recently from 6786374 to 65ec54c Compare December 10, 2024 10:06
Comment on lines +80 to +86
if target.public_key().serialize().to_vec()
!= input.script_pubkey().clone()
{
return Err(ZcashError::InvalidPczt(
"transparent input script pubkey mismatch".to_string(),
));
}
Copy link

Choose a reason for hiding this comment

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

I have not confirmed the alterations to your vendored code, but if target here has type bip32::ExtendedPublicKey<secp256k1::PublicKey> (like it does inside zcash_primitives::legacy::keys::AccountPubKey) then there is a bug here: you are comparing the serialized public key to the script_pubkey, but for P2PKH scripts the serialized public key appears in the script_sig; only its hash is present in script_pubkey.

Comment on lines +57 to +61
match script.address() {
Some(TransparentAddress::PublicKeyHash(hash)) => {
let pubkey = input.bip32_derivation().keys().find(|pubkey| {
return hash[..] == Ripemd160::digest(Sha256::digest(pubkey))[..];
});
Copy link

Choose a reason for hiding this comment

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

Similarly, this check is incorrect:

  • hash is the hash of the script_pubkey
  • input.bip32_derivation() contains a map from the encoded public key to its derivation.

This follows PSBT semantics (from BIP 174) where the derivation map lists encoded keys; bip32_derivation is not a map from script_pubkey to derivation path. This is because a P2SH script may contain multiple such keys and require multiple signatures. A P2PKH script happens to only contain one, but for symmetry the PCZT format treats it the same way (like PSBT).

Comment on lines +112 to +117
match script.address() {
Some(TransparentAddress::PublicKeyHash(hash)) => {
let pubkey = output
.bip32_derivation()
.keys()
.find(|pubkey| hash[..] == Ripemd160::digest(Sha256::digest(pubkey))[..]);
Copy link

Choose a reason for hiding this comment

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

This is similarly incorrect.

Comment on lines +136 to +142
if target.public_key().serialize().to_vec()
!= output.script_pubkey().clone()
{
return Err(ZcashError::InvalidPczt(
"transparent output script pubkey mismatch".to_string(),
));
}
Copy link

Choose a reason for hiding this comment

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

This is similarly incorrect.

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.

3 participants