diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 98e97972a9..ad6ee7b0f4 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -81,3 +81,10 @@ jobs: - uses: actions/checkout@v1 - name: Lint code for quality and style with Clippy run: make lint + arbitrary-check: + runs-on: ubuntu-latest + needs: cargo-fmt + steps: + - uses: actions/checkout@v1 + - name: Validate state_processing feature arbitrary-fuzz + run: make arbitrary-fuzz diff --git a/Cargo.lock b/Cargo.lock index 16469bb6d2..4388ba6646 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,6 +109,15 @@ version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9a60d744a80c30fcb657dfe2c1b22bcb3e814c1a1e3674f32bf5820b570fbff" +[[package]] +name = "arbitrary" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5eb01a9ab8a3369f2f7632b9461c34f5920bd454774bab5b9fc6744f21d6143" +dependencies = [ + "derive_arbitrary", +] + [[package]] name = "arc-swap" version = "0.4.6" @@ -151,7 +160,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d0864d84b8e07b145449be9a8537db86bf9de5ce03b913214694643b4743502" dependencies = [ - "quote 1.0.3", + "quote 1.0.4", "syn 1.0.18", ] @@ -239,9 +248,9 @@ dependencies = [ [[package]] name = "backtrace-sys" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78848718ee1255a2485d1309ad9cdecfc2e7d0362dd11c6829364c6b35ae1bc7" +checksum = "18fbebbe1c9d1f383a9cc7e8ccdb471b91c8d024ee9c2ca5b5346121fe8b4399" dependencies = [ "cc", "libc", @@ -461,6 +470,7 @@ dependencies = [ name = "bls" version = "0.2.0" dependencies = [ + "arbitrary", "eth2_hashing", "eth2_ssz", "eth2_ssz_types", @@ -570,9 +580,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.52" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" +checksum = "8dae9c4b8fedcae85592ba623c4fd08cfdab3e3b72d6df780c6ead964a69bfff" [[package]] name = "cfg-if" @@ -1014,7 +1024,7 @@ name = "deposit_contract" version = "0.2.0" dependencies = [ "eth2_ssz", - "ethabi 11.0.0", + "ethabi", "reqwest 0.9.24", "serde_json", "tree_hash", @@ -1032,14 +1042,25 @@ dependencies = [ "syn 0.15.44", ] +[[package]] +name = "derive_arbitrary" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cee758ebd1c79a9c6fb95f242dcc30bdbf555c28369ae908d21fdaf81537496" +dependencies = [ + "proc-macro2 1.0.12", + "quote 1.0.4", + "syn 1.0.18", +] + [[package]] name = "derive_more" version = "0.99.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2323f3f47db9a0e77ce7a300605d8d2098597fc451ed1a97bb1f6411bb550a7" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", ] @@ -1382,6 +1403,7 @@ dependencies = [ name = "eth2_ssz_types" version = "0.2.0" dependencies = [ + "arbitrary", "eth2_ssz", "serde", "serde_derive", @@ -1407,24 +1429,9 @@ dependencies = [ [[package]] name = "ethabi" -version = "9.0.1" +version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "965126c64662832991f5a748893577630b558e47fa94e7f35aefcd20d737cef7" -dependencies = [ - "error-chain", - "ethereum-types", - "rustc-hex", - "serde", - "serde_derive", - "serde_json", - "tiny-keccak 1.5.0", -] - -[[package]] -name = "ethabi" -version = "11.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97652a7d1f2504d6c885c87e242a06ccef5bd3054093d3fb742d8fb64806231a" +checksum = "052a565e3de82944527d6d10a465697e6bb92476b772ca7141080c901f6a63c6" dependencies = [ "ethereum-types", "rustc-hex", @@ -1436,27 +1443,27 @@ dependencies = [ [[package]] name = "ethbloom" -version = "0.8.1" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32cfe1c169414b709cf28aa30c74060bdb830a03a8ba473314d079ac79d80a5f" +checksum = "befe713756981dbbda28e23f5c65c85de512915db695284342cc2ee36b7a184f" dependencies = [ "crunchy 0.2.2", "fixed-hash", "impl-rlp", - "impl-serde 0.2.3", - "tiny-keccak 1.5.0", + "impl-serde", + "tiny-keccak 2.0.2", ] [[package]] name = "ethereum-types" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba744248e3553a393143d5ebb68939fc3a4ec0c22a269682535f5ffe7fed728c" +checksum = "8616dc6a7bc7d81ab8a6425635299ee3582975d4ddeb9312b8b0b8ea54dfecf8" dependencies = [ "ethbloom", "fixed-hash", "impl-rlp", - "impl-serde 0.2.3", + "impl-serde", "primitive-types", "uint", ] @@ -1482,9 +1489,9 @@ dependencies = [ [[package]] name = "failure" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8529c2421efa3066a5cbd8063d2244603824daccb6936b079010bb2aa89464b" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" dependencies = [ "backtrace", "failure_derive", @@ -1492,12 +1499,12 @@ dependencies = [ [[package]] name = "failure_derive" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030a733c8287d6213886dd487564ff5c8f6aae10278b3588ed177f9d18f8d231" +checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", "synstructure", ] @@ -1510,10 +1517,11 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" [[package]] name = "fixed-hash" -version = "0.5.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3367952ceb191f4ab95dd5685dc163ac539e36202f9fcfd0cb22f9f9c542fefc" +checksum = "11498d382790b7a8f2fd211780bec78619bba81cdad3a283997c0c41f836759c" dependencies = [ + "arbitrary", "byteorder 1.3.4", "rand 0.7.3", "rustc-hex", @@ -1654,8 +1662,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", ] @@ -2103,18 +2111,9 @@ dependencies = [ [[package]] name = "impl-serde" -version = "0.2.3" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58e3cae7e99c7ff5a995da2cf78dd0a5383740eda71d98cf7b1910c301ac69b8" -dependencies = [ - "serde", -] - -[[package]] -name = "impl-serde" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bbe9ea9b182f0fb1cabbd61f4ff9b7b7b9197955e95a7e4c27de5055eb29ff8" +checksum = "b47ca4d2b6931707a55fce5cf66aff80e2178c8b63bbb4ecb5695cbc870ddf6f" dependencies = [ "serde", ] @@ -2184,9 +2183,9 @@ checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" [[package]] name = "js-sys" -version = "0.3.38" +version = "0.3.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b823ebafcee1632403f2782d28728aab353f7881547a700043ef455c078326f" +checksum = "fa5a448de267e7358beaf4a5d849518fe9a0c13fce7afd44b06e68550e5562a7" dependencies = [ "wasm-bindgen", ] @@ -2391,7 +2390,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "329127858e4728db5ab60c33d5ae352a999325fdf190ed022ec7d3a4685ae2e6" dependencies = [ - "quote 1.0.3", + "quote 1.0.4", "syn 1.0.18", ] @@ -2934,9 +2933,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.21" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" +checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" dependencies = [ "cfg-if", "fuchsia-zircon", @@ -2977,9 +2976,9 @@ dependencies = [ [[package]] name = "mio-uds" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" +checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" dependencies = [ "iovec", "libc", @@ -3063,9 +3062,9 @@ dependencies = [ [[package]] name = "net2" -version = "0.2.33" +version = "0.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" dependencies = [ "cfg-if", "libc", @@ -3191,9 +3190,9 @@ checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" [[package]] name = "oorandom" -version = "11.1.0" +version = "11.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcec7c9c2a95cacc7cd0ecb89d8a8454eca13906f6deb55258ffff0adeb9405" +checksum = "94af325bc33c7f60191be4e2c984d48aaa21e2854f473b85398344b60c9b6358" [[package]] name = "opaque-debug" @@ -3392,21 +3391,21 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f6a7f5eee6292c559c793430c55c00aea9d3b3d1905e855806ca4d7253426a2" +checksum = "36e3dcd42688c05a66f841d22c5d8390d9a5d4c9aaf57b9285eae4900a080063" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8988430ce790d8682672117bc06dda364c0be32d3abd738234f19f3240bad99a" +checksum = "f4d7346ac577ff1296e06a418e7618e22655bae834d4970cb6e39d6da8119969" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", ] @@ -3430,9 +3429,9 @@ checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" [[package]] name = "plotters" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e3bb8da247d27ae212529352020f3e5ee16e83c0c258061d27b08ab92675eeb" +checksum = "f9b1d9ca091d370ea3a78d5619145d1b59426ab0c9eedbad2514a4cee08bf389" dependencies = [ "js-sys", "num-traits", @@ -3448,14 +3447,14 @@ checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" [[package]] name = "primitive-types" -version = "0.6.2" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4336f4f5d5524fa60bcbd6fe626f9223d8142a50e7053e979acdf0da41ab975" +checksum = "c55c21c64d0eaa4d7ed885d959ef2d62d9e488c27c0e02d9aa5ce6c877b7d5f8" dependencies = [ "fixed-hash", "impl-codec", "impl-rlp", - "impl-serde 0.3.0", + "impl-serde", "uint", ] @@ -3482,9 +3481,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.10" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3" +checksum = "8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319" dependencies = [ "unicode-xid 0.2.0", ] @@ -3539,8 +3538,8 @@ checksum = "537aa19b95acde10a12fec4301466386f757403de4cd4e5b4fa78fb5ecb18f72" dependencies = [ "anyhow", "itertools 0.8.2", - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", ] @@ -3638,11 +3637,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" +checksum = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7" dependencies = [ - "proc-macro2 1.0.10", + "proc-macro2 1.0.12", ] [[package]] @@ -4073,13 +4072,13 @@ dependencies = [ [[package]] name = "ring" -version = "0.16.13" +version = "0.16.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "703516ae74571f24b465b4a1431e81e2ad51336cb0ded733a55a1aa3eccac196" +checksum = "1ba5a8ec64ee89a76c98c549af81ff14813df09c3e6dc4766c3856da48597a0c" dependencies = [ "cc", + "lazy_static", "libc", - "once_cell", "spin", "untrusted", "web-sys", @@ -4247,6 +4246,24 @@ dependencies = [ "untrusted", ] +[[package]] +name = "secp256k1" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2932dc07acd2066ff2e3921a4419606b220ba6cd03a9935123856cc534877056" +dependencies = [ + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ab2c26f0d3552a0f12e639ae8a64afc2e3db9c52fe32f5fc6c289d38519f220" +dependencies = [ + "cc", +] + [[package]] name = "security-framework" version = "0.4.3" @@ -4306,8 +4323,8 @@ version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", ] @@ -4336,8 +4353,8 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", ] @@ -4675,6 +4692,7 @@ checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" name = "state_processing" version = "0.2.0" dependencies = [ + "arbitrary", "beacon_chain", "bls", "criterion", @@ -4794,8 +4812,8 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "410a7488c0a728c7ceb4ad59b9567eb4053d02e8cc7f5c0e0eeeb39518369213" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "unicode-xid 0.2.0", ] @@ -4805,8 +4823,8 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", "unicode-xid 0.2.0", ] @@ -4898,8 +4916,8 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f34e0c1caaa462fd840ec6b768946ea1e7842620d94fe29d5b847138f521269" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", ] @@ -5110,8 +5128,8 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", ] @@ -5313,7 +5331,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edcf0b9b2caa5f4804ef77aeee1b929629853d806117c48258f402b69737e65c" dependencies = [ - "quote 1.0.3", + "quote 1.0.4", "syn 1.0.18", ] @@ -5387,6 +5405,7 @@ checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" name = "types" version = "0.2.0" dependencies = [ + "arbitrary", "bls", "cached_tree_hash", "compare_fields", @@ -5427,6 +5446,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "173cd16430c206dc1a430af8a89a0e9c076cf15cb42b4aedb10e8cc8fee73681" dependencies = [ + "arbitrary", "byteorder 1.3.4", "crunchy 0.2.2", "rustc-hex", @@ -5656,9 +5676,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.61" +version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f56e97dbea16d5f56549d6c8ea7f36efb6be98507308650c1a5970574b3941b9" +checksum = "e3c7d40d09cdbf0f4895ae58cf57d92e1e57a9dd8ed2e8390514b54a47cc5551" dependencies = [ "cfg-if", "serde", @@ -5668,24 +5688,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.61" +version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75d4f3f9b81dfc7d66b955876b325b20e8affd4ce8d93e51162626fc5faadb" +checksum = "c3972e137ebf830900db522d6c8fd74d1900dcfc733462e9a12e942b00b4ac94" dependencies = [ "bumpalo", "lazy_static", "log 0.4.8", - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "736dcd8f8455458c82614f12116aabd0209d440c1a28d8824bcaed755ac3e058" +checksum = "8a369c5e1dfb7569e14d62af4da642a3cbc2f9a3652fe586e26ac22222aa4b04" dependencies = [ "cfg-if", "js-sys", @@ -5695,22 +5715,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.61" +version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dcde4b19e863521c1e78ecf100935132396291b09ae0ae2e155ff84ccbe9736" +checksum = "2cd85aa2c579e8892442954685f0d801f9129de24fa2136b2c6a539c76b65776" dependencies = [ - "quote 1.0.3", + "quote 1.0.4", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.61" +version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d87d2b117af2b86472402d70f7eb173bbe166beb5e727f3c0bebecdf356504" +checksum = "8eb197bd3a47553334907ffd2f16507b4f4f01bbec3ac921a7719e0decdfe72a" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", "wasm-bindgen-backend", "wasm-bindgen-shared", @@ -5718,15 +5738,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.61" +version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71f77b681efd0bca6f8ea356cdc2e497538b41d3e2a02afed18ce8f022231d29" +checksum = "a91c2916119c17a8e316507afaaa2dd94b47646048014bbdf6bef098c1bb58ad" [[package]] name = "wasm-bindgen-test" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07cd6ad5265ce3c44de5666db14607969256fdc97a9851861fdf36f39450bf6" +checksum = "fd8e9dad8040e378f0696b017570c6bc929aac373180e06b3d67ac5059c52da3" dependencies = [ "console_error_panic_hook", "js-sys", @@ -5738,12 +5758,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a0787ef0855c462e163e4380f9a7f2743ae2527638a045cc50e9fa836d28025" +checksum = "c358c8d2507c1bae25efa069e62ea907aa28700b25c8c33dafb0b15ba4603627" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", ] [[package]] @@ -5764,9 +5784,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.38" +version = "0.3.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07c5819dc39222a788ca169a81aef7d02739019256300534f493b5747d5469c2" +checksum = "8bc359e5dd3b46cb9687a051d50a2fdd228e4ba7cf6fcf861a5365c3d671a642" dependencies = [ "js-sys", "wasm-bindgen", @@ -5775,13 +5795,12 @@ dependencies = [ [[package]] name = "web3" version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0631c83208cf420eeb2ed9b6cb2d5fc853aa76a43619ccec2a3d52d741f1261" +source = "git+https://github.com/tomusdrw/rust-web3#b6c81f978ede4e5c250b2d6f93399f31f7ac2a48" dependencies = [ "arrayvec 0.5.1", - "base64 0.11.0", + "base64 0.12.0", "derive_more", - "ethabi 9.0.1", + "ethabi", "ethereum-types", "futures 0.1.29", "hyper 0.12.35", @@ -5790,15 +5809,19 @@ dependencies = [ "log 0.4.8", "native-tls", "parking_lot 0.10.2", + "rlp", "rustc-hex", + "secp256k1", "serde", "serde_json", + "tiny-keccak 2.0.2", "tokio-core", "tokio-io", "tokio-timer 0.1.2", "tokio-uds 0.1.7", "url 2.1.1", "websocket", + "zeroize", ] [[package]] @@ -6003,8 +6026,8 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de251eec69fc7c1bc3923403d18ececb929380e016afe103da75f396704f8ca2" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.12", + "quote 1.0.4", "syn 1.0.18", "synstructure", ] diff --git a/Cargo.toml b/Cargo.toml index 453577d231..75bfa5644f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,3 +60,4 @@ eth2_ssz = { path = "eth2/utils/ssz" } eth2_ssz_derive = { path = "eth2/utils/ssz_derive" } eth2_ssz_types = { path = "eth2/utils/ssz_types" } eth2_hashing = { path = "eth2/utils/eth2_hashing" } +web3 = { git = "https://github.com/tomusdrw/rust-web3" } diff --git a/Makefile b/Makefile index bebf7f8265..ecebc51982 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,10 @@ lint: make-ef-tests: make -C $(EF_TESTS) +# Verifies that state_processing feature arbitrary-fuzz will compile +arbitrary-fuzz: + cargo check --manifest-path=eth2/state_processing/Cargo.toml --features arbitrary-fuzz + # Performs a `cargo` clean and cleans the `ef_tests` directory. clean: cargo clean diff --git a/beacon_node/eth1/src/service.rs b/beacon_node/eth1/src/service.rs index 6596abf032..55ef6b9336 100644 --- a/beacon_node/eth1/src/service.rs +++ b/beacon_node/eth1/src/service.rs @@ -633,6 +633,36 @@ impl Service { ); } + let block_cache = self.inner.block_cache.read(); + let latest_block_mins = block_cache + .latest_block_timestamp() + .and_then(|timestamp| { + SystemTime::now() + .duration_since(UNIX_EPOCH) + .ok() + .and_then(|now| now.checked_sub(Duration::from_secs(timestamp))) + }) + .map(|duration| format!("{} mins", duration.as_secs() / 60)) + .unwrap_or_else(|| "n/a".into()); + + if blocks_imported > 0 { + debug!( + self.log, + "Imported eth1 block(s)"; + "latest_block_age" => latest_block_mins, + "latest_block" => block_cache.highest_block_number(), + "total_cached_blocks" => block_cache.len(), + "new" => blocks_imported + ); + } else { + debug!( + self.log, + "No new eth1 blocks imported"; + "latest_block" => block_cache.highest_block_number(), + "cached_blocks" => block_cache.len(), + ); + } + Ok(BlockCacheUpdateOutcome { blocks_imported, head_block_number: self.inner.block_cache.read().highest_block_number(), diff --git a/beacon_node/eth2-libp2p/src/peer_manager/mod.rs b/beacon_node/eth2-libp2p/src/peer_manager/mod.rs index b51f5c55f7..d019240990 100644 --- a/beacon_node/eth2-libp2p/src/peer_manager/mod.rs +++ b/beacon_node/eth2-libp2p/src/peer_manager/mod.rs @@ -394,8 +394,17 @@ impl PeerManager { // For disconnected peers, lower their reputation by 1 for every hour they // stay disconnected. This helps us slowly forget disconnected peers. // In the same way, slowly allow banned peers back again. - let dc_hours = (now - since).as_secs() / 3600; - let last_dc_hours = (self.last_updated - since).as_secs() / 3600; + let dc_hours = now + .checked_duration_since(since) + .unwrap_or_else(|| Duration::from_secs(0)) + .as_secs() + / 3600; + let last_dc_hours = self + .last_updated + .checked_duration_since(since) + .unwrap_or_else(|| Duration::from_secs(0)) + .as_secs() + / 3600; if dc_hours > last_dc_hours { // this should be 1 most of the time let rep_dif = (dc_hours - last_dc_hours) diff --git a/eth2/state_processing/Cargo.toml b/eth2/state_processing/Cargo.toml index 6387a59aef..a13e25f123 100644 --- a/eth2/state_processing/Cargo.toml +++ b/eth2/state_processing/Cargo.toml @@ -34,6 +34,16 @@ types = { path = "../types" } rayon = "1.2.0" eth2_hashing = { path = "../utils/eth2_hashing" } int_to_bytes = { path = "../utils/int_to_bytes" } +arbitrary = { version = "0.4.3", features = ["derive"], optional = true } [features] fake_crypto = ["bls/fake_crypto"] +arbitrary-fuzz = [ + "arbitrary", + "types/arbitrary-fuzz", + "bls/arbitrary", + "merkle_proof/arbitrary", + "eth2_ssz/arbitrary", + "eth2_ssz_types/arbitrary", + "tree_hash/arbitrary", +] diff --git a/eth2/state_processing/src/per_block_processing.rs b/eth2/state_processing/src/per_block_processing.rs index a4f2be87ef..7d47e80cee 100644 --- a/eth2/state_processing/src/per_block_processing.rs +++ b/eth2/state_processing/src/per_block_processing.rs @@ -33,7 +33,11 @@ mod verify_deposit; mod verify_exit; mod verify_proposer_slashing; +#[cfg(feature = "arbitrary-fuzz")] +use arbitrary::Arbitrary; + /// The strategy to be used when validating the block's signatures. +#[cfg_attr(feature = "arbitrary-fuzz", derive(Arbitrary))] #[derive(PartialEq, Clone, Copy)] pub enum BlockSignatureStrategy { /// Do not validate any signature. Use with caution. @@ -45,6 +49,7 @@ pub enum BlockSignatureStrategy { } /// The strategy to be used when validating the block's signatures. +#[cfg_attr(feature = "arbitrary-fuzz", derive(Arbitrary))] #[derive(PartialEq, Clone, Copy)] pub enum VerifySignatures { /// Validate all signatures encountered. diff --git a/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs b/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs index 269e366adf..9410e823fe 100644 --- a/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs +++ b/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs @@ -2,6 +2,9 @@ use crate::common::get_attesting_indices; use safe_arith::SafeArith; use types::*; +#[cfg(feature = "arbitrary-fuzz")] +use arbitrary::Arbitrary; + /// Sets the boolean `var` on `self` to be true if it is true on `other`. Otherwise leaves `self` /// as is. macro_rules! set_self_if_other_is_true { @@ -13,6 +16,7 @@ macro_rules! set_self_if_other_is_true { } /// The information required to reward a block producer for including an attestation in a block. +#[cfg_attr(feature = "arbitrary-fuzz", derive(Arbitrary))] #[derive(Debug, Clone, Copy)] pub struct InclusionInfo { /// The distance between the attestation slot and the slot that attestation was included in a @@ -44,6 +48,7 @@ impl InclusionInfo { } /// Information required to reward some validator during the current and previous epoch. +#[cfg_attr(feature = "arbitrary-fuzz", derive(Arbitrary))] #[derive(Debug, Default, Clone)] pub struct ValidatorStatus { /// True if the validator has been slashed, ever. @@ -108,7 +113,9 @@ impl ValidatorStatus { /// The total effective balances for different sets of validators during the previous and current /// epochs. + #[derive(Clone, Debug)] +#[cfg_attr(feature = "arbitrary-fuzz", derive(Arbitrary))] pub struct TotalBalances { /// The effective balance increment from the spec. effective_balance_increment: u64, @@ -165,6 +172,7 @@ impl TotalBalances { /// Summarised information about validator participation in the _previous and _current_ epochs of /// some `BeaconState`. +#[cfg_attr(feature = "arbitrary-fuzz", derive(Arbitrary))] #[derive(Debug, Clone)] pub struct ValidatorStatuses { /// Information about each individual validator from the state's validator registry. diff --git a/eth2/types/Cargo.toml b/eth2/types/Cargo.toml index 48c98a67f0..31db5cfd86 100644 --- a/eth2/types/Cargo.toml +++ b/eth2/types/Cargo.toml @@ -15,7 +15,7 @@ compare_fields_derive = { path = "../utils/compare_fields_derive" } dirs = "2.0.2" derivative = "1.0.3" eth2_interop_keypairs = { path = "../utils/eth2_interop_keypairs" } -ethereum-types = "0.8.0" +ethereum-types = "0.9.1" eth2_hashing = "0.1.0" hex = "0.3" int_to_bytes = { path = "../utils/int_to_bytes" } @@ -38,8 +38,21 @@ rand_xorshift = "0.2.0" cached_tree_hash = { path = "../utils/cached_tree_hash" } serde_yaml = "0.8.11" tempfile = "3.1.0" +arbitrary = { version = "0.4", features = ["derive"], optional = true } [dev-dependencies] env_logger = "0.7.1" serde_json = "1.0.41" criterion = "0.3.0" + +[features] +arbitrary-fuzz = [ + "arbitrary", + "ethereum-types/arbitrary", + "bls/arbitrary", + "eth2_ssz/arbitrary", + "eth2_ssz_types/arbitrary", + "merkle_proof/arbitrary", + "swap_or_not_shuffle/arbitrary", + "tree_hash/arbitrary", +] diff --git a/eth2/types/src/aggregate_and_proof.rs b/eth2/types/src/aggregate_and_proof.rs index f5376c06eb..2cf1d2a512 100644 --- a/eth2/types/src/aggregate_and_proof.rs +++ b/eth2/types/src/aggregate_and_proof.rs @@ -11,6 +11,7 @@ use tree_hash_derive::TreeHash; /// A Validators aggregate attestation and selection proof. /// /// Spec v0.10.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode, TestRandom, TreeHash)] #[serde(bound = "T: EthSpec")] pub struct AggregateAndProof { diff --git a/eth2/types/src/attestation.rs b/eth2/types/src/attestation.rs index 34c11f26f8..26052cbaa9 100644 --- a/eth2/types/src/attestation.rs +++ b/eth2/types/src/attestation.rs @@ -20,6 +20,7 @@ pub enum Error { /// Details an attestation that can be slashable. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] #[serde(bound = "T: EthSpec")] pub struct Attestation { diff --git a/eth2/types/src/attestation_data.rs b/eth2/types/src/attestation_data.rs index 15d9920f70..756c24bd1d 100644 --- a/eth2/types/src/attestation_data.rs +++ b/eth2/types/src/attestation_data.rs @@ -9,6 +9,7 @@ use tree_hash_derive::TreeHash; /// The data upon which an attestation is based. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive( Debug, Clone, diff --git a/eth2/types/src/attestation_duty.rs b/eth2/types/src/attestation_duty.rs index d9117fc11f..c32e4683e1 100644 --- a/eth2/types/src/attestation_duty.rs +++ b/eth2/types/src/attestation_duty.rs @@ -1,6 +1,7 @@ use crate::*; use serde_derive::{Deserialize, Serialize}; +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Copy, Default, Serialize, Deserialize)] pub struct AttestationDuty { /// The slot during which the attester must attest. diff --git a/eth2/types/src/attester_slashing.rs b/eth2/types/src/attester_slashing.rs index c5aa6b5288..6b0873fe7b 100644 --- a/eth2/types/src/attester_slashing.rs +++ b/eth2/types/src/attester_slashing.rs @@ -8,6 +8,7 @@ use tree_hash_derive::TreeHash; /// Two conflicting attestations. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] #[serde(bound = "T: EthSpec")] pub struct AttesterSlashing { diff --git a/eth2/types/src/beacon_block.rs b/eth2/types/src/beacon_block.rs index e2fed91439..2eee8b8e7d 100644 --- a/eth2/types/src/beacon_block.rs +++ b/eth2/types/src/beacon_block.rs @@ -11,6 +11,7 @@ use tree_hash_derive::TreeHash; /// A block of the `BeaconChain`. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] #[serde(bound = "T: EthSpec")] pub struct BeaconBlock { diff --git a/eth2/types/src/beacon_block_body.rs b/eth2/types/src/beacon_block_body.rs index 643db5ecac..d716f7801e 100644 --- a/eth2/types/src/beacon_block_body.rs +++ b/eth2/types/src/beacon_block_body.rs @@ -11,6 +11,7 @@ use tree_hash_derive::TreeHash; /// The body of a `BeaconChain` block, containing operations. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] #[serde(bound = "T: EthSpec")] pub struct BeaconBlockBody { diff --git a/eth2/types/src/beacon_block_header.rs b/eth2/types/src/beacon_block_header.rs index fb2f532b12..2fec8e82b6 100644 --- a/eth2/types/src/beacon_block_header.rs +++ b/eth2/types/src/beacon_block_header.rs @@ -10,6 +10,7 @@ use tree_hash_derive::TreeHash; /// A header of a `BeaconBlock`. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] pub struct BeaconBlockHeader { pub slot: Slot, diff --git a/eth2/types/src/beacon_committee.rs b/eth2/types/src/beacon_committee.rs index e237499ff7..6483c009af 100644 --- a/eth2/types/src/beacon_committee.rs +++ b/eth2/types/src/beacon_committee.rs @@ -17,6 +17,7 @@ impl<'a> BeaconCommittee<'a> { } } +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Default, Clone, Debug, PartialEq)] pub struct OwnedBeaconCommittee { pub slot: Slot, diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index 4f980a0191..603dbc22d7 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -2,6 +2,7 @@ use self::committee_cache::get_active_validator_indices; use self::exit_cache::ExitCache; use crate::test_utils::TestRandom; use crate::*; + use cached_tree_hash::{CacheArena, CachedTreeHash}; use compare_fields_derive::CompareFields; use eth2_hashing::hash; @@ -102,6 +103,7 @@ impl AllowNextEpoch { } } +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(PartialEq, Eq, Hash, Clone, Copy)] pub struct BeaconStateHash(Hash256); @@ -1155,3 +1157,46 @@ impl From for Error { Error::ArithError(e) } } + +#[cfg(feature = "arbitrary-fuzz")] +impl arbitrary::Arbitrary for BeaconState { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + Ok(Self { + genesis_time: u64::arbitrary(u)?, + genesis_validators_root: Hash256::arbitrary(u)?, + slot: Slot::arbitrary(u)?, + fork: Fork::arbitrary(u)?, + latest_block_header: BeaconBlockHeader::arbitrary(u)?, + block_roots: >::arbitrary(u)?, + state_roots: >::arbitrary(u)?, + historical_roots: >::arbitrary(u)?, + eth1_data: Eth1Data::arbitrary(u)?, + eth1_data_votes: >::arbitrary(u)?, + eth1_deposit_index: u64::arbitrary(u)?, + validators: >::arbitrary(u)?, + balances: >::arbitrary(u)?, + randao_mixes: >::arbitrary(u)?, + slashings: >::arbitrary(u)?, + previous_epoch_attestations: , + T::MaxPendingAttestations, + >>::arbitrary(u)?, + current_epoch_attestations: , + T::MaxPendingAttestations, + >>::arbitrary(u)?, + justification_bits: >::arbitrary(u)?, + previous_justified_checkpoint: Checkpoint::arbitrary(u)?, + current_justified_checkpoint: Checkpoint::arbitrary(u)?, + finalized_checkpoint: Checkpoint::arbitrary(u)?, + committee_caches: [ + CommitteeCache::arbitrary(u)?, + CommitteeCache::arbitrary(u)?, + CommitteeCache::arbitrary(u)?, + ], + pubkey_cache: PubkeyCache::arbitrary(u)?, + exit_cache: ExitCache::arbitrary(u)?, + tree_hash_cache: None, + }) + } +} diff --git a/eth2/types/src/beacon_state/committee_cache.rs b/eth2/types/src/beacon_state/committee_cache.rs index d5d89d3112..02f6ea9202 100644 --- a/eth2/types/src/beacon_state/committee_cache.rs +++ b/eth2/types/src/beacon_state/committee_cache.rs @@ -277,3 +277,10 @@ pub fn get_active_validator_indices(validators: &[Validator], epoch: Epoch) -> V active } + +#[cfg(feature = "arbitrary-fuzz")] +impl arbitrary::Arbitrary for CommitteeCache { + fn arbitrary(_u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + Ok(Self::default()) + } +} diff --git a/eth2/types/src/beacon_state/exit_cache.rs b/eth2/types/src/beacon_state/exit_cache.rs index aff05baaf7..0fc2e05754 100644 --- a/eth2/types/src/beacon_state/exit_cache.rs +++ b/eth2/types/src/beacon_state/exit_cache.rs @@ -70,3 +70,10 @@ impl ExitCache { Ok(self.exits_per_epoch.get(&epoch).cloned().unwrap_or(0)) } } + +#[cfg(feature = "arbitrary-fuzz")] +impl arbitrary::Arbitrary for ExitCache { + fn arbitrary(_u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + Ok(Self::default()) + } +} diff --git a/eth2/types/src/beacon_state/pubkey_cache.rs b/eth2/types/src/beacon_state/pubkey_cache.rs index a4a38ebc47..6b9f8e8386 100644 --- a/eth2/types/src/beacon_state/pubkey_cache.rs +++ b/eth2/types/src/beacon_state/pubkey_cache.rs @@ -39,3 +39,10 @@ impl PubkeyCache { self.map.get(pubkey).copied() } } + +#[cfg(feature = "arbitrary-fuzz")] +impl arbitrary::Arbitrary for PubkeyCache { + fn arbitrary(_u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + Ok(Self::default()) + } +} diff --git a/eth2/types/src/chain_spec.rs b/eth2/types/src/chain_spec.rs index 40cda04639..22c248ce82 100644 --- a/eth2/types/src/chain_spec.rs +++ b/eth2/types/src/chain_spec.rs @@ -26,6 +26,7 @@ pub enum Domain { /// Holds all the "constants" for a BeaconChain. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(PartialEq, Debug, Clone, Serialize, Deserialize)] #[serde(default)] pub struct ChainSpec { diff --git a/eth2/types/src/checkpoint.rs b/eth2/types/src/checkpoint.rs index 45321d6ff5..c7a06defdf 100644 --- a/eth2/types/src/checkpoint.rs +++ b/eth2/types/src/checkpoint.rs @@ -8,6 +8,7 @@ use tree_hash_derive::TreeHash; /// Casper FFG checkpoint, used in attestations. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive( Debug, Clone, diff --git a/eth2/types/src/deposit.rs b/eth2/types/src/deposit.rs index 5cd8482448..9d9880aeec 100644 --- a/eth2/types/src/deposit.rs +++ b/eth2/types/src/deposit.rs @@ -1,9 +1,8 @@ use crate::test_utils::TestRandom; use crate::*; -use ssz_types::typenum::U33; - use serde_derive::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; +use ssz_types::typenum::U33; use test_random_derive::TestRandom; use tree_hash_derive::TreeHash; @@ -12,6 +11,7 @@ pub const DEPOSIT_TREE_DEPTH: usize = 32; /// A deposit to potentially become a beacon chain validator. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] pub struct Deposit { pub proof: FixedVector, diff --git a/eth2/types/src/deposit_data.rs b/eth2/types/src/deposit_data.rs index 14019a7b6d..fa82c943fd 100644 --- a/eth2/types/src/deposit_data.rs +++ b/eth2/types/src/deposit_data.rs @@ -1,7 +1,7 @@ use crate::test_utils::TestRandom; use crate::*; -use bls::{PublicKeyBytes, SignatureBytes}; +use bls::{PublicKeyBytes, SignatureBytes}; use serde_derive::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; use test_random_derive::TestRandom; @@ -10,6 +10,7 @@ use tree_hash_derive::TreeHash; /// The data supplied by the user to the deposit contract. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] pub struct DepositData { pub pubkey: PublicKeyBytes, diff --git a/eth2/types/src/deposit_message.rs b/eth2/types/src/deposit_message.rs index 3ed43122dc..2d0d1ef686 100644 --- a/eth2/types/src/deposit_message.rs +++ b/eth2/types/src/deposit_message.rs @@ -1,7 +1,7 @@ use crate::test_utils::TestRandom; use crate::*; -use bls::PublicKeyBytes; +use bls::PublicKeyBytes; use serde_derive::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; use test_random_derive::TestRandom; @@ -10,6 +10,7 @@ use tree_hash_derive::TreeHash; /// The data supplied by the user to the deposit contract. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] pub struct DepositMessage { pub pubkey: PublicKeyBytes, diff --git a/eth2/types/src/enr_fork_id.rs b/eth2/types/src/enr_fork_id.rs index f1c5ac6bf1..e10744368f 100644 --- a/eth2/types/src/enr_fork_id.rs +++ b/eth2/types/src/enr_fork_id.rs @@ -11,6 +11,7 @@ use tree_hash_derive::TreeHash; /// a nodes local ENR. /// /// Spec v0.11 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive( Debug, Clone, PartialEq, Default, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom, )] diff --git a/eth2/types/src/eth1_data.rs b/eth2/types/src/eth1_data.rs index 5ba6870e7e..8d8807582b 100644 --- a/eth2/types/src/eth1_data.rs +++ b/eth2/types/src/eth1_data.rs @@ -9,6 +9,7 @@ use tree_hash_derive::TreeHash; /// Contains data obtained from the Eth1 chain. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive( Debug, PartialEq, diff --git a/eth2/types/src/eth_spec.rs b/eth2/types/src/eth_spec.rs index 18ee3e5a91..c3c60bae06 100644 --- a/eth2/types/src/eth_spec.rs +++ b/eth2/types/src/eth_spec.rs @@ -1,4 +1,5 @@ use crate::*; + use safe_arith::SafeArith; use serde_derive::{Deserialize, Serialize}; use ssz_types::typenum::{ @@ -131,6 +132,7 @@ macro_rules! params_from_eth_spec { /// Ethereum Foundation specifications. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] pub struct MainnetEthSpec; @@ -164,6 +166,7 @@ pub type FoundationBeaconState = BeaconState; /// Ethereum Foundation minimal spec, as defined in the eth2.0-specs repo. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] pub struct MinimalEthSpec; @@ -198,6 +201,7 @@ impl EthSpec for MinimalEthSpec { pub type MinimalBeaconState = BeaconState; /// Interop testnet spec +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] pub struct InteropEthSpec; diff --git a/eth2/types/src/fork.rs b/eth2/types/src/fork.rs index 7d9bfb1295..90ce75128f 100644 --- a/eth2/types/src/fork.rs +++ b/eth2/types/src/fork.rs @@ -10,6 +10,7 @@ use tree_hash_derive::TreeHash; /// Specifies a fork of the `BeaconChain`, to prevent replay attacks. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive( Debug, Clone, PartialEq, Default, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom, )] diff --git a/eth2/types/src/fork_data.rs b/eth2/types/src/fork_data.rs index ac5848012f..7d52155268 100644 --- a/eth2/types/src/fork_data.rs +++ b/eth2/types/src/fork_data.rs @@ -10,6 +10,7 @@ use tree_hash_derive::TreeHash; /// Specifies a fork of the `BeaconChain`, to prevent replay attacks. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive( Debug, Clone, PartialEq, Default, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom, )] diff --git a/eth2/types/src/free_attestation.rs b/eth2/types/src/free_attestation.rs index 16d4f67281..6215fb0cd7 100644 --- a/eth2/types/src/free_attestation.rs +++ b/eth2/types/src/free_attestation.rs @@ -4,6 +4,7 @@ use super::{AttestationData, Signature}; use serde_derive::Serialize; +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, Clone, PartialEq, Serialize)] pub struct FreeAttestation { pub data: AttestationData, diff --git a/eth2/types/src/historical_batch.rs b/eth2/types/src/historical_batch.rs index 9b7e04f558..ae875ee340 100644 --- a/eth2/types/src/historical_batch.rs +++ b/eth2/types/src/historical_batch.rs @@ -10,6 +10,7 @@ use tree_hash_derive::TreeHash; /// Historical block and state roots. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] pub struct HistoricalBatch { pub block_roots: FixedVector, diff --git a/eth2/types/src/indexed_attestation.rs b/eth2/types/src/indexed_attestation.rs index c77b6f401e..f603354d99 100644 --- a/eth2/types/src/indexed_attestation.rs +++ b/eth2/types/src/indexed_attestation.rs @@ -1,4 +1,5 @@ use crate::{test_utils::TestRandom, AggregateSignature, AttestationData, EthSpec, VariableList}; + use serde_derive::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; use test_random_derive::TestRandom; @@ -9,6 +10,7 @@ use tree_hash_derive::TreeHash; /// To be included in an `AttesterSlashing`. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] #[serde(bound = "T: EthSpec")] pub struct IndexedAttestation { diff --git a/eth2/types/src/pending_attestation.rs b/eth2/types/src/pending_attestation.rs index 9d78d9cd69..455245edde 100644 --- a/eth2/types/src/pending_attestation.rs +++ b/eth2/types/src/pending_attestation.rs @@ -17,6 +17,18 @@ pub struct PendingAttestation { pub proposer_index: u64, } +#[cfg(feature = "arbitrary-fuzz")] +impl arbitrary::Arbitrary for PendingAttestation { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + Ok(Self { + aggregation_bits: >::arbitrary(u)?, + data: AttestationData::arbitrary(u)?, + inclusion_delay: u64::arbitrary(u)?, + proposer_index: u64::arbitrary(u)?, + }) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/eth2/types/src/proposer_slashing.rs b/eth2/types/src/proposer_slashing.rs index f82fdd4aeb..1febc1d647 100644 --- a/eth2/types/src/proposer_slashing.rs +++ b/eth2/types/src/proposer_slashing.rs @@ -9,6 +9,7 @@ use tree_hash_derive::TreeHash; /// Two conflicting proposals from the same proposer (validator). /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] pub struct ProposerSlashing { pub signed_header_1: SignedBeaconBlockHeader, diff --git a/eth2/types/src/relative_epoch.rs b/eth2/types/src/relative_epoch.rs index f179b0c707..133e7e3c96 100644 --- a/eth2/types/src/relative_epoch.rs +++ b/eth2/types/src/relative_epoch.rs @@ -6,10 +6,14 @@ pub enum Error { EpochTooHigh { base: Epoch, other: Epoch }, } +#[cfg(feature = "arbitrary-fuzz")] +use arbitrary::Arbitrary; + /// Defines the epochs relative to some epoch. Most useful when referring to the committees prior /// to and following some epoch. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(Arbitrary))] #[derive(Debug, PartialEq, Clone, Copy)] pub enum RelativeEpoch { /// The prior epoch. diff --git a/eth2/types/src/selection_proof.rs b/eth2/types/src/selection_proof.rs index 18c62ba400..df8c330f92 100644 --- a/eth2/types/src/selection_proof.rs +++ b/eth2/types/src/selection_proof.rs @@ -3,6 +3,7 @@ use safe_arith::{ArithError, SafeArith}; use std::convert::TryInto; use tree_hash::TreeHash; +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(PartialEq, Debug, Clone)] pub struct SelectionProof(Signature); diff --git a/eth2/types/src/signed_aggregate_and_proof.rs b/eth2/types/src/signed_aggregate_and_proof.rs index 7508181678..1d9c587511 100644 --- a/eth2/types/src/signed_aggregate_and_proof.rs +++ b/eth2/types/src/signed_aggregate_and_proof.rs @@ -12,6 +12,7 @@ use tree_hash_derive::TreeHash; /// gossipsub topic. /// /// Spec v0.10.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode, TestRandom, TreeHash)] #[serde(bound = "T: EthSpec")] pub struct SignedAggregateAndProof { diff --git a/eth2/types/src/signed_beacon_block.rs b/eth2/types/src/signed_beacon_block.rs index 81abc0dfd1..733d3e06aa 100644 --- a/eth2/types/src/signed_beacon_block.rs +++ b/eth2/types/src/signed_beacon_block.rs @@ -1,13 +1,13 @@ use crate::{test_utils::TestRandom, BeaconBlock, EthSpec, Hash256, Slot}; -use bls::Signature; - use std::fmt; +use bls::Signature; use serde_derive::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; use test_random_derive::TestRandom; use tree_hash::TreeHash; +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(PartialEq, Eq, Hash, Clone, Copy)] pub struct SignedBeaconBlockHash(Hash256); @@ -38,6 +38,7 @@ impl From for Hash256 { /// A `BeaconBlock` and a signature from its proposer. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TestRandom)] #[serde(bound = "E: EthSpec")] pub struct SignedBeaconBlock { diff --git a/eth2/types/src/signed_beacon_block_header.rs b/eth2/types/src/signed_beacon_block_header.rs index 11627b9ee6..b3c6b06bc4 100644 --- a/eth2/types/src/signed_beacon_block_header.rs +++ b/eth2/types/src/signed_beacon_block_header.rs @@ -9,6 +9,7 @@ use tree_hash_derive::TreeHash; /// An exit voluntarily submitted a validator who wishes to withdraw. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] pub struct SignedBeaconBlockHeader { pub message: BeaconBlockHeader, diff --git a/eth2/types/src/signed_voluntary_exit.rs b/eth2/types/src/signed_voluntary_exit.rs index 6507d67961..0bf1550af8 100644 --- a/eth2/types/src/signed_voluntary_exit.rs +++ b/eth2/types/src/signed_voluntary_exit.rs @@ -9,6 +9,7 @@ use tree_hash_derive::TreeHash; /// An exit voluntarily submitted a validator who wishes to withdraw. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] pub struct SignedVoluntaryExit { pub message: VoluntaryExit, diff --git a/eth2/types/src/signing_root.rs b/eth2/types/src/signing_root.rs index f3a96df1f6..6d060bf077 100644 --- a/eth2/types/src/signing_root.rs +++ b/eth2/types/src/signing_root.rs @@ -1,11 +1,13 @@ use crate::test_utils::TestRandom; use crate::Hash256; + use serde_derive::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; use test_random_derive::TestRandom; use tree_hash::TreeHash; use tree_hash_derive::TreeHash; +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] pub struct SigningRoot { pub object_root: Hash256, diff --git a/eth2/types/src/slot_epoch.rs b/eth2/types/src/slot_epoch.rs index 7f3b45ce41..86de832580 100644 --- a/eth2/types/src/slot_epoch.rs +++ b/eth2/types/src/slot_epoch.rs @@ -12,6 +12,7 @@ use crate::test_utils::TestRandom; use crate::SignedRoot; + use rand::RngCore; use serde_derive::{Deserialize, Serialize}; use ssz::{ssz_encode, Decode, DecodeError, Encode}; @@ -21,10 +22,12 @@ use std::hash::{Hash, Hasher}; use std::iter::Iterator; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, Sub, SubAssign}; +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Eq, Clone, Copy, Default, Serialize, Deserialize)] #[serde(transparent)] pub struct Slot(u64); +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Eq, Clone, Copy, Default, Serialize, Deserialize)] pub struct Epoch(u64); diff --git a/eth2/types/src/subnet_id.rs b/eth2/types/src/subnet_id.rs index 6699d6cc0b..11e8e13377 100644 --- a/eth2/types/src/subnet_id.rs +++ b/eth2/types/src/subnet_id.rs @@ -2,6 +2,7 @@ use serde_derive::{Deserialize, Serialize}; use std::ops::{Deref, DerefMut}; +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct SubnetId(u64); diff --git a/eth2/types/src/validator.rs b/eth2/types/src/validator.rs index dbdea61ab5..726a1d955c 100644 --- a/eth2/types/src/validator.rs +++ b/eth2/types/src/validator.rs @@ -9,6 +9,7 @@ use tree_hash_derive::TreeHash; /// Information about a `BeaconChain` validator. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode, TestRandom, TreeHash)] pub struct Validator { pub pubkey: PublicKeyBytes, diff --git a/eth2/types/src/voluntary_exit.rs b/eth2/types/src/voluntary_exit.rs index 19feca8eef..84586ac155 100644 --- a/eth2/types/src/voluntary_exit.rs +++ b/eth2/types/src/voluntary_exit.rs @@ -11,6 +11,7 @@ use tree_hash_derive::TreeHash; /// An exit voluntarily submitted a validator who wishes to withdraw. /// /// Spec v0.11.1 +#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)] pub struct VoluntaryExit { /// Earliest epoch when voluntary exit can be processed. diff --git a/eth2/utils/bls/Cargo.toml b/eth2/utils/bls/Cargo.toml index 25a577834c..93df124921 100644 --- a/eth2/utils/bls/Cargo.toml +++ b/eth2/utils/bls/Cargo.toml @@ -15,6 +15,7 @@ serde_hex = { path = "../serde_hex" } eth2_ssz = "0.1.2" eth2_ssz_types = { path = "../ssz_types" } tree_hash = "0.1.0" +arbitrary = { version = "0.4", features = ["derive"], optional = true } [features] fake_crypto = [] diff --git a/eth2/utils/bls/src/aggregate_public_key.rs b/eth2/utils/bls/src/aggregate_public_key.rs index 6389915c4f..628ed86d16 100644 --- a/eth2/utils/bls/src/aggregate_public_key.rs +++ b/eth2/utils/bls/src/aggregate_public_key.rs @@ -88,3 +88,12 @@ impl<'de> Deserialize<'de> for AggregatePublicKey { Ok(agg_sig) } } + +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for AggregatePublicKey { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let mut bytes = [0u8; BLS_PUBLIC_KEY_BYTE_SIZE]; + u.fill_buffer(&mut bytes)?; + Self::from_bytes(&bytes).map_err(|_| arbitrary::Error::IncorrectFormat) + } +} diff --git a/eth2/utils/bls/src/aggregate_signature.rs b/eth2/utils/bls/src/aggregate_signature.rs index 8ff6c8bd8b..176e61804f 100644 --- a/eth2/utils/bls/src/aggregate_signature.rs +++ b/eth2/utils/bls/src/aggregate_signature.rs @@ -179,6 +179,15 @@ impl<'de> Deserialize<'de> for AggregateSignature { } } +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for AggregateSignature { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let mut bytes = [0u8; BLS_AGG_SIG_BYTE_SIZE]; + u.fill_buffer(&mut bytes)?; + Self::from_bytes(&bytes).map_err(|_| arbitrary::Error::IncorrectFormat) + } +} + #[cfg(test)] mod tests { use super::super::{Keypair, Signature}; diff --git a/eth2/utils/bls/src/fake_aggregate_public_key.rs b/eth2/utils/bls/src/fake_aggregate_public_key.rs index fc9b7db5ad..cabd6862c4 100644 --- a/eth2/utils/bls/src/fake_aggregate_public_key.rs +++ b/eth2/utils/bls/src/fake_aggregate_public_key.rs @@ -119,3 +119,12 @@ impl<'de> Deserialize<'de> for FakeAggregatePublicKey { Ok(pubkey) } } + +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for FakeAggregatePublicKey { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let mut bytes = [0u8; BLS_PUBLIC_KEY_BYTE_SIZE]; + u.fill_buffer(&mut bytes)?; + Self::from_bytes(&bytes).map_err(|_| arbitrary::Error::IncorrectFormat) + } +} diff --git a/eth2/utils/bls/src/fake_aggregate_signature.rs b/eth2/utils/bls/src/fake_aggregate_signature.rs index 401c448788..3744f95792 100644 --- a/eth2/utils/bls/src/fake_aggregate_signature.rs +++ b/eth2/utils/bls/src/fake_aggregate_signature.rs @@ -132,6 +132,15 @@ impl<'de> Deserialize<'de> for FakeAggregateSignature { } } +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for FakeAggregateSignature { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let mut bytes = [0u8; BLS_AGG_SIG_BYTE_SIZE]; + u.fill_buffer(&mut bytes)?; + Self::from_bytes(&bytes).map_err(|_| arbitrary::Error::IncorrectFormat) + } +} + #[cfg(test)] mod tests { use super::super::{Keypair, Signature}; diff --git a/eth2/utils/bls/src/fake_public_key.rs b/eth2/utils/bls/src/fake_public_key.rs index b78145cfff..168d940004 100644 --- a/eth2/utils/bls/src/fake_public_key.rs +++ b/eth2/utils/bls/src/fake_public_key.rs @@ -157,6 +157,15 @@ impl Hash for FakePublicKey { } } +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for FakePublicKey { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let mut bytes = [0u8; BLS_PUBLIC_KEY_BYTE_SIZE]; + u.fill_buffer(&mut bytes)?; + Self::from_bytes(&bytes).map_err(|_| arbitrary::Error::IncorrectFormat) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/eth2/utils/bls/src/fake_signature.rs b/eth2/utils/bls/src/fake_signature.rs index ce4866c8de..df77a3d935 100644 --- a/eth2/utils/bls/src/fake_signature.rs +++ b/eth2/utils/bls/src/fake_signature.rs @@ -114,6 +114,15 @@ impl<'de> Deserialize<'de> for FakeSignature { } } +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for FakeSignature { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let mut bytes = [0u8; BLS_SIG_BYTE_SIZE]; + u.fill_buffer(&mut bytes)?; + Self::from_bytes(&bytes).map_err(|_| arbitrary::Error::IncorrectFormat) + } +} + #[cfg(test)] mod tests { use super::super::Keypair; diff --git a/eth2/utils/bls/src/lib.rs b/eth2/utils/bls/src/lib.rs index 2d6b56a646..e7ed092341 100644 --- a/eth2/utils/bls/src/lib.rs +++ b/eth2/utils/bls/src/lib.rs @@ -16,6 +16,9 @@ pub use crate::signature_bytes::SignatureBytes; pub use milagro_bls::{compress_g2, hash_to_curve_g2}; pub use signature_set::{verify_signature_sets, SignatureSet}; +#[cfg(feature = "arbitrary")] +pub use arbitrary; + #[cfg(feature = "fake_crypto")] mod fake_aggregate_public_key; #[cfg(feature = "fake_crypto")] diff --git a/eth2/utils/bls/src/macros.rs b/eth2/utils/bls/src/macros.rs index 4eddaf27c7..a7b1a99bab 100644 --- a/eth2/utils/bls/src/macros.rs +++ b/eth2/utils/bls/src/macros.rs @@ -252,5 +252,14 @@ macro_rules! bytes_struct { Ok(signature) } } + + #[cfg(feature = "arbitrary")] + impl $crate::arbitrary::Arbitrary for $name { + fn arbitrary(u: &mut $crate::arbitrary::Unstructured<'_>) -> $crate::arbitrary::Result { + let mut bytes = [0u8; $byte_size]; + u.fill_buffer(&mut bytes)?; + Self::from_bytes(&bytes).map_err(|_| $crate::arbitrary::Error::IncorrectFormat) + } + } }; } diff --git a/eth2/utils/bls/src/public_key.rs b/eth2/utils/bls/src/public_key.rs index 70ad37f352..1af555ace0 100644 --- a/eth2/utils/bls/src/public_key.rs +++ b/eth2/utils/bls/src/public_key.rs @@ -145,6 +145,15 @@ impl Hash for PublicKey { } } +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for PublicKey { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let mut bytes = [0u8; BLS_PUBLIC_KEY_BYTE_SIZE]; + u.fill_buffer(&mut bytes)?; + Self::from_bytes(&bytes).map_err(|_| arbitrary::Error::IncorrectFormat) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/eth2/utils/bls/src/signature.rs b/eth2/utils/bls/src/signature.rs index 64b877bfb4..73de59bf9a 100644 --- a/eth2/utils/bls/src/signature.rs +++ b/eth2/utils/bls/src/signature.rs @@ -111,6 +111,15 @@ impl<'de> Deserialize<'de> for Signature { } } +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for Signature { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let mut bytes = [0u8; BLS_SIG_BYTE_SIZE]; + u.fill_buffer(&mut bytes)?; + Self::from_bytes(&bytes).map_err(|_| arbitrary::Error::IncorrectFormat) + } +} + #[cfg(test)] mod tests { use super::super::Keypair; diff --git a/eth2/utils/cached_tree_hash/Cargo.toml b/eth2/utils/cached_tree_hash/Cargo.toml index 252806aaaa..5ac4d5e81d 100644 --- a/eth2/utils/cached_tree_hash/Cargo.toml +++ b/eth2/utils/cached_tree_hash/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Michael Sproul "] edition = "2018" [dependencies] -ethereum-types = "0.8" +ethereum-types = "0.9" eth2_ssz_types = { path = "../ssz_types" } eth2_hashing = "0.1" eth2_ssz_derive = "0.1.0" @@ -16,3 +16,6 @@ smallvec = "1.2.0" [dev-dependencies] quickcheck = "0.9" quickcheck_macros = "0.8" + +[features] +arbitrary = ["ethereum-types/arbitrary"] diff --git a/eth2/utils/deposit_contract/Cargo.toml b/eth2/utils/deposit_contract/Cargo.toml index 877fa388bd..0c3abacf55 100644 --- a/eth2/utils/deposit_contract/Cargo.toml +++ b/eth2/utils/deposit_contract/Cargo.toml @@ -14,4 +14,4 @@ serde_json = "1.0" types = { path = "../../types"} eth2_ssz = { path = "../ssz"} tree_hash = { path = "../tree_hash"} -ethabi = "11.0" +ethabi = "12.0" diff --git a/eth2/utils/merkle_proof/Cargo.toml b/eth2/utils/merkle_proof/Cargo.toml index d4127a53f8..e56fab7f31 100644 --- a/eth2/utils/merkle_proof/Cargo.toml +++ b/eth2/utils/merkle_proof/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Michael Sproul "] edition = "2018" [dependencies] -ethereum-types = "0.8.0" +ethereum-types = "0.9" eth2_hashing = "0.1.0" lazy_static = "1.4.0" safe_arith = { path = "../safe_arith" } @@ -13,3 +13,6 @@ safe_arith = { path = "../safe_arith" } [dev-dependencies] quickcheck = "0.9.0" quickcheck_macros = "0.8.0" + +[features] +arbitrary = ["ethereum-types/arbitrary"] diff --git a/eth2/utils/ssz/Cargo.toml b/eth2/utils/ssz/Cargo.toml index 5846099a34..162c91ae13 100644 --- a/eth2/utils/ssz/Cargo.toml +++ b/eth2/utils/ssz/Cargo.toml @@ -13,5 +13,8 @@ name = "ssz" eth2_ssz_derive = "0.1.0" [dependencies] -ethereum-types = "0.8.0" +ethereum-types = "0.9.1" smallvec = "1.2.0" + +[features] +arbitrary = ["ethereum-types/arbitrary"] diff --git a/eth2/utils/ssz_types/Cargo.toml b/eth2/utils/ssz_types/Cargo.toml index d019373e9f..eb7ffb4835 100644 --- a/eth2/utils/ssz_types/Cargo.toml +++ b/eth2/utils/ssz_types/Cargo.toml @@ -14,6 +14,7 @@ serde_derive = "1.0.102" serde_hex = { path = "../serde_hex" } eth2_ssz = "0.1.2" typenum = "1.11.2" +arbitrary = { version = "0.4", features = ["derive"], optional = true } [dev-dependencies] serde_yaml = "0.8.11" diff --git a/eth2/utils/ssz_types/src/bitfield.rs b/eth2/utils/ssz_types/src/bitfield.rs index 4192a8a4f7..1b6dce3ec0 100644 --- a/eth2/utils/ssz_types/src/bitfield.rs +++ b/eth2/utils/ssz_types/src/bitfield.rs @@ -617,6 +617,28 @@ impl tree_hash::TreeHash for Bitfield> { } } +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for Bitfield> { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let size = N::to_usize(); + let mut vec: Vec = vec![0u8; size]; + u.fill_buffer(&mut vec)?; + Ok(Self::from_bytes(vec).map_err(|_| arbitrary::Error::IncorrectFormat)?) + } +} + +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for Bitfield> { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let max_size = N::to_usize(); + let rand = usize::arbitrary(u)?; + let size = std::cmp::min(rand, max_size); + let mut vec: Vec = vec![0u8; size]; + u.fill_buffer(&mut vec)?; + Ok(Self::from_bytes(vec).map_err(|_| arbitrary::Error::IncorrectFormat)?) + } +} + #[cfg(test)] mod bitvector { use super::*; diff --git a/eth2/utils/ssz_types/src/fixed_vector.rs b/eth2/utils/ssz_types/src/fixed_vector.rs index dffd2ad753..455bb512dc 100644 --- a/eth2/utils/ssz_types/src/fixed_vector.rs +++ b/eth2/utils/ssz_types/src/fixed_vector.rs @@ -266,6 +266,18 @@ where } } +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for FixedVector { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let size = N::to_usize(); + let mut vec: Vec = Vec::with_capacity(size); + for _ in 0..size { + vec.push(::arbitrary(u)?); + } + Ok(Self::new(vec).map_err(|_| arbitrary::Error::IncorrectFormat)?) + } +} + #[cfg(test)] mod test { use super::*; diff --git a/eth2/utils/ssz_types/src/variable_list.rs b/eth2/utils/ssz_types/src/variable_list.rs index c5cb185772..1e3e559353 100644 --- a/eth2/utils/ssz_types/src/variable_list.rs +++ b/eth2/utils/ssz_types/src/variable_list.rs @@ -256,6 +256,20 @@ where } } +#[cfg(feature = "arbitrary")] +impl arbitrary::Arbitrary for VariableList { + fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let max_size = N::to_usize(); + let rand = usize::arbitrary(u)?; + let size = std::cmp::min(rand, max_size); + let mut vec: Vec = Vec::with_capacity(size); + for _ in 0..size { + vec.push(::arbitrary(u)?); + } + Ok(Self::new(vec).map_err(|_| arbitrary::Error::IncorrectFormat)?) + } +} + #[cfg(test)] mod test { use super::*; diff --git a/eth2/utils/swap_or_not_shuffle/Cargo.toml b/eth2/utils/swap_or_not_shuffle/Cargo.toml index ef86d25696..e624964168 100644 --- a/eth2/utils/swap_or_not_shuffle/Cargo.toml +++ b/eth2/utils/swap_or_not_shuffle/Cargo.toml @@ -12,8 +12,10 @@ harness = false criterion = "0.3.0" yaml-rust = "0.4.3" hex = "0.3" -ethereum-types = "0.8.0" [dependencies] eth2_hashing = "0.1.0" -ethereum-types = "0.8.0" +ethereum-types = "0.9.1" + +[features] +arbitrary = ["ethereum-types/arbitrary"] diff --git a/eth2/utils/tree_hash/Cargo.toml b/eth2/utils/tree_hash/Cargo.toml index 7ef54a74ca..db207ab4ac 100644 --- a/eth2/utils/tree_hash/Cargo.toml +++ b/eth2/utils/tree_hash/Cargo.toml @@ -18,6 +18,9 @@ types = { path = "../../types" } lazy_static = "1.4.0" [dependencies] -ethereum-types = "0.8.0" +ethereum-types = "0.9" eth2_hashing = "0.1.0" smallvec = "1.2.0" + +[features] +arbitrary = ["ethereum-types/arbitrary"] diff --git a/tests/ef_tests/Cargo.toml b/tests/ef_tests/Cargo.toml index 77aabac048..252cf1f90d 100644 --- a/tests/ef_tests/Cargo.toml +++ b/tests/ef_tests/Cargo.toml @@ -12,7 +12,7 @@ fake_crypto = ["bls/fake_crypto"] [dependencies] bls = { path = "../../eth2/utils/bls" } compare_fields = { path = "../../eth2/utils/compare_fields" } -ethereum-types = "0.8.0" +ethereum-types = "0.9" hex = "0.3" rayon = "1.2.0" serde = "1.0.102"