Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump stint to v2.0: new array backend #5113

Merged
merged 4 commits into from
Sep 12, 2023
Merged

Bump stint to v2.0: new array backend #5113

merged 4 commits into from
Sep 12, 2023

Conversation

jangko
Copy link
Contributor

@jangko jangko commented Jun 21, 2023

No description provided.

@github-actions
Copy link

github-actions bot commented Jun 21, 2023

Unit Test Results

         9 files    1 089 suites   38m 41s ⏱️
  3 846 tests   3 567 ✔️ 279 💤 0
15 889 runs  15 584 ✔️ 305 💤 0

Results for commit 5aaeae4.

♻️ This comment has been updated with latest results.

@arnetheduck arnetheduck marked this pull request as draft June 22, 2023 09:40
@arnetheduck
Copy link
Member

let's hold off on merging this one into eth2 until we've increased general testing efforts in stint itself - ie fuzzing for example - we don't use a lot of stint, but the parts we use must be solid

@mratsim
Copy link
Contributor

mratsim commented Jun 24, 2023

I strongly suggest adding the fuzzing technique from libsecp256k1 (and libopus), see mratsim/constantine#53

Nim version: https://github.com/mratsim/constantine/blob/151f284/helpers/prng_unsafe.nim#L230-L244

func random_long01Seq(rng: var RngState, a: var openArray[byte]) =
  ## Initialize a bytearray
  ## It is skewed towards producing strings of 1111... and 0000
  ## to trigger edge cases
  # See libsecp256k1: https://github.com/bitcoin-core/secp256k1/blob/dbd41db1/src/testrand_impl.h#L90-L104
  let Bits = a.len * 8
  var bit = 0
  zeroMem(a[0].addr, a.len)
  while bit < Bits :
    var now = 1 + (rng.random_unsafe(1 shl 6) * rng.random_unsafe(1 shl 5) + 16) div 31
    let val = rng.sample_unsafe([0, 1])
    while now > 0 and bit < Bits:
      a[bit shr 3] = a[bit shr 3] or byte(val shl (bit and 7))
      dec now
      inc bit

This helps catch all low probability carry issues, full zeros or full ones issues. (even in cosntant-time code that traditional fuzzers have issue with compared to branches)

Then use that RNG for random testing vs GMP.

It allowed me to easily find a division bug in nim-bigints as well: nim-lang/bigints#123 (comment)

@jangko
Copy link
Contributor Author

jangko commented Jul 7, 2023

don't know what's wrong with jenkins, I have no access to read it.

@jangko jangko marked this pull request as ready for review September 12, 2023 18:15
@jangko jangko merged commit 5c88e74 into unstable Sep 12, 2023
@jangko jangko deleted the bump-stint branch September 12, 2023 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants