Skip to content

Commit

Permalink
add fuzz corpus
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed Jul 21, 2024
1 parent 518c1cb commit 292e502
Show file tree
Hide file tree
Showing 144 changed files with 134 additions and 28 deletions.
41 changes: 28 additions & 13 deletions .github/workflows/cflite_batch.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
name: ClusterFuzzLite batch fuzzing
name: ClusterFuzzLite cron tasks
on:
workflow_dispatch:
push:
branches:
- develop # Use your actual default branch here.
schedule:
- cron: "0 8 * * 1" # At 08:00 on Monday.
permissions: read-all
jobs:
BatchFuzzing:
Fuzzing:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sanitizer: [address, undefined, memory]
include:
- mode: batch
sanitizer: address
- mode: batch
sanitizer: undefined
- mode: batch
sanitizer: memory
- mode: prune
sanitizer: address
- mode: coverage
sanitizer: coverage
steps:
- name: Build Fuzzers (${{ matrix.sanitizer }})
- name: Build Fuzzers (${{ matrix.mode }} - ${{ matrix.sanitizer }})
id: build
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
with:
language: c++
language: c # Change this to the language you are fuzzing.
github-token: ${{ secrets.GITHUB_TOKEN }}
sanitizer: ${{ matrix.sanitizer }}
- name: Run Fuzzers (${{ matrix.sanitizer }})
storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/lightsail-network/app-stellar-fuzz-corpus
storage-repo-branch: main
storage-repo-branch-coverage: gh-pages
- name: Run Fuzzers (${{ matrix.mode }} - ${{ matrix.sanitizer }})
id: run
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fuzz-seconds: 3600 # 1 hour
mode: "batch"
fuzz-seconds: 600 # 10 minutes
mode: ${{ matrix.mode }}
sanitizer: ${{ matrix.sanitizer }}
# Optional but recommended: For storing certain artifacts from fuzzing.
# See later section on "Git repo for storage".
#storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/LedgerHQ/fuzzers-corpus.git
#storage-repo-branch: main # Optional. Defaults to "main"
#storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages".
storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/lightsail-network/app-stellar-fuzz-corpus
storage-repo-branch: main # Optional. Defaults to "main"
storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages".
25 changes: 10 additions & 15 deletions .github/workflows/cflite_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,27 @@ jobs:
strategy:
fail-fast: false
matrix:
sanitizer: [address, undefined, memory]
sanitizer: [address, undefined, memory] # Override this with the sanitizers you want.
steps:
- name: Build Fuzzers (${{ matrix.sanitizer }})
id: build
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
with:
language: c++
language: c # Change this to the language you are fuzzing.
github-token: ${{ secrets.GITHUB_TOKEN }}
sanitizer: ${{ matrix.sanitizer }}
# Optional but recommended: used to only run fuzzers that are affected
# by the PR.
# See later section on "Git repo for storage".
#storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/LedgerHQ/fuzzers-corpus.git
#storage-repo-branch: main # Optional. Defaults to "main"
#storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages".
storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/lightsail-network/app-stellar-fuzz-corpus
storage-repo-branch: main
storage-repo-branch-coverage: gh-pages
- name: Run Fuzzers (${{ matrix.sanitizer }})
id: run
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fuzz-seconds: 600 # 10 minutes
fuzz-seconds: 300 # 5 minutes
mode: "code-change"
sanitizer: ${{ matrix.sanitizer }}
# Optional but recommended: used to download the corpus produced by
# batch fuzzing.
# See later section on "Git repo for storage".
#storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/LedgerHQ/fuzzers-corpus.git
#storage-repo-branch: main # Optional. Defaults to "main"
#storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages".
output-sarif: true
storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/lightsail-network/app-stellar-fuzz-corpus
storage-repo-branch: main
storage-repo-branch-coverage: gh-pages
6 changes: 6 additions & 0 deletions fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ if (NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR "Fuzzer needs to be built with Clang")
endif ()

# Build with code coverage generation
if(CODE_COVERAGE)
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
add_link_options(-fprofile-instr-generate -fcoverage-mapping)
endif()

include(CTest)
ENABLE_TESTING()

