Skip to content

Instantly share code, notes, and snippets.

@paxthemax
Created January 17, 2022 17:01
Show Gist options
  • Save paxthemax/e7e9d3f580f16b37c4d7cddadd213685 to your computer and use it in GitHub Desktop.
Save paxthemax/e7e9d3f580f16b37c4d7cddadd213685 to your computer and use it in GitHub Desktop.

Here is how we can do the hash disribution:

Let's say we have a GIVBacks round with a total of N GIVBacks.

We can divide the round into multiple batches defined as:

  • i (the order of the batch)
  • address[] 1..k(i)
  • amount[] 1..k(i)

Where k(i) is the size of the batch

This structure forms a tree with a depth of 1:

root
|_ (1,address[], amount[])
|_ (2,address[], amount[])
.
|_ (n,address[], amount[])

The root hash is calculated as:

h(root)=h(h(b1)|h(b2)|...|h(bn))

The hash of each batch is calculated as:

h(b(i))=h(i|address(i)[]|amount(i)[]

The relayer contract stores the root hash of the tree.

The validator must know:

  • The order number of the batch
  • Batch data
    • address[]
    • amount[]
  • Hashes of other batches

Execute function would provide:

execute(uint256 batchNo, address[] accounts, uint256[] amounts, bytes32[] batchRoots)

The execute function will:

  • Check if the batchNo is executed
  • Compute the hash of the batchNo batch
  • Compute the root hash
  • Check if the root hash is valid
  • Set the batchNo as executed
  • Call the sendGivbacks function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment