StratisBitcoinFullNode icon indicating copy to clipboard operation
StratisBitcoinFullNode copied to clipboard

BlockMerkleRootRule - clarify leaves maximum

Open ghost opened this issue 5 years ago • 1 comments

Hi,

I've been reading BlockMerkleRootRule.cs and I have encountered the following line: https://github.com/stratisproject/StratisBitcoinFullNode/blob/master/src/Stratis.Bitcoin.Features.Consensus/Rules/CommonRules/BlockMerkleRootRule.cs#L73 containing:

/// <remarks>This implements a constant-space merkle root/path calculator, limited to 2^32 leaves.</remarks>

The remark is misleading because leaves input parameter of the function:

public static uint256 ComputeMerkleRoot(List<uint256> leaves, out bool mutated)

is limited to Int32.MaxValue elements which is actually lower, i.e. 2^31 - 1. So the implementation can handle rather Int32.MaxValue leaves and not 2^32 leaves.

ghost avatar Mar 07 '19 11:03 ghost

I think this is mostly correct, but 0 can be a leaf too. So the maximum is Int32.MaxValue + 1 = 2^31.

rowandh avatar Mar 07 '19 12:03 rowandh