Skip to content

[Fuzz] Sum of products #547

@mratsim

Description

@mratsim

From #546

test_finite_fields_mulsquare xoshiro512** seed: 1747301483

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

[Suite] Random Modular Squaring is consistent with Modular Multiplication [64-bit words]
  [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 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`gensym1306 == r_ref`gensym1306)`  [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

It seems like we have an overflow in sum of products:

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)

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