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

Link to this function

build_liabilities_tree(block_height, liabilities, liability_maximum_threshold_sat)

View Source

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.

Link to this function

find_balances_for_accounts(leaves, block_height, accounts)

View Source
@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

get_tree_root returns the root node of a Merkle Sum Tree.

Link to this function

serialize_liabilities(block_height, tree)

View Source
@spec serialize_liabilities(non_neg_integer(), [
  [ProofOfReserves.MerkleSumTree.Node.t()]
]) :: String.t()

serialize_liabilities formats the Proof of Liabilities into a String.

Link to this function

shuffle_liabilities(liabilities)

View Source
@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.

Link to this function

split_liabilities(liabilities, liability_maximum_threshold_sat)

View Source

split_liabilities divides the liabilities according to the following rules:

  1. split all liabilities at least once (unless the liability is 1 sat).
  2. All leaves must be below the threshold.
  3. 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.