Expand Down
Binary file added fuzz/corpus/feeBumpTx.raw
Binary file not shown.
Binary file added fuzz/corpus/feeBumpTxOmitFeeSourceEqualSigner.raw
Binary file not shown.
Binary file added fuzz/corpus/feeBumpTxOmitFeeSourceNotEqualSigner.raw
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/feeBumpTxWithMuxedFeeSource.raw
Binary file not shown.
Binary file added fuzz/corpus/opAccountMerge.raw
Binary file not shown.
Binary file added fuzz/corpus/opAccountMergeWithMuxedDestination.raw
Binary file not shown.
Binary file added fuzz/corpus/opAllowTrustAuthorize.raw
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opAllowTrustDeauthorize.raw
Binary file not shown.
Binary file added fuzz/corpus/opBeginSponsoringFutureReserves.raw
Binary file not shown.
Binary file added fuzz/corpus/opBumpSequence.raw
Binary file not shown.
Binary file added fuzz/corpus/opChangeTrustAddTrustLine.raw
Binary file not shown.
Binary file added fuzz/corpus/opChangeTrustRemoveTrustLine.raw
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opClaimClaimableBalance.raw
Binary file not shown.
Binary file added fuzz/corpus/opClawback.raw
Binary file not shown.
Binary file added fuzz/corpus/opClawbackClaimableBalance.raw
Binary file not shown.
Binary file added fuzz/corpus/opClawbackWithMuxedFrom.raw
Binary file not shown.
Binary file added fuzz/corpus/opCreateAccount.raw
Binary file not shown.
Binary file added fuzz/corpus/opCreateClaimableBalance.raw
Binary file not shown.
Binary file added fuzz/corpus/opCreatePassiveSellOffer.raw
Binary file not shown.
Binary file added fuzz/corpus/opEndSponsoringFutureReserves.raw
Binary file not shown.
Binary file added fuzz/corpus/opExtendFootprintTtl.raw
Binary file not shown.
Binary file added fuzz/corpus/opInflation.raw
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionApproveUsdc.raw
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionAssetApprove.raw
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionAssetTransfer.raw
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionScvalsCase0.raw
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionScvalsCase1.raw
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionScvalsCase2.raw
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionTestPlugin.raw
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionTransferUsdc.raw
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionTransferXlm.raw
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionUploadWasm.raw
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionWithAuth.raw
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opInvokeHostFunctionWithoutArgs.raw
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opLiquidityPoolDeposit.raw
Binary file not shown.
Binary file added fuzz/corpus/opLiquidityPoolWithdraw.raw
Binary file not shown.
Binary file added fuzz/corpus/opManageBuyOfferCreate.raw
Binary file not shown.
Binary file added fuzz/corpus/opManageBuyOfferDelete.raw
Binary file not shown.
Binary file added fuzz/corpus/opManageBuyOfferUpdate.raw
Binary file not shown.
Binary file added fuzz/corpus/opManageDataAdd.raw
Binary file not shown.
Binary file added fuzz/corpus/opManageDataAddWithUnprintableData.raw
Binary file not shown.
Binary file added fuzz/corpus/opManageDataRemove.raw
Binary file not shown.
Binary file added fuzz/corpus/opManageSellOfferCreate.raw
Binary file not shown.
Binary file added fuzz/corpus/opManageSellOfferDelete.raw
Binary file not shown.
Binary file added fuzz/corpus/opManageSellOfferUpdate.raw
Binary file not shown.
Binary file added fuzz/corpus/opPathPaymentStrictReceive.raw
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opPathPaymentStrictSend.raw
Binary file not shown.
Binary file added fuzz/corpus/opPathPaymentStrictSendWithEmptyPath.raw
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opPaymentAssetAlphanum12.raw
Binary file not shown.
Binary file added fuzz/corpus/opPaymentAssetAlphanum4.raw
Binary file not shown.
Binary file added fuzz/corpus/opPaymentAssetNative.raw
Binary file not shown.
Binary file added fuzz/corpus/opPaymentWithMuxedDestination.raw
Binary file not shown.
Binary file added fuzz/corpus/opRestoreFootprint.raw
Binary file not shown.
Binary file added fuzz/corpus/opRevokeSponsorshipAccount.raw
Binary file not shown.
Binary file added fuzz/corpus/opRevokeSponsorshipClaimableBalance.raw
Binary file not shown.
Binary file added fuzz/corpus/opRevokeSponsorshipData.raw
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opRevokeSponsorshipHashXSigner.raw
Binary file not shown.
Binary file added fuzz/corpus/opRevokeSponsorshipLiquidityPool.raw
Binary file not shown.
Binary file added fuzz/corpus/opRevokeSponsorshipOffer.raw
Binary file not shown.
Binary file added fuzz/corpus/opRevokeSponsorshipPreAuthTxSigner.raw
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opSetOptions.raw
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opSetOptionsAddHashXSigner.raw
Binary file not shown.
Binary file added fuzz/corpus/opSetOptionsAddPreAuthTxSigner.raw
Binary file not shown.
Binary file added fuzz/corpus/opSetOptionsAddPublicKeySigner.raw
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opSetOptionsRemoveHashXSigner.raw
Binary file not shown.
Binary file added fuzz/corpus/opSetOptionsRemovePreAuthTxSigner.raw
Binary file not shown.
Binary file added fuzz/corpus/opSetOptionsRemovePublicKeySigner.raw
Binary file not shown.
Binary file added fuzz/corpus/opSetOptionsWithEmptyBody.raw
Binary file not shown.
Binary file added fuzz/corpus/opSetTrustLineFlagsAuthorized.raw
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opSetTrustLineFlagsUnauthorized.raw
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/opWithEmptySource.raw
Binary file not shown.
Binary file added fuzz/corpus/opWithMuxedSource.raw
Binary file not shown.
Binary file added fuzz/corpus/sorobanAuthCreateSmartContract.raw
Binary file not shown.
Binary file added fuzz/corpus/sorobanAuthInvokeContract.raw
Binary file not shown.
Binary file added fuzz/corpus/sorobanAuthInvokeContractTestPlugin.raw
Binary file not shown.
Binary file not shown.
Binary file added fuzz/corpus/sorobanAuthInvokeContractWithoutArgs.raw
Binary file not shown.
Binary file added fuzz/corpus/sorobanAuthPublic.raw
Binary file not shown.
Binary file added fuzz/corpus/sorobanAuthTestnet.raw
Binary file not shown.
Binary file added fuzz/corpus/sorobanAuthUnknownNetwork.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondExtraSignersWithOneSigner.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondExtraSignersWithTwoSigners.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondIsNone.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondLedgerBounds.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondLedgerBoundsAreZero.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondLedgerBoundsMaxIsZero.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondLedgerBoundsMinIsZero.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondMinAccountSequence.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondMinAccountSequenceAge.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondMinAccountSequenceLedgerGap.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondTimeBounds.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondTimeBoundsAreZero.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondTimeBoundsIsNone.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondTimeBoundsMaxIsZero.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondTimeBoundsMinIsZero.raw
Binary file not shown.
Binary file added fuzz/corpus/txCondWithAllItems.raw
Binary file not shown.
Binary file added fuzz/corpus/txCustomBaseFee.raw
Binary file not shown.
Binary file added fuzz/corpus/txMemoHash.raw
Binary file not shown.
Binary file added fuzz/corpus/txMemoId.raw
Binary file not shown.
Binary file added fuzz/corpus/txMemoNone.raw
Binary file not shown.
Binary file added fuzz/corpus/txMemoReturnHash.raw
Binary file not shown.
Binary file added fuzz/corpus/txMemoText.raw
Binary file not shown.
Binary file added fuzz/corpus/txMemoTextUnprintable.raw
Binary file not shown.
Binary file added fuzz/corpus/txMultiOperations.raw
Binary file not shown.
Binary file added fuzz/corpus/txNetworkCustom.raw
Binary file not shown.
Binary file added fuzz/corpus/txNetworkPublic.raw
Binary file not shown.
Binary file added fuzz/corpus/txNetworkTestnet.raw
Binary file not shown.
Binary file added fuzz/corpus/txSourceOmitMuxedSourceEqualSigner.raw
Binary file not shown.
Binary file added fuzz/corpus/txSourceOmitSourceEqualSigner.raw
Binary file not shown.
Binary file added fuzz/corpus/txSourceOmitSourceNotEqualSigner.raw
Binary file not shown.
Binary file added fuzz/corpus/txWithMuxedSource.raw
Binary file not shown.
68 changes: 68 additions & 0 deletions fuzz/fuzz_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
#define DETAIL_CAPTION_MAX_LENGTH 21
#define DETAIL_VALUE_MAX_LENGTH 105

