HarryR / ethsnarks

A toolkit for viable zk-SNARKS on Ethereum, Web, Mobile and Desktop
GNU Lesser General Public License v3.0
240 stars 57 forks source link

Floating Point Integer format, for zkSNARK circuits #93

Open HarryR opened 5 years ago

HarryR commented 5 years ago

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:

Operations required:

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.

HarryR commented 5 years ago

There is an implementation by Matter Inc - https://github.com/matterinc/sapling-crypto/blob/master/src/circuit/float_point.rs