Skip to content
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

Libspark fuzzing harness #1340

Merged
merged 163 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
c4a3f5b
Spark address/key serialization functions implemented
levonpetrosyan93 May 31, 2022
9ad3318
CSparkWallet and mint db functions added
levonpetrosyan93 May 31, 2022
adb68c8
Spark mint tx creation, GetAvailableSparkCoins() implemented
levonpetrosyan93 May 31, 2022
1be6605
Bind serial commitments to chain context
AaronFeickert Jun 2, 2022
ac6451a
Use default curve generator for spend component
AaronFeickert Jun 2, 2022
ac05fc4
Merge remote-tracking branch 'aaron/spark' into spark-integration
levonpetrosyan93 Jun 3, 2022
88ce194
Completed merge
levonpetrosyan93 Jun 4, 2022
06384fe
Use default address when auto minting
levonpetrosyan93 Jun 5, 2022
f070135
Adding domain separators when doing hashes
levonpetrosyan93 Jun 6, 2022
44b6340
Adding version and checksum in address serialization
levonpetrosyan93 Jun 6, 2022
1f74f82
Saving serial_context into CSparkMintMeta
levonpetrosyan93 Jun 12, 2022
a469bcc
Moving Spark related code into separate directory
levonpetrosyan93 Jun 16, 2022
b204911
Embed KDF derived key size into hash instantiation
AaronFeickert Jun 22, 2022
cd4dcc0
Generalize range proofs to arbitrary set sizes
AaronFeickert Jun 22, 2022
89c9a11
Merge remote-tracking branch 'aaron/spark' into spark_second_iteration
levonpetrosyan93 Jun 24, 2022
d3174d3
Spark state implemented
levonpetrosyan93 Jun 27, 2022
8630557
More state functionality implemented
levonpetrosyan93 Jun 27, 2022
9ab17dd
WIP: spend verification batching
AaronFeickert Jun 24, 2022
ec25b62
Adding Spark state into mempool
levonpetrosyan93 Jul 6, 2022
187426a
Merge branch 'master' into spark_second_iteration
levonpetrosyan93 Jul 6, 2022
84155cb
Use a key-committing AEAD construction
AaronFeickert Aug 9, 2022
9c4c09d
More spark state functionality implemented
levonpetrosyan93 Aug 29, 2022
3243ea3
Merge remote-tracking branch 'aaron/spark' into spark_second_iteration
levonpetrosyan93 Aug 29, 2022
b5bb40b
Merge remote-tracking branch 'aaron/spark-key-commitment' into spark_…
levonpetrosyan93 Aug 29, 2022
ad2728e
Spark balance proof fixed
levonpetrosyan93 Sep 13, 2022
8682e66
Merge branch 'spark_balanceproof' into spark_second_iteration
levonpetrosyan93 Sep 13, 2022
65e408e
Adds an encoding method for address scrambling
AaronFeickert Sep 5, 2022
bbe9f77
Switch from hex to `bech32m` encoding
AaronFeickert Sep 16, 2022
a5696b5
Add tests
AaronFeickert Sep 16, 2022
47dec9b
Merge remote-tracking branch 'aaron/f4grumble' into spark_second_iter…
levonpetrosyan93 Sep 17, 2022
df0e4ac
SpendTransaction refactored and added serialization for it
levonpetrosyan93 Sep 18, 2022
d91c1e2
Merge branch 'spark_second_iteration' of https://github.com/firoorg/f…
levonpetrosyan93 Sep 18, 2022
8f72c66
Review comment applied and fixed a bug in mint generation
levonpetrosyan93 Sep 18, 2022
0229b3a
Spark spend creation
levonpetrosyan93 Sep 26, 2022
c67c03e
Spark spend verification
levonpetrosyan93 Oct 3, 2022
4bfcd09
More state functionality implemented and bug fixes
levonpetrosyan93 Oct 17, 2022
9ef0a48
Merge branch 'spark' into spark_second_iteration
levonpetrosyan93 Oct 17, 2022
6f3ca51
Some bug fixes and cleanup
levonpetrosyan93 Oct 23, 2022
5d589ef
Merge branch 'spark_second_iteration' of https://github.com/firoorg/f…
levonpetrosyan93 Oct 23, 2022
9493672
Bug fixes and review comments resolved
levonpetrosyan93 Oct 27, 2022
be80840
More review comments resolved
levonpetrosyan93 Oct 28, 2022
88b4993
Adding several rpc calls for spark
levonpetrosyan93 Oct 28, 2022
03dabc5
Adding more rpc calls
levonpetrosyan93 Oct 29, 2022
ed73e5f
Failing unittests fixed
levonpetrosyan93 Oct 31, 2022
713d808
Version bump
levonpetrosyan93 Nov 3, 2022
3a66338
Devnet Spark HF block
levonpetrosyan93 Nov 3, 2022
712230e
Added fuzz folder for persistent fuzzing libspark fuzzing
Mikerah Nov 4, 2022
e703bcd
bech32 fuzzing harness for honggfuzz added
Mikerah Nov 4, 2022
6b6f70c
fix bech32_fuzz.cpp
onurinanc Nov 4, 2022
5115085
Added f4grumble fuzzing harness
Mikerah Nov 4, 2022
a09c876
Forgot to add return statement to f4grumble_fuzz.cpp
Mikerah Nov 4, 2022
134c38c
Moved libspark related fuzzing to its own folder
Mikerah Nov 11, 2022
f948a91
Added FuzzedDataProvider.h
Mikerah Nov 15, 2022
cc86a41
Integrated FuzzedDataProvider.h in bech32_fuzz.cpp
Mikerah Nov 15, 2022
d432fa1
Fixed fuzzing enum in bech32_fuzz.cpp
Mikerah Nov 16, 2022
330cff6
missing semicolon
Mikerah Nov 16, 2022
b211a73
Added fuzz folder for persistent fuzzing libspark fuzzing
Mikerah Nov 4, 2022
7ba4dcc
Added fuzzing utilities for group elements and scalars
Mikerah Nov 19, 2022
ed77757
Added fuzzing for aead.cpp
Mikerah Nov 20, 2022
a3c0822
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 20, 2022
c0edb4f
Added vector versions of GetGroupElement and GetScalar in fuzzing_uti…
Mikerah Nov 21, 2022
b1edcfb
Added single proof fuzz test for bpplus_fuzz
Mikerah Nov 21, 2022
3123611
LelantusToSpark function implemented
levonpetrosyan93 Nov 21, 2022
d3060b2
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 22, 2022
0a42a82
Refactoring of file paths
levonpetrosyan93 Nov 24, 2022
18055a8
lelantustospark rpc name refactored
levonpetrosyan93 Nov 24, 2022
5efcbb4
Adding check to stop lelantus on consensus level
levonpetrosyan93 Nov 24, 2022
cc2c40f
Added fuzz folder for persistent fuzzing libspark fuzzing
Mikerah Nov 4, 2022
0b61131
Added fuzzing utilities for group elements and scalars
Mikerah Nov 19, 2022
c4aaadb
Added fuzzing for aead.cpp
Mikerah Nov 20, 2022
6f80a75
Added vector versions of GetGroupElement and GetScalar in fuzzing_uti…
Mikerah Nov 21, 2022
e7ceb86
Added single proof fuzz test for bpplus_fuzz
Mikerah Nov 21, 2022
fa3c13f
Merge branch 'spark_second_iteration' of https://github.com/firoorg/f…
Nov 24, 2022
b50bc75
Changed relative paths of dependencies in secp256k1/src/cpp
Mikerah Nov 24, 2022
4481900
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 24, 2022
ec26b64
More relative path changes in src/secp256k1
Mikerah Nov 24, 2022
a0b300b
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 24, 2022
5bc8995
Changed relative paths in crypto/common.h
Mikerah Nov 25, 2022
14ce20d
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
d3ffa26
Removed FuzzedSecp256k1Object deconstructor
Mikerah Nov 25, 2022
ba0dd10
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
9b9a517
Addedd aead_fuzz.cpp and other utilities
levonpetrosyan93 Nov 24, 2022
3ea8e4a
Added vector versions of GetGroupElement and GetScalar in fuzzing_uti…
Mikerah Nov 21, 2022
701c161
Added single proof fuzz test for bpplus_fuzz
Mikerah Nov 21, 2022
a079a62
Changed relative paths of dependencies in secp256k1/src/cpp
Mikerah Nov 24, 2022
e54fc75
More relative path changes in src/secp256k1
Mikerah Nov 24, 2022
d64c3f2
Changed relative paths in crypto/common.h
Mikerah Nov 25, 2022
1624ba4
Removed FuzzedSecp256k1Object deconstructor
Mikerah Nov 25, 2022
f1d6a0f
Added batch bpplus proofs fuzzing tests
Mikerah Nov 25, 2022
744a540
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
c8453f3
Changed relative paths in libspark/params.h
Mikerah Nov 25, 2022
90c562a
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
2b52010
Fixed errors in bpplus_fuzz.cpp
Mikerah Nov 25, 2022
8edd054
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
b049f6d
Fixed more errors
Mikerah Nov 25, 2022
92cc7b6
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
cd3850a
More fixes in bpplus.cpp
Mikerah Nov 25, 2022
62acf4b
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
dc031ea
Completed bpplus_fuzz tests
Mikerah Nov 25, 2022
840d679
Added chaum_fuzz.cpp
Mikerah Nov 25, 2022
debc169
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
ff72472
Changed relative paths in src/wallet/crypter.h
Mikerah Nov 25, 2022
c03f02f
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
ef1897e
Changed relative path in arith_uint256.h
Mikerah Nov 25, 2022
a0eba45
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
d71442c
Completed chaum fuzz tests
Mikerah Nov 25, 2022
21ff946
Added schnorr_fuzz.cpp
Mikerah Nov 25, 2022
e1b5fa4
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
c927cf3
Addedd grootle_fuzz.cpp
Mikerah Nov 25, 2022
24e9970
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
91fb24f
Added length to ConsumeBytes call
Mikerah Nov 25, 2022
ac6784a
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
0e46401
Initialized sizes vector via a loop in grootle_fuzz.cpp
Mikerah Nov 25, 2022
fb85e80
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
484f138
Changed relative paths in support/allocator/secure.h
Mikerah Nov 25, 2022
bed91ff
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
5fd4cbc
Changed relative paths in support/allocator/secure.h again
Mikerah Nov 25, 2022
6714fa7
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 25, 2022
52ff84f
Added mint_transaction_fuzz.cpp
Mikerah Nov 26, 2022
106fd12
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 26, 2022
159bc6f
Changed type of parameter in MintTransaction in mint_transaction_fuzz…
Mikerah Nov 26, 2022
6134f5b
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 26, 2022
0f25e99
Changed relative path in params.cpp
Mikerah Nov 26, 2022
2b76ac5
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 26, 2022
888c3ff
Changed relative paths in consensus/params.h
Mikerah Nov 26, 2022
b0eafea
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 26, 2022
b620526
Changed relative paths in primitives/block.h
Mikerah Nov 26, 2022
90f6f7b
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 26, 2022
d0b0c14
Changed relative paths in primitives/transaction.h
Mikerah Nov 26, 2022
7e444eb
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 26, 2022
5bbf24b
Changed relative paths in src/script/script.h
Mikerah Nov 26, 2022
26685f6
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 26, 2022
0ad57ba
Changed more relative paths in src/script/script.h
Mikerah Nov 26, 2022
a61dcdf
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 26, 2022
7fe78f8
Changed relative paths in crypto/MerkleTreeProof/mtp.h
Mikerah Nov 26, 2022
294ae80
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 26, 2022
c882c7e
Changed relative paths in crypto/MerkleTreeProof/mtp.h. Actually this…
Mikerah Nov 26, 2022
8a23169
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 26, 2022
cd2667d
Changed relative paths in crypto/progpow.h
Mikerah Nov 27, 2022
9ca3714
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 27, 2022
20db43c
Completed mint_transaction_fuzz.cpp
Mikerah Nov 26, 2022
64408a6
Added spend_transaction_fuzz.cpp
Mikerah Nov 27, 2022
743de68
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 27, 2022
eb17eed
Fixed errors in spend_transaction_fuzz.cpp
Mikerah Nov 27, 2022
0bef115
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Nov 27, 2022
5fb41f9
Completed spend_transaction_fuzz.cpp
Mikerah Nov 27, 2022
04957a0
Updated relative paths in MultiExponent.cpp
Mikerah Dec 1, 2022
5f839fe
Merge branch 'fuzz/libspark' of https://github.com/hashcloak/firo int…
Dec 1, 2022
2aaa590
fuzzing and coverage of different libspark files
Aug 21, 2023
3af1890
makefile and code-coverage for libspark
Sep 4, 2023
9596842
spend transaction modified
Oct 2, 2023
7bdc6db
spark conflict resolved
Oct 2, 2023
5d06627
coverage, input, results removed
Oct 3, 2023
83d2415
empty and temporary files deleted
Oct 3, 2023
e1ee513
empty files removed
Oct 3, 2023
378b83d
readme for fuzzing modified
Oct 3, 2023
760d9b4
original paths restored and conflict resolved, flags added in fuzz ma…
Oct 11, 2023
72db3e4
Merge branch 'spark' of https://github.com/firoorg/firo into spark_fu…
Oct 11, 2023
636f845
path fixed and merged latest spark
Oct 11, 2023
9dda00d
path fixed
Oct 11, 2023
85dd71c
instructions for installing dependencies added in fuzz readme
Oct 11, 2023
572d9bf
binary removed and loop length resized
Oct 27, 2023
9f75eac
readme modified & vetor size reserved in fuzzing_utilities
Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/crypto/progpow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ uint256 progpow_hash_full(const CProgPowHeader& header, uint256& mix_hash);
/* Performs a light progpow hash (DAG loops excluded) provided header has mix_hash */
uint256 progpow_hash_light(const CProgPowHeader& header);

