mldsa-native icon indicating copy to clipboard operation
mldsa-native copied to clipboard

Standardize on signed integers in quantifiers and loops.

Open rod-chapman opened this issue 2 months ago • 5 comments

Conjecture: it is better for proof performance and stability to use signed "int" types for quantifiers, loop indexing expressions, for loop counters. This PR implements this change to gain data on its impact on proof and runtime performance.

Specifically, use signed "int" for:

  1. for loop counters
  2. quantified expressions
  3. variables and struct fields that count or index into arrays
  4. formal parameters for array indexes, offsets and counts

Additionally, strengthen pre-conditions on polyvecl_add() and polyveck_add() to stabilize proof of those functions for all parameter sets.

Opening a PR here to get Benchmark results.

rod-chapman avatar Nov 17 '25 05:11 rod-chapman

Turning into draft. Please mark it as ready once you are happy.

mkannwischer avatar Nov 17 '25 05:11 mkannwischer

This change, if we want it, should be coordinated with mlkem-native. However, I seem to remember that we have done a round-trip on this one already on mlkem-native, changing to int and back. If there is a larger win to be had, OK (the CI should tell!), but otherwise I prefer not to change this again for now. There's a lot of issues open at the moment that we should work on first.

hanno-becker avatar Nov 17 '25 15:11 hanno-becker

Proof results, running on an r7g instance with -j16 (so as close as I can get to the CI runner that we use for CBMC). The first figure is real-time, the second is CPU "user" time,

Branch main:

  MLDSA-44: 6m56s, 40m57s
  MLDSA-65: 5m13s, 45m38s
  MLDSA-87: 8m03s, 52m10s

Branch signed_loop_quants:

  MLDSA-44: 3m39s, 31m42s
  MLDSA-65: 3m29s, 34m57s
  MLDSA-87: 7m41s, 40m36s

rod-chapman avatar Nov 17 '25 16:11 rod-chapman

The proof performance looks really good, but runtime performance is affected by 1-5% for the C backend(s), particularly on Intel/AMD. I will look at the "components" benchmark to see what's going on.

rod-chapman avatar Nov 18 '25 15:11 rod-chapman

The performance degradation appears to be concentrated in the Inverse NTT in the C backend. Not sure what's going on.

rod-chapman avatar Nov 18 '25 23:11 rod-chapman