zBlock-2 / summa-solvency-diffie

Apache License 2.0
0 stars 0 forks source link

Evaluating N_BYTES value of the circuit #13

Open kiseln opened 4 months ago

kiseln commented 4 months ago

Summary Currently deployed verifier has a range check of 8 bytes. Let's evaluate whether this is sufficient to represent tokens with very large supply.

Additional context

Max 8-byte number is 18,446,744,073,709,551,615 or roughly 18e18. This number needs to represent not only the integer part of the balance but also the decimal part. While ERC20 tokens tend to have 18 decimals, on most exhanges like Binance, balances are limited to 8 decimals. Therefore an 8-byte range check can work if balances do not exceed 18e10 tokens.

This value will be enough for most of the crypto assets. However, let's have a look at tokens with huge supply and small nominal worth like SHIB and PEPE. Looking at the holder distribution of SHIB we can see that the top exchanges hold amounts that exceed 1e13. However, if we look at how exchanges handle these type of tokens, they tend to have less decimals than other assets. Both SHIB and PEPE have only 2 decimals on Binance. With 2 decimals we need to be able to support 1e15 values which is within the bounds of our range check.

Additionally, if some token's balances reach the boundary of 18e18, it can be acceptable to cut a few decimals off to store balances in MST. Precision loss will not be significant.

Conclusion N_BYTES of 8 looks to be enough to support all popular tokens with necessary level of precison.