diff --git a/Cargo.lock b/Cargo.lock index 8c84dec..6f663dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,7 +18,7 @@ dependencies = [ "rand 0.8.5", "serde", "serde_json", - "sha2 0.10.8", + "sha2", "utxo", ] @@ -132,7 +132,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13d324164c51f63867b57e73ba5936ea151b8a41a1d23d1031eeb9f70d0236f8" dependencies = [ "bytestring", - "cfg-if 1.0.0", + "cfg-if", "http 0.2.12", "regex", "regex-lite", @@ -204,7 +204,7 @@ dependencies = [ "ahash 0.7.8", "bytes", "bytestring", - "cfg-if 1.0.0", + "cfg-if", "derive_more 0.99.19", "encoding_rs", "futures-core", @@ -284,7 +284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" dependencies = [ "crypto-common", - "generic-array 0.14.7", + "generic-array", ] [[package]] @@ -293,7 +293,7 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cipher", "cpufeatures", ] @@ -309,15 +309,9 @@ dependencies = [ "cipher", "ctr", "ghash", - "subtle 2.6.1", + "subtle", ] -[[package]] -name = "ahash" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" - [[package]] name = "ahash" version = "0.7.8" @@ -335,7 +329,7 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "once_cell", "version_check", "zerocopy 0.7.35", @@ -411,10 +405,10 @@ dependencies = [ "ark-std", "blake2", "derivative", - "digest 0.10.7", + "digest", "fnv", "merlin", - "sha2 0.10.8", + "sha2", ] [[package]] @@ -459,13 +453,13 @@ dependencies = [ "ark-ff-macros", "ark-serialize", "ark-std", - "arrayvec 0.7.6", - "digest 0.10.7", + "arrayvec", + "digest", "educe", "itertools 0.13.0", "num-bigint 0.4.6", "num-traits", - "paste 1.0.15", + "paste", "zeroize", ] @@ -559,8 +553,8 @@ checksum = "3f4d068aaf107ebcd7dfb52bc748f8030e0fc930ac8e360146ca54c1203088f7" dependencies = [ "ark-serialize-derive", "ark-std", - "arrayvec 0.7.6", - "digest 0.10.7", + "arrayvec", + "digest", "num-bigint 0.4.6", ] @@ -603,27 +597,6 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" -[[package]] -name = "arrayref" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" - -[[package]] -name = "arrayvec" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" -dependencies = [ - "nodrop", -] - -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - [[package]] name = "arrayvec" version = "0.7.6" @@ -669,7 +642,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line 0.24.2", - "cfg-if 1.0.0", + "cfg-if", "libc", "miniz_oxide", "object 0.36.7", @@ -773,32 +746,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "blake2-rfc" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" -dependencies = [ - "arrayvec 0.4.12", - "constant_time_eq", -] - -[[package]] -name = "blake3" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "667d945f23cefed0b5f973af35c4bc3319caa6776fbda270e4897d8504afa8e4" -dependencies = [ - "arrayref", - "arrayvec 0.5.2", - "cc", - "cfg-if 0.1.10", - "constant_time_eq", - "crypto-mac", - "digest 0.8.1", + "digest", ] [[package]] @@ -807,34 +755,13 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" -[[package]] -name = "block-buffer" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" -dependencies = [ - "block-padding", - "byte-tools", - "byteorder", - "generic-array 0.12.4", -] - [[package]] name = "block-buffer" version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "generic-array 0.14.7", -] - -[[package]] -name = "block-padding" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" -dependencies = [ - "byte-tools", + "generic-array", ] [[package]] @@ -878,12 +805,6 @@ version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - [[package]] name = "bytemuck" version = "1.22.0" @@ -990,12 +911,6 @@ dependencies = [ "nom", ] -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -1082,14 +997,13 @@ dependencies = [ "elliptic-curve", "hex", "log", - "monotree", "reqwest 0.11.27", "risc0-zkvm", "rs_merkle", "secp256k1-zkp", "serde", "serde_json", - "sha2 0.10.8", + "sha2", "thiserror 1.0.69", ] @@ -1112,12 +1026,6 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - [[package]] name = "convert_case" version = "0.4.0" @@ -1157,7 +1065,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96e58d342ad113c2b878f16d5d034c03be492ae460cdbc02b7f0f2284d310c7d" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1175,7 +1083,7 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1224,9 +1132,9 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ - "generic-array 0.14.7", + "generic-array", "rand_core 0.6.4", - "subtle 2.6.1", + "subtle", "zeroize", ] @@ -1236,21 +1144,11 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "generic-array 0.14.7", + "generic-array", "rand_core 0.6.4", "typenum", ] -[[package]] -name = "crypto-mac" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" -dependencies = [ - "generic-array 0.12.4", - "subtle 1.0.0", -] - [[package]] name = "ctr" version = "0.9.2" @@ -1447,25 +1345,16 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "digest" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" -dependencies = [ - "generic-array 0.12.4", -] - [[package]] name = "digest" version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer 0.10.4", + "block-buffer", "const-oid", "crypto-common", - "subtle 2.6.1", + "subtle", ] [[package]] @@ -1527,7 +1416,7 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ac1e888d6830712d565b2f3a974be3200be9296bc1b03db8251a4cbf18a4a34" dependencies = [ - "digest 0.10.7", + "digest", "futures", "rand 0.8.5", "reqwest 0.12.15", @@ -1552,7 +1441,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ "der", - "digest 0.10.7", + "digest", "elliptic-curve", "rfc6979", "serdect", @@ -1592,15 +1481,15 @@ checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ "base16ct", "crypto-bigint", - "digest 0.10.7", + "digest", "ff", - "generic-array 0.14.7", + "generic-array", "group", "pkcs8", "rand_core 0.6.4", "sec1", "serdect", - "subtle 2.6.1", + "subtle", "zeroize", ] @@ -1622,7 +1511,7 @@ version = "0.8.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1704,12 +1593,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" - [[package]] name = "fallible-iterator" version = "0.3.0" @@ -1732,7 +1615,7 @@ dependencies = [ "byteorder", "ff_derive", "rand_core 0.6.4", - "subtle 2.6.1", + "subtle", ] [[package]] @@ -1927,15 +1810,6 @@ dependencies = [ "slab", ] -[[package]] -name = "generic-array" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" -dependencies = [ - "typenum", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -1947,24 +1821,13 @@ dependencies = [ "zeroize", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", @@ -1977,7 +1840,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "libc", "r-efi", @@ -1991,7 +1854,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" dependencies = [ - "opaque-debug 0.3.1", + "opaque-debug", "polyval", ] @@ -2034,7 +1897,7 @@ checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", "rand_core 0.6.4", - "subtle 2.6.1", + "subtle", ] [[package]] @@ -2065,16 +1928,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf" -dependencies = [ - "ahash 0.3.8", - "autocfg", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -2170,7 +2023,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.7", + "digest", ] [[package]] @@ -2527,7 +2380,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" dependencies = [ - "generic-array 0.14.7", + "generic-array", ] [[package]] @@ -2624,12 +2477,12 @@ version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "ecdsa", "elliptic-curve", "once_cell", "serdect", - "sha2 0.10.8", + "sha2", "signature", ] @@ -2698,7 +2551,7 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "windows-targets 0.52.6", ] @@ -2970,7 +2823,7 @@ dependencies = [ "foreign-types 0.5.0", "log", "objc", - "paste 1.0.15", + "paste", ] [[package]] @@ -3012,25 +2865,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "monotree" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6724f66abef26ea20981177c87a500f2416a420d96daf50c5d96d97a10892d5f" -dependencies = [ - "blake2-rfc", - "blake3", - "digest 0.8.1", - "hashbrown 0.7.2", - "hex", - "num", - "paste 0.1.18", - "rand 0.7.3", - "scopeguard", - "sha2 0.8.2", - "sha3", -] - [[package]] name = "native-tls" version = "0.2.14" @@ -3055,7 +2889,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "882ed72dce9365842bf196bdeedf5055305f11fc8c03dee7bb0194a6cad34841" dependencies = [ "matrixmultiply", - "num-complex 0.4.6", + "num-complex", "num-integer", "num-traits", "portable-atomic", @@ -3095,7 +2929,6 @@ dependencies = [ "hex", "k256", "log", - "monotree", "rand 0.8.5", "reqwest 0.11.27", "risc0-zkvm", @@ -3103,7 +2936,7 @@ dependencies = [ "secp256k1-zkp", "serde", "serde_json", - "sha2 0.10.8", + "sha2", "storage", "tempfile", "thiserror 1.0.69", @@ -3164,12 +2997,6 @@ dependencies = [ "zkvm", ] -[[package]] -name = "nodrop" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" - [[package]] name = "nom" version = "7.1.3" @@ -3180,31 +3007,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "num" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36" -dependencies = [ - "num-bigint 0.2.6", - "num-complex 0.2.4", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-bigint" version = "0.3.3" @@ -3226,16 +3028,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-complex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" -dependencies = [ - "autocfg", - "num-traits", -] - [[package]] name = "num-complex" version = "0.4.6" @@ -3271,29 +3063,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-iter" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" -dependencies = [ - "autocfg", - "num-bigint 0.2.6", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -3348,12 +3117,6 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" -[[package]] -name = "opaque-debug" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" - [[package]] name = "opaque-debug" version = "0.3.1" @@ -3367,7 +3130,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e14130c6a98cd258fdcb0fb6d744152343ff729cbfcb28c656a9d12b999fbcd" dependencies = [ "bitflags 2.9.0", - "cfg-if 1.0.0", + "cfg-if", "foreign-types 0.3.2", "libc", "once_cell", @@ -3432,38 +3195,19 @@ version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "redox_syscall", "smallvec", "windows-targets 0.52.6", ] -[[package]] -name = "paste" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" -dependencies = [ - "paste-impl", - "proc-macro-hack", -] - [[package]] name = "paste" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "paste-impl" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" -dependencies = [ - "proc-macro-hack", -] - [[package]] name = "peeking_take_while" version = "0.1.2" @@ -3510,9 +3254,9 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", - "opaque-debug 0.3.1", + "opaque-debug", "universal-hash", ] @@ -3602,12 +3346,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" version = "1.0.94" @@ -3648,7 +3386,7 @@ checksum = "fa9dae7b05c02ec1a6bc9bcf20d8bc64a7dcbf57934107902a872014899b741f" dependencies = [ "anyhow", "byteorder", - "cfg-if 1.0.0", + "cfg-if", "itertools 0.10.5", "once_cell", "parking_lot", @@ -3729,19 +3467,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" 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" @@ -3764,16 +3489,6 @@ dependencies = [ "zerocopy 0.8.24", ] -[[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" @@ -3794,15 +3509,6 @@ dependencies = [ "rand_core 0.9.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.4" @@ -3821,15 +3527,6 @@ dependencies = [ "getrandom 0.3.2", ] -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", -] - [[package]] name = "rawpointer" version = "0.2.1" @@ -4004,7 +3701,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" dependencies = [ "hmac", - "subtle 2.6.1", + "subtle", ] [[package]] @@ -4014,7 +3711,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", - "cfg-if 1.0.0", + "cfg-if", "getrandom 0.2.15", "libc", "untrusted", @@ -4078,7 +3775,7 @@ dependencies = [ "glob", "hex", "rayon", - "sha2 0.10.8", + "sha2", "tempfile", ] @@ -4089,9 +3786,9 @@ source = "git+https://github.com/risc0/risc0.git?branch=release-2.0#fdd54f961b84 dependencies = [ "anyhow", "bytemuck", - "cfg-if 1.0.0", + "cfg-if", "keccak", - "paste 1.0.15", + "paste", "rayon", "risc0-binfmt", "risc0-circuit-keccak-sys", @@ -4125,7 +3822,7 @@ source = "git+https://github.com/risc0/risc0.git?branch=release-2.0#fdd54f961b84 dependencies = [ "anyhow", "bytemuck", - "cfg-if 1.0.0", + "cfg-if", "cust", "downloader", "hex", @@ -4138,7 +3835,7 @@ dependencies = [ "risc0-sys", "risc0-zkp", "serde", - "sha2 0.10.8", + "sha2", "tracing", "zip", ] @@ -4165,13 +3862,13 @@ dependencies = [ "bit-vec", "bytemuck", "byteorder", - "cfg-if 1.0.0", + "cfg-if", "derive_more 2.0.1", "enum-map", "malachite", "num-derive", "num-traits", - "paste 1.0.15", + "paste", "postcard", "rand 0.8.5", "rayon", @@ -4266,16 +3963,16 @@ dependencies = [ "blake2", "borsh", "bytemuck", - "cfg-if 1.0.0", + "cfg-if", "cust", - "digest 0.10.7", + "digest", "ff", "hex", "hex-literal", "metal", "ndarray", "parking_lot", - "paste 1.0.15", + "paste", "rand 0.8.5", "rand_core 0.6.4", "rayon", @@ -4283,7 +3980,7 @@ dependencies = [ "risc0-sys", "risc0-zkvm-platform", "serde", - "sha2 0.10.8", + "sha2", "stability", "tracing", ] @@ -4327,7 +4024,7 @@ dependencies = [ "rzup", "semver", "serde", - "sha2 0.10.8", + "sha2", "stability", "tempfile", "tracing", @@ -4340,7 +4037,7 @@ version = "2.0.1" source = "git+https://github.com/risc0/risc0.git?branch=release-2.0#fdd54f961b84b38831a8a488b9d67534a02d80a2" dependencies = [ "bytemuck", - "cfg-if 1.0.0", + "cfg-if", "getrandom 0.2.15", "libm", "stability", @@ -4363,7 +4060,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4382d3af3a4ebdae7f64ba6edd9114fff92c89808004c4943b393377a25d001" dependencies = [ "downcast-rs", - "paste 1.0.15", + "paste", ] [[package]] @@ -4372,7 +4069,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb09b49230ba22e8c676e7b75dfe2887dea8121f18b530ae0ba519ce442d2b21" dependencies = [ - "sha2 0.10.8", + "sha2", ] [[package]] @@ -4438,7 +4135,7 @@ dependencies = [ "ring", "rustls-pki-types", "rustls-webpki", - "subtle 2.6.1", + "subtle", "zeroize", ] @@ -4533,13 +4230,12 @@ dependencies = [ "k256", "light-poseidon", "log", - "monotree", "rand 0.8.5", "risc0-zkvm", "secp256k1-zkp", "serde", "serde_json", - "sha2 0.10.8", + "sha2", "storage", "utxo", ] @@ -4567,10 +4263,10 @@ checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ "base16ct", "der", - "generic-array 0.14.7", + "generic-array", "pkcs8", "serdect", - "subtle 2.6.1", + "subtle", "zeroize", ] @@ -4782,21 +4478,9 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", - "digest 0.10.7", -] - -[[package]] -name = "sha2" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" -dependencies = [ - "block-buffer 0.7.3", - "digest 0.8.1", - "fake-simd", - "opaque-debug 0.2.3", + "digest", ] [[package]] @@ -4805,22 +4489,9 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", - "digest 0.10.7", -] - -[[package]] -name = "sha3" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" -dependencies = [ - "block-buffer 0.7.3", - "byte-tools", - "digest 0.8.1", - "keccak", - "opaque-debug 0.2.3", + "digest", ] [[package]] @@ -4844,7 +4515,7 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ - "digest 0.10.7", + "digest", "rand_core 0.6.4", ] @@ -4990,12 +4661,6 @@ dependencies = [ "syn 2.0.100", ] -[[package]] -name = "subtle" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" - [[package]] name = "subtle" version = "2.6.1" @@ -5398,7 +5063,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "static_assertions", ] @@ -5457,7 +5122,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" dependencies = [ "crypto-common", - "subtle 2.6.1", + "subtle", ] [[package]] @@ -5498,10 +5163,9 @@ dependencies = [ "env_logger", "hex", "log", - "monotree", "serde", "serde_json", - "sha2 0.10.8", + "sha2", ] [[package]] @@ -5554,12 +5218,6 @@ dependencies = [ "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]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -5581,7 +5239,7 @@ version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "once_cell", "rustversion", "wasm-bindgen-macro", @@ -5607,7 +5265,7 @@ version = "0.4.50" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "once_cell", "wasm-bindgen", @@ -6002,7 +5660,7 @@ version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "windows-sys 0.48.0", ] diff --git a/Cargo.toml b/Cargo.toml index 59417cd..7af2e24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,6 @@ lru = "0.7.8" thiserror = "1.0" rs_merkle = "1.4" sha2 = "0.10.8" -monotree = "0.1.5" hex = "0.4.3" aes-gcm = "0.10.3" toml = "0.7.4" diff --git a/common/Cargo.toml b/common/Cargo.toml index f3327ea..b692f5f 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -9,7 +9,6 @@ thiserror.workspace = true serde_json.workspace = true serde.workspace = true reqwest.workspace = true -monotree.workspace = true risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-2.0" } rs_merkle.workspace = true diff --git a/common/src/commitments_sparse_merkle_tree.rs b/common/src/commitments_sparse_merkle_tree.rs deleted file mode 100644 index 3182275..0000000 --- a/common/src/commitments_sparse_merkle_tree.rs +++ /dev/null @@ -1,283 +0,0 @@ -use monotree::database::MemoryDB; -use monotree::hasher::Blake3; -use monotree::{Hasher, Monotree, Proof}; - -use crate::commitment::Commitment; -use crate::merkle_tree_public::CommitmentHashType; - -pub struct CommitmentsSparseMerkleTree { - pub curr_root: Option, - pub tree: Monotree, - pub hasher: Blake3, -} - -impl CommitmentsSparseMerkleTree { - pub fn new() -> Self { - CommitmentsSparseMerkleTree { - curr_root: None, - tree: Monotree::default(), - hasher: Blake3::new(), - } - } - - pub fn insert_item(&mut self, commitment: Commitment) -> Result<(), monotree::Errors> { - let root = self - .curr_root - .as_ref() - .map(|val| val[0..32].try_into().unwrap()); - - let new_root = self.tree.insert( - root, - &commitment.commitment_hash[0..32].try_into().unwrap(), - &commitment.commitment_hash[0..32].try_into().unwrap(), - )?; - - self.curr_root = new_root.map(|val| val.to_vec()); - - Ok(()) - } - - pub fn insert_items(&mut self, commitments: Vec) -> Result<(), monotree::Errors> { - let root = self - .curr_root - .as_ref() - .map(|val| val[0..32].try_into().unwrap()); - - let hashes: Vec<_> = commitments - .iter() - .map(|val| val.commitment_hash[0..32].try_into().unwrap()) - .collect::>(); - - let new_root = self.tree.inserts(root, &hashes, &hashes)?; - - self.curr_root = new_root.map(|val| val[0..32].try_into().unwrap()); - - Ok(()) - } - - pub fn search_item_inclusion( - &mut self, - commitment_hash: CommitmentHashType, - ) -> Result { - self.tree - .get( - self.curr_root - .as_ref() - .map(|val| val[0..32].try_into().unwrap()), - &commitment_hash[0..32].try_into().unwrap(), - ) - .map(|data| data.is_some()) - } - - pub fn search_item_inclusions( - &mut self, - commitment_hashes: &[CommitmentHashType], - ) -> Result, monotree::Errors> { - let mut inclusions = vec![]; - - for nullifier_hash in commitment_hashes { - let is_included = self - .tree - .get( - self.curr_root - .as_ref() - .map(|val| val[0..32].try_into().unwrap()), - nullifier_hash[0..32].try_into().unwrap(), - ) - .map(|data| data.is_some())?; - - inclusions.push(is_included); - } - - Ok(inclusions) - } - - pub fn get_non_membership_proof( - &mut self, - commitment_hash: CommitmentHashType, - ) -> Result<(Option, Option), monotree::Errors> { - let is_member = self.search_item_inclusion(commitment_hash.clone())?; - - if is_member { - Err(monotree::Errors::new("Is a member")) - } else { - Ok(( - self.tree.get_merkle_proof( - self.curr_root - .as_ref() - .map(|val| val[0..32].try_into().unwrap()), - &commitment_hash, - )?, - self.curr_root.clone(), - )) - } - } - - #[allow(clippy::type_complexity)] - pub fn get_non_membership_proofs( - &mut self, - commitment_hashes: &[CommitmentHashType], - ) -> Result, Option)>, monotree::Errors> { - let mut non_membership_proofs = vec![]; - - for commitment_hash in commitment_hashes { - let is_member = self.search_item_inclusion(commitment_hash.clone())?; - - if is_member { - return Err(monotree::Errors::new( - format!("{commitment_hash:?} Is a member").as_str(), - )); - } else { - non_membership_proofs.push(( - self.tree.get_merkle_proof( - self.curr_root - .as_ref() - .map(|val| val[0..32].try_into().unwrap()), - commitment_hash, - )?, - self.curr_root.clone(), - )) - }; - } - - Ok(non_membership_proofs) - } -} - -impl Default for CommitmentsSparseMerkleTree { - fn default() -> Self { - Self::new() - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::nullifier::UTXONullifier; - use monotree::database::MemoryDB; - use monotree::hasher::Blake3; - use monotree::Monotree; - - fn create_nullifier(hash: CommitmentHashType) -> Commitment { - Commitment { - commitment_hash: hash, - } - } - - #[test] - fn test_new_tree_initialization() { - let tree = CommitmentsSparseMerkleTree::new(); - assert!(tree.curr_root.is_none()); - } - - #[test] - fn test_insert_single_item() { - let mut tree = CommitmentsSparseMerkleTree::new(); - let nullifier = create_nullifier([1u8; 32].to_vec()); // Sample 32-byte hash - - let result = tree.insert_item(nullifier); - assert!(result.is_ok()); - assert!(tree.curr_root.is_some()); - } - - #[test] - fn test_insert_multiple_items() { - let mut tree = CommitmentsSparseMerkleTree::new(); - let nullifiers = vec![ - create_nullifier([1u8; 32].to_vec()), - create_nullifier([2u8; 32].to_vec()), - create_nullifier([3u8; 32].to_vec()), - ]; - - let result = tree.insert_items(nullifiers); - assert!(result.is_ok()); - assert!(tree.curr_root.is_some()); - } - - #[test] - fn test_search_item_inclusion() { - let mut tree = CommitmentsSparseMerkleTree::new(); - let nullifier = create_nullifier([1u8; 32].to_vec()); - - tree.insert_item(nullifier.clone()).unwrap(); - - let result = tree.search_item_inclusion([1u8; 32].to_vec()); - assert!(result.is_ok()); - assert_eq!(result.unwrap(), true); - - let non_existing = tree.search_item_inclusion([99u8; 32].to_vec()); - assert!(non_existing.is_ok()); - assert_eq!(non_existing.unwrap(), false); - } - - #[test] - fn test_search_multiple_item_inclusions() { - let mut tree = CommitmentsSparseMerkleTree::new(); - let nullifiers = vec![ - create_nullifier([1u8; 32].to_vec()), - create_nullifier([2u8; 32].to_vec()), - create_nullifier([3u8; 32].to_vec()), - ]; - - tree.insert_items(nullifiers).unwrap(); - - let search_hashes = vec![[1u8; 32].to_vec(), [2u8; 32].to_vec(), [99u8; 32].to_vec()]; - let result = tree.search_item_inclusions(&search_hashes); - assert!(result.is_ok()); - - let expected_results = vec![true, true, false]; - assert_eq!(result.unwrap(), expected_results); - } - - #[test] - fn test_non_membership_proof() { - let mut tree = CommitmentsSparseMerkleTree::new(); - let non_member_hash = [5u8; 32].to_vec(); - - let result = tree.get_non_membership_proof(non_member_hash); - assert!(result.is_ok()); - - let (proof, root) = result.unwrap(); - assert!(root.is_none()); - } - - #[test] - fn test_non_membership_proofs_multiple() { - let mut tree = CommitmentsSparseMerkleTree::new(); - let non_member_hashes = vec![[5u8; 32].to_vec(), [6u8; 32].to_vec(), [7u8; 32].to_vec()]; - - let result = tree.get_non_membership_proofs(&non_member_hashes); - assert!(result.is_ok()); - - let proofs = result.unwrap(); - for (proof, root) in proofs { - assert!(root.is_none()); - } - } - - #[test] - fn test_insert_and_get_proof_of_existing_item() { - let mut tree = CommitmentsSparseMerkleTree::new(); - let nullifier = create_nullifier([1u8; 32].to_vec()); - - tree.insert_item(nullifier.clone()).unwrap(); - - let proof_result = tree.get_non_membership_proof([1u8; 32].to_vec()); - assert!(proof_result.is_err()); - } - - #[test] - fn test_insert_and_get_proofs_of_existing_items() { - let mut tree = CommitmentsSparseMerkleTree::new(); - let nullifiers = vec![ - create_nullifier([1u8; 32].to_vec()), - create_nullifier([2u8; 32].to_vec()), - ]; - - tree.insert_items(nullifiers).unwrap(); - - let proof_result = - tree.get_non_membership_proofs(&[[1u8; 32].to_vec(), [2u8; 32].to_vec()]); - assert!(proof_result.is_err()); - } -} diff --git a/common/src/lib.rs b/common/src/lib.rs index a13fdd4..46868d9 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -3,10 +3,8 @@ use serde::Deserialize; pub mod block; pub mod commitment; -pub mod commitments_sparse_merkle_tree; pub mod merkle_tree_public; pub mod nullifier; -pub mod nullifier_sparse_merkle_tree; pub mod rpc_primitives; pub mod transaction; pub mod utxo_commitment; @@ -67,8 +65,6 @@ pub enum ExecutionFailureKind { AmountMismatchError, #[error("Sequencer client error: {0:?}")] SequencerClientError(#[from] SequencerClientError), - #[error("Datebase returned error : {0:?}")] - MonoTreeError(#[from] monotree::Errors), #[error("Insufficient gas for operation")] InsufficientGasError, #[error("Can not pay for operation")] diff --git a/common/src/nullifier.rs b/common/src/nullifier.rs index 5033fa6..2c95741 100644 --- a/common/src/nullifier.rs +++ b/common/src/nullifier.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::merkle_tree_public::TreeHashType; //ToDo: Update Nullifier model, when it is clear -#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq)] +#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] ///General nullifier object pub struct UTXONullifier { pub utxo_hash: TreeHashType, diff --git a/common/src/nullifier_sparse_merkle_tree.rs b/common/src/nullifier_sparse_merkle_tree.rs deleted file mode 100644 index 282fccc..0000000 --- a/common/src/nullifier_sparse_merkle_tree.rs +++ /dev/null @@ -1,245 +0,0 @@ -use monotree::database::MemoryDB; -use monotree::hasher::Blake3; -use monotree::{Hasher, Monotree, Proof}; - -use crate::merkle_tree_public::TreeHashType; -use crate::nullifier::UTXONullifier; - -pub struct NullifierSparseMerkleTree { - pub curr_root: Option, - pub tree: Monotree, - pub hasher: Blake3, -} - -impl NullifierSparseMerkleTree { - pub fn new() -> Self { - NullifierSparseMerkleTree { - curr_root: None, - tree: Monotree::default(), - hasher: Blake3::new(), - } - } - - pub fn insert_item(&mut self, nullifier: UTXONullifier) -> Result<(), monotree::Errors> { - let root = self.curr_root.as_ref(); - - let new_root = self - .tree - .insert(root, &nullifier.utxo_hash, &nullifier.utxo_hash)?; - - self.curr_root = new_root; - - Ok(()) - } - - pub fn insert_items(&mut self, nullifiers: Vec) -> Result<(), monotree::Errors> { - let root = self.curr_root.as_ref(); - - let hashes: Vec = nullifiers.iter().map(|nu| nu.utxo_hash).collect(); - - let new_root = self.tree.inserts(root, &hashes, &hashes)?; - - self.curr_root = new_root; - - Ok(()) - } - - pub fn search_item_inclusion( - &mut self, - nullifier_hash: TreeHashType, - ) -> Result { - self.tree - .get(self.curr_root.as_ref(), &nullifier_hash) - .map(|data| data.is_some()) - } - - pub fn search_item_inclusions( - &mut self, - nullifier_hashes: &[TreeHashType], - ) -> Result, monotree::Errors> { - let mut inclusions = vec![]; - - for nullifier_hash in nullifier_hashes { - let is_included = self - .tree - .get(self.curr_root.as_ref(), nullifier_hash) - .map(|data| data.is_some())?; - - inclusions.push(is_included); - } - - Ok(inclusions) - } - - pub fn get_non_membership_proof( - &mut self, - nullifier_hash: TreeHashType, - ) -> Result<(Option, Option), monotree::Errors> { - let is_member = self.search_item_inclusion(nullifier_hash)?; - - if is_member { - Err(monotree::Errors::new("Is a member")) - } else { - Ok(( - self.tree - .get_merkle_proof(self.curr_root.as_ref(), &nullifier_hash)?, - self.curr_root, - )) - } - } - - #[allow(clippy::type_complexity)] - pub fn get_non_membership_proofs( - &mut self, - nullifier_hashes: &[TreeHashType], - ) -> Result, Option)>, monotree::Errors> { - let mut non_membership_proofs = vec![]; - - for nullifier_hash in nullifier_hashes { - let is_member = self.search_item_inclusion(*nullifier_hash)?; - - if is_member { - return Err(monotree::Errors::new( - format!("{nullifier_hash:?} Is a member").as_str(), - )); - } else { - non_membership_proofs.push(( - self.tree - .get_merkle_proof(self.curr_root.as_ref(), nullifier_hash)?, - self.curr_root, - )) - }; - } - - Ok(non_membership_proofs) - } -} - -impl Default for NullifierSparseMerkleTree { - fn default() -> Self { - Self::new() - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::nullifier::UTXONullifier; - - fn create_nullifier(hash: TreeHashType) -> UTXONullifier { - UTXONullifier { utxo_hash: hash } - } - - #[test] - fn test_new_tree_initialization() { - let tree = NullifierSparseMerkleTree::new(); - assert!(tree.curr_root.is_none()); - } - - #[test] - fn test_insert_single_item() { - let mut tree = NullifierSparseMerkleTree::new(); - let nullifier = create_nullifier([1u8; 32]); // Sample 32-byte hash - - let result = tree.insert_item(nullifier); - assert!(result.is_ok()); - assert!(tree.curr_root.is_some()); - } - - #[test] - fn test_insert_multiple_items() { - let mut tree = NullifierSparseMerkleTree::new(); - let nullifiers = vec![ - create_nullifier([1u8; 32]), - create_nullifier([2u8; 32]), - create_nullifier([3u8; 32]), - ]; - - let result = tree.insert_items(nullifiers); - assert!(result.is_ok()); - assert!(tree.curr_root.is_some()); - } - - #[test] - fn test_search_item_inclusion() { - let mut tree = NullifierSparseMerkleTree::new(); - let nullifier = create_nullifier([1u8; 32]); - - tree.insert_item(nullifier.clone()).unwrap(); - - let result = tree.search_item_inclusion([1u8; 32]); - assert!(result.is_ok()); - assert_eq!(result.unwrap(), true); - - let non_existing = tree.search_item_inclusion([99u8; 32]); - assert!(non_existing.is_ok()); - assert_eq!(non_existing.unwrap(), false); - } - - #[test] - fn test_search_multiple_item_inclusions() { - let mut tree = NullifierSparseMerkleTree::new(); - let nullifiers = vec![ - create_nullifier([1u8; 32]), - create_nullifier([2u8; 32]), - create_nullifier([3u8; 32]), - ]; - - tree.insert_items(nullifiers).unwrap(); - - let search_hashes = vec![[1u8; 32], [2u8; 32], [99u8; 32]]; - let result = tree.search_item_inclusions(&search_hashes); - assert!(result.is_ok()); - - let expected_results = vec![true, true, false]; - assert_eq!(result.unwrap(), expected_results); - } - - #[test] - fn test_non_membership_proof() { - let mut tree = NullifierSparseMerkleTree::new(); - let non_member_hash = [5u8; 32]; - - let result = tree.get_non_membership_proof(non_member_hash); - assert!(result.is_ok()); - - let (proof, root) = result.unwrap(); - assert!(root.is_none()); - } - - #[test] - fn test_non_membership_proofs_multiple() { - let mut tree = NullifierSparseMerkleTree::new(); - let non_member_hashes = vec![[5u8; 32], [6u8; 32], [7u8; 32]]; - - let result = tree.get_non_membership_proofs(&non_member_hashes); - assert!(result.is_ok()); - - let proofs = result.unwrap(); - for (proof, root) in proofs { - assert!(root.is_none()); - } - } - - #[test] - fn test_insert_and_get_proof_of_existing_item() { - let mut tree = NullifierSparseMerkleTree::new(); - let nullifier = create_nullifier([1u8; 32]); - - tree.insert_item(nullifier.clone()).unwrap(); - - let proof_result = tree.get_non_membership_proof([1u8; 32]); - assert!(proof_result.is_err()); - } - - #[test] - fn test_insert_and_get_proofs_of_existing_items() { - let mut tree = NullifierSparseMerkleTree::new(); - let nullifiers = vec![create_nullifier([1u8; 32]), create_nullifier([2u8; 32])]; - - tree.insert_items(nullifiers).unwrap(); - - let proof_result = tree.get_non_membership_proofs(&[[1u8; 32], [2u8; 32]]); - assert!(proof_result.is_err()); - } -} diff --git a/common/src/rpc_primitives/requests.rs b/common/src/rpc_primitives/requests.rs index 92e0abe..6cad01d 100644 --- a/common/src/rpc_primitives/requests.rs +++ b/common/src/rpc_primitives/requests.rs @@ -21,8 +21,8 @@ pub struct RegisterAccountRequest { #[derive(Serialize, Deserialize, Debug)] pub struct SendTxRequest { pub transaction: Transaction, - ///Nullifier Root, UTXO Commitment Root, Pub Tx Root - pub tx_roots: [[u8; 32]; 3], + ///UTXO Commitment Root, Pub Tx Root + pub tx_roots: [[u8; 32]; 2], } #[derive(Serialize, Deserialize, Debug)] diff --git a/node_core/Cargo.toml b/node_core/Cargo.toml index d948e79..18120b2 100644 --- a/node_core/Cargo.toml +++ b/node_core/Cargo.toml @@ -12,7 +12,6 @@ serde.workspace = true rand.workspace = true k256.workspace = true sha2.workspace = true -monotree.workspace = true bincode.workspace = true elliptic-curve.workspace = true reqwest.workspace = true diff --git a/node_core/src/chain_storage/mod.rs b/node_core/src/chain_storage/mod.rs index 3abe0b1..26bb809 100644 --- a/node_core/src/chain_storage/mod.rs +++ b/node_core/src/chain_storage/mod.rs @@ -1,5 +1,5 @@ use std::{ - collections::{BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, HashSet}, path::Path, }; @@ -10,7 +10,6 @@ use common::{ block::Block, merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree}, nullifier::UTXONullifier, - nullifier_sparse_merkle_tree::NullifierSparseMerkleTree, utxo_commitment::UTXOCommitment, }; use k256::AffinePoint; @@ -26,7 +25,7 @@ pub mod public_context; pub struct NodeChainStore { pub acc_map: HashMap, pub block_store: NodeBlockStore, - pub nullifier_store: NullifierSparseMerkleTree, + pub nullifier_store: HashSet, pub utxo_commitments_store: UTXOCommitmentsMerkleTree, pub pub_tx_store: PublicTransactionMerkleTree, } @@ -34,7 +33,7 @@ pub struct NodeChainStore { impl NodeChainStore { pub fn new_with_genesis(home_dir: &Path, genesis_block: Block) -> Self { let acc_map = HashMap::new(); - let nullifier_store = NullifierSparseMerkleTree::default(); + let nullifier_store = HashSet::new(); let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]); let pub_tx_store = PublicTransactionMerkleTree::new(vec![]); @@ -97,13 +96,11 @@ impl NodeChainStore { .collect(), ); - self.nullifier_store.insert_items( - tx.nullifier_created_hashes - .clone() - .into_iter() - .map(|hash| UTXONullifier { utxo_hash: hash }) - .collect(), - )?; + for nullifier in tx.nullifier_created_hashes.iter() { + self.nullifier_store.insert(UTXONullifier { + utxo_hash: *nullifier, + }); + } if !tx.encoded_data.is_empty() { let ephemeral_public_key_sender = @@ -153,7 +150,6 @@ impl NodeChainStore { caller_address: caller, caller_balance: self.acc_map.get(&caller).unwrap().balance, account_masks, - nullifier_store_root: self.nullifier_store.curr_root.unwrap_or([0; 32]), comitment_store_root: self.utxo_commitments_store.get_root().unwrap_or([0; 32]), pub_tx_store_root: self.pub_tx_store.get_root().unwrap_or([0; 32]), } diff --git a/node_core/src/chain_storage/public_context.rs b/node_core/src/chain_storage/public_context.rs index 5d5ceb6..438fa50 100644 --- a/node_core/src/chain_storage/public_context.rs +++ b/node_core/src/chain_storage/public_context.rs @@ -9,7 +9,6 @@ pub const CALLER_ADDRESS: &str = "caller_address"; pub const CALLER_BALANCE: &str = "caller_balance"; pub const ACCOUNT_MASKS_KEYS_SORTED: &str = "account_masks_keys_sorted"; pub const ACCOUNT_MASKS_VALUES_SORTED: &str = "account_masks_values_sorted"; -pub const NULLIFIER_STORE_ROOT: &str = "nullifier_store_root"; pub const COMMITMENT_STORE_ROOT: &str = "commitment_store_root"; pub const PUT_TX_STORE_ROOT: &str = "put_tx_store_root"; @@ -18,7 +17,6 @@ pub struct PublicSCContext { pub caller_address: AccountAddress, pub caller_balance: u64, pub account_masks: BTreeMap, - pub nullifier_store_root: TreeHashType, pub comitment_store_root: TreeHashType, pub pub_tx_store_root: TreeHashType, } @@ -41,7 +39,6 @@ impl Serialize for PublicSCContext { s.serialize_field(CALLER_BALANCE, &self.caller_balance)?; s.serialize_field(ACCOUNT_MASKS_KEYS_SORTED, &account_masks_keys)?; s.serialize_field(ACCOUNT_MASKS_VALUES_SORTED, &account_mask_values)?; - s.serialize_field(NULLIFIER_STORE_ROOT, &self.nullifier_store_root)?; s.serialize_field(COMMITMENT_STORE_ROOT, &self.comitment_store_root)?; s.serialize_field(PUT_TX_STORE_ROOT, &self.pub_tx_store_root)?; @@ -100,7 +97,6 @@ mod tests { fn create_test_context() -> PublicSCContext { let caller_address = [1; 32]; - let nullifier_store_root = [2; 32]; let comitment_store_root = [3; 32]; let pub_tx_store_root = [4; 32]; @@ -118,7 +114,6 @@ mod tests { caller_address, caller_balance: 100, account_masks, - nullifier_store_root, comitment_store_root, pub_tx_store_root, } diff --git a/node_core/src/executions/de.rs b/node_core/src/executions/de.rs deleted file mode 100644 index f73ba85..0000000 --- a/node_core/src/executions/de.rs +++ /dev/null @@ -1,232 +0,0 @@ -use bincode; -use common::{ - commitment::Commitment, commitments_sparse_merkle_tree::CommitmentsSparseMerkleTree, - nullifier::UTXONullifier, nullifier_sparse_merkle_tree::NullifierSparseMerkleTree, -}; -use k256::Scalar; -use monotree::hasher::Blake3; -use monotree::{Hasher, Monotree}; -use rand::thread_rng; -use secp256k1_zkp::{CommitmentSecrets, Generator, PedersenCommitment, Tag, Tweak, SECP256K1}; -use sha2::{Digest, Sha256}; -use utxo::utxo_core::UTXO; - -#[allow(unused)] -fn commitment_secrets_random(value: u64) -> CommitmentSecrets { - CommitmentSecrets { - value, - value_blinding_factor: Tweak::new(&mut thread_rng()), - generator_blinding_factor: Tweak::new(&mut thread_rng()), - } -} - -pub fn tag_random() -> Tag { - use rand::thread_rng; - use rand::RngCore; - - let mut bytes = [0u8; 32]; - thread_rng().fill_bytes(&mut bytes); - - Tag::from(bytes) -} - -pub fn commit(comm: &CommitmentSecrets, tag: Tag) -> PedersenCommitment { - let generator = Generator::new_blinded(SECP256K1, tag, comm.generator_blinding_factor); - - PedersenCommitment::new(SECP256K1, comm.value, comm.value_blinding_factor, generator) -} - -fn hash(input: &[u8]) -> Vec { - Sha256::digest(input).to_vec() -} - -// Generate nullifiers - -// takes the input_utxo and nsk -// returns the nullifiers[i], where the nullifier[i] = hash(in_commitments[i] || nsk) where the hash function -pub fn generate_nullifiers(input_utxo: &UTXO, nsk: &[u8]) -> Vec { - let mut input = bincode::serialize(input_utxo).unwrap().to_vec(); - input.extend_from_slice(nsk); - hash(&input) -} - -// Generate commitments for output UTXOs - -// uses the list of input_utxos[] -// returns in_commitments[] where each in_commitments[i] = Commitment(in_utxos[i]) where the commitment -pub fn generate_commitments(input_utxos: &[UTXO]) -> Vec> { - input_utxos - .iter() - .map(|utxo| { - let serialized = bincode::serialize(utxo).unwrap(); // Serialize UTXO. - hash(&serialized) - }) - .collect() -} - -// Validate inclusion proof for in_commitments - -// takes the in_commitments[i] as a leaf, the root hash root_commitment and the path in_commitments_proofs[i][], -// returns True if the in_commitments[i] is in the tree with root hash root_commitment otherwise returns False, as membership proof. -pub fn validate_in_commitments_proof( - in_commitment: &Vec, - root_commitment: Vec, - in_commitments_proof: &[Vec], -) -> bool { - // Placeholder implementation. - // Replace with Merkle proof verification logic. - // hash(&[pedersen_commitment.serialize().to_vec(), in_commitments_proof.concat()].concat()) == root_commitment - - let mut nsmt = CommitmentsSparseMerkleTree { - curr_root: Option::Some(root_commitment), - tree: Monotree::default(), - hasher: Blake3::new(), - }; - - let commitments: Vec<_> = in_commitments_proof - .into_iter() - .map(|n_p| Commitment { - commitment_hash: n_p.clone(), - }) - .collect(); - nsmt.insert_items(commitments).unwrap(); - - nsmt.get_non_membership_proof(in_commitment.clone()) - .unwrap() - .1 - .is_some() -} - -// Validate non-membership proof for nullifiers - -// takes the nullifiers[i], path nullifiers_proof[i][] and the root hash root_nullifier, -// returns True if the nullifiers[i] is not in the tree with root hash root_nullifier otherwise returns False, as non-membership proof. -pub fn validate_nullifiers_proof( - nullifier: [u8; 32], - root_nullifier: [u8; 32], - nullifiers_proof: &[[u8; 32]], -) -> bool { - let mut nsmt = NullifierSparseMerkleTree { - curr_root: Option::Some(root_nullifier), - tree: Monotree::default(), - hasher: Blake3::new(), - }; - - let nullifiers: Vec<_> = nullifiers_proof - .into_iter() - .map(|n_p| UTXONullifier { utxo_hash: *n_p }) - .collect(); - nsmt.insert_items(nullifiers).unwrap(); - - nsmt.get_non_membership_proof(nullifier) - .unwrap() - .1 - .is_none() -} - -// Check balances - -// takes the public_info and output_utxos[], -// returns the True if the token amount in public_info matches the sum of all output_utxos[], otherwise return False. -pub fn check_balances(public_info: u128, output_utxos: &[UTXO]) -> bool { - let total_output: u128 = output_utxos.iter().map(|utxo| utxo.amount).sum(); - public_info == total_output -} - -// Verify Pedersen commitment - -// takes the public_info, secret_r and pedersen_commitment and -// checks that commitment(public_info,secret_r) is equal pedersen_commitment where the commitment is pedersen commitment. -pub fn verify_commitment( - public_info: u64, - secret_r: &[u8], - pedersen_commitment: &PedersenCommitment, -) -> bool { - let commitment_secrets = CommitmentSecrets { - value: public_info, - value_blinding_factor: Tweak::from_slice(secret_r).unwrap(), - generator_blinding_factor: Tweak::new(&mut thread_rng()), - }; - - let tag = tag_random(); - let commitment = commit(&commitment_secrets, tag); - - commitment == *pedersen_commitment -} - -// new_commitment -pub fn new_commitment(public_info: u64, secret_r: &[u8]) -> (Tweak, &[u8], PedersenCommitment) { - let generator_blinding_factor = Tweak::new(&mut thread_rng()); - let commitment_secrets = CommitmentSecrets { - value: public_info, - value_blinding_factor: Tweak::from_slice(secret_r).unwrap(), - generator_blinding_factor, - }; - - let tag = tag_random(); - let commitment = commit(&commitment_secrets, tag); - - (generator_blinding_factor, secret_r, commitment) -} - -// new_commitment for a Vec of values -pub fn new_commitment_vec( - public_info_vec: Vec, - secret_r: &[u8], -) -> (Tweak, &[u8], Vec) { - let generator_blinding_factor = Tweak::new(&mut thread_rng()); - let tag = tag_random(); - - let vec_commitments = public_info_vec - .into_iter() - .map(|public_info| { - let commitment_secrets = CommitmentSecrets { - value: public_info, - value_blinding_factor: Tweak::from_slice(secret_r).unwrap(), - generator_blinding_factor, - }; - - commit(&commitment_secrets, tag) - }) - .collect(); - - (generator_blinding_factor, secret_r, vec_commitments) -} - -#[allow(unused)] -fn de_kernel( - root_commitment: &[u8], - root_nullifier: [u8; 32], - public_info: u64, - input_utxos: &[UTXO], - in_commitments_proof: &[Vec], - nullifiers_proof: &[[u8; 32]], - nullifier_secret_key: Scalar, -) -> (Vec, Vec>) { - check_balances(public_info as u128, input_utxos); - - let nullifiers: Vec<_> = input_utxos - .into_iter() - .map(|utxo| generate_nullifiers(&utxo, &nullifier_secret_key.to_bytes())) - .collect(); - - let in_commitments = generate_commitments(&input_utxos); - - for in_commitment in in_commitments { - validate_in_commitments_proof( - &in_commitment, - root_commitment.to_vec(), - in_commitments_proof, - ); - } - - for nullifier in nullifiers.iter() { - validate_nullifiers_proof( - nullifier[0..32].try_into().unwrap(), - root_nullifier, - nullifiers_proof, - ); - } - - (vec![], nullifiers) -} diff --git a/node_core/src/executions/mod.rs b/node_core/src/executions/mod.rs deleted file mode 100644 index 7c9d33e..0000000 --- a/node_core/src/executions/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod de; -pub mod private_exec; -pub mod se; diff --git a/node_core/src/executions/private_exec.rs b/node_core/src/executions/private_exec.rs deleted file mode 100644 index 2e06c86..0000000 --- a/node_core/src/executions/private_exec.rs +++ /dev/null @@ -1,133 +0,0 @@ -use bincode; -use common::{ - commitment::Commitment, commitments_sparse_merkle_tree::CommitmentsSparseMerkleTree, - nullifier::UTXONullifier, nullifier_sparse_merkle_tree::NullifierSparseMerkleTree, -}; -use k256::Scalar; -use monotree::hasher::Blake3; -use monotree::{Hasher, Monotree}; -use sha2::{Digest, Sha256}; -use utxo::utxo_core::UTXO; - -fn hash(input: &[u8]) -> Vec { - Sha256::digest(input).to_vec() -} - -// Generate nullifiers - -// takes the input_utxo and nsk -// returns the nullifiers[i], where the nullifier[i] = hash(in_commitments[i] || nsk) where the hash function -pub fn generate_nullifiers(input_utxo: &UTXO, nsk: &[u8]) -> Vec { - let mut input = bincode::serialize(input_utxo).unwrap().to_vec(); - input.extend_from_slice(nsk); - hash(&input) -} - -// Generate commitments for output UTXOs - -// uses the list of input_utxos[] -// returns in_commitments[] where each in_commitments[i] = Commitment(in_utxos[i]) where the commitment -pub fn generate_commitments(input_utxos: &[UTXO]) -> Vec> { - input_utxos - .iter() - .map(|utxo| { - let serialized = bincode::serialize(utxo).unwrap(); // Serialize UTXO. - hash(&serialized) - }) - .collect() -} - -// Validate inclusion proof for in_commitments - -// takes the in_commitments[i] as a leaf, the root hash root_commitment and the path in_commitments_proofs[i][], -// returns True if the in_commitments[i] is in the tree with root hash root_commitment otherwise returns False, as membership proof. -pub fn validate_in_commitments_proof( - in_commitment: &Vec, - root_commitment: Vec, - in_commitments_proof: &[Vec], -) -> bool { - // Placeholder implementation. - // Replace with Merkle proof verification logic. - // hash(&[pedersen_commitment.serialize().to_vec(), in_commitments_proof.concat()].concat()) == root_commitment - - let mut nsmt = CommitmentsSparseMerkleTree { - curr_root: Option::Some(root_commitment), - tree: Monotree::default(), - hasher: Blake3::new(), - }; - - let commitments: Vec<_> = in_commitments_proof - .into_iter() - .map(|n_p| Commitment { - commitment_hash: n_p.clone(), - }) - .collect(); - nsmt.insert_items(commitments).unwrap(); - - nsmt.get_non_membership_proof(in_commitment.clone()) - .unwrap() - .1 - .is_some() -} - -// Validate non-membership proof for nullifiers - -// takes the nullifiers[i], path nullifiers_proof[i][] and the root hash root_nullifier, -// returns True if the nullifiers[i] is not in the tree with root hash root_nullifier otherwise returns False, as non-membership proof. -pub fn validate_nullifiers_proof( - nullifier: [u8; 32], - root_nullifier: [u8; 32], - nullifiers_proof: &[[u8; 32]], -) -> bool { - let mut nsmt = NullifierSparseMerkleTree { - curr_root: Option::Some(root_nullifier), - tree: Monotree::default(), - hasher: Blake3::new(), - }; - - let nullifiers: Vec<_> = nullifiers_proof - .into_iter() - .map(|n_p| UTXONullifier { utxo_hash: *n_p }) - .collect(); - nsmt.insert_items(nullifiers).unwrap(); - - nsmt.get_non_membership_proof(nullifier) - .unwrap() - .1 - .is_none() -} - -#[allow(unused)] -fn private_kernel( - root_commitment: &[u8], - root_nullifier: [u8; 32], - input_utxos: &[UTXO], - in_commitments_proof: &[Vec], - nullifiers_proof: &[[u8; 32]], - nullifier_secret_key: Scalar, -) -> (Vec, Vec>) { - let nullifiers: Vec<_> = input_utxos - .into_iter() - .map(|utxo| generate_nullifiers(&utxo, &nullifier_secret_key.to_bytes())) - .collect(); - - let in_commitments = generate_commitments(&input_utxos); - - for in_commitment in in_commitments { - validate_in_commitments_proof( - &in_commitment, - root_commitment.to_vec(), - in_commitments_proof, - ); - } - - for nullifier in nullifiers.iter() { - validate_nullifiers_proof( - nullifier[0..32].try_into().unwrap(), - root_nullifier, - nullifiers_proof, - ); - } - - (vec![], nullifiers) -} diff --git a/node_core/src/executions/se.rs b/node_core/src/executions/se.rs deleted file mode 100644 index d37fee5..0000000 --- a/node_core/src/executions/se.rs +++ /dev/null @@ -1,186 +0,0 @@ -use bincode; -use common::{ - commitment::Commitment, commitments_sparse_merkle_tree::CommitmentsSparseMerkleTree, - nullifier::UTXONullifier, nullifier_sparse_merkle_tree::NullifierSparseMerkleTree, -}; -use k256::Scalar; -use monotree::hasher::Blake3; -use monotree::{Hasher, Monotree}; -use rand::thread_rng; -use secp256k1_zkp::{CommitmentSecrets, Generator, PedersenCommitment, Tag, Tweak, SECP256K1}; -use sha2::{Digest, Sha256}; -use utxo::utxo_core::UTXO; - -#[allow(unused)] -fn commitment_secrets_random(value: u64) -> CommitmentSecrets { - CommitmentSecrets { - value, - value_blinding_factor: Tweak::new(&mut thread_rng()), - generator_blinding_factor: Tweak::new(&mut thread_rng()), - } -} - -pub fn tag_random() -> Tag { - use rand::thread_rng; - use rand::RngCore; - - let mut bytes = [0u8; 32]; - thread_rng().fill_bytes(&mut bytes); - - Tag::from(bytes) -} - -pub fn commit(comm: &CommitmentSecrets, tag: Tag) -> PedersenCommitment { - let generator = Generator::new_blinded(SECP256K1, tag, comm.generator_blinding_factor); - - PedersenCommitment::new(SECP256K1, comm.value, comm.value_blinding_factor, generator) -} - -fn hash(input: &[u8]) -> Vec { - Sha256::digest(input).to_vec() -} - -// Generate nullifiers - -// takes the pedersen_commitment and nsk then -// returns a list of nullifiers, where the nullifier = hash(pedersen_commitment || nsk) where the hash function will be determined - -pub fn generate_nullifiers(pedersen_commitment: &PedersenCommitment, nsk: &[u8]) -> Vec { - let mut input = pedersen_commitment.serialize().to_vec(); - input.extend_from_slice(nsk); - hash(&input) -} - -// Generate commitments for output UTXOs - -// uses the list of output_utxos[] and -// returns out_commitments[] where each out_commitments[i] = Commitment(output_utxos[i]) -// where the commitment will be determined -pub fn generate_commitments(output_utxos: &[UTXO]) -> Vec> { - output_utxos - .iter() - .map(|utxo| { - let serialized = bincode::serialize(utxo).unwrap(); // Serialize UTXO. - hash(&serialized) - }) - .collect() -} - -// Validate inclusion proof for in_commitments - -// takes the pedersen_commitment as a leaf, the root hash root_commitment and the path in_commitments_proof[], -// returns True if the pedersen_commitment is in the tree with root hash root_commitment -// otherwise -// returns False, as membership proof. -pub fn validate_in_commitments_proof( - pedersen_commitment: &PedersenCommitment, - root_commitment: Vec, - in_commitments_proof: &[Vec], -) -> bool { - let mut nsmt = CommitmentsSparseMerkleTree { - curr_root: Option::Some(root_commitment), - tree: Monotree::default(), - hasher: Blake3::new(), - }; - - let commitments: Vec<_> = in_commitments_proof - .into_iter() - .map(|n_p| Commitment { - commitment_hash: n_p.clone(), - }) - .collect(); - nsmt.insert_items(commitments).unwrap(); - - nsmt.get_non_membership_proof(pedersen_commitment.serialize().to_vec()) - .unwrap() - .1 - .is_some() -} - -// Validate non-membership proof for nullifiers - -// takes the nullifier, path nullifiers_proof[] and the root hash root_nullifier, -// returns True if the nullifier is not in the tree with root hash root_nullifier -// otherwise -// returns False, as non-membership proof. -pub fn validate_nullifiers_proof( - nullifier: [u8; 32], - root_nullifier: [u8; 32], - nullifiers_proof: &[[u8; 32]], -) -> bool { - let mut nsmt = NullifierSparseMerkleTree { - curr_root: Option::Some(root_nullifier), - tree: Monotree::default(), - hasher: Blake3::new(), - }; - - let nullifiers: Vec<_> = nullifiers_proof - .into_iter() - .map(|n_p| UTXONullifier { utxo_hash: *n_p }) - .collect(); - nsmt.insert_items(nullifiers).unwrap(); - - nsmt.get_non_membership_proof(nullifier) - .unwrap() - .1 - .is_none() -} - -// Check balances - -// takes the public_info and output_utxos[], -// returns the True if the token amount in public_info matches the sum of all output_utxos[], otherwise return False. -pub fn check_balances(public_info: u128, output_utxos: &[UTXO]) -> bool { - let total_output: u128 = output_utxos.iter().map(|utxo| utxo.amount).sum(); - public_info == total_output -} - -// Verify Pedersen commitment - -// takes the public_info, secret_r and pedersen_commitment and -// checks that commitment(public_info,secret_r) is equal pedersen_commitment where the commitment is pedersen commitment. -pub fn verify_commitment( - public_info: u64, - secret_r: &[u8], - pedersen_commitment: &PedersenCommitment, -) -> bool { - let commitment_secrets = CommitmentSecrets { - value: public_info, - value_blinding_factor: Tweak::from_slice(secret_r).unwrap(), - generator_blinding_factor: Tweak::new(&mut thread_rng()), - }; - - let tag = tag_random(); - let commitment = commit(&commitment_secrets, tag); - - commitment == *pedersen_commitment -} - -#[allow(unused)] -fn se_kernel( - root_commitment: &[u8], - root_nullifier: [u8; 32], - public_info: u64, - pedersen_commitment: PedersenCommitment, - secret_r: &[u8], - output_utxos: &[UTXO], - in_commitments_proof: &[Vec], - nullifiers_proof: &[[u8; 32]], - nullifier_secret_key: Scalar, -) -> (Vec, Vec>, Vec) { - check_balances(public_info as u128, output_utxos); - - let out_commitments = generate_commitments(output_utxos); - - let nullifier = generate_nullifiers(&pedersen_commitment, &nullifier_secret_key.to_bytes()); - - validate_in_commitments_proof( - &pedersen_commitment, - root_commitment.to_vec(), - in_commitments_proof, - ); - - verify_commitment(public_info, secret_r, &pedersen_commitment); - - (vec![], out_commitments, nullifier) -} diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index 5228e9b..ca412c4 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -10,9 +10,10 @@ use anyhow::Result; use chain_storage::NodeChainStore; use common::transaction::{Transaction, TransactionPayload, TxKind}; use config::NodeConfig; -use executions::private_exec::{generate_commitments, generate_nullifiers}; use log::info; -use sc_core::proofs_circuits::pedersen_commitment_vec; +use sc_core::proofs_circuits::{ + generate_commitments, generate_nullifiers, generate_nullifiers_se, pedersen_commitment_vec, +}; use sequencer_client::{json::SendTxResponse, SequencerClient}; use serde::{Deserialize, Serialize}; use storage::sc_db_utils::DataBlobChangeVariant; @@ -28,7 +29,6 @@ pub const BLOCK_GEN_DELAY_SECS: u64 = 20; pub mod chain_storage; pub mod config; -pub mod executions; ///Module, which includes pre start setup helperfunctions pub mod pre_start; pub mod sequencer_client; @@ -164,10 +164,9 @@ impl NodeCore { }) } - pub async fn get_roots(&self) -> [[u8; 32]; 3] { + pub async fn get_roots(&self) -> [[u8; 32]; 2] { let storage = self.storage.read().await; [ - storage.nullifier_store.curr_root.unwrap_or([0; 32]), storage.utxo_commitments_store.get_root().unwrap_or([0; 32]), storage.pub_tx_store.get_root().unwrap_or([0; 32]), ] @@ -651,7 +650,7 @@ impl NodeCore { ) .unwrap(); - let nullifier = executions::se::generate_nullifiers( + let nullifier = generate_nullifiers_se( &commitment, &account .key_holder diff --git a/node_core/src/sequencer_client/json.rs b/node_core/src/sequencer_client/json.rs index 0c5373b..df94ca2 100644 --- a/node_core/src/sequencer_client/json.rs +++ b/node_core/src/sequencer_client/json.rs @@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] pub struct SendTxRequest { pub transaction: Transaction, - ///Nullifier Root, UTXO Commitment Root, Pub Tx Root - pub tx_roots: [[u8; 32]; 3], + ///UTXO Commitment Root, Pub Tx Root + pub tx_roots: [[u8; 32]; 2], } //Responses diff --git a/node_core/src/sequencer_client/mod.rs b/node_core/src/sequencer_client/mod.rs index bc40a3a..7accd5f 100644 --- a/node_core/src/sequencer_client/mod.rs +++ b/node_core/src/sequencer_client/mod.rs @@ -73,7 +73,7 @@ impl SequencerClient { pub async fn send_tx( &self, transaction: Transaction, - tx_roots: [[u8; 32]; 3], + tx_roots: [[u8; 32]; 2], ) -> Result { let tx_req = SendTxRequest { transaction, diff --git a/node_rpc/src/types/err_rpc.rs b/node_rpc/src/types/err_rpc.rs index e1ace1f..0e75f7a 100644 --- a/node_rpc/src/types/err_rpc.rs +++ b/node_rpc/src/types/err_rpc.rs @@ -81,6 +81,5 @@ pub fn cast_common_execution_error_into_rpc_error(comm_exec_err: ExecutionFailur ExecutionFailureKind::SequencerClientError(seq_cli_err) => { cast_seq_client_error_into_rpc_error(seq_cli_err) } - ExecutionFailureKind::MonoTreeError(_) => RpcError::new_internal_error(None, &error_string), } } diff --git a/sc_core/Cargo.toml b/sc_core/Cargo.toml index 55ba888..e93c955 100644 --- a/sc_core/Cargo.toml +++ b/sc_core/Cargo.toml @@ -12,7 +12,6 @@ serde.workspace = true rand.workspace = true k256.workspace = true sha2.workspace = true -monotree.workspace = true bincode.workspace = true elliptic-curve.workspace = true hex.workspace = true diff --git a/sc_core/src/proofs_circuits.rs b/sc_core/src/proofs_circuits.rs index 2072e55..cbebe3e 100644 --- a/sc_core/src/proofs_circuits.rs +++ b/sc_core/src/proofs_circuits.rs @@ -1,11 +1,5 @@ use bincode; -use common::{ - commitment::Commitment, commitments_sparse_merkle_tree::CommitmentsSparseMerkleTree, - nullifier::UTXONullifier, nullifier_sparse_merkle_tree::NullifierSparseMerkleTree, -}; use k256::Scalar; -use monotree::hasher::Blake3; -use monotree::{Hasher, Monotree}; use rand::{thread_rng, RngCore}; use secp256k1_zkp::{CommitmentSecrets, Generator, PedersenCommitment, Tag, Tweak, SECP256K1}; use sha2::{Digest, Sha256}; @@ -44,59 +38,21 @@ pub fn generate_commitments(input_utxos: &[UTXO]) -> Vec> { // takes the in_commitments[i] as a leaf, the root hash root_commitment and the path in_commitments_proofs[i][], // returns True if the in_commitments[i] is in the tree with root hash root_commitment otherwise returns False, as membership proof. pub fn validate_in_commitments_proof( - in_commitment: &Vec, - root_commitment: Vec, - in_commitments_proof: &[Vec], + _in_commitment: &Vec, + _root_commitment: Vec, + _in_commitments_proof: &[Vec], ) -> bool { - // Placeholder implementation. - // Replace with Merkle proof verification logic. - // hash(&[pedersen_commitment.serialize().to_vec(), in_commitments_proof.concat()].concat()) == root_commitment + // ToDo: Implement correct check - let mut nsmt = CommitmentsSparseMerkleTree { - curr_root: Option::Some(root_commitment), - tree: Monotree::default(), - hasher: Blake3::new(), - }; - - let commitments: Vec<_> = in_commitments_proof - .into_iter() - .map(|n_p| Commitment { - commitment_hash: n_p.clone(), - }) - .collect(); - nsmt.insert_items(commitments).unwrap(); - - nsmt.get_non_membership_proof(in_commitment.clone()) - .unwrap() - .1 - .is_some() + todo!() } -// Validate non-membership proof for nullifiers - -// takes the nullifiers[i], path nullifiers_proof[i][] and the root hash root_nullifier, -// returns True if the nullifiers[i] is not in the tree with root hash root_nullifier otherwise returns False, as non-membership proof. -pub fn validate_nullifiers_proof( +// Validate that `nullifier` has not been present in set items before +pub fn validate_nullifier_not_present_in_set_items( nullifier: [u8; 32], - root_nullifier: [u8; 32], - nullifiers_proof: &[[u8; 32]], + nullifiers_items: &[[u8; 32]], ) -> bool { - let mut nsmt = NullifierSparseMerkleTree { - curr_root: Option::Some(root_nullifier), - tree: Monotree::default(), - hasher: Blake3::new(), - }; - - let nullifiers: Vec<_> = nullifiers_proof - .into_iter() - .map(|n_p| UTXONullifier { utxo_hash: *n_p }) - .collect(); - nsmt.insert_items(nullifiers).unwrap(); - - nsmt.get_non_membership_proof(nullifier) - .unwrap() - .1 - .is_none() + !nullifiers_items.contains(&nullifier) } #[allow(unused)] @@ -124,9 +80,8 @@ fn private_kernel( } for nullifier in nullifiers.iter() { - validate_nullifiers_proof( + validate_nullifier_not_present_in_set_items( nullifier[0..32].try_into().unwrap(), - root_nullifier, nullifiers_proof, ); } @@ -243,9 +198,8 @@ fn de_kernel( } for nullifier in nullifiers.iter() { - validate_nullifiers_proof( + validate_nullifier_not_present_in_set_items( nullifier[0..32].try_into().unwrap(), - root_nullifier, nullifiers_proof, ); } @@ -260,28 +214,13 @@ fn de_kernel( // otherwise // returns False, as membership proof. pub fn validate_in_commitments_proof_se( - pedersen_commitment: &PedersenCommitment, - root_commitment: Vec, - in_commitments_proof: &[Vec], + _pedersen_commitment: &PedersenCommitment, + _root_commitment: Vec, + _in_commitments_proof: &[Vec], ) -> bool { - let mut nsmt = CommitmentsSparseMerkleTree { - curr_root: Option::Some(root_commitment), - tree: Monotree::default(), - hasher: Blake3::new(), - }; + // ToDo: Implement correct check - let commitments: Vec<_> = in_commitments_proof - .into_iter() - .map(|n_p| Commitment { - commitment_hash: n_p.clone(), - }) - .collect(); - nsmt.insert_items(commitments).unwrap(); - - nsmt.get_non_membership_proof(pedersen_commitment.serialize().to_vec()) - .unwrap() - .1 - .is_some() + todo!() } // Generate nullifiers SE diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index d073ffb..7a083f1 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -59,9 +59,8 @@ impl SequencerCore { } } - pub fn get_tree_roots(&self) -> [[u8; 32]; 3] { + pub fn get_tree_roots(&self) -> [[u8; 32]; 2] { [ - self.store.nullifier_store.curr_root.unwrap_or([0; 32]), self.store .utxo_commitments_store .get_root() @@ -73,7 +72,7 @@ impl SequencerCore { pub fn transaction_pre_check( &mut self, tx: &Transaction, - tx_roots: [[u8; 32]; 3], + tx_roots: [[u8; 32]; 2], ) -> Result<(), TransactionMalformationErrorKind> { let Transaction { hash, @@ -135,10 +134,9 @@ impl SequencerCore { let nullifier_tree_check = nullifier_created_hashes .iter() .map(|nullifier_hash| { - self.store - .nullifier_store - .search_item_inclusion(*nullifier_hash) - .unwrap_or(false) + self.store.nullifier_store.contains(&UTXONullifier { + utxo_hash: *nullifier_hash, + }) }) .any(|check| check); let utxo_commitments_check = utxo_commitments_created_hashes @@ -173,7 +171,7 @@ impl SequencerCore { pub fn push_tx_into_mempool_pre_check( &mut self, item: TransactionMempool, - tx_roots: [[u8; 32]; 3], + tx_roots: [[u8; 32]; 2], ) -> Result<(), TransactionMalformationErrorKind> { self.transaction_pre_check(&item.tx, tx_roots)?; @@ -187,7 +185,8 @@ impl SequencerCore { tx: TransactionMempool, ) -> Result<(), TransactionMalformationErrorKind> { let Transaction { - hash, + // ToDo: remove hashing of transactions on node side [Issue #66] + hash: _, ref utxo_commitments_created_hashes, ref nullifier_created_hashes, .. @@ -199,16 +198,10 @@ impl SequencerCore { .add_tx(UTXOCommitment { hash: *utxo_comm }); } - for nullifier in nullifier_created_hashes { - self.store - .nullifier_store - .insert_item(UTXONullifier { - utxo_hash: *nullifier, - }) - .map_err(|err| TransactionMalformationErrorKind::FailedToInsert { - tx: hash, - details: format!("{err:?}"), - })?; + for nullifier in nullifier_created_hashes.iter() { + self.store.nullifier_store.insert(UTXONullifier { + utxo_hash: *nullifier, + }); } self.store.pub_tx_store.add_tx(tx.tx); @@ -225,12 +218,14 @@ impl SequencerCore { ///Produces new block from transactions in mempool pub fn produce_new_block_with_mempool_transactions(&mut self) -> Result { + let new_block_height = self.chain_height + 1; + let transactions = self .mempool .pop_size(self.sequencer_config.max_num_tx_in_block); - for tx in transactions.clone() { - self.execute_check_transaction_on_state(tx)?; + for tx in &transactions { + self.execute_check_transaction_on_state(tx.clone())?; } let prev_block_hash = self @@ -240,7 +235,7 @@ impl SequencerCore { .hash; let hashable_data = HashableBlockData { - block_id: self.chain_height + 1, + block_id: new_block_height, prev_block_id: self.chain_height, transactions: transactions.into_iter().map(|tx_mem| tx_mem.tx).collect(), data: vec![], @@ -337,7 +332,7 @@ mod tests { common_setup(&mut sequencer); let roots = sequencer.get_tree_roots(); - assert_eq!(roots.len(), 3); // Should return three roots + assert_eq!(roots.len(), 2); // Should return two roots } #[test] diff --git a/sequencer_core/src/sequencer_store/mod.rs b/sequencer_core/src/sequencer_store/mod.rs index fd09d93..322c99d 100644 --- a/sequencer_core/src/sequencer_store/mod.rs +++ b/sequencer_core/src/sequencer_store/mod.rs @@ -1,11 +1,11 @@ -use std::path::Path; +use std::{collections::HashSet, path::Path}; use accounts_store::SequencerAccountsStore; use block_store::SequecerBlockStore; use common::{ block::{Block, HashableBlockData}, merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree}, - nullifier_sparse_merkle_tree::NullifierSparseMerkleTree, + nullifier::UTXONullifier, }; use rand::{rngs::OsRng, RngCore}; @@ -15,7 +15,7 @@ pub mod block_store; pub struct SequecerChainStore { pub acc_store: SequencerAccountsStore, pub block_store: SequecerBlockStore, - pub nullifier_store: NullifierSparseMerkleTree, + pub nullifier_store: HashSet, pub utxo_commitments_store: UTXOCommitmentsMerkleTree, pub pub_tx_store: PublicTransactionMerkleTree, } @@ -23,7 +23,7 @@ pub struct SequecerChainStore { impl SequecerChainStore { pub fn new_with_genesis(home_dir: &Path, genesis_id: u64, is_genesis_random: bool) -> Self { let acc_store = SequencerAccountsStore::default(); - let nullifier_store = NullifierSparseMerkleTree::default(); + let nullifier_store = HashSet::new(); let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]); let pub_tx_store = PublicTransactionMerkleTree::new(vec![]); diff --git a/utxo/Cargo.toml b/utxo/Cargo.toml index 9b99cf9..0d97789 100644 --- a/utxo/Cargo.toml +++ b/utxo/Cargo.toml @@ -9,7 +9,6 @@ serde_json.workspace = true env_logger.workspace = true log.workspace = true serde.workspace = true -monotree.workspace = true sha2.workspace = true hex.workspace = true