diff --git a/.gitignore b/.gitignore index fae9d28..d808a4d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ my_permanent_leveldb/ *.json *DS_Store *tar -release/ +/release/ diff --git a/Cargo.lock b/Cargo.lock index 63353f3..c411060 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,19 +107,19 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -159,7 +159,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.74", + "syn 2.0.77", "which", ] @@ -204,9 +204,12 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.10" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +dependencies = [ + "shlex", +] [[package]] name = "cexpr" @@ -276,9 +279,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.15" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11d8838454fda655dafd3accb2b6e2bea645b9e4078abe84a22ceb947235c5cc" +checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" dependencies = [ "clap_builder", "clap_derive", @@ -286,9 +289,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.15" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" +checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" dependencies = [ "anstream", "anstyle", @@ -298,14 +301,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -316,9 +319,9 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "cmake" -version = "0.1.50" +version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +checksum = "fb1e43aa7fd152b1f968787f7dbcdeb306d1867ff373c69955211876c053f91a" dependencies = [ "cc", ] @@ -389,9 +392,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -501,7 +504,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -512,7 +515,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -533,9 +536,9 @@ dependencies = [ [[package]] name = "diesel" -version = "2.2.2" +version = "2.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf97ee7261bb708fa3402fa9c17a54b70e90e3cb98afb3dc8999d5512cb03f94" +checksum = "158fe8e2e68695bd615d7e4f3227c0727b151330d3e253b525086c348d055d5e" dependencies = [ "bitflags 2.6.0", "byteorder", @@ -549,15 +552,15 @@ dependencies = [ [[package]] name = "diesel_derives" -version = "2.2.2" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6ff2be1e7312c858b2ef974f5c7089833ae57b5311b334b30923af58e5718d8" +checksum = "e7f2c3de51e2ba6bf2a648285696137aaf0f5f487bcbea93972fe8a364e131a4" dependencies = [ "diesel_table_macro_syntax", "dsl_auto_type", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -566,7 +569,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" dependencies = [ - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -602,7 +605,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -827,6 +830,12 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + [[package]] name = "hex" version = "0.4.3" @@ -850,9 +859,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -900,9 +909,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.3.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -933,11 +942,11 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" dependencies = [ - "hermit-abi", + "hermit-abi 0.4.0", "libc", "windows-sys 0.52.0", ] @@ -1003,9 +1012,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -1068,9 +1077,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.155" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libloading" @@ -1154,14 +1163,14 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] name = "mysqlclient-sys" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2aa3a303b6e9878b34811838301b00a56878693c47f9ac0ba397f91adc7bf12" +checksum = "478e2040dbc35c73927b77a2be91a496de19deab376a6982ed61e89592434619" dependencies = [ "pkg-config", "vcpkg", @@ -1274,7 +1283,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.9", "libc", ] @@ -1375,9 +1384,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.11" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95" +checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9" dependencies = [ "memchr", "thiserror", @@ -1386,9 +1395,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.11" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a548d2beca6773b1c244554d36fcf8548a8a58e74156968211567250e48e49a" +checksum = "4d3a6e3394ec80feb3b6393c725571754c6188490265c61aaf260810d6b95aa0" dependencies = [ "pest", "pest_generator", @@ -1396,22 +1405,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.11" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c93a82e8d145725dcbaf44e5ea887c8a869efdcc28706df2d08c69e17077183" +checksum = "94429506bde1ca69d1b5601962c73f4172ab4726571a59ea95931218cb0e930e" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] name = "pest_meta" -version = "2.7.11" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a941429fea7e08bedec25e4f6785b6ffaacc6b755da98df5ef3e7dcf4a124c4f" +checksum = "ac8a071862e93690b6e34e9a5fb8e33ff3734473ac0245b27232222c4906a33f" dependencies = [ "once_cell", "pest", @@ -1435,7 +1444,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -1452,9 +1461,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "plonky2" @@ -1516,9 +1525,9 @@ source = "git+https://github.com/okx/plonky2#140d97a8081cfae1d08e43199e13084c1ac [[package]] name = "portable-atomic" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" +checksum = "d30538d42559de6b034bc76fd6dd4c38961b1ee5c6c56e3808c50128fdbc22ce" [[package]] name = "powerfmt" @@ -1563,12 +1572,12 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.20" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -1592,9 +1601,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -1699,9 +1708,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "355ae415ccd3a04315d3f8246e86d67689ea74d88d915576e1589a351062a13b" dependencies = [ "bitflags 2.6.0", ] @@ -1788,9 +1797,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.6.0", "errno", @@ -1831,29 +1840,29 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.206" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b3e4cd94123dd520a128bcd11e34d9e9e423e7e3e50425cb1b4b1e3549d0284" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.206" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabfb6138d2383ea8208cf98ccf69cdfb1aff4088460681d84189aa259762f97" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] name = "serde_json" -version = "1.0.124" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66ad62847a56b3dba58cc891acd13884b9c61138d330c0d7b6181713d4fce38d" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", @@ -1871,7 +1880,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.3.0", + "indexmap 2.5.0", "serde", "serde_derive", "serde_json", @@ -1888,7 +1897,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -1957,9 +1966,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.74" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -1984,22 +1993,22 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -2117,7 +2126,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -2227,24 +2236,24 @@ checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "unroll" @@ -2309,34 +2318,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2344,22 +2354,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "which" @@ -2522,7 +2532,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -2542,7 +2552,6 @@ dependencies = [ "serde_json", "tracing", "zk-por-core", - "zk-por-db", "zk-por-tracing", ] diff --git a/crates/zk-por-cli/Cargo.toml b/crates/zk-por-cli/Cargo.toml index 5a67e95..82eda25 100644 --- a/crates/zk-por-cli/Cargo.toml +++ b/crates/zk-por-cli/Cargo.toml @@ -18,7 +18,6 @@ default = [] [dependencies] zk-por-tracing={path="../zk-por-tracing"} -zk-por-db={path="../zk-por-db"} zk-por-core={path="../zk-por-core"} plonky2={workspace=true} plonky2_field={workspace=true} diff --git a/crates/zk-por-cli/src/checker.rs b/crates/zk-por-cli/src/checker.rs new file mode 100644 index 0000000..3c6591e --- /dev/null +++ b/crates/zk-por-cli/src/checker.rs @@ -0,0 +1,75 @@ +use super::{constant::DEFAULT_BATCH_SIZE, prover::calculate_per_parse_account_num}; +use plonky2_field::types::{Field, PrimeField64}; + +use std::str::FromStr; +use zk_por_core::{ + config::ProverConfig, + error::PoRError, + parser::{AccountParser, FileAccountReader, FileManager, FilesCfg}, + types::F, +}; +use zk_por_tracing::{init_tracing, TraceConfig}; + +pub fn check_non_neg_user(cfg: ProverConfig) -> Result<(), PoRError> { + let trace_cfg: TraceConfig = cfg.log.into(); + let _g = init_tracing(trace_cfg); + + let batch_size = cfg.prover.batch_size.unwrap_or(DEFAULT_BATCH_SIZE); + let file_manager = FileManager {}; + let mut account_parser = FileAccountReader::new( + FilesCfg { + dir: std::path::PathBuf::from_str(&cfg.prover.user_data_path).unwrap(), + batch_size: batch_size, + tokens: cfg.prover.tokens.clone(), + }, + &file_manager, + ); + account_parser.log_state(); + let mut offset = 0; + let batch_prove_threads_num = cfg.prover.batch_prove_threads_num; + let per_parse_account_num = + calculate_per_parse_account_num(batch_size, batch_prove_threads_num); + + let batch_num = account_parser.total_num_of_users().div_ceil(batch_size); + let token_num = cfg.prover.tokens.len(); + let mut parse_num = 0; + + tracing::info!( + "start to check {} accounts with {} tokens, {} batch size", + account_parser.total_num_of_users(), + token_num, + batch_size, + ); + + while offset < account_parser.total_num_of_users() { + let accounts = account_parser.read_n_accounts(offset, per_parse_account_num, &file_manager); + let account_num = accounts.len(); + + tracing::info!( + "parse {} times, with number of accounts {}, number of batches {}", + parse_num, + account_num, + batch_num, + ); + parse_num += 1; + tracing::info!("finish checking {} accounts", offset); + offset += per_parse_account_num; + + for account in accounts { + let equity_sum = + account.equity.iter().fold(F::ZERO, |acc, x| acc + *x).to_canonical_u64(); + let debt_sum = account.debt.iter().fold(F::ZERO, |acc, x| acc + *x).to_canonical_u64(); + + if equity_sum < debt_sum { + tracing::error!( + "account {} has negative equity, the equity sum {}, the debt sum {}", + account.id, + equity_sum, + debt_sum + ); + return Err(PoRError::InvalidUser); + } + } + } + Ok(()) +} diff --git a/crates/zk-por-cli/src/constant.rs b/crates/zk-por-cli/src/constant.rs index d780dba..31103eb 100644 --- a/crates/zk-por-cli/src/constant.rs +++ b/crates/zk-por-cli/src/constant.rs @@ -1,6 +1,6 @@ pub const RECURSION_BRANCHOUT_NUM: usize = 64; pub const DEFAULT_BATCH_SIZE: usize = 1024; -pub const GLOBAL_PROOF_FILENAME: &str = "global_proof.json"; +pub const GLOBAL_PROOF_FILENAME: &str = "sum_proof_data.json"; pub const GLOBAL_INFO_FILENAME: &str = "global_info.json"; pub const USER_PROOF_DIRNAME: &str = "user_proofs"; pub const DEFAULT_USER_PROOF_FILE_PATTERN: &str = "*_inclusion_proof.json"; diff --git a/crates/zk-por-cli/src/lib.rs b/crates/zk-por-cli/src/lib.rs index 3ffdd5c..7716968 100644 --- a/crates/zk-por-cli/src/lib.rs +++ b/crates/zk-por-cli/src/lib.rs @@ -1,3 +1,4 @@ +pub mod checker; pub mod constant; pub mod prover; pub mod verifier; diff --git a/crates/zk-por-cli/src/main.rs b/crates/zk-por-cli/src/main.rs index 17a1391..e0e3af8 100644 --- a/crates/zk-por-cli/src/main.rs +++ b/crates/zk-por-cli/src/main.rs @@ -1,7 +1,12 @@ -use std::{path::PathBuf, str::FromStr}; +use std::{ + io::{stdin, Read}, + path::PathBuf, + str::FromStr, +}; use clap::{Parser, Subcommand}; use zk_por_cli::{ + checker::check_non_neg_user, constant::{DEFAULT_USER_PROOF_FILE_PATTERN, GLOBAL_PROOF_FILENAME}, prover::prove, verifier::{verify_global, verify_user}, @@ -27,6 +32,11 @@ pub enum ZkPorCommitCommands { #[arg(short, long)] output_path: String, // path to output file }, + CheckNonNegUser { + #[arg(short, long)] + cfg_path: String, // path to config file + }, + VerifyGlobal { #[arg(short, long)] proof_path: String, @@ -51,6 +61,13 @@ impl Execute for Option { prove(prover_cfg, output_path) } + Some(ZkPorCommitCommands::CheckNonNegUser { cfg_path }) => { + let cfg = zk_por_core::config::ProverConfig::load(&cfg_path) + .map_err(|e| PoRError::ConfigError(e))?; + let prover_cfg = cfg.try_deserialize().unwrap(); + check_non_neg_user(prover_cfg) + } + Some(ZkPorCommitCommands::VerifyGlobal { proof_path: global_proof_path }) => { let global_proof_path = PathBuf::from_str(&global_proof_path).unwrap(); verify_global(global_proof_path, true) @@ -66,8 +83,21 @@ impl Execute for Option { None => { println!("============Validation started============"); - let global_proof_path = PathBuf::from_str(GLOBAL_PROOF_FILENAME).unwrap(); - let user_proof_path_pattern = DEFAULT_USER_PROOF_FILE_PATTERN.to_owned(); + let exec_parent_path = std::env::current_exe() + .expect("fail to get current exe path") + .parent() + .unwrap() + .to_path_buf(); + + // join the dir path and GLOBAL_PROOF_FILENAME + let global_proof_path = exec_parent_path.join(GLOBAL_PROOF_FILENAME); + + let user_proof_path_pattern = exec_parent_path + .join(DEFAULT_USER_PROOF_FILE_PATTERN) + .to_str() + .unwrap() + .to_string(); + if verify_global(global_proof_path.clone(), false).is_ok() { println!("Total sum and non-negative constraint validation passed") } else { @@ -89,6 +119,7 @@ impl Execute for Option { fn main() -> std::result::Result<(), PoRError> { let cli = Cli::parse(); let r = cli.command.execute(); - println!("Execution result: {:?}", r); + println!("Execution result: {:?}. Press Enter to quit...", r); + stdin().read_exact(&mut [0]).unwrap(); Ok(()) } diff --git a/crates/zk-por-cli/src/prover.rs b/crates/zk-por-cli/src/prover.rs index ac5c84d..e0bcd3b 100644 --- a/crates/zk-por-cli/src/prover.rs +++ b/crates/zk-por-cli/src/prover.rs @@ -6,11 +6,11 @@ use indicatif::ProgressBar; use plonky2::hash::hash_types::HashOut; use plonky2_field::types::PrimeField64; use rayon::{iter::ParallelIterator, prelude::*}; -use serde_json::json; + use std::{ fs, fs::File, - io::Write, + io::{BufWriter, Write}, path::PathBuf, str::FromStr, sync::{Arc, RwLock}, @@ -20,7 +20,7 @@ use zk_por_core::{ circuit_config::{get_recursive_circuit_configs, STANDARD_CONFIG}, circuit_registry::registry::CircuitRegistry, config::{ConfigProver, ProverConfig}, - database::{PoRDB, PoRGMSTMemoryDB, PoRLevelDB, PoRLevelDBOption}, + database::{init_db, PoRDB}, e2e::{batch_prove_accounts, prove_subproofs}, error::PoRError, global::{GlobalConfig, GlobalMst, GLOBAL_MST}, @@ -35,7 +35,7 @@ use zk_por_core::{ use zk_por_tracing::{init_tracing, TraceConfig}; // as we use one thread to prove each batch, we load num_cpus batches to increase the parallelism. -fn calculate_per_parse_account_num(batch_size: usize, threads_num: usize) -> usize { +pub fn calculate_per_parse_account_num(batch_size: usize, threads_num: usize) -> usize { let num_cpus = num_cpus::get(); let num_cpus = if threads_num < num_cpus { threads_num } else { num_cpus }; num_cpus * batch_size @@ -64,15 +64,7 @@ pub fn prove(cfg: ProverConfig, proof_output_path: PathBuf) -> Result<(), PoRErr let user_proof_output_path = proof_output_path.join(USER_PROOF_DIRNAME); ensure_output_dir_empty(user_proof_output_path)?; - let mut database: Box; - if let Some(level_db_config) = cfg.db { - database = Box::new(PoRLevelDB::new(PoRLevelDBOption { - user_map_dir: level_db_config.level_db_user_path.to_string(), - gmst_dir: level_db_config.level_db_gmst_path.to_string(), - })); - } else { - database = Box::new(PoRGMSTMemoryDB::new()); - } + let mut database = init_db(cfg.db); let batch_size = cfg.prover.batch_size.unwrap_or(DEFAULT_BATCH_SIZE); let token_num = cfg.prover.tokens.len(); @@ -362,12 +354,14 @@ fn dump_proofs( let user_proof_output_dir_path = proof_output_dir_path.join(USER_PROOF_DIRNAME); // directory has been checked empty before. let global_proof_output_path = proof_output_dir_path.join(GLOBAL_PROOF_FILENAME); - let mut global_proof_file = + let global_proof_file = File::create(global_proof_output_path.clone()).map_err(|e| PoRError::Io(e))?; - global_proof_file - .write_all(json!(root_proof).to_string().as_bytes()) - .map_err(|e| return PoRError::Io(e))?; + let mut global_proof_writer = BufWriter::new(global_proof_file); + serde_json::to_writer(&mut global_proof_writer, &root_proof).expect( + format!("fail to dump global proof file to {:?}", global_proof_output_path).as_str(), + ); + global_proof_writer.flush()?; /////////////////////////////////////////////// let hash_offset = RecursiveTargets::::pub_input_hash_offset(); @@ -395,12 +389,14 @@ fn dump_proofs( }; let global_info_output_path = proof_output_dir_path.join(GLOBAL_INFO_FILENAME); - let mut global_info_file = + let global_info_file = File::create(global_info_output_path.clone()).map_err(|e| PoRError::Io(e))?; - global_info_file - .write_all(json!(info).to_string().as_bytes()) - .map_err(|e| return PoRError::Io(e))?; + let mut global_info_writer = BufWriter::new(global_info_file); + serde_json::to_writer(&mut global_info_writer, &info).expect( + format!("fail to dump global info file to {:?}", global_proof_output_path).as_str(), + ); + global_info_writer.flush()?; /////////////////////////////////////////////// // generate and dump proof for each user @@ -447,15 +443,20 @@ fn dump_proofs( let user_proof_output_path = user_proof_output_dir_path.join(format!("{}.json", account.id)); - let mut user_proof_file = File::create(user_proof_output_path).expect( + let user_proof_file = File::create(user_proof_output_path).expect( format!("fail to create user proof file for account {}", user_proof.account.id) .as_str(), ); - user_proof_file.write_all(json!(user_proof).to_string().as_bytes()).expect( + let mut user_proof_writer = BufWriter::new(user_proof_file); + serde_json::to_writer(&mut user_proof_writer, &user_proof).expect( format!("fail to write user proof file for account {}", user_proof.account.id) .as_str(), ); + user_proof_writer.flush().expect( + format!("fail to write user proof file for account {}", user_proof.account.id) + .as_str(), + ) }); bar.inc(chunk.len() as u64); diff --git a/crates/zk-por-cli/src/verifier.rs b/crates/zk-por-cli/src/verifier.rs index d3c9f9a..8045a1b 100644 --- a/crates/zk-por-cli/src/verifier.rs +++ b/crates/zk-por-cli/src/verifier.rs @@ -70,7 +70,9 @@ pub fn verify_user( .map(|user_proof_path| { let merkle_path = File::open(&user_proof_path).unwrap(); let reader = std::io::BufReader::new(merkle_path); - let proof: MerkleProof = from_reader(reader).unwrap(); + let proof: MerkleProof = from_reader(reader).expect( + format!("fail to parse user proof from path {:?}", user_proof_path).as_str(), + ); let result = proof.verify_merkle_proof(root_hash); if verbose { bar.inc(1); diff --git a/crates/zk-por-core/Cargo.toml b/crates/zk-por-core/Cargo.toml index 5f6c147..64179b2 100644 --- a/crates/zk-por-core/Cargo.toml +++ b/crates/zk-por-core/Cargo.toml @@ -18,7 +18,7 @@ default = [] verifier = [] [dependencies] -zk-por-db={path="../zk-por-db"} +zk-por-db={path="../zk-por-db", optional = true} zk-por-tracing={path="../zk-por-tracing"} plonky2={workspace=true} plonky2_field={workspace=true} diff --git a/crates/zk-por-core/src/account.rs b/crates/zk-por-core/src/account.rs index c811da4..8b6bad0 100644 --- a/crates/zk-por-core/src/account.rs +++ b/crates/zk-por-core/src/account.rs @@ -6,18 +6,78 @@ use plonky2::{ hash::{hash_types::HashOut, poseidon::PoseidonHash}, plonk::config::Hasher, }; -use plonky2_field::types::Field; +use plonky2_field::types::{Field, PrimeField64}; use rand::Rng; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// A struct representing a users account. It represents their equity and debt as a Vector of goldilocks field elements. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone)] pub struct Account { pub id: String, // 256 bit hex string pub equity: Vec, pub debt: Vec, } +impl Serialize for Account { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + use serde::ser::SerializeStruct; + let mut state = serializer.serialize_struct("Account", 3)?; + state.serialize_field("id", &self.id)?; + // Custom serialization for equity and debt to ensure they are serialized in a specific format if needed + let equity_as_strings: Vec = self + .equity + .iter() + .map(|e| { + let num = e.to_canonical_u64(); + num.to_string() + }) + .collect(); + state.serialize_field("equity", &equity_as_strings)?; + + let debt_as_strings: Vec = self + .debt + .iter() + .map(|e| { + let num = e.to_canonical_u64(); + num.to_string() + }) + .collect(); + state.serialize_field("debt", &debt_as_strings)?; + state.end() + } +} + +impl<'de> Deserialize<'de> for Account { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + #[derive(Deserialize)] + struct InnerAccount { + id: String, + equity: Vec, + debt: Vec, + } + + let helper = InnerAccount::deserialize(deserializer)?; + let equity = helper + .equity + .iter() + .map(|e| F::from_canonical_u64(u64::from_str_radix(e, 10).unwrap())) + .collect(); + let debt = helper + .debt + .iter() + .map(|e| F::from_canonical_u64(u64::from_str_radix(e, 10).unwrap())) + .collect(); + + Ok(Account { id: helper.id, equity: equity, debt: debt }) + } +} + impl Account { /// Gets the account hash for a given account. pub fn get_hash(&self) -> HashOut { @@ -117,3 +177,30 @@ pub fn gen_empty_accounts(batch_size: usize, num_assets: usize) -> Vec ]; accounts } + +#[cfg(test)] +mod tests { + use super::*; + use serde_json; + + #[test] + fn test_account_json_marshalling() { + // Step 1: Create an instance of `Account` + let original_account = Account { + id: "1".to_owned(), // Assuming `id` is of type that implements `Serialize` and `Deserialize` + equity: vec![F::from_canonical_u64(0), F::from_canonical_u64(1)], + debt: vec![F::from_canonical_u64(0), F::from_canonical_u64(2)], + }; + + // Step 2: Serialize the `Account` instance to a JSON string + let json_string = serde_json::to_string(&original_account).unwrap(); + + // Step 3: Deserialize the JSON string back into an `Account` instance + let deserialized_account: Account = serde_json::from_str(&json_string).unwrap(); + + // Step 4: Assert that the original and deserialized instances are equal + assert_eq!(original_account.id, deserialized_account.id); + assert_eq!(original_account.equity, deserialized_account.equity); + assert_eq!(original_account.debt, deserialized_account.debt); + } +} diff --git a/crates/zk-por-core/src/database.rs b/crates/zk-por-core/src/database.rs index 5d32fcf..12779c2 100644 --- a/crates/zk-por-core/src/database.rs +++ b/crates/zk-por-core/src/database.rs @@ -1,10 +1,16 @@ -use std::str::FromStr; - use hex::ToHex; -use plonky2::{hash::hash_types::HashOut, plonk::config::GenericHashOut}; +use plonky2::hash::hash_types::HashOut; use rand::Rng; + +#[cfg(feature = "zk-por-db")] +use plonky2::plonk::config::GenericHashOut; +#[cfg(feature = "zk-por-db")] +use std::str::FromStr; +#[cfg(feature = "zk-por-db")] use zk_por_db::LevelDb; +use super::config::ConfigDb; + use crate::{error::PoRError, global::GLOBAL_MST, types::F}; use std::{collections::HashMap, sync::RwLock}; #[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)] @@ -70,11 +76,13 @@ pub struct PoRLevelDBOption { pub gmst_dir: String, } +#[cfg(feature = "zk-por-db")] pub struct PoRLevelDB { user_db: LevelDb, gmst_db: LevelDb, // we use i32 as a key of type u32 is not provided by default in leveldb } +#[cfg(feature = "zk-por-db")] impl PoRLevelDB { pub fn new(opt: PoRLevelDBOption) -> Self { Self { @@ -84,6 +92,7 @@ impl PoRLevelDB { } } +#[cfg(feature = "zk-por-db")] impl PoRDB for PoRLevelDB { fn add_batch_users(&mut self, batches: Vec<(UserId, u32)>) { let batches = batches @@ -124,6 +133,27 @@ impl PoRDB for PoRLevelDB { } } +pub fn init_db(db_config: Option) -> Box { + let database: Box; + if let Some(level_db_config) = db_config { + #[cfg(feature = "zk-por-db")] + { + database = Box::new(PoRLevelDB::new(PoRLevelDBOption { + user_map_dir: level_db_config.level_db_user_path.to_string(), + gmst_dir: level_db_config.level_db_gmst_path.to_string(), + })); + } + + #[cfg(not(feature = "zk-por-db"))] + { + _ = level_db_config; + panic!("leveldb feature is not enabled"); + } + } else { + database = Box::new(PoRGMSTMemoryDB::new()); + } + database +} pub struct PoRMemoryDB { user_map: HashMap, gmst_map: HashMap>, @@ -192,10 +222,14 @@ impl PoRDB for PoRGMSTMemoryDB { #[cfg(test)] mod test { use plonky2::{field::types::Sample, hash::hash_types::HashOut}; + + #[cfg(feature = "zk-por-db")] use tempdir::TempDir; + #[cfg(feature = "zk-por-db")] + use crate::database::{PoRLevelDB, PoRLevelDBOption}; use crate::{ - database::{PoRDB, PoRLevelDB, PoRLevelDBOption, PoRMemoryDB, UserId}, + database::{PoRDB, PoRMemoryDB, UserId}, types::F, }; use std::sync::RwLock; @@ -226,6 +260,7 @@ mod test { } #[test] + #[cfg(feature = "zk-por-db")] fn test_leveldb() { let tempdir_user = TempDir::new("example_user").unwrap(); let tempdir_gmst = TempDir::new("example_gmst").unwrap(); diff --git a/crates/zk-por-core/src/global.rs b/crates/zk-por-core/src/global.rs index 6cac866..ebce391 100644 --- a/crates/zk-por-core/src/global.rs +++ b/crates/zk-por-core/src/global.rs @@ -158,13 +158,6 @@ impl GlobalMst { /// `recursive_level` count from bottom to top; recursive_level = 1 means the bottom layer; increase whilve moving to the top. pub fn set_recursive_hash(&mut self, recursive_level: usize, index: usize, hash: HashOut) { let idx = GlobalMst::get_recursive_global_index(&self.cfg, recursive_level, index); - tracing::debug!( - "set_recursive_hash, recursive_level: {:?}, index: {:?}, hash: {:?}, idx: {:?}", - recursive_level, - index, - hash, - idx, - ); self.inner[idx] = hash; } diff --git a/crates/zk-por-core/src/merkle_proof.rs b/crates/zk-por-core/src/merkle_proof.rs index cc646ff..fb3ff6b 100644 --- a/crates/zk-por-core/src/merkle_proof.rs +++ b/crates/zk-por-core/src/merkle_proof.rs @@ -1,10 +1,10 @@ use itertools::Itertools; use plonky2::{ hash::{hash_types::HashOut, poseidon::PoseidonHash}, - plonk::config::Hasher, + plonk::config::{GenericHashOut, Hasher}, }; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; -use serde::{Deserialize, Serialize}; +use serde::{self, Deserialize, Deserializer, Serialize, Serializer}; use crate::{ account::Account, @@ -111,12 +111,76 @@ pub fn get_recursive_siblings_index( /// We use this wrapper struct for the left and right hashes of our recursive siblings. This is needed so a user knows the position of /// their own hash when hashing. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq)] pub struct RecursiveHashes { left_hashes: Vec>, right_hashes: Vec>, } +impl Serialize for RecursiveHashes { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + use serde::ser::SerializeStruct; + let mut state = serializer.serialize_struct("RecursiveHashes", 2)?; + + let left_hashes: Vec = self + .left_hashes + .iter() + .map(|e| { + let bytes = e.to_bytes(); + hex::encode(&bytes) + }) + .collect(); + state.serialize_field("left_hashes", &left_hashes)?; + + let right_hashes: Vec = self + .right_hashes + .iter() + .map(|e| { + let bytes = e.to_bytes(); + hex::encode(&bytes) + }) + .collect(); + state.serialize_field("right_hashes", &right_hashes)?; + state.end() + } +} + +impl<'de> Deserialize<'de> for RecursiveHashes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + #[derive(Deserialize)] + struct Inner { + left_hashes: Vec, + right_hashes: Vec, + } + + let helper = Inner::deserialize(deserializer)?; + let left_hashes = helper + .left_hashes + .iter() + .map(|e| { + let bytes = hex::decode(e).unwrap(); + HashOut::from_bytes(&bytes) + }) + .collect(); + let right_hashes = helper + .right_hashes + .iter() + .map(|e| { + let bytes = hex::decode(e).unwrap(); + HashOut::from_bytes(&bytes) + }) + .collect(); + + Ok(RecursiveHashes { left_hashes: left_hashes, right_hashes: right_hashes }) + } +} + impl RecursiveHashes { pub fn new_from_index(indexes: &RecursiveIndex, db: Arc) -> Self { let left_hashes = indexes @@ -146,7 +210,7 @@ impl RecursiveHashes { /// Hashes for a given users merkle proof of inclusion siblings in the Global Merkle Sum Tree, also includes account data as it is needed for the verification /// of the merkle proof (needed to calculate own hash) -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone)] pub struct MerkleProof { pub account: Account, pub index: usize, @@ -154,6 +218,63 @@ pub struct MerkleProof { pub recursive_tree_siblings: Vec, } +impl Serialize for MerkleProof { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + use serde::ser::SerializeStruct; + let mut state = serializer.serialize_struct("MerkleProof", 4)?; + state.serialize_field("account", &self.account)?; + state.serialize_field("index", &self.index)?; + + let sum_tree_siblings: Vec = self + .sum_tree_siblings + .iter() + .map(|e| { + let bytes = e.to_bytes(); + hex::encode(&bytes) + }) + .collect(); + + state.serialize_field("sum_tree_siblings", &sum_tree_siblings)?; + state.serialize_field("recursive_tree_siblings", &self.recursive_tree_siblings)?; + state.end() + } +} + +impl<'de> Deserialize<'de> for MerkleProof { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + #[derive(Deserialize)] + struct InnerMerkleProof { + account: Account, + index: usize, + sum_tree_siblings: Vec, + recursive_tree_siblings: Vec, + } + + let helper = InnerMerkleProof::deserialize(deserializer)?; + let sum_tree_siblings = helper + .sum_tree_siblings + .iter() + .map(|e| { + let bytes = hex::decode(e).unwrap(); + HashOut::from_bytes(&bytes) + }) + .collect(); + + Ok(MerkleProof { + account: helper.account, + index: helper.index, + sum_tree_siblings: sum_tree_siblings, + recursive_tree_siblings: helper.recursive_tree_siblings, + }) + } +} + impl MerkleProof { pub fn new_from_account( account: &Account, @@ -466,112 +587,83 @@ pub mod test { res.unwrap(); } - // THIS IS THE TEST DATA FOR VERIFY - // #[test] - // pub fn poseidon_hash() { - // let equity = vec![3,3,3,].iter().map(|x| F::from_canonical_u32(*x)).collect_vec(); - // let debt = vec![1,1,1,].iter().map(|x| F::from_canonical_u32(*x)).collect_vec(); - - // let accounts = vec![ - // Account{ - // id: "320b5ea99e653bc2b593db4130d10a4efd3a0b4cc2e1a6672b678d71dfbd33ad".to_string(), - // equity: equity.clone(), - // debt: debt.clone(), - // }, - // Account{ - // id: "320b5ea99e653bc2b593db4130d10a4efd3a0b4cc2e1a6672b678d71dfbd33ac".to_string(), - // equity: equity.clone(), - // debt: debt.clone(), - // }, - // Account{ - // id: "320b5ea99e653bc2b593db4130d10a4efd3a0b4cc2e1a6672b678d71dfbd33ab".to_string(), - // equity: equity.clone(), - // debt: debt.clone(), - // }, - // Account{ - // id: "320b5ea99e653bc2b593db4130d10a4efd3a0b4cc2e1a6672b678d71dfbd33aa".to_string(), - // equity: equity.clone(), - // debt: debt.clone(), - // }, - // Account{ - // id: "320b5ea99e653bc2b593db4130d10a4efd3a0b4cc2e1a6672b678d71dfbd33a1".to_string(), - // equity: equity.clone(), - // debt: debt.clone(), - // }, - // Account{ - // id: "320b5ea99e653bc2b593db4130d10a4efd3a0b4cc2e1a6672b678d71dfbd33a2".to_string(), - // equity: equity.clone(), - // debt: debt.clone(), - // }, - // Account{ - // id: "320b5ea99e653bc2b593db4130d10a4efd3a0b4cc2e1a6672b678d71dfbd33a3".to_string(), - // equity: equity.clone(), - // debt: debt.clone(), - // }, - // Account{ - // id: "320b5ea99e653bc2b593db4130d10a4efd3a0b4cc2e1a6672b678d71dfbd33a4".to_string(), - // equity: equity.clone(), - // debt: debt.clone(), - // } - // ]; - - // let msts: Vec = accounts - // .chunks(2) - // .map(|account_batch| MerkleSumTree::new_tree_from_accounts(&account_batch.to_vec())) - // .collect(); - - // let mst_hashes = msts.iter().map(|x| x.merkle_sum_tree.iter().map(|y| y.hash).collect_vec()).collect_vec(); - // println!("msts:{:?}", mst_hashes); - // let inputs = vec![ - // HashOut::from_vec( - // vec![ - // 8699257539652901730, - // 12847577670763395377, - // 14540605839220144846, - // 1921995570040415498, - // ] - // .iter() - // .map(|x| F::from_canonical_u64(*x)) - // .collect::>(), - // ), - // HashOut::from_vec( - // vec![ - // 15026394135096265436, - // 13313300609834454638, - // 10151802728958521275, - // 6200471959130767555, - // ] - // .iter() - // .map(|x| F::from_canonical_u64(*x)) - // .collect::>(), - // ), - // HashOut::from_vec( - // vec![ - // 2010803994799996791, - // 568450490466247075, - // 18209684900543488748, - // 7678193912819861368, - // ] - // .iter() - // .map(|x| F::from_canonical_u64(*x)) - // .collect::>(), - // ), - // HashOut::from_vec( - // vec![ - // 13089029781628355232, - // 10704046654659337561, - // 15794212269117984095, - // 15948192230150472783, - // ] - // .iter() - // .map(|x| F::from_canonical_u64(*x)) - // .collect::>(), - // ), - // ]; - - // let hash = PoseidonHash::hash_no_pad( - // inputs.iter().map(|x| x.elements).flatten().collect_vec().as_slice(), - // ); - // println!("Hash: {:?}", hash); - // } + #[test] + pub fn test_json_merkle_proof() { + let _gmst = GlobalMst::new(GlobalConfig { + num_of_tokens: 3, + num_of_batches: 4, + batch_size: 2, + recursion_branchout_num: 4, + }); + + let equity = vec![0, 3, 3].iter().map(|x| F::from_canonical_u32(*x)).collect_vec(); + let debt = vec![1, 1, 1].iter().map(|x| F::from_canonical_u32(*x)).collect_vec(); + + let sum_tree_siblings = vec![HashOut::from_vec( + vec![ + 7609058119952049295, + 8895839458156070742, + 1052773619972611009, + 6038312163525827182, + ] + .iter() + .map(|x| F::from_canonical_u64(*x)) + .collect::>(), + )]; + + let recursive_tree_siblings = vec![RecursiveHashes { + left_hashes: vec![], + right_hashes: vec![ + HashOut::from_vec( + vec![ + 15026394135096265436, + 13313300609834454638, + 10151802728958521275, + 6200471959130767555, + ] + .iter() + .map(|x| F::from_canonical_u64(*x)) + .collect::>(), + ), + HashOut::from_vec( + vec![ + 2010803994799996791, + 568450490466247075, + 18209684900543488748, + 7678193912819861368, + ] + .iter() + .map(|x| F::from_canonical_u64(*x)) + .collect::>(), + ), + HashOut::from_vec( + vec![ + 13089029781628355232, + 10704046654659337561, + 15794212269117984095, + 15948192230150472783, + ] + .iter() + .map(|x| F::from_canonical_u64(*x)) + .collect::>(), + ), + ], + }]; + + let account = Account { + id: "320b5ea99e653bc2b593db4130d10a4efd3a0b4cc2e1a6672b678d71dfbd33ad".to_string(), + equity: equity.clone(), + debt: debt.clone(), + }; + + let merkle_proof = + MerkleProof { account, sum_tree_siblings, recursive_tree_siblings, index: 0 }; + + let json_string = serde_json::to_string(&merkle_proof).unwrap(); + + // Step 3: Deserialize the JSON string back into an `Account` instance + let deserialized_merkle_proof: MerkleProof = serde_json::from_str(&json_string).unwrap(); + assert_eq!(merkle_proof.index, deserialized_merkle_proof.index); + assert_eq!(merkle_proof.sum_tree_siblings, deserialized_merkle_proof.sum_tree_siblings); + } } diff --git a/crates/zk-por-core/src/parser.rs b/crates/zk-por-core/src/parser.rs index bb78420..98de05c 100644 --- a/crates/zk-por-core/src/parser.rs +++ b/crates/zk-por-core/src/parser.rs @@ -200,7 +200,7 @@ impl AccountParser for FileAccountReader { let mut filled_len = 0; if self.offset < self.buffered_accounts.len() { - let filled_len = self.buffered_accounts.len() - self.offset; + filled_len = self.buffered_accounts.len() - self.offset; result[0..filled_len].clone_from_slice(&self.buffered_accounts[(self.offset)..]); } let mut missing_len = result.len() - (self.buffered_accounts.len() - self.offset); @@ -258,28 +258,27 @@ pub fn parse_account_state(parsed_data: &Map, tokens: &Vec().unwrap(); + let abs_val = parsed_balance.abs() as u64; + if parsed_balance < 0 { + parsed_debt = abs_val; + } else { + parsed_equity = abs_val; + } } - let parsed_val = parsed_token.unwrap().as_str().unwrap().parse::().unwrap(); - let abs_val = parsed_val.abs() as u64; - - if parsed_val < 0 { - parsed_debts.push(F::from_canonical_u64(abs_val)); - parsed_equities.push(F::ZERO); - } else { - parsed_equities.push(F::from_canonical_u64(abs_val)); - parsed_debts.push(F::ZERO); - } + parsed_equities.push(F::from_canonical_u64(parsed_equity)); + parsed_debts.push(F::from_canonical_u64(parsed_debt)); } Account { id: account_id.into(), equity: parsed_equities, debt: parsed_debts } diff --git a/docs/release.md b/docs/release.md index 1d1d785..1e8f99c 100644 --- a/docs/release.md +++ b/docs/release.md @@ -1,6 +1,13 @@ # Config Edit `config/default.toml` such that `user_data_path` is the directory containing the user files only. Currently, it is set to `./sample_data` for demo. +# Check +check all user accounst are non-negative +``` +cfg_dir_path="config" +./zk-por-checker check-non-neg-user --cfg-path "${cfg_dir_path}" --output-path "${output_proof_dir_path}" +``` + # Prove ``` cfg_dir_path="config" @@ -10,7 +17,7 @@ output_proof_dir_path="proof" ``` In the current directory, a directory `proof` is generated with the below files: ``` -- global_proof.json # the sum and non-negative proof +- sum_proof_data.json # the sum and non-negative proof - global_info.json # contains the root hash, the sum of equity, debt and balance (equity - debt) - user-proofs/ # directory containing user inclusion proofs, one user per file named with accountID - xxxxxxx.json @@ -20,9 +27,9 @@ In the current directory, a directory `proof` is generated with the below files: ## Verify only global proof For internal use. ``` -global_proof_path="./proof/global_proof.json" +sum_proof_data_path="./proof/sum_proof_data.json" -./zk-por-verifier verify-global --proof-path "${global_proof_path}" +./zk_STARK_Validator_v2 verify-global --proof-path "${sum_proof_data_path}" ``` If successful, the console shows ``` @@ -36,7 +43,7 @@ For internal use. ``` user_proof_path_pattern="./proof/user_proofs/*.json" # use wildcard to verify multiple files -./zk-por-verifier verify-user --global-proof-path "${global_proof_path}" --user-proof-path-pattern "${user_proof_path_pattern}" +./zk_STARK_Validator_v2 verify-user --global-proof-path "${sum_proof_data_path}" --user-proof-path-pattern "${user_proof_path_pattern}" ``` If successful, the console shows ``` @@ -49,13 +56,13 @@ Execution result: Ok(()) ## Global proof and user proofs For external users to verify, ``` -# the binary will look for global_proof.json and any files with *_inclusion_proof.json in the same directory for verification. So we first copy them to the current directory. +# the binary will look for sum_proof_data.json and any files with *_inclusion_proof.json in the same directory for verification. So we first copy them to the current directory. -cp proof/global_proof.json ./global_proof.json +cp proof/sum_proof_data.json ./sum_proof_data.json # copy any one of user proofs. cp proof/user_proofs/$(ls proof/user_proofs/ | head -n 1) ./user_inclusion_proof.json -./zk-por-verifier +./zk_STARK_Validator_v2 ``` If successful, the console shows: ``` diff --git a/rust-toolchain.toml b/rust-toolchain.toml index e61a9e3..44727f9 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2024-07-25" +channel = "nightly-2024-09-25" components = [] targets = [ # Linux diff --git a/scripts/release.sh b/scripts/release.sh deleted file mode 100755 index 39e4ab7..0000000 --- a/scripts/release.sh +++ /dev/null @@ -1,16 +0,0 @@ -rm -rf release -mkdir -p release/{config,sample_data} - -cargo build --release -mv target/release/zk-por-cli release/zk-por-prover -cargo build --features zk-por-core/verifier --release -mv target/release/zk-por-cli release/zk-por-verifier - -mkdir -p release/config -sed 's|/opt/data/zkpor/users/|./sample_data/|g' config/default.toml > release/config/default.toml - -mkdir -p release/sample_data -cp -r test-data/batch0.json release/sample_data -cp docs/release.md release/README.md - -tar -cvf zk-por.tar ./release/ \ No newline at end of file diff --git a/scripts/release/prover/aarch64-apple-darwin.sh b/scripts/release/prover/aarch64-apple-darwin.sh new file mode 100755 index 0000000..2a743e5 --- /dev/null +++ b/scripts/release/prover/aarch64-apple-darwin.sh @@ -0,0 +1,4 @@ +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +. "$DIR/common.sh" + +build_and_package aarch64-apple-darwin \ No newline at end of file diff --git a/scripts/release/prover/common.sh b/scripts/release/prover/common.sh new file mode 100755 index 0000000..c2c9f1c --- /dev/null +++ b/scripts/release/prover/common.sh @@ -0,0 +1,25 @@ +function build_and_package() { + TARGET=$1 + rustup target add $TARGET + RELEASE_TMP_DIR="./release_tmp" + rm -rf ${RELEASE_TMP_DIR} + mkdir -p ${RELEASE_TMP_DIR}/{config,sample_data} + + RUSTFLAGS="-C target-feature=+crt-static" cargo build --features zk-por-core/zk-por-db --release --target ${TARGET} --package zk-por-cli --bin zk-por-cli + + mv target/${TARGET}/release/zk-por-cli ${RELEASE_TMP_DIR}/zk-por-prover + + RUSTFLAGS="-C target-feature=+crt-static" cargo build --features zk-por-core/verifier --release --target ${TARGET} --package zk-por-cli --bin zk-por-cli + + mv target/${TARGET}/release/zk-por-cli ${RELEASE_TMP_DIR}/zk_STARK_Validator_v2 + + cp ${RELEASE_TMP_DIR}/zk_STARK_Validator_v2 ${RELEASE_TMP_DIR}/zk-por-checker + + sed 's|/opt/data/zkpor/users/|./sample_data/|g' config/default.toml > ${RELEASE_TMP_DIR}/config/default.toml + + cp -r test-data/batch0.json ${RELEASE_TMP_DIR}/sample_data + cp docs/release.md ${RELEASE_TMP_DIR}/README.md + + tar -cvf zk-por-${TARGET}.tar ${RELEASE_TMP_DIR} + rm -rf ${RELEASE_TMP_DIR} +} \ No newline at end of file diff --git a/scripts/release/prover/x86_64-unknown-linux-gnu.sh b/scripts/release/prover/x86_64-unknown-linux-gnu.sh new file mode 100755 index 0000000..3d4575e --- /dev/null +++ b/scripts/release/prover/x86_64-unknown-linux-gnu.sh @@ -0,0 +1,4 @@ +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +. "$DIR/common.sh" + +build_and_package x86_64-unknown-linux-gnu \ No newline at end of file diff --git a/scripts/release/verifier/aarch64-apple-darwin.sh b/scripts/release/verifier/aarch64-apple-darwin.sh new file mode 100755 index 0000000..a6c3e3c --- /dev/null +++ b/scripts/release/verifier/aarch64-apple-darwin.sh @@ -0,0 +1,9 @@ +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +. "$DIR/common.sh" + +if [ -z "$1" ]; then + echo "Version Number not Provided. Abort. " + exit 1 +else + build_and_package aarch64-apple-darwin "$1" +fi \ No newline at end of file diff --git a/scripts/release/verifier/common.sh b/scripts/release/verifier/common.sh new file mode 100755 index 0000000..61f78b4 --- /dev/null +++ b/scripts/release/verifier/common.sh @@ -0,0 +1,21 @@ +function build_and_package() { + mkdir -p validator/bin + TARGET=$1 + rustup target add $TARGET + VERSION=$2 + TMR_DIR="" + RUSTFLAGS="-C target-feature=+crt-static" cargo build --features zk-por-core/verifier --release --target ${TARGET} --package zk-por-cli --bin zk-por-cli + + if [ -f target/${TARGET}/release/zk-por-cli ]; then + mv target/${TARGET}/release/zk-por-cli ./zk_STARK_Validator_V2_${TARGET}_${VERSION} + elif [ -f target/${TARGET}/release/zk-por-cli.exe ]; then + mv target/${TARGET}/release/zk-por-cli.exe ./zk_STARK_Validator_V2_${TARGET}_${VERSION} + else + echo "zk-por-cli binary does not exist." + return 1 + fi + + zip ./zk_STARK_Validator_V2_${TARGET}_${VERSION}.zip ./zk_STARK_Validator_V2_${TARGET}_${VERSION} + rm ./zk_STARK_Validator_V2_${TARGET}_${VERSION} + mv ./zk_STARK_Validator_V2_${TARGET}_${VERSION}.zip validator/bin +} \ No newline at end of file diff --git a/scripts/release/verifier/x86_64-apple-darwin.sh b/scripts/release/verifier/x86_64-apple-darwin.sh new file mode 100755 index 0000000..f88ff83 --- /dev/null +++ b/scripts/release/verifier/x86_64-apple-darwin.sh @@ -0,0 +1,9 @@ +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +. "$DIR/common.sh" + +if [ -z "$1" ]; then + echo "Version Number not Provided. Abort. " + exit 1 +else + build_and_package x86_64-apple-darwin "$1" +fi \ No newline at end of file diff --git a/scripts/release/verifier/x86_64-pc-windows-gnu.sh b/scripts/release/verifier/x86_64-pc-windows-gnu.sh new file mode 100755 index 0000000..26ea3bf --- /dev/null +++ b/scripts/release/verifier/x86_64-pc-windows-gnu.sh @@ -0,0 +1,9 @@ +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +. "$DIR/common.sh" + +if [ -z "$1" ]; then + echo "Version Number not Provided. Abort. " + exit 1 +else + build_and_package x86_64-pc-windows-gnu "$1" +fi \ No newline at end of file diff --git a/scripts/release/verifier/x86_64-unknown-linux-gnu.sh b/scripts/release/verifier/x86_64-unknown-linux-gnu.sh new file mode 100755 index 0000000..a76aeb5 --- /dev/null +++ b/scripts/release/verifier/x86_64-unknown-linux-gnu.sh @@ -0,0 +1,9 @@ +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +. "$DIR/common.sh" + +if [ -z "$1" ]; then + echo "Version Number not Provided. Abort. " + exit 1 +else + build_and_package x86_64-unknown-linux-gnu "$1" +fi \ No newline at end of file diff --git a/validator/bin/zk_STARK_Validator_V2_aarch64-apple-darwin_v3.1.0.zip b/validator/bin/zk_STARK_Validator_V2_aarch64-apple-darwin_v3.1.0.zip new file mode 100644 index 0000000..6b35e31 Binary files /dev/null and b/validator/bin/zk_STARK_Validator_V2_aarch64-apple-darwin_v3.1.0.zip differ diff --git a/validator/bin/zk_STARK_Validator_V2_x86_64-apple-darwin_v3.1.0.zip b/validator/bin/zk_STARK_Validator_V2_x86_64-apple-darwin_v3.1.0.zip new file mode 100644 index 0000000..9a77bf0 Binary files /dev/null and b/validator/bin/zk_STARK_Validator_V2_x86_64-apple-darwin_v3.1.0.zip differ diff --git a/validator/bin/zk_STARK_Validator_V2_x86_64-pc-windows-gnu_v3.1.0.zip b/validator/bin/zk_STARK_Validator_V2_x86_64-pc-windows-gnu_v3.1.0.zip new file mode 100644 index 0000000..b91acc8 Binary files /dev/null and b/validator/bin/zk_STARK_Validator_V2_x86_64-pc-windows-gnu_v3.1.0.zip differ diff --git a/validator/bin/zk_STARK_Validator_V2_x86_64-unknown-linux-gnu_v3.1.0.zip b/validator/bin/zk_STARK_Validator_V2_x86_64-unknown-linux-gnu_v3.1.0.zip new file mode 100644 index 0000000..cc30741 Binary files /dev/null and b/validator/bin/zk_STARK_Validator_V2_x86_64-unknown-linux-gnu_v3.1.0.zip differ