From 3f98e5969c775f66573455f293614f566eb73f17 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Wed, 18 Sep 2024 12:25:26 +0200 Subject: [PATCH] post-rebase fixes --- Cargo.lock | 249 +++++++++++++++++------ Cargo.toml | 42 +++- build.rs | 1 + src/cascading_merkle_tree/storage_ops.rs | 3 +- src/generic_storage/mmap_vec.rs | 21 +- src/lib.rs | 126 ++++++------ 6 files changed, 292 insertions(+), 150 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1628dcf..c8e3825 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,7 +130,7 @@ dependencies = [ "ark-std 0.4.0", "derivative", "hashbrown 0.13.2", - "itertools", + "itertools 0.10.5", "num-traits", "rayon", "zeroize", @@ -166,7 +166,7 @@ dependencies = [ "ark-std 0.4.0", "derivative", "digest 0.10.7", - "itertools", + "itertools 0.10.5", "num-bigint", "num-traits", "paste", @@ -513,6 +513,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "bytemuck" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" + [[package]] name = "byteorder" version = "1.4.3" @@ -757,8 +763,7 @@ dependencies = [ "clap", "criterion-plot", "csv", - "futures", - "itertools", + "itertools 0.10.5", "lazy_static 1.4.0", "num-traits", "oorandom", @@ -770,7 +775,6 @@ dependencies = [ "serde_derive", "serde_json", "tinytemplate", - "tokio", "walkdir", ] @@ -781,7 +785,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876" dependencies = [ "cast", - "itertools", + "itertools 0.10.5", ] [[package]] @@ -1317,6 +1321,7 @@ checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" dependencies = [ "futures-channel", "futures-core", + "futures-executor", "futures-io", "futures-sink", "futures-task", @@ -1339,6 +1344,17 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +[[package]] +name = "futures-executor" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.29" @@ -1363,6 +1379,7 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ + "futures-channel", "futures-core", "futures-io", "futures-sink", @@ -1510,9 +1527,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "hmac" @@ -1699,6 +1716,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.9" @@ -1791,6 +1817,16 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.20" @@ -1924,9 +1960,9 @@ dependencies = [ [[package]] name = "mmap-rs" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e6ae912d061146fa8d2b8bf15f66710c8641ac5d1e6478fb6d56839fd958a04" +checksum = "86968d85441db75203c34deefd0c88032f275aaa85cee19a1dcfff6ae9df56da" dependencies = [ "bitflags 1.3.2", "combine", @@ -2056,9 +2092,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", "libm", @@ -2118,9 +2154,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oorandom" @@ -2235,6 +2271,29 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.4", + "smallvec", + "windows-targets 0.52.6", +] + [[package]] name = "paste" version = "1.0.14" @@ -2523,6 +2582,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags 2.4.1", +] + [[package]] name = "regalloc" version = "0.0.34" @@ -2705,16 +2773,18 @@ dependencies = [ [[package]] name = "ruint" -version = "1.10.1" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95294d6e3a6192f3aabf91c38f56505a625aa495533442744185a36d75a790c4" +checksum = "2c3cc4c2511671f327125da14133d0c5c5d137f006a1017a16f557bc85b16286" dependencies = [ "alloy-rlp", "ark-ff 0.3.0", "ark-ff 0.4.1", + "bytemuck", "bytes", "fastrlp", "num-bigint", + "num-traits", "parity-scale-codec", "primitive-types", "proptest", @@ -2728,9 +2798,9 @@ dependencies = [ [[package]] name = "ruint-macro" -version = "1.1.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e666a5496a0b2186dbcd0ff6106e29e093c15591bde62c20d3842007c6978a09" +checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" [[package]] name = "rustc-demangle" @@ -2838,6 +2908,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "scc" +version = "2.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c947adb109a8afce5fc9c7bf951f87f146e9147b3a6a58413105628fb1d1e66" +dependencies = [ + "sdd", +] + [[package]] name = "schannel" version = "0.1.22" @@ -2859,6 +2938,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" +[[package]] +name = "sdd" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a7b59a5d9b0099720b417b6325d91a52cbf5b3dcb5041d864be53eefa58abc" + [[package]] name = "seahash" version = "4.1.0" @@ -2915,12 +3000,13 @@ dependencies = [ "ark-std 0.4.0", "ark-zkey", "bincode", + "bytemuck", "color-eyre", - "criterion", "ethabi", "ethers-core", "hex", "hex-literal", + "itertools 0.13.0", "mmap-rs", "num-bigint", "once_cell", @@ -2934,6 +3020,7 @@ dependencies = [ "semaphore-depth-macros", "serde", "serde_json", + "serial_test", "sha2", "tempfile", "thiserror", @@ -2951,7 +3038,7 @@ version = "0.1.0" name = "semaphore-depth-macros" version = "0.1.0" dependencies = [ - "itertools", + "itertools 0.10.5", "proc-macro2", "quote", "semaphore-depth-config", @@ -3044,6 +3131,31 @@ dependencies = [ "serde", ] +[[package]] +name = "serial_test" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b4b487fe2acf240a021cf57c6b2b4903b1e78ca0ecd862a71b71d2a51fed77d" +dependencies = [ + "futures", + "log", + "once_cell", + "parking_lot", + "scc", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82fe9db325bcef1fbcde82e078a5cc4efdf787e96b3b9cf45b50b529f2083d67" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "sha2" version = "0.10.8" @@ -4058,11 +4170,11 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.44.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e745dab35a0c4c77aa3ce42d595e13d2003d6902d6b08c9ef5fc326d08da12b" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets 0.42.2", + "windows-targets 0.48.5", ] [[package]] @@ -4087,21 +4199,6 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows-targets" version = "0.48.5" @@ -4118,10 +4215,20 @@ dependencies = [ ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" +name = "windows-targets" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] [[package]] name = "windows_aarch64_gnullvm" @@ -4129,6 +4236,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_msvc" version = "0.33.0" @@ -4137,15 +4250,15 @@ checksum = "cd761fd3eb9ab8cc1ed81e56e567f02dd82c4c837e48ac3b2181b9ffc5060807" [[package]] name = "windows_aarch64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -4155,15 +4268,21 @@ checksum = "cab0cf703a96bab2dc0c02c0fa748491294bf9b7feb27e1f4f96340f208ada0e" [[package]] name = "windows_i686_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -4173,15 +4292,15 @@ checksum = "8cfdbe89cc9ad7ce618ba34abc34bbb6c36d99e96cae2245b7943cd75ee773d0" [[package]] name = "windows_i686_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -4191,27 +4310,27 @@ checksum = "b4dd9b0c0e9ece7bb22e84d70d01b71c6d6248b81a3c60d11869451b4cb24784" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -4221,15 +4340,15 @@ checksum = "ff1e4aa646495048ec7f3ffddc411e1d829c026a2ec62b39da15c1055e406eaa" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" diff --git a/Cargo.toml b/Cargo.toml index 826903a..db9f3cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,10 +25,18 @@ repository = "https://github.com/worldcoin/semaphore-rs" [features] default = [] -bench = ["criterion", "proptest"] -depth_16 = ["semaphore-depth-config/depth_16", "semaphore-depth-macros/depth_16"] -depth_20 = ["semaphore-depth-config/depth_20", "semaphore-depth-macros/depth_20"] -depth_30 = ["semaphore-depth-config/depth_30", "semaphore-depth-macros/depth_30"] +depth_16 = [ + "semaphore-depth-config/depth_16", + "semaphore-depth-macros/depth_16", +] +depth_20 = [ + "semaphore-depth-config/depth_20", + "semaphore-depth-macros/depth_20", +] +depth_30 = [ + "semaphore-depth-config/depth_30", + "semaphore-depth-macros/depth_30", +] [[bench]] name = "cascading_merkle_tree" @@ -36,24 +44,40 @@ harness = false [dependencies] ark-bn254 = { version = "=0.4.0" } -ark-circom = { git = "https://github.com/arkworks-rs/circom-compat.git", rev="f97ac2b", features = ["circom-2"] } -ark-ec = { version = "0.4.1", default-features = false, features = ["parallel"] } -ark-ff = { version = "0.4.1", default-features = false, features = ["parallel", "asm"] } +ark-circom = { git = "https://github.com/arkworks-rs/circom-compat.git", rev = "f97ac2b", features = [ + "circom-2", +] } +ark-ec = { version = "0.4.1", default-features = false, features = [ + "parallel", +] } +ark-ff = { version = "0.4.1", default-features = false, features = [ + "parallel", + "asm", +] } ark-groth16 = { version = "=0.4.0", features = ["parallel"] } ark-relations = { version = "=0.4.0", default-features = false } -ark-std = { version = "0.4.0", default-features = false, features = ["parallel"] } +ark-std = { version = "0.4.0", default-features = false, features = [ + "parallel", +] } # TODO: Need to give mopro a example zkey for satisfying its tests # for now i just commented them out # ark-zkey = { git = "https://github.com/worldcoin/mopro" } ark-zkey = { path = "crates/ark-zkey" } +bytemuck = "1.18" color-eyre = "0.6" hex = "0.4.0" hex-literal = "0.4" +itertools = "0.13" num-bigint = { version = "0.4", default-features = false, features = ["rand"] } once_cell = "1.8" rand = "0.8.4" rayon = "1.5.1" -ruint = { version = "1.10.1", features = ["serde", "num-bigint", "ark-ff"] } +ruint = { version = "1.12.3", features = [ + "bytemuck", + "serde", + "num-bigint", + "ark-ff", +] } semaphore-depth-config = { path = "crates/semaphore-depth-config" } serde = "1.0" sha2 = "0.10.1" diff --git a/build.rs b/build.rs index b04bd86..4523ae7 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,4 @@ +use std::path::{absolute, PathBuf}; use std::{ fs::{create_dir, create_dir_all, File}, path::Path, diff --git a/src/cascading_merkle_tree/storage_ops.rs b/src/cascading_merkle_tree/storage_ops.rs index fa1b2f9..692c156 100644 --- a/src/cascading_merkle_tree/storage_ops.rs +++ b/src/cascading_merkle_tree/storage_ops.rs @@ -4,7 +4,6 @@ use color_eyre::{ eyre::{bail, ensure}, Result, }; -use itertools::Itertools; use rayon::prelude::*; use crate::{ @@ -153,7 +152,7 @@ where for height in 0..=depth { let row = self.row(height); let parents = self.row(height + 1); - let row_couple = row.tuples(); + let row_couple = itertools::Itertools::tuples(row); parents .zip(row_couple) diff --git a/src/generic_storage/mmap_vec.rs b/src/generic_storage/mmap_vec.rs index d9cac42..89d5d6c 100644 --- a/src/generic_storage/mmap_vec.rs +++ b/src/generic_storage/mmap_vec.rs @@ -1,8 +1,6 @@ -use std::{ - fs::{File, OpenOptions}, - ops::{Deref, DerefMut}, - path::Path, -}; +use std::fs::{File, OpenOptions}; +use std::ops::{Deref, DerefMut}; +use std::path::Path; use bytemuck::Pod; use color_eyre::eyre::{ensure, Context}; @@ -13,10 +11,10 @@ const META_SIZE: usize = std::mem::size_of::(); pub struct MmapVec { // This must be Option to properly uphold aliasing access safety guarantees // Look at the `resize` method for more details - mmap: Option, - file: File, + mmap: Option, + file: File, capacity: usize, - phantom: std::marker::PhantomData, + phantom: std::marker::PhantomData, } // Public API @@ -95,7 +93,10 @@ impl MmapVec { } let data_len = byte_len.saturating_sub(META_SIZE); - ensure!(data_len % std::mem::size_of::() == 0); + ensure!( + data_len % std::mem::size_of::() == 0, + "data must be divisible by size of T" + ); let capacity = data_len / std::mem::size_of::(); @@ -112,7 +113,7 @@ impl MmapVec { }; let len = s.storage_len(); - ensure!(len <= capacity); + ensure!(len <= capacity, "len must be lower than capacity"); Ok(s) } diff --git a/src/lib.rs b/src/lib.rs index 66cfc1c..bc38091 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,8 +17,6 @@ pub mod poseidon_tree; pub mod protocol; pub mod util; -pub mod lazy_merkle_tree; - use ark_bn254::Config; use ark_ec::bn::Bn; @@ -141,65 +139,65 @@ mod test { } } -#[cfg(feature = "bench")] -pub mod bench { - use crate::{ - hash_to_field, - identity::Identity, - poseidon_tree::LazyPoseidonTree, - protocol::{generate_proof, generate_witness}, - Field, - }; - use criterion::Criterion; - use semaphore_depth_config::get_supported_depths; - - pub fn group(criterion: &mut Criterion) { - for depth in get_supported_depths() { - bench_proof(criterion, *depth); - bench_witness(criterion, *depth); - } - crate::lazy_merkle_tree::bench::group(criterion); - } - - fn bench_proof(criterion: &mut Criterion, depth: usize) { - let leaf = Field::from(0); - - // Create tree - let mut hello = *b"hello"; - let id = Identity::from_secret(&mut hello, None); - let mut tree = LazyPoseidonTree::new(depth, leaf).derived(); - tree = tree.update(0, &id.commitment()); - let merkle_proof = tree.proof(0); - - // change signal and external_nullifier here - let signal_hash = hash_to_field(b"xxx"); - let external_nullifier_hash = hash_to_field(b"appId"); - - criterion.bench_function(&format!("proof_{depth}"), move |b| { - b.iter(|| { - generate_proof(&id, &merkle_proof, external_nullifier_hash, signal_hash).unwrap(); - }); - }); - } - - fn bench_witness(criterion: &mut Criterion, depth: usize) { - let leaf = Field::from(0); - - // Create tree - let mut hello = *b"hello"; - let id = Identity::from_secret(&mut hello, None); - let mut tree = LazyPoseidonTree::new(depth, leaf).derived(); - tree = tree.update(0, &id.commitment()); - let merkle_proof = tree.proof(0); - - // change signal and external_nullifier here - let signal_hash = hash_to_field(b"xxx"); - let external_nullifier_hash = hash_to_field(b"appId"); - - criterion.bench_function(&format!("witness_{depth}"), move |b| { - b.iter(|| { - generate_witness(&id, &merkle_proof, external_nullifier_hash, signal_hash); - }); - }); - } -} +// #[cfg(feature = "bench")] +// pub mod bench { +// use crate::{ +// hash_to_field, +// identity::Identity, +// poseidon_tree::LazyPoseidonTree, +// protocol::{generate_proof, generate_witness}, +// Field, +// }; +// use criterion::Criterion; +// use semaphore_depth_config::get_supported_depths; + +// pub fn group(criterion: &mut Criterion) { +// for depth in get_supported_depths() { +// bench_proof(criterion, *depth); +// bench_witness(criterion, *depth); +// } +// crate::lazy_merkle_tree::bench::group(criterion); +// } + +// fn bench_proof(criterion: &mut Criterion, depth: usize) { +// let leaf = Field::from(0); + +// // Create tree +// let mut hello = *b"hello"; +// let id = Identity::from_secret(&mut hello, None); +// let mut tree = LazyPoseidonTree::new(depth, leaf).derived(); +// tree = tree.update(0, &id.commitment()); +// let merkle_proof = tree.proof(0); + +// // change signal and external_nullifier here +// let signal_hash = hash_to_field(b"xxx"); +// let external_nullifier_hash = hash_to_field(b"appId"); + +// criterion.bench_function(&format!("proof_{depth}"), move |b| { +// b.iter(|| { +// generate_proof(&id, &merkle_proof, external_nullifier_hash, signal_hash).unwrap(); +// }); +// }); +// } + +// fn bench_witness(criterion: &mut Criterion, depth: usize) { +// let leaf = Field::from(0); + +// // Create tree +// let mut hello = *b"hello"; +// let id = Identity::from_secret(&mut hello, None); +// let mut tree = LazyPoseidonTree::new(depth, leaf).derived(); +// tree = tree.update(0, &id.commitment()); +// let merkle_proof = tree.proof(0); + +// // change signal and external_nullifier here +// let signal_hash = hash_to_field(b"xxx"); +// let external_nullifier_hash = hash_to_field(b"appId"); + +// criterion.bench_function(&format!("witness_{depth}"), move |b| { +// b.iter(|| { +// generate_witness(&id, &merkle_proof, external_nullifier_hash, signal_hash); +// }); +// }); +// } +// }