#endif // FIRO_PROGPOW_H
#endif // FIRO_PROGPOW_H
398 changes: 398 additions & 0 deletions src/fuzz/FuzzedDataProvider.h

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions src/fuzz/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
CXX := hfuzz-clang++

CXXFLAGS := -DHAVE_CONFIG_H -I../../src/ -iquote ../../src/config/ -iquote ../secp256k1/ -iquote ../secp256k1/src/ -iquote ../secp256k1/include/
CXXFLAGS2 := -DHAVE_CONFIG_H

LIBS := -lcrypto -lstdc++ -lboost_thread -lboost_filesystem -lboost_program_options -lboost_chrono
LIBS2 := -lstdc++ -lcrypto

INCLUDE_HEADER := -include ../streams.h -include ../version.h

BPPLUS_SRCS := libspark/bpplus_fuzz.cpp ../libspark/bpplus.cpp ../libspark/util.cpp fuzzing_utilities.cpp ../libspark/hash.cpp ../libspark/kdf.cpp ../libspark/transcript.cpp ../crypto/aes.cpp ../crypto/chacha20.cpp ../crypto/sha512.cpp ../secp256k1/src/cpp/Scalar.cpp ../secp256k1/src/cpp/GroupElement.cpp ../secp256k1/src/cpp/MultiExponent.cpp ../support/cleanse.cpp ../util.cpp ../utiltime.cpp ../utilstrencodings.cpp ../random.cpp ../chainparamsbase.cpp
BPPLUS_OUTPUT := libspark/bpplus_hfuzz
BPPLUS_OUTPUT_DEBUG := libspark/bpplus_debug

