Skip to content

Fuzz failure: 32-bit Sum of products #533

@mratsim

Description

@mratsim

As of commit 56616f2

================================================================================
||
|| Running #18/112: nim c -r --passC:-fstack-protector-strong  --passC:-D_FORTIFY_SOURCE=3  -d:CTT_ASM=false  -d:lto  --passC:-Wno-stringop-overflow --passL:-Wno-stringop-overflow  --passC:-Wno-alloc-size-larger-than --passL:-Wno-alloc-size-larger-than  --tlsEmulation=off  -d:danger  --panics:on -d:noSignalHandler  --mm:arc -d:useMalloc  --verbosity:0 --hints:off --warnings:off  --passC:-fno-semantic-interposition  --passC:-falign-functions=64  --passC:-fmerge-all-constants --outdir:build/test_suite  --nimcache:nimcache/tests/math_fields/t_finite_fields_mulsquare.nim tests/math_fields/t_finite_fields_mulsquare.nim
||
================================================================================

------------------------------------------------------

test_finite_fields_mulsquare xoshiro512** seed: 1739968506

[Suite] Modular squaring is consistent with multiplication on special elements [32-bit words]
[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 = false]
[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 [32-bit words]
  [OK] P-256 [FastSquaring = false]

[Suite] Random Modular Squaring is consistent with Modular Multiplication [32-bit words]
stack trace: (most recent call last)
/tmp/nimblecache-709449152/nimscriptapi_1968637122.nim(216, 16)
/home/runner/work/constantine/constantine/constantine/constantine.nimble(920, 3) test_parallelTask
/home/runner/work/constantine/constantine/nim-linux-i386-version-2-2-510ac845188a26d4c317893ff7b260582beee54d/lib/system/nimscript.nim(264, 7) exec
/home/runner/work/constantine/constantine/nim-linux-i386-version-2-2-510ac845188a26d4c317893ff7b260582beee54d/lib/system/nimscript.nim(264, 7) Error: unhandled exception: FAILED: build/test_suite/pararun build/test_suite_parallel.txt [OSError]
  [OK] Random squaring mod P-224 [FastSquaring = false]
  [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  [32-bit words]
  [OK] Random sum products mod P-224]
  [OK] Random sum products mod BN254_Nogami]
fatal.nim(53)            sysFatal
Error: unhandled exception: t_finite_fields_mulsquare.nim(344, 7) `bool(r`gensym1900 == r_ref`gensym1900)`  [AssertionDefect]
Error: execution of an external program failed: '/home/runner/work/constantine/constantine/constantine/build/test_suite/t_finite_fields_mulsquare'

========================== Command exited with code 1 ==========================
[FAIL]: 'nim c -r --passC:-fstack-protector-strong  --passC:-D_FORTIFY_SOURCE=3  -d:CTT_ASM=false  -d:lto  --passC:-Wno-stringop-overflow --passL:-Wno-stringop-overflow  --passC:-Wno-alloc-size-larger-than --passL:-Wno-alloc-size-larger-than  --tlsEmulation=off  -d:danger  --panics:on -d:noSignalHandler  --mm:arc -d:useMalloc  --verbosity:0 --hints:off --warnings:off  --passC:-fno-semantic-interposition  --passC:-falign-functions=64  --passC:-fmerge-all-constants --outdir:build/test_suite  --nimcache:nimcache/tests/math_fields/t_finite_fields_mulsquare.nim tests/math_fields/t_finite_fields_mulsquare.nim' (#18/112)
[FAIL]: Command #18 exited with error 1

The issue happens here:

proc random_sumprod(Name: static Algebra, N: static int) =
template sumprod_test(random_instancer: untyped) =
block:
var a: array[N, Fp[Name]]
var b: array[N, Fp[Name]]
for i in 0 ..< N:
a[i] = rng.random_instancer(Fp[Name])
b[i] = rng.random_instancer(Fp[Name])
var r, r_ref, t: Fp[Name]
r_ref.prod(a[0], b[0])
for i in 1 ..< N:
t.prod(a[i], b[i])
r_ref += t
r.sumprod(a, b)
doAssert bool(r == r_ref)

for BN254-Snarks:

suite "Random sum products is consistent with naive " & " [" & $WordBitWidth & "-bit words]":
const MaxLength = 8
test "Random sum products mod P-224]":
for _ in 0 ..< Iters:
staticFor N, 2, MaxLength:
random_sumprod(P224, N)
test "Random sum products mod BN254_Nogami]":
for _ in 0 ..< Iters:
staticFor N, 2, MaxLength:
random_sumprod(BN254_Nogami, N)
test "Random sum products mod BN254_Snarks]":
for _ in 0 ..< Iters:
staticFor N, 2, MaxLength:
random_sumprod(BN254_Snarks, N)
test "Random sum products mod BLS12_377]":
for _ in 0 ..< Iters:
staticFor N, 2, MaxLength:
random_sumprod(BLS12_377, N)
test "Random sum products mod BLS12_381]":
for _ in 0 ..< Iters:
staticFor N, 2, MaxLength:
random_sumprod(BLS12_381, N)

with seed 1739968506 without assembly

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲Something isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions