-
Notifications
You must be signed in to change notification settings - Fork 53
/
run-c-kzg-4844-fuzz.sh
130 lines (101 loc) · 2.57 KB
/
run-c-kzg-4844-fuzz.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
# current checkout hash
C_KZG_4844_GIT_HASH=1bccee0878ffc80efe8741afdb5793ef9105aa35
set -e
print_msg () {
echo "[*]" "$1"
}
###################### parallel & backend configuration ######################
parallel=false
use_arkmsm=false
use_bgmw=false
backend="unknown"
while [[ -n $# ]]; do
case $1 in
-p|--parallel)
parallel=true
;;
--arkmsm)
use_arkmsm=true
;;
--bgmw)
use_bgmw=true
;;
blst|arkworks|arkworks3|mcl|zkcrypto|constantine)
backend="$1"
;;
*)
break
;;
esac
shift
done
if [ "$backend" == "unknown" ]; then
echo "Unknown backend: $backend"
exit 1
fi
features=""
#Check if --arkmsm is specified
if [ "$use_arkmsm" = true ]; then
features+="arkmsm,"
fi
# Check if --bgmw is specified
if [ "$use_bgmw" = true ]; then
features+="bgmw"
fi
# Trim the trailing comma, if any
features=$(echo "$features" | sed 's/,$//')
###################### building static libs ######################
print_msg "Compiling rust-kzg-$backend"
cd $backend
if [[ "$parallel" = true ]]; then
print_msg "Using parallel version"
cargo rustc --release --crate-type=staticlib --features="$features"
else
print_msg "Using non-parallel version"
cargo rustc --release --crate-type=staticlib --features="$features"
fi
mv ../target/release/librust_kzg_$backend.a ../target/release/rust_kzg_$backend.a
###################### cloning c-kzg-4844 ######################
print_msg "Removing existing c-kzg-4844"
rm -rf c-kzg-4844
print_msg "Cloning c-kzg-4844"
git clone https://github.com/ethereum/c-kzg-4844.git
cd c-kzg-4844 || exit
git -c advice.detachedHead=false checkout "$C_KZG_4844_GIT_HASH"
git submodule update --init
print_msg "Applying patches and building blst"
cd src
export CFLAGS="-Ofast -fno-builtin-memcpy -fPIC -Wall -Wextra -Werror"
make blst
unset CFLAGS
cd ..
###################### detecting os ######################
case $(uname -s) in
"Linux")
CSHARP_PLATFORM=linux-x64
CLANG_PLATFORM=x86_64-linux
;;
"Darwin")
CSHARP_PLATFORM=osx-x64
CLANG_PLATFORM=x86_64-darwin
;;
*)
echo "FAIL: unsupported OS"
exit 1
;;
esac
###################### fuzzing ######################
pwd
print_msg "Patching go binding"
git apply < ../go.patch
cd bindings/go || exit
git clone https://github.com/jtraglia/kzg-fuzz.git
cd kzg-fuzz || exit
go clean -modcache
echo 'replace "github.com/ethereum/c-kzg-4844" v0.3.1 => "../../../"' >> go.mod
go install
bash fuzz.sh
# ###################### cleaning up ######################
print_msg "Cleaning up"
rm -rf c-kzg-4844