feat: library based fuzzing #7444
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Random Number Generation and Fuzzing Support to forc-test
Summary
This PR introduces deterministic and non-deterministic random number generation capabilities to the forc-test VM through new syscalls, and provides a comprehensive Sway fuzzing library that enables property-based testing for any Sway type without requiring trait implementations.
Changes
1. New VM Syscalls
Added two new environment call (ecal) syscalls to the forc-test VM:
random): Non-deterministic random byte generationrandom_seeded): Deterministic seeded random byte generationThese syscalls are implemented in
forc-test/src/ecal.rsand write random bytes directly to VM memory.2. Sway Fuzzing Library
Created a new library at
forc-test/sway-testwith three modules:randommoduleLow-level functions for random number generation:
fuzzmoduleHigh-level fuzzing framework using memory-level fuzzing to support any Sway type without trait implementations:
Deterministic Fuzzing
Key Features
__size_ofand__addr_ofintrinsics to fill type memory with random bytesImplementation Details
The fuzzing works by:
Tusing__size_of::<T>()__addr_of(value)This approach requires no trait implementations and works uniformly across all types.
Testing
Added 11 comprehensive tests covering:
Example