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

Adapt SIGHASH_FORKID for (1) NU0 replay protection (2) fixing quadratic hashing (3) hardware wallets #2584

Closed
bitcartel opened this issue Aug 15, 2017 · 16 comments
Assignees
Labels
I-performance Problems and improvements with respect to performance I-SECURITY Problems and improvements related to security. network upgrade management Z-NU0 wishlist

Comments

@bitcartel
Copy link
Contributor

bitcartel commented Aug 15, 2017

Edit 2017-11-20 by Nathan: We need to adapt SIGHASH_FORKID for Zcash by making several modifications: see #2584 (comment). Fulfilling this ticket requires doing that design work.

Upstream Bitcoin Cash clients have implemented SIGHASH_FORKID for

  1. Replay protection
  2. Quadratic hashing fix
  3. Lightweight wallet signing e.g. hardware wallets

SIGHASH_FORKID is specified here:
https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/doc/abc/replay-protected-sighash.md
and discussed in context here:
https://github.com/Bitcoin-UAHF/spec/blob/master/uahf-technical-spec.md

SIGHASH_FORKID is an implementation of the digest algorithm for transaction signature verification as described in BIP143 (and used in BIP 141).
https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki

This ticket can resolve #1162, #2411, #2415, #2566 and satisfy #2254.

@nathan-at-least
Copy link
Contributor

How much evaluation does that scheme have?

One immediate thought after a scan is item 6 in the Digest Algorithm section:

Doesn't this add a new dependency on signature verification where the verifier must load one transaction for every input to look up the value? If so, that changes signature validation from "contextless" to requiring a transaction (or UTXO) index, which seems like a major change. Maybe there's a way around it by requiring the prevout values to be serialized next to the transaction?

Anyway, I need to think about this a lot more (as well as an alternative proposal from @str4d, and potentially others) before I feel comfortable with it.

@str4d
Copy link
Contributor

str4d commented Nov 15, 2017

How much evaluation does that scheme have?

AFAICT (hard to tell quickly because the SIGHASH_FORKID proposal copied and then changed the Markdown formatting), the only difference between this proposal and BIP 143 is the ORing of a 24-bit fork ID into the sighash type. Thus it has the entirety of SegWit evaluation behind it.

One immediate thought after a scan is item 6 in the Digest Algorithm section:

Doesn't this add a new dependency on signature verification where the verifier must load one transaction for every input to look up the value? If so, that changes signature validation from "contextless" to requiring a transaction (or UTXO) index, which seems like a major change. Maybe there's a way around it by requiring the prevout values to be serialized next to the transaction?

This lookup has always been necessary; the sighash change just changes where it happens. Currently, the only way to verifiably check the value balance for a transaction is to load the input transactions, and validate them. This is fine for full nodes, but a lot of overhead for e.g. hardware wallets (see this TREZOR blogpost). With this change, the hardware wallet can just be given the values, and know that they are authentic (because they are part of the signature, rather than a hop away through the prevouts). The value still needs to be looked up, but this can be done when a block arrives, and then cached for later use.

@str4d
Copy link
Contributor

str4d commented Nov 15, 2017

I outlined my proposal in #174 (comment), which is the parent for (1) in OP title.

@nathan-at-least nathan-at-least changed the title Backport SIGHASH_FORKID for (1) HF0 replay protection (2) fixing quadratic hashing (3) hardware wallets Adapt SIGHASH_FORKID for (1) HF0 replay protection (2) fixing quadratic hashing (3) hardware wallets Nov 20, 2017
@nathan-at-least
Copy link
Contributor

nathan-at-least commented Nov 27, 2017

We changed the title to use "adapt" because we need to change these parts on top of SIGHASH_FORKID:

  • pick a better name (see next comment).
  • require new transactions to use this scheme. It will no longer be possible for version 3 txns to use "legacy" quadratic hashing.
  • specify how JoinSplits are covered by signatures.
  • change the hashing scheme to blake2 with first-class personalization.
  • add guidance for future upgrades about how to use the personalization field, especially when considering competing alternatives.

@nathan-at-least nathan-at-least changed the title Adapt SIGHASH_FORKID for (1) HF0 replay protection (2) fixing quadratic hashing (3) hardware wallets Adapt SIGHASH_FORKID for (1) NU0 replay protection (2) fixing quadratic hashing (3) hardware wallets Nov 27, 2017
@nathan-at-least
Copy link
Contributor

Also, let's pick a better name from SIGHASH_FORKID, which is confusing in a few ways:

  • The hashing scheme for signature generation/validation applies to all SIGHASH_* types, such as SIGHASH_ALL.
  • We wish to avoid the word fork due to various ambiguities.

@str4d str4d added this to the 1.0.14 milestone Nov 29, 2017
@arielgabizon
Copy link
Contributor

Are we sure we want to fix quadratic hashing, value signing in NU0?
If we would just want replay protection it would be much simpler probably.

@arielgabizon
Copy link
Contributor

arielgabizon commented Dec 2, 2017

The simplest thing seems to be just to change nversion to something unique for the fork.
I mean, is someone really attacking any network with huge transactions with a lot of signatures? And they would have to keep it up for a lot of blocks to get any DOS effect.
Let's keep it simple so we can focus on deploying Sapling.

@str4d
Copy link
Contributor

str4d commented Dec 2, 2017

