0

Hash functions like SHA-2 are widely used to validate the transfer of data or to validate cryptographic integer calculations.

Is it possible to use hash functions to validate floating point calculations, e.g. a physics simulation. In other words is it possible and viable to make floating point calculations consistent across multiple platforms?

If the answer to the previous question is "no", given the calculations are carefully crafted, it might be possible to hash data with reduced precision and still get high confidence in the validation. Is there any ongoing project which tries to achieve that?

VoidStar
  • 936
  • 1
  • 7
  • 17
  • What do you mean by "validate" floating point calculations? You can use a hash function to determine if you get the exact same value, identical to the bit. But your only hope is to use floating point operations with guaranteed platform-independent behavior. – President James K. Polk Nov 28 '21 at 20:46
  • I want to validate the physics calculation done by several nodes on a network without the need to transfer all the data for comparison. How can I use "floating point operations with guaranteed platform-independent behavior" ? – VoidStar Nov 28 '21 at 21:04
  • In addition to the questions I linked to, clause 11 of IEEE 754-2019 (and IEEE 754-2008) discusses reproducible results. It is elusive in high-level languages due to their lack of control over floating-point arithmetic; standards are generally lax in specifying floating-point behaviors. It is easier in assembly language. – Eric Postpischil Nov 29 '21 at 02:20

1 Answers1

0

Hashes work on binary input, usually bytes. So if you want to use hashes to compare results instead of comparing the results themselves then you need to create a canonical binary encoding of the values. For floating point, the common standard that specifies how numbers can be encoded is IEEE 754, and most languages will specify how they use floats compared to that standard.

For instance, Java adheres to the "round-to-nearest rule of IEEE 754 floating-point arithmetic" and starts with this part:

The floating-point types are float and double, which are conceptually associated with the single-precision 32-bit and double-precision 64-bit format IEEE 754 values and operations as specified in IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Standard 754-1985 (IEEE, New York).

Please that you should also understand the strictfp flag for Java. Similar tricks may be required for other languages as well.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263