Merkle Path Binary Format

Deggen ([email protected])

Abstract

We propose a binary format for a Single Merkle Path optimized for storage in a key value database.

This BRC is licensed under the Open BSV license.

Motivation

The TSC format includes oddities in it for future extensions which are no longer necessary since they are covered by the compound merkle path format defined in BRC-61. So now we attempt to specify the smallest possible encoding of a simple merkle path.

Specification

We take the JSON version from BRC-58 eg.


{ 
   "index": 136,
   "path": [
	"6cf512411d03ab9b61643515e7aa9afd005bf29e1052ade95410b3475f02820c",
	"cd73c0c6bb645581816fa960fd2f1636062fcbf23cb57981074ab8d708a76e3b",
	"b4c8d919190a090e77b73ffcd52b85babaaeeb62da000473102aca7f070facef",
	"3470d882cf556a4b943639eba15dc795dffdbebdc98b9a98e3637fda96e3811e"
    ]
}

Encoding in bytes we start with a VarInt for index, followed by nPath being the number of leaves to follow, followed by 32 byte leaves.

Data Types

Field
Description
Size

index

VarInt tx index number from within a block

1-9 bytes

nLeaves

VarInt number of leaves which follow

1-9 bytes

leaf

Each leaf of the path is a 32 byte hash

32 bytes x nLeaves

Example

Hex

Bytewise Breakdown

Implementation

Let's start by dumping this format as hex into a Buffer and parsing it into an object with a Buffer Reader. Then we construct an object

Last updated

Was this helpful?