Skip to content

Neo Compiler Fuzzer Implementation and Unit Tests #1314

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Apr 21, 2025

Overview

This PR implements a production-ready Neo Compiler Fuzzer for testing the Neo N3 smart contract compiler. The fuzzer dynamically generates valid smart contracts with various combinations of C# syntax features and Neo-specific functionality, compiles them using the Neo.Compiler.CSharp CompilationEngine, and optionally tests their execution.

Key Features

  • Dynamic Contract Generation: Generates random, valid Neo N3 smart contracts with configurable feature sets
  • Comprehensive Coverage: Tests a wide range of C# syntax features and Neo-specific functionality
  • Long-Running Support: Can run for specified durations (minutes, hours, days, weeks) with checkpointing
  • Detailed Reporting: Generates comprehensive reports and statistics about the fuzzing process
  • Production-Ready Implementation: Uses the Neo.Compiler.CSharp CompilationEngine directly
  • Robust Error Handling: Comprehensive error handling and validation
  • Extensive Documentation: Complete documentation in the docs/fuzzer/compiler directory

Implementation Details

  1. Core Components:

    • DynamicContractFuzzer: Main class for orchestrating the fuzzing process
    • FragmentGenerator: Generates code fragments for various features
    • Logger: Provides logging functionality
  2. Command-Line Interface:

    • Support for both iteration-based and duration-based fuzzing
    • Configurable feature count, output directory, and log level
    • Checkpoint interval configuration for long-running sessions
  3. Shell Script:

    • Updated run-compiler-fuzzer.sh script for easy execution
    • Support for all command-line options
  4. Unit Tests:

    • Comprehensive test suite in tests/Neo.Compiler.Fuzzer.Tests
    • Tests for contract generation, compilation, and feature handling

Documentation

Added comprehensive documentation in the docs/fuzzer/compiler directory:

  • README.md: Overview and getting started guide
  • features.md: Detailed list of supported features
  • architecture.md: System architecture and component interactions
  • configuration.md: Configuration options and customization
  • reports.md: Report formats and interpretation
  • troubleshooting.md: Common issues and solutions

Testing

The implementation has been tested with various configurations:

  • Different feature counts (1-10 features per contract)
  • Different iteration counts (1-100 iterations)
  • Different durations (minutes to hours)
  • With and without execution testing

Current success rate is approximately 70% with 3 features per contract, which is expected given the random nature of the feature combinations.

Future Work

Potential future enhancements:

  • Additional feature generators for more comprehensive coverage
  • Improved success rate through better feature compatibility handling
  • Support for targeted fuzzing of specific compiler components

Checklist

  • Code follows the project's coding style
  • Documentation has been updated
  • Unit tests have been added/updated and pass
  • Shell script has been updated
  • PR description adequately describes the changes

@Wi1l-B0t
Copy link
Contributor

Wi1l-B0t commented Apr 25, 2025

Need rebase master(better than merge)

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