zcash / lightwalletd

Lightwalletd is a backend service that provides a bandwidth-efficient interface to the Zcash blockchain
MIT License
83 stars 86 forks source link

Implement ZIP 244 txid logic for v5 transactions #392

Open str4d opened 2 years ago

str4d commented 2 years ago

Support for parsing v5 transactions (as specified in ZIP 225) was added in #367. However, the txid computation for v5 transactions (as specified in ZIP 244) was not implemented. This means that at present, lightwalletd returns incorrect txids for v5 transactions in compact blocks:

https://github.com/zcash/lightwalletd/blob/ab4c0fef70dcb195f131d3d794e0c9cec2972dba/common/common.go#L261-L274

https://github.com/zcash/lightwalletd/blob/ab4c0fef70dcb195f131d3d794e0c9cec2972dba/parser/block.go#L108-L127

https://github.com/zcash/lightwalletd/blob/ab4c0fef70dcb195f131d3d794e0c9cec2972dba/parser/transaction.go#L379-L383

https://github.com/zcash/lightwalletd/blob/ab4c0fef70dcb195f131d3d794e0c9cec2972dba/parser/transaction.go#L346-L365

str4d commented 2 years ago

367 had test vectors that include txids; these passed because the test conditional was backwards, and checking that the derived txid didn't match the test vector.

https://github.com/zcash/lightwalletd/blob/ab4c0fef70dcb195f131d3d794e0c9cec2972dba/parser/transaction_test.go#L88-L90

str4d commented 1 year ago

Reopening because this shouldn't have been closed by #393 (which only partially fixed the problem, the internal code still derives the wrong txid and needs fixing).

LarryRuane commented 1 year ago

@str4d, prompted by your recent comment, I began looking into this and discovered that the Golang version of blake2b doesn't have the personalization interface. Investigating this, I found that you had already opened an issue against this 4 years ago: https://github.com/golang/go/issues/32447#issue-452464387

Since this has still not been implemented, I went ahead and wrote a patch to zcashd's getblock RPC to add another verbosity level, 3, that returns exactly the information that lightwalletd needs. I know you don't like this, but it bothers me greatly that lightwalletd makes two RPC calls for each block it fetches (one at verbosity=1 to get the txids, and another at verbosity=0 to get the raw block hex). The lightwalletd sync now takes about 12 hours on my high-end desktop, and reducing the number of RPCs by half is sure to help.

Think of it as a short-term improvement until Golang can implement blake2 properly.

The lightwalletd PR is #449 and the corresponding zcashd PR is https://github.com/zcash/zcash/pull/6747. (These can be merged and deployed in either order.)