ethsnarks
ethsnarks copied to clipboard
Floating Point Integer format, for zkSNARK circuits
It has been suggested that floating point numbers offer a larger dynamic range than integers, which is useful when dealing with cryptocurrencies that may have many zeros and arbitrary units.
Implement a floating point integer format in-circuit with matching Python implementation.
References:
- https://en.wikipedia.org/wiki/Half-precision_floating-point_format
- https://github.com/xennygrimmato/z3-floating-point-proofs
- https://github.com/fredrik-johansson/mpmath
- https://github.com/qlootens/FloatingPointConverter
- http://www.toves.org/books/float/
- https://en.wikipedia.org/wiki/Single-precision_floating-point_format
- https://www.eetimes.com/author.asp?section_id=36&doc_id=1287491
- https://blog.penjee.com/binary-numbers-floating-point-conversion/
- https://www.eetimes.com/author.asp?section_id=36&doc_id=1287491
Operations required:
- Validate
- Convert to Unsigned Integer
- Convert from Unsigned Integer
There is no need for addition, multiplication or division operations, it is only necessary to use it as a mechanism for compressing payment amounts.
The precision required by the exponent/mantissa format should be enough to make transfers of up to 1 million units of an ERC-20 token with 18 decimal places. This is different from 'floating point', it is more like a 'high dynamic range integer' where a smaller number of bits control the exponentiation of the integer while a smaller number represent its entropy.
10**18 * 1000000 = 1000000000000000000000000
The dynamic range for integers in Wei should be 0
to 1000000000000000000000000
, with as much precision as possible to allow for payments which as closely match what the user desired.