static bool plugin_check_presence(const uint8_t *contract_address);
static stellar_plugin_result_t plugin_init_contract(const uint8_t *contract_address);
static stellar_plugin_result_t plugin_query_data_pair_count(const uint8_t *contract_address,
uint8_t *data_pair_count);
static stellar_plugin_result_t plugin_query_data_pair(const uint8_t *contract_address,
uint8_t data_pair_index,
char *caption,
uint8_t caption_len,
char *value,
uint8_t value_len);

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
envelope_t envelope;
bool data_exists = true;
Expand Down Expand Up @@ -57,6 +68,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
.caption_len = DETAIL_CAPTION_MAX_LENGTH,
.value_len = DETAIL_VALUE_MAX_LENGTH,
.display_sequence = true,
.plugin_check_presence = &plugin_check_presence,
.plugin_init_contract = &plugin_init_contract,
.plugin_query_data_pair_count = &plugin_query_data_pair_count,
.plugin_query_data_pair = &plugin_query_data_pair,
};

reset_formatter();
Expand All @@ -74,3 +89,56 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {

return 0;
}

static bool plugin_check_presence(const uint8_t *contract_address) {
uint8_t expected[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
return memcmp(contract_address, expected, 32) == 0;
}

stellar_plugin_result_t plugin_init_contract(const uint8_t *contract_address) {
// Build-in token plugin
if (plugin_check_presence(contract_address)) {
return STELLAR_PLUGIN_RESULT_OK;
}
return STELLAR_PLUGIN_RESULT_UNAVAILABLE;
}

stellar_plugin_result_t plugin_query_data_pair_count(const uint8_t *contract_address,
uint8_t *data_pair_count) {
// Build-in token plugin
if (plugin_check_presence(contract_address)) {
*data_pair_count = 3;
return STELLAR_PLUGIN_RESULT_OK;
}
return STELLAR_PLUGIN_RESULT_UNAVAILABLE;
}

stellar_plugin_result_t plugin_query_data_pair(const uint8_t *contract_address,
uint8_t data_pair_index,
char *caption,
uint8_t caption_len,
char *value,
uint8_t value_len) {
if (!plugin_check_presence(contract_address)) {
return STELLAR_PLUGIN_RESULT_UNAVAILABLE;
}
switch (data_pair_index) {
case 0:
strncpy(caption, "caption 0", caption_len);
strncpy(value, "value 0", value_len);
break;
case 1:
strncpy(caption, "caption 1", caption_len);
strncpy(value, "value 1", value_len);
break;
case 2:
strncpy(caption, "caption 2", caption_len);
strncpy(value, "value 2", value_len);
break;
default:
return STELLAR_PLUGIN_RESULT_ERROR;
}
return STELLAR_PLUGIN_RESULT_OK;
}
22 changes: 22 additions & 0 deletions fuzz/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -e

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BUILDDIR="$SCRIPTDIR/cmake-build-fuzz-coverage"
CORPUSDIR="$SCRIPTDIR/corpus"
HTMLCOVDIR="$SCRIPTDIR/html-coverage"

# Compile the fuzzer with code coverage support
rm -rf "$BUILDDIR" "$HTMLCOVDIR"
cmake -DBOLOS_SDK=/opt/ledger-secure-sdk -DCMAKE_C_COMPILER=clang -DCODE_COVERAGE=1 -B"$BUILDDIR" -H.
cmake --build "$BUILDDIR" --target fuzz_tx

# Run the fuzzer on the corpus files
export LLVM_PROFILE_FILE="$BUILDDIR/fuzz_tx.%p.profraw"
# "$BUILDDIR/fuzz_tx" "$CORPUSDIR"/*
"$BUILDDIR/fuzz_tx" -rss_limit_mb=1024 -max_len=20000 -max_total_time=600 -print_final_stats=1 "$CORPUSDIR" -jobs=4 -workers=4
llvm-profdata merge --sparse "$BUILDDIR"/fuzz_tx.*.profraw -o "$BUILDDIR/fuzz_tx.profdata"

# Exclude lib_standard_app directory, base32 and base64 code from coverage report
llvm-cov show "$BUILDDIR/fuzz_tx" -instr-profile="$BUILDDIR/fuzz_tx.profdata" -show-line-counts-or-regions -output-dir="$HTMLCOVDIR" -format=html -ignore-filename-regex="(.*lib_standard_app.*)|(.*libstellar/base64\.c.*)|(.*libstellar/base32\.c.*)"
llvm-cov report "$BUILDDIR/fuzz_tx" -instr-profile="$BUILDDIR/fuzz_tx.profdata" -ignore-filename-regex="(.*lib_standard_app.*)|(.*libstellar/base64\.c.*)|(.*libstellar/base32\.c.*)"

0 comments on commit 292e502

Please sign in to comment.