From e0c2123b05839b9c61cc8f057d491294ca2b9b65 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Tue, 24 Mar 2020 14:53:50 +0000 Subject: [PATCH] ZIP 221: change the pseudocode so that CONSENSUS_BRANCH_ID doesn't look as though it's a constant. Signed-off-by: Daira Hopwood --- zip-0221.html | 17 +++++++++-------- zip-0221.rst | 17 +++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/zip-0221.html b/zip-0221.html index 7aef4120..9d9222b8 100644 --- a/zip-0221.html +++ b/zip-0221.html @@ -334,11 +334,8 @@ License: MIT

Once the MMR has been generated, we produce hashChainHistoryRoot, which we define as the BLAKE2b-256 digest of the serialization of the root node.

Tree nodes and hashing (pseudocode)

-
CONSENSUS_BRANCH_ID: bytes = b''
-
-
-def H(msg: bytes) -> bytes:
-    return blake2b256(msg, personalization=b'ZcashHistory' + CONSENSUS_BRANCH_ID)
+                
def H(msg: bytes, consensusBranchId: bytes) -> bytes:
+    return blake2b256(msg, personalization=b'ZcashHistory' + consensusBranchId)
 
 class ZcashMMRNode():
     # leaf nodes have no children
@@ -358,6 +355,8 @@ License: MIT
nLatestHeight: int nSaplingTxCount: int # number of Sapling transactions in block + consensusBranchId: bytes + @classmethod def from_block(Z, block: ZcashBlock) -> ZcashMMRNode: '''Create a leaf node from a block''' @@ -374,7 +373,8 @@ License: MIT
nSubTreeTotalWork=calculate_work(block.nBits), nEarliestHeight=block.height, nLatestHeight=block.height, - nSaplingTxCount=block.sapling_tx_count) + nSaplingTxCount=block.sapling_tx_count, + consensusBranchId=block.consensusBranchId) def serialize(self) -> bytes: '''serializes a node''' @@ -408,11 +408,12 @@ License: MIT nSubTreeTotalWork=left_child.nSubTreeTotalWork + right_child.nSubTreeTotalWork, nEarliestHeight=left_child.nEarliestHeight, nLatestHeight=right_child.nLatestHeight, - nSaplingTxCount=left_child.nSaplingTxCount + right_child.nSaplingTxCount) + nSaplingTxCount=left_child.nSaplingTxCount + right_child.nSaplingTxCount, + consensusBranchId=left_child.consensusBranchId) def make_root_commitment(root: ZcashMMRNode) -> bytes: '''Makes the root commitment for a blockheader''' - return H(root.serialize()) + return H(root.serialize(), root.consensusBranchId)

Incremental push and pop (pseudocode)

With each new block diff --git a/zip-0221.rst b/zip-0221.rst index a0ab45cf..a927baac 100644 --- a/zip-0221.rst +++ b/zip-0221.rst @@ -341,11 +341,8 @@ Tree nodes and hashing (pseudocode) .. code-block:: python - CONSENSUS_BRANCH_ID: bytes = b'' - - - def H(msg: bytes) -> bytes: - return blake2b256(msg, personalization=b'ZcashHistory' + CONSENSUS_BRANCH_ID) + def H(msg: bytes, consensusBranchId: bytes) -> bytes: + return blake2b256(msg, personalization=b'ZcashHistory' + consensusBranchId) class ZcashMMRNode(): # leaf nodes have no children @@ -365,6 +362,8 @@ Tree nodes and hashing (pseudocode) nLatestHeight: int nSaplingTxCount: int # number of Sapling transactions in block + consensusBranchId: bytes + @classmethod def from_block(Z, block: ZcashBlock) -> ZcashMMRNode: '''Create a leaf node from a block''' @@ -381,7 +380,8 @@ Tree nodes and hashing (pseudocode) nSubTreeTotalWork=calculate_work(block.nBits), nEarliestHeight=block.height, nLatestHeight=block.height, - nSaplingTxCount=block.sapling_tx_count) + nSaplingTxCount=block.sapling_tx_count, + consensusBranchId=block.consensusBranchId) def serialize(self) -> bytes: '''serializes a node''' @@ -415,11 +415,12 @@ Tree nodes and hashing (pseudocode) nSubTreeTotalWork=left_child.nSubTreeTotalWork + right_child.nSubTreeTotalWork, nEarliestHeight=left_child.nEarliestHeight, nLatestHeight=right_child.nLatestHeight, - nSaplingTxCount=left_child.nSaplingTxCount + right_child.nSaplingTxCount) + nSaplingTxCount=left_child.nSaplingTxCount + right_child.nSaplingTxCount, + consensusBranchId=left_child.consensusBranchId) def make_root_commitment(root: ZcashMMRNode) -> bytes: '''Makes the root commitment for a blockheader''' - return H(root.serialize()) + return H(root.serialize(), root.consensusBranchId) Incremental push and pop (pseudocode) -------------------------------------