'How can I build and verify Merkle Tree in solidity

A group of users is eligible for rewards in a certain token type. I want to store the total reward in a smart contract called Distributor and allow the user to withdraw his reward portion from this contract. To make sure that each user can only withdraw the amount he is assigned I want to use the Merkle Tree where all the distribution information is encoded into the Merkle root.

I want to build and verify the Merkle tree in the solidity file, not using javascript library such as merkletreejs, etc.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source