ProofError

Git Source (opens in a new tab)

enum ProofError {
    NONE,
    InvalidProofLeafIdxOutOfBounds,
    InvalidProofBadLeftRange,
    InvalidProofBadRightRange,
    InvalidProofUnrecognizedRoot
}

decomposeNonZeroInterval

Git Source (opens in a new tab)

seedHeight=

Helper for calculating range size for a non-zero-starting interval.

The bitmath here decomposes the interval into two parts that in combination represent the compact range needed to express the interval.

function decomposeNonZeroInterval(uint256 begin, uint256 end) pure returns (uint256 left, uint256 right);

Parameters

NameTypeDescription
beginuint256The start of the interval of the range's coverage (inclusive).
enduint256The end of the interval of the range's coverage (exclusive).

Returns

NameTypeDescription
leftuint256Bitmap representing the left part of the interval.
rightuint256Bitmap representing the right part of the interval.

validateProof

Git Source (opens in a new tab)

function validateProof(Proof calldata proof, uint256 targetTreeSize) pure returns (ProofError);

merge

Git Source (opens in a new tab)

Merges two compact ranges along a given seed node.

Merge folds hashes in from leftRange and rightRange into seed in order to create a combined compact range. The merged range is left + seed + right. leftRange is assumed to start its coverage at index 0.

function merge(
    bytes32[] calldata leftRange,
    bytes32 seed,
    uint256 seedHeight,
    uint256 seedIndex,
    bytes32[] calldata rightRange,
    uint256 rightRangeEnd
)
    pure
    returns (bytes32[] calldata left, bytes32 newSeed, bytes32[] calldata right);

Parameters

NameTypeDescription
leftRangebytes32[]The left compact range to merge.
seedbytes32The seed node to merge along.
seedHeightuint256The height of the seed node.
seedIndexuint256The index of the seed node.
rightRangebytes32[]The right compact range to merge.
rightRangeEnduint256The end of the right range's coverage.

Returns

NameTypeDescription
leftbytes32[]The left portion of the merged compact range.
newSeedbytes32The new seed node of the merged range.
rightbytes32[]The right portion of the merged compact range.

getRangeSizeForNonZeroBeginningInterval

Git Source (opens in a new tab)

Returns the expected size of a compact range needed to express a non-zero-starting interval.

function getRangeSizeForNonZeroBeginningInterval(uint256 start, uint256 end) pure returns (uint256);

Parameters

NameTypeDescription
startuint256The start of the interval of the range's coverage (inclusive).
enduint256The end of the interval of the range's coverage (exclusive).

Returns

NameTypeDescription
<none>uint256size The size of the compact range needed to express the interval [start, end).

hashToParent

Git Source (opens in a new tab)

Hashes two bytes32s together as into a merkle parent.

function hashToParent(bytes32 left, bytes32 right) pure returns (bytes32 parent);

Parameters

NameTypeDescription
leftbytes32The left child to hash.
rightbytes32The right child to hash.

Returns

NameTypeDescription
parentbytes32The parent hash.

ProofErrors

Git Source (opens in a new tab)

enum ProofErrors {
    NONE,
    InvalidProofLeafIdxOutOfBounds,
    InvalidProofBadLeftRange,
    InvalidProofBadRightRange,
    InvalidProofUnrecognizedRoot
}

getRoot

Git Source (opens in a new tab)

Returns the root for a given compact range.

This method "bags the peaks" of the compact range, folding in from R2L.

function getRoot(bytes32[] calldata hashes) pure returns (bytes32 root);

Parameters

NameTypeDescription
hashesbytes32[]The hashes of the compact range to calculate the root for.

Returns

NameTypeDescription
rootbytes32The root of the compact range.

getRootForMergedRange

Git Source (opens in a new tab)

Utility for calculating the root of a compact range provided in a gas-convenient representation.

function getRootForMergedRange(
    bytes32[] calldata leftRange,
    bytes32 seed,
    bytes32[] calldata rightRange
)
    pure
    returns (bytes32 root);

Parameters

NameTypeDescription
leftRangebytes32[]The left portion of the compact range to merge.
seedbytes32The middle portion of the compact range to merge.
rightRangebytes32[]The right portion of the compact range to merge.

Returns

NameTypeDescription
rootbytes32The calculated root of the compact range.