BECH32_SRCS := libspark/bech32_fuzz_2.cpp ../libspark/bech32.cpp
BECH32_OUTPUT := libspark/bech32_hfuzz
BECH32_OUTPUT_DEBUG := libspark/bech32_debug

AEAD_SRCS := libspark/aead_fuzz.cpp ../libspark/aead.cpp ../libspark/util.cpp ../libspark/kdf.cpp ../libspark/hash.cpp ../fuzz/fuzzing_utilities.cpp ../crypto/aes.cpp ../support/lockedpool.cpp ../support/cleanse.cpp ../secp256k1/src/cpp/Scalar.cpp ../secp256k1/src/cpp/GroupElement.cpp
AEAD_OUTPUT := libspark/aead_hfuzz
AEAD_OUTPUT_DEBUG := libspark/aead_debug

GROOTLE_SRCS := libspark/grootle_fuzz.cpp ../libspark/grootle.cpp ../libspark/util.cpp fuzzing_utilities.cpp ../libspark/hash.cpp ../libspark/kdf.cpp ../libspark/transcript.cpp ../crypto/aes.cpp ../crypto/chacha20.cpp ../crypto/sha512.cpp ../secp256k1/src/cpp/Scalar.cpp ../secp256k1/src/cpp/GroupElement.cpp ../secp256k1/src/cpp/MultiExponent.cpp ../support/cleanse.cpp ../util.cpp ../utiltime.cpp ../utilstrencodings.cpp ../random.cpp ../chainparamsbase.cpp
GROOTLE_OUTPUT := libspark/grootle_hfuzz
GROOTLE_OUTPUT_DEBUG := libspark/grootle_debug

CHAUM_SRCS := libspark/chaum_fuzz.cpp ../libspark/chaum.cpp ../libspark/transcript.cpp fuzzing_utilities.cpp ../secp256k1/src/cpp/Scalar.cpp ../secp256k1/src/cpp/GroupElement.cpp ../secp256k1/src/cpp/MultiExponent.cpp ../support/cleanse.cpp
CHAUM_OUTPUT := libspark/chaum_hfuzz
CHAUM_OUTPUT_DEBUG := libspark/chaum_debug

SCHNORR_SRCS := libspark/schnorr_fuzz.cpp ../libspark/schnorr.cpp ../fuzz/fuzzing_utilities.cpp ../secp256k1/src/cpp/Scalar.cpp ../secp256k1/src/cpp/GroupElement.cpp ../secp256k1/src/cpp/MultiExponent.cpp ../libspark/transcript.cpp ../support/cleanse.cpp
SCHNORR_OUTPUT := libspark/schnorr_hfuzz
SCHNORR_OUTPUT_DEBUG := libspark/schnorr_debug

COIN_SRCS := libspark/coin_fuzz.cpp ../libspark/coin.cpp ../libspark/params.cpp ../crypto/aes.cpp ../crypto/ripemd160.cpp ../crypto/sha256.cpp ../secp256k1/src/cpp/Scalar.cpp ../secp256k1/src/cpp/GroupElement.cpp ../secp256k1/src/cpp/MultiExponent.cpp ../support/*.cpp ../uint256.cpp ../utilstrencodings.cpp fuzzing_utilities.cpp ../libspark/aead.cpp ../libspark/util.cpp ../libspark/keys.cpp ../libspark/f4grumble.cpp ../libspark/hash.cpp ../libspark/bech32.cpp ../libspark/kdf.cpp
COIN_OUTPUT := libspark/coin_hfuzz
COIN_OUTPUT_DEBUG := libspark/coin_debug

MINT_TRANSACTION_SRCS := libspark/mint_transaction_fuzz.cpp ../libspark/mint_transaction.cpp ../libspark/coin.cpp ../libspark/keys.cpp ../libspark/schnorr.cpp ../fuzz/fuzzing_utilities.cpp ../libspark/util.cpp ../libspark/hash.cpp ../libspark/kdf.cpp ../libspark/transcript.cpp ../libspark/f4grumble.cpp ../libspark/params.cpp ../libspark/bech32.cpp ../libspark/aead.cpp ../crypto/aes.cpp ../crypto/ripemd160.cpp ../crypto/sha256.cpp ../secp256k1/src/cpp/Scalar.cpp ../secp256k1/src/cpp/GroupElement.cpp ../secp256k1/src/cpp/MultiExponent.cpp ../support/cleanse.cpp ../uint256.cpp ../utilstrencodings.cpp
MINT_TRANSACTION_OUTPUT := libspark/mint_transaction_hfuzz
MINT_TRANSACTION_OUTPUT_DEBUG := libspark/mint_transaction_debug

SPEND_TRANSACTION_SRCS := libspark/spend_transaction_fuzz.cpp ../libspark/spend_transaction.cpp ../libspark/coin.cpp ../libspark/keys.cpp ../libspark/schnorr.cpp ../fuzz/fuzzing_utilities.cpp ../libspark/util.cpp ../libspark/hash.cpp ../libspark/kdf.cpp ../libspark/transcript.cpp ../libspark/f4grumble.cpp ../libspark/params.cpp ../libspark/bech32.cpp ../libspark/aead.cpp ../libspark/chaum.cpp ../libspark/bpplus.cpp ../libspark/grootle.cpp ../crypto/aes.cpp ../crypto/ripemd160.cpp ../crypto/sha256.cpp ../crypto/chacha20.cpp ../crypto/sha512.cpp ../secp256k1/src/cpp/Scalar.cpp ../secp256k1/src/cpp/GroupElement.cpp ../secp256k1/src/cpp/MultiExponent.cpp ../support/cleanse.cpp ../uint256.cpp ../utilstrencodings.cpp ../util.cpp ../utiltime.cpp ../chainparamsbase.cpp ../random.cpp
SPEND_TRANSACTION_OUTPUT := libspark/spend_transaction_hfuzz
SPEND_TRANSACTION_OUTPUT_DEBUG := libspark/spend_transaction_debug

F4GRUMBLE_SRCS := libspark/f4grumble_fuzz.cpp ../libspark/f4grumble.cpp ../libspark/util.cpp ../libspark/kdf.cpp ../libspark/hash.cpp ../crypto/aes.cpp ../support/lockedpool.cpp ../support/cleanse.cpp ../secp256k1/src/cpp/Scalar.cpp ../secp256k1/src/cpp/GroupElement.cpp
F4GRUMBLE_OUTPUT := libspark/f4grumble_hfuzz
F4GRUMBLE_OUTPUT_DEBUG := libspark/f4grumble_debug

DEBUG_FLAGS := -g -O0 -ggdb

bpplus: $(BPPLUS_OUTPUT)
$(BPPLUS_OUTPUT): $(BPPLUS_SRCS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

bpplus_debug: $(BPPLUS_OUTPUT_DEBUG)
$(BPPLUS_OUTPUT_DEBUG): $(BPPLUS_SRCS)
$(CXX) $(DEBUG_FLAGS) $(CXXFLAGS) $^ -o $@ $(LIBS)

bech32: $(BECH32_OUTPUT)
$(BECH32_OUTPUT): $(BECH32_SRCS)
$(CXX) $(CXXFLAGS2) $^ -o $@ $(LIBS2)

bech32_debug: $(BECH32_OUTPUT_DEBUG)
$(BECH32_OUTPUT_DEBUG): $(BECH32_SRCS)
$(CXX) $(DEBUG_FLAGS) $(CXXFLAGS2) $^ -o $@ $(LIBS2)

aead: $(AEAD_OUTPUT)
$(AEAD_OUTPUT): $(AEAD_SRCS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS2)

aead_debug: $(AEAD_OUTPUT_DEBUG)
$(AEAD_OUTPUT_DEBUG): $(AEAD_SRCS)
$(CXX) $(DEBUG_FLAGS) $(CXXFLAGS) $^ -o $@ $(LIBS2)

grootle: $(GROOTLE_OUTPUT)
$(GROOTLE_OUTPUT): $(GROOTLE_SRCS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

grootle_debug: $(GROOTLE_OUTPUT_DEBUG)
$(GROOTLE_OUTPUT_DEBUG): $(GROOTLE_SRCS)
$(CXX) $(DEBUG_FLAGS) $(CXXFLAGS) $^ -o $@ $(LIBS)

chaum: $(CHAUM_OUTPUT)
$(CHAUM_OUTPUT): $(CHAUM_SRCS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(INCLUDE_HEADER) $(LIBS)

chaum_debug: $(CHAUM_OUTPUT_DEBUG)
$(CHAUM_OUTPUT_DEBUG): $(CHAUM_SRCS)
$(CXX) $(DEBUG_FLAGS) $(CXXFLAGS2) $^ -o $@ $(INCLUDE_HEADER) $(LIBS)

schnorr: $(SCHNORR_OUTPUT)
$(SCHNORR_OUTPUT): $(SCHNORR_SRCS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(INCLUDE_HEADER) $(LIBS)

schnorr_debug: $(SCHNORR_OUTPUT_DEBUG)
$(SCHNORR_OUTPUT_DEBUG): $(SCHNORR_SRCS)
$(CXX) $(DEBUG_FLAGS) $(CXXFLAGS) $^ -o $@ $(INCLUDE_HEADER) $(LIBS)

coin: $(COIN_OUTPUT)
$(COIN_OUTPUT): $(COIN_SRCS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

coin_debug: $(COIN_OUTPUT_DEBUG)
$(COIN_OUTPUT_DEBUG): $(COIN_SRCS)
$(CXX) $(DEBUG_FLAGS) $(CXXFLAGS) $^ -o $@ $(LIBS)

mint_transaction: $(MINT_TRANSACTION_OUTPUT)
$(MINT_TRANSACTION_OUTPUT): $(MINT_TRANSACTION_SRCS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS2)

mint_transaction_debug: $(MINT_TRANSACTION_OUTPUT_DEBUG)
$(MINT_TRANSACTION_OUTPUT_DEBUG): $(MINT_TRANSACTION_SRCS)
$(CXX) $(DEBUG_FLAGS) $(CXXFLAGS2) $^ -o $@ $(LIBS2)

spend_transaction: $(SPEND_TRANSACTION_OUTPUT)
$(SPEND_TRANSACTION_OUTPUT): $(SPEND_TRANSACTION_SRCS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

spend_transaction_debug: $(SPEND_TRANSACTION_OUTPUT_DEBUG)
$(SPEND_TRANSACTION_OUTPUT_DEBUG): $(SPEND_TRANSACTION_SRCS)
$(CXX) $(DEBUG_FLAGS) $(CXXFLAGS) $^ -o $@ $(LIBS)

f4grumble: $(F4GRUMBLE_OUTPUT)
$(F4GRUMBLE_OUTPUT): $(F4GRUMBLE_SRCS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

f4grumble_debug: $(F4GRUMBLE_OUTPUT_DEBUG)
$(F4GRUMBLE_OUTPUT_DEBUG): $(F4GRUMBLE_SRCS)
$(CXX) $(DEBUG_FLAGS) $(CXXFLAGS) $^ -o $@ $(LIBS)

clean:
rm -f $(BPPLUS_OUTPUT) $(BPPLUS_OUTPUT_DEBUG) $(BECH32_OUTPUT) $(BECH32_OUTPUT_DEBUG) $(AEAD_OUTPUT) $(AEAD_OUTPUT_DEBUG) $(GROOTLE_OUTPUT) $(GROOTLE_OUTPUT_DEBUG) $(CHAUM_OUTPUT) $(CHAUM_OUTPUT_DEBUG) $(SCHNORR_OUTPUT) $(SCHNORR_OUTPUT_DEBUG) $(COIN_OUTPUT) $(COIN_OUTPUT_DEBUG) $(MINT_TRANSACTION_OUTPUT) $(MINT_TRANSACTION_OUTPUT_DEBUG) $(SPEND_TRANSACTION_OUTPUT) $(SPEND_TRANSACTION_OUTPUT_DEBUG) *.o
142 changes: 142 additions & 0 deletions src/fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Fuzzing libspark

## Quickstart Guide
To quickly get started fuzzing libspark using honggfuzz:

### Build firo
- clone this repo:
```
git clone -b spark https://github.com/firoorg/firo.git
```
- Build firo: Follow instruction from https://github.com/firoorg/firo/tree/spark#readme

Once the build is successful, we have to install honggfuzz and required dependencies.

### Installing fuzzer and Dependencies
- Install honggfuzz (https://github.com/google/honggfuzz)
```
sudo apt-get install binutils-dev libunwind-dev libblocksruntime-dev clang
git clone https://github.com/google/honggfuzz.git
cd honggfuzz
make
sudo make install
```
For more information you can look at https://github.com/google/honggfuzz/blob/master/docs/USAGE.md

You might also need to install the following boost and ssl dependencies in order to compile the fuzzing harness:

```
sudo apt install libboost-dev
sudo apt install libssl-dev
sudo apt install libstdc++-12-dev
sudo apt install libboost-filesystem-dev
sudo apt install libboost-thread-dev
sudo apt install libboost-program-options-dev
sudo apt install libboost-chrono-dev
```

### Fuzzing using honggfuzz
* In order to fuzz `firo/src/libpark` using Honggfuzz:

```
cd firo/src/fuzz/
export CC=hfuzz-clang
export CXX=hfuzz-clang++
```

To compile with `hfuzz-clang++`, inside src/fuzz run:

```
make <filename>
```

For example(for bpplus):
```
make bpplus
```
The above command will generate an instrumented binary with name `<filename>_hfuzz` (eg: bpplus_hfuzz) inside src/fuzz/libspark.

The fuzzing harness of the following spark files is availabe: aead, bech32, bpplus, chaum, coin, f4grumble, grootle, mint_transaction, schnorr and spend_transaction.

* To start fuzzing:

1. create directories for input corpora and for saving all the crashes
```
mkdir input crashes
```
2. Inside the crashes directory run:
```
honggfuzz -i input -- ./libspark/<filename>_hfuzz ___FILE___
```

example:
1. `mkdir input crashes`
2. `cd crashes`
2. `honggfuzz -i ../input -- ./../libspark/bpplus_hfuzz ___FILE___`
3. To stop press `ctrl+c`

Here we are providing an empty corpora. In case of an already available corpora, we can provide the availabe corpora.
The flag `-i` is for the input folder which we are providing `./../<filename>_hfuzz>` is the target binary which we want to fuzz.

### Analyzing the crashes

If there is a crash, the reason for the crash can be found in HONGGFUZZ.REPORT.TXT or simply by running
```
./libspark/<binary_file> <input_file>
```

Example:
```
./libspark/bpplus_hfuzz SIGABRT.PC.7ffff7a8400b.STACK.1b5b5f0067.CODE.-6.ADDR.0.INSTR.mov____0x108(%rsp),%rax
```

To debug or to do the rootcause analysis, gdb debugger can be used. to debug using gdb debugger:

1. First compile the harness using gdb flags `-g -O0 -ggdb`. To compile using gdb debugger, inside `src/fuzz` run:
```
make <filename>_debug
```
Example:
```
make bpplus_debug
```

2. start the debugger by running:
```
gdb --args <filename_debug> <crashed_input>
```
Example:
```
gdb --args bpplus_debug SIGABRT.PC.7ffff7a8400b.STACK.1b5b5f0067.CODE.-6.ADDR.0.INSTR.mov____0x108(%rsp),%rax
```
This will start the debugger.

3. You can do heap analysis by running `heap-analysis` inside the debugger and/or `bt` for backtracing.


### Generating a Coverage Report using kcov
* Install kcov (https://github.com/SimonKagstrom/kcov/tree/master)
```
sudo apt-get install binutils-dev libssl-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
git clone https://github.com/SimonKagstrom/kcov.git
cd /path/to/kcov/source/dir
mkdir build
cd build
cmake ..
make
sudo make install
```
Once successfully installed, follow the below instructions to generate the code-coverage

1. First compile the harness with gdb flag. run `make <filename>_debug` inside src/fuzz to compile using gdb debugger.
2. take the input_folder as the input corpora from fuzzing or one can also create it by running: `honggfuzz -i <input_folder> -– ./<filename>_hfuzz ___FILE___ @@`. This will start the fuzzer. Kill it by `ctrl+C`. The fuzzer will generate some random inputs inside the input_folder. Since kcov will generate coverage for each input inside the input_folder, it's preffered to have only a few inputs, otherwise it will take a long time to generate the entire coverage.

3. inside the `generate_coverage.sh` replace the input_folder, output_folder and fuzz_exe by your inpur corpora, coverage output folder and harness binary.
4. run `./generate_coverage.sh`. This will generated a merged output for all the inputs present in the input_folder.
5. To view the result run run `firefox ./merged-output/index.html`.

6. alternatively or if you are on a VM, go inside coverage output folder and then merged-output
7. run `python3 -m http.server`. This will start a http server at http://0.0.0.0:8000/
8. open your browser and paste http://0.0.0.0:8000/ to see the result.

NOTE: to view the coverage for every dependent file, `generate_coverage.sh` should be in the root folder. Also, you should either delete the previous port or start the server on new port by running `python3 -m http.server <port_number>` for different files.
89 changes: 89 additions & 0 deletions src/fuzz/fuzzing_utilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "fuzzing_utilities.h"

FuzzedSecp256k1Object::FuzzedSecp256k1Object(FuzzedDataProvider *fdp) {
this->fdp = fdp;
}

secp_primitives::GroupElement FuzzedSecp256k1Object::GetGroupElement() {
char* x = (char *)this->fdp->ConsumeBytes<uint8_t>(256).data();
char* y = (char *)this->fdp->ConsumeBytes<uint8_t>(256).data();
secp_primitives::GroupElement ge = secp_primitives::GroupElement(x, y);

return ge;
}

secp_primitives::Scalar FuzzedSecp256k1Object::GetScalar() {
uint64_t value = this->fdp->ConsumeIntegral<uint64_t>();
secp_primitives::Scalar s = secp_primitives::Scalar(value);

return s;
}

secp_primitives::GroupElement FuzzedSecp256k1Object::GetMemberGroupElement() {
secp_primitives::GroupElement ge;
ge.randomize();
return ge;
}

std::vector<secp_primitives::GroupElement> FuzzedSecp256k1Object::GetMemberGroupElements(size_t len) {
std::vector<secp_primitives::GroupElement> ge_vec;
ge_vec.resize(len);
for (size_t i = 0; i < len; i++) {
ge_vec[i] = (GetMemberGroupElement());
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved
}
return ge_vec;
}

std::vector<secp_primitives::GroupElement> FuzzedSecp256k1Object::GetRandomGroupVector(size_t len) {
std::vector<secp_primitives::GroupElement> result;
result.resize(len);
for (size_t i = 0; i < len; i++) {
result[i].randomize();
}
return result;
}

std::vector<secp_primitives::GroupElement> FuzzedSecp256k1Object::GetGroupElements(int len) {
std::vector<secp_primitives::GroupElement> ge_vec;
ge_vec.reserve(len);
for (int i = 0; i < len; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this loop, as ge_vec.resize(len) does the same, or do reserve() instead of resize().

ge_vec.push_back(GetGroupElement());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resize creates len number of infinity GroupElements and pushes into ge_vec, and here we push len+1 number of GroupElements, is this function suppose to work that way?

}

return ge_vec;
}

std::vector<secp_primitives::Scalar> FuzzedSecp256k1Object::GetScalars(size_t len) {
std::vector<secp_primitives::Scalar> scalar_vec;
scalar_vec.reserve(len);
for (int i = 0; i < len; i++) {
scalar_vec.push_back(GetScalar());
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved
}

return scalar_vec;
}

std::vector<secp_primitives::Scalar> FuzzedSecp256k1Object::GetScalarsVector(size_t len) {
std::vector<secp_primitives::Scalar> scalar_vec;
scalar_vec.reserve(len);
for (int i = 0; i < len; i++) {
scalar_vec.push_back(GetScalar());
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved
}

return scalar_vec;
}

secp_primitives::Scalar FuzzedSecp256k1Object::GetScalar_modified() {
secp_primitives::Scalar s = secp_primitives::Scalar(this->fdp->ConsumeBytes<uint8_t>(256).data());
return s;
}

std::vector<secp_primitives::Scalar> FuzzedSecp256k1Object::GetScalars_modified(int len) {
std::vector<secp_primitives::Scalar> scalar_vec;
scalar_vec.reserve(len);
for (int i = 0; i < len; i++) {
scalar_vec.push_back(GetScalar_modified());
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved
}

return scalar_vec;
}
Loading