The mathematics behind blockchain