from typing import List


def unpack_merkle_leaf(leaf: bytes, dims: int, num_polys: int) -> List[bytes]:
  """Unpacks a merkle leaf created by merkelize_polynomials.

  Note that the packing in each Merkle leaf is

  polyval_1_dim_1 polyval_1_dim_2 poly_val_2_dim_1 poly_val_2_dim_2 ...

  Each value is encoded in 32 bytes, so the total length of
  the leaf is 32 * num_polys * dims bytes.

  Parameters
  ----------
  leaf: bytestring
    A bytestring holding the Merkle leaf
  dims: Int
    The dimensionality of the state space
  num_polys: int
    The number of polynomials
  """
  vals = []
  for poly_ind in range(num_polys):
    for dim in range(dims):
      start_index = 32 * (poly_ind * dims + dim)
      end_index = 32 * (poly_ind * dims + dim + 1)
      byte_val = leaf[start_index:end_index]
      vals.append(byte_val)
  return vals