diff --git a/.gitignore b/.gitignore index d3d18f1..6b51961 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,5 @@ lighthouse/* target/ **/*.txt **/*.rs.bk -Cargo.lock files/tools/*/bin .mypy_cache/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 90fed9a..925510b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,31 +5,38 @@ repos: # Python # TODO remove branch paths, should use specific revisions - - repo: https://github.com/psf/black - rev: 19.10b0 - hooks: - - id: black - name: python-black - +# - repo: https://github.com/psf/black +# rev: 20.8b1 +# hooks: +# - id: black +# name: python-black +# # - repo: https://github.com/asottile/seed-isort-config # rev: v1.9.3 # hooks: # - id: seed-isort-config # name: seed-isort-config - - - repo: https://github.com/timothycrosley/isort - rev: 4.3.21 - hooks: - - id: isort - name: python-isort - additional_dependencies: [toml] +# +# - repo: https://github.com/timothycrosley/isort +# rev: 5.5.3 +# hooks: +# - id: isort +# name: python-isort +# additional_dependencies: [toml] # Rust - repo: https://github.com/doublify/pre-commit-rust - rev: 55f347186aec7f2a4ec13c31effdb4b26512f2bc + rev: v1.0 hooks: - id: fmt - name: rust-fmt + name: cargo-fmt-bf2 + args: [--manifest-path, beaconfuzz_v2/Cargo.toml, --] + - id: fmt + name: cargo-fmt-eth2fuzz + args: [--manifest-path, eth2fuzz/Cargo.toml, --] + - id: fmt + name: cargo-fmt-eth2diff + args: [--manifest-path, eth2diff/Cargo.toml, --] # TODO currently doesn't work if Cargo.toml isn't in the root directory # Can have a hook that takes in Cargo.toml files and uses manifest-path for each # - id: cargo-check @@ -69,7 +76,7 @@ repos: # Shell - repo: https://github.com/jumanjihouse/pre-commit-hooks - rev: 1.11.0 + rev: 2.1.4 hooks: # These need external installation # TODO specify via additional_dependencies ? @@ -78,8 +85,8 @@ repos: args: ['-l', '-i', '4', '-ci', '-w'] # C, C++ etc - - repo: https://gitlab.com/daverona-env/pre-commit-cpp - rev: 0.6.0 + - repo: https://gitlab.com/daverona/pre-commit/cpp + rev: 0.8.0 hooks: - id: clang-format - id: cpplint @@ -100,7 +107,7 @@ repos: # Misc/General - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.4.0 + rev: v3.2.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer diff --git a/beaconfuzz_v2/Cargo.lock b/beaconfuzz_v2/Cargo.lock new file mode 100644 index 0000000..1c120a5 --- /dev/null +++ b/beaconfuzz_v2/Cargo.lock @@ -0,0 +1,1909 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "addr2line" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" + +[[package]] +name = "aho-corasick" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +dependencies = [ + "memchr", +] + +[[package]] +name = "amcl" +version = "0.2.0" +source = "git+https://github.com/sigp/milagro_bls?branch=paulh#7662690845f3f2594e46cfe71b6b0bb91d5e1f82" +dependencies = [ + "hex 0.3.2", + "lazy_static", +] + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "arbitrary" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0922a3e746b5a44e111e5603feb6704e5cc959116f66737f50bb5cbd264e9d87" +dependencies = [ + "derive_arbitrary", +] + +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "backtrace" +version = "0.3.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" + +[[package]] +name = "beaconfuzz_v2" +version = "0.1.0" +dependencies = [ + "clap", + "eth2_ssz", + "eth2_ssz_derive", + "eth2clientsfuzz", + "failure", + "honggfuzz", + "rand 0.6.5", + "state_processing", + "structopt", + "teku", + "types", + "walkdir", +] + +[[package]] +name = "bfuzz-jni" +version = "0.1.0" +dependencies = [ + "bindgen", + "cc", +] + +[[package]] +name = "bindgen" +version = "0.55.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b13ce559e6433d360c26305643803cb52cfbabbc2b9c47ce04a58493dfb443" +dependencies = [ + "bitflags", + "cexpr", + "cfg-if", + "clang-sys", + "clap", + "env_logger", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "which", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "bitvec" +version = "0.17.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41262f11d771fd4a61aa3ce019fca363b4b6c282fca9da2a31186d3965a47a5c" +dependencies = [ + "either", + "radium", +] + +[[package]] +name = "blake2b_simd" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bls" +version = "0.2.0" +dependencies = [ + "arbitrary", + "blst", + "eth2_hashing", + "eth2_ssz", + "ethereum-types", + "hex 0.3.2", + "milagro_bls", + "rand 0.7.3", + "serde", + "serde_derive", + "serde_hex", + "tree_hash", + "zeroize", +] + +[[package]] +name = "blst" +version = "0.1.1" +source = "git+https://github.com/sigp/blst.git?rev=284f7059642851c760a09fb1708bcb59c7ca323c#284f7059642851c760a09fb1708bcb59c7ca323c" +dependencies = [ + "cc", + "glob", + "threadpool", +] + +[[package]] +name = "bumpalo" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" + +[[package]] +name = "byte-slice-cast" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0a5e3906bcbf133e33c1d4d95afc664ad37fbdb9f6568d8043e7ea8c27d93d3" + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + +[[package]] +name = "cached_tree_hash" +version = "0.1.0" +dependencies = [ + "eth2_hashing", + "eth2_ssz", + "eth2_ssz_derive", + "eth2_ssz_types", + "ethereum-types", + "smallvec", + "tree_hash", +] + +[[package]] +name = "cc" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66120af515773fb005778dc07c261bd201ec8ce50bd6e7144c927753fe013381" + +[[package]] +name = "cexpr" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "clang-sys" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9da1484c6a890e374ca5086062d4847e0a2c1e5eba9afa5d48c09e8eb39b2519" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "compare_fields" +version = "0.2.0" + +[[package]] +name = "compare_fields_derive" +version = "0.2.0" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" + +[[package]] +name = "crossbeam-channel" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ee0cc8804d5393478d743b035099520087a5186f3b93fa58cec08fa62407b6" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" +dependencies = [ + "autocfg 1.0.1", + "cfg-if", + "crossbeam-utils", + "lazy_static", + "maybe-uninit", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg 1.0.1", + "cfg-if", + "lazy_static", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "derivative" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_arbitrary" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0f7c6c81276b6b8702074defbdb1938933ddf98c7f7e0dca8d9e9214dd6c730" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dirs" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" +dependencies = [ + "cfg-if", + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dtoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" + +[[package]] +name = "either" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" + +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "eth2_hashing" +version = "0.1.1" +dependencies = [ + "lazy_static", + "ring", + "sha2", +] + +[[package]] +name = "eth2_interop_keypairs" +version = "0.2.0" +dependencies = [ + "bls", + "eth2_hashing", + "hex 0.4.2", + "lazy_static", + "num-bigint", + "serde", + "serde_derive", + "serde_yaml", +] + +[[package]] +name = "eth2_ssz" +version = "0.1.2" +dependencies = [ + "ethereum-types", + "smallvec", +] + +[[package]] +name = "eth2_ssz_derive" +version = "0.1.0" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "eth2_ssz_types" +version = "0.2.0" +dependencies = [ + "arbitrary", + "eth2_ssz", + "serde", + "serde_derive", + "serde_hex", + "tree_hash", + "typenum", +] + +[[package]] +name = "eth2clientsfuzz" +version = "0.1.0" +dependencies = [ + "arbitrary", + "eth2_ssz", + "eth2_ssz_derive", + "lighthouse", + "nimbus", + "prysm", + "state_processing", + "teku", + "types", +] + +[[package]] +name = "ethbloom" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71a6567e6fd35589fea0c63b94b4cf2e55573e413901bdbe60ab15cf0e25e5df" +dependencies = [ + "crunchy", + "fixed-hash", + "impl-rlp", + "impl-serde", + "tiny-keccak", +] + +[[package]] +name = "ethereum-types" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "473aecff686bd8e7b9db0165cbbb53562376b39bf35b427f0c60446a9e1634b0" +dependencies = [ + "ethbloom", + "fixed-hash", + "impl-rlp", + "impl-serde", + "primitive-types", + "uint", +] + +[[package]] +name = "failure" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" +dependencies = [ + "backtrace", + "failure_derive", +] + +[[package]] +name = "failure_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + +[[package]] +name = "fixed-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11498d382790b7a8f2fd211780bec78619bba81cdad3a283997c0c41f836759c" +dependencies = [ + "arbitrary", + "byteorder", + "rand 0.7.3", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "heck" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" + +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" + +[[package]] +name = "honggfuzz" +version = "0.5.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f085725a5828d7e959f014f624773094dfe20acc91be310ef106923c30594bc" +dependencies = [ + "arbitrary", + "lazy_static", + "memmap", +] + +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + +[[package]] +name = "impl-codec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1be51a921b067b0eaca2fad532d9400041561aa922221cc65f95a85641c6bf53" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-rlp" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f7a72f11830b52333f36e3b09a288333888bf54380fd0ac0790a3c31ab0f3c5" +dependencies = [ + "rlp", +] + +[[package]] +name = "impl-serde" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b47ca4d2b6931707a55fce5cf66aff80e2178c8b63bbb4ecb5695cbc870ddf6f" +dependencies = [ + "serde", +] + +[[package]] +name = "int_to_bytes" +version = "0.2.0" +dependencies = [ + "bytes", +] + +[[package]] +name = "integer-sqrt" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f65877bf7d44897a473350b1046277941cee20b263397e90869c50b6e766088b" + +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + +[[package]] +name = "js-sys" +version = "0.3.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85a7e2c92a4804dd459b86c339278d0fe87cf93757fae222c3fa3ae75458bc73" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3" + +[[package]] +name = "libloading" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2443d8f0478b16759158b2f66d525991a05491138bc05814ef52a250148ef4f9" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e704a02bcaecd4a08b93a23f6be59d0bd79cd161e0963e9499165a0a35df7bd" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "lighthouse" +version = "0.1.0" +dependencies = [ + "eth2_ssz", + "eth2_ssz_derive", + "state_processing", + "types", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" + +[[package]] +name = "log" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "lru-cache" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "memoffset" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f" +dependencies = [ + "autocfg 1.0.1", +] + +[[package]] +name = "merkle_proof" +version = "0.2.0" +dependencies = [ + "eth2_hashing", + "ethereum-types", + "lazy_static", + "safe_arith", +] + +[[package]] +name = "milagro_bls" +version = "1.1.0" +source = "git+https://github.com/sigp/milagro_bls?branch=paulh#7662690845f3f2594e46cfe71b6b0bb91d5e1f82" +dependencies = [ + "amcl", + "hex 0.4.2", + "lazy_static", + "rand 0.7.3", + "zeroize", +] + +[[package]] +name = "miniz_oxide" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d7559a8a40d0f97e1edea3220f698f78b1c5ab67532e49f68fde3910323b722" +dependencies = [ + "adler", +] + +[[package]] +name = "nimbus" +version = "0.1.0" +dependencies = [ + "eth2_ssz", + "eth2_ssz_derive", + "state_processing", + "types", +] + +[[package]] +name = "nom" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +dependencies = [ + "memchr", + "version_check", +] + +[[package]] +name = "num-bigint" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f3fc75e3697059fb1bc465e3d8cca6cf92f56854f201158b3f9c77d5a3cfa0" +dependencies = [ + "autocfg 1.0.1", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +dependencies = [ + "autocfg 1.0.1", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +dependencies = [ + "autocfg 1.0.1", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" + +[[package]] +name = "once_cell" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "parity-scale-codec" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34d38aeaffc032ec69faa476b3caaca8d4dd7f3f798137ff30359e5c7869ceb6" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "serde", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "pkg-config" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" + +[[package]] +name = "ppv-lite86" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" + +[[package]] +name = "primitive-types" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c55c21c64d0eaa4d7ed885d959ef2d62d9e488c27c0e02d9aa5ce6c877b7d5f8" +dependencies = [ + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "uint", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "prysm" +version = "0.1.0" + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.7", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc 0.1.0", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg", + "rand_xorshift 0.1.1", + "winapi", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.3.1", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.4.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_xorshift" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77d416b86801d23dde1aa643023b775c3a462efc0ed96443add11546cdf1dca8" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rayon" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfd016f0c045ad38b5251be2c9c0ab806917f82da4d36b2a327e5166adad9270" +dependencies = [ + "autocfg 1.0.1", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91739a34c4355b5434ce54c9086c5895604a9c278586d1f1aa95e04f66b525a0" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "redox_users" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431" +dependencies = [ + "getrandom", + "redox_syscall", + "rust-argon2", +] + +[[package]] +name = "regex" +version = "1.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "ring" +version = "0.16.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "952cd6b98c85bbc30efa1ba5783b8abf12fec8b3287ffa52605b9432313e34e4" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + +[[package]] +name = "rlp" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a7d3f9bed94764eac15b8f14af59fac420c236adaff743b7bcc88e265cb4345" +dependencies = [ + "rustc-hex", +] + +[[package]] +name = "rusqlite" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45d0fd62e1df63d254714e6cb40d0a0e82e7a1623e7a27f679d851af092ae58b" +dependencies = [ + "bitflags", + "fallible-iterator", + "fallible-streaming-iterator", + "libsqlite3-sys", + "lru-cache", + "memchr", + "smallvec", + "time", +] + +[[package]] +name = "rust-argon2" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017" +dependencies = [ + "base64", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + +[[package]] +name = "safe_arith" +version = "0.1.0" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "serde" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" + +[[package]] +name = "serde_derive" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_hex" +version = "0.2.0" +dependencies = [ + "hex 0.4.2", + "serde", +] + +[[package]] +name = "serde_yaml" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3e2dd40a7cdc18ca80db804b7f461a39bb721160a85c9a1fa30134bf3c02a5" +dependencies = [ + "dtoa", + "linked-hash-map", + "serde", + "yaml-rust", +] + +[[package]] +name = "sha2" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2933378ddfeda7ea26f48c555bdad8bb446bf8a3d17832dc83e380d444cfb8c1" +dependencies = [ + "block-buffer", + "cfg-if", + "cpuid-bool", + "digest", + "opaque-debug", +] + +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + +[[package]] +name = "slog" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cc9c640a4adbfbcc11ffb95efe5aa7af7309e002adab54b185507dbf2377b99" + +[[package]] +name = "smallvec" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "state_processing" +version = "0.2.0" +dependencies = [ + "arbitrary", + "bls", + "eth2_hashing", + "eth2_ssz", + "eth2_ssz_types", + "int_to_bytes", + "integer-sqrt", + "itertools", + "log", + "merkle_proof", + "rayon", + "safe_arith", + "tree_hash", + "tree_hash_derive", + "types", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "structopt" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5472fb24d7e80ae84a7801b7978f95a19ec32cb1876faea59ab711eb901976" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0eb37335aeeebe51be42e2dc07f031163fbabfa6ac67d7ea68b5c2f68d5f99" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "swap_or_not_shuffle" +version = "0.2.0" +dependencies = [ + "eth2_hashing", + "ethereum-types", +] + +[[package]] +name = "syn" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "synstructure" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + +[[package]] +name = "teku" +version = "0.1.0" +dependencies = [ + "bfuzz-jni", + "eth2_ssz", + "eth2_ssz_derive", + "types", +] + +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +dependencies = [ + "cfg-if", + "libc", + "rand 0.7.3", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "termcolor" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "test_random_derive" +version = "0.2.0" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "time" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tree_hash" +version = "0.1.1" +dependencies = [ + "eth2_hashing", + "ethereum-types", + "smallvec", +] + +[[package]] +name = "tree_hash_derive" +version = "0.2.0" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "types" +version = "0.2.0" +dependencies = [ + "arbitrary", + "bls", + "cached_tree_hash", + "compare_fields", + "compare_fields_derive", + "derivative", + "dirs", + "eth2_hashing", + "eth2_interop_keypairs", + "eth2_ssz", + "eth2_ssz_derive", + "eth2_ssz_types", + "ethereum-types", + "hex 0.4.2", + "int_to_bytes", + "log", + "merkle_proof", + "rand 0.7.3", + "rand_xorshift 0.2.0", + "rayon", + "rusqlite", + "safe_arith", + "serde", + "serde_derive", + "serde_yaml", + "slog", + "swap_or_not_shuffle", + "tempfile", + "test_random_derive", + "tree_hash", + "tree_hash_derive", +] + +[[package]] +name = "uint" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9db035e67dfaf7edd9aebfe8676afcd63eed53c8a4044fed514c8cccf1835177" +dependencies = [ + "arbitrary", + "byteorder", + "crunchy", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "unicode-segmentation" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "vcpkg" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" + +[[package]] +name = "walkdir" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasm-bindgen" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc71e4c5efa60fb9e74160e89b93353bc24059999c0ae0fb03affc39770310b0" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97c57cefa5fa80e2ba15641578b44d36e7a64279bc5ed43c6dbaf329457a2ed2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092" + +[[package]] +name = "web-sys" +version = "0.3.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dda38f4e5ca63eda02c059d243aa25b5f35ab98451e518c51612cd0f1bd19a47" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "which" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" +dependencies = [ + "libc", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "yaml-rust" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39f0c922f1a334134dc2f7a8b67dc5d25f0735263feec974345ff706bcf20b0d" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "zeroize" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de251eec69fc7c1bc3923403d18ececb929380e016afe103da75f396704f8ca2" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] diff --git a/beaconfuzz_v2/Cargo.toml b/beaconfuzz_v2/Cargo.toml index c378dc4..38399fd 100644 --- a/beaconfuzz_v2/Cargo.toml +++ b/beaconfuzz_v2/Cargo.toml @@ -22,13 +22,16 @@ types = { path = "../../lighthouse/consensus/types" } #prysm = { path = "libs/prysm" } # lighthouse = { path = "libs/lighthouse" } eth2clientsfuzz = { path = "libs/eth2clientsfuzz" } +teku = { path = "libs/teku" } [workspace] members = [ "libs/prysm", "libs/nimbus", - "libs/lighthouse", - "libs/eth2clientsfuzz" + "libs/lighthouse", + "libs/eth2clientsfuzz", + "libs/bfuzz-jni", + "libs/teku", ] diff --git a/beaconfuzz_v2/README.md b/beaconfuzz_v2/README.md index d0c70bf..75cd6a8 100644 --- a/beaconfuzz_v2/README.md +++ b/beaconfuzz_v2/README.md @@ -38,7 +38,7 @@ Clone the repository of nimbus and compile the nimbus fuzzing library: ``` git clone https://github.com/status-im/nim-beacon-chain --branch devel cd nim-beacon-chain -NIMFLAGS="-d:disableLTO" make libnfuzz.a libnfuzz.so +NIMFLAGS="-d:disableLTO" make libnfuzz.a ``` Finally, set the following variable with the current path of nimbus: @@ -65,6 +65,70 @@ Set the following variable with the current path of prysm: export CARGO_PRYSM_DIR=beacon-fuzz/beaconfuzz_v2/libs ``` +### teku setup + +Install Java 11 or greater + +e.g. + +```console +$ sudo apt install openjdk-11-jdk +``` + +Ensure `JAVA_HOME` is set. + +(If `echo $JAVA_HOME` is displays no output) it should probably be set to something like: + +```console +$ export JAVA_HOME="$(dirname $(dirname $(readlink -f $(command -v java))))" +``` + +Probably want to add it to your `.profile` +(This is `/usr/lib/jvm/java-11-openjdk-amd64` in ubuntu) + +Add `$JAVA_HOME/lib/server` to your runtime library path via *either* of the following methods: + +**via LD_LIBRARY_PATH** + +```console +$ export LD_LIBRARY_PATH="$JAVA_HOME/lib/server" +``` + +This needs to be set at runtime - i.e. whenever you want to run the teku fuzzer, not when you're building it. + +Or + +**via ldconfig** + +```console +$ echo "$JAVA_HOME/lib/server" >> /etc/ld.so.conf.d/java.conf +$ sudo ldconfig +``` + + + + +Clone teku repository: +```console +$ git clone https://github.com/PegaSysEng/teku.git +``` + +Set `BFUZZ_TEKU_DIR` to the root teku directory: +```console +$ BFUZZ_TEKU_DIR="$(realpath -e path/to/teku)" && export BFUZZ_TEKU_DIR +``` + +Build teku: +```console +$ cd teku +$ ./gradlew installDist -x test --stacktrace +$ ./gradlew fuzz:build +``` + + ### Beaconfuzz_v2 compilation Compile the project using the Makefile @@ -82,9 +146,9 @@ cargo +nightly install honggfuzz Compile and run the fuzzers: ``` make fuzz_* -fuzz_attestation fuzz_block fuzz_proposer_slashing +fuzz_attestation fuzz_block fuzz_proposer_slashing fuzz_attestation-struct fuzz_block-struct fuzz_proposer_slashing-struct -fuzz_attester_slashing fuzz_deposit fuzz_voluntary_exit +fuzz_attester_slashing fuzz_deposit fuzz_voluntary_exit fuzz_attester_slashing-struct fuzz_deposit-struct fuzz_voluntary_exit-struct ``` @@ -94,4 +158,4 @@ there is two differents kind of fuzzing targets: \ No newline at end of file + --> diff --git a/beaconfuzz_v2/fuzz/Cargo.toml b/beaconfuzz_v2/fuzz/Cargo.toml index 94b476a..e2519fb 100644 --- a/beaconfuzz_v2/fuzz/Cargo.toml +++ b/beaconfuzz_v2/fuzz/Cargo.toml @@ -21,6 +21,7 @@ types = { path = "../../../lighthouse/consensus/types", features = ["arbitrary-f # local library lighthouse = { path = "../libs/lighthouse" } eth2clientsfuzz = { path = "../libs/eth2clientsfuzz" } +teku = { path = "../libs/teku" } [patch.crates-io] # Needed to provide paths to some relevant dependencies diff --git a/beaconfuzz_v2/fuzz/fuzz_targets/struct_attestation.rs b/beaconfuzz_v2/fuzz/fuzz_targets/struct_attestation.rs index 2066177..7cf1494 100644 --- a/beaconfuzz_v2/fuzz/fuzz_targets/struct_attestation.rs +++ b/beaconfuzz_v2/fuzz/fuzz_targets/struct_attestation.rs @@ -17,6 +17,7 @@ use std::process; use rand::seq::SliceRandom; use rand::thread_rng; +use teku; /// List file in folder and return list of files paths #[inline(always)] @@ -134,6 +135,7 @@ lazy_static! { static ref INIT_OK: bool = { // initialize client only once eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::Attestation); true }; } diff --git a/beaconfuzz_v2/fuzz/fuzz_targets/struct_attester_slashing.rs b/beaconfuzz_v2/fuzz/fuzz_targets/struct_attester_slashing.rs index d4fdaa2..5cac4f3 100644 --- a/beaconfuzz_v2/fuzz/fuzz_targets/struct_attester_slashing.rs +++ b/beaconfuzz_v2/fuzz/fuzz_targets/struct_attester_slashing.rs @@ -135,6 +135,7 @@ lazy_static! { static ref INIT_OK: bool = { // initialize client only once eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::AttesterSlashing); true }; } diff --git a/beaconfuzz_v2/fuzz/fuzz_targets/struct_block.rs b/beaconfuzz_v2/fuzz/fuzz_targets/struct_block.rs index 75b0669..3c04685 100644 --- a/beaconfuzz_v2/fuzz/fuzz_targets/struct_block.rs +++ b/beaconfuzz_v2/fuzz/fuzz_targets/struct_block.rs @@ -135,6 +135,7 @@ lazy_static! { static ref INIT_OK: bool = { // initialize client only once eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::Block); true }; } diff --git a/beaconfuzz_v2/fuzz/fuzz_targets/struct_block_header.rs b/beaconfuzz_v2/fuzz/fuzz_targets/struct_block_header.rs index 7d857fa..1967836 100644 --- a/beaconfuzz_v2/fuzz/fuzz_targets/struct_block_header.rs +++ b/beaconfuzz_v2/fuzz/fuzz_targets/struct_block_header.rs @@ -6,7 +6,7 @@ use lazy_static::lazy_static; use walkdir::WalkDir; use ssz::{Decode, Encode}; -use types::{BeaconState, MainnetEthSpec, BeaconBlock}; +use types::{BeaconBlock, BeaconState, MainnetEthSpec}; use std::fs::File; use std::fs::OpenOptions; @@ -135,6 +135,7 @@ lazy_static! { static ref INIT_OK: bool = { // initialize client only once eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::BlockHeader); true }; } diff --git a/beaconfuzz_v2/fuzz/fuzz_targets/struct_deposit.rs b/beaconfuzz_v2/fuzz/fuzz_targets/struct_deposit.rs index 070e5b2..8233f9e 100644 --- a/beaconfuzz_v2/fuzz/fuzz_targets/struct_deposit.rs +++ b/beaconfuzz_v2/fuzz/fuzz_targets/struct_deposit.rs @@ -135,6 +135,7 @@ lazy_static! { static ref INIT_OK: bool = { // initialize client only once eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::Deposit); true }; } diff --git a/beaconfuzz_v2/fuzz/fuzz_targets/struct_proposer_slashing.rs b/beaconfuzz_v2/fuzz/fuzz_targets/struct_proposer_slashing.rs index 77717aa..96ba18f 100644 --- a/beaconfuzz_v2/fuzz/fuzz_targets/struct_proposer_slashing.rs +++ b/beaconfuzz_v2/fuzz/fuzz_targets/struct_proposer_slashing.rs @@ -135,6 +135,7 @@ lazy_static! { static ref INIT_OK: bool = { // initialize client only once eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::ProposerSlashing); true }; } diff --git a/beaconfuzz_v2/fuzz/fuzz_targets/struct_voluntary_exit.rs b/beaconfuzz_v2/fuzz/fuzz_targets/struct_voluntary_exit.rs index 9be5c78..81db55a 100644 --- a/beaconfuzz_v2/fuzz/fuzz_targets/struct_voluntary_exit.rs +++ b/beaconfuzz_v2/fuzz/fuzz_targets/struct_voluntary_exit.rs @@ -135,6 +135,7 @@ lazy_static! { static ref INIT_OK: bool = { // initialize client only once eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::VoluntaryExit); true }; } diff --git a/beaconfuzz_v2/libs/bfuzz-jni/Cargo.toml b/beaconfuzz_v2/libs/bfuzz-jni/Cargo.toml new file mode 100644 index 0000000..8a6dca9 --- /dev/null +++ b/beaconfuzz_v2/libs/bfuzz-jni/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "bfuzz-jni" +version = "0.1.0" +authors = ["Nathaniel Jensen "] +edition = "2018" +description = "Provides interface to Java beacon-fuzz harnesses via JNI" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[build-dependencies] +cc = "1.0.59" +bindgen = "0.55.1" diff --git a/beaconfuzz_v2/libs/bfuzz-jni/build.rs b/beaconfuzz_v2/libs/bfuzz-jni/build.rs new file mode 100644 index 0000000..25e0a2a --- /dev/null +++ b/beaconfuzz_v2/libs/bfuzz-jni/build.rs @@ -0,0 +1,39 @@ +use bindgen; + +use std::env; +use std::path::PathBuf; + +fn main() { + // TODO does it matter where I put these? + // TODO use clang? + println!("cargo:rerun-if-changed=src/bfuzzjni.c"); + println!("cargo:rerun-if-changed=src/bfuzzjni.h"); + + let jvm_home = PathBuf::from(env::var("JAVA_HOME").expect("JAVA_HOME not set")); + println!("cargo:rustc-link-search={}", jvm_home.join("lib").display()); + println!( + "cargo:rustc-link-search={}", + jvm_home.join("lib/server").display() + ); + println!("cargo:rustc-link-lib=jvm"); + // TODO need the equiv of -Wl,-R"${JAVA_HOME}/lib/server"? + // NOTE assumes a linux system here. + cc::Build::new() + .file("src/bfuzzjni.c") + .include("src") + .include(jvm_home.join("include")) + .include(jvm_home.join("include/linux")) + .compile("bfuzzjni"); + + let bindings = bindgen::Builder::default() + .header("src/bfuzzjni.h") + .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + .generate() + .expect("Unable to generate bindings"); + + // Write the bindings to the $OUT_DIR/bindings.rs file. + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); +} diff --git a/beaconfuzz_v2/libs/bfuzz-jni/src/DummyFuzzUtil.class b/beaconfuzz_v2/libs/bfuzz-jni/src/DummyFuzzUtil.class new file mode 100644 index 0000000..263c733 Binary files /dev/null and b/beaconfuzz_v2/libs/bfuzz-jni/src/DummyFuzzUtil.class differ diff --git a/beaconfuzz_v2/libs/bfuzz-jni/src/DummyFuzzUtil.java b/beaconfuzz_v2/libs/bfuzz-jni/src/DummyFuzzUtil.java new file mode 100644 index 0000000..6e0e83a --- /dev/null +++ b/beaconfuzz_v2/libs/bfuzz-jni/src/DummyFuzzUtil.java @@ -0,0 +1,30 @@ +import java.util.Optional; + +// TODO convert to testdata + +public class DummyFuzzUtil { + // NOTE: alternatively could also have these all in separate classes, which implement a + // "FuzzHarness" interface + + // Size of ValidatorIndex returned by shuffle + private static final int OUTPUT_INDEX_BYTES = Long.BYTES; + + private final boolean disable_bls; + + // NOTE: this uses primitive values as parameters to more easily call via JNI + public DummyFuzzUtil(final boolean useMainnetConfig, final boolean disable_bls) { + initialize(useMainnetConfig, disable_bls); + this.disable_bls = disable_bls; + } + + public static void initialize(final boolean useMainnetConfig, final boolean disable_bls) { + System.out.println("Initializing in Java"); + } + + public Optional fuzzAttestation(final byte[] input) { + System.out.println("Calling Java fuzzAttestation!"); + //Just return the input + //return Optional.of(input); + return Optional.empty(); + } +} diff --git a/beaconfuzz_v2/libs/bfuzz-jni/src/bfuzzjni.c b/beaconfuzz_v2/libs/bfuzz-jni/src/bfuzzjni.c new file mode 100644 index 0000000..02c3feb --- /dev/null +++ b/beaconfuzz_v2/libs/bfuzz-jni/src/bfuzzjni.c @@ -0,0 +1,405 @@ +#include "bfuzzjni.h" + +#include +#include +#include +#include +#include +#include +#include + +// LINT_C_FILE + +// TODO(gnattishness) note assumptions regarding trying to fuzz multiple Java +// targets or implementations +// TODO(gnattishness) allow fuzzing with more than 1 target - i.e. multiple +// methods? + +// NOTE: just use global variables to store state for now +// Means we can't have more than 1 Java client at once, but can't run multiple +// JVM interpreters anyway + +static JavaVM *g_jvm; // Pointer to the JVM +static JNIEnv *g_env; // Pointer to native interface +static jclass g_fuzz_class; +static jobject g_fuzz_instance; +static jmethodID g_fuzz_method; +static jclass g_optional_class; +static jmethodID g_optional_is_present; +static jmethodID g_optional_get; + +/** + * Holds the last result from the fuzzing target. + * + * May be NULL if the last result was an error + * A JNI global ref, needs to be explicitly freed. + */ +static jobject g_last_result; + +/** + * Stores the size of the last result, if it exists. + * + * May be -1 if the last result was an error. + * + * (Used for bounds checking) + * + * \Note jsize == int32_t + */ +static int32_t g_last_result_size; + +// TODO(gnattishness) do we reset g_last_result_size or leave as garbage when +// freeing last result? if reset, can more safely handle when an error-free, +// valid result is empty (with size 0) +// * Only valid when `g_last_result != NULL` + +// TODO(gnattishness) use a persistent block of memory to hold most recent +// result or malloc/free every time? time vs space tradeoffs we malloc for now, +// for simplicity + +/** + * TODO(gnattishness) delete, outdated? + * Helper function to setup the temporary "g_last_result" storage for some size + * + * Upon completion, g_last_result points to some memory that can hold new_size + * bytes, and g_last_result_size == new_size. + * + * appropriately handles if g_last_result == NULL or not without leaking memory + * + * \param[in] new_size How big g_last_result should be. + * If 0 or negative, g_last_result is set to NULL. + * + */ +// void prepare_last_result(int32_t new_size){ +// // Also good for encapsulation so can more easily convert to fancier +// // methods to reduce memory allocations between fuzzing executions +// if (new_size <= 0) { +// if (g_last_result != NULL) { +// free(g_last_result); +// g_last_result = NULL; +// } +// } else if (g_last_result != NULL) { +// g_last_result = realloc(new_size); +// if (g_last_result == NULL) { +// fprintf(stderr, "BFUZZ Fatal: memory allocation failed."); +// abort(); +// } +// } else { +// g_last_result = malloc(new_size); +// if (g_last_result == NULL) { +// fprintf(stderr, "BFUZZ Fatal: memory allocation failed."); +// abort(); +// } +// } +// g_last_result_size = new_size; +//} + +/** + * Just some safety checking. + * + * Should be NULL if bfuzz_jni_load_result was appropriately called after a + * successful result. + */ +void last_result_should_be_null() { + if (g_last_result != NULL) { + fprintf(stderr, + "BFUZZ warning: Need to call bfuzz_jni_load_result after every " + "successful call to bfuzz_jni_run! Likely bug in fuzzer.\n"); + (*g_env)->DeleteGlobalRef(g_env, g_last_result); + g_last_result = NULL; + } +} + +/** + * Initialize Java vm and target for fuzzing. + * + * \warning Should only be called once for the lifetime of the process. + * + * \param[in] fuzz_class_name The name Java class containing the fuzzing target + * to exercise. \param[in] fuzz_method_name The name of the fuzzing target to + * exercise. \param[in] class_path Java Classpath containing user defined + * classes and packages. Colon delimited in Unix. \param[in] bls_disabled + * Whether to disable bls verification. \see + * https://en.wikipedia.org/wiki/Classpath + */ +void bfuzz_jni_init(char const *fuzz_class_name, char const *fuzz_method_name, + char const *class_path, bool bls_disabled) { + // TODO(gnattishness) more docs on what the expected Java interface looks + // like? i.e. Java take in some byte array and returns an optional byte array + JavaVMInitArgs vm_args; + size_t len = strlen(class_path); + char const *prefix = "-Djava.class.path="; + size_t prefix_len = strlen(prefix); + // can be big so use a heap variable + char *class_path_option = malloc(prefix_len + len + 1); + if (class_path_option == NULL) { + fprintf(stderr, "BFUZZ Fatal: Failed to allocate class_path_option memory"); + abort(); + } + strncpy(class_path_option, prefix, prefix_len + 1); + // TODO(gnattishness) best practice to add a null at the end here? it should + // never overflow anyway + strncat(class_path_option, class_path, len); + + JavaVMOption options[1]; + options[0].optionString = class_path_option; + // options[1].optionString = (char*)"-verbose:jni"; + + // TODO(gnattishness) abort and exit hooks if it doesn't immediately abort + // already? + // https://docs.oracle.com/en/java/javase/11/docs/specs/jni/invocation.html#jni_createjavavm + // TODO(gnattishness) what version should I use? + vm_args.version = JNI_VERSION_10; + vm_args.nOptions = 1; + vm_args.options = options; + vm_args.ignoreUnrecognized = false; + jint err = JNI_CreateJavaVM(&g_jvm, (void **)&g_env, &vm_args); + free(class_path_option); + if (err != JNI_OK) { + fprintf(stderr, + "BFUZZ Fatal: JNI_CreateJavaVM() initialization failed: %" PRId32 + "\n", + (int32_t)err); + abort(); + } + + g_fuzz_class = (*g_env)->FindClass(g_env, fuzz_class_name); + if (g_fuzz_class == NULL) { + fprintf(stderr, "BFUZZ Fatal: Unable to load %s class definition\n", + fuzz_class_name); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + jmethodID fuzzCtor = + (*g_env)->GetMethodID(g_env, g_fuzz_class, "", "(ZZ)V"); + if (fuzzCtor == NULL) { + fprintf(stderr, "BFUZZ Fatal: Unable to locate fuzz class constructor\n"); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + // bool params correspond to useMainnetConfig, disable_bls flags + g_fuzz_instance = (*g_env)->NewObject(g_env, g_fuzz_class, fuzzCtor, JNI_TRUE, + bls_disabled); + if (g_fuzz_instance == NULL) { + fprintf(stderr, "BFUZZ Fatal: Unable to construct fuzz class instance.\n"); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + g_fuzz_method = (*g_env)->GetMethodID(g_env, g_fuzz_class, fuzz_method_name, + "([B)Ljava/util/Optional;"); + if (g_fuzz_method == NULL) { + fprintf(stderr, "BFUZZ Fatal: Unable to find method: %s.\n", + fuzz_method_name); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + // we keep a reference to this so subsequent methodIds remain valid + // see + // https://docs.oracle.com/en/java/javase/11/docs/specs/jni/design.html#accessing-fields-and-methods + g_optional_class = (*g_env)->FindClass(g_env, "java/util/Optional"); + if (g_optional_class == NULL) { + fprintf(stderr, "BFUZZ Fatal: Unable to locate \"Optional\" class\n"); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + g_optional_is_present = + (*g_env)->GetMethodID(g_env, g_optional_class, "isPresent", "()Z"); + if (g_optional_is_present == NULL) { + fprintf(stderr, + "BFUZZ Fatal: Unable to locate Optional.isPresent() method\n"); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + // NOTE: for the types here, get should return a jbyteArray "()[B", but this + // is not enforced at runtime + g_optional_get = (*g_env)->GetMethodID(g_env, g_optional_class, "get", + "()Ljava/lang/Object;"); + if (g_optional_get == NULL) { + fprintf(stderr, "BFUZZ Fatal: Unable to locate Optional.get() method\n"); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + + g_last_result = + NULL; // It should probably be this anyway, but double checking. + g_last_result_size = -1; + // TODO(gnattishness) detach? +} + +/** + * Run the registered Java fuzzing target with some input. + * + * \param[in] data The memory area to pass to the fuzzing target. + * \param[in] size The number of bytes to pass. + * \return The number of bytes in the target's output, or -1 if an (expected) + * error occurred + * + * \note + * max java array size is contained within an int32, so fine to use an int32_t + * as the return type + * https://stackoverflow.com/questions/3038392/do-java-arrays-have-a-maximum-size + * Also GetArrayLength returns a jint, which is an int32 + * https://docs.oracle.com/en/java/javase/11/docs/specs/jni/functions.html#getarraylength + * https://docs.oracle.com/en/java/javase/11/docs/specs/jni/types.html#primitive-types + * + */ +// TODO(gnattishness) should data be const? +int32_t bfuzz_jni_run(uint8_t const *data, size_t size) { + last_result_should_be_null(); + + if (size > INT32_MAX) { + // this makes it ok to call NewByteArray without worrying about it + // truncating the size value. + fprintf(stderr, + "BFUZZ Fatal: input size %zu too large for Java Array (must be " + "within int32)\n", + size); + abort(); + } + + // TODO(gnattishness) in 2 steps to find the exact size? + // Does rust want to provide the return destination? + // or do we make it free the result? + // Just do the same as for Prysm for now + // + // TODO(gnattishness) think about how many times these are copied + // TODO(gnattishness) use primitivearraycritical to reduce copying? + + jbyteArray input = (*g_env)->NewByteArray(g_env, size); + if (input == NULL) { + fprintf(stderr, "BFUZZ Fatal: Unable to create input jarray.\n"); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + + (*g_env)->SetByteArrayRegion(g_env, input, 0, size, (const jbyte *)data); + + // NOTE: type checking is not performed here + jobject maybe_result = + (*g_env)->CallObjectMethod(g_env, g_fuzz_instance, g_fuzz_method, input); + if ((*g_env)->ExceptionCheck(g_env) == JNI_TRUE) { + fprintf(stderr, "Uncaught Java exception while calling target:\n"); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + (*g_env)->DeleteLocalRef(g_env, input); // no longer need this + + if ((*g_env)->CallBooleanMethod(g_env, maybe_result, g_optional_is_present) == + JNI_TRUE) { + // bytes were returned + jbyteArray result = (jbyteArray)(*g_env)->CallObjectMethod( + g_env, maybe_result, g_optional_get); + if (result == NULL) { + fprintf(stderr, "BFUZZ Fatal: Java result array unexpectedly NULL.\n"); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + jsize result_size = (*g_env)->GetArrayLength(g_env, result); + if ((*g_env)->ExceptionCheck(g_env) == JNI_TRUE) { + // NOTE: better practice to check for pending exceptions after each + // call, as later calls may have undefined behavior, but we are ok to + // abort if any exception occurs in the above + fprintf(stderr, + "BFUZZ Fatal: Unexpected exception extracting Java result.\n"); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + + if (result_size == 0) { + // don't worry about the result if it's a 0 length array + (*g_env)->DeleteLocalRef(g_env, result); + } else { + g_last_result = (*g_env)->NewGlobalRef(g_env, result); + if (g_last_result == NULL) { + fprintf(stderr, "BFUZZ Fatal: System probably out of memory.\n"); + abort(); + } + } + g_last_result_size = result_size; + } else { + // optional result is empty, indicating an error during processing + g_last_result_size = -1; + } + + // docs e.g. + // https://docs.oracle.com/en/java/javase/11/docs/specs/jni/design.html#referencing-java-objects + // refer to the case where java is calling a native method that eventually + // returns not the other way around - can a local ref used within a c++ + // method be freed during any subsequent JNI method that is not + // `NewGlobalRef`? + // + // or are local references never automatically freed because this doesn't + // "return" to Java according to this: + // https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/com.ibm.java.vm.80.doc/docs/jni_refs.html + // we would need to detach from the JVM in order for automatic garbage + // collection to occur as this is single threaded, we never perform garbage + // collection unless we detach or manually Can methods create local + // references internally that can then explode? + // + // could detach and attach the jvm each time, but a fair bit of overhead? + // And how would gc occur without an active Java thread? a daemon-thread? + // TODO(gnattishness) if internal code creates local references that are + // never gc'd we'd need to detach + // + // TODO(gnattishness) delete local references + // shouldn't need to worry about threads and attaching the vm, + // as libfuzzer is single-threaded + // + // don't have to worry about cleaning up if we abort. + (*g_env)->DeleteLocalRef(g_env, maybe_result); + + // TODO(gnattishness) detach? + return g_last_result_size; +} + +/** + * Copy last successful fuzzing result into dest. + * + * \param[out] dest the memory region in which to store the result + * \param[in] size the maximum number of bytes to copy to dest + * + * \warning Should only be called at most once per call to bfuzz_jni_run + * + * Should be called if the last call to bfuzz_jni_run returned successfully + * + * may or may not deallocate the result after copying, so don't call it twice! + * size is not a necessary parameter, but is used to protect against accidental + * buffer overflows. will abort if size is not as expected + */ +void bfuzz_jni_load_result(uint8_t *dest, size_t size) { + if (g_last_result_size == -1) { + // Either called this twice in a row, or trying to get a result when an + // error was returned + fprintf(stderr, + "BFUZZ Fatal: trying to load a result when none was last returned. " + "Bug in fuzzing!\n"); + abort(); + } + if ((ptrdiff_t)size != (ptrdiff_t)g_last_result_size) { + fprintf(stderr, + "BFUZZ Fatal: trying to load result with wrong size. Bug in " + "fuzzing!\n"); + abort(); + } + if (g_last_result_size == 0) { + // TODO(gnattishness) implement - what to do it last_result_size is 0? + // complain or zero out, or noop? + fprintf(stderr, + "Need to figure out what to do for empty but valid results\n"); + abort(); + } + (*g_env)->GetByteArrayRegion(g_env, g_last_result, 0, size, (jbyte *)(dest)); + if ((*g_env)->ExceptionCheck(g_env) == JNI_TRUE) { + fprintf(stderr, + "BFUZZ Fatal: Unexpected exception extracting Java result.\n"); + (*g_env)->ExceptionDescribe(g_env); + abort(); + } + // free g_last_result and uninitialize it + (*g_env)->DeleteGlobalRef(g_env, g_last_result); + g_last_result = NULL; + g_last_result_size = -1; + + // TODO(gnattishness) detach? +} + +// TODO(gnattishness) destroy VM? diff --git a/beaconfuzz_v2/libs/bfuzz-jni/src/bfuzzjni.h b/beaconfuzz_v2/libs/bfuzz-jni/src/bfuzzjni.h new file mode 100644 index 0000000..3463d1c --- /dev/null +++ b/beaconfuzz_v2/libs/bfuzz-jni/src/bfuzzjni.h @@ -0,0 +1,58 @@ +#ifndef BEACONFUZZ_V2_LIBS_BFUZZ_JNI_SRC_BFUZZJNI_H_ +#define BEACONFUZZ_V2_LIBS_BFUZZ_JNI_SRC_BFUZZJNI_H_ + +#include +#include +#include + +/** + * Initialize Java vm and target for fuzzing. + * + * \warning Should only be called once for the lifetime of the process. + * + * \param[in] fuzz_class_name The name Java class containing the fuzzing target + * to exercise. \param[in] fuzz_method_name The name of the fuzzing target to + * exercise. \param[in] class_path Java Classpath containing user defined + * classes and packages. Colon delimited in Unix. \param[in] bls_disabled + * Whether to disable bls verification. \see + * https://en.wikipedia.org/wiki/Classpath + */ +void bfuzz_jni_init(char const *fuzz_class_name, char const *fuzz_method_name, + char const *class_path, bool bls_disabled); + +/** + * Run the registered Java fuzzing target with some input. + * + * \param[in] data The memory area to pass to the fuzzing target. + * \param[in] size The number of bytes to pass. + * \return The number of bytes in the target's output, or -1 if an (expected) + * error occurred + * + * \note + * max java array size is contained within an int32, so fine to use an int32_t + * as the return type + * https://stackoverflow.com/questions/3038392/do-java-arrays-have-a-maximum-size + * Also GetArrayLength returns a jint, which is an int32 + * https://docs.oracle.com/en/java/javase/11/docs/specs/jni/functions.html#getarraylength + * https://docs.oracle.com/en/java/javase/11/docs/specs/jni/types.html#primitive-types + * + */ +int32_t bfuzz_jni_run(uint8_t const *data, size_t size); + +/** + * Copy last successful fuzzing result into dest. + * + * \param[out] dest the memory region in which to store the result + * \param[in] size the maximum number of bytes to copy to dest + * + * \warning Should only be called at most once per call to bfuzz_jni_run + * + * Should be called if the last call to bfuzz_jni_run returned successfully + * + * may or may not deallocate the result after copying, so don't call it twice! + * size is not a necessary parameter, but is used to protect against accidental + * buffer overflows. will abort if size is not as expected + */ +void bfuzz_jni_load_result(uint8_t *dest, size_t size); + +#endif // BEACONFUZZ_V2_LIBS_BFUZZ_JNI_SRC_BFUZZJNI_H_ diff --git a/beaconfuzz_v2/libs/bfuzz-jni/src/dummy.c b/beaconfuzz_v2/libs/bfuzz-jni/src/dummy.c new file mode 100644 index 0000000..b198ce8 --- /dev/null +++ b/beaconfuzz_v2/libs/bfuzz-jni/src/dummy.c @@ -0,0 +1,19 @@ +#include + +#include "bfuzzjni.h" + +int main() { + bfuzz_jni_init("DummyFuzzUtil", "fuzzAttestation", ".", 1); + uint8_t data[50] = {1, 2, 3, 4, 5}; + int out = bfuzz_jni_run(data, 50); + printf("In C Result val=%d\n", out); + if (out > 0) { + uint8_t result[out]; + bfuzz_jni_load_result(result, out); + printf("Result content: "); + for (int i = 0; i < 50; i++) { + printf("%d ", result[i]); + } + printf("\n"); + } +} diff --git a/beaconfuzz_v2/libs/bfuzz-jni/src/lib.rs b/beaconfuzz_v2/libs/bfuzz-jni/src/lib.rs new file mode 100644 index 0000000..37fc988 --- /dev/null +++ b/beaconfuzz_v2/libs/bfuzz-jni/src/lib.rs @@ -0,0 +1,23 @@ +use std::env; + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +// TODO do we want any more wrapped bindings here, so the unsafe stuff is done here? + +#[cfg(test)] +mod tests { + use super::*; + // TODO(gnattishness) relevant tests + + //#[test] + //fn call_it() { + // unsafe { + // hello(); + // } + //} + + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/beaconfuzz_v2/libs/eth2clientsfuzz/Cargo.toml b/beaconfuzz_v2/libs/eth2clientsfuzz/Cargo.toml index d423823..47cab80 100644 --- a/beaconfuzz_v2/libs/eth2clientsfuzz/Cargo.toml +++ b/beaconfuzz_v2/libs/eth2clientsfuzz/Cargo.toml @@ -8,10 +8,11 @@ edition = "2018" [dependencies] nimbus = { path = "../nimbus" } +teku = { path = "../teku" } prysm = { path = "../prysm" } lighthouse = { path = "../lighthouse" } eth2_ssz = { path = "../../../../lighthouse/consensus/ssz/" } eth2_ssz_derive = { path = "../../../../lighthouse/consensus/ssz_derive/" } state_processing = { path = "../../../../lighthouse/consensus/state_processing/", features = ["arbitrary-fuzz"]} types = { path = "../../../../lighthouse/consensus/types", features = ["arbitrary-fuzz"]} -arbitrary = { version = "0.4.6", features = ["derive"] } \ No newline at end of file +arbitrary = { version = "0.4.6", features = ["derive"] } diff --git a/beaconfuzz_v2/libs/eth2clientsfuzz/src/attestation.rs b/beaconfuzz_v2/libs/eth2clientsfuzz/src/attestation.rs index 87b20ca..56c92e1 100644 --- a/beaconfuzz_v2/libs/eth2clientsfuzz/src/attestation.rs +++ b/beaconfuzz_v2/libs/eth2clientsfuzz/src/attestation.rs @@ -53,6 +53,7 @@ pub fn run_attestation(beacon_blob: &[u8], data: &[u8], debug: bool) { if debug { println!("[LIGHTHOUSE] Processing {}", true); } + //TODO avoid serializing post 3 times // call prysm let res = prysm::process_attestation(&beacon_blob, &data, &post.as_ssz_bytes()); @@ -71,6 +72,15 @@ pub fn run_attestation(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, true); } + + // call teku + let res = teku::process_attestation(&state.clone(), &att, &post.as_ssz_bytes()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, true); + } } else { if debug { println!("[LIGHTHOUSE] Processing {}", false); @@ -93,6 +103,15 @@ pub fn run_attestation(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, false); } + + // Verify that teku gives same result as lighthouse + let res = teku::process_attestation(&state.clone(), &att, &beacon_blob.clone()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, false); + } } // Data is an invalid SSZ container diff --git a/beaconfuzz_v2/libs/eth2clientsfuzz/src/attester_slashing.rs b/beaconfuzz_v2/libs/eth2clientsfuzz/src/attester_slashing.rs index 65eead4..2fd4944 100644 --- a/beaconfuzz_v2/libs/eth2clientsfuzz/src/attester_slashing.rs +++ b/beaconfuzz_v2/libs/eth2clientsfuzz/src/attester_slashing.rs @@ -38,6 +38,15 @@ pub fn run_attester_slashing(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, true); } + + // call teku + let res = teku::process_attester_slashing(&state.clone(), &att, &post.as_ssz_bytes()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, true); + } } else { if debug { println!("[LIGHTHOUSE] Processing {}", false); @@ -60,6 +69,15 @@ pub fn run_attester_slashing(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, false); } + + // Verify that teku gives same result as lighthouse + let res = teku::process_attester_slashing(&state.clone(), &att, &beacon_blob.clone()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, false); + } } // Data is an invalid SSZ container diff --git a/beaconfuzz_v2/libs/eth2clientsfuzz/src/block.rs b/beaconfuzz_v2/libs/eth2clientsfuzz/src/block.rs index bfcd625..4c1278b 100644 --- a/beaconfuzz_v2/libs/eth2clientsfuzz/src/block.rs +++ b/beaconfuzz_v2/libs/eth2clientsfuzz/src/block.rs @@ -38,6 +38,15 @@ pub fn run_block(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, true); } + + // call teku + let res = teku::process_block(&state.clone(), &att, &post.as_ssz_bytes()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, true); + } } else { if debug { println!("[LIGHTHOUSE] Processing {}", false); @@ -60,6 +69,15 @@ pub fn run_block(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, false); } + + // Verify that teku gives same result as lighthouse + let res = teku::process_block(&state.clone(), &att, &beacon_blob.clone()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, false); + } } // Data is an invalid SSZ container diff --git a/beaconfuzz_v2/libs/eth2clientsfuzz/src/block_header.rs b/beaconfuzz_v2/libs/eth2clientsfuzz/src/block_header.rs index afeb5ac..de6c9bf 100644 --- a/beaconfuzz_v2/libs/eth2clientsfuzz/src/block_header.rs +++ b/beaconfuzz_v2/libs/eth2clientsfuzz/src/block_header.rs @@ -38,6 +38,15 @@ pub fn run_block_header(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, true); } + + // call teku + let res = teku::process_block_header(&state.clone(), &att, &post.as_ssz_bytes()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, true); + } } else { if debug { println!("[LIGHTHOUSE] Processing {}", false); @@ -60,6 +69,15 @@ pub fn run_block_header(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, false); } + + // Verify that teku gives same result as lighthouse + let res = teku::process_block_header(&state.clone(), &att, &beacon_blob.clone()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, false); + } } // Data is an invalid SSZ container diff --git a/beaconfuzz_v2/libs/eth2clientsfuzz/src/deposit.rs b/beaconfuzz_v2/libs/eth2clientsfuzz/src/deposit.rs index a083d7f..f0fb847 100644 --- a/beaconfuzz_v2/libs/eth2clientsfuzz/src/deposit.rs +++ b/beaconfuzz_v2/libs/eth2clientsfuzz/src/deposit.rs @@ -38,6 +38,15 @@ pub fn run_deposit(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, true); } + + // call teku + let res = teku::process_deposit(&state.clone(), &att, &post.as_ssz_bytes()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, true); + } } else { if debug { println!("[LIGHTHOUSE] Processing {}", false); @@ -60,6 +69,15 @@ pub fn run_deposit(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, false); } + + // Verify that teku gives same result as lighthouse + let res = teku::process_deposit(&state.clone(), &att, &beacon_blob.clone()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, false); + } } // Data is an invalid SSZ container diff --git a/beaconfuzz_v2/libs/eth2clientsfuzz/src/lib.rs b/beaconfuzz_v2/libs/eth2clientsfuzz/src/lib.rs index 0e25575..a73d995 100644 --- a/beaconfuzz_v2/libs/eth2clientsfuzz/src/lib.rs +++ b/beaconfuzz_v2/libs/eth2clientsfuzz/src/lib.rs @@ -7,6 +7,7 @@ pub mod proposer_slashing; pub mod voluntary_exit; // Initialize eth2clients +// NOTE: teku needs to be initialized separately pub fn initialize_clients(disable_bls: bool) { prysm::init_prysm(disable_bls); nimbus::init_nimbus(disable_bls); @@ -17,6 +18,7 @@ pub fn debug_clients(activate_debug_mode: bool) { prysm::debug_mode_prysm(activate_debug_mode); nimbus::debug_mode_nimbus(activate_debug_mode); lighthouse::debug_mode_lighthouse(activate_debug_mode); + teku::debug_mode_teku(activate_debug_mode); } // TODO - testing diff --git a/beaconfuzz_v2/libs/eth2clientsfuzz/src/proposer_slashing.rs b/beaconfuzz_v2/libs/eth2clientsfuzz/src/proposer_slashing.rs index c3fa063..4f85ffc 100644 --- a/beaconfuzz_v2/libs/eth2clientsfuzz/src/proposer_slashing.rs +++ b/beaconfuzz_v2/libs/eth2clientsfuzz/src/proposer_slashing.rs @@ -38,6 +38,15 @@ pub fn run_proposer_slashing(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, true); } + + // call teku + let res = teku::process_proposer_slashing(&state.clone(), &att, &post.as_ssz_bytes()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, true); + } } else { if debug { println!("[LIGHTHOUSE] Processing {}", false); @@ -60,6 +69,15 @@ pub fn run_proposer_slashing(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, false); } + + // Verify that teku gives same result as lighthouse + let res = teku::process_proposer_slashing(&state.clone(), &att, &beacon_blob.clone()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, false); + } } // Data is an invalid SSZ container diff --git a/beaconfuzz_v2/libs/eth2clientsfuzz/src/voluntary_exit.rs b/beaconfuzz_v2/libs/eth2clientsfuzz/src/voluntary_exit.rs index 1b3095c..e47bf72 100644 --- a/beaconfuzz_v2/libs/eth2clientsfuzz/src/voluntary_exit.rs +++ b/beaconfuzz_v2/libs/eth2clientsfuzz/src/voluntary_exit.rs @@ -38,6 +38,15 @@ pub fn run_voluntary_exit(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, true); } + + // call teku + let res = teku::process_voluntary_exit(&state.clone(), &att, &post.as_ssz_bytes()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, true); + } } else { if debug { println!("[LIGHTHOUSE] Processing {}", false); @@ -60,6 +69,15 @@ pub fn run_voluntary_exit(beacon_blob: &[u8], data: &[u8], debug: bool) { } else { assert_eq!(res, false); } + + // Verify that teku gives same result as lighthouse + let res = teku::process_voluntary_exit(&state.clone(), &att, &beacon_blob.clone()); + + if debug { + println!("[TEKU] Processing {}", res); + } else { + assert_eq!(res, false); + } } // Data is an invalid SSZ container diff --git a/beaconfuzz_v2/libs/nimbus/build.rs b/beaconfuzz_v2/libs/nimbus/build.rs index 24cca9b..803dc95 100644 --- a/beaconfuzz_v2/libs/nimbus/build.rs +++ b/beaconfuzz_v2/libs/nimbus/build.rs @@ -4,6 +4,16 @@ fn main() { let nimbus_dir = env::var("CARGO_NIMBUS_DIR").expect("NIMBUS build: CARGO_NIMBUS_DIR not defined"); + println!("cargo:rerun-if-env-changed=CARGO_NIMBUS_DIR"); + println!("cargo:rerun-if-changed={}/build/libnfuzz.a", nimbus_dir); + println!( + "cargo:rustc-link-search=native={}/vendor/nim-libbacktrace/install/usr/lib/libbacktrace.a", + nimbus_dir + ); + println!( + "cargo:rustc-link-search=native={}/vendor/nim-libbacktrace/install/usr/lib/libbacktracenim.a", + nimbus_dir + ); println!("cargo:rustc-link-search=native={}/build/", nimbus_dir); println!("cargo:rustc-link-lib=static=nfuzz"); println!( diff --git a/beaconfuzz_v2/libs/prysm/build.rs b/beaconfuzz_v2/libs/prysm/build.rs index e0ea796..ec837df 100644 --- a/beaconfuzz_v2/libs/prysm/build.rs +++ b/beaconfuzz_v2/libs/prysm/build.rs @@ -6,11 +6,20 @@ fn main() { // go build -o libpfuzz.a -buildmode=c-archive pfuzz.go // Prysm deps + println!("cargo:rerun-if-env-changed=CARGO_PRYSM_DIR"); + println!( + "cargo:rustc-link-search=native={}/pfuzz/libpfuzz.a", + prysm_dir + ); + println!( + "cargo:rustc-link-search=native={}/pfuzz/libbls384_256.a", + prysm_dir + ); + println!("cargo:rustc-link-search=native={}/pfuzz", prysm_dir); println!("cargo:rustc-link-lib=static=pfuzz"); // deps patrick local //println!("cargo:rustc-link-search=native={}/src/github.com/herumi/bls-eth-go-binary/bls/lib/linux/amd64", prysm_dir); - println!("cargo:rustc-link-search=native={}/pfuzz", prysm_dir); println!("cargo:rustc-link-lib=static=bls384_256"); println!("cargo:rustc-link-lib=dylib=stdc++"); } diff --git a/beaconfuzz_v2/libs/teku/Cargo.toml b/beaconfuzz_v2/libs/teku/Cargo.toml new file mode 100644 index 0000000..739d91d --- /dev/null +++ b/beaconfuzz_v2/libs/teku/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "teku" +version = "0.1.0" +authors = ["Nathaniel Jensen "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bfuzz-jni = { path = "../bfuzz-jni" } +eth2_ssz = { path = "../../../../lighthouse/consensus/ssz/" } +eth2_ssz_derive = { path = "../../../../lighthouse/consensus/ssz_derive/" } +types = { path = "../../../../lighthouse/consensus/types" } diff --git a/beaconfuzz_v2/libs/teku/src/attestation.rs b/beaconfuzz_v2/libs/teku/src/attestation.rs new file mode 100644 index 0000000..76ca9d4 --- /dev/null +++ b/beaconfuzz_v2/libs/teku/src/attestation.rs @@ -0,0 +1,29 @@ +use ssz::Encode; //Decode +use ssz_derive::{Decode, Encode}; + +use types::{Attestation, BeaconState, MainnetEthSpec}; + +// TODO move to common types/util crate? +#[derive(Decode, Encode)] +struct AttestationTestCase { + pre: BeaconState, + attestation: Attestation, +} + +use crate::util::run_target; + +pub fn process_attestation( + beacon: &BeaconState, + attest: &Attestation, + post: &[u8], + debug: bool, +) -> bool { + // create testcase ssz struct + let target: AttestationTestCase = AttestationTestCase { + pre: beacon.clone(), + attestation: attest.clone(), + }; + + let input_ssz = target.as_ssz_bytes(); + run_target(input_ssz.as_slice(), post, debug) +} diff --git a/beaconfuzz_v2/libs/teku/src/attester_slashing.rs b/beaconfuzz_v2/libs/teku/src/attester_slashing.rs new file mode 100644 index 0000000..1ece8a4 --- /dev/null +++ b/beaconfuzz_v2/libs/teku/src/attester_slashing.rs @@ -0,0 +1,28 @@ +use ssz::Encode; //Decode +use ssz_derive::{Decode, Encode}; + +use crate::util::run_target; +use types::{AttesterSlashing, BeaconState, MainnetEthSpec}; + +// TODO move to common types/util crate? +#[derive(Decode, Encode)] +struct AttesterSlashingTestCase { + pub pre: BeaconState, + pub attester_slashing: AttesterSlashing, +} + +pub fn process_attester_slashing( + beacon: &BeaconState, + attester_slashing: &AttesterSlashing, + post: &[u8], + debug: bool, +) -> bool { + // create testcase ssz struct + let target: AttesterSlashingTestCase = AttesterSlashingTestCase { + pre: beacon.clone(), + attester_slashing: attester_slashing.clone(), + }; + + let input_ssz = target.as_ssz_bytes(); + run_target(input_ssz.as_slice(), post, debug) +} diff --git a/beaconfuzz_v2/libs/teku/src/block.rs b/beaconfuzz_v2/libs/teku/src/block.rs new file mode 100644 index 0000000..9ffa50b --- /dev/null +++ b/beaconfuzz_v2/libs/teku/src/block.rs @@ -0,0 +1,27 @@ +use ssz::Encode; //Decode +use ssz_derive::{Decode, Encode}; + +use crate::util::run_target; +use types::{BeaconState, MainnetEthSpec, SignedBeaconBlock}; + +#[derive(Decode, Encode)] +struct BlockTestCase { + pub pre: BeaconState, + pub beacon_block: SignedBeaconBlock, +} + +pub fn process_block( + beacon: &BeaconState, + beacon_block: &SignedBeaconBlock, + post: &[u8], + debug: bool, +) -> bool { + // create testcase ssz struct + let target: BlockTestCase = BlockTestCase { + pre: beacon.clone(), + beacon_block: beacon_block.clone(), + }; + + let input_ssz = target.as_ssz_bytes(); + run_target(input_ssz.as_slice(), post, debug) +} diff --git a/beaconfuzz_v2/libs/teku/src/block_header.rs b/beaconfuzz_v2/libs/teku/src/block_header.rs new file mode 100644 index 0000000..8ae7d1a --- /dev/null +++ b/beaconfuzz_v2/libs/teku/src/block_header.rs @@ -0,0 +1,32 @@ +use ssz::Encode; //Decode +use ssz_derive::{Decode, Encode}; + +use crate::util::run_target; +use types::{BeaconBlock, BeaconState, MainnetEthSpec, Signature, SignedBeaconBlock}; + +#[derive(Decode, Encode)] +struct BlockHeaderTestCase { + pub pre: BeaconState, + pub beacon_block: SignedBeaconBlock, +} + +// TODO modify to take a SignedBeaconBlock instead? +pub fn process_block_header( + beacon: &BeaconState, + beacon_block: &BeaconBlock, + post: &[u8], + debug: bool, +) -> bool { + // create testcase ssz struct + // we need to wrap BeaconBlock into a SignedBeaconBlock + let target: BlockHeaderTestCase = BlockHeaderTestCase { + pre: beacon.clone(), + beacon_block: SignedBeaconBlock { + message: beacon_block.clone(), + signature: Signature::empty(), + }, + }; + + let input_ssz = target.as_ssz_bytes(); + run_target(input_ssz.as_slice(), post, debug) +} diff --git a/beaconfuzz_v2/libs/teku/src/debug.rs b/beaconfuzz_v2/libs/teku/src/debug.rs new file mode 100644 index 0000000..fa1785d --- /dev/null +++ b/beaconfuzz_v2/libs/teku/src/debug.rs @@ -0,0 +1,22 @@ +use std::fs::File; +use std::io::Write; + +const PREFIX: &str = "teku"; + +pub fn dump_post_state(post: &[u8], out: &[u8]) { + // Create dump file for lighthouse post + // in case lighthouse return an error, this file will be the pre-state + let mut file_post = + File::create(&format!("{}_debug_post.ssz", PREFIX)).expect("Cannot open debug_post file"); + + // write the content + file_post + .write(&post) + .expect("Cannot write debug_post file"); + + // Create dump file for other client post + let mut file_out = + File::create(&format!("{}_debug_out.ssz", PREFIX)).expect("Cannot open debug_out file"); + // write the content + file_out.write(&out).expect("Cannot write debug_out file"); +} diff --git a/beaconfuzz_v2/libs/teku/src/deposit.rs b/beaconfuzz_v2/libs/teku/src/deposit.rs new file mode 100644 index 0000000..1a0c4b4 --- /dev/null +++ b/beaconfuzz_v2/libs/teku/src/deposit.rs @@ -0,0 +1,28 @@ +use ssz::Encode; //Decode +use ssz_derive::{Decode, Encode}; + +use crate::util::run_target; +use types::{BeaconState, Deposit, MainnetEthSpec}; + +// TODO move to common types/util crate? +#[derive(Decode, Encode)] +struct DepositTestCase { + pub pre: BeaconState, + pub deposit: Deposit, +} + +pub fn process_deposit( + beacon: &BeaconState, + deposit: &Deposit, + post: &[u8], + debug: bool, +) -> bool { + // create testcase ssz struct + let target: DepositTestCase = DepositTestCase { + pre: beacon.clone(), + deposit: deposit.clone(), + }; + + let input_ssz = target.as_ssz_bytes(); + run_target(input_ssz.as_slice(), post, debug) +} diff --git a/beaconfuzz_v2/libs/teku/src/lib.rs b/beaconfuzz_v2/libs/teku/src/lib.rs new file mode 100644 index 0000000..87f20ca --- /dev/null +++ b/beaconfuzz_v2/libs/teku/src/lib.rs @@ -0,0 +1,85 @@ +use types::{ + Attestation, AttesterSlashing, BeaconBlock, BeaconState, Deposit, MainnetEthSpec, + ProposerSlashing, SignedBeaconBlock, SignedVoluntaryExit, +}; + +pub mod attestation; +pub mod attester_slashing; +pub mod block; +pub mod block_header; +pub mod debug; +pub mod deposit; +pub mod proposer_slashing; +pub mod util; +pub mod voluntary_exit; + +static mut DEBUG: bool = false; + +pub fn debug_mode_teku(activate_debug_mode: bool) { + unsafe { + DEBUG = activate_debug_mode; + } +} + +pub use util::init_teku; +pub use util::FuzzTarget; + +pub fn process_attestation( + beacon: &BeaconState, + attest: &Attestation, + post: &[u8], +) -> bool { + self::attestation::process_attestation(beacon, attest, post, unsafe { DEBUG }) +} + +pub fn process_attester_slashing( + beacon: &BeaconState, + attester_slashing: &AttesterSlashing, + post: &[u8], +) -> bool { + self::attester_slashing::process_attester_slashing(beacon, attester_slashing, post, unsafe { + DEBUG + }) +} + +pub fn process_block( + beacon: &BeaconState, + beacon_block: &SignedBeaconBlock, + post: &[u8], +) -> bool { + self::block::process_block(beacon, beacon_block, post, unsafe { DEBUG }) +} + +pub fn process_block_header( + beacon: &BeaconState, + beacon_block: &BeaconBlock, + post: &[u8], +) -> bool { + self::block_header::process_block_header(beacon, beacon_block, post, unsafe { DEBUG }) +} + +pub fn process_deposit( + beacon: &BeaconState, + deposit: &Deposit, + post: &[u8], +) -> bool { + self::deposit::process_deposit(beacon, deposit, post, unsafe { DEBUG }) +} + +pub fn process_proposer_slashing( + beacon: &BeaconState, + proposer_slashing: &ProposerSlashing, + post: &[u8], +) -> bool { + self::proposer_slashing::process_proposer_slashing(beacon, proposer_slashing, post, unsafe { + DEBUG + }) +} + +pub fn process_voluntary_exit( + beacon: &BeaconState, + exit: &SignedVoluntaryExit, + post: &[u8], +) -> bool { + self::voluntary_exit::process_voluntary_exit(beacon, exit, post, unsafe { DEBUG }) +} diff --git a/beaconfuzz_v2/libs/teku/src/proposer_slashing.rs b/beaconfuzz_v2/libs/teku/src/proposer_slashing.rs new file mode 100644 index 0000000..fa28f96 --- /dev/null +++ b/beaconfuzz_v2/libs/teku/src/proposer_slashing.rs @@ -0,0 +1,27 @@ +use ssz::Encode; //Decode +use ssz_derive::{Decode, Encode}; + +use crate::util::run_target; +use types::{BeaconState, MainnetEthSpec, ProposerSlashing}; + +#[derive(Decode, Encode)] +struct ProposerSlashingTestCase { + pub pre: BeaconState, + pub proposer_slashing: ProposerSlashing, +} + +pub fn process_proposer_slashing( + beacon: &BeaconState, + proposer_slashing: &ProposerSlashing, + post: &[u8], + debug: bool, +) -> bool { + // create testcase ssz struct + let target: ProposerSlashingTestCase = ProposerSlashingTestCase { + pre: beacon.clone(), + proposer_slashing: proposer_slashing.clone(), + }; + + let input_ssz = target.as_ssz_bytes(); + run_target(input_ssz.as_slice(), post, debug) +} diff --git a/beaconfuzz_v2/libs/teku/src/util.rs b/beaconfuzz_v2/libs/teku/src/util.rs new file mode 100644 index 0000000..8957d96 --- /dev/null +++ b/beaconfuzz_v2/libs/teku/src/util.rs @@ -0,0 +1,206 @@ +use bfuzz_jni; +use std::convert::TryInto; +use std::env; +use std::ffi::CString; +use std::format; +use std::path::Path; +use std::path::PathBuf; +use std::process::Command; + +use crate::debug::dump_post_state; + +const FUZZ_CLASS: &str = "tech/pegasys/teku/fuzz/FuzzUtil"; + +// All supported teku fuzzing targets +pub enum FuzzTarget { + Attestation, + AttesterSlashing, + Block, + BlockHeader, + Deposit, + ProposerSlashing, + Shuffle, + VoluntaryExit, +} + +impl FuzzTarget { + fn to_method_name(&self) -> &str { + match self { + Self::Attestation => "fuzzAttestation", + Self::AttesterSlashing => "fuzzAttesterSlashing", + Self::Block => "fuzzBlock", + Self::BlockHeader => "fuzzBlockHeader", + Self::Deposit => "fuzzDeposit", + Self::ProposerSlashing => "fuzzProposerSlashing", + Self::Shuffle => "fuzzShuffle", + Self::VoluntaryExit => "fuzzVoluntaryExit", + } + } +} + +// Extracts suitable Java CLASS_PATH from teku shell script +// requires teku to have already been built and locally "installed" +fn extract_classpath>(teku_root: P) -> String { + let teku_root_p = teku_root.as_ref(); + let teku_script = teku_root_p.join("build/scripts/teku"); + if !teku_script.is_file() { + panic!( + "BeaconFuzz fatal: File does not exist: '{:?}'. Have you built teku?", + teku_script + ) + } + let teku_home = teku_root_p + .join("build/install/teku") + .canonicalize() + .unwrap(); + if !teku_home.is_dir() { + panic!( + "BeaconFuzz fatal: Directory does not exist '{:?}'. Have you built teku?", + teku_home + ) + } + // TODO replace with rust equivalent + // JAVA_CLASSPATH=$(grep -F CLASSPATH= "$TEKU_SCRIPT" | head -n 1 | cut -d= -f 2 | sed 's:\$APP_HOME:'"$TEKU_HOME"':g') + let output = Command::new("sh") + .arg("-c") + .arg(format!( + "grep -F CLASSPATH= \"{}\" | head -n 1 | cut -d= -f 2 | sed 's:\\$APP_HOME:'\"{}\"':g'", + teku_script.display(), + teku_home.display() + )) + .output() + .expect("BeaconFuzz failed to execute command to extract Teku CLASSPATH"); + if !output.status.success() { + panic!("BeaconFuzz fatal: Failed to extract Teku CLASSPATH() from script"); + } + let dist_classpath = String::from_utf8(output.stdout).unwrap(); + // TODO replace/fix workaround + // NOTE: this is hard-coding the fuzz output path so will break when new teku versions are + // released, also might have pain on Mac OS? + let teku_fuzz_jar = teku_root_p.join("fuzz/build/libs/teku-fuzz-0.12.9-SNAPSHOT.jar").canonicalize().expect("BeaconFuzz fatal: unable to locate teku fuzz class. Did you build with ./gradlew fuzz:build?"); + format!("{}:{}", dist_classpath, teku_fuzz_jar.display()) +} + +// TODO safety to ensure this is never called twice +pub fn init_teku(disable_bls: bool, target: FuzzTarget) { + let teku_root = PathBuf::from( + env::var("BFUZZ_TEKU_DIR").expect("BeaconFuzz config error: BFUZZ_TEKU_DIR not defined"), + ); + let class_path = CString::new(extract_classpath(teku_root)).expect("CString::new failed"); + let fuzz_class = CString::new(FUZZ_CLASS).expect("CString::new failed"); + let method_name = CString::new(target.to_method_name()).expect("CString::new failed"); + + unsafe { + bfuzz_jni::bfuzz_jni_init( + fuzz_class.as_ptr(), + method_name.as_ptr(), + class_path.as_ptr(), + disable_bls, + ); + } +} + +pub fn run_target(input: &[u8], lh_post: &[u8], debug: bool) -> bool { + // TODO make unsafe chunk smaller + // only needed around the 2 bfuzz_jni calls and the set_len + unsafe { + let ret = bfuzz_jni::bfuzz_jni_run(input.as_ptr(), input.len().try_into().unwrap()); + if debug { + println!("bfuzz_jni_run result val: {:?}", ret); + } + // If error triggered during processing, we return immediately + if ret < 0 { + return false; + } + + let mut result: Vec = Vec::with_capacity(ret.try_into().unwrap()); + let result_size: usize = ret.try_into().unwrap(); + // NOTE: the C code uses a size_t but bindgen uses a u64 instead of usize + // (though looks to be more accurate behaviour) + // https://github.com/rust-lang/rust-bindgen/issues/1671 + bfuzz_jni::bfuzz_jni_load_result(result.as_mut_ptr(), result_size.try_into().unwrap()); + result.set_len(result_size); + if debug { + println!("result content: {:?}", result); + } + if result.as_slice() != lh_post { + if debug { + println!("[TEKU] Mismatch post"); + } else { + // make fuzzer to crash + panic!("[TEKU] Mismatch post"); + } + } + + // dump post files for debugging + if debug { + dump_post_state(&lh_post, result.as_slice()); + } + } + + true +} + +/* +fn main() { + init_teku(true, FuzzTarget::Attestation); + // NOTE: this raises an exception because we expect to have received valid SSZ after initial + // pre-processing + let data: Vec = vec![0; 50]; + let post: Vec = vec![0; 50]; + run_target(data.as_slice(), post.as_slice(), true); +} +*/ + +// TODO(gnattishness) use for unit test +/*fn main() { + // dummy to try calling the java + let class_name = CString::new("DummyFuzzUtil").expect("CString::new failed"); + let method_name = CString::new("fuzzAttestation").expect("CString::new failed"); + // lol at this rust code + //let class_path = CString::new( + // env::current_dir() + // .unwrap() + // .canonicalize() + // .unwrap() + // .to_str() + // .unwrap(), + //) + //.expect("CString::new failed"); + let class_path = CString::new( + env::current_dir() + .unwrap() + .join("../bfuzz-jni/src") + .canonicalize() + .unwrap() + .to_str() + .unwrap(), + ) + .expect("CString::new failed"); + let bls_disabled = true; + let mut data: Vec = vec![0; 50]; + for i in 1..=5 { + data[i - 1] = i as u8; + } + // data is 1,2,3,4,5,0,0,0,0... + unsafe { + bfuzz_jni::bfuzz_jni_init( + class_name.as_ptr(), + method_name.as_ptr(), + class_path.as_ptr(), + bls_disabled, + ); + let ret = bfuzz_jni::bfuzz_jni_run(data.as_ptr(), data.len().try_into().unwrap()); + println!("bfuzz_jni_run result val: {:?}", ret); + if ret >= 0 { + let mut result: Vec = Vec::with_capacity(ret.try_into().unwrap()); + let result_size: usize = ret.try_into().unwrap(); + // NOTE: the C code uses a size_t but bindgen uses a u64 instead of usize + // (though looks to be more accurate behaviour) + // https://github.com/rust-lang/rust-bindgen/issues/1671 + bfuzz_jni::bfuzz_jni_load_result(result.as_mut_ptr(), result_size.try_into().unwrap()); + result.set_len(result_size); + println!("result content: {:?}", result); + } + } +}*/ diff --git a/beaconfuzz_v2/libs/teku/src/voluntary_exit.rs b/beaconfuzz_v2/libs/teku/src/voluntary_exit.rs new file mode 100644 index 0000000..4f29629 --- /dev/null +++ b/beaconfuzz_v2/libs/teku/src/voluntary_exit.rs @@ -0,0 +1,27 @@ +use ssz::Encode; //Decode +use ssz_derive::{Decode, Encode}; + +use crate::util::run_target; +use types::{BeaconState, MainnetEthSpec, SignedVoluntaryExit}; + +#[derive(Decode, Encode)] +struct VoluntaryExitTestCase { + pub pre: BeaconState, + pub exit: SignedVoluntaryExit, +} + +pub fn process_voluntary_exit( + beacon: &BeaconState, + exit: &SignedVoluntaryExit, + post: &[u8], + debug: bool, +) -> bool { + // create testcase ssz struct + let target: VoluntaryExitTestCase = VoluntaryExitTestCase { + pre: beacon.clone(), + exit: exit.clone(), + }; + + let input_ssz = target.as_ssz_bytes(); + run_target(input_ssz.as_slice(), post, debug) +} diff --git a/beaconfuzz_v2/src/bin/diff_attestation.rs b/beaconfuzz_v2/src/bin/diff_attestation.rs index 6501aac..7321874 100644 --- a/beaconfuzz_v2/src/bin/diff_attestation.rs +++ b/beaconfuzz_v2/src/bin/diff_attestation.rs @@ -25,6 +25,8 @@ extern crate rand; use rand::seq::SliceRandom; use rand::thread_rng; +use teku; + /// List file in folder and return list of files paths #[inline(always)] fn list_files_in_folder(path_str: &String) -> Result, ()> { @@ -130,6 +132,7 @@ fn main() { // Initialize eth2client environment eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::Attestation); // Run fuzzing loop loop { diff --git a/beaconfuzz_v2/src/bin/diff_attester_slashing.rs b/beaconfuzz_v2/src/bin/diff_attester_slashing.rs index ddf5668..4cad2e2 100644 --- a/beaconfuzz_v2/src/bin/diff_attester_slashing.rs +++ b/beaconfuzz_v2/src/bin/diff_attester_slashing.rs @@ -130,6 +130,7 @@ fn main() { // Initialize eth2client environment eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::AttesterSlashing); // Run fuzzing loop loop { diff --git a/beaconfuzz_v2/src/bin/diff_block.rs b/beaconfuzz_v2/src/bin/diff_block.rs index 847d3f8..a2575eb 100644 --- a/beaconfuzz_v2/src/bin/diff_block.rs +++ b/beaconfuzz_v2/src/bin/diff_block.rs @@ -130,6 +130,7 @@ fn main() { // Initialize eth2client environment eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::Block); // Run fuzzing loop loop { diff --git a/beaconfuzz_v2/src/bin/diff_block_header.rs b/beaconfuzz_v2/src/bin/diff_block_header.rs index 2aa8c44..877f726 100644 --- a/beaconfuzz_v2/src/bin/diff_block_header.rs +++ b/beaconfuzz_v2/src/bin/diff_block_header.rs @@ -130,6 +130,7 @@ fn main() { // Initialize eth2client environment eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::BlockHeader); // Run fuzzing loop loop { diff --git a/beaconfuzz_v2/src/bin/diff_deposit.rs b/beaconfuzz_v2/src/bin/diff_deposit.rs index aef0ebe..0d50f75 100644 --- a/beaconfuzz_v2/src/bin/diff_deposit.rs +++ b/beaconfuzz_v2/src/bin/diff_deposit.rs @@ -130,6 +130,7 @@ fn main() { // Initialize eth2client environment eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::Deposit); // Run fuzzing loop loop { diff --git a/beaconfuzz_v2/src/bin/diff_proposer_slashing.rs b/beaconfuzz_v2/src/bin/diff_proposer_slashing.rs index 3d413da..62a5f55 100644 --- a/beaconfuzz_v2/src/bin/diff_proposer_slashing.rs +++ b/beaconfuzz_v2/src/bin/diff_proposer_slashing.rs @@ -130,6 +130,7 @@ fn main() { // Initialize eth2client environment eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::ProposerSlashing); // Run fuzzing loop loop { diff --git a/beaconfuzz_v2/src/bin/diff_voluntary_exit.rs b/beaconfuzz_v2/src/bin/diff_voluntary_exit.rs index 3835982..1a5a9bb 100644 --- a/beaconfuzz_v2/src/bin/diff_voluntary_exit.rs +++ b/beaconfuzz_v2/src/bin/diff_voluntary_exit.rs @@ -130,6 +130,7 @@ fn main() { // Initialize eth2client environment eth2clientsfuzz::initialize_clients(true); + teku::init_teku(true, teku::FuzzTarget::VoluntaryExit); // Run fuzzing loop loop {