I mean, is someone really attacking any network with huge transactions with a lot of signatures? And they would have to keep it up for a lot of blocks to get any DOS effect.

We already see this happening non-maliciously: there are various exchanges trying to merge many UTXOs into more usable amounts. The first time this happened, individual blocks were taking between six and ten seconds to validate (see #2333), which broke many of the mining pools, and is why we implemented #2342 as a short-term fix. There are various other optimisations we need to pull in from upstream (#2333 (comment)), but it isn't going to be possible to noticeably decrease the size of the UTXO set for these exchanges without fixing the quadratic hashing problem.

@arielgabizon
Copy link
Contributor

Right, my mistake, I thought you need to create an artificial script with a lot of checksigs to run into this.
There's still the question, do we want to do replay protection with this signature type SIGHASH_FORKID, or just change the nversion for the fork?
And I'm curious with the short-term fix what num of inputs are miners allowing?
And is that interfering with mining pools' ability to make large transactions?

@arielgabizon
Copy link
Contributor

Here's my first attempt at adapting the linear hashing code from bitcoin https://github.com/arielgabizon/zcash/tree/fix-quadratic-hashing

@arielgabizon
Copy link
Contributor

Here's my second attempt, using cherry-pick instead of copy-paste as @str4d requested https://github.com/arielgabizon/zcash/tree/integrate-quadhash-fix
I have detailed notes about the process, with all the things I didn't cherry-pick on the way, that we may want to integrate.

@arielgabizon
Copy link
Contributor

The function signatureHash will be changed when we decide on our hardfork mechanism.

@str4d str4d modified the milestones: 1.0.14, NU0 Specification Jan 2, 2018
@daira
Copy link
Contributor

daira commented Jan 8, 2018

I think we should use BLAKE2b-256 rather than BLAKE2s. Section 3.3 of the BLAKE2 paper says that "a typical implementation of [BLAKE2s] in embedded software stores in RAM at least [168 bytes]. BLAKE2b only requires 336 bytes of RAM [...]".

The difference between 168 and 336 bytes is not material even for embedded implementations. For a hardware wallet you'll also want to be doing EdDSA signing, which also likely requires at least 336 bytes (and you don't need to do signing and hashing at the same time). For reference, Trezor uses a Cortex M3 with 128 KiB of RAM.

Therefore, we should choose the (significantly) faster BLAKE2b-256, to reduce the cost of hashing large transactions/blocks.

@daira
Copy link
Contributor

daira commented Jan 10, 2018

The Ledger Nano S uses an ST31H320 with 10 KiB of RAM. This is still sufficient that the difference in RAM usage between BLAKE2s and BLAKE2b is unlikely to be an obstacle.

Note that EdDSA requires a hash with 512-bit output for which we are going to use BLAKE2b (see #2853), and so an implementation of that will be required in any case for doing shielded spend authorisation signatures.

@daira
Copy link
Contributor

daira commented Jan 11, 2018

Let's call it "Replay-Protected Scalable Lightweight-wallet-friendly hashing" or "RPSL hashing".

"Overwinter signature hashing" will do fine.

zkbot added a commit that referenced this issue Feb 8, 2018
Overwinter SignatureHash

Implements zcash/zips#129.

Includes code cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7276
- bitcoin/bitcoin#7976
- bitcoin/bitcoin#8118
- bitcoin/bitcoin#8149
  - Only amount validation and SignatureHash commits.
- bitcoin/bitcoin#6915
  - Only the rework of `mempool.check()` calls that the next PR depends on.
- bitcoin/bitcoin#8346
- bitcoin/bitcoin#8524

Part of  #2254. Closes #1408 and #2584.
zkbot added a commit that referenced this issue Feb 19, 2018
Overwinter SignatureHash

Implements zcash/zips#129.

Includes code cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7276
- bitcoin/bitcoin#7976
- bitcoin/bitcoin#8118
- bitcoin/bitcoin#8149
  - Only amount validation and SignatureHash commits.
- bitcoin/bitcoin#6915
  - Only the rework of `mempool.check()` calls that the next PR depends on.
- bitcoin/bitcoin#8346
- bitcoin/bitcoin#8524

Part of #2074 and #2254. Closes #1408 and #2584.
zkbot added a commit that referenced this issue Feb 20, 2018
Overwinter SignatureHash

Implements ZIP 143.

Includes code cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7276
- bitcoin/bitcoin#7976
- bitcoin/bitcoin#8118
- bitcoin/bitcoin#8149
  - Only amount validation and SignatureHash commits.
- bitcoin/bitcoin#8346
- bitcoin/bitcoin#8524

Part of #2074 and #2254. Closes #1408 and #2584.
zkbot added a commit that referenced this issue Feb 20, 2018
Overwinter SignatureHash

Implements ZIP 143.

Includes code cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7276
- bitcoin/bitcoin#7976
- bitcoin/bitcoin#8118
- bitcoin/bitcoin#8149
  - Only amount validation and SignatureHash commits.
- bitcoin/bitcoin#8346
- bitcoin/bitcoin#8524

Part of #2074 and #2254. Closes #1408 and #2584.
@str4d
Copy link
Contributor

str4d commented Feb 20, 2018

Closed by #2903.

@str4d str4d closed this as completed Feb 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-performance Problems and improvements with respect to performance I-SECURITY Problems and improvements related to security. network upgrade management Z-NU0 wishlist
Projects
None yet
Development

No branches or pull requests

5 participants