View Source ProofOfReserves (proof_of_reserves v0.1.0)
Documentation for ProofOfReserves
.
Summary
Functions
build_liabilities_tree builds a Merkle Sum Tree from a list of liabilities. First, we split the liabilities to mask account balances and ensure the liability count is a power of 2, then we shuffle them. Then, we convert the liabilities to nodes and build the Merkle Sum Tree.
find_balances_for_accounts finds all leaves that belong to a particular account using the attestation_key
get_tree_root returns the root node of a Merkle Sum Tree.
serialize_liabilities formats the Proof of Liabilities into a String.
shuffle_liabilities shuffles the liabilities using cryptographic randomness. It does this by zipping each liability with a random number, sorting by the random number, then extracting the liability.
split_liabilities divides the liabilities according to the following rules
Functions
build_liabilities_tree(block_height, liabilities, liability_maximum_threshold_sat)
View Source@spec build_liabilities_tree( non_neg_integer(), [ProofOfReserves.Liability.t()], non_neg_integer() ) :: [ [ProofOfReserves.MerkleSumTree.Node.t()] ]
build_liabilities_tree builds a Merkle Sum Tree from a list of liabilities. First, we split the liabilities to mask account balances and ensure the liability count is a power of 2, then we shuffle them. Then, we convert the liabilities to nodes and build the Merkle Sum Tree.
@spec find_balances_for_accounts( [ProofOfReserves.MerkleSumTree.Node.t()], non_neg_integer(), [ %{account_id: non_neg_integer(), account_subkey: binary()} ] ) :: [ %{ account_id: non_neg_integer(), balance: non_neg_integer(), attestation_key: binary() } ]
find_balances_for_accounts finds all leaves that belong to a particular account using the attestation_key
@spec get_tree_root([[ProofOfReserves.MerkleSumTree.Node.t()]]) :: {:ok, ProofOfReserves.MerkleSumTree.Node.t()}
get_tree_root returns the root node of a Merkle Sum Tree.
@spec serialize_liabilities(non_neg_integer(), [ [ProofOfReserves.MerkleSumTree.Node.t()] ]) :: String.t()
serialize_liabilities formats the Proof of Liabilities into a String.
@spec shuffle_liabilities([ProofOfReserves.Liability.t()]) :: [ ProofOfReserves.Liability.t() ]
shuffle_liabilities shuffles the liabilities using cryptographic randomness. It does this by zipping each liability with a random number, sorting by the random number, then extracting the liability.
@spec split_liabilities([ProofOfReserves.Liability.t()], non_neg_integer()) :: [ ProofOfReserves.Liability.t() ]
split_liabilities divides the liabilities according to the following rules:
- split all liabilities at least once (unless the liability is 1 sat).
- All leaves must be below the threshold.
- Divide the liabilities until a power of two is reached. If this is impossible, we add zero-amount liabilities to reach the next power of two.