fix ssz hashing

This commit is contained in:
Noah Citron 2022-08-12 12:38:40 -04:00
parent 573fd7fcc4
commit d42d327f26
3 changed files with 121 additions and 693 deletions

702
Cargo.lock generated
View File

@ -2,12 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "arrayvec"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -28,9 +22,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bitvec" name = "bitvec"
version = "0.20.4" version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7774144344a4faa177370406a7ff5f1da24303817368584c6206c8303eb07848" checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
dependencies = [ dependencies = [
"funty", "funty",
"radium", "radium",
@ -40,61 +34,19 @@ dependencies = [
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.10.2" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
dependencies = [ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "bls"
version = "0.2.0"
dependencies = [
"blst",
"eth2_hashing",
"eth2_serde_utils",
"eth2_ssz",
"ethereum-types",
"hex",
"rand 0.7.3",
"serde",
"serde_derive",
"tree_hash",
"zeroize",
]
[[package]]
name = "blst"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a30d0edd9dd1c60ddb42b80341c7852f6f985279a5c1a83659dcb65899dec99"
dependencies = [
"cc",
"glob",
"threadpool",
"which",
"zeroize",
]
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.10.0" version = "3.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3"
[[package]]
name = "byte-slice-cast"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.2.1" version = "1.2.1"
@ -139,83 +91,14 @@ dependencies = [
] ]
[[package]] [[package]]
name = "crunchy" name = "digest"
version = "0.2.2" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [ dependencies = [
"generic-array", "generic-array",
"typenum",
] ]
[[package]]
name = "darling"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]]
name = "derivative"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "digest"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]]
name = "either"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.31" version = "0.8.31"
@ -225,91 +108,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "eth2_hashing"
version = "0.3.0"
source = "git+https://github.com/sigp/lighthouse#df51a73272489fe154bd10995c96199062b6c3f7"
dependencies = [
"cpufeatures",
"lazy_static",
"ring",
"sha2",
]
[[package]]
name = "eth2_serde_utils"
version = "0.1.1"
source = "git+https://github.com/sigp/lighthouse#df51a73272489fe154bd10995c96199062b6c3f7"
dependencies = [
"ethereum-types",
"hex",
"serde",
"serde_derive",
"serde_json",
]
[[package]]
name = "eth2_ssz"
version = "0.4.1"
dependencies = [
"ethereum-types",
"itertools",
"smallvec",
]
[[package]]
name = "eth2_ssz_derive"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "635b86d2c941bb71e7419a571e1763d65c93e51a1bafc400352e3bef6ff59fc9"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "eth2_ssz_types"
version = "0.2.2"
dependencies = [
"derivative",
"eth2_serde_utils",
"eth2_ssz",
"serde",
"serde_derive",
"smallvec",
"tree_hash",
"typenum",
]
[[package]]
name = "ethbloom"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfb684ac8fa8f6c5759f788862bb22ec6fe3cb392f6bfd08e3c64b603661e3f8"
dependencies = [
"crunchy",
"fixed-hash",
"impl-rlp",
"impl-serde",
"tiny-keccak",
]
[[package]]
name = "ethereum-types"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05136f7057fe789f06e6d41d07b34e6f70d8c86e5693b60f97aaa6553553bdaf"
dependencies = [
"ethbloom",
"fixed-hash",
"impl-rlp",
"impl-serde",
"primitive-types",
"uint",
]
[[package]] [[package]]
name = "eyre" name = "eyre"
version = "0.6.8" version = "0.6.8"
@ -329,18 +127,6 @@ dependencies = [
"instant", "instant",
] ]
[[package]]
name = "fixed-hash"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c"
dependencies = [
"byteorder",
"rand 0.8.5",
"rustc-hex",
"static_assertions",
]
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -374,9 +160,9 @@ dependencies = [
[[package]] [[package]]
name = "funty" name = "funty"
version = "1.1.0" version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
[[package]] [[package]]
name = "futures-channel" name = "futures-channel"
@ -427,34 +213,6 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "getrandom"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
dependencies = [
"cfg-if",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
]
[[package]]
name = "getrandom"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
dependencies = [
"cfg-if",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.13" version = "0.3.13"
@ -566,12 +324,6 @@ dependencies = [
"tokio-native-tls", "tokio-native-tls",
] ]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.2.3" version = "0.2.3"
@ -583,44 +335,6 @@ dependencies = [
"unicode-normalization", "unicode-normalization",
] ]
[[package]]
name = "impl-codec"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "161ebdfec3c8e3b52bf61c4f3550a1eea4f9579d10dc1b936f3171ebdcd6c443"
dependencies = [
"parity-scale-codec",
]
[[package]]
name = "impl-rlp"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808"
dependencies = [
"rlp",
]
[[package]]
name = "impl-serde"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4551f042f3438e64dbd6226b20527fc84a6e1fe65688b58746a2f53623f25f5c"
dependencies = [
"serde",
]
[[package]]
name = "impl-trait-for-tuples"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "indenter" name = "indenter"
version = "0.3.3" version = "0.3.3"
@ -652,15 +366,6 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b"
[[package]]
name = "itertools"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.3" version = "1.0.3"
@ -692,20 +397,12 @@ checksum = "64de3cc433455c14174d42e554d4027ee631c4d046d43e3ecc6efc4636cdc7a7"
name = "lightclient" name = "lightclient"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bls",
"eth2_hashing",
"eth2_ssz",
"eth2_ssz_derive",
"eth2_ssz_types",
"ethereum-types",
"eyre", "eyre",
"hex", "hex",
"merkle_proof",
"reqwest", "reqwest",
"serde", "serde",
"ssz-rs",
"tokio", "tokio",
"tree_hash",
"tree_hash_derive",
] ]
[[package]] [[package]]
@ -739,17 +436,6 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "merkle_proof"
version = "0.2.0"
source = "git+https://github.com/sigp/lighthouse#df51a73272489fe154bd10995c96199062b6c3f7"
dependencies = [
"eth2_hashing",
"ethereum-types",
"lazy_static",
"safe_arith",
]
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.16" version = "0.3.16"
@ -764,7 +450,7 @@ checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf"
dependencies = [ dependencies = [
"libc", "libc",
"log", "log",
"wasi 0.11.0+wasi-snapshot-preview1", "wasi",
"windows-sys", "windows-sys",
] ]
@ -786,6 +472,36 @@ dependencies = [
"tempfile", "tempfile",
] ]
[[package]]
name = "num-bigint"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "1.13.1" version = "1.13.1"
@ -802,6 +518,12 @@ version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
[[package]]
name = "opaque-debug"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]] [[package]]
name = "openssl" name = "openssl"
version = "0.10.41" version = "0.10.41"
@ -847,32 +569,6 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "parity-scale-codec"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373b1a4c1338d9cd3d1fa53b3a11bdab5ab6bd80a20f7f7becd76953ae2be909"
dependencies = [
"arrayvec",
"bitvec",
"byte-slice-cast",
"impl-trait-for-tuples",
"parity-scale-codec-derive",
"serde",
]
[[package]]
name = "parity-scale-codec-derive"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1557010476e0595c9b568d16dcfb81b93cdeb157612726f5170d31aa707bed27"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.1" version = "0.12.1"
@ -920,36 +616,6 @@ version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]]
name = "ppv-lite86"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "primitive-types"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373"
dependencies = [
"fixed-hash",
"impl-codec",
"impl-rlp",
"impl-serde",
"uint",
]
[[package]]
name = "proc-macro-crate"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9"
dependencies = [
"once_cell",
"thiserror",
"toml",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.43" version = "1.0.43"
@ -970,80 +636,9 @@ dependencies = [
[[package]] [[package]]
name = "radium" name = "radium"
version = "0.6.2" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom 0.1.16",
"libc",
"rand_chacha 0.2.2",
"rand_core 0.5.1",
"rand_hc",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha 0.3.1",
"rand_core 0.6.3",
]
[[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_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core 0.6.3",
]
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom 0.1.16",
]
[[package]]
name = "rand_core"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
"getrandom 0.2.7",
]
[[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]] [[package]]
name = "redox_syscall" name = "redox_syscall"
@ -1100,48 +695,12 @@ dependencies = [
"winreg", "winreg",
] ]
[[package]]
name = "ring"
version = "0.16.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
dependencies = [
"cc",
"libc",
"once_cell",
"spin",
"untrusted",
"web-sys",
"winapi",
]
[[package]]
name = "rlp"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "999508abb0ae792aabed2460c45b89106d97fe4adac593bdaef433c2605847b5"
dependencies = [
"bytes",
"rustc-hex",
]
[[package]]
name = "rustc-hex"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.11" version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "safe_arith"
version = "0.1.0"
source = "git+https://github.com/sigp/lighthouse#df51a73272489fe154bd10995c96199062b6c3f7"
[[package]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.20" version = "0.1.20"
@ -1226,13 +785,15 @@ dependencies = [
[[package]] [[package]]
name = "sha2" name = "sha2"
version = "0.10.2" version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
dependencies = [ dependencies = [
"block-buffer",
"cfg-if", "cfg-if",
"cpufeatures", "cpufeatures",
"digest", "digest",
"opaque-debug",
] ]
[[package]] [[package]]
@ -1270,22 +831,29 @@ dependencies = [
] ]
[[package]] [[package]]
name = "spin" name = "ssz-rs"
version = "0.5.2" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/ralexstokes/ssz-rs#bd7cfb5a836e28747e6ce5e570234d14df0b24f7"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" dependencies = [
"bitvec",
"hex",
"lazy_static",
"num-bigint",
"serde",
"sha2",
"ssz-rs-derive",
"thiserror",
]
[[package]] [[package]]
name = "static_assertions" name = "ssz-rs-derive"
version = "1.1.0" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/ralexstokes/ssz-rs#bd7cfb5a836e28747e6ce5e570234d14df0b24f7"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" dependencies = [
"proc-macro2",
[[package]] "quote",
name = "strsim" "syn",
version = "0.10.0" ]
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
@ -1298,18 +866,6 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "synstructure"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
dependencies = [
"proc-macro2",
"quote",
"syn",
"unicode-xid",
]
[[package]] [[package]]
name = "tap" name = "tap"
version = "1.0.1" version = "1.0.1"
@ -1350,24 +906,6 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "threadpool"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa"
dependencies = [
"num_cpus",
]
[[package]]
name = "tiny-keccak"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
dependencies = [
"crunchy",
]
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.6.0" version = "1.6.0"
@ -1439,15 +977,6 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "toml"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "tower-service" name = "tower-service"
version = "0.3.2" version = "0.3.2"
@ -1474,24 +1003,6 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "tree_hash"
version = "0.4.1"
dependencies = [
"eth2_hashing",
"ethereum-types",
"smallvec",
]
[[package]]
name = "tree_hash_derive"
version = "0.4.0"
dependencies = [
"darling",
"quote",
"syn",
]
[[package]] [[package]]
name = "try-lock" name = "try-lock"
version = "0.2.3" version = "0.2.3"
@ -1504,18 +1015,6 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]]
name = "uint"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0"
dependencies = [
"byteorder",
"crunchy",
"hex",
"static_assertions",
]
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.8" version = "0.3.8"
@ -1537,18 +1036,6 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "unicode-xid"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
[[package]]
name = "untrusted"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]] [[package]]
name = "url" name = "url"
version = "2.2.2" version = "2.2.2"
@ -1583,12 +1070,6 @@ dependencies = [
"try-lock", "try-lock",
] ]
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"
@ -1671,17 +1152,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "which"
version = "4.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae"
dependencies = [
"either",
"lazy_static",
"libc",
]
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"
@ -1758,27 +1228,9 @@ dependencies = [
[[package]] [[package]]
name = "wyz" name = "wyz"
version = "0.2.0" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" checksum = "30b31594f29d27036c383b53b59ed3476874d518f0efb151b27a4c275141390e"
[[package]]
name = "zeroize"
version = "1.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f"
dependencies = [ dependencies = [
"zeroize_derive", "tap",
]
[[package]]
name = "zeroize_derive"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17"
dependencies = [
"proc-macro2",
"quote",
"syn",
"synstructure",
] ]

View File

@ -10,20 +10,6 @@ reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
eyre = "0.6.8" eyre = "0.6.8"
serde = { version = "1.0.143", features = ["derive"] } serde = { version = "1.0.143", features = ["derive"] }
eth2_ssz = { path = "../lighthouse/consensus/ssz" }
eth2_ssz_derive = "0.3.0"
eth2_ssz_types = { path = "../lighthouse/consensus/ssz_types" }
hex = "0.4.3" hex = "0.4.3"
eth2_hashing = { git = "https://github.com/sigp/lighthouse" } ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs" }
merkle_proof = { git = "https://github.com/sigp/lighthouse" }
ethereum-types = "0.12.1"
tree_hash = { path = "../lighthouse/consensus/tree_hash" }
tree_hash_derive = { path = "../lighthouse/consensus/tree_hash_derive" }
bls = { path = "../lighthouse/crypto/bls" }
# types = { path = "../lighthouse/consensus/types" }
[patch.crates-io]
eth2_hashing = { git = "https://github.com/sigp/lighthouse" }
eth2_serde_utils = { git = "https://github.com/sigp/lighthouse" }
tree_hash = { path = "../lighthouse/consensus/tree_hash" }
# eth2_ssz = { git = "https://github.com/sigp/lighthouse" }

View File

@ -1,14 +1,6 @@
use eyre::Result; use eyre::Result;
use serde::{Deserialize, Deserializer}; use serde::Deserializer;
use ssz::Encode; use ssz_rs::prelude::*;
use ssz_types::typenum::*;
use ssz_derive::Encode;
use ssz_types::FixedVector;
use eth2_hashing::hash;
use merkle_proof::verify_merkle_proof;
use ethereum_types::H256;
use bls::PublicKeyBytes;
use tree_hash_derive::TreeHash;
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
@ -38,33 +30,28 @@ struct Store {
impl LightClient { impl LightClient {
async fn new(nimbus_rpc: &str, checkpoint_block_root: &str) -> Result<LightClient> { async fn new(nimbus_rpc: &str, checkpoint_block_root: &str) -> Result<LightClient> {
let bootstrap = Self::get_bootstrap(nimbus_rpc, checkpoint_block_root).await?; let mut bootstrap = Self::get_bootstrap(nimbus_rpc, checkpoint_block_root).await?;
let committee_hash = tree_hash::TreeHash::tree_hash_root(&bootstrap.current_sync_committee); let committee_hash = bootstrap.current_sync_committee.hash_tree_root()?;
println!("{:?}", committee_hash); let root = Node::from_bytes(hex::decode(bootstrap.header.state_root.strip_prefix("0x").unwrap()).unwrap().try_into().unwrap());
let committee_branch = bootstrap.current_sync_committee_branch.iter().map(|elem| {
Node::from_bytes(hex::decode(elem.strip_prefix("0x").unwrap()).unwrap().try_into().unwrap())
}).collect::<Vec<_>>();
let committee_hash = H256::from_slice(&committee_hash[..]); println!("{}", committee_hash);
let branch = &bootstrap.current_sync_committee_branch.iter().map(|elem| {
H256::from_slice(&hex::decode(elem.strip_prefix("0x").unwrap()).unwrap())
}).collect::<Vec<H256>>()[..];
let index = 22; let is_valid = is_valid_merkle_branch(&committee_hash, committee_branch.iter(), 5, 22, &root);
let depth = 5; println!("{}", is_valid);
let root = H256::from_slice(&hex::decode(checkpoint_block_root.strip_prefix("0x").unwrap()).unwrap()); // let store = Store {
// header: bootstrap.header,
// current_sync_committee: bootstrap.current_sync_committee,
// next_sync_committee: None,
// };
let is_valid = verify_merkle_proof(committee_hash, branch, depth, index, root); // Ok(LightClient { nimbus_rpc: nimbus_rpc.to_string(), store })
println!("{}", is_valid);
println!("{:?}", committee_hash);
println!("{:?}", branch);
let store = Store { eyre::bail!("")
header: bootstrap.header,
current_sync_committee: bootstrap.current_sync_committee,
next_sync_committee: None,
};
Ok(LightClient { nimbus_rpc: nimbus_rpc.to_string(), store })
} }
async fn sync(&self) -> Result<()> { async fn sync(&self) -> Result<()> {
@ -104,57 +91,60 @@ impl LightClient {
} }
} }
#[derive(Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
struct BootstrapResponse { struct BootstrapResponse {
data: BootstrapData, data: BootstrapData,
} }
#[derive(Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
struct BootstrapData { struct BootstrapData {
v: Bootstrap, v: Bootstrap,
} }
#[derive(Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
struct Bootstrap { struct Bootstrap {
header: Header, header: Header,
current_sync_committee: SyncCommittee, current_sync_committee: SyncCommittee,
current_sync_committee_branch: Vec<String>, current_sync_committee_branch: Vec<String>,
} }
#[derive(Deserialize, Debug, Clone, Encode, TreeHash)] #[derive(Debug, Clone, Default, SimpleSerialize, serde::Deserialize)]
struct SyncCommittee { struct SyncCommittee {
#[serde(deserialize_with = "pubkeys_deserialize")] #[serde(deserialize_with = "pubkeys_deserialize")]
pubkeys: FixedVector<PublicKeyBytes, U512>, pubkeys: Vector<BLSPubKey, 512>,
#[serde(deserialize_with = "pubkey_deserialize")] #[serde(deserialize_with = "pubkey_deserialize")]
aggregate_pubkey: PublicKeyBytes, aggregate_pubkey: BLSPubKey,
} }
fn pubkey_deserialize<'de, D>(deserializer: D) -> Result<PublicKeyBytes, D::Error> where D: Deserializer<'de> { type BLSPubKey = Vector<u8, 48>;
let key: String = Deserialize::deserialize(deserializer)?;
fn pubkey_deserialize<'de, D>(deserializer: D) -> Result<BLSPubKey, D::Error> where D: serde::Deserializer<'de> {
let key: String = serde::Deserialize::deserialize(deserializer)?;
let key_bytes = hex::decode(key.strip_prefix("0x").unwrap()).unwrap(); let key_bytes = hex::decode(key.strip_prefix("0x").unwrap()).unwrap();
Ok(PublicKeyBytes::deserialize(&key_bytes).unwrap()) Ok(Vector::from_iter(key_bytes))
} }
fn pubkeys_deserialize<'de, D>(deserializer: D) -> Result<FixedVector<PublicKeyBytes, U512>, D::Error> where D: Deserializer<'de> { fn pubkeys_deserialize<'de, D>(deserializer: D) -> Result<Vector<BLSPubKey, 512>, D::Error> where D: serde::Deserializer<'de> {
let keys: Vec<String> = Deserialize::deserialize(deserializer)?; let keys: Vec<String> = serde::Deserialize::deserialize(deserializer)?;
let vec = keys.iter().map(|key| { Ok(keys.iter().map(|key| {
let key_bytes = hex::decode(key.strip_prefix("0x").unwrap()).unwrap(); let key_bytes = hex::decode(key.strip_prefix("0x").unwrap()).unwrap();
PublicKeyBytes::deserialize(&key_bytes).unwrap() Vector::from_iter(key_bytes)
}).collect::<Vec<PublicKeyBytes>>(); }).collect::<Vector<BLSPubKey, 512>>())
Ok(FixedVector::new(vec).unwrap())
} }
#[derive(Deserialize, Debug, Clone)] #[derive(serde::Deserialize, Debug, Clone)]
struct Header { struct Header {
slot: String, slot: String,
state_root: String,
body_root: String,
} }
#[derive(Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
struct UpdateResponse { struct UpdateResponse {
data: Vec<Update>, data: Vec<Update>,
} }
#[derive(Deserialize, Debug, Clone)] #[derive(serde::Deserialize, Debug, Clone)]
struct Update { struct Update {
attested_header: Header, attested_header: Header,
next_sync_committee: SyncCommittee, next_sync_committee: SyncCommittee,
@ -164,18 +154,18 @@ struct Update {
sync_aggregate: SyncAggregate, sync_aggregate: SyncAggregate,
} }
#[derive(Deserialize, Debug, Clone)] #[derive(serde::Deserialize, Debug, Clone)]
struct SyncAggregate { struct SyncAggregate {
sync_committee_bits: String, sync_committee_bits: String,
sync_committee_signature: String, sync_committee_signature: String,
} }
#[derive(Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
struct FinalityUpdateResponse { struct FinalityUpdateResponse {
data: FinalityUpdate, data: FinalityUpdate,
} }
#[derive(Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
struct FinalityUpdate { struct FinalityUpdate {
attested_header: Header, attested_header: Header,
finalized_header: Header, finalized_header: Header,