Skip to content

adding fuzz tests#59

Closed
jeffoodchain wants to merge 22 commits intoChainSafe:mainfrom
jeffoodchain:jeff/fuzz-test
Closed

adding fuzz tests#59
jeffoodchain wants to merge 22 commits intoChainSafe:mainfrom
jeffoodchain:jeff/fuzz-test

Conversation

@jeffoodchain
Copy link
Copy Markdown

@jeffoodchain jeffoodchain commented Mar 3, 2026

Previously I was using the native fuzzing in zig. However, after discussing with @GrapeBaBa, I think the native zig fuzzing in 0.14.1 is not mature enough for our testing purpose. Therefore, I switched the method to what has done in ssz fuzzing in lodestar-z.

Currently the first initial corpus is generated from the spec tests through this file.

corpus is a collection of seed inputs (files, packets, or data) used to guide a fuzzer to explore code paths efficiently.

And currently this only supports on Linux machine.

to run the fuzzing:
e.g.,

  1. sudo apt install afl++
  2. cd test/fuzz
  3. zig build fuzz-public_key
AFL ++4.09c {default} (...64d672b6e452d6305a3425b7e2487cb/public_key) [fast]
┌─ process timing ────────────────────────────────────┬─ overall results ────┐
│        run time : 0 days, 0 hrs, 0 min, 8 sec       │  cycles done : 20    │
│   last new find : 0 days, 0 hrs, 0 min, 8 sec       │ corpus count : 14    │
│last saved crash : none seen yet                     │saved crashes : 0     │
│ last saved hang : none seen yet                     │  saved hangs : 0     │
├─ cycle progress ─────────────────────┬─ map coverage┴──────────────────────┤
│  now processing : 2.197 (14.3%)      │    map density : 0.17% / 0.48%      │
│  runs timed out : 0 (0.00%)          │ count coverage : 2.89 bits/tuple    │
├─ stage progress ─────────────────────┼─ findings in depth ─────────────────┤
│  now trying : splice 10              │ favored items : 10 (71.43%)         │
│ stage execs : 85/86 (98.84%)         │  new edges on : 10 (71.43%)         │
│ total execs : 424k                   │ total crashes : 0 (0 saved)         │
│  exec speed : 52.7k/sec              │  total tmouts : 0 (0 saved)         │
├─ fuzzing strategy yields ────────────┴─────────────┬─ item geometry ───────┤
│   bit flips : disabled (default, enable with -D)   │    levels : 2         │
│  byte flips : disabled (default, enable with -D)   │   pending : 0         │
│ arithmetics : disabled (default, enable with -D)   │  pend fav : 0         │
│  known ints : disabled (default, enable with -D)   │ own finds : 7         │
│  dictionary : n/a                                  │  imported : 0         │
│havoc/splice : 7/180k, 0/244k                       │ stability : 100.00%   │
│py/custom/rq : unused, unused, unused, unused       ├───────────────────────┘
│    trim/eff : 5.20%/170, disabled                  │          [cpu000: 31%]
└─ strategy: explore ────────── state: started :-) ──┘

@jeffoodchain jeffoodchain marked this pull request as ready for review March 10, 2026 08:25
@wemeetagain
Copy link
Copy Markdown
Member

wemeetagain pushed a commit to ChainSafe/lodestar-z that referenced this pull request Mar 30, 2026
This is moved from [this
PR](ChainSafe/blst-z#59).

to run the fuzzing: 
(If you are on Linux)
e.g.,
1. `sudo apt install afl++`
2. cd `test/fuzz`
3. `zig build run-bls_public_key`

(If you are using MacOs)
1. `brew install afl++`
2. cd `test/fuzz`
3. follow the instruction in this
[session](https://github.com/jeffoodchain/lodestar-z/blob/jeff/fuzz-test/test/fuzz/README.md#on-macos).
4. run `zig build run-bls_public_key`

you could see the following dashboard running in your terminal

```bash
AFL ++4.09c {default} (...64d672b6e452d6305a3425b7e2487cb/public_key) [fast]
┌─ process timing ────────────────────────────────────┬─ overall results ────┐
│        run time : 0 days, 0 hrs, 0 min, 8 sec       │  cycles done : 20    │
│   last new find : 0 days, 0 hrs, 0 min, 8 sec       │ corpus count : 14    │
│last saved crash : none seen yet                     │saved crashes : 0     │
│ last saved hang : none seen yet                     │  saved hangs : 0     │
├─ cycle progress ─────────────────────┬─ map coverage┴──────────────────────┤
│  now processing : 2.197 (14.3%)      │    map density : 0.17% / 0.48%      │
│  runs timed out : 0 (0.00%)          │ count coverage : 2.89 bits/tuple    │
├─ stage progress ─────────────────────┼─ findings in depth ─────────────────┤
│  now trying : splice 10              │ favored items : 10 (71.43%)         │
│ stage execs : 85/86 (98.84%)         │  new edges on : 10 (71.43%)         │
│ total execs : 424k                   │ total crashes : 0 (0 saved)         │
│  exec speed : 52.7k/sec              │  total tmouts : 0 (0 saved)         │
├─ fuzzing strategy yields ────────────┴─────────────┬─ item geometry ───────┤
│   bit flips : disabled (default, enable with -D)   │    levels : 2         │
│  byte flips : disabled (default, enable with -D)   │   pending : 0         │
│ arithmetics : disabled (default, enable with -D)   │  pend fav : 0         │
│  known ints : disabled (default, enable with -D)   │ own finds : 7         │
│  dictionary : n/a                                  │  imported : 0         │
│havoc/splice : 7/180k, 0/244k                       │ stability : 100.00%   │
│py/custom/rq : unused, unused, unused, unused       ├───────────────────────┘
│    trim/eff : 5.20%/170, disabled                  │          [cpu000: 31%]
└─ strategy: explore ────────── state: started :-) ──┘

```

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

2 participants