From a023ba9b1671ec74055dee6f1763ae5a33128d7d Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Mon, 15 Jun 2020 15:08:14 -0700 Subject: [PATCH] Add serde bounds to zebra-chain structures. (#231) --- Cargo.lock | 310 +++++++++++-------- zebra-chain/Cargo.toml | 7 +- zebra-chain/src/block.rs | 15 +- zebra-chain/src/equihash_solution.rs | 14 +- zebra-chain/src/lib.rs | 1 + zebra-chain/src/merkle_tree.rs | 2 +- zebra-chain/src/note_commitment_tree.rs | 2 +- zebra-chain/src/notes/sapling.rs | 7 +- zebra-chain/src/notes/sprout.rs | 5 +- zebra-chain/src/proofs.rs | 13 +- zebra-chain/src/proofs/bctv14.rs | 6 +- zebra-chain/src/proofs/groth16.rs | 5 +- zebra-chain/src/serde_helpers.rs | 31 ++ zebra-chain/src/transaction.rs | 4 +- zebra-chain/src/transaction/hash.rs | 3 +- zebra-chain/src/transaction/joinsplit.rs | 14 +- zebra-chain/src/transaction/shielded_data.rs | 9 +- zebra-chain/src/transaction/transparent.rs | 8 +- zebra-chain/src/types.rs | 6 +- 19 files changed, 295 insertions(+), 167 deletions(-) create mode 100644 zebra-chain/src/serde_helpers.rs diff --git a/Cargo.lock b/Cargo.lock index 6e6231e8..c96708a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,9 +34,9 @@ source = "git+https://github.com/yaahc/abscissa.git?branch=develop#41d342a9344e3 dependencies = [ "darling", "ident_case", - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", "synstructure", ] @@ -49,6 +49,12 @@ dependencies = [ "gimli", ] +[[package]] +name = "adler32" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d" + [[package]] name = "aho-corasick" version = "0.7.10" @@ -75,9 +81,9 @@ checksum = "bc4662175ead9cd84451d5c35070517777949a2ed84551764129cedb88384841" [[package]] name = "arc-swap" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d663a8e9a99154b5fb793032533f6328da35e23aac63d5c152279aa8ba356825" +checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" [[package]] name = "arrayref" @@ -110,13 +116,14 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" [[package]] name = "backtrace" -version = "0.3.48" +version = "0.3.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df2f85c8a2abbe3b7d7e748052fdd9b76a0458fdeb16ad4223f5eca78c7c130" +checksum = "05100821de9e028f12ae3d189176b41ee198341eb8f369956407fea2f5cc666c" dependencies = [ "addr2line", "cfg-if", "libc", + "miniz_oxide", "object", "rustc-demangle", ] @@ -129,18 +136,18 @@ checksum = "cdcf67bb7ba7797a081cd19009948ab533af7c355d5caf1d08c777582d351e9c" [[package]] name = "bit-set" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" dependencies = [ "bit-vec", ] [[package]] name = "bit-vec" -version = "0.5.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb" +checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" [[package]] name = "bitflags" @@ -357,13 +364,14 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26778518a7f6cffa1d25a44b602b62b979bd88adb9e99ffec546998cf3404839" +checksum = "5d85653f070353a16313d0046f173f70d1aadd5b42600a14de626f0dfb3473a5" dependencies = [ "byteorder", "digest", "rand_core 0.5.1", + "serde", "subtle", "zeroize", ] @@ -386,10 +394,10 @@ checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" dependencies = [ "fnv", "ident_case", - "proc-macro2 1.0.9", - "quote 1.0.3", + "proc-macro2 1.0.18", + "quote 1.0.7", "strsim", - "syn 1.0.17", + "syn 1.0.31", ] [[package]] @@ -399,8 +407,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ "darling_core", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.7", + "syn 1.0.31", ] [[package]] @@ -420,11 +428,12 @@ checksum = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3" [[package]] name = "ed25519-zebra" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6195ea92e78e243aef73daa954f7afa0f018cd5bad78c39b7f141244eb78b3" +checksum = "f1a8b1ce4012933385e8a820355e972bcfb8ee55993cd63e70d47a085298020b" dependencies = [ "curve25519-dalek", + "hex", "rand_core 0.5.1", "serde", "sha2", @@ -448,9 +457,9 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" [[package]] name = "fnv" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fs2" @@ -539,9 +548,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", ] [[package]] @@ -590,9 +599,9 @@ dependencies = [ [[package]] name = "generational-arena" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e40d0cee2e2fb4fba18b55a27bf96faf49fa86d49f178695bd3bf4500b156b4" +checksum = "8e1d3b771574f62d0548cee0ad9057857e9fc25d7a3335f140c84f6acd0bf601" dependencies = [ "cfg-if", ] @@ -638,16 +647,16 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90454ce4de40b7ca6a8968b5ef367bdab48413962588d0d2b1638d60090c35d7" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", ] [[package]] name = "h2" -version = "0.2.2" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5c295d1c0c68e4e42003d75f908f5e16a1edd1cbe0b0d02e4dc2006a384f47" +checksum = "79b7246d7e4b979c03fa093da39cfb3617a96bbeee6310af63991668d7e843ff" dependencies = [ "bytes", "fnv", @@ -659,7 +668,7 @@ dependencies = [ "log", "slab", "tokio", - "tokio-util", + "tokio-util 0.3.1", ] [[package]] @@ -674,9 +683,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.8" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8" +checksum = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909" dependencies = [ "libc", ] @@ -689,9 +698,9 @@ checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" [[package]] name = "http" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b708cc7f06493459026f53b9a61a7a121a5d1ec6238dee58ea4941132b30156b" +checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" dependencies = [ "bytes", "fnv", @@ -813,15 +822,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.68" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" +checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" [[package]] name = "linked-hash-map" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" +checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" [[package]] name = "lock_api" @@ -928,9 +937,9 @@ dependencies = [ [[package]] name = "metrics-observer-prometheus" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f9bb94f40e189c87cf70ef1c78815b949ab9d28fe76ebb81f15f79bd19a33d6" +checksum = "4bfe24ad8285ef8b239232135a65f89cc5fa4690bbfaf8907f4bef38f8b08eba" dependencies = [ "hdrhistogram", "metrics-core", @@ -981,10 +990,19 @@ dependencies = [ ] [[package]] -name = "mio" -version = "0.6.21" +name = "miniz_oxide" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" +checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" +dependencies = [ + "adler32", +] + +[[package]] +name = "mio" +version = "0.6.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" dependencies = [ "cfg-if", "fuchsia-zircon", @@ -1007,15 +1025,15 @@ checksum = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" dependencies = [ "log", "mio", - "miow 0.3.4", + "miow 0.3.5", "winapi 0.3.8", ] [[package]] name = "mio-uds" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" +checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" dependencies = [ "iovec", "libc", @@ -1036,9 +1054,9 @@ dependencies = [ [[package]] name = "miow" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22dfdd1d51b2639a5abd17ed07005c3af05fb7a2a3b1a1d0d7af1000a520c1c7" +checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e" dependencies = [ "socket2", "winapi 0.3.8", @@ -1046,9 +1064,9 @@ dependencies = [ [[package]] name = "net2" -version = "0.2.33" +version = "0.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" dependencies = [ "cfg-if", "libc", @@ -1057,9 +1075,9 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" +checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" dependencies = [ "autocfg", "num-traits", @@ -1067,18 +1085,18 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" dependencies = [ "autocfg", ] [[package]] name = "num_cpus" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" dependencies = [ "hermit-abi", "libc", @@ -1086,9 +1104,9 @@ dependencies = [ [[package]] name = "object" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2" +checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" [[package]] name = "once_cell" @@ -1167,16 +1185,16 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", ] [[package]] name = "pin-project-lite" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae" +checksum = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715" [[package]] name = "pin-utils" @@ -1186,21 +1204,21 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "ppv-lite86" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" [[package]] name = "proc-macro-hack" -version = "0.5.14" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcfdefadc3d57ca21cf17990a28ef4c0f7c61383a28cb7604cf4a18e6ede1420" +checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4" [[package]] name = "proc-macro-nested" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e946095f9d3ed29ec38de908c22f95d9ac008e424c7bcae54c75a79c527c694" +checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" [[package]] name = "proc-macro2" @@ -1213,9 +1231,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.9" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" dependencies = [ "unicode-xid 0.2.0", ] @@ -1278,11 +1296,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.3" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ - "proc-macro2 1.0.9", + "proc-macro2 1.0.18", ] [[package]] @@ -1393,9 +1411,9 @@ checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" [[package]] name = "regex" -version = "1.3.5" +version = "1.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8900ebc1363efa7ea1c399ccc32daed870b4002651e0bed86e72d501ebbe0048" +checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" dependencies = [ "aho-corasick", "memchr", @@ -1415,15 +1433,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.17" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" +checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" [[package]] name = "remove_dir_all" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ "winapi 0.3.8", ] @@ -1468,9 +1486,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "535622e6be132bccd223f4bb2b8ac8d53cda3c7a6394944d3b2b33fb974f9d76" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "scopeguard" @@ -1541,22 +1559,32 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-big-array" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52309f7932ab258e58bcf73cc89037e307ffef3bcfb7ce7a246580c26f81dc55" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "serde_derive" version = "1.0.112" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf0343ce212ac0d3d6afd9391ac8e9c9efe06b533c8d33f660f6390cc4093f57" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", ] [[package]] name = "serde_json" -version = "1.0.48" +version = "1.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25" +checksum = "ec2c5d7e739bc07a3e73381a39d61fdb5f671c60c1df26a130690665803d8226" dependencies = [ "itoa", "ryu", @@ -1565,9 +1593,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.8.11" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35" +checksum = "ae3e2dd40a7cdc18ca80db804b7f461a39bb721160a85c9a1fa30134bf3c02a5" dependencies = [ "dtoa", "linked-hash-map", @@ -1598,9 +1626,9 @@ dependencies = [ [[package]] name = "signal-hook" -version = "0.1.13" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10b9f3a1686a29f53cfd91ee5e3db3c12313ec02d33765f02c1a9645a1811e2c" +checksum = "8ff2db2112d6c761e12522c65f7768548bd6e8cd23d2a9dae162520626629bd6" dependencies = [ "libc", "signal-hook-registry", @@ -1612,7 +1640,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" dependencies = [ - "arc-swap 0.4.5", + "arc-swap 0.4.7", "libc", ] @@ -1680,9 +1708,9 @@ version = "0.1.3" source = "git+https://github.com/yaahc/spandoc.git#554358be632b156a6f0af963b0b244e2665b4767" dependencies = [ "matches", - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", "tracing", "tracing-futures", ] @@ -1695,9 +1723,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" [[package]] name = "subtle" -version = "2.2.2" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c65d530b10ccaeac294f349038a597e435b18fb456aadd0840a623f83b9e941" +checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" [[package]] name = "syn" @@ -1712,24 +1740,24 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.17" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03" +checksum = "b5304cfdf27365b7585c25d4af91b35016ed21ef88f17ced89c7093b43dba8b6" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", + "proc-macro2 1.0.18", + "quote 1.0.7", "unicode-xid 0.2.0", ] [[package]] name = "synstructure" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", "unicode-xid 0.2.0", ] @@ -1781,9 +1809,9 @@ version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "893582086c2f98cde18f906265a65b5030a074b1046c674ae898be6519a7f479" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", ] [[package]] @@ -1797,12 +1825,11 @@ dependencies = [ [[package]] name = "time" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "redox_syscall", "winapi 0.3.8", ] @@ -1836,9 +1863,9 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", ] [[package]] @@ -1855,6 +1882,20 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-util" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.5.6" @@ -1915,14 +1956,15 @@ checksum = "a35d656f2638b288b33495d1053ea74c40dc05ec0b92084dd71ca5566c4ed1dc" [[package]] name = "tower-limit" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4030a1dc1ab99ec6fc9475fc18c62f6cc4da035d370fcbd22fe342f9dd16cd" +checksum = "92c3040c5dbed68abffaa0d4517ac1a454cd741044f33ab0eefab6b8d1361404" dependencies = [ "futures-core", "pin-project", "tokio", "tower-layer", + "tower-load", "tower-service", ] @@ -2013,9 +2055,9 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99bbad0de3fd923c9c3232ead88510b783e5a4d16a6154adffa3d53308de984c" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", ] [[package]] @@ -2096,9 +2138,9 @@ checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" [[package]] name = "typenum" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "unicode-xid" @@ -2167,9 +2209,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ "winapi 0.3.8", ] @@ -2198,14 +2240,15 @@ checksum = "637ff90c9540fa3073bb577e65033069e4bae7c79d49d74aa3ffdf5342a53217" dependencies = [ "curve25519-dalek", "rand_core 0.5.1", + "serde", "zeroize", ] [[package]] name = "yaml-rust" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d" +checksum = "39f0c922f1a334134dc2f7a8b67dc5d25f0735263feec974345ff706bcf20b0d" dependencies = [ "linked-hash-map", ] @@ -2232,6 +2275,7 @@ dependencies = [ "ripemd160", "secp256k1", "serde", + "serde-big-array", "sha2", "thiserror", "x25519-dalek", @@ -2279,7 +2323,7 @@ dependencies = [ "serde", "thiserror", "tokio", - "tokio-util", + "tokio-util 0.2.0", "tower", "tower-load", "tracing", @@ -2371,8 +2415,8 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de251eec69fc7c1bc3923403d18ececb929380e016afe103da75f396704f8ca2" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", "synstructure", ] diff --git a/zebra-chain/Cargo.toml b/zebra-chain/Cargo.toml index de3bfcd6..2edd9711 100644 --- a/zebra-chain/Cargo.toml +++ b/zebra-chain/Cargo.toml @@ -13,7 +13,7 @@ blake2b_simd = "0.5.10" blake2s_simd = "0.5.10" bs58 = { version = "0.3", features = ["check"] } byteorder = "1.3" -chrono = "0.4" +chrono = { version = "0.4", features = ["serde"] } futures = "0.3" hex = "0.4" jubjub = "0.3.0" @@ -21,13 +21,14 @@ lazy_static = "1.4.0" rand_core = "0.5.1" ripemd160 = "0.8.0" secp256k1 = { version = "0.17.2", features = ["serde"] } -serde = { version = "1", features = ["serde_derive"] } +serde = { version = "1", features = ["serde_derive", "rc"] } sha2 = { version = "0.8.2", features=["compress"] } thiserror = "1" -x25519-dalek = "0.6" +x25519-dalek = { version = "0.6", features = ["serde"] } # ZF deps ed25519-zebra = "0.2" redjubjub = "0.1" +serde-big-array = "0.3.0" [dev-dependencies] proptest = "0.10" diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 2cce8d6c..15ee3c20 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -6,6 +6,7 @@ mod tests; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use chrono::{DateTime, TimeZone, Utc}; +use serde::{Deserialize, Serialize}; use std::{fmt, io, sync::Arc}; #[cfg(test)] @@ -31,7 +32,7 @@ use crate::types::BlockHeight; /// the direct bytes of the transactions as well as the header. So /// for now I want to call it a `BlockHeaderHash` because that's /// more explicit. -#[derive(Copy, Clone, Eq, PartialEq, Hash)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] pub struct BlockHeaderHash(pub [u8; 32]); @@ -84,7 +85,7 @@ impl std::str::FromStr for BlockHeaderHash { /// backwards reference (previous header hash) present in the block /// header. Each block points backwards to its parent, all the way /// back to the genesis block (the first block in the blockchain). -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct BlockHeader { /// The block's version field. This is supposed to be `4`: /// @@ -197,9 +198,13 @@ impl ZcashDeserialize for BlockHeader { } } -/// A Zcash block, containing a [`BlockHeader`] and a sequence of -/// [`Transaction`]s. -#[derive(Clone, Debug, Eq, PartialEq)] +/// A block in your blockchain. +/// +/// A block is a data structure with two fields: +/// +/// Block header: a data structure containing the block's metadata +/// Transactions: an array (vector in Rust) of transactions +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] pub struct Block { /// The block header, containing block metadata. diff --git a/zebra-chain/src/equihash_solution.rs b/zebra-chain/src/equihash_solution.rs index bc82c629..477c05e5 100644 --- a/zebra-chain/src/equihash_solution.rs +++ b/zebra-chain/src/equihash_solution.rs @@ -5,12 +5,15 @@ use std::{fmt, io}; #[cfg(test)] use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*}; -use crate::serialization::{ - ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize, +use crate::{ + serde_helpers, + serialization::{ + ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize, + }, }; /// The size of an Equihash solution in bytes (always 1344). -const EQUIHASH_SOLUTION_SIZE: usize = 1344; +pub(crate) const EQUIHASH_SOLUTION_SIZE: usize = 1344; /// Equihash Solution. /// @@ -20,7 +23,10 @@ const EQUIHASH_SOLUTION_SIZE: usize = 1344; /// /// The size of an Equihash solution in bytes is always 1344 so the /// length of this type is fixed. -pub struct EquihashSolution(pub [u8; EQUIHASH_SOLUTION_SIZE]); +#[derive(Deserialize, Serialize)] +pub struct EquihashSolution( + #[serde(with = "serde_helpers::BigArray")] pub [u8; EQUIHASH_SOLUTION_SIZE], +); impl PartialEq for EquihashSolution { fn eq(&self, other: &EquihashSolution) -> bool { diff --git a/zebra-chain/src/lib.rs b/zebra-chain/src/lib.rs index 5a733ef5..9902bb19 100644 --- a/zebra-chain/src/lib.rs +++ b/zebra-chain/src/lib.rs @@ -8,6 +8,7 @@ extern crate serde; mod merkle_tree; +mod serde_helpers; mod sha256d_writer; pub mod addresses; diff --git a/zebra-chain/src/merkle_tree.rs b/zebra-chain/src/merkle_tree.rs index 891e1067..6af26ac0 100644 --- a/zebra-chain/src/merkle_tree.rs +++ b/zebra-chain/src/merkle_tree.rs @@ -32,7 +32,7 @@ impl ZcashDeserialize for MerkleTree { /// A SHA-256d hash of the root node of a merkle tree of SHA256-d /// hashed transactions in a block. -#[derive(Clone, Copy, Eq, PartialEq)] +#[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] pub struct MerkleTreeRootHash(pub [u8; 32]); diff --git a/zebra-chain/src/note_commitment_tree.rs b/zebra-chain/src/note_commitment_tree.rs index 143c7ea7..a5a9f5c3 100644 --- a/zebra-chain/src/note_commitment_tree.rs +++ b/zebra-chain/src/note_commitment_tree.rs @@ -32,7 +32,7 @@ pub struct SaplingNoteCommitmentTree; /// commitment tree corresponding to the final Sapling treestate of /// this block. A root of a note commitment tree is associated with /// each treestate. -#[derive(Clone, Copy, Default, Eq, PartialEq)] +#[derive(Clone, Copy, Default, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] pub struct SaplingNoteTreeRootHash(pub [u8; 32]); diff --git a/zebra-chain/src/notes/sapling.rs b/zebra-chain/src/notes/sapling.rs index 0c33ba14..50adcb8a 100644 --- a/zebra-chain/src/notes/sapling.rs +++ b/zebra-chain/src/notes/sapling.rs @@ -6,6 +6,7 @@ use std::{fmt, io}; #[cfg(test)] use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*}; +use crate::serde_helpers; use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; use super::*; @@ -39,7 +40,8 @@ pub struct NotePlaintext { } /// A ciphertext component for encrypted output notes. -pub struct EncryptedCiphertext(pub [u8; 580]); +#[derive(Deserialize, Serialize)] +pub struct EncryptedCiphertext(#[serde(with = "serde_helpers::BigArray")] pub [u8; 580]); impl fmt::Debug for EncryptedCiphertext { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -102,7 +104,8 @@ impl Arbitrary for EncryptedCiphertext { } /// A ciphertext component for encrypted output notes. -pub struct OutCiphertext(pub [u8; 80]); +#[derive(Deserialize, Serialize)] +pub struct OutCiphertext(#[serde(with = "serde_helpers::BigArray")] pub [u8; 80]); impl fmt::Debug for OutCiphertext { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/zebra-chain/src/notes/sprout.rs b/zebra-chain/src/notes/sprout.rs index b7f249c2..7ebb9927 100644 --- a/zebra-chain/src/notes/sprout.rs +++ b/zebra-chain/src/notes/sprout.rs @@ -1,6 +1,7 @@ //! #![allow(dead_code)] +use serde::{Deserialize, Serialize}; use std::{ fmt, io::{self}, @@ -9,6 +10,7 @@ use std::{ #[cfg(test)] use proptest::{collection::vec, prelude::*}; +use crate::serde_helpers; use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; use super::{memo::Memo, *}; @@ -34,7 +36,8 @@ pub struct NotePlaintext { } /// A ciphertext component for encrypted output notes. -pub struct EncryptedCiphertext(pub [u8; 601]); +#[derive(Serialize, Deserialize)] +pub struct EncryptedCiphertext(#[serde(with = "serde_helpers::BigArray")] pub [u8; 601]); impl fmt::Debug for EncryptedCiphertext { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/zebra-chain/src/proofs.rs b/zebra-chain/src/proofs.rs index beebcf8f..5721c423 100644 --- a/zebra-chain/src/proofs.rs +++ b/zebra-chain/src/proofs.rs @@ -2,6 +2,8 @@ use std::fmt::Debug; +use serde::{de::DeserializeOwned, Serialize}; + use crate::serialization::{ZcashDeserialize, ZcashSerialize}; mod bctv14; @@ -12,7 +14,16 @@ pub use groth16::Groth16Proof; /// A marker trait used to abstract over BCTV14 or Groth16 proofs. pub trait ZkSnarkProof: - Copy + Clone + Debug + PartialEq + Eq + ZcashSerialize + ZcashDeserialize + private::Sealed + Copy + + Clone + + Debug + + PartialEq + + Eq + + Serialize + + DeserializeOwned + + ZcashSerialize + + ZcashDeserialize + + private::Sealed { } impl ZkSnarkProof for Bctv14Proof {} diff --git a/zebra-chain/src/proofs/bctv14.rs b/zebra-chain/src/proofs/bctv14.rs index 280c68fd..88b9a228 100644 --- a/zebra-chain/src/proofs/bctv14.rs +++ b/zebra-chain/src/proofs/bctv14.rs @@ -1,9 +1,13 @@ use std::{fmt, io}; +use serde::{Deserialize, Serialize}; + +use crate::serde_helpers; use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; /// An encoding of a BCTV14 proof, as used in Zcash. -pub struct Bctv14Proof(pub [u8; 296]); +#[derive(Serialize, Deserialize)] +pub struct Bctv14Proof(#[serde(with = "serde_helpers::BigArray")] pub [u8; 296]); impl fmt::Debug for Bctv14Proof { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/zebra-chain/src/proofs/groth16.rs b/zebra-chain/src/proofs/groth16.rs index 4cc1789b..4ff6f772 100644 --- a/zebra-chain/src/proofs/groth16.rs +++ b/zebra-chain/src/proofs/groth16.rs @@ -1,9 +1,12 @@ +use serde::{Deserialize, Serialize}; use std::{fmt, io}; +use crate::serde_helpers; use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; /// An encoding of a Groth16 proof, as used in Zcash. -pub struct Groth16Proof(pub [u8; 192]); +#[derive(Serialize, Deserialize)] +pub struct Groth16Proof(#[serde(with = "serde_helpers::BigArray")] pub [u8; 192]); impl fmt::Debug for Groth16Proof { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/zebra-chain/src/serde_helpers.rs b/zebra-chain/src/serde_helpers.rs new file mode 100644 index 00000000..e29e475e --- /dev/null +++ b/zebra-chain/src/serde_helpers.rs @@ -0,0 +1,31 @@ +use super::equihash_solution::EQUIHASH_SOLUTION_SIZE; +use serde_big_array::big_array; + +big_array! { + BigArray; + +EQUIHASH_SOLUTION_SIZE, + 80, // `sapling::OutCiphertext` + 580, // `sapling::EncryptedCiphertext` + 601, // `sprout::EncryptedCiphertext` + 296, // `bctv14::Bctv14Proof` +} + +#[derive(Deserialize, Serialize)] +#[serde(remote = "jubjub::AffinePoint")] +pub(crate) struct AffinePoint { + #[serde(getter = "jubjub::AffinePoint::to_bytes")] + bytes: [u8; 32], +} + +impl From for jubjub::AffinePoint { + fn from(local: AffinePoint) -> Self { + jubjub::AffinePoint::from_bytes(local.bytes).unwrap() + } +} + +#[derive(Deserialize, Serialize)] +#[serde(remote = "futures::future::Either")] +pub(crate) enum Either { + Left(A), + Right(B), +} diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs index c4a12635..5170adf6 100644 --- a/zebra-chain/src/transaction.rs +++ b/zebra-chain/src/transaction.rs @@ -1,5 +1,7 @@ //! Transaction types. +use serde::{Deserialize, Serialize}; + mod hash; mod joinsplit; mod serialize; @@ -30,7 +32,7 @@ use crate::types::{BlockHeight, LockTime}; /// Zcash has a number of different transaction formats. They are represented /// internally by different enum variants. Because we checkpoint on Sapling /// activation, we do not parse any pre-Sapling transaction types. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] // XXX consider boxing the Optional fields of V4 txs #[allow(clippy::large_enum_variant)] pub enum Transaction { diff --git a/zebra-chain/src/transaction/hash.rs b/zebra-chain/src/transaction/hash.rs index e9e53630..6095d249 100644 --- a/zebra-chain/src/transaction/hash.rs +++ b/zebra-chain/src/transaction/hash.rs @@ -3,6 +3,7 @@ use std::fmt; #[cfg(test)] use proptest_derive::Arbitrary; +use serde::{Deserialize, Serialize}; use crate::{ serialization::{SerializationError, ZcashSerialize}, @@ -15,7 +16,7 @@ use super::Transaction; /// /// TODO: I'm pretty sure this is also a SHA256d hash but I haven't /// confirmed it yet. -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] pub struct TransactionHash(pub [u8; 32]); diff --git a/zebra-chain/src/transaction/joinsplit.rs b/zebra-chain/src/transaction/joinsplit.rs index b95a92f3..0963cb36 100644 --- a/zebra-chain/src/transaction/joinsplit.rs +++ b/zebra-chain/src/transaction/joinsplit.rs @@ -1,12 +1,13 @@ #[cfg(test)] use proptest::{array, collection::vec, prelude::*}; +use serde::{Deserialize, Serialize}; use crate::{ed25519_zebra, notes::sprout, proofs::ZkSnarkProof}; /// A _JoinSplit Description_, as described in [protocol specification §7.2][ps]. /// /// [ps]: https://zips.z.cash/protocol/protocol.pdf#joinsplitencoding -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct JoinSplit { /// A value that the JoinSplit transfer removes from the transparent value /// pool. @@ -44,6 +45,7 @@ pub struct JoinSplit { /// A ZK JoinSplit proof, either a /// [`Groth16Proof`](crate::proofs::Groth16Proof) or a /// [`Bctv14Proof`](crate::proofs::Bctv14Proof). + #[serde(bound(serialize = "P: ZkSnarkProof", deserialize = "P: ZkSnarkProof"))] pub zkproof: P, /// A ciphertext component for this output note. pub enc_ciphertexts: [sprout::EncryptedCiphertext; 2], @@ -119,7 +121,7 @@ impl Arbitrary for JoinSplit

{ } /// A bundle of JoinSplit descriptions and signature data. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct JoinSplitData { /// The first JoinSplit description, using proofs of type `P`. /// @@ -129,11 +131,19 @@ pub struct JoinSplitData { /// However, it's not necessary to access or process `first` and `rest` /// separately, as the [`JoinSplitData::joinsplits`] method provides an /// iterator over all of the `JoinSplit`s. + #[serde(bound( + serialize = "JoinSplit

: Serialize", + deserialize = "JoinSplit

: Deserialize<'de>" + ))] pub first: JoinSplit

, /// The rest of the JoinSplit descriptions, using proofs of type `P`. /// /// The [`JoinSplitData::joinsplits`] method provides an iterator over /// all `JoinSplit`s. + #[serde(bound( + serialize = "JoinSplit

: Serialize", + deserialize = "JoinSplit

: Deserialize<'de>" + ))] pub rest: Vec>, /// The public key for the JoinSplit signature. pub pub_key: ed25519_zebra::PublicKeyBytes, diff --git a/zebra-chain/src/transaction/shielded_data.rs b/zebra-chain/src/transaction/shielded_data.rs index 472c5ec5..b680efb5 100644 --- a/zebra-chain/src/transaction/shielded_data.rs +++ b/zebra-chain/src/transaction/shielded_data.rs @@ -8,11 +8,12 @@ use crate::note_commitment_tree::SaplingNoteTreeRootHash; use crate::notes::sapling; use crate::proofs::Groth16Proof; use crate::redjubjub::{self, Binding, SpendAuth}; +use crate::serde_helpers; /// A _Spend Description_, as described in [protocol specification §7.3][ps]. /// /// [ps]: https://zips.z.cash/protocol/protocol.pdf#spendencoding -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Spend { /// A value commitment to the value of the input note. /// @@ -68,7 +69,7 @@ impl Arbitrary for Spend { /// A _Output Description_, as described in [protocol specification §7.4][ps]. /// /// [ps]: https://zips.z.cash/protocol/protocol.pdf#outputencoding -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Output { /// A value commitment to the value of the input note. /// @@ -79,6 +80,7 @@ pub struct Output { /// XXX refine to a specific type. pub cmu: [u8; 32], /// An encoding of an ephemeral Jubjub public key. + #[serde(with = "serde_helpers::AffinePoint")] pub ephemeral_key: jubjub::AffinePoint, /// A ciphertext component for the encrypted output note. pub enc_ciphertext: sapling::EncryptedCiphertext, @@ -122,7 +124,7 @@ impl Arbitrary for Output { } /// Sapling-on-Groth16 spend and output descriptions. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct ShieldedData { /// Either a spend or output description. /// @@ -133,6 +135,7 @@ pub struct ShieldedData { /// separately, as the [`ShieldedData::spends`] and [`ShieldedData::outputs`] /// methods provide iterators over all of the [`SpendDescription`]s and /// [`Output`]s. + #[serde(with = "serde_helpers::Either")] pub first: Either, /// The rest of the [`Spend`]s for this transaction. /// diff --git a/zebra-chain/src/transaction/transparent.rs b/zebra-chain/src/transaction/transparent.rs index d7ff6e37..6d25abd2 100644 --- a/zebra-chain/src/transaction/transparent.rs +++ b/zebra-chain/src/transaction/transparent.rs @@ -9,7 +9,7 @@ use crate::types::{BlockHeight, Script}; use super::TransactionHash; /// Arbitrary data inserted by miners into a coinbase transaction. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct CoinbaseData( /// Invariant: this vec, together with the coinbase height, must be less than /// 100 bytes. We enforce this by only constructing CoinbaseData fields by @@ -29,7 +29,7 @@ impl AsRef<[u8]> for CoinbaseData { /// OutPoint /// /// A particular transaction output reference. -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] pub struct OutPoint { /// References the transaction that contains the UTXO being spent. @@ -41,7 +41,7 @@ pub struct OutPoint { } /// A transparent input to a transaction. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub enum TransparentInput { /// A reference to an output of a previous transaction. PrevOut { @@ -75,7 +75,7 @@ pub enum TransparentInput { /// I only own one UTXO worth 2 ZEC, I would construct a transaction /// that spends my UTXO and sends 1 ZEC to you and 1 ZEC back to me /// (just like receiving change). -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] pub struct TransparentOutput { /// Transaction value. diff --git a/zebra-chain/src/types.rs b/zebra-chain/src/types.rs index bacbb1d2..2d31c621 100644 --- a/zebra-chain/src/types.rs +++ b/zebra-chain/src/types.rs @@ -43,7 +43,7 @@ impl fmt::Debug for Sha256dChecksum { /// # Invariants /// /// Users should not construct block heights greater than or equal to `500_000_000`. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct BlockHeight(pub u32); #[cfg(test)] @@ -65,7 +65,7 @@ impl Arbitrary for BlockHeight { /// Users should not construct a `LockTime` with `BlockHeight` greater than or /// equal to `500_000_000` or a timestamp before 4 November 1985 (Unix timestamp /// less than `500_000_000`). -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub enum LockTime { /// Unlock at a particular block height. Height(BlockHeight), @@ -115,7 +115,7 @@ impl Arbitrary for LockTime { } /// An encoding of a Bitcoin script. -#[derive(Clone, Eq, PartialEq)] +#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] pub struct Script(pub Vec);