New Target for Contributions Decode Encode #72
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [ main, stable, unstable ] | |
| pull_request: | |
| branches: [ main, stable, unstable ] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| # Fix ring crate compilation on macOS ARM64 | |
| CFLAGS_aarch64_apple_darwin: "-mcpu=apple-m1" | |
| RUSTFLAGS: "-C target-cpu=native" | |
| jobs: | |
| test: | |
| name: Test | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@nightly | |
| - name: Install system dependencies (Ubuntu) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt update | |
| sudo apt install -y build-essential llvm-dev clang | |
| - name: Install system dependencies (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| # Dependencies should already be available on macOS runners | |
| which clang || echo "clang not found" | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('.github/workflows/ci.yml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}- | |
| ${{ runner.os }}-cargo- | |
| - name: Cache target directory | |
| uses: actions/cache@v4 | |
| with: | |
| path: target | |
| key: ${{ runner.os }}-target-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('fuzz/Cargo.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-target-${{ hashFiles('**/Cargo.lock') }}- | |
| ${{ runner.os }}-target- | |
| - name: Cache Go modules and build cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/go/pkg/mod | |
| ~/.cache/go-build | |
| diff_fuzzing/go.sum | |
| key: ${{ runner.os }}-go-${{ hashFiles('diff_fuzzing/go.mod', 'diff_fuzzing/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Install AFL++ and cargo-afl | |
| run: | | |
| # Install AFL++ system package | |
| if [[ "${{ runner.os }}" == "Linux" ]]; then | |
| if ! command -v afl-fuzz &> /dev/null; then | |
| sudo apt-get update | |
| sudo apt-get install -y afl++ | |
| else | |
| echo "AFL++ already installed" | |
| fi | |
| elif [[ "${{ runner.os }}" == "macOS" ]]; then | |
| if ! command -v afl-fuzz &> /dev/null; then | |
| brew install afl++ | |
| else | |
| echo "AFL++ already installed" | |
| fi | |
| fi | |
| # Install cargo-afl if not cached | |
| if ! command -v cargo-afl &> /dev/null; then | |
| cargo install cargo-afl | |
| else | |
| echo "cargo-afl already installed" | |
| fi | |
| # Configure system for optimal AFL fuzzing performance | |
| sudo cargo afl system-config || echo "System config failed, continuing..." | |
| - name: Download Go dependencies | |
| working-directory: ./diff_fuzzing | |
| run: | | |
| # Download all direct dependencies | |
| go mod download | |
| # Download specific problematic dependencies as suggested by error messages | |
| go mod download github.com/libp2p/go-libp2p-pubsub | |
| go get github.com/ssvlabs/ssv/message/validation@v1.2.1-0.20250626110133-f6f994903796 | |
| # Force tidy to resolve all dependencies | |
| go mod tidy | |
| - name: Build libraries | |
| working-directory: ./diff_fuzzing | |
| run: ./build_libs.sh | |
| - name: Build workspace and key fuzz targets | |
| run: | | |
| # Set macOS ARM64 flags for ring crate compatibility | |
| if [[ "${{ runner.os }}" == "macOS" ]]; then | |
| export CFLAGS_aarch64_apple_darwin="-mcpu=apple-m1" | |
| export RUSTFLAGS="-C target-cpu=apple-m1" | |
| fi | |
| # Build main workspace (excluding fuzz crate) | |
| cargo build --workspace --exclude fuzz | |
| # Build fuzz targets with AFL instrumentation | |
| cd fuzz | |
| cargo afl build --bin validate_ssv_message | |
| cargo afl build --bin diff_fuzz_split | |
| cargo afl build --bin custom_ssz | |
| echo "All components built successfully" | |
| - name: Run AFL++ smoke tests | |
| run: | | |
| cd fuzz | |
| # Create minimal test inputs for smoke tests | |
| mkdir -p test_inputs | |
| echo "test" > test_inputs/minimal.txt | |
| # Test that AFL fuzz targets can start and exit cleanly (5 second timeout) | |
| # Use gtimeout on macOS, timeout on Linux | |
| if [[ "${{ runner.os }}" == "macOS" ]]; then | |
| brew install coreutils | |
| TIMEOUT_CMD="gtimeout" | |
| else | |
| TIMEOUT_CMD="timeout" | |
| fi | |
| echo "Testing validate_ssv_message..." | |
| $TIMEOUT_CMD 5s cargo afl fuzz -i test_inputs -o test_outputs_1 -V 1 ../target/debug/validate_ssv_message || true | |
| echo "Testing diff_fuzz_split..." | |
| $TIMEOUT_CMD 5s cargo afl fuzz -i test_inputs -o test_outputs_2 -V 1 ../target/debug/diff_fuzz_split || true | |
| echo "Testing custom_ssz..." | |
| $TIMEOUT_CMD 5s cargo afl fuzz -i test_inputs -o test_outputs_3 -V 1 ../target/debug/custom_ssz || true | |
| echo "AFL++ smoke tests completed - key fuzz targets can start successfully" |