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

Fix block height encoding for heights 1-16 #517

Closed
teor2345 opened this issue May 31, 2021 · 1 comment
Closed

Fix block height encoding for heights 1-16 #517

teor2345 opened this issue May 31, 2021 · 1 comment

Comments

@teor2345
Copy link
Contributor

teor2345 commented May 31, 2021

The Zcash mainnet and testnet chains encode heights 1 to 16 (inclusive) as individual numeric opcodes (OP_N). These opcodes are encoded as n + 0x50.

But the spec requires a "1-byte signed little endian" encoding:

image

Here is the coinbase field of mainnet block 1, showing the OP_1 encoding:

{
  "hash": "0007bc227e1c57a4a70e237cad00e7b7ce565155ab49166bc57397a26d339283",
  "height": 1,
  "tx": [
    {
      "txid": "851bf6fbf7a976327817c738c489d7fa657752445430922d94c983c0b9ed4609",
      "version": 1,
      "vin": [
        {
          "coinbase": "5100",
        }
      ],
    },
  ],
}

(I removed all the irrelevant fields.)

Here is an example of correct deserialization:

// Blocks 1 through 16 inclusive encode block height with OP_N opcodes.
(Some(op_n @ 0x51..=0x60), len) if len >= 1 => Height((op_n - 0x50) as u32),

Based on https://github.com/ZcashFoundation/zebra/blob/ebe1c9f88ecc44570ee335c3e8a25bcb53672acd/zebra-chain/src/transparent/serialize.rs#L55-L60

@daira
Copy link
Collaborator

daira commented May 31, 2021

Thanks, I'll fix it.

@daira daira added this to the Core Sprint 2021-20 milestone Jun 1, 2021
@daira daira closed this as completed in 9e2938b Jun 6, 2021
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

No branches or pull requests

2 participants