LibBinaryMerkleTree
State Variables
LOG2_MAX_DATA_BLOCK_SIZE
Log2 of the maximum data block size.
The data block must still be smaller than the drive. We limit the size of data blocks because of the block gas limit.
uint256 constant LOG2_MAX_DATA_BLOCK_SIZE = 12
Functions
merkleRootAfterReplacement
Compute the root of a Merkle tree after replacing one of its nodes.
Level of node is deduced by the length of the siblings array.
Raises an InvalidNodeIndex error if an invalid node index is provided.
function merkleRootAfterReplacement(
bytes32[] calldata sibs,
uint256 nodeIndex,
bytes32 node,
function(bytes32, bytes32) pure returns (bytes32) nodeFromChildren
) internal pure returns (bytes32);
Parameters
| Name | Type | Description |
|---|---|---|
sibs | bytes32[] | The siblings of the node in bottom-up order |
nodeIndex | uint256 | The index of the node |
node | bytes32 | The new node |
nodeFromChildren | function (bytes32, bytes32) pure returns (bytes32) | The function that computes nodes from their children |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bytes32 | The root hash of the new Merkle tree |
merkleRoot
Get the Merkle root of a byte array.
Data blocks are right-padded with zeros if necessary.
leafFromDataAt receives the data, the block index, and the block size
function merkleRoot(
bytes memory data,
uint256 log2DriveSize,
uint256 log2DataBlockSize,
function(bytes memory, uint256, uint256) pure returns (bytes32) leafFromDataAt,
function(bytes32, bytes32) pure returns (bytes32) nodeFromChildren
) internal pure returns (bytes32);
Parameters
| Name | Type | Description |
|---|---|---|
data | bytes | The byte array |
log2DriveSize | uint256 | The log2 of the drive size |
log2DataBlockSize | uint256 | The log2 of the data block size |
leafFromDataAt | function (bytes memory, uint256, uint256) pure returns (bytes32) | The function that computes leaves from data blocks |
nodeFromChildren | function (bytes32, bytes32) pure returns (bytes32) | The function that computes nodes from their children |