<p>You are correct that the Sprout commitment tree root / anchor is not stored in the block header. It is <a href="https://github.com/zcash/zcash/blob/master/src/main.cpp#L2520" rel="nofollow noreferrer">calculated by each node when a block arrives</a>, and is stored in the <a href="https://github.com/zcash/zcash/blob/master/src/chain.h#L155-L159" rel="nofollow noreferrer">block index</a>.</p>

<p>The Sapling commitment tree root <em>is</em> stored in the <a href="https://github.com/zcash/zcash/blob/master/src/primitives/block.h#L29" rel="nofollow noreferrer">block header</a> (in what was the <code>hashReserved</code> field); nodes <a href="https://github.com/zcash/zcash/blob/master/src/main.cpp#L2524-L2532" rel="nofollow noreferrer">check this against the block contents</a> and reject blocks with an invalid root in the header. This will make shielded address support significantly easier to implement for light clients.</p>

<p>The mappings from Sprout and Sapling tree roots to the IncrementalMerkleTrees themselves are stored in the coins database, and can be accessed wherever you have a <a href="https://github.com/zcash/zcash/blob/master/src/coins.h#L343-L347" rel="nofollow noreferrer">CCoinsView</a>.</p>

CC BY-SA 4.0
2018-06-13T04:50:38.297Z
2018-06-13T04:50:38.297Z
str4d
<p>Where are the treestates stored?<br>
In other words, when a JoinSplit transaction is being validated, where is the anchor being checked?<br>
A look at <a href="https://github.com/zcash/zcash/blob/master/src/primitives/block.h" rel="nofollow noreferrer">https://github.com/zcash/zcash/blob/master/src/primitives/block.h</a> brings me to conclude that the commitments (i.e., notes) merkle-tree is not stored in the block-header.<br>
Is it in a LevelDB database?<br>
What is the data-structure it uses for storing the mapping of trees roots for blocks?</p>

<p>Any answer with a specific reference to code will be very appreciated.</p>

<zcash>
Zcash - where are treestates stored?
oleiba
# Zcash - where are treestates stored?

(Asked by: username_0 on 2018-03-14)

Where are the treestates stored?  
In other words, when a JoinSplit transaction is being validated, where is the anchor being checked?  
A look at <https://github.com/zcash/zcash/blob/master/src/primitives/block.h> brings me to conclude that the commitments (i.e., notes) merkle-tree is not stored in the block-header.  
Is it in a LevelDB database?  
What is the data-structure it uses for storing the mapping of trees roots for blocks?

Any answer with a specific reference to code will be very appreciated.

**Tags:** zcash


---

## 1 answers

### Answer by username_1 on 2018-06-13. Score: 1 | Accepted answer

You are correct that the Sprout commitment tree root / anchor is not stored in the block header. It is [calculated by each node when a block arrives](https://github.com/zcash/zcash/blob/master/src/main.cpp#L2520), and is stored in the [block index](https://github.com/zcash/zcash/blob/master/src/chain.h#L155-L159).

The Sapling commitment tree root *is* stored in the [block header](https://github.com/zcash/zcash/blob/master/src/primitives/block.h#L29) (in what was the `hashReserved` field); nodes [check this against the block contents](https://github.com/zcash/zcash/blob/master/src/main.cpp#L2524-L2532) and reject blocks with an invalid root in the header. This will make shielded address support significantly easier to implement for light clients.

The mappings from Sprout and Sapling tree roots to the IncrementalMerkleTrees themselves are stored in the coins database, and can be accessed wherever you have a [CCoinsView](https://github.com/zcash/zcash/blob/master/src/coins.h#L343-L347).


---

