feat!: migrate Orchard commitment trees to Frontier

This commit is contained in:
Rene Vergara 2024-09-30 12:05:00 -05:00
parent 5de1844e9d
commit 48afd81595
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
9 changed files with 283 additions and 244 deletions

View file

@ -5,9 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.7.1.0]
### Added
- Type `OrchardFrontier`
### Changed
- Modified Orchard commitment trees functions to use Frontier
## [0.7.0.2] ## [0.7.0.2]
## Changed ### Changed
- Modified witness update functions to skip the process if no commitments are present - Modified witness update functions to skip the process if no commitments are present

View file

@ -66,9 +66,9 @@ checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d"
[[package]] [[package]]
name = "base64ct" name = "base64ct"
version = "1.0.1" version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]] [[package]]
name = "bech32" name = "bech32"
@ -120,9 +120,9 @@ dependencies = [
[[package]] [[package]]
name = "bip0039" name = "bip0039"
version = "0.10.1" version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef0f0152ec5cf17f49a5866afaa3439816207fd4f0a224c0211ffaf5e278426" checksum = "568b6890865156d9043af490d4c4081c385dd68ea10acd6ca15733d511e6b51c"
dependencies = [ dependencies = [
"hmac", "hmac",
"pbkdf2", "pbkdf2",
@ -132,6 +132,22 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "bip32"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa13fae8b6255872fd86f7faf4b41168661d7d78609f7bfe6771b85c6739a15b"
dependencies = [
"bs58 0.5.0",
"hmac",
"rand_core",
"ripemd",
"secp256k1",
"sha2 0.10.6",
"subtle",
"zeroize",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -318,12 +334,6 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "bumpalo"
version = "3.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
version = "1.4.3" version = "1.4.3"
@ -709,19 +719,6 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "hdwallet"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a03ba7d4c9ea41552cd4351965ff96883e629693ae85005c501bb4b9e1c48a7"
dependencies = [
"lazy_static",
"rand_core",
"ring",
"secp256k1",
"thiserror",
]
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.4.1" version = "0.4.1"
@ -760,9 +757,9 @@ dependencies = [
[[package]] [[package]]
name = "incrementalmerkletree" name = "incrementalmerkletree"
version = "0.5.1" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb1872810fb725b06b8c153dde9e86f3ec26747b9b60096da7a869883b549cbe" checksum = "75346da3bd8e3d8891d02508245ed2df34447ca6637e343829f8d08986e9cde2"
dependencies = [ dependencies = [
"either", "either",
] ]
@ -815,15 +812,6 @@ dependencies = [
"either", "either",
] ]
[[package]]
name = "js-sys"
version = "0.3.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee"
dependencies = [
"wasm-bindgen",
]
[[package]] [[package]]
name = "jubjub" name = "jubjub"
version = "0.10.0" version = "0.10.0"
@ -999,9 +987,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]] [[package]]
name = "orchard" name = "orchard"
version = "0.7.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fb255c3ffdccd3c84fe9ebed72aef64fdc72e6a3e4180dd411002d47abaad42" checksum = "4dc7bde644aeb980be296cd908c6650894dc8541deb56f9f5294c52ed7ca568f"
dependencies = [ dependencies = [
"aes", "aes",
"bitvec", "bitvec",
@ -1022,6 +1010,7 @@ dependencies = [
"serde", "serde",
"subtle", "subtle",
"tracing", "tracing",
"visibility",
"zcash_note_encryption", "zcash_note_encryption",
"zcash_spec", "zcash_spec",
"zip32", "zip32",
@ -1038,9 +1027,9 @@ dependencies = [
[[package]] [[package]]
name = "password-hash" name = "password-hash"
version = "0.3.2" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d791538a6dcc1e7cb7fe6f6b58aca40e7f79403c45b2bc274008b5e647af1d8" checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166"
dependencies = [ dependencies = [
"base64ct", "base64ct",
"rand_core", "rand_core",
@ -1064,9 +1053,9 @@ dependencies = [
[[package]] [[package]]
name = "pbkdf2" name = "pbkdf2"
version = "0.10.1" version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271779f35b581956db91a3e55737327a03aa051e90b1c47aeb189508533adfd7" checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
dependencies = [ dependencies = [
"digest 0.10.7", "digest 0.10.7",
"password-hash", "password-hash",
@ -1147,9 +1136,9 @@ dependencies = [
[[package]] [[package]]
name = "prost" name = "prost"
version = "0.12.3" version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a" checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f"
dependencies = [ dependencies = [
"bytes", "bytes",
"prost-derive", "prost-derive",
@ -1157,9 +1146,9 @@ dependencies = [
[[package]] [[package]]
name = "prost-build" name = "prost-build"
version = "0.12.3" version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c55e02e35260070b6f716a2423c2ff1c3bb1642ddca6f99e1f26d06268a0e2d2" checksum = "0c1318b19085f08681016926435853bbf7858f9c082d0999b80550ff5d9abe15"
dependencies = [ dependencies = [
"bytes", "bytes",
"heck", "heck",
@ -1174,14 +1163,13 @@ dependencies = [
"regex", "regex",
"syn 2.0.32", "syn 2.0.32",
"tempfile", "tempfile",
"which",
] ]
[[package]] [[package]]
name = "prost-derive" name = "prost-derive"
version = "0.12.3" version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"itertools", "itertools",
@ -1192,9 +1180,9 @@ dependencies = [
[[package]] [[package]]
name = "prost-types" name = "prost-types"
version = "0.12.3" version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "193898f59edcf43c26227dcd4c8427f00d99d61e95dcde58dabd49fa291d470e" checksum = "4759aa0d3a6232fb8dbdb97b61de2c20047c68aca932c7ed76da9d788508d670"
dependencies = [ dependencies = [
"prost", "prost",
] ]
@ -1341,21 +1329,6 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "ring"
version = "0.16.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
dependencies = [
"cc",
"libc",
"once_cell",
"spin",
"untrusted",
"web-sys",
"winapi",
]
[[package]] [[package]]
name = "ripemd" name = "ripemd"
version = "0.1.3" version = "0.1.3"
@ -1384,6 +1357,7 @@ name = "rustzcash-wrapper"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bech32 0.11.0", "bech32 0.11.0",
"bip0039",
"borsh 0.10.3", "borsh 0.10.3",
"f4jumble", "f4jumble",
"haskell-ffi", "haskell-ffi",
@ -1405,9 +1379,9 @@ dependencies = [
[[package]] [[package]]
name = "sapling-crypto" name = "sapling-crypto"
version = "0.1.3" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02f4270033afcb0c74c5c7d59c73cfd1040367f67f224fe7ed9a919ae618f1b7" checksum = "15e379398fffad84e49f9a45a05635fc004f66086e65942dbf4eb95332c26d2a"
dependencies = [ dependencies = [
"aes", "aes",
"bellman", "bellman",
@ -1443,9 +1417,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "secp256k1" name = "secp256k1"
version = "0.26.0" version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4124a35fe33ae14259c490fd70fa199a32b9ce9502f2ee6bc4f81ec06fa65894" checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f"
dependencies = [ dependencies = [
"secp256k1-sys", "secp256k1-sys",
] ]
@ -1514,9 +1488,9 @@ dependencies = [
[[package]] [[package]]
name = "shardtree" name = "shardtree"
version = "0.2.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf20c7a2747d9083092e3a3eeb9a7ed75577ae364896bebbc5e0bdcd4e97735" checksum = "78222845cd8bbe5eb95687407648ff17693a35de5e8abaa39a4681fb21e033f9"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"either", "either",
@ -1649,13 +1623,14 @@ dependencies = [
[[package]] [[package]]
name = "tonic-build" name = "tonic-build"
version = "0.10.2" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d021fc044c18582b9a2408cd0dd05b1596e3ecdb5c4df822bb0183545683889" checksum = "9557ce109ea773b399c9b9e5dca39294110b74f1f342cb347a80d1fce8c26a11"
dependencies = [ dependencies = [
"prettyplease", "prettyplease",
"proc-macro2", "proc-macro2",
"prost-build", "prost-build",
"prost-types",
"quote", "quote",
"syn 2.0.32", "syn 2.0.32",
] ]
@ -1718,9 +1693,9 @@ checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
[[package]] [[package]]
name = "unicode-normalization" name = "unicode-normalization"
version = "0.1.22" version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956"
dependencies = [ dependencies = [
"tinyvec", "tinyvec",
] ]
@ -1735,18 +1710,23 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "untrusted"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "visibility"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d674d135b4a8c1d7e813e2f8d1c9a58308aee4a680323066025e53132218bd91"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.32",
]
[[package]] [[package]]
name = "wagyu-zcash-parameters" name = "wagyu-zcash-parameters"
version = "0.2.0" version = "0.2.0"
@ -1803,70 +1783,6 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.32",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.32",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
[[package]]
name = "web-sys"
version = "0.3.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]] [[package]]
name = "which" name = "which"
version = "4.4.0" version = "4.4.0"
@ -1878,28 +1794,6 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.48.0" version = "0.48.0"
@ -1989,21 +1883,22 @@ dependencies = [
[[package]] [[package]]
name = "zcash_address" name = "zcash_address"
version = "0.3.1" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bce173f1d9ed4f806e310bc3a873301531e7a6dc209928584d6404e3f8228ef4" checksum = "a6d26f21381dc220836dd8d2a9a10dbe85928a26232b011bc6a42b611789b743"
dependencies = [ dependencies = [
"bech32 0.9.1", "bech32 0.9.1",
"bs58 0.5.0", "bs58 0.5.0",
"f4jumble", "f4jumble",
"zcash_encoding", "zcash_encoding",
"zcash_protocol",
] ]
[[package]] [[package]]
name = "zcash_client_backend" name = "zcash_client_backend"
version = "0.11.1" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "001ec65dc2828ee648dc6d29f0944d7a877fe68ad06e001a203c11770ab1b3d4" checksum = "80e3a0f3e5d7f299d8b7ef3237697630989c31ab1b162824c99c1cd8bc83715e"
dependencies = [ dependencies = [
"base64", "base64",
"bech32 0.9.1", "bech32 0.9.1",
@ -2029,19 +1924,21 @@ dependencies = [
"tonic-build", "tonic-build",
"tracing", "tracing",
"which", "which",
"zcash_address 0.3.1", "zcash_address 0.4.0",
"zcash_encoding", "zcash_encoding",
"zcash_keys", "zcash_keys",
"zcash_note_encryption", "zcash_note_encryption",
"zcash_primitives", "zcash_primitives",
"zcash_protocol",
"zip32", "zip32",
"zip321",
] ]
[[package]] [[package]]
name = "zcash_encoding" name = "zcash_encoding"
version = "0.2.0" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f03391b81727875efa6ac0661a20883022b6fba92365dc121c48fa9b00c5aac0" checksum = "052d8230202f0a018cd9b5d1b56b94cd25e18eccc2d8665073bcea8261ab87fc"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"nonempty", "nonempty",
@ -2049,11 +1946,12 @@ dependencies = [
[[package]] [[package]]
name = "zcash_keys" name = "zcash_keys"
version = "0.1.1" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f22d3407fdd6992b49f037f23862ab376be6013be6f2d0bc85948a635edc1f5" checksum = "712faf4070107ab0b2828d0eda6aeaf4c3cb02564109832d95b97ad3467c95a5"
dependencies = [ dependencies = [
"bech32 0.9.1", "bech32 0.9.1",
"blake2b_simd",
"bls12_381", "bls12_381",
"bs58 0.5.0", "bs58 0.5.0",
"document-features", "document-features",
@ -2062,11 +1960,13 @@ dependencies = [
"nonempty", "nonempty",
"rand_core", "rand_core",
"sapling-crypto", "sapling-crypto",
"secrecy",
"subtle", "subtle",
"tracing", "tracing",
"zcash_address 0.3.1", "zcash_address 0.4.0",
"zcash_encoding", "zcash_encoding",
"zcash_primitives", "zcash_primitives",
"zcash_protocol",
"zip32", "zip32",
] ]
@ -2085,20 +1985,20 @@ dependencies = [
[[package]] [[package]]
name = "zcash_primitives" name = "zcash_primitives"
version = "0.14.0" version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9070e084570bb78aed4f8d71fd6254492e62c87a5d01e084183980e98117092d" checksum = "5f044bc9cf2887ec408196fbafb44749e5581f57cc18d8da7aabaeb60cc40c64"
dependencies = [ dependencies = [
"aes", "aes",
"bip0039", "bip32",
"blake2b_simd", "blake2b_simd",
"bs58 0.5.0",
"byteorder", "byteorder",
"document-features", "document-features",
"equihash", "equihash",
"ff", "ff",
"fpe", "fpe",
"group", "group",
"hdwallet",
"hex", "hex",
"incrementalmerkletree", "incrementalmerkletree",
"jubjub", "jubjub",
@ -2114,13 +2014,24 @@ dependencies = [
"sha2 0.10.6", "sha2 0.10.6",
"subtle", "subtle",
"tracing", "tracing",
"zcash_address 0.3.1", "zcash_address 0.4.0",
"zcash_encoding", "zcash_encoding",
"zcash_note_encryption", "zcash_note_encryption",
"zcash_protocol",
"zcash_spec", "zcash_spec",
"zip32", "zip32",
] ]
[[package]]
name = "zcash_protocol"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f35eac659fdbba614333d119217c5963c0d7cea43aee33176c4f2f95e5460d8d"
dependencies = [
"document-features",
"memuse",
]
[[package]] [[package]]
name = "zcash_spec" name = "zcash_spec"
version = "0.1.0" version = "0.1.0"
@ -2160,3 +2071,16 @@ dependencies = [
"memuse", "memuse",
"subtle", "subtle",
] ]
[[package]]
name = "zip321"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dc85f862f7be64fb0d46f9eb5b82ad54e58cde314fa979d5bae591bc0143693"
dependencies = [
"base64",
"nom",
"percent-encoding",
"zcash_address 0.4.0",
"zcash_protocol",
]

View file

@ -11,19 +11,20 @@ f4jumble = "0.1"
zcash_address = "0.2.0" zcash_address = "0.2.0"
borsh = "0.10" borsh = "0.10"
bech32 = "0.11" bech32 = "0.11"
orchard = "0.7.1" orchard = "0.9.0"
zcash_note_encryption = "0.4.0" zcash_note_encryption = "0.4.0"
zcash_primitives = { version = "0.14.0", features = ["transparent-inputs"]} zcash_primitives = { version = "0.16.0", features = ["transparent-inputs"]}
zcash_client_backend = "0.11.1" zcash_client_backend = "0.13.0"
sapling-crypto = "0.1.3" sapling-crypto = "0.2"
zip32 = "0.1.0" zip32 = "0.1.0"
proc-macro2 = "1.0.66" proc-macro2 = "1.0.66"
nonempty = "0.7.0" nonempty = "0.7.0"
incrementalmerkletree = "0.5.0" incrementalmerkletree = "0.6.0"
secp256k1 = "0.26.0" secp256k1 = "0.27.0"
jubjub = "0.10.0" jubjub = "0.10.0"
rand_core = { version = "0.6.4", features = ["getrandom"]} rand_core = { version = "0.6.4", features = ["getrandom"]}
wagyu-zcash-parameters = "0.2.0" wagyu-zcash-parameters = "0.2.0"
bip0039 = "0.12.0"
[features] [features]

View file

@ -30,7 +30,12 @@ use secp256k1::SecretKey;
use jubjub::Fr; use jubjub::Fr;
use incrementalmerkletree::{ use incrementalmerkletree::{
frontier::CommitmentTree, Position,
frontier::{
CommitmentTree,
Frontier,
NonEmptyFrontier
},
witness::IncrementalWitness witness::IncrementalWitness
}; };
@ -79,18 +84,20 @@ use sapling_crypto::{
} }
}; };
use bip0039::{Count, Mnemonic, English};
use zcash_primitives::{ use zcash_primitives::{
merkle_tree::{ merkle_tree::{
read_commitment_tree, read_commitment_tree,
write_commitment_tree, write_commitment_tree,
read_incremental_witness, read_incremental_witness,
write_incremental_witness write_incremental_witness,
read_frontier_v1
}, },
legacy::{ legacy::{
Script, Script,
TransparentAddress TransparentAddress
}, },
zip339::{Count, Mnemonic},
transaction::{ transaction::{
Transaction, Transaction,
fees::zip317::FeeRule, fees::zip317::FeeRule,
@ -147,7 +154,7 @@ use orchard::{
}, },
Action, Action,
keys::{SpendingKey, FullViewingKey, PreparedIncomingViewingKey, Scope}, keys::{SpendingKey, FullViewingKey, PreparedIncomingViewingKey, Scope},
note::{RandomSeed, Note, Nullifier, TransmittedNoteCiphertext, ExtractedNoteCommitment}, note::{Rho, RandomSeed, Note, Nullifier, TransmittedNoteCiphertext, ExtractedNoteCommitment},
note_encryption::OrchardDomain, note_encryption::OrchardDomain,
primitives::redpallas::{VerificationKey, SpendAuth, Signature}, primitives::redpallas::{VerificationKey, SpendAuth, Signature},
tree::{ tree::{
@ -686,6 +693,27 @@ impl<RW> ToHaskell<RW> for Hsvk {
} }
} }
#[derive(BorshSerialize, BorshDeserialize)]
pub struct Hfrontier {
position: u64,
leaf: Hhex,
ommers: Vec<Vec<u8>>
}
impl<RW> ToHaskell<RW> for Hfrontier {
fn to_haskell<W: Write>(&self, writer: &mut W, _tag: PhantomData<RW>) -> Result<()> {
self.serialize(writer)?;
Ok(())
}
}
impl<RW> FromHaskell<RW> for Hfrontier {
fn from_haskell(buf: &mut &[u8], _tag: PhantomData<RW>) -> Result<Self> {
let x = Hfrontier::deserialize(buf)?;
Ok(x)
}
}
fn to_array<T, const N: usize>(v: Vec<T>) -> [T; N] { fn to_array<T, const N: usize>(v: Vec<T>) -> [T; N] {
v.try_into().unwrap_or_else(|v: Vec<T>| panic!("Expected a Vec of length {} but it was {}", N, v.len())) v.try_into().unwrap_or_else(|v: Vec<T>| panic!("Expected a Vec of length {} but it was {}", N, v.len()))
} }
@ -1026,7 +1054,7 @@ pub extern "C" fn rust_wrapper_orchard_note_decrypt(
ValueCommitment::from_bytes(&to_array(note_input.cv.bytes)).unwrap(), ValueCommitment::from_bytes(&to_array(note_input.cv.bytes)).unwrap(),
Signature::from(to_array(note_input.auth.bytes))); Signature::from(to_array(note_input.auth.bytes)));
let fvk_array = to_array(fvk_input); let fvk_array = to_array(fvk_input);
let domain = OrchardDomain::for_nullifier(*action.nullifier()); let domain = OrchardDomain::for_action(&action);
let dec_fvk = FullViewingKey::from_bytes(&fvk_array); let dec_fvk = FullViewingKey::from_bytes(&fvk_array);
match dec_fvk { match dec_fvk {
Some(fvk) => { Some(fvk) => {
@ -1073,7 +1101,7 @@ pub extern "C" fn rust_wrapper_orchard_note_decrypt_sk(
ValueCommitment::from_bytes(&to_array(note_input.cv.bytes)).unwrap(), ValueCommitment::from_bytes(&to_array(note_input.cv.bytes)).unwrap(),
Signature::from(to_array(note_input.auth.bytes))); Signature::from(to_array(note_input.auth.bytes)));
let sk_array = to_array(sk_input); let sk_array = to_array(sk_input);
let domain = OrchardDomain::for_nullifier(*action.nullifier()); let domain = OrchardDomain::for_action(&action);
let dec_sk = SpendingKey::from_bytes(sk_array).unwrap(); let dec_sk = SpendingKey::from_bytes(sk_array).unwrap();
let fvk = FullViewingKey::from(&dec_sk); let fvk = FullViewingKey::from(&dec_sk);
let ivk = if external { let ivk = if external {
@ -1186,7 +1214,7 @@ pub extern "C" fn rust_wrapper_gen_seed_phrase(
out: *mut u8, out: *mut u8,
out_len: &mut usize out_len: &mut usize
){ ){
let mnemonic = Mnemonic::generate(Count::Words24); let mnemonic: Mnemonic<English> = Mnemonic::generate(Count::Words24);
let seed = mnemonic.phrase().as_bytes().to_vec(); let seed = mnemonic.phrase().as_bytes().to_vec();
marshall_to_haskell_var(&seed, out, out_len, RW); marshall_to_haskell_var(&seed, out, out_len, RW);
} }
@ -1199,7 +1227,7 @@ pub extern "C" fn rust_wrapper_recover_seed(
out_len: &mut usize out_len: &mut usize
){ ){
let phrase: String = marshall_from_haskell_var(input, input_len, RW); let phrase: String = marshall_from_haskell_var(input, input_len, RW);
let mnemonic = Mnemonic::from_phrase(phrase); let mnemonic = <Mnemonic<English>>::from_phrase(phrase);
match mnemonic { match mnemonic {
Ok(m) => { Ok(m) => {
let s = m.to_seed("").to_vec(); let s = m.to_seed("").to_vec();
@ -1456,6 +1484,34 @@ pub extern "C" fn rust_wrapper_update_sapling_witness(
} }
} }
#[no_mangle]
pub extern "C" fn rust_wrapper_read_orchard_frontier(
tree: *const u8,
tree_len: usize,
out: *mut u8,
out_len: &mut usize
){
let tree_in: Vec<u8> = marshall_from_haskell_var(tree, tree_len, RW);
let tree_reader = Cursor::new(tree_in);
let comm_tree: CommitmentTree<MerkleHashOrchard, 32> = read_commitment_tree(tree_reader).unwrap();
//let comm_tree: Frontier<MerkleHashOrchard, 32> = read_frontier_v1(tree_reader).unwrap();
let frontier: Frontier<MerkleHashOrchard, 32> = comm_tree.to_frontier();
match frontier.value() {
Some(f1) => {
let (pos, leaf, omm) = f1.clone().into_parts();
let f = Hfrontier { position: <u64>::from(pos), leaf: Hhex { bytes: leaf.to_bytes().to_vec()}, ommers: omm.iter().map(|&x| x.to_bytes().to_vec()).collect()};
marshall_to_haskell_var(&f, out, out_len, RW);
},
None => {
let f0 = Hfrontier { position: 0, leaf: Hhex { bytes: vec![0]}, ommers: vec![vec![0]]};
marshall_to_haskell_var(&f0, out, out_len, RW);
}
}
}
#[no_mangle] #[no_mangle]
pub extern "C" fn rust_wrapper_read_orchard_commitment_tree( pub extern "C" fn rust_wrapper_read_orchard_commitment_tree(
tree: *const u8, tree: *const u8,
@ -1465,37 +1521,23 @@ pub extern "C" fn rust_wrapper_read_orchard_commitment_tree(
out: *mut u8, out: *mut u8,
out_len: &mut usize out_len: &mut usize
){ ){
let tree_in: Vec<u8> = marshall_from_haskell_var(tree, tree_len, RW); let tree_in: Hfrontier = marshall_from_haskell_var(tree, tree_len, RW);
let tree_reader = Cursor::new(tree_in); //let tree_reader = Cursor::new(tree_in);
let ct = read_commitment_tree::<MerkleHashOrchard, Cursor<Vec<u8>>, 32>(tree_reader); //let mut comm_tree: CommitmentTree<MerkleHashOrchard, 32> = read_commitment_tree(tree_reader).unwrap();
match ct { //let mut comm_tree: Frontier<MerkleHashOrchard, 32> = read_frontier_v1(tree_reader).unwrap();
Ok(mut comm_tree) => { let leaf = MerkleHashOrchard::from_bytes(&to_array(tree_in.leaf.bytes)).unwrap();
let node_in: Vec<u8> = marshall_from_haskell_var(node, node_len, RW); let mut comm_tree: NonEmptyFrontier<MerkleHashOrchard> = NonEmptyFrontier::from_parts(Position::from(tree_in.position), leaf, tree_in.ommers.iter().map(|x| MerkleHashOrchard::from_bytes(&to_array(x.clone())).unwrap() ).collect()).unwrap();
let orchard_note_comm = ExtractedNoteCommitment::from_bytes(&to_array(node_in)); let node_in: Vec<u8> = marshall_from_haskell_var(node, node_len, RW);
if orchard_note_comm.is_some().into() { let orchard_note_comm = ExtractedNoteCommitment::from_bytes(&to_array(node_in));
let n = MerkleHashOrchard::from_cmx(&orchard_note_comm.unwrap()); if orchard_note_comm.is_some().into() {
comm_tree.append(n); let n = MerkleHashOrchard::from_cmx(&orchard_note_comm.unwrap());
let mut out_bytes: Vec<u8> = Vec::new(); comm_tree.append(n);
let result = write_commitment_tree(&comm_tree, &mut out_bytes ); let (pos, leaf, omm) = comm_tree.into_parts();
match result { let f = Hfrontier { position: <u64>::from(pos), leaf: Hhex { bytes: leaf.to_bytes().to_vec()}, ommers: omm.iter().map(|&x| x.to_bytes().to_vec()).collect()};
Ok(()) => { marshall_to_haskell_var(&f, out, out_len, RW);
let h = Hhex { bytes: out_bytes}; } else {
marshall_to_haskell_var(&h, out, out_len, RW); let f0 = Hfrontier { position: 0, leaf: Hhex { bytes: vec![0]}, ommers: vec![vec![0]]};
}, marshall_to_haskell_var(&f0, out, out_len, RW);
Err(_e) => {
let h0 = Hhex { bytes: vec![0]};
marshall_to_haskell_var(&h0, out, out_len, RW);
}
}
} else {
let h0 = Hhex { bytes: vec![0]};
marshall_to_haskell_var(&h0, out, out_len, RW);
}
},
Err(_e) => {
let h0 = Hhex { bytes: vec![0]};
marshall_to_haskell_var(&h0, out, out_len, RW);
}
} }
} }
@ -1726,7 +1768,7 @@ pub extern "C" fn rust_wrapper_create_transaction(
if o_in.sk.len() > 1 { if o_in.sk.len() > 1 {
let sp_key = SpendingKey::from_bytes(o_in.sk[0..32].try_into().unwrap()).unwrap(); let sp_key = SpendingKey::from_bytes(o_in.sk[0..32].try_into().unwrap()).unwrap();
let pay_addr = OrchardAddress::from_raw_address_bytes(&to_array(o_in.note.recipient)).unwrap(); let pay_addr = OrchardAddress::from_raw_address_bytes(&to_array(o_in.note.recipient)).unwrap();
let rho = Nullifier::from_bytes(&to_array(o_in.note.rho)).unwrap(); let rho = Rho::from_bytes(&to_array(o_in.note.rho)).unwrap();
let rseed = RandomSeed::from_bytes(to_array(o_in.note.rseed.bytes), &rho).unwrap(); let rseed = RandomSeed::from_bytes(to_array(o_in.note.rseed.bytes), &rho).unwrap();
let val = NoteValue::from_raw(o_in.note.note); let val = NoteValue::from_raw(o_in.note.note);
let note = Note::from_parts(pay_addr, val, rho, rseed).unwrap(); let note = Note::from_parts(pay_addr, val, rho, rseed).unwrap();

View file

@ -240,9 +240,16 @@ import ZcashHaskell.Types
#} #}
{# fun unsafe rust_wrapper_read_orchard_commitment_tree as rustWrapperReadOrchardCommitmentTree {# fun unsafe rust_wrapper_read_orchard_commitment_tree as rustWrapperReadOrchardCommitmentTree
{ toBorshVar* `BS.ByteString'& { toBorshVar* `OrchardFrontier'&
, toBorshVar* `BS.ByteString'& , toBorshVar* `BS.ByteString'&
, getVarBuffer `Buffer HexString'& , getVarBuffer `Buffer OrchardFrontier'&
}
-> `()'
#}
{# fun unsafe rust_wrapper_read_orchard_frontier as rustWrapperReadOrchardFrontier
{ toBorshVar* `BS.ByteString'&
, getVarBuffer `Buffer OrchardFrontier'&
} }
-> `()' -> `()'
#} #}

View file

@ -24,6 +24,7 @@ import C.Zcash
, rustWrapperOrchardNoteDecode , rustWrapperOrchardNoteDecode
, rustWrapperOrchardNoteDecodeSK , rustWrapperOrchardNoteDecodeSK
, rustWrapperReadOrchardCommitmentTree , rustWrapperReadOrchardCommitmentTree
, rustWrapperReadOrchardFrontier
, rustWrapperReadOrchardPosition , rustWrapperReadOrchardPosition
, rustWrapperReadOrchardWitness , rustWrapperReadOrchardWitness
, rustWrapperUADecode , rustWrapperUADecode
@ -194,21 +195,29 @@ decryptOrchardActionSK sk scope oa =
withPureBorshVarBuffer $ withPureBorshVarBuffer $
rustWrapperOrchardNoteDecodeSK (getBytes sk) oa (scope == External) rustWrapperOrchardNoteDecodeSK (getBytes sk) oa (scope == External)
-- | Update a Orchard commitment tree getOrchardFrontier :: OrchardCommitmentTree -> Maybe OrchardFrontier
updateOrchardCommitmentTree :: getOrchardFrontier tree =
OrchardCommitmentTree -- ^ the base tree if of_pos updatedTree > 1
-> HexString -- ^ the new note commitment then Just updatedTree
-> Maybe OrchardCommitmentTree
updateOrchardCommitmentTree tree cmx =
if BS.length (hexBytes updatedTree) > 1
then Just $ OrchardCommitmentTree updatedTree
else Nothing else Nothing
where where
updatedTree = updatedTree =
withPureBorshVarBuffer $ withPureBorshVarBuffer $
rustWrapperReadOrchardCommitmentTree rustWrapperReadOrchardFrontier $ toBytes $ orchTree tree
(hexBytes $ orchTree tree)
(hexBytes cmx) -- | Update a Orchard commitment tree
updateOrchardCommitmentTree ::
OrchardFrontier -- ^ the base tree
-> HexString -- ^ the new note commitment
-> Maybe OrchardFrontier
updateOrchardCommitmentTree tree cmx =
if of_pos updatedTree > 1
then Just updatedTree
else Nothing
where
updatedTree =
withPureBorshVarBuffer $
rustWrapperReadOrchardCommitmentTree tree (hexBytes cmx)
-- | Get the Orchard incremental witness from a commitment tree -- | Get the Orchard incremental witness from a commitment tree
getOrchardWitness :: OrchardCommitmentTree -> Maybe OrchardWitness getOrchardWitness :: OrchardCommitmentTree -> Maybe OrchardWitness

View file

@ -708,6 +708,15 @@ newtype OrchardCommitmentTree = OrchardCommitmentTree
{ orchTree :: HexString { orchTree :: HexString
} deriving (Eq, Prelude.Show, Read) } deriving (Eq, Prelude.Show, Read)
data OrchardFrontier = OrchardFrontier
{ of_pos :: !Int64
, of_leaf :: !HexString
, of_ommers :: ![BS.ByteString]
} deriving stock (Eq, Prelude.Show, GHC.Generic)
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
deriving anyclass (Data.Structured.Show)
deriving (BorshSize, ToBorsh, FromBorsh) via AsStruct OrchardFrontier
-- | Type for a Sapling incremental witness -- | Type for a Sapling incremental witness
newtype OrchardWitness = OrchardWitness newtype OrchardWitness = OrchardWitness
{ orchWit :: HexString { orchWit :: HexString

View file

@ -922,7 +922,7 @@ main = do
getSaplingNotePosition <$> getSaplingNotePosition <$>
(getSaplingWitness =<< updateSaplingCommitmentTree tree cmu1) (getSaplingWitness =<< updateSaplingCommitmentTree tree cmu1)
p `shouldBe` Just 129405 p `shouldBe` Just 129405
describe "Orchard commitment trees" $ do {- describe "Orchard commitment trees" $ do
let tree = let tree =
OrchardCommitmentTree $ OrchardCommitmentTree $
hexString hexString
@ -942,7 +942,7 @@ main = do
let p = let p =
getOrchardNotePosition <$> getOrchardNotePosition <$>
(getOrchardWitness =<< updateOrchardCommitmentTree tree cmx) (getOrchardWitness =<< updateOrchardCommitmentTree tree cmx)
p `shouldBe` Just 39432 p `shouldBe` Just 39432 -}
describe "Extract Sapling Address - UA Valid" $ do describe "Extract Sapling Address - UA Valid" $ do
let sr = let sr =
getSaplingFromUA getSaplingFromUA
@ -1148,6 +1148,43 @@ main = do
Just addr -> do Just addr -> do
let eadr = decodeExchangeAddress (E.encodeUtf8 addr) let eadr = decodeExchangeAddress (E.encodeUtf8 addr)
eadr `shouldNotBe` Nothing eadr `shouldNotBe` Nothing
describe "Tree updates" $ do
it "Orchard" $ do
let tree =
OrchardCommitmentTree $
hexString
"0136a7886d7d73bc1845223165fd9cb0cef02046c707e8f88a7f61564720bd0f3501dca1fbdd7b5ba92a0809af5e85874626ce0db14d0532a48e41dde6f0f81b46011f0001fb48c27bd07e68f27aba47cd6e93fa961e0ef8c63f993963a614e56855d2013c0001ea572db9c5c2d24c7ad9132ae32b27179466bf67a580d59901d13b281d3f530b01c160348f10b9ad893d9731317ebe36ac8665e01c52cbe15a56aa9b72e4e6c41e000001cd7695156de2debdc5b13ea84d32e4e3ac020fb0aa7cd372c57ce765103bd70401746e6bc066a10e7f80a9ff8993dcb25c819edd64f2ca10ac248ef7848d41450500011e6191f91b3fceb62dc881a156e1b9d2e88e09dca25093cf9c4936c8869fb41a013bf8b923e4187754e85175748d9cce4824a6787e4258977b5bfe1ba59012c032000001f3bbdc62260c4fca5c84bf3487246d4542da48eeeec8ec40c1029b6908eef83c00000000000000000000000000000000"
let cmx1 =
hexString
"1712ead46028d4349e234abf59e94e0640fe7a0829e2e2e17e1a931631810400"
let cmx2 =
hexString
"39f5ad39817fb432fa07c5feb3a957189fbe7662a4b5555ca95093b6d853cf07"
let cmx3 =
hexString
"84f7fbc4b9f87215c653078d7fdd90756c3ba370c745065167da9eb73a65a83f"
let cmx4 =
hexString
"e55ad64e1ea2b261893fdea6ad0509b66e5f62d3142f351298c7135c4498d429"
let finalTree =
getOrchardFrontier $
OrchardCommitmentTree $
hexString
"0184f7fbc4b9f87215c653078d7fdd90756c3ba370c745065167da9eb73a65a83f01e55ad64e1ea2b261893fdea6ad0509b66e5f62d3142f351298c7135c4498d4291f0000014b1a76d3820087b26cd087ca84e17f3067a25ebed82ad23a93fa485affb5530b01ea572db9c5c2d24c7ad9132ae32b27179466bf67a580d59901d13b281d3f530b01c160348f10b9ad893d9731317ebe36ac8665e01c52cbe15a56aa9b72e4e6c41e000001cd7695156de2debdc5b13ea84d32e4e3ac020fb0aa7cd372c57ce765103bd70401746e6bc066a10e7f80a9ff8993dcb25c819edd64f2ca10ac248ef7848d41450500011e6191f91b3fceb62dc881a156e1b9d2e88e09dca25093cf9c4936c8869fb41a013bf8b923e4187754e85175748d9cce4824a6787e4258977b5bfe1ba59012c032000001f3bbdc62260c4fca5c84bf3487246d4542da48eeeec8ec40c1029b6908eef83c00000000000000000000000000000000"
case getOrchardFrontier tree of
Nothing -> assertFailure "Failed to get frontier"
Just t1 ->
case updateOrchardCommitmentTree t1 cmx1 of
Nothing -> assertFailure "Failed to update frontier with cmx"
Just t2 ->
case updateOrchardCommitmentTree t2 cmx2 of
Nothing -> assertFailure "Failed to update frontier with cmx"
Just t3 ->
case updateOrchardCommitmentTree t3 cmx3 of
Nothing ->
assertFailure "Failed to update frontier with cmx"
Just t4 ->
updateOrchardCommitmentTree t4 cmx4 `shouldBe` finalTree
describe "Witness updates" $ do describe "Witness updates" $ do
it "Sapling" $ do it "Sapling" $ do
let wit = let wit =

View file

@ -5,7 +5,7 @@ cabal-version: 3.0
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
name: zcash-haskell name: zcash-haskell
version: 0.7.0.2 version: 0.7.1.0
synopsis: Utilities to interact with the Zcash blockchain synopsis: Utilities to interact with the Zcash blockchain
description: Please see the README on the repo at <https://git.vergara.tech/Vergara_Tech/zcash-haskell#readme> description: Please see the README on the repo at <https://git.vergara.tech/Vergara_Tech/zcash-haskell#readme>
category: Blockchain category: Blockchain