mratsim / constantine

Constantine: modular, high-performance, zero-dependency cryptography stack for verifiable computation, proof systems and blockchain protocols.
Other
413 stars 44 forks source link

[Fuzz fail] Fused sumproduct failure #208

Open mratsim opened 2 years ago

mratsim commented 2 years ago

Windows 64-bit, no assembly

https://github.com/mratsim/constantine/actions/runs/3352747379/jobs/5555094891#step:21:340

test_finite_fields_mulsquare xoshiro512** seed: 1667073731

[Suite] Modular squaring is consistent with multiplication on special elements [64-bit mode]
[OK] Squaring 0,1,2 with Fake101 [FastSquaring = true]
[OK] Squaring 0,1,2 with Mersenne61 [FastSquaring = true]
[OK] Squaring 0,1,2 with Mersenne127 [FastSquaring = false]
[OK] Squaring 0,1,2 with P224 [FastSquaring = true]
[OK] Squaring 0,1,2 with P256 [FastSquaring = false]
[OK] Squaring 0,1,2 with Secp256k1 [FastSquaring = false]
[OK] Squaring 0,1,2 with BLS12_381 [FastSquaring = true]
[OK] Squaring 0,1,2 with Edwards25519 [FastSquaring = false]
[OK] Squaring 0,1,2 with Bandersnatch [FastSquaring = false]
[OK] Squaring 0,1,2 with Pallas [FastSquaring = false]
[OK] Squaring 0,1,2 with Vesta [FastSquaring = false]

[Suite] Modular Squaring: selected tricky cases [64-bit mode]
  [OK] P-256 [FastSquaring = false]

[Suite] Random Modular Squaring is consistent with Modular Multiplication [64-bit mode]
  [OK] Random squaring mod P-224 [FastSquaring = true]
  [OK] Random squaring mod P-256 [FastSquaring = false]
  [OK] Random squaring mod Secp256k1 [FastSquaring = false]
  [OK] Random squaring mod BLS12_381 [FastSquaring = true]
  [OK] Random squaring mod Edwards25519 [FastSquaring = false]
  [OK] Random squaring mod Bandersnatch [FastSquaring = false]
  [OK] Random squaring mod Pallas [FastSquaring = false]
  [OK] Random squaring mod Vesta [FastSquaring = false]

[Suite] Modular squaring - bugs highlighted by property-based testing
  [OK] a² == (-a)² on for Fp[2^127 - 1] - #61
  [OK] a² == (-a)² on for Fp[2^127 - 1] - #62
  [OK] 32-bit fast squaring on BLS12-381 - #42
  [OK] 32-bit fast squaring on BLS12-381 - #43

[Suite] Random sum products is consistent with naive  [64-bit mode]
  [OK] Random sum products mod P-224]
  [OK] Random sum products mod BN254_Nogami]
fatal.nim(54)            sysFatal

    Unhandled exception: t_finite_fields_mulsquare.nim(334, 16) `bool(r`gensym1260 == r_ref`gensym1260)`  [AssertionDefect]
  [FAILED] Random sum products mod BN254_Snarks]
  [OK] Random sum products mod BLS12_377]
  [OK] Random sum products mod BLS12_381]
Error: execution of an external program failed: 'D:\a\constantine\constantine\constantine\build\testsuite\t_finite_fields_mulsquare.exe '
==== Command exited with code 1 ====
[FAIL]: 'nim c -d:release  -d:CttASM=false --verbosity:0 --outdir:build/testsuite -r --hints:off --warnings:off  --nimcache:nimcache/tests/math/t_finite_fields_mulsquare.nim tests/math/t_finite_fields_mulsquare.nim' (#13)
mratsim commented 1 year ago

Failing inputs

a:
   ["0x0b75f0b660e27ec6d5220f6211b8a4ae6d899403120eaf0311fe70331ade3d94",
    "0x1249a4b841852b5e34a383d86582dfc9daaeb21327cd4c8c1259af3cde9976b5",
    "0x20f5038383dbe3cdb86d663d22b918bda7754d6e8d939d959f58da68368d09b7",
    "0x1b989f0a60ce802069cb493cc208d2dc4a646b93b4913781116ed5d9445a9304",
    "0x213ed7527348d6e69218ca6f670ac042f2772cef4837b7ce5d08f850cfef9689",
    "0x05abdcb70ebda6a0be036391392276b223e68376c3a05fa6c4b48aa3fa6f10db",
    "0x121ec3625121f1fd310b4ad2269de996baad1860dbade730fd625f4b597b9b51"]

b:
   ["0x01a437d8098bd72616b1842b6d222c957ab98dfaf20b91ac18f32f74906093fb",
    "0x1ebdf2ee7f3efc7bee4792cdd3fac0ba70fff7113b87f798b66d739c018b6b4b",
    "0x0bb015a9dccd285f28abe4688a11fb11e8e49fa0eee9a7033809f856fcadec5a",
    "0x1569e6e0189c538f95a2c3c068129bc2f4ee6eab11cff219e385314fb0c3a982",
    "0x0cc5c44649bab5a5f806c64d1b1047b62edcf7487cf550e4f5595796821ce6ba",
    "0x06e03c9a13d17dc26cea2cca7b7904c5b137766da920252078e8a8a5f5e9d54a",
    "0x00f092e5435db8f33fa3f2e6984edb4c9c0d9889c1dd42e72d2bb0c6917d5990"]
 [AssertionDefect]
  [FAILED] Random sum products mod BN254_Snarks]

Note: the assembly (with or without ADX) works while no assembly fails.