-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
Libspark fuzzing harness #1340
Changes from 161 commits
c4a3f5b
9ad3318
adb68c8
1be6605
ac6451a
ac05fc4
88ce194
06384fe
f070135
44b6340
1f74f82
a469bcc
b204911
cd4dcc0
89c9a11
d3174d3
8630557
9ab17dd
ec25b62
187426a
84155cb
9c4c09d
3243ea3
b5bb40b
ad2728e
8682e66
65e408e
bbe9f77
a5696b5
47dec9b
df0e4ac
d91c1e2
8f72c66
0229b3a
c67c03e
4bfcd09
9ef0a48
6f3ca51
5d589ef
9493672
be80840
88b4993
03dabc5
ed73e5f
713d808
3a66338
712230e
e703bcd
6b6f70c
5115085
a09c876
134c38c
f948a91
cc86a41
d432fa1
330cff6
b211a73
7ba4dcc
ed77757
a3c0822
c0edb4f
b1edcfb
3123611
d3060b2
0a42a82
18055a8
5efcbb4
cc2c40f
0b61131
c4aaadb
6f80a75
e7ceb86
fa3c13f
b50bc75
4481900
ec26b64
a0b300b
5bc8995
14ce20d
d3ffa26
ba0dd10
9b9a517
3ea8e4a
701c161
a079a62
e54fc75
d64c3f2
1624ba4
f1d6a0f
744a540
c8453f3
90c562a
2b52010
8edd054
b049f6d
92cc7b6
cd3850a
62acf4b
dc031ea
840d679
debc169
ff72472
c03f02f
ef1897e
a0eba45
d71442c
21ff946
e1b5fa4
c927cf3
24e9970
91fb24f
ac6784a
0e46401
fb85e80
484f138
bed91ff
5fd4cbc
6714fa7
52ff84f
106fd12
159bc6f
6134f5b
0f25e99
2b76ac5
888c3ff
b0eafea
b620526
90f6f7b
d0b0c14
7e444eb
5bbf24b
26685f6
0ad57ba
a61dcdf
7fe78f8
294ae80
c882c7e
8a23169
cd2667d
9ca3714
20db43c
64408a6
743de68
eb17eed
0bef115
5fb41f9
04957a0
5f839fe
2aaa590
3af1890
9596842
7bdc6db
5d06627
83d2415
e1ee513
378b83d
760d9b4
72db3e4
636f845
9dda00d
85dd71c
572d9bf
9f75eac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Fuzzing libspark | ||
|
||
## Quickstart Guide | ||
* Dependencies | ||
1. 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 | ||
``` | ||
|
||
2. Build firo | ||
Follow the instructions from https://github.com/firoorg/firo/tree/spark#readme | ||
|
||
* In order to fuzz `firo/src/libpark` using LLVM LibFuzzer: | ||
|
||
``` | ||
git clone -b spark_fuzz_blog https://github.com/hashcloak/firo.git | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be changed to the upstream repository. |
||
cd firo/src/fuzz/ | ||
export CC=hfuzz-clang | ||
export CXX=hfuzz-clang++ | ||
``` | ||
|
||
To compile with `hfuzz-clang++`: | ||
|
||
``` | ||
cd src/fuzz/ | ||
make <filename> | ||
``` | ||
|
||
For example(for bpplus): | ||
``` | ||
cd src/fuzz/ | ||
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 a directory to save all the crahses. | ||
2. Inside the directory run: | ||
``` | ||
hongfuzz -i <path_of_input_corpora>/<filename_inputs> -- ./<filename_hfuzz> ___FILE___ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
``` | ||
|
||
example: | ||
1. `mkdir src/fuzz/bpplus_results && cd src/fuzz/bpplus_results` | ||
2. `hongfuzz -i ../../inputs/bpplus_inputs -- ./../../libspark/bpplus_hfuzz ___FILE___` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, |
||
3. To stop press `ctrl+c` | ||
|
||
If there is no input corpora, empty corpora can be provided. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide a note that this means creating and passing an empty directory via |
||
|
||
### Analyzing the crashes | ||
|
||
If there is a crash, the reason for the crash can be found simply by running | ||
``` | ||
./<binary_file> <input_file> | ||
``` | ||
|
||
Example: | ||
``` | ||
./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. |
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.resize(len); | ||
for (int i = 0; i <= len; i++) { | ||
ge_vec.push_back(GetGroupElement()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.resize(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.resize(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.resize(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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "FuzzedDataProvider.h" | ||
#include "../secp256k1/include/Scalar.h" | ||
#include "../secp256k1/include/GroupElement.h" | ||
|
||
class FuzzedSecp256k1Object { | ||
public: | ||
FuzzedSecp256k1Object(FuzzedDataProvider *fdp); | ||
|
||
FuzzedDataProvider *fdp; | ||
|
||
secp_primitives::GroupElement GetGroupElement(); | ||
secp_primitives::Scalar GetScalar(); | ||
secp_primitives::GroupElement GetMemberGroupElement(); | ||
secp_primitives::Scalar GetScalar_modified(); | ||
|
||
std::vector<secp_primitives::GroupElement> GetGroupElements(int len); | ||
std::vector<secp_primitives::Scalar> GetScalars(size_t len); | ||
std::vector<secp_primitives::GroupElement> GetMemberGroupElements(size_t len); | ||
std::vector<secp_primitives::GroupElement> GetRandomGroupVector(size_t len); | ||
std::vector<secp_primitives::Scalar> GetScalars_modified(int len); | ||
std::vector<secp_primitives::Scalar> GetScalarsVector(size_t len); | ||
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
input_folder="../../src/fuzz/inputs/bpplus_inputs" | ||
output_folder="../../src/fuzz/coverage_result/bpplus_coverage" | ||
fuzz_exe="../../src/fuzz/libspark/bpplus_debug" | ||
|
||
mkdir $output_folder | ||
|
||
number_of_files=$(ls $input_folder | wc | awk '{print $1}') | ||
echo "Number of input files to test: $number_of_files" | ||
|
||
count=0 | ||
|
||
for i in $(ls $input_folder); | ||
do | ||
kcov --include-path=. ./$output_folder/input_$count ./$fuzz_exe --stdout -d ./$input_folder/$i > /dev/null; | ||
((count++)); | ||
echo "[++] Count of files processed: $count"; | ||
done | ||
|
||
kcov --merge ./$output_folder/merged-output ./$output_folder/input_* |
levonpetrosyan93 marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This contradicts the
git clone
command in the next step.