-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Comments
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. |
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.
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. |
I outlined my proposal in #174 (comment), which is the parent for (1) in OP title. |
We changed the title to use "adapt" because we need to change these parts on top of SIGHASH_FORKID:
|
Also, let's pick a better name from
|
Are we sure we want to fix quadratic hashing, value signing in NU0? |
The simplest thing seems to be just to change |
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. |
Right, my mistake, I thought you need to create an artificial script with a lot of checksigs to run into this. |
Here's my first attempt at adapting the linear hashing code from bitcoin https://github.com/arielgabizon/zcash/tree/fix-quadratic-hashing |
Here's my second attempt, using cherry-pick instead of copy-paste as @str4d requested https://github.com/arielgabizon/zcash/tree/integrate-quadhash-fix |
The function |
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. |
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. |
"Overwinter signature hashing" will do fine. |
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.
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.
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.
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.
Closed by #2903. |
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
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.
The text was updated successfully, but these errors were encountered: