Sparse Merkle Tree and System State
Last updated
Last updated
We use fixed-height Merkle trees to store the state of the system, in a similar way to how Ethereumβs state is stored. This way, we can encode the whole state of the system into a single field element. There are several tree instances used to store usersβ balances and orders respectively.
Each users' account includes their public key and the tokens they own. Tokens are stored in a 16-level tall Merkle tree, which can record up to different tokens. In addition, all usersβ accounts are stored in a 24-level tall Merkle tree, which can accommodate up to around 16 million users.
A given user with ID i
will be stored at the i
-th leaf node starting from the left. The first leaf (0
-th) is reserved as the default value of the account.
A Merkle tree is used to store orders placed by lenders and borrowers in different rounds of auctions. After getting matched, fulfilled orders are removed from the tree, while partially filled orders remain in the tree, with their amount to be filled updated.