diff --git a/.changelog/unreleased/improvements/1930-update-borsh.md b/.changelog/unreleased/improvements/1930-update-borsh.md new file mode 100644 index 0000000000..e7fb8b994e --- /dev/null +++ b/.changelog/unreleased/improvements/1930-update-borsh.md @@ -0,0 +1 @@ +- Migrate to upstream borsh ([\#1930](https://github.com/anoma/namada/pull/1930)) \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 41e6231cbd..96a3b66044 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,18 +37,6 @@ dependencies = [ "generic-array 0.14.7", ] -[[package]] -name = "aes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" -dependencies = [ - "cfg-if 1.0.0", - "cipher 0.3.0", - "cpufeatures", - "opaque-debug 0.3.0", -] - [[package]] name = "aes" version = "0.8.3" @@ -497,16 +485,16 @@ checksum = "cf9ff0bbfd639f15c74af777d81383cf53efb7c93613f6cab67c6c11e05bbf8b" [[package]] name = "bellman" -version = "0.13.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4dd656ef4fdf7debb6d87d4dd92642fcbcdb78cbf6600c13e25c87e4d1a3807" +checksum = "9afceed28bac7f9f5a508bca8aeeff51cdfa4770c0b967ac55c621e2ddfd6171" dependencies = [ "bitvec 1.0.1", "blake2s_simd", "byteorder", "crossbeam-channel 0.5.8", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "lazy_static", "log", "num_cpus", @@ -557,14 +545,14 @@ dependencies = [ [[package]] name = "bip0039" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0830ae4cc96b0617cc912970c2b17e89456fecbf55e8eed53a956f37ab50c41" +checksum = "bef0f0152ec5cf17f49a5866afaa3439816207fd4f0a224c0211ffaf5e278426" dependencies = [ - "hmac 0.11.0", - "pbkdf2 0.9.0", + "hmac 0.12.1", + "pbkdf2 0.10.1", "rand 0.8.5", - "sha2 0.9.9", + "sha2 0.10.6", "unicode-normalization", "zeroize", ] @@ -679,7 +667,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ - "block-padding 0.1.5", + "block-padding", "byte-tools", "byteorder", "generic-array 0.12.4", @@ -703,16 +691,6 @@ dependencies = [ "generic-array 0.14.7", ] -[[package]] -name = "block-modes" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb03d1bed155d89dce0f845b7899b18a9a163e148fd004e1c28421a783e2d8e" -dependencies = [ - "block-padding 0.2.1", - "cipher 0.3.0", -] - [[package]] name = "block-padding" version = "0.1.5" @@ -722,20 +700,14 @@ dependencies = [ "byte-tools", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "bls12_381" -version = "0.7.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3c196a77437e7cc2fb515ce413a6401291578b5afc8ecb29a3c7ab957f05941" +checksum = "d7bc6d6292be3a19e6379786dac800f551e5865a5bb51ebbe3064ab80433f403" dependencies = [ - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "pairing", "rand_core 0.6.4", "subtle 2.4.1", @@ -743,10 +715,11 @@ dependencies = [ [[package]] name = "borsh" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" dependencies = [ - "borsh-derive 0.9.4", + "borsh-derive 0.9.3", "hashbrown 0.11.2", ] @@ -760,13 +733,24 @@ dependencies = [ "hashbrown 0.12.3", ] +[[package]] +name = "borsh" +version = "1.0.0-alpha.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41898277107b0d3f027593697912977397eba6ac39a55bdd2eb02c1d5d5013b5" +dependencies = [ + "borsh-derive 1.0.0-alpha.4", + "cfg_aliases", +] + [[package]] name = "borsh-derive" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" dependencies = [ - "borsh-derive-internal 0.9.4", - "borsh-schema-derive-internal 0.9.4", + "borsh-derive-internal 0.9.3", + "borsh-schema-derive-internal 0.9.3", "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.109", @@ -785,10 +769,25 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-derive" +version = "1.0.0-alpha.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413cb435569fe499e89235f758304e0e7198016baa351d8f5827ea0f40526ce0" +dependencies = [ + "once_cell", + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 2.0.15", + "syn_derive", +] + [[package]] name = "borsh-derive-internal" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" dependencies = [ "proc-macro2", "quote", @@ -806,10 +805,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-ext" +version = "1.0.0-alpha.4" +source = "git+https://github.com/heliaxdev/borsh-ext?tag=v1.0.0-alpha.4#6bebf357002f96574ac37a28f547b6c88e91b799" +dependencies = [ + "borsh 1.0.0-alpha.4", +] + [[package]] name = "borsh-schema-derive-internal" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" dependencies = [ "proc-macro2", "quote", @@ -961,6 +969,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher 0.4.4", +] + [[package]] name = "cc" version = "1.0.79" @@ -991,6 +1008,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chacha20" version = "0.8.2" @@ -1202,27 +1225,27 @@ dependencies = [ [[package]] name = "color-eyre" -version = "0.5.11" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f1885697ee8a177096d42f158922251a41973117f6d8a234cee94b9509157b7" +checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" dependencies = [ "backtrace", "color-spantrace", "eyre", "indenter", "once_cell", - "owo-colors 1.3.0", + "owo-colors", "tracing-error", ] [[package]] name = "color-spantrace" -version = "0.1.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eee477a4a8a72f4addd4de416eb56d54bc307b284d6601bafdee1f4ea462d1" +checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce" dependencies = [ "once_cell", - "owo-colors 1.3.0", + "owo-colors", "tracing-core 0.1.31", "tracing-error", ] @@ -1409,7 +1432,7 @@ dependencies = [ "clap", "criterion-plot", "is-terminal", - "itertools", + "itertools 0.10.5", "num-traits 0.2.15", "once_cell", "oorandom", @@ -1430,7 +1453,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" dependencies = [ "cast", - "itertools", + "itertools 0.10.5", ] [[package]] @@ -1545,16 +1568,6 @@ dependencies = [ "subtle 2.4.1", ] -[[package]] -name = "crypto-mac" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" -dependencies = [ - "generic-array 0.14.7", - "subtle 2.4.1", -] - [[package]] name = "ct-codecs" version = "1.1.1" @@ -1893,9 +1906,9 @@ dependencies = [ "base16ct", "crypto-bigint", "digest 0.10.6", - "ff 0.13.0", + "ff", "generic-array 0.14.7", - "group 0.13.0", + "group", "pkcs8", "rand_core 0.6.4", "sec1", @@ -2026,7 +2039,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fda3bf123be441da5260717e0661c25a2fd9cb2b2c1d20bf2e05580047158ab" dependencies = [ - "aes 0.8.3", + "aes", "ctr", "digest 0.10.6", "hex", @@ -2411,14 +2424,14 @@ dependencies = [ "bincode", "blake2", "blake2b_simd", - "borsh 0.9.4", + "borsh 0.9.3", "digest 0.10.6", "ed25519-dalek", "either", "ferveo-common", "group-threshold-cryptography", "hex", - "itertools", + "itertools 0.10.5", "measure_time", "miracl_core", "num 0.4.0", @@ -2445,23 +2458,13 @@ dependencies = [ "serde_bytes", ] -[[package]] -name = "ff" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" -dependencies = [ - "bitvec 1.0.1", - "rand_core 0.6.4", - "subtle 2.4.1", -] - [[package]] name = "ff" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ + "bitvec 1.0.1", "rand_core 0.6.4", "subtle 2.4.1", ] @@ -2559,12 +2562,12 @@ dependencies = [ [[package]] name = "fpe" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd910db5f9ca4dc3116f8c46367825807aa2b942f72565f16b4be0b208a00a9e" +checksum = "26c4b37de5ae15812a764c958297cfc50f5c010438f60c6ce75d11b802abd404" dependencies = [ - "block-modes", - "cipher 0.3.0", + "cbc", + "cipher 0.4.4", "libm", "num-bigint 0.4.3", "num-integer", @@ -2797,25 +2800,14 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "group" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" -dependencies = [ - "ff 0.12.1", - "memuse", - "rand_core 0.6.4", - "subtle 2.4.1", -] - [[package]] name = "group" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "ff 0.13.0", + "ff", + "memuse", "rand_core 0.6.4", "subtle 2.4.1", ] @@ -2835,7 +2827,7 @@ dependencies = [ "blake2b_simd", "chacha20 0.8.2", "hex", - "itertools", + "itertools 0.10.5", "miracl_core", "rand 0.8.5", "rand_core 0.6.4", @@ -3004,16 +2996,6 @@ dependencies = [ "digest 0.9.0", ] -[[package]] -name = "hmac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" -dependencies = [ - "crypto-mac 0.11.1", - "digest 0.9.0", -] - [[package]] name = "hmac" version = "0.12.1" @@ -3329,10 +3311,10 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "index-set" -version = "0.7.1" -source = "git+https://github.com/heliaxdev/index-set?tag=v0.7.1#dc24cdbbe3664514d59f1a4c4031863fc565f1c2" +version = "0.8.0" +source = "git+https://github.com/heliaxdev/index-set?tag=v0.8.0#0c218cc300c1bb7a1acf34f21b6e9d489df5fda8" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "serde 1.0.163", ] @@ -3412,7 +3394,7 @@ checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", - "rustix 0.37.1", + "rustix 0.37.13", "windows-sys 0.48.0", ] @@ -3425,6 +3407,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.6" @@ -3451,14 +3442,14 @@ dependencies = [ [[package]] name = "jubjub" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a575df5f985fe1cd5b2b05664ff6accfc46559032b954529fd225a2168d27b0f" +checksum = "8499f7a74008aafbecb2a2e608a3e13e4dd3e84df198b604451efe93f2de6e61" dependencies = [ "bitvec 1.0.1", "bls12_381", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "rand_core 0.6.4", "subtle 2.4.1", ] @@ -3696,9 +3687,9 @@ dependencies = [ [[package]] name = "masp_note_encryption" version = "0.2.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=449a7295fe24d96456ece24c223ca9eb76b0e6ba#449a7295fe24d96456ece24c223ca9eb76b0e6ba" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "chacha20 0.9.1", "chacha20poly1305", "cipher 0.4.4", @@ -3709,19 +3700,19 @@ dependencies = [ [[package]] name = "masp_primitives" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=449a7295fe24d96456ece24c223ca9eb76b0e6ba#449a7295fe24d96456ece24c223ca9eb76b0e6ba" dependencies = [ - "aes 0.7.5", + "aes", "bip0039", "bitvec 1.0.1", "blake2b_simd", "blake2s_simd", "bls12_381", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "byteorder", - "ff 0.12.1", + "ff", "fpe", - "group 0.12.1", + "group", "hex", "incrementalmerkletree", "jubjub", @@ -3732,7 +3723,7 @@ dependencies = [ "num-traits 0.2.15", "rand 0.8.5", "rand_core 0.6.4", - "sha2 0.9.9", + "sha2 0.10.6", "subtle 2.4.1", "zcash_encoding", ] @@ -3740,15 +3731,15 @@ dependencies = [ [[package]] name = "masp_proofs" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=449a7295fe24d96456ece24c223ca9eb76b0e6ba#449a7295fe24d96456ece24c223ca9eb76b0e6ba" dependencies = [ "bellman", "blake2b_simd", "bls12_381", "directories", "getrandom 0.2.9", - "group 0.12.1", - "itertools", + "group", + "itertools 0.11.0", "jubjub", "lazy_static", "masp_primitives", @@ -3910,14 +3901,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.48.0", + "windows-sys 0.45.0", ] [[package]] @@ -3964,7 +3955,8 @@ dependencies = [ "async-trait", "base58 0.2.0", "bimap", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "byte-unit", "circular-queue", "clru", @@ -3976,7 +3968,7 @@ dependencies = [ "eyre", "fd-lock", "futures", - "itertools", + "itertools 0.10.5", "k256", "loupe", "masp_primitives", @@ -3988,7 +3980,7 @@ dependencies = [ "namada_test_utils", "num256", "orion", - "owo-colors 3.5.0", + "owo-colors", "parity-wasm", "parse_duration", "paste", @@ -4012,7 +4004,7 @@ dependencies = [ "tokio", "toml 0.5.9", "tracing 0.1.37", - "tracing-subscriber 0.3.17", + "tracing-subscriber", "wasm-instrument", "wasmer", "wasmer-cache", @@ -4038,7 +4030,8 @@ dependencies = [ "bimap", "bit-set", "blake2b-rs", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "byte-unit", "byteorder", "bytes", @@ -4059,7 +4052,7 @@ dependencies = [ "flate2", "futures", "git2", - "itertools", + "itertools 0.10.5", "lazy_static", "libc", "libloading", @@ -4108,7 +4101,7 @@ dependencies = [ "tracing 0.1.37", "tracing-appender", "tracing-log", - "tracing-subscriber 0.3.17", + "tracing-subscriber", "warp", "winapi", "zeroize", @@ -4119,7 +4112,8 @@ name = "namada_benchmarks" version = "0.23.0" dependencies = [ "async-trait", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "criterion", "ferveo-common", "masp_primitives", @@ -4134,7 +4128,7 @@ dependencies = [ "sha2 0.9.9", "tempfile", "tokio", - "tracing-subscriber 0.3.17", + "tracing-subscriber", ] [[package]] @@ -4146,7 +4140,8 @@ dependencies = [ "ark-serialize", "assert_matches", "bech32 0.8.1", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "chrono", "data-encoding", "derivative", @@ -4162,7 +4157,7 @@ dependencies = [ "ics23", "impl-num-traits", "index-set", - "itertools", + "itertools 0.10.5", "k256", "masp_primitives", "namada_macros", @@ -4190,7 +4185,7 @@ dependencies = [ "toml 0.5.9", "tonic-build", "tracing 0.1.37", - "tracing-subscriber 0.3.17", + "tracing-subscriber", "uint", "zeroize", ] @@ -4199,8 +4194,8 @@ dependencies = [ name = "namada_encoding_spec" version = "0.23.0" dependencies = [ - "borsh 0.9.4", - "itertools", + "borsh 1.0.0-alpha.4", + "itertools 0.10.5", "lazy_static", "madato", "namada", @@ -4211,12 +4206,13 @@ name = "namada_ethereum_bridge" version = "0.23.0" dependencies = [ "assert_matches", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "data-encoding", "ethabi", "ethers", "eyre", - "itertools", + "itertools 0.10.5", "namada_core", "namada_macros", "namada_proof_of_stake", @@ -4243,10 +4239,10 @@ dependencies = [ name = "namada_proof_of_stake" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "data-encoding", "derivative", - "itertools", + "itertools 0.10.5", "namada_core", "once_cell", "proptest", @@ -4254,7 +4250,7 @@ dependencies = [ "test-log", "thiserror", "tracing 0.1.37", - "tracing-subscriber 0.3.17", + "tracing-subscriber", ] [[package]] @@ -4264,7 +4260,8 @@ dependencies = [ "assert_matches", "async-trait", "bimap", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "circular-queue", "data-encoding", "derivation-path", @@ -4272,7 +4269,7 @@ dependencies = [ "ethers", "fd-lock", "futures", - "itertools", + "itertools 0.10.5", "masp_primitives", "masp_proofs", "namada_core", @@ -4281,7 +4278,7 @@ dependencies = [ "namada_test_utils", "num256", "orion", - "owo-colors 3.5.0", + "owo-colors", "parse_duration", "paste", "prost", @@ -4308,7 +4305,7 @@ dependencies = [ name = "namada_test_utils" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "namada_core", "strum", ] @@ -4319,7 +4316,8 @@ version = "0.23.0" dependencies = [ "assert_cmd", "async-trait", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "chrono", "clap", "color-eyre", @@ -4332,7 +4330,7 @@ dependencies = [ "file-serve", "fs_extra", "hyper", - "itertools", + "itertools 0.10.5", "lazy_static", "namada", "namada_apps", @@ -4358,14 +4356,15 @@ dependencies = [ "tokio", "toml 0.5.9", "tracing 0.1.37", - "tracing-subscriber 0.3.17", + "tracing-subscriber", ] [[package]] name = "namada_tx_prelude" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "masp_primitives", "namada_core", "namada_macros", @@ -4379,7 +4378,7 @@ dependencies = [ name = "namada_vm_env" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "masp_primitives", "namada_core", ] @@ -4388,7 +4387,8 @@ dependencies = [ name = "namada_vp_prelude" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "namada_core", "namada_macros", "namada_proof_of_stake", @@ -4687,9 +4687,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "oorandom" @@ -4805,12 +4805,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" -[[package]] -name = "owo-colors" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" - [[package]] name = "owo-colors" version = "3.5.0" @@ -4819,11 +4813,11 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" [[package]] name = "pairing" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "135590d8bdba2b31346f9cd1fb2a912329f5135e832a4f422942eb6ead8b6b3b" +checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" dependencies = [ - "group 0.12.1", + "group", ] [[package]] @@ -4903,6 +4897,19 @@ dependencies = [ "subtle 2.4.1", ] +[[package]] +name = "pasta_curves" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e57598f73cc7e1b2ac63c79c517b31a0877cd7c402cdcaa311b5208de7a095" +dependencies = [ + "ff", + "group", + "rand 0.8.5", + "static_assertions", + "subtle 2.4.1", +] + [[package]] name = "paste" version = "1.0.12" @@ -4920,11 +4927,11 @@ dependencies = [ [[package]] name = "pbkdf2" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f05894bce6a1ba4be299d0c5f29563e08af2bc18bb7d48313113bed71e904739" +checksum = "271779f35b581956db91a3e55737327a03aa051e90b1c47aeb189508533adfd7" dependencies = [ - "crypto-mac 0.11.1", + "digest 0.10.6", "password-hash", ] @@ -5116,7 +5123,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" dependencies = [ "difflib", - "itertools", + "itertools 0.10.5", "predicates-core", ] @@ -5281,7 +5288,7 @@ checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", "heck", - "itertools", + "itertools 0.10.5", "lazy_static", "log", "multimap", @@ -5302,7 +5309,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.5", "proc-macro2", "quote", "syn 1.0.109", @@ -5478,21 +5485,36 @@ dependencies = [ ] [[package]] -name = "redjubjub" -version = "0.5.0" +name = "reddsa" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6039ff156887caf92df308cbaccdc058c9d3155a913da046add6e48c4cdbd91d" +checksum = "78a5191930e84973293aa5f532b513404460cd2216c1cfb76d08748c15b40b02" dependencies = [ "blake2b_simd", "byteorder", - "digest 0.9.0", + "group", + "hex", "jubjub", + "pasta_curves", "rand_core 0.6.4", "serde 1.0.163", "thiserror", "zeroize", ] +[[package]] +name = "redjubjub" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a60db2c3bc9c6fd1e8631fee75abc008841d27144be744951d6b9b75f9b569c" +dependencies = [ + "rand_core 0.6.4", + "reddsa", + "serde 1.0.163", + "thiserror", + "zeroize", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -5780,16 +5802,16 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.1" +version = "0.37.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4790277f605573dd24b6751701e0823582a63c7cafc095e427e6c66e45dd75e" +checksum = "f79bef90eb6d984c72722595b5b1348ab39275a5e5123faca6863bf07d75a4e0" dependencies = [ "bitflags 1.2.1", "errno", "io-lifetimes", "libc", "linux-raw-sys 0.3.7", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -6378,10 +6400,10 @@ dependencies = [ [[package]] name = "sparse-merkle-tree" version = "0.3.1-pre" -source = "git+https://github.com/heliaxdev/sparse-merkle-tree?rev=e086b235ed6e68929bf73f617dd61cd17b000a56#e086b235ed6e68929bf73f617dd61cd17b000a56" +source = "git+https://github.com/heliaxdev/sparse-merkle-tree?rev=df7ec062e7c40d5e76b136064e9aaf8bd2490750#df7ec062e7c40d5e76b136064e9aaf8bd2490750" dependencies = [ "blake2b-rs", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "cfg-if 1.0.0", "ics23", "sha2 0.9.9", @@ -6511,6 +6533,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6eef0000c4a12ecdfd7873ea84a8b5aab5e44db72e38e07b028a25386f29a5" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.15", +] + [[package]] name = "sync_wrapper" version = "0.1.2" @@ -6563,7 +6597,7 @@ dependencies = [ "cfg-if 1.0.0", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.1", + "rustix 0.37.13", "windows-sys 0.45.0", ] @@ -7171,7 +7205,7 @@ checksum = "09d48f71a791638519505cefafe162606f706c25592e4bde4d97600c0195312e" dependencies = [ "crossbeam-channel 0.5.8", "time", - "tracing-subscriber 0.3.17", + "tracing-subscriber", ] [[package]] @@ -7215,12 +7249,12 @@ dependencies = [ [[package]] name = "tracing-error" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" dependencies = [ "tracing 0.1.37", - "tracing-subscriber 0.2.25", + "tracing-subscriber", ] [[package]] @@ -7263,17 +7297,6 @@ dependencies = [ "tracing-core 0.1.31", ] -[[package]] -name = "tracing-subscriber" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" -dependencies = [ - "sharded-slab", - "thread_local", - "tracing-core 0.1.31", -] - [[package]] name = "tracing-subscriber" version = "0.3.17" @@ -8303,8 +8326,8 @@ dependencies = [ [[package]] name = "zcash_encoding" -version = "0.0.0" -source = "git+https://github.com/zcash/librustzcash?rev=43c18d0#43c18d000fcbe45363b2d53585d5102841eff99e" +version = "0.2.0" +source = "git+https://github.com/zcash/librustzcash?rev=bd7f9d7#bd7f9d7c3ce5cfd14af169ffe0e1c5c903162f46" dependencies = [ "byteorder", "nonempty", diff --git a/Cargo.toml b/Cargo.toml index 3af3afa7cb..141006744b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ ark-bls12-381 = {version = "0.3"} ark-serialize = {version = "0.3"} ark-std = "0.3.0" # branch = "bat/arse-merkle-tree" -arse-merkle-tree = {package = "sparse-merkle-tree", git = "https://github.com/heliaxdev/sparse-merkle-tree", rev = "e086b235ed6e68929bf73f617dd61cd17b000a56", default-features = false, features = ["std", "borsh"]} +arse-merkle-tree = {package = "sparse-merkle-tree", git = "https://github.com/heliaxdev/sparse-merkle-tree", rev = "df7ec062e7c40d5e76b136064e9aaf8bd2490750", default-features = false, features = ["std", "borsh"]} assert_cmd = "1.0.7" assert_matches = "1.5.0" async-trait = {version = "0.1.51"} @@ -53,12 +53,13 @@ bit-set = "0.5.2" blake2b-rs = "0.2.0" byte-unit = "4.0.13" byteorder = "1.4.2" -borsh = "0.9.0" +borsh = {version = "1.0.0-alpha.4", features = ["schema", "derive"]} +borsh-ext = {tag = "v1.0.0-alpha.4", git = "https://github.com/heliaxdev/borsh-ext"} chrono = {version = "0.4.22", default-features = false, features = ["clock", "std"]} circular-queue = "0.2.6" clap = "4.3.4" clru = {git = "https://github.com/marmeladema/clru-rs.git", rev = "71ca566"} -color-eyre = "0.5.10" +color-eyre = "0.6.2" concat-idents = "1.1.2" config = "0.11.0" data-encoding = "2.3.2" @@ -84,15 +85,15 @@ fs_extra = "1.2.0" futures = "0.3" git2 = "0.13.25" ics23 = "0.9.0" -index-set = {git = "https://github.com/heliaxdev/index-set", tag = "v0.7.1", features = ["serialize-borsh", "serialize-serde"]} +index-set = {git = "https://github.com/heliaxdev/index-set", tag = "v0.8.0", features = ["serialize-borsh", "serialize-serde"]} itertools = "0.10.0" k256 = { version = "0.13.0", default-features = false, features = ["ecdsa", "pkcs8", "precomputed-tables", "serde", "std"]} lazy_static = "1.4.0" libc = "0.2.97" libloading = "0.7.2" # branch = "murisi/namada-integration" -masp_primitives = { git = "https://github.com/anoma/masp", rev = "50acc5028fbcd52a05970fe7991c7850ab04358e" } -masp_proofs = { git = "https://github.com/anoma/masp", rev = "50acc5028fbcd52a05970fe7991c7850ab04358e", default-features = false, features = ["local-prover"] } +masp_primitives = { git = "https://github.com/anoma/masp", rev = "449a7295fe24d96456ece24c223ca9eb76b0e6ba" } +masp_proofs = { git = "https://github.com/anoma/masp", rev = "449a7295fe24d96456ece24c223ca9eb76b0e6ba", default-features = false, features = ["local-prover"] } num256 = "0.3.5" num_cpus = "1.13.0" num-derive = "0.3.3" @@ -148,13 +149,6 @@ wasmparser = "0.107.0" winapi = "0.3.9" zeroize = {version = "1.5.5", features = ["zeroize_derive"]} -[patch.crates-io] -# TODO temp patch for , and more tba. -borsh = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} -borsh-derive = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} -borsh-derive-internal = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} -borsh-schema-derive-internal = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} - [profile.release] lto = true opt-level = 3 diff --git a/apps/Cargo.toml b/apps/Cargo.toml index 02bcf60373..3f35f53241 100644 --- a/apps/Cargo.toml +++ b/apps/Cargo.toml @@ -78,6 +78,7 @@ bech32.workspace = true bimap.workspace = true blake2b-rs.workspace = true borsh.workspace = true +borsh-ext.workspace = true byte-unit.workspace = true byteorder.workspace = true clap.workspace = true diff --git a/apps/src/lib/cli/wallet.rs b/apps/src/lib/cli/wallet.rs index 247835f46b..14b9ab9d9a 100644 --- a/apps/src/lib/cli/wallet.rs +++ b/apps/src/lib/cli/wallet.rs @@ -3,7 +3,7 @@ use std::fs::File; use std::io::{self, Write}; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use color_eyre::eyre::Result; use itertools::sorted; use masp_primitives::zip32::ExtendedFullViewingKey; @@ -545,9 +545,7 @@ fn key_export( wallet .find_key(alias.to_lowercase(), None) .map(|keypair| { - let file_data = keypair - .try_to_vec() - .expect("Encoding keypair shouldn't fail"); + let file_data = keypair.serialize_to_vec(); let file_name = format!("key_{}", alias.to_lowercase()); let mut file = File::create(&file_name).unwrap(); diff --git a/apps/src/lib/client/rpc.rs b/apps/src/lib/client/rpc.rs index d7150bfa9a..d727a56f0b 100644 --- a/apps/src/lib/client/rpc.rs +++ b/apps/src/lib/client/rpc.rs @@ -7,7 +7,8 @@ use std::io; use std::iter::Iterator; use std::str::FromStr; -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXLOWER; use itertools::Either; use masp_primitives::asset_type::AssetType; @@ -839,10 +840,7 @@ pub async fn query_shielded_balance<'a>( // Compute the unique asset identifier from the token address let token = token; let _asset_type = AssetType::new( - (token.clone(), epoch.0) - .try_to_vec() - .expect("token addresses should serialize") - .as_ref(), + (token.clone(), epoch.0).serialize_to_vec().as_ref(), ) .unwrap(); let token_alias = context.wallet().await.lookup_alias(&token); diff --git a/apps/src/lib/client/utils.rs b/apps/src/lib/client/utils.rs index 83fd499071..16bf625c23 100644 --- a/apps/src/lib/client/utils.rs +++ b/apps/src/lib/client/utils.rs @@ -5,7 +5,7 @@ use std::io::Write; use std::path::{Path, PathBuf}; use std::str::FromStr; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use flate2::read::GzDecoder; use flate2::write::GzEncoder; use flate2::Compression; @@ -384,12 +384,12 @@ pub fn id_from_pk(pk: &common::PublicKey) -> TendermintNodeId { match pk { common::PublicKey::Ed25519(_) => { let _pk: ed25519::PublicKey = pk.try_to_pk().unwrap(); - let digest = Sha256::digest(_pk.try_to_vec().unwrap().as_slice()); + let digest = Sha256::digest(_pk.serialize_to_vec().as_slice()); bytes.copy_from_slice(&digest[..TENDERMINT_NODE_ID_LENGTH]); } common::PublicKey::Secp256k1(_) => { let _pk: secp256k1::PublicKey = pk.try_to_pk().unwrap(); - let digest = Sha256::digest(_pk.try_to_vec().unwrap().as_slice()); + let digest = Sha256::digest(_pk.serialize_to_vec().as_slice()); bytes.copy_from_slice(&digest[..TENDERMINT_NODE_ID_LENGTH]); } } @@ -723,7 +723,7 @@ pub fn init_network( // Generate the chain ID first let genesis = genesis_config::load_genesis_config(config_clean.clone()); - let genesis_bytes = genesis.try_to_vec().unwrap(); + let genesis_bytes = genesis.serialize_to_vec(); let chain_id = ChainId::from_genesis(chain_id_prefix, genesis_bytes); let chain_dir = global_args.base_dir.join(chain_id.as_str()); let genesis_path = global_args @@ -1144,12 +1144,11 @@ pub fn write_tendermint_node_key( // but does not for secp256k1. let (node_keypair, key_str) = match node_sk { common::SecretKey::Ed25519(sk) => ( - [sk.try_to_vec().unwrap(), sk.ref_to().try_to_vec().unwrap()] - .concat(), + [sk.serialize_to_vec(), sk.ref_to().serialize_to_vec()].concat(), "Ed25519", ), common::SecretKey::Secp256k1(sk) => { - (sk.try_to_vec().unwrap(), "Secp256k1") + (sk.serialize_to_vec(), "Secp256k1") } }; diff --git a/apps/src/lib/config/genesis.rs b/apps/src/lib/config/genesis.rs index 222e7b4f1f..63a431fca2 100644 --- a/apps/src/lib/config/genesis.rs +++ b/apps/src/lib/config/genesis.rs @@ -729,7 +729,7 @@ pub mod genesis_config { } #[derive(Debug, BorshSerialize, BorshDeserialize)] -#[borsh_init(init)] +#[borsh(init=init)] pub struct Genesis { pub genesis_time: DateTimeUtc, pub native_token: Address, @@ -1136,7 +1136,7 @@ pub fn genesis(num_validators: u64) -> Genesis { #[cfg(test)] pub mod tests { - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use namada::types::address::testing::gen_established_address; use namada::types::key::*; use rand::prelude::ThreadRng; @@ -1152,7 +1152,7 @@ pub mod tests { let mut rng: ThreadRng = thread_rng(); let keypair: common::SecretKey = ed25519::SigScheme::generate(&mut rng).try_to_sk().unwrap(); - let kp_arr = keypair.try_to_vec().unwrap(); + let kp_arr = keypair.serialize_to_vec(); let (protocol_keypair, _eth_hot_bridge_keypair, dkg_keypair) = wallet::defaults::validator_keys(); @@ -1169,14 +1169,14 @@ pub mod tests { println!("address: {}", address); println!("keypair: {:?}", kp_arr); println!("protocol_keypair: {:?}", protocol_keypair); - println!("dkg_keypair: {:?}", dkg_keypair.try_to_vec().unwrap()); + println!("dkg_keypair: {:?}", dkg_keypair.serialize_to_vec()); println!( "eth_cold_gov_keypair: {:?}", - eth_cold_gov_keypair.try_to_vec().unwrap() + eth_cold_gov_keypair.serialize_to_vec() ); println!( "eth_hot_bridge_keypair: {:?}", - eth_hot_bridge_keypair.try_to_vec().unwrap() + eth_hot_bridge_keypair.serialize_to_vec() ); } } diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index 9c24005957..c6d03a7f47 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -1200,10 +1200,7 @@ mod test_finalize_block { shell .wl_storage .storage - .write( - &balance_key, - Amount::native_whole(1000).try_to_vec().unwrap(), - ) + .write(&balance_key, Amount::native_whole(1000).serialize_to_vec()) .unwrap(); // create some wrapper txs @@ -1385,10 +1382,7 @@ mod test_finalize_block { shell .wl_storage .storage - .write( - &balance_key, - Amount::native_whole(1000).try_to_vec().unwrap(), - ) + .write(&balance_key, Amount::native_whole(1000).serialize_to_vec()) .unwrap(); // create two decrypted txs @@ -1638,7 +1632,7 @@ mod test_finalize_block { &KeccakHash([1; 32]), 3.into(), ); - let value = BlockHeight(4).try_to_vec().expect("Test failed"); + let value = BlockHeight(4).serialize_to_vec(); shell .wl_storage .storage @@ -1649,10 +1643,7 @@ mod test_finalize_block { shell .wl_storage .storage - .write( - &get_nonce_key(), - Uint::from(1).try_to_vec().expect("Test failed"), - ) + .write(&get_nonce_key(), Uint::from(1).serialize_to_vec()) .expect("Test failed"); let (tx, action) = craft_tx(&mut shell); let processed_tx = ProcessedTx { @@ -1828,10 +1819,7 @@ mod test_finalize_block { shell .wl_storage .storage - .write( - &balance_key, - Amount::native_whole(1000).try_to_vec().unwrap(), - ) + .write(&balance_key, Amount::native_whole(1000).serialize_to_vec()) .unwrap(); // Add a proposal to be executed on next epoch change. diff --git a/apps/src/lib/node/ledger/shell/init_chain.rs b/apps/src/lib/node/ledger/shell/init_chain.rs index 6faf48f2d1..60b46369f7 100644 --- a/apps/src/lib/node/ledger/shell/init_chain.rs +++ b/apps/src/lib/node/ledger/shell/init_chain.rs @@ -53,7 +53,7 @@ where genesis::genesis(&self.base_dir, &self.wl_storage.storage.chain_id); #[cfg(not(any(test, feature = "dev")))] { - let genesis_bytes = genesis.try_to_vec().unwrap(); + let genesis_bytes = genesis.serialize_to_vec(); let errors = self.wl_storage.storage.chain_id.validate(genesis_bytes); use itertools::Itertools; @@ -210,7 +210,7 @@ where self.wl_storage .write_bytes( &namada::eth_bridge::storage::active_key(), - EthBridgeStatus::Disabled.try_to_vec().unwrap(), + EthBridgeStatus::Disabled.serialize_to_vec(), ) .unwrap(); } diff --git a/apps/src/lib/node/ledger/shell/mod.rs b/apps/src/lib/node/ledger/shell/mod.rs index 8977a319a0..8c360f3bc4 100644 --- a/apps/src/lib/node/ledger/shell/mod.rs +++ b/apps/src/lib/node/ledger/shell/mod.rs @@ -26,7 +26,8 @@ use std::path::{Path, PathBuf}; #[allow(unused_imports)] use std::rc::Rc; -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; +use borsh_ext::BorshSerializeExt; use masp_primitives::transaction::Transaction; use namada::core::hints; use namada::core::ledger::eth_bridge; @@ -93,10 +94,10 @@ fn key_to_tendermint( ) -> std::result::Result { match pk { common::PublicKey::Ed25519(_) => ed25519::PublicKey::try_from_pk(pk) - .map(|pk| public_key::Sum::Ed25519(pk.try_to_vec().unwrap())), + .map(|pk| public_key::Sum::Ed25519(pk.serialize_to_vec())), common::PublicKey::Secp256k1(_) => { secp256k1::PublicKey::try_from_pk(pk) - .map(|pk| public_key::Sum::Secp256k1(pk.try_to_vec().unwrap())) + .map(|pk| public_key::Sum::Secp256k1(pk.serialize_to_vec())) } } } @@ -1988,7 +1989,7 @@ mod test_utils { .wl_storage .write_bytes( &active_key(), - EthBridgeStatus::Disabled.try_to_vec().expect("Test failed"), + EthBridgeStatus::Disabled.serialize_to_vec(), ) .expect("Test failed"); } @@ -2363,7 +2364,7 @@ mod shell_tests { }))); // invalid tx type, it doesn't match the // tx type declared in the header - tx.set_data(Data::new(ext.try_to_vec().expect("Test falied"))); + tx.set_data(Data::new(ext.serialize_to_vec())); tx.add_section(Section::Signature(Signature::new( tx.sechashes(), [(0, protocol_key)].into_iter().collect(), diff --git a/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/apps/src/lib/node/ledger/shell/prepare_proposal.rs index 198ddb8b30..84bc468ed9 100644 --- a/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -493,7 +493,7 @@ mod test_prepare_proposal { #[cfg(feature = "abcipp")] use std::collections::{BTreeSet, HashMap}; - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use namada::core::ledger::storage_api::collections::lazy_map::{ NestedSubKey, SubKey, }; @@ -584,8 +584,7 @@ mod test_prepare_proposal { bridge_pool_root: Some(bp_root), validator_set_update: None, } - .try_to_vec() - .expect("Test failed"); + .serialize_to_vec(); let vote = ExtendedVoteInfo { vote_extension, @@ -1028,7 +1027,7 @@ mod test_prepare_proposal { validator_set_update: None, }; let vote = ExtendedVoteInfo { - vote_extension: vote_extension.try_to_vec().unwrap(), + vote_extension: vote_extension.serialize_to_vec(), ..Default::default() }; // this should panic @@ -1083,10 +1082,7 @@ mod test_prepare_proposal { shell .wl_storage .storage - .write( - &balance_key, - Amount::native_whole(1_000).try_to_vec().unwrap(), - ) + .write(&balance_key, Amount::native_whole(1_000).serialize_to_vec()) .unwrap(); let mut req = RequestPrepareProposal { @@ -1151,11 +1147,11 @@ mod test_prepare_proposal { assert_eq!( received .iter() - .map(|x| x.try_to_vec().unwrap()) + .map(|x| x.serialize_to_vec()) .collect::>(), expected_txs .iter() - .map(|x| x.try_to_vec().unwrap()) + .map(|x| x.serialize_to_vec()) .collect::>(), ); } diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index e5b1e94e13..3503c5adc9 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -2180,10 +2180,7 @@ mod test_process_proposal { shell .wl_storage .storage - .write( - &balance_key, - Amount::native_whole(1000).try_to_vec().unwrap(), - ) + .write(&balance_key, Amount::native_whole(1000).serialize_to_vec()) .unwrap(); let mut wrapper = diff --git a/apps/src/lib/node/ledger/shell/queries.rs b/apps/src/lib/node/ledger/shell/queries.rs index f1e56c295f..28843fabc6 100644 --- a/apps/src/lib/node/ledger/shell/queries.rs +++ b/apps/src/lib/node/ledger/shell/queries.rs @@ -1,6 +1,6 @@ //! Shell methods for querying state -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use ferveo_common::TendermintValidator; use namada::ledger::dry_run_tx; use namada::ledger::pos::into_tm_voting_power; @@ -89,9 +89,7 @@ where &self, pk: &common::PublicKey, ) -> Option> { - let pk_bytes = pk - .try_to_vec() - .expect("Serializing public key should not fail"); + let pk_bytes = pk.serialize_to_vec(); // get the current epoch let (current_epoch, _) = self.wl_storage.storage.get_current_epoch(); diff --git a/apps/src/lib/node/ledger/shell/vote_extensions.rs b/apps/src/lib/node/ledger/shell/vote_extensions.rs index e7e19bf96d..847a791ea0 100644 --- a/apps/src/lib/node/ledger/shell/vote_extensions.rs +++ b/apps/src/lib/node/ledger/shell/vote_extensions.rs @@ -87,7 +87,7 @@ where _req: request::ExtendVote, ) -> response::ExtendVote { response::ExtendVote { - vote_extension: self.craft_extension().try_to_vec().unwrap(), + vote_extension: self.craft_extension().serialize_to_vec(), } } diff --git a/apps/src/lib/node/ledger/shell/vote_extensions/bridge_pool_vext.rs b/apps/src/lib/node/ledger/shell/vote_extensions/bridge_pool_vext.rs index 201c96983f..7af066dc58 100644 --- a/apps/src/lib/node/ledger/shell/vote_extensions/bridge_pool_vext.rs +++ b/apps/src/lib/node/ledger/shell/vote_extensions/bridge_pool_vext.rs @@ -270,7 +270,7 @@ where mod test_bp_vote_extensions { #[cfg(feature = "abcipp")] use borsh::BorshDeserialize; - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; #[cfg(not(feature = "abcipp"))] use namada::core::ledger::eth_bridge::storage::bridge_pool::get_key_from_hash; use namada::ledger::pos::PosQueries; @@ -325,13 +325,7 @@ mod test_bp_vote_extensions { let pk_key = protocol_pk_key(&bertha_address()); shell .wl_storage - .write_bytes( - &pk_key, - bertha_keypair() - .ref_to() - .try_to_vec() - .expect("Test failed."), - ) + .write_bytes(&pk_key, bertha_keypair().ref_to().serialize_to_vec()) .expect("Test failed."); // change pipeline length to 1 @@ -481,7 +475,7 @@ mod test_bp_vote_extensions { .as_bytes() .to_vec(), height: 0, - vote_extension: vote_extension.try_to_vec().expect("Test failed"), + vote_extension: vote_extension.serialize_to_vec(), }; let res = shell.verify_vote_extension(req); assert_eq!(res.status, i32::from(VerifyStatus::Accept)); @@ -692,8 +686,7 @@ mod test_bp_vote_extensions { let address = shell.mode.get_validator_address().unwrap().clone(); shell.wl_storage.storage.block.height = 4.into(); let key = get_key_from_hash(&KeccakHash([1; 32])); - let height = - shell.wl_storage.storage.block.height.try_to_vec().unwrap(); + let height = shell.wl_storage.storage.block.height.serialize_to_vec(); shell .wl_storage .storage @@ -719,8 +712,7 @@ mod test_bp_vote_extensions { .delete(&key) .expect("Test failed"); let key = get_key_from_hash(&KeccakHash([2; 32])); - let height = - shell.wl_storage.storage.block.height.try_to_vec().unwrap(); + let height = shell.wl_storage.storage.block.height.serialize_to_vec(); shell .wl_storage .storage @@ -780,8 +772,7 @@ mod test_bp_vote_extensions { let address = shell.mode.get_validator_address().unwrap().clone(); shell.wl_storage.storage.block.height = 4.into(); let key = get_key_from_hash(&KeccakHash([1; 32])); - let height = - shell.wl_storage.storage.block.height.try_to_vec().unwrap(); + let height = shell.wl_storage.storage.block.height.serialize_to_vec(); shell .wl_storage .storage @@ -807,8 +798,7 @@ mod test_bp_vote_extensions { .delete(&key) .expect("Test failed"); let key = get_key_from_hash(&KeccakHash([2; 32])); - let height = - shell.wl_storage.storage.block.height.try_to_vec().unwrap(); + let height = shell.wl_storage.storage.block.height.serialize_to_vec(); shell .wl_storage .storage diff --git a/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs b/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs index e7dbdc255b..8b9c140cfc 100644 --- a/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs +++ b/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs @@ -411,7 +411,7 @@ mod test_vote_extensions { #[cfg(feature = "abcipp")] use borsh::BorshDeserialize; - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use namada::core::ledger::storage_api::collections::lazy_map::{ NestedSubKey, SubKey, }; @@ -461,7 +461,7 @@ mod test_vote_extensions { shell .wl_storage .storage - .write(&bridge_pool::get_nonce_key(), nonce.try_to_vec().unwrap()) + .write(&bridge_pool::get_nonce_key(), nonce.serialize_to_vec()) .expect("Test failed"); // write nam nonce to the eth events queue @@ -642,7 +642,7 @@ mod test_vote_extensions { .as_bytes() .to_vec(), height: 1, - vote_extension: vote_extension.try_to_vec().expect("Test failed"), + vote_extension: vote_extension.serialize_to_vec(), }; let res = shell.verify_vote_extension(req); assert_eq!(res.status, i32::from(VerifyStatus::Accept)); @@ -720,8 +720,7 @@ mod test_vote_extensions { }, validator_set_update: None, } - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), }; #[cfg(feature = "abcipp")] assert_eq!( @@ -899,15 +898,14 @@ mod test_vote_extensions { }; let req = request::VerifyVoteExtension { hash: vec![], - validator_address: address.try_to_vec().expect("Test failed"), + validator_address: address.serialize_to_vec(), height: 0, vote_extension: VoteExtension { ethereum_events: Some(signed_vext), bridge_pool_root: Some(bp_root), validator_set_update: None, } - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), }; assert_eq!( @@ -952,9 +950,9 @@ mod test_vote_extensions { #[cfg(feature = "abcipp")] let req = request::VerifyVoteExtension { hash: vec![], - validator_address: address.try_to_vec().expect("Test failed"), + validator_address: address.serialize_to_vec(), height: 0, - vote_extension: vote_ext.try_to_vec().expect("Test failed"), + vote_extension: vote_ext.serialize_to_vec(), }; #[cfg(feature = "abcipp")] assert_eq!( diff --git a/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs b/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs index 4888c10be1..ef1a3f9771 100644 --- a/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs +++ b/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs @@ -419,8 +419,7 @@ mod test_vote_extensions { bridge_pool_root: Some(bp_root), validator_set_update, } - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ..Default::default() }; @@ -506,8 +505,7 @@ mod test_vote_extensions { bridge_pool_root: Some(bp_root), validator_set_update, } - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ..Default::default() }; assert_eq!( @@ -715,8 +713,7 @@ mod test_vote_extensions { bridge_pool_root: Some(bp_root), validator_set_update: validator_set_update.clone(), } - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ..Default::default() }; assert_eq!( diff --git a/apps/src/lib/node/ledger/storage/rocksdb.rs b/apps/src/lib/node/ledger/storage/rocksdb.rs index 61eb2c32e5..1e2d74fbf3 100644 --- a/apps/src/lib/node/ledger/storage/rocksdb.rs +++ b/apps/src/lib/node/ledger/storage/rocksdb.rs @@ -40,7 +40,8 @@ use std::str::FromStr; use std::sync::Mutex; use ark_serialize::Write; -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXLOWER; use namada::core::types::ethereum_structs; use namada::ledger::storage::types::PrefixIterator; @@ -903,11 +904,9 @@ impl DB for RocksDB { let key = prefix_key .push(&"header".to_owned()) .map_err(Error::KeyError)?; - batch.0.put_cf( - block_cf, - key.to_string(), - h.try_to_vec().expect("serialization failed"), - ); + batch + .0 + .put_cf(block_cf, key.to_string(), h.serialize_to_vec()); } } // Block hash diff --git a/apps/src/lib/node/ledger/tendermint_node.rs b/apps/src/lib/node/ledger/tendermint_node.rs index 2bd5168ffa..0833f7c3a7 100644 --- a/apps/src/lib/node/ledger/tendermint_node.rs +++ b/apps/src/lib/node/ledger/tendermint_node.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use std::process::Stdio; use std::str::FromStr; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use namada::types::chain::ChainId; use namada::types::key::*; use namada::types::storage::BlockHeight; @@ -24,7 +24,6 @@ use crate::facade::tendermint::{block, Genesis}; use crate::facade::tendermint_config::{ Error as TendermintError, TendermintConfig, }; - /// Env. var to output Tendermint log to stdout pub const ENV_VAR_TM_STDOUT: &str = "NAMADA_CMT_STDOUT"; @@ -243,19 +242,17 @@ fn validator_key_to_json( let (id_str, pk_arr, kp_arr) = match sk { common::SecretKey::Ed25519(_) => { let sk_ed: ed25519::SecretKey = sk.try_to_sk().unwrap(); - let keypair = [ - sk_ed.try_to_vec().unwrap(), - sk_ed.ref_to().try_to_vec().unwrap(), - ] - .concat(); - ("Ed25519", sk_ed.ref_to().try_to_vec().unwrap(), keypair) + let keypair = + [sk_ed.serialize_to_vec(), sk_ed.ref_to().serialize_to_vec()] + .concat(); + ("Ed25519", sk_ed.ref_to().serialize_to_vec(), keypair) } common::SecretKey::Secp256k1(_) => { let sk_sec: secp256k1::SecretKey = sk.try_to_sk().unwrap(); ( "Secp256k1", - sk_sec.ref_to().try_to_vec().unwrap(), - sk_sec.try_to_vec().unwrap(), + sk_sec.ref_to().serialize_to_vec(), + sk_sec.serialize_to_vec(), ) } }; diff --git a/apps/src/lib/wallet/cli_utils.rs b/apps/src/lib/wallet/cli_utils.rs index 46349167ef..9908af12bb 100644 --- a/apps/src/lib/wallet/cli_utils.rs +++ b/apps/src/lib/wallet/cli_utils.rs @@ -1,7 +1,7 @@ use std::fs::File; use std::io::{self, Write}; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use itertools::sorted; use masp_primitives::zip32::ExtendedFullViewingKey; use namada::types::key::{PublicKeyHash, RefTo}; @@ -430,9 +430,7 @@ pub fn key_export(ctx: Context, args::KeyExport { alias }: args::KeyExport) { wallet .find_key(alias.to_lowercase(), None) .map(|keypair| { - let file_data = keypair - .try_to_vec() - .expect("Encoding keypair shouldn't fail"); + let file_data = keypair.serialize_to_vec(); let file_name = format!("key_{}", alias.to_lowercase()); let mut file = File::create(&file_name).unwrap(); diff --git a/benches/Cargo.toml b/benches/Cargo.toml index ebd99eedda..d5a954b785 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -44,6 +44,7 @@ path = "host_env.rs" [dependencies] async-trait.workspace = true borsh.workspace = true +borsh-ext.workspace = true ferveo-common.workspace = true masp_primitives.workspace = true masp_proofs.workspace = true diff --git a/benches/host_env.rs b/benches/host_env.rs index 6f385b93bc..1c611f4e18 100644 --- a/benches/host_env.rs +++ b/benches/host_env.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use criterion::{criterion_group, criterion_main, Criterion}; use namada::core::types::account::AccountPublicKeysMap; use namada::core::types::address; @@ -19,7 +19,7 @@ fn tx_section_signature_validation(c: &mut Criterion) { key: None, shielded: None, }; - let section = Section::Data(Data::new(transfer_data.try_to_vec().unwrap())); + let section = Section::Data(Data::new(transfer_data.serialize_to_vec())); let section_hash = section.get_hash(); let pkim = AccountPublicKeysMap::from_iter([ diff --git a/benches/lib.rs b/benches/lib.rs index 038d7017f0..1d07f2e250 100644 --- a/benches/lib.rs +++ b/benches/lib.rs @@ -21,6 +21,7 @@ use std::path::PathBuf; use std::sync::Once; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use masp_primitives::transaction::Transaction; use masp_primitives::zip32::ExtendedFullViewingKey; use masp_proofs::prover::LocalTxProver; @@ -438,7 +439,7 @@ pub fn generate_tx( WASM_DIR, wasm_code_path, ))); - tx.set_data(Data::new(data.try_to_vec().unwrap())); + tx.set_data(Data::new(data.serialize_to_vec())); if let Some(transaction) = shielded { tx.add_section(Section::MaspTx(transaction)); @@ -493,8 +494,7 @@ pub fn generate_foreign_key_tx(signer: &SecretKey) -> Tx { key: Key::from("bench_foreign_key".to_string().to_db_key()), value: vec![0; 64], } - .try_to_vec() - .unwrap(), + .serialize_to_vec(), )); tx.add_section(Section::Signature(Signature::new( tx.sechashes(), @@ -565,7 +565,7 @@ impl Clone for WrapperTempDir { #[derive(BorshSerialize, BorshDeserialize, Debug, Clone, Default)] pub struct BenchShieldedUtils { - #[borsh_skip] + #[borsh(skip)] context_dir: WrapperTempDir, } diff --git a/core/Cargo.toml b/core/Cargo.toml index 0dbd4b1822..31fc8e8314 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -56,6 +56,7 @@ ark-serialize.workspace = true arse-merkle-tree.workspace = true bech32.workspace = true borsh.workspace = true +borsh-ext.workspace = true chrono.workspace = true data-encoding.workspace = true derivative.workspace = true diff --git a/core/src/ledger/governance/cli/offline.rs b/core/src/ledger/governance/cli/offline.rs index fb56a1270a..64b13e29db 100644 --- a/core/src/ledger/governance/cli/offline.rs +++ b/core/src/ledger/governance/cli/offline.rs @@ -3,6 +3,7 @@ use std::fs::{File, ReadDir}; use std::path::PathBuf; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use serde::{Deserialize, Serialize}; use super::onchain::ProposalVote; @@ -214,14 +215,8 @@ impl OfflineVote { keypairs: Vec, account_public_keys_map: &AccountPublicKeysMap, ) -> Self { - let proposal_vote_data = self - .vote - .try_to_vec() - .expect("Conversion to bytes shouldn't fail."); - let delegations_hash = self - .delegations - .try_to_vec() - .expect("Conversion to bytes shouldn't fail."); + let proposal_vote_data = self.vote.serialize_to_vec(); + let delegations_hash = self.delegations.serialize_to_vec(); let vote_hash = Hash::sha256( [ @@ -248,18 +243,9 @@ impl OfflineVote { /// compute the hash of a proposal pub fn compute_hash(&self) -> Hash { - let proposal_hash_data = self - .proposal_hash - .try_to_vec() - .expect("Conversion to bytes shouldn't fail."); - let proposal_vote_data = self - .vote - .try_to_vec() - .expect("Conversion to bytes shouldn't fail."); - let delegations_hash = self - .delegations - .try_to_vec() - .expect("Conversion to bytes shouldn't fail."); + let proposal_hash_data = self.proposal_hash.serialize_to_vec(); + let proposal_vote_data = self.vote.serialize_to_vec(); + let delegations_hash = self.delegations.serialize_to_vec(); let vote_serialized = &[proposal_hash_data, proposal_vote_data, delegations_hash] .concat(); diff --git a/core/src/ledger/governance/storage/proposal.rs b/core/src/ledger/governance/storage/proposal.rs index 72a15b8631..c4a59389ef 100644 --- a/core/src/ledger/governance/storage/proposal.rs +++ b/core/src/ledger/governance/storage/proposal.rs @@ -55,6 +55,7 @@ impl StoragePgfFunding { PartialEq, Eq, PartialOrd, + Ord, BorshSerialize, BorshDeserialize, Serialize, diff --git a/core/src/ledger/ibc/context/common.rs b/core/src/ledger/ibc/context/common.rs index 5e963e7a5f..a9733b18ac 100644 --- a/core/src/ledger/ibc/context/common.rs +++ b/core/src/ledger/ibc/context/common.rs @@ -1,6 +1,7 @@ //! IbcCommonContext implementation for IBC -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; +use borsh_ext::BorshSerializeExt; use prost::Message; use sha2::Digest; @@ -374,10 +375,7 @@ pub trait IbcCommonContext: IbcStorageContext { }) })?; if !has_key { - let bytes = denom - .as_ref() - .try_to_vec() - .expect("encoding shouldn't fail"); + let bytes = denom.as_ref().serialize_to_vec(); self.write(&key, bytes).map_err(|_| { ContextError::ChannelError(ChannelError::Other { description: format!( @@ -434,7 +432,7 @@ pub trait IbcCommonContext: IbcStorageContext { if !has_key { // IBC denomination should be zero for U256 let denom = token::Denomination::from(0); - let bytes = denom.try_to_vec().expect("encoding shouldn't fail"); + let bytes = denom.serialize_to_vec(); self.write(&key, bytes).map_err(|_| { ContextError::ChannelError(ChannelError::Other { description: format!( diff --git a/core/src/ledger/ibc/context/execution.rs b/core/src/ledger/ibc/context/execution.rs index ec0708ce2a..0160cb1d29 100644 --- a/core/src/ledger/ibc/context/execution.rs +++ b/core/src/ledger/ibc/context/execution.rs @@ -1,6 +1,7 @@ //! ExecutionContext implementation for IBC -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; +use borsh_ext::BorshSerializeExt; use super::super::{IbcActions, IbcCommonContext}; use crate::ibc::core::events::IbcEvent; @@ -179,7 +180,7 @@ where }))? } }; - let bytes = list.try_to_vec().expect("encoding shouldn't fail"); + let bytes = list.serialize_to_vec(); self.ctx.borrow_mut().write(&key, bytes).map_err(|_| { ContextError::ConnectionError(ConnectionError::Other { description: format!( diff --git a/core/src/ledger/storage/masp_conversions.rs b/core/src/ledger/storage/masp_conversions.rs index 624fe2aa1f..a9f6c9342d 100644 --- a/core/src/ledger/storage/masp_conversions.rs +++ b/core/src/ledger/storage/masp_conversions.rs @@ -3,6 +3,7 @@ use std::collections::BTreeMap; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use masp_primitives::asset_type::AssetType; use masp_primitives::convert::AllowedConversion; use masp_primitives::merkle_tree::FrozenCommitmentTree; @@ -203,11 +204,7 @@ where .into_storage_result()?; // We cannot borrow `conversion_state` at the same time as when we call // `wl_storage.write`, so we encode it manually first - let conv_bytes = wl_storage - .storage - .conversion_state - .try_to_vec() - .into_storage_result()?; + let conv_bytes = wl_storage.storage.conversion_state.serialize_to_vec(); wl_storage.write_bytes(&state_key, conv_bytes)?; Ok(()) } @@ -218,9 +215,7 @@ pub fn encode_asset_type( denom: MaspDenom, epoch: Epoch, ) -> AssetType { - let new_asset_bytes = (addr, denom, epoch.0) - .try_to_vec() - .expect("unable to serialize address and epoch"); + let new_asset_bytes = (addr, denom, epoch.0).serialize_to_vec(); AssetType::new(new_asset_bytes.as_ref()) .expect("unable to derive asset identifier") } diff --git a/core/src/ledger/storage/merkle_tree.rs b/core/src/ledger/storage/merkle_tree.rs index eb4e34e20b..961cbc3c35 100644 --- a/core/src/ledger/storage/merkle_tree.rs +++ b/core/src/ledger/storage/merkle_tree.rs @@ -8,6 +8,7 @@ use arse_merkle_tree::{ Hash as SmtHash, Key as TreeKey, SparseMerkleTree as ArseMerkleTree, H256, }; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use ics23::commitment_proof::Proof as Ics23Proof; use ics23::{CommitmentProof, ExistenceProof, NonExistenceProof}; use thiserror::Error; @@ -152,13 +153,12 @@ impl<'a> StoreRef<'a> { /// Borsh Seriliaze the backing stores of our Merkle tree. pub fn encode(&self) -> Vec { match self { - Self::Base(store) => store.try_to_vec(), - Self::Account(store) => store.try_to_vec(), - Self::Ibc(store) => store.try_to_vec(), - Self::PoS(store) => store.try_to_vec(), - Self::BridgePool(store) => store.try_to_vec(), + Self::Base(store) => store.serialize_to_vec(), + Self::Account(store) => store.serialize_to_vec(), + Self::Ibc(store) => store.serialize_to_vec(), + Self::PoS(store) => store.serialize_to_vec(), + Self::BridgePool(store) => store.serialize_to_vec(), } - .expect("Serialization failed") } } diff --git a/core/src/ledger/storage/mockdb.rs b/core/src/ledger/storage/mockdb.rs index 971584e742..3412959a3b 100644 --- a/core/src/ledger/storage/mockdb.rs +++ b/core/src/ledger/storage/mockdb.rs @@ -6,7 +6,8 @@ use std::ops::Bound::{Excluded, Included}; use std::path::Path; use std::str::FromStr; -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; +use borsh_ext::BorshSerializeExt; use super::merkle_tree::{MerkleTreeStoresRead, StoreType}; use super::{ @@ -295,10 +296,9 @@ impl DB for MockDB { let key = prefix_key .push(&"header".to_owned()) .map_err(Error::KeyError)?; - self.0.borrow_mut().insert( - key.to_string(), - h.try_to_vec().expect("serialization failed"), - ); + self.0 + .borrow_mut() + .insert(key.to_string(), h.serialize_to_vec()); } } // Block hash diff --git a/core/src/ledger/storage/mod.rs b/core/src/ledger/storage/mod.rs index 81be7e48a6..845b2d6f4b 100644 --- a/core/src/ledger/storage/mod.rs +++ b/core/src/ledger/storage/mod.rs @@ -15,6 +15,7 @@ use std::cmp::Ordering; use std::format; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; pub use merkle_tree::{ MerkleTree, MerkleTreeStoresRead, MerkleTreeStoresWrite, StoreType, }; @@ -664,8 +665,7 @@ where if is_pending_transfer_key(key) { // The tree of the bright pool stores the current height for the // pending transfer - let height = - self.block.height.try_to_vec().expect("Encoding failed"); + let height = self.block.height.serialize_to_vec(); self.block.tree.update(key, height)?; } else if !is_replay_protection_key(key) { // Update the merkle tree for all but replay-protection entries @@ -801,10 +801,7 @@ where tree.update( &new_key, if is_pending_transfer_key(&new_key) { - target_height.try_to_vec().expect( - "Serialization should never \ - fail", - ) + target_height.serialize_to_vec() } else { new.1.clone() }, @@ -826,10 +823,7 @@ where tree.update( &new_key, if is_pending_transfer_key(&new_key) { - target_height.try_to_vec().expect( - "Serialization should never \ - fail", - ) + target_height.serialize_to_vec() } else { new.1.clone() }, @@ -857,9 +851,7 @@ where tree.update( &key, if is_pending_transfer_key(&key) { - target_height.try_to_vec().expect( - "Serialization should never fail", - ) + target_height.serialize_to_vec() } else { new.1.clone() }, @@ -1055,8 +1047,7 @@ where if is_pending_transfer_key(key) { // The tree of the bright pool stores the current height for the // pending transfer - let height = - self.block.height.try_to_vec().expect("Encoding failed"); + let height = self.block.height.serialize_to_vec(); self.block.tree.update(key, height)?; } else if !is_replay_protection_key(key) { // Update the merkle tree for all but replay-protection entries diff --git a/core/src/ledger/storage/traits.rs b/core/src/ledger/storage/traits.rs index 2892110480..40b094e411 100644 --- a/core/src/ledger/storage/traits.rs +++ b/core/src/ledger/storage/traits.rs @@ -5,7 +5,8 @@ use std::fmt; use arse_merkle_tree::traits::{Hasher, Value}; use arse_merkle_tree::{Key as TreeKey, H256}; -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; +use borsh_ext::BorshSerializeExt; use ics23::commitment_proof::Proof as Ics23Proof; use ics23::{CommitmentProof, ExistenceProof}; use sha2::{Digest, Sha256}; @@ -199,7 +200,7 @@ impl<'a> SubTreeRead for &'a BridgePoolTree { fn subtree_get(&self, key: &Key) -> Result, Error> { match self.get(key) { - Ok(height) => Ok(height.try_to_vec().expect("Encoding failed")), + Ok(height) => Ok(height.serialize_to_vec()), Err(err) => Err(Error::MerkleTree(err.to_string())), } } diff --git a/core/src/ledger/storage/wl_storage.rs b/core/src/ledger/storage/wl_storage.rs index 87107a35c9..e55f9be033 100644 --- a/core/src/ledger/storage/wl_storage.rs +++ b/core/src/ledger/storage/wl_storage.rs @@ -504,7 +504,8 @@ where mod tests { use std::collections::BTreeMap; - use borsh::{BorshDeserialize, BorshSerialize}; + use borsh::BorshDeserialize; + use borsh_ext::BorshSerializeExt; use proptest::prelude::*; use proptest::test_runner::Config; // Use `RUST_LOG=info` (or another tracing level) and `--nocapture` to @@ -638,16 +639,16 @@ mod tests { | Level::BlockWriteLog(WlMod::Delete | WlMod::DeletePrefix) => { } Level::TxWriteLog(WlMod::Write(val)) => { - s.write_log.write(key, val.try_to_vec().unwrap()).unwrap(); + s.write_log.write(key, val.serialize_to_vec()).unwrap(); } Level::BlockWriteLog(WlMod::Write(val)) => { s.write_log // protocol only writes at block level - .protocol_write(key, val.try_to_vec().unwrap()) + .protocol_write(key, val.serialize_to_vec()) .unwrap(); } Level::Storage(val) => { - s.storage.write(key, val.try_to_vec().unwrap()).unwrap(); + s.storage.write(key, val.serialize_to_vec()).unwrap(); } } } diff --git a/core/src/ledger/storage_api/mod.rs b/core/src/ledger/storage_api/mod.rs index 1108c44e3d..3ec75843b1 100644 --- a/core/src/ledger/storage_api/mod.rs +++ b/core/src/ledger/storage_api/mod.rs @@ -11,6 +11,7 @@ pub mod token; pub mod validation; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; pub use error::{CustomError, Error, OptionExt, Result, ResultExt}; use crate::types::address::Address; @@ -109,7 +110,7 @@ pub trait StorageWrite { key: &storage::Key, val: T, ) -> Result<()> { - let bytes = val.try_to_vec().into_storage_result()?; + let bytes = val.serialize_to_vec(); self.write_bytes(key, bytes) } diff --git a/core/src/proto/types.rs b/core/src/proto/types.rs index a6082fbbab..186fe4eaf6 100644 --- a/core/src/proto/types.rs +++ b/core/src/proto/types.rs @@ -3,14 +3,17 @@ use std::cmp::Ordering; use std::collections::{BTreeMap, HashMap, HashSet}; use std::convert::TryFrom; use std::hash::{Hash, Hasher}; +#[cfg(feature = "ferveo-tpke")] +use std::io::Read; use std::marker::PhantomData; #[cfg(feature = "ferveo-tpke")] use ark_ec::AffineCurve; #[cfg(feature = "ferveo-tpke")] use ark_ec::PairingEngine; -use borsh::schema::{Declaration, Definition}; +use borsh::schema::{add_definition, Declaration, Definition}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXUPPER; use masp_primitives::transaction::builder::Builder; use masp_primitives::transaction::components::sapling::builder::SaplingMetadata; @@ -129,8 +132,7 @@ impl Signable for SerializeWithBorsh { type Output = Vec; fn as_signable(data: &T) -> Vec { - data.try_to_vec() - .expect("Encoding data for signing shouldn't fail") + data.serialize_to_vec() } } @@ -183,17 +185,22 @@ impl PartialOrd for Signed { self.data.partial_cmp(&other.data) } } +impl Ord for Signed { + fn cmp(&self, other: &Self) -> Ordering { + self.data.cmp(&other.data) + } +} impl BorshSchema for Signed { fn add_definitions_recursively( - definitions: &mut HashMap, + definitions: &mut BTreeMap, ) { - let fields = borsh::schema::Fields::NamedFields(borsh::maybestd::vec![ + let fields = borsh::schema::Fields::NamedFields(vec![ ("data".to_string(), T::declaration()), - ("sig".to_string(), ::declaration()) + ("sig".to_string(), ::declaration()), ]); let definition = borsh::schema::Definition::Struct { fields }; - Self::add_definition(Self::declaration(), definition, definitions); + add_definition(Self::declaration(), definition, definitions); T::add_definitions_recursively(definitions); ::add_definitions_recursively(definitions); } @@ -265,9 +272,7 @@ impl Data { /// Hash this data section pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { - hasher.update( - self.try_to_vec().expect("unable to serialize data section"), - ); + hasher.update(self.serialize_to_vec()); hasher } } @@ -410,8 +415,7 @@ impl SignatureIndex { } pub fn serialize(&self) -> String { - let signature_bytes = - self.try_to_vec().expect("Signature should be serializable"); + let signature_bytes = self.serialize_to_vec(); HEXUPPER.encode(&signature_bytes) } @@ -524,10 +528,7 @@ impl Signature { /// Hash this signature section pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { - hasher.update( - self.try_to_vec() - .expect("unable to serialize multisignature section"), - ); + hasher.update(self.serialize_to_vec()); hasher } @@ -663,8 +664,7 @@ impl Ciphertext { #[cfg(feature = "ferveo-tpke")] pub fn new(sections: Vec
, pubkey: &EncryptionKey) -> Self { let mut rng = rand::thread_rng(); - let bytes = - sections.try_to_vec().expect("unable to serialize sections"); + let bytes = sections.serialize_to_vec(); Self { ciphertext: tpke::encrypt(&bytes, pubkey.0, &mut rng), } @@ -683,9 +683,7 @@ impl Ciphertext { /// Get the hash of this ciphertext section. This operation is done in such /// a way it matches the hash of the type pun pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { - hasher.update( - self.try_to_vec().expect("unable to serialize decrypted tx"), - ); + hasher.update(self.serialize_to_vec()); hasher } } @@ -725,34 +723,42 @@ impl borsh::ser::BorshSerialize for Ciphertext { #[cfg(feature = "ferveo-tpke")] impl borsh::BorshDeserialize for Ciphertext { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { - type VecTuple = (u32, Vec, Vec, Vec); - let (_length, nonce, ciphertext, auth_tag): VecTuple = - BorshDeserialize::deserialize(buf)?; - Ok(Self { - ciphertext: tpke::Ciphertext { - nonce: ark_serialize::CanonicalDeserialize::deserialize( - &*nonce, - ) - .map_err(|err| { - std::io::Error::new(std::io::ErrorKind::InvalidData, err) - })?, - ciphertext, - auth_tag: ark_serialize::CanonicalDeserialize::deserialize( - &*auth_tag, - ) - .map_err(|err| { - std::io::Error::new(std::io::ErrorKind::InvalidData, err) - })?, - }, - }) + fn deserialize_reader(reader: &mut R) -> std::io::Result { + { + type VecTuple = (u32, Vec, Vec, Vec); + let (_length, nonce, ciphertext, auth_tag): VecTuple = + BorshDeserialize::deserialize_reader(reader)?; + Ok(Self { + ciphertext: tpke::Ciphertext { + nonce: ark_serialize::CanonicalDeserialize::deserialize( + &*nonce, + ) + .map_err(|err| { + std::io::Error::new( + std::io::ErrorKind::InvalidData, + err, + ) + })?, + ciphertext, + auth_tag: ark_serialize::CanonicalDeserialize::deserialize( + &*auth_tag, + ) + .map_err(|err| { + std::io::Error::new( + std::io::ErrorKind::InvalidData, + err, + ) + })?, + }, + }) + } } } #[cfg(feature = "ferveo-tpke")] impl borsh::BorshSchema for Ciphertext { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, @@ -785,9 +791,7 @@ struct SerializedCiphertext { impl From for SerializedCiphertext { fn from(tx: Ciphertext) -> Self { SerializedCiphertext { - payload: tx - .try_to_vec() - .expect("Unable to serialize encrypted transaction"), + payload: tx.serialize_to_vec(), } } } @@ -824,7 +828,7 @@ where T: From>, T: serde::Serialize, { - Into::::into(obj.try_to_vec().unwrap()).serialize(ser) + Into::::into(obj.serialize_to_vec()).serialize(ser) } fn serde_borsh<'de, T, S, U>(ser: S) -> std::result::Result @@ -901,16 +905,14 @@ impl MaspBuilder { /// Get the hash of this ciphertext section. This operation is done in such /// a way it matches the hash of the type pun pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { - hasher.update( - self.try_to_vec().expect("unable to serialize MASP builder"), - ); + hasher.update(self.serialize_to_vec()); hasher } } impl borsh::BorshSchema for MaspBuilder { fn add_definitions_recursively( - _definitions: &mut std::collections::HashMap< + _definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, @@ -962,8 +964,7 @@ impl Section { /// allowing transaction sections to cross reference. pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { // Get the index corresponding to this variant - let discriminant = - self.try_to_vec().expect("sections should serialize")[0]; + let discriminant = self.serialize_to_vec()[0]; // Use Borsh's discriminant in the Section's hash hasher.update([discriminant]); match self { @@ -1111,10 +1112,7 @@ impl Header { /// Get the hash of this transaction header. pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { - hasher.update( - self.try_to_vec() - .expect("unable to serialize transaction header"), - ); + hasher.update(self.serialize_to_vec()); hasher } @@ -1221,9 +1219,7 @@ impl Tx { /// Serialize tx to hex string pub fn serialize(&self) -> String { - let tx_bytes = self - .try_to_vec() - .expect("Transation should be serializable"); + let tx_bytes = self.serialize_to_vec(); HEXUPPER.encode(&tx_bytes) } @@ -1351,7 +1347,7 @@ impl Tx { pub fn to_bytes(&self) -> Vec { let mut bytes = vec![]; let tx: types::Tx = types::Tx { - data: self.try_to_vec().expect("encoding a transaction failed"), + data: self.serialize_to_vec(), }; tx.encode(&mut bytes) .expect("encoding a transaction failed"); @@ -1716,7 +1712,7 @@ impl Tx { /// Add wasm data to the tx builder pub fn add_data(&mut self, data: impl BorshSerialize) -> &mut Self { - let bytes = data.try_to_vec().expect("Encoding tx data shouldn't fail"); + let bytes = data.serialize_to_vec(); self.set_data(Data::new(bytes)); self } @@ -1987,16 +1983,13 @@ mod tests { // check that encryption doesn't do trivial things assert_ne!( encrypted.ciphertext.ciphertext, - plaintext.try_to_vec().expect("Test failed") + plaintext.serialize_to_vec() ); // decrypt the payload and check we got original data back let decrypted = encrypted.decrypt(privkey); assert_eq!( - decrypted - .expect("Test failed") - .try_to_vec() - .expect("Test failed"), - plaintext.try_to_vec().expect("Test failed"), + decrypted.expect("Test failed").serialize_to_vec(), + plaintext.serialize_to_vec(), ); } @@ -2014,7 +2007,7 @@ mod tests { ))]; let encrypted = Ciphertext::new(plaintext.clone(), &pubkey); // serialize via Borsh - let borsh = encrypted.try_to_vec().expect("Test failed"); + let borsh = encrypted.serialize_to_vec(); // deserialize again let new_encrypted: Ciphertext = BorshDeserialize::deserialize(&mut borsh.as_ref()) @@ -2022,11 +2015,8 @@ mod tests { // check that decryption works as expected let decrypted = new_encrypted.decrypt(privkey); assert_eq!( - decrypted - .expect("Test failed") - .try_to_vec() - .expect("Test failed"), - plaintext.try_to_vec().expect("Test failed"), + decrypted.expect("Test failed").serialize_to_vec(), + plaintext.serialize_to_vec(), ); } @@ -2051,11 +2041,8 @@ mod tests { let decrypted = new_encrypted.decrypt(privkey); // check that decryption works as expected assert_eq!( - decrypted - .expect("Test failed") - .try_to_vec() - .expect("Test failed"), - plaintext.try_to_vec().expect("Test failed"), + decrypted.expect("Test failed").serialize_to_vec(), + plaintext.serialize_to_vec(), ); } } diff --git a/core/src/types/address.rs b/core/src/types/address.rs index 416b3f059e..2605168aad 100644 --- a/core/src/types/address.rs +++ b/core/src/types/address.rs @@ -9,6 +9,7 @@ use std::str::FromStr; use bech32::{self, FromBase32, ToBase32, Variant}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXUPPER; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; @@ -494,9 +495,7 @@ impl EstablishedAddressGen { &mut self, rng_source: impl AsRef<[u8]>, ) -> Address { - let gen_bytes = self - .try_to_vec() - .expect("Encoding established addresses generator shouldn't fail"); + let gen_bytes = self.serialize_to_vec(); let bytes = [&gen_bytes, rng_source.as_ref()].concat(); let full_hash = Sha256::digest(&bytes); // take first 20 bytes of the hash @@ -753,7 +752,7 @@ pub mod tests { #[test] fn test_established_address_bytes_length(address in testing::arb_established_address()) { let address = Address::Established(address); - let bytes = address.try_to_vec().unwrap(); + let bytes = address.serialize_to_vec(); assert_eq!(bytes.len(), ESTABLISHED_ADDRESS_BYTES_LEN); } } diff --git a/core/src/types/chain.rs b/core/src/types/chain.rs index b14fdbbef2..43977d8812 100644 --- a/core/src/types/chain.rs +++ b/core/src/types/chain.rs @@ -95,7 +95,7 @@ impl<'de> Deserialize<'de> for ProposalBytes { impl BorshSchema for ProposalBytes { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut std::collections::BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, diff --git a/core/src/types/eth_bridge_pool.rs b/core/src/types/eth_bridge_pool.rs index 0f1a887345..8e533ea262 100644 --- a/core/src/types/eth_bridge_pool.rs +++ b/core/src/types/eth_bridge_pool.rs @@ -4,6 +4,7 @@ use std::borrow::Cow; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use ethabi::token::Token; use serde::{Deserialize, Serialize}; @@ -68,7 +69,7 @@ pub enum TransferToEthereumKind { Deserialize, BorshSerialize, BorshDeserialize, - BorshSchema, + /* BorshSchema, */ )] pub struct PendingTransferAppendix<'transfer> { /// The kind of the pending transfer to Ethereum. @@ -105,9 +106,7 @@ impl<'t> From<&'t PendingTransfer> for PendingTransferAppendix<'t> { impl<'transfer> PendingTransferAppendix<'transfer> { /// Calculate the checksum of this [`PendingTransferAppendix`]. pub fn checksum(&self) -> HashDigest { - let serialized = self - .try_to_vec() - .expect("Serializing a PendingTransferAppendix should not fail"); + let serialized = self.serialize_to_vec(); HashDigest::sha256(serialized) } } diff --git a/core/src/types/ethereum_events.rs b/core/src/types/ethereum_events.rs index 8dce0a39a4..2dc3601e5e 100644 --- a/core/src/types/ethereum_events.rs +++ b/core/src/types/ethereum_events.rs @@ -6,6 +6,7 @@ use std::ops::{Add, Sub}; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use ethabi::ethereum_types::{H160, U256 as ethUint}; use ethabi::Token; use eyre::{eyre, Context}; @@ -308,7 +309,7 @@ pub enum EthereumEvent { impl EthereumEvent { /// SHA256 of the Borsh serialization of the [`EthereumEvent`]. pub fn hash(&self) -> Result { - let bytes = self.try_to_vec()?; + let bytes = self.serialize_to_vec(); Ok(Hash::sha256(bytes)) } } diff --git a/core/src/types/ethereum_structs.rs b/core/src/types/ethereum_structs.rs index bccab79d65..f029edc4b6 100644 --- a/core/src/types/ethereum_structs.rs +++ b/core/src/types/ethereum_structs.rs @@ -1,5 +1,6 @@ //! Ethereum bridge struct re-exports and types to do with ethereum. use std::fmt; +use std::io::Read; use std::num::NonZeroU64; use std::ops::{Add, AddAssign, Deref}; @@ -96,8 +97,8 @@ impl BorshSerialize for BlockHeight { } impl BorshDeserialize for BlockHeight { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { - let be: Vec = BorshDeserialize::deserialize(buf)?; + fn deserialize_reader(reader: &mut R) -> std::io::Result { + let be: Vec = BorshDeserialize::deserialize_reader(reader)?; Ok(Self(Uint256::from_bytes_be(&be))) } } diff --git a/core/src/types/key/common.rs b/core/src/types/key/common.rs index b3c4f3a52f..9ca0bdaffc 100644 --- a/core/src/types/key/common.rs +++ b/core/src/types/key/common.rs @@ -5,6 +5,7 @@ use std::fmt::Display; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXLOWER; #[cfg(feature = "rand")] use rand::{CryptoRng, RngCore}; @@ -48,19 +49,19 @@ impl super::PublicKey for PublicKey { pk: &PK, ) -> Result { if PK::TYPE == Self::TYPE { - Self::try_from_slice(pk.try_to_vec().unwrap().as_slice()) + Self::try_from_slice(pk.serialize_to_vec().as_slice()) .map_err(ParsePublicKeyError::InvalidEncoding) } else if PK::TYPE == ed25519::PublicKey::TYPE { Ok(Self::Ed25519( ed25519::PublicKey::try_from_slice( - pk.try_to_vec().unwrap().as_slice(), + pk.serialize_to_vec().as_slice(), ) .map_err(ParsePublicKeyError::InvalidEncoding)?, )) } else if PK::TYPE == secp256k1::PublicKey::TYPE { Ok(Self::Secp256k1( secp256k1::PublicKey::try_from_slice( - pk.try_to_vec().unwrap().as_slice(), + pk.serialize_to_vec().as_slice(), ) .map_err(ParsePublicKeyError::InvalidEncoding)?, )) @@ -72,7 +73,7 @@ impl super::PublicKey for PublicKey { impl Display for PublicKey { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", HEXLOWER.encode(&self.try_to_vec().unwrap())) + write!(f, "{}", HEXLOWER.encode(&self.serialize_to_vec())) } } @@ -174,19 +175,19 @@ impl super::SecretKey for SecretKey { sk: &SK, ) -> Result { if SK::TYPE == Self::TYPE { - Self::try_from_slice(sk.try_to_vec().unwrap().as_ref()) + Self::try_from_slice(sk.serialize_to_vec().as_ref()) .map_err(ParseSecretKeyError::InvalidEncoding) } else if SK::TYPE == ed25519::SecretKey::TYPE { Ok(Self::Ed25519( ed25519::SecretKey::try_from_slice( - sk.try_to_vec().unwrap().as_ref(), + sk.serialize_to_vec().as_ref(), ) .map_err(ParseSecretKeyError::InvalidEncoding)?, )) } else if SK::TYPE == secp256k1::SecretKey::TYPE { Ok(Self::Secp256k1( secp256k1::SecretKey::try_from_slice( - sk.try_to_vec().unwrap().as_ref(), + sk.serialize_to_vec().as_ref(), ) .map_err(ParseSecretKeyError::InvalidEncoding)?, )) @@ -207,7 +208,7 @@ impl RefTo for SecretKey { impl Display for SecretKey { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", HEXLOWER.encode(&self.try_to_vec().unwrap())) + write!(f, "{}", HEXLOWER.encode(&self.serialize_to_vec())) } } @@ -230,6 +231,7 @@ impl FromStr for SecretKey { Eq, PartialEq, PartialOrd, + Ord, Hash, Serialize, Deserialize, @@ -263,19 +265,19 @@ impl super::Signature for Signature { sig: &SIG, ) -> Result { if SIG::TYPE == Self::TYPE { - Self::try_from_slice(sig.try_to_vec().unwrap().as_slice()) + Self::try_from_slice(sig.serialize_to_vec().as_slice()) .map_err(ParseSignatureError::InvalidEncoding) } else if SIG::TYPE == ed25519::Signature::TYPE { Ok(Self::Ed25519( ed25519::Signature::try_from_slice( - sig.try_to_vec().unwrap().as_slice(), + sig.serialize_to_vec().as_slice(), ) .map_err(ParseSignatureError::InvalidEncoding)?, )) } else if SIG::TYPE == secp256k1::Signature::TYPE { Ok(Self::Secp256k1( secp256k1::Signature::try_from_slice( - sig.try_to_vec().unwrap().as_slice(), + sig.serialize_to_vec().as_slice(), ) .map_err(ParseSignatureError::InvalidEncoding)?, )) diff --git a/core/src/types/key/dkg_session_keys.rs b/core/src/types/key/dkg_session_keys.rs index f2cafb639c..ccca82aeba 100644 --- a/core/src/types/key/dkg_session_keys.rs +++ b/core/src/types/key/dkg_session_keys.rs @@ -1,12 +1,14 @@ //! Utilities around the DKG session keys use std::cmp::Ordering; +use std::collections::BTreeMap; use std::fmt::Display; -use std::io::{Error, ErrorKind}; +use std::io::{Error, ErrorKind, Read}; use std::str::FromStr; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXLOWER; use serde::{Deserialize, Serialize}; @@ -51,8 +53,8 @@ impl BorshSerialize for DkgKeypair { } impl BorshDeserialize for DkgKeypair { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { - let kp_bytes: Vec = BorshDeserialize::deserialize(buf)?; + fn deserialize_reader(reader: &mut R) -> std::io::Result { + let kp_bytes: Vec = BorshDeserialize::deserialize_reader(reader)?; let kp: ferveo_common::Keypair = CanonicalDeserialize::deserialize(kp_bytes.as_slice()) .map_err(|err| Error::new(ErrorKind::InvalidInput, err))?; @@ -111,8 +113,8 @@ impl BorshSerialize for DkgPublicKey { } impl BorshDeserialize for DkgPublicKey { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { - let pk_bytes: Vec = BorshDeserialize::deserialize(buf)?; + fn deserialize_reader(reader: &mut R) -> std::io::Result { + let pk_bytes: Vec = BorshDeserialize::deserialize_reader(reader)?; let pk: ferveo_common::PublicKey = CanonicalDeserialize::deserialize(pk_bytes.as_slice()) .map_err(|err| Error::new(ErrorKind::InvalidInput, err))?; @@ -122,7 +124,7 @@ impl BorshDeserialize for DkgPublicKey { impl BorshSchema for DkgPublicKey { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, @@ -140,9 +142,7 @@ impl BorshSchema for DkgPublicKey { impl Display for DkgPublicKey { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let vec = self - .try_to_vec() - .expect("Encoding public key shouldn't fail"); + let vec = self.serialize_to_vec(); write!(f, "{}", HEXLOWER.encode(&vec)) } } diff --git a/core/src/types/key/ed25519.rs b/core/src/types/key/ed25519.rs index 12863cca09..48460a2d2f 100644 --- a/core/src/types/key/ed25519.rs +++ b/core/src/types/key/ed25519.rs @@ -1,11 +1,14 @@ //! Ed25519 keys and related functionality +use std::cmp::Ordering; +use std::collections::BTreeMap; use std::fmt::{Debug, Display}; use std::hash::{Hash, Hasher}; -use std::io::Write; +use std::io::{Read, Write}; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXLOWER; #[cfg(feature = "rand")] use rand::{CryptoRng, RngCore}; @@ -38,7 +41,7 @@ impl super::PublicKey for PublicKey { _ => Err(ParsePublicKeyError::MismatchedScheme), }) } else if PK::TYPE == Self::TYPE { - Self::try_from_slice(pk.try_to_vec().unwrap().as_slice()) + Self::try_from_slice(pk.serialize_to_vec().as_slice()) .map_err(ParsePublicKeyError::InvalidEncoding) } else { Err(ParsePublicKeyError::MismatchedScheme) @@ -47,17 +50,17 @@ impl super::PublicKey for PublicKey { } impl BorshDeserialize for PublicKey { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { + fn deserialize_reader(reader: &mut R) -> std::io::Result { Ok(PublicKey( ed25519_consensus::VerificationKey::try_from( - <[u8; PUBLIC_KEY_LENGTH] as BorshDeserialize>::deserialize( - buf, + <[u8; PUBLIC_KEY_LENGTH] as BorshDeserialize>::deserialize_reader( + reader, )? - .as_ref(), + .as_ref(), ) - .map_err(|e| { - std::io::Error::new(std::io::ErrorKind::InvalidInput, e) - })?, + .map_err(|e| { + std::io::Error::new(std::io::ErrorKind::InvalidInput, e) + })?, )) } } @@ -70,7 +73,7 @@ impl BorshSerialize for PublicKey { impl BorshSchema for PublicKey { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, @@ -142,7 +145,7 @@ impl super::SecretKey for SecretKey { _ => Err(ParseSecretKeyError::MismatchedScheme), }) } else if PK::TYPE == Self::TYPE { - Self::try_from_slice(pk.try_to_vec().unwrap().as_slice()) + Self::try_from_slice(pk.serialize_to_vec().as_slice()) .map_err(ParseSecretKeyError::InvalidEncoding) } else { Err(ParseSecretKeyError::MismatchedScheme) @@ -165,17 +168,17 @@ impl Clone for SecretKey { } impl BorshDeserialize for SecretKey { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { + fn deserialize_reader(reader: &mut R) -> std::io::Result { Ok(SecretKey(Box::new( ed25519_consensus::SigningKey::try_from( - <[u8; SECRET_KEY_LENGTH] as BorshDeserialize>::deserialize( - buf, + <[u8; SECRET_KEY_LENGTH] as BorshDeserialize>::deserialize_reader( + reader, )? - .as_ref(), + .as_ref(), ) - .map_err(|e| { - std::io::Error::new(std::io::ErrorKind::InvalidInput, e) - })?, + .map_err(|e| { + std::io::Error::new(std::io::ErrorKind::InvalidInput, e) + })?, ))) } } @@ -188,7 +191,7 @@ impl BorshSerialize for SecretKey { impl BorshSchema for SecretKey { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, @@ -239,7 +242,7 @@ impl super::Signature for Signature { _ => Err(ParseSignatureError::MismatchedScheme), }) } else if PK::TYPE == Self::TYPE { - Self::try_from_slice(pk.try_to_vec().unwrap().as_slice()) + Self::try_from_slice(pk.serialize_to_vec().as_slice()) .map_err(ParseSignatureError::InvalidEncoding) } else { Err(ParseSignatureError::MismatchedScheme) @@ -248,10 +251,10 @@ impl super::Signature for Signature { } impl BorshDeserialize for Signature { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { + fn deserialize_reader(reader: &mut R) -> std::io::Result { Ok(Signature( ed25519_consensus::Signature::try_from( - <[u8; SIGNATURE_LENGTH] as BorshDeserialize>::deserialize(buf)? + <[u8; SIGNATURE_LENGTH] as BorshDeserialize>::deserialize_reader(reader)? .as_ref(), ) .map_err(|e| { @@ -269,7 +272,7 @@ impl BorshSerialize for Signature { impl BorshSchema for Signature { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, @@ -299,6 +302,12 @@ impl PartialOrd for Signature { } } +impl Ord for Signature { + fn cmp(&self, other: &Self) -> Ordering { + self.0.to_bytes().cmp(&other.0.to_bytes()) + } +} + /// An implementation of the Ed25519 signature scheme #[derive( Debug, diff --git a/core/src/types/key/mod.rs b/core/src/types/key/mod.rs index e6e52f108b..15b1380e2c 100644 --- a/core/src/types/key/mod.rs +++ b/core/src/types/key/mod.rs @@ -11,6 +11,7 @@ use std::hash::Hash; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXUPPER; use lazy_map::LazyMap; use namada_macros::StorageKeys; @@ -211,7 +212,7 @@ pub trait Signature: sig: &SIG, ) -> Result { if SIG::TYPE == Self::TYPE { - let sig_arr = sig.try_to_vec().unwrap(); + let sig_arr = sig.serialize_to_vec(); let res = Self::try_from_slice(sig_arr.as_ref()); res.map_err(ParseSignatureError::InvalidEncoding) } else { @@ -247,7 +248,7 @@ pub trait PublicKey: pk: &PK, ) -> Result { if Self::TYPE == PK::TYPE { - let pk_arr = pk.try_to_vec().unwrap(); + let pk_arr = pk.serialize_to_vec(); let res = Self::try_from_slice(pk_arr.as_ref()); res.map_err(ParsePublicKeyError::InvalidEncoding) } else { @@ -283,7 +284,7 @@ pub trait SecretKey: sk: &SK, ) -> Result { if SK::TYPE == Self::TYPE { - let sk_vec = sk.try_to_vec().unwrap(); + let sk_vec = sk.serialize_to_vec(); let res = Self::try_from_slice(sk_vec.as_ref()); res.map_err(ParseSecretKeyError::InvalidEncoding) } else { @@ -440,8 +441,7 @@ pub enum PkhFromStringError { impl From<&PK> for PublicKeyHash { fn from(pk: &PK) -> Self { - let pk_bytes = - pk.try_to_vec().expect("Public key encoding shouldn't fail"); + let pk_bytes = pk.serialize_to_vec(); let full_hash = Sha256::digest(&pk_bytes); // take first 20 bytes of the hash let mut hash: [u8; PKH_LEN] = Default::default(); @@ -630,10 +630,7 @@ macro_rules! sigscheme_test { let mut rng: ThreadRng = thread_rng(); let keypair = <$type>::generate(&mut rng); - println!( - "keypair {:?}", - keypair.try_to_vec().unwrap().as_slice() - ); + println!("keypair {:?}", keypair.serialize_to_vec().as_slice()); } /// Run `cargo test gen_keypair -- --nocapture` to generate a /// new keypair. diff --git a/core/src/types/key/secp256k1.rs b/core/src/types/key/secp256k1.rs index e65ae7fcbd..7d823d5305 100644 --- a/core/src/types/key/secp256k1.rs +++ b/core/src/types/key/secp256k1.rs @@ -1,13 +1,15 @@ //! secp256k1 keys and related functionality use std::cmp::Ordering; +use std::collections::BTreeMap; use std::fmt; use std::fmt::{Debug, Display}; use std::hash::{Hash, Hasher}; -use std::io::{ErrorKind, Write}; +use std::io::{ErrorKind, Read, Write}; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXLOWER; use ethabi::Token; use k256::ecdsa::RecoveryId; @@ -52,7 +54,7 @@ impl super::PublicKey for PublicKey { _ => Err(ParsePublicKeyError::MismatchedScheme), }) } else if PK::TYPE == Self::TYPE { - Self::try_from_slice(pk.try_to_vec().unwrap().as_slice()) + Self::try_from_slice(pk.serialize_to_vec().as_slice()) .map_err(ParsePublicKeyError::InvalidEncoding) } else { Err(ParsePublicKeyError::MismatchedScheme) @@ -61,18 +63,16 @@ impl super::PublicKey for PublicKey { } impl BorshDeserialize for PublicKey { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { + fn deserialize_reader(reader: &mut R) -> std::io::Result { // deserialize the bytes first - let bytes = buf - .get(0..COMPRESSED_PUBLIC_KEY_SIZE) - .ok_or_else(|| std::io::Error::from(ErrorKind::UnexpectedEof))?; - let pk = k256::PublicKey::from_sec1_bytes(bytes).map_err(|e| { + let mut key_buf = [0u8; COMPRESSED_PUBLIC_KEY_SIZE]; + reader.read_exact(&mut key_buf[..])?; + let pk = k256::PublicKey::from_sec1_bytes(&key_buf).map_err(|e| { std::io::Error::new( ErrorKind::InvalidInput, format!("Error decoding secp256k1 public key: {}", e), ) })?; - *buf = &buf[COMPRESSED_PUBLIC_KEY_SIZE..]; Ok(PublicKey(pk)) } } @@ -86,7 +86,7 @@ impl BorshSerialize for PublicKey { impl BorshSchema for PublicKey { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, @@ -179,7 +179,7 @@ impl super::SecretKey for SecretKey { _ => Err(ParseSecretKeyError::MismatchedScheme), }) } else if PK::TYPE == Self::TYPE { - Self::try_from_slice(pk.try_to_vec().unwrap().as_slice()) + Self::try_from_slice(pk.serialize_to_vec().as_slice()) .map_err(ParseSecretKeyError::InvalidEncoding) } else { Err(ParseSecretKeyError::MismatchedScheme) @@ -211,9 +211,10 @@ impl<'de> Deserialize<'de> for SecretKey { } impl BorshDeserialize for SecretKey { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { + fn deserialize_reader(reader: &mut R) -> std::io::Result { // deserialize the bytes first - let bytes: [u8; SECRET_KEY_SIZE] = BorshDeserialize::deserialize(buf)?; + let bytes: [u8; SECRET_KEY_SIZE] = + BorshDeserialize::deserialize_reader(reader)?; let sk = k256::SecretKey::from_slice(&bytes).map_err(|e| { std::io::Error::new( ErrorKind::InvalidInput, @@ -233,7 +234,7 @@ impl BorshSerialize for SecretKey { impl BorshSchema for SecretKey { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, @@ -290,7 +291,7 @@ impl super::Signature for Signature { _ => Err(ParseSignatureError::MismatchedScheme), }) } else if PK::TYPE == Self::TYPE { - Self::try_from_slice(pk.try_to_vec().unwrap().as_slice()) + Self::try_from_slice(pk.serialize_to_vec().as_slice()) .map_err(ParseSignatureError::InvalidEncoding) } else { Err(ParseSignatureError::MismatchedScheme) @@ -367,10 +368,10 @@ impl<'de> Deserialize<'de> for Signature { } impl BorshDeserialize for Signature { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { + fn deserialize_reader(reader: &mut R) -> std::io::Result { // deserialize the bytes first let (sig_bytes, recovery_id): ([u8; 64], u8) = - BorshDeserialize::deserialize(buf)?; + BorshDeserialize::deserialize_reader(reader)?; Ok(Signature( k256::ecdsa::Signature::from_slice(&sig_bytes).map_err(|e| { @@ -398,7 +399,7 @@ impl BorshSerialize for Signature { impl BorshSchema for Signature { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, @@ -640,7 +641,7 @@ mod test { let to_sign = "test".as_bytes(); let mut signature = SigScheme::sign(&sk, to_sign); signature.1 = RecoveryId::from_byte(3).expect("Test failed"); - let sig_bytes = signature.try_to_vec().expect("Test failed"); + let sig_bytes = signature.serialize_to_vec(); let sig = Signature::try_from_slice(sig_bytes.as_slice()) .expect("Test failed"); assert_eq!(sig, signature); diff --git a/core/src/types/masp.rs b/core/src/types/masp.rs index e5ad0202b1..9083852a81 100644 --- a/core/src/types/masp.rs +++ b/core/src/types/masp.rs @@ -6,6 +6,7 @@ use std::str::FromStr; use bech32::{FromBase32, ToBase32}; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use sha2::{Digest, Sha256}; use crate::types::address::{ @@ -147,9 +148,7 @@ impl PaymentAddress { /// Hash this payment address pub fn hash(&self) -> String { - let bytes = (self.0, self.1) - .try_to_vec() - .expect("Payment address encoding shouldn't fail"); + let bytes = (self.0, self.1).serialize_to_vec(); let mut hasher = Sha256::new(); hasher.update(bytes); // hex of the first 40 chars of the hash diff --git a/core/src/types/storage.rs b/core/src/types/storage.rs index ad0c14f499..b4c6a595dd 100644 --- a/core/src/types/storage.rs +++ b/core/src/types/storage.rs @@ -2,13 +2,14 @@ use std::collections::VecDeque; use std::convert::{TryFrom, TryInto}; use std::fmt::Display; -use std::io::Write; +use std::io::{Read, Write}; use std::num::ParseIntError; use std::ops::{Add, AddAssign, Deref, Div, Drop, Mul, Rem, Sub}; use std::str::FromStr; use arse_merkle_tree::InternalKey; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use data_encoding::{BASE32HEX_NOPAD, HEXUPPER}; use ics23::CommitmentProof; use index_set::vec::VecIndexSet; @@ -320,7 +321,7 @@ pub struct Header { impl Header { /// The number of bytes when this header is encoded pub fn encoded_len(&self) -> usize { - self.try_to_vec().unwrap().len() + self.serialize_to_vec().len() } } @@ -404,13 +405,13 @@ impl BorshSerialize for StringKey { } impl BorshDeserialize for StringKey { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { + fn deserialize_reader(reader: &mut R) -> std::io::Result { use std::io::ErrorKind; let (original, tree_key, length): ( Vec, InternalKey, usize, - ) = BorshDeserialize::deserialize(buf)?; + ) = BorshDeserialize::deserialize_reader(reader)?; let original: [u8; IBC_KEY_LIMIT] = original.try_into().map_err(|_| { std::io::Error::new( diff --git a/core/src/types/time.rs b/core/src/types/time.rs index 0670392f94..341a81411c 100644 --- a/core/src/types/time.rs +++ b/core/src/types/time.rs @@ -1,7 +1,9 @@ //! Types for dealing with time and durations. +use std::collections::BTreeMap; use std::convert::{TryFrom, TryInto}; use std::fmt::Display; +use std::io::Read; use std::ops::{Add, Sub}; use std::str::FromStr; @@ -183,9 +185,9 @@ impl BorshSerialize for DateTimeUtc { } impl BorshDeserialize for DateTimeUtc { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { + fn deserialize_reader(reader: &mut R) -> std::io::Result { use std::io::{Error, ErrorKind}; - let raw: String = BorshDeserialize::deserialize(buf)?; + let raw: String = BorshDeserialize::deserialize_reader(reader)?; let actual = DateTime::parse_from_rfc3339(&raw) .map_err(|err| Error::new(ErrorKind::InvalidData, err))?; Ok(Self(actual.into())) @@ -194,7 +196,7 @@ impl BorshDeserialize for DateTimeUtc { impl BorshSchema for DateTimeUtc { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, diff --git a/core/src/types/token.rs b/core/src/types/token.rs index 0ee60b4326..289602ae23 100644 --- a/core/src/types/token.rs +++ b/core/src/types/token.rs @@ -749,6 +749,7 @@ impl From for Uint { )] #[repr(u8)] #[allow(missing_docs)] +#[borsh(use_discriminant = true)] pub enum MaspDenom { Zero = 0, One, diff --git a/core/src/types/transaction/decrypted.rs b/core/src/types/transaction/decrypted.rs index bbebc85e77..3a7ba2f335 100644 --- a/core/src/types/transaction/decrypted.rs +++ b/core/src/types/transaction/decrypted.rs @@ -7,6 +7,7 @@ pub mod decrypted_tx { #[cfg(feature = "ferveo-tpke")] use ark_ec::PairingEngine; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; + use borsh_ext::BorshSerializeExt; use sha2::{Digest, Sha256}; #[derive( @@ -32,9 +33,7 @@ pub mod decrypted_tx { impl DecryptedTx { /// Produce a SHA-256 hash of this header pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { - hasher.update( - self.try_to_vec().expect("unable to serialize decrypted tx"), - ); + hasher.update(self.serialize_to_vec()); hasher } } diff --git a/core/src/types/transaction/encrypted.rs b/core/src/types/transaction/encrypted.rs index 277ec6d3fd..8b547fea88 100644 --- a/core/src/types/transaction/encrypted.rs +++ b/core/src/types/transaction/encrypted.rs @@ -3,7 +3,7 @@ /// *Not wasm compatible* #[cfg(feature = "ferveo-tpke")] pub mod encrypted_tx { - use std::io::{Error, ErrorKind, Write}; + use std::io::{Error, ErrorKind, Read, Write}; use ark_ec::PairingEngine; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; @@ -32,8 +32,10 @@ pub mod encrypted_tx { } impl borsh::de::BorshDeserialize for EncryptionKey { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { - let key: Vec = BorshDeserialize::deserialize(buf)?; + fn deserialize_reader( + reader: &mut R, + ) -> std::io::Result { + let key: Vec = BorshDeserialize::deserialize_reader(reader)?; Ok(EncryptionKey( CanonicalDeserialize::deserialize(&*key) .map_err(|err| Error::new(ErrorKind::InvalidData, err))?, diff --git a/core/src/types/transaction/mod.rs b/core/src/types/transaction/mod.rs index 8acb9e6c7e..895f1c43fd 100644 --- a/core/src/types/transaction/mod.rs +++ b/core/src/types/transaction/mod.rs @@ -22,6 +22,7 @@ use std::collections::BTreeSet; use std::fmt; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use borsh_ext::BorshSerializeExt; pub use decrypted::*; #[cfg(feature = "ferveo-tpke")] pub use encrypted::EncryptionKey; @@ -160,7 +161,7 @@ pub enum TxType { impl TxType { /// Produce a SHA-256 hash of this header pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { - hasher.update(self.try_to_vec().expect("unable to serialize header")); + hasher.update(self.serialize_to_vec()); hasher } } diff --git a/core/src/types/transaction/protocol.rs b/core/src/types/transaction/protocol.rs index 1a51434b29..78feafb3bd 100644 --- a/core/src/types/transaction/protocol.rs +++ b/core/src/types/transaction/protocol.rs @@ -24,10 +24,12 @@ pub struct UpdateDkgSessionKey { #[cfg(feature = "ferveo-tpke")] mod protocol_txs { - use std::io::{ErrorKind, Write}; + use std::collections::BTreeMap; + use std::io::{ErrorKind, Read, Write}; use std::path::Path; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; + use borsh_ext::BorshSerializeExt; use ferveo::dkg::pv::Message; use serde_json; @@ -77,9 +79,7 @@ mod protocol_txs { /// Produce a SHA-256 hash of this section pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { - hasher.update( - self.try_to_vec().expect("unable to serialize protocol"), - ); + hasher.update(self.serialize_to_vec()); hasher } } @@ -213,7 +213,7 @@ mod protocol_txs { ( $( $type:ident ),* $(,)?) => { match self { $( EthereumTxData::$type(x) => - x.try_to_vec().map(|data| (data, ProtocolTxType::$type))),* + (x.serialize_to_vec(), ProtocolTxType::$type)),* } } } @@ -225,7 +225,6 @@ mod protocol_txs { BridgePoolVext, ValSetUpdateVext, } - .expect("Should be able to borsh-serialize tx data") } /// Deserialize Ethereum protocol transaction data. @@ -330,10 +329,7 @@ mod protocol_txs { }))); outer_tx.header.chain_id = chain_id; outer_tx.set_code(Code::new(code)); - outer_tx.set_data(Data::new( - data.try_to_vec() - .expect("Serializing request should not fail"), - )); + outer_tx.set_data(Data::new(data.serialize_to_vec())); outer_tx.add_section(Section::Signature(Signature::new( vec![ outer_tx.header_hash(), @@ -375,8 +371,10 @@ mod protocol_txs { } impl BorshDeserialize for DkgMessage { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { - let blob: Vec = BorshDeserialize::deserialize(buf)?; + fn deserialize_reader( + reader: &mut R, + ) -> std::io::Result { + let blob: Vec = BorshDeserialize::deserialize_reader(reader)?; let json = String::from_utf8(blob).map_err(|err| { std::io::Error::new(ErrorKind::InvalidData, err) })?; @@ -389,7 +387,7 @@ mod protocol_txs { impl BorshSchema for DkgMessage { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, diff --git a/core/src/types/transaction/wrapper.rs b/core/src/types/transaction/wrapper.rs index e9b49b0c07..1064833925 100644 --- a/core/src/types/transaction/wrapper.rs +++ b/core/src/types/transaction/wrapper.rs @@ -10,6 +10,7 @@ pub mod wrapper_tx { #[cfg(feature = "ferveo-tpke")] pub use ark_ec::{AffineCurve, PairingEngine}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; + use borsh_ext::BorshSerializeExt; use masp_primitives::transaction::Transaction; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; @@ -225,9 +226,7 @@ pub mod wrapper_tx { /// Produce a SHA-256 hash of this section pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { - hasher.update( - self.try_to_vec().expect("unable to serialize wrapper"), - ); + hasher.update(self.serialize_to_vec()); hasher } @@ -305,12 +304,7 @@ pub mod wrapper_tx { key: None, shielded: Some(masp_hash), }; - let data = transfer.try_to_vec().map_err(|_| { - WrapperTxErr::InvalidUnshield( - "Error while serializing the unshield transfer data" - .to_string(), - ) - })?; + let data = transfer.serialize_to_vec(); tx.set_data(Data::new(data)); tx.set_code(Code::from_hash(transfer_code_hash)); @@ -349,7 +343,7 @@ pub mod wrapper_tx { ); // Test borsh roundtrip - let borsh = limit.try_to_vec().expect("Test failed"); + let borsh = limit.serialize_to_vec(); assert_eq!( limit, BorshDeserialize::deserialize(&mut borsh.as_ref()) diff --git a/core/src/types/vote_extensions/bridge_pool_roots.rs b/core/src/types/vote_extensions/bridge_pool_roots.rs index 5670d3967c..22718521f3 100644 --- a/core/src/types/vote_extensions/bridge_pool_roots.rs +++ b/core/src/types/vote_extensions/bridge_pool_roots.rs @@ -21,6 +21,7 @@ use crate::types::storage::BlockHeight; Clone, PartialEq, PartialOrd, + Ord, Eq, Hash, BorshSerialize, diff --git a/core/src/types/voting_power.rs b/core/src/types/voting_power.rs index a28eedc1a4..292fadb6f9 100644 --- a/core/src/types/voting_power.rs +++ b/core/src/types/voting_power.rs @@ -1,6 +1,8 @@ //! This module contains types related with validator voting power calculations. +use std::collections::BTreeMap; use std::fmt::{Display, Formatter}; +use std::io::Read; use std::iter::Sum; use std::ops::{Add, AddAssign, Mul}; @@ -247,26 +249,30 @@ impl BorshSerialize for FractionalVotingPower { } impl BorshDeserialize for FractionalVotingPower { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { - let (numer, denom): (Uint, Uint) = BorshDeserialize::deserialize(buf)?; + fn deserialize_reader(reader: &mut R) -> std::io::Result { + let (numer, denom): (Uint, Uint) = + BorshDeserialize::deserialize_reader(reader)?; Ok(FractionalVotingPower(Ratio::::new(numer, denom))) } } impl BorshSchema for FractionalVotingPower { fn add_definitions_recursively( - definitions: &mut std::collections::HashMap< + definitions: &mut BTreeMap< borsh::schema::Declaration, borsh::schema::Definition, >, ) { - let fields = - borsh::schema::Fields::UnnamedFields(borsh::maybestd::vec![ - Uint::declaration(), - Uint::declaration() - ]); + let fields = borsh::schema::Fields::UnnamedFields(vec![ + Uint::declaration(), + Uint::declaration(), + ]); let definition = borsh::schema::Definition::Struct { fields }; - Self::add_definition(Self::declaration(), definition, definitions); + borsh::schema::add_definition( + Self::declaration(), + definition, + definitions, + ); } fn declaration() -> borsh::schema::Declaration { diff --git a/encoding_spec/src/main.rs b/encoding_spec/src/main.rs index 5889b03b8d..4365fd4a01 100644 --- a/encoding_spec/src/main.rs +++ b/encoding_spec/src/main.rs @@ -15,10 +15,12 @@ #![deny(rustdoc::broken_intra_doc_links)] #![deny(rustdoc::private_intra_doc_links)] -use std::collections::HashSet; +use std::collections::{BTreeMap, HashSet}; use std::io::Write; +use std::iter::Extend; -use borsh::{schema, BorshSchema}; +use borsh::schema::{BorshSchemaContainer, Declaration, Definition}; +use borsh::{schema, schema_container_of}; use itertools::Itertools; use lazy_static::lazy_static; use madato::types::TableRow; @@ -56,179 +58,188 @@ lazy_static! { ]); } +fn btree(b: &BorshSchemaContainer) -> BTreeMap { + b.definitions() + .map(|(x, y)| (x.clone(), y.clone())) + .collect() +} + fn main() -> Result<(), Box> { let mut file = std::fs::File::create(OUTPUT_PATH).unwrap(); write_generated_code_notice(&mut file)?; // Top-level definitions are displayed at the top - let address_schema = Address::schema_container(); - let token_amount_schema = token::Amount::schema_container(); - let epoch_schema = Epoch::schema_container(); - let parameters_schema = Parameters::schema_container(); + + let address_schema = schema_container_of::
(); + let token_amount_schema = schema_container_of::(); + let epoch_schema = schema_container_of::(); + let parameters_schema = schema_container_of::(); // TODO update after - let public_key_schema = PublicKey::schema_container(); + let public_key_schema = schema_container_of::(); // TODO update after - let signature_schema = Signature::schema_container(); + let signature_schema = schema_container_of::(); let init_account_schema = - transaction::account::InitAccount::schema_container(); + schema_container_of::(); let init_validator_schema = - transaction::pos::InitValidator::schema_container(); - let token_transfer_schema = token::Transfer::schema_container(); + schema_container_of::(); + let token_transfer_schema = schema_container_of::(); let update_account = - transaction::account::UpdateAccount::schema_container(); - let pos_bond_schema = pos::Bond::schema_container(); - let pos_withdraw_schema = pos::Withdraw::schema_container(); - let wrapper_tx_schema = transaction::WrapperTx::schema_container(); + schema_container_of::(); + let pos_bond_schema = schema_container_of::(); + let pos_withdraw_schema = schema_container_of::(); + let wrapper_tx_schema = schema_container_of::(); // TODO derive BorshSchema after - // let tx_result_schema = transaction::TxResult::schema_container(); - let tx_type_schema = transaction::TxType::schema_container(); - let prefix_value_schema = storage::PrefixValue::schema_container(); + // let tx_result_schema = schema_container_of::(); + let tx_type_schema = schema_container_of::(); + let prefix_value_schema = schema_container_of::(); // PoS // TODO add after // TODO imported from `use namada::ledger::pos::Bonds;` - // let pos_bonds_schema = Bonds::schema_container(); + // let pos_bonds_schema = schema_container_of::(); // Merge type definitions - let mut definitions = address_schema.definitions; + + let mut definitions = btree(&address_schema); + // TODO check for conflicts (same name, different declaration) - definitions.extend(token_amount_schema.definitions); - definitions.extend(epoch_schema.definitions); - definitions.extend(parameters_schema.definitions); - definitions.extend(public_key_schema.definitions); - definitions.extend(signature_schema.definitions); - definitions.extend(init_account_schema.definitions); - definitions.extend(init_validator_schema.definitions); - definitions.extend(token_transfer_schema.definitions); - definitions.extend(update_account.definitions); - definitions.extend(pos_bond_schema.definitions); - definitions.extend(pos_withdraw_schema.definitions); - definitions.extend(wrapper_tx_schema.definitions); - // definitions.extend(tx_result_schema.definitions); - definitions.extend(tx_type_schema.definitions); - definitions.extend(prefix_value_schema.definitions); - // definitions.extend(pos_bonds_schema.definitions); + definitions.extend(btree(&token_amount_schema)); + definitions.extend(btree(&epoch_schema)); + definitions.extend(btree(¶meters_schema)); + definitions.extend(btree(&public_key_schema)); + definitions.extend(btree(&signature_schema)); + definitions.extend(btree(&init_account_schema)); + definitions.extend(btree(&init_validator_schema)); + definitions.extend(btree(&token_transfer_schema)); + definitions.extend(btree(&update_account)); + definitions.extend(btree(&pos_bond_schema)); + definitions.extend(btree(&pos_withdraw_schema)); + definitions.extend(btree(&wrapper_tx_schema)); + // definitions.extend(btree(&tx_result_schema)); + definitions.extend(btree(&tx_type_schema)); + definitions.extend(btree(&prefix_value_schema)); + // definitions.extend(btree(&pos_bonds_schema)); let mut tables: Vec = Vec::with_capacity(definitions.len()); // Add the top-level definitions first let address_definition = - definitions.remove(&address_schema.declaration).unwrap(); + definitions.remove(address_schema.declaration()).unwrap(); let address_table = - definition_to_table(address_schema.declaration, address_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/address/enum.Address.html"); + definition_to_table( address_schema.declaration(), address_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/address/enum.Address.html"); tables.push(address_table); let token_amount_definition = definitions - .remove(&token_amount_schema.declaration) + .remove(token_amount_schema.declaration()) .unwrap(); let token_amount_table = definition_to_table( - token_amount_schema.declaration, + token_amount_schema.declaration(), token_amount_definition, ).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/token/struct.Amount.html"); tables.push(token_amount_table); let epoch_definition = - definitions.remove(&epoch_schema.declaration).unwrap(); + definitions.remove(epoch_schema.declaration()).unwrap(); let epoch_table = - definition_to_table(epoch_schema.declaration, epoch_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/storage/struct.Epoch.html"); + definition_to_table(epoch_schema.declaration(), epoch_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/storage/struct.Epoch.html"); tables.push(epoch_table); let parameters_definition = - definitions.remove(¶meters_schema.declaration).unwrap(); + definitions.remove(parameters_schema.declaration()).unwrap(); let parameters_table = - definition_to_table(parameters_schema.declaration, parameters_definition).with_rust_doc_link("file:///Users/tz/dev/namada/target/doc/namada/ledger/parameters/struct.Parameters.html"); + definition_to_table(parameters_schema.declaration(), parameters_definition).with_rust_doc_link("file:///Users/tz/dev/namada/target/doc/namada/ledger/parameters/struct.Parameters.html"); tables.push(parameters_table); let public_key_definition = - definitions.remove(&public_key_schema.declaration).unwrap(); + definitions.remove(public_key_schema.declaration()).unwrap(); let public_key_table = - definition_to_table(public_key_schema.declaration, public_key_definition).with_rust_doc_link( + definition_to_table(public_key_schema.declaration(), public_key_definition).with_rust_doc_link( // TODO update after "https://dev.namada.net/master/rustdoc/namada/types/key/ed25519/struct.PublicKey.html"); tables.push(public_key_table); let signature_definition = - definitions.remove(&signature_schema.declaration).unwrap(); + definitions.remove(signature_schema.declaration()).unwrap(); let signature_table = - definition_to_table(signature_schema.declaration, signature_definition).with_rust_doc_link( + definition_to_table(signature_schema.declaration(), signature_definition).with_rust_doc_link( // TODO update after "https://dev.namada.net/master/rustdoc/namada/types/key/ed25519/struct.Signature.html"); tables.push(signature_table); let init_account_definition = definitions - .remove(&init_account_schema.declaration) + .remove(init_account_schema.declaration()) .unwrap(); let init_account_table = definition_to_table( - init_account_schema.declaration, + init_account_schema.declaration(), init_account_definition, ).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/struct.InitAccount.html"); tables.push(init_account_table); let init_validator_definition = definitions - .remove(&init_validator_schema.declaration) + .remove(init_validator_schema.declaration()) .unwrap(); let init_validator_table = definition_to_table( - init_validator_schema.declaration, + init_validator_schema.declaration(), init_validator_definition, ).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/struct.InitValidator.html"); tables.push(init_validator_table); let token_transfer_definition = definitions - .remove(&token_transfer_schema.declaration) + .remove(token_transfer_schema.declaration()) .unwrap(); let token_transfer_table = definition_to_table( - token_transfer_schema.declaration, + token_transfer_schema.declaration(), token_transfer_definition, ).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/token/struct.Transfer.html"); tables.push(token_transfer_table); let update_account_definition = - definitions.remove(&update_account.declaration).unwrap(); + definitions.remove(update_account.declaration()).unwrap(); let update_accoun_table = - definition_to_table(update_account.declaration, update_account_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/struct.UpdateVp.html"); + definition_to_table(update_account.declaration(), update_account_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/struct.UpdateVp.html"); tables.push(update_accoun_table); let pos_bond_definition = - definitions.remove(&pos_bond_schema.declaration).unwrap(); + definitions.remove(pos_bond_schema.declaration()).unwrap(); let pos_bond_table = - definition_to_table(pos_bond_schema.declaration, pos_bond_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/pos/struct.Bond.html"); + definition_to_table(pos_bond_schema.declaration(), pos_bond_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/pos/struct.Bond.html"); tables.push(pos_bond_table); let pos_withdraw_definition = definitions - .remove(&pos_withdraw_schema.declaration) + .remove(pos_withdraw_schema.declaration()) .unwrap(); let pos_withdraw_table = definition_to_table( - pos_withdraw_schema.declaration, + pos_withdraw_schema.declaration(), pos_withdraw_definition, ).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/pos/struct.Withdraw.html"); tables.push(pos_withdraw_table); let wrapper_tx_definition = - definitions.remove(&wrapper_tx_schema.declaration).unwrap(); + definitions.remove(wrapper_tx_schema.declaration()).unwrap(); let wrapper_tx_table = definition_to_table( - wrapper_tx_schema.declaration, + wrapper_tx_schema.declaration(), wrapper_tx_definition, ).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/wrapper/wrapper_tx/struct.WrapperTx.html"); tables.push(wrapper_tx_table); // let tx_result_definition = - // definitions.remove(&tx_result_schema.declaration).unwrap(); + // definitions.remove(tx_result_schema.declaration()).unwrap(); // let tx_result_table = - // definition_to_table(tx_result_schema.declaration, + // definition_to_table(tx_result_schema.declaration(), // tx_result_definition).with_rust_doc_link("TODO"); // tables.push(tx_result_table); let tx_type_definition = - definitions.remove(&tx_type_schema.declaration).unwrap(); + definitions.remove(tx_type_schema.declaration()).unwrap(); let tx_type_table = - definition_to_table(tx_type_schema.declaration, tx_type_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/tx_types/enum.TxType.html"); + definition_to_table(tx_type_schema.declaration(), tx_type_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/tx_types/enum.TxType.html"); tables.push(tx_type_table); let prefix_value_definition = definitions - .remove(&prefix_value_schema.declaration) + .remove(prefix_value_schema.declaration()) .unwrap(); let prefix_value_table = - definition_to_table(prefix_value_schema.declaration, prefix_value_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/prefix_values/enum.TxType.html"); + definition_to_table(prefix_value_schema.declaration(), prefix_value_definition).with_rust_doc_link("https://dev.namada.net/master/rustdoc/namada/types/transaction/prefix_values/enum.TxType.html"); tables.push(prefix_value_table); // Add PoS definitions @@ -243,7 +254,7 @@ fn main() -> Result<(), Box> { .into_iter() .sorted_by_key(|(key, _val)| key.clone()) { - tables.push(definition_to_table(declaration, defition)) + tables.push(definition_to_table(&declaration, defition)) } // Print the tables to markdown @@ -271,7 +282,7 @@ struct Table { rows: Option>, } -fn definition_to_table(name: String, def: schema::Definition) -> Table { +fn definition_to_table(name: &Declaration, def: schema::Definition) -> Table { let (desc, rows) = match def { schema::Definition::Array { length, elements } => { let rows = None; @@ -345,7 +356,11 @@ fn definition_to_table(name: String, def: schema::Definition) -> Table { } } }; - Table { name, desc, rows } + Table { + name: name.to_string(), + desc, + rows, + } } /// Format a type to markdown. For internal types, adds anchors. diff --git a/ethereum_bridge/Cargo.toml b/ethereum_bridge/Cargo.toml index 85b0959106..40d8e6f422 100644 --- a/ethereum_bridge/Cargo.toml +++ b/ethereum_bridge/Cargo.toml @@ -33,6 +33,7 @@ namada_core = {path = "../core", default-features = false, features = ["ferveo-t namada_macros = {path = "../macros"} namada_proof_of_stake = {path = "../proof_of_stake", default-features = false} borsh.workspace = true +borsh-ext.workspace = true ethers.workspace = true eyre.workspace = true itertools.workspace = true diff --git a/ethereum_bridge/src/parameters.rs b/ethereum_bridge/src/parameters.rs index c86ef1e6ed..599ef0c5f8 100644 --- a/ethereum_bridge/src/parameters.rs +++ b/ethereum_bridge/src/parameters.rs @@ -367,6 +367,7 @@ where #[cfg(test)] mod tests { + use borsh_ext::BorshSerializeExt; use eyre::Result; use namada_core::ledger::storage::testing::TestWlStorage; use namada_core::types::ethereum_events::EthAddress; @@ -474,7 +475,7 @@ mod tests { wl_storage .write_bytes( &bridge_storage::min_confirmations_key(), - MinimumConfirmations::default().try_to_vec().unwrap(), + MinimumConfirmations::default().serialize_to_vec(), ) .unwrap(); diff --git a/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs b/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs index 3271efeed5..9cb4377cef 100644 --- a/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs +++ b/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs @@ -18,7 +18,6 @@ use crate::protocol::transactions::{utils, votes, ChangedKeys}; use crate::storage::eth_bridge_queries::EthBridgeQueries; use crate::storage::proof::BridgePoolRootProof; use crate::storage::vote_tallies::{self, BridgePoolRoot}; - /// Applies a tally of signatures on over the Ethereum /// bridge pool root and nonce. Note that every signature /// passed into this function will be for the same @@ -222,7 +221,8 @@ mod test_apply_bp_roots_to_storage { use std::collections::BTreeSet; use assert_matches::assert_matches; - use borsh::{BorshDeserialize, BorshSerialize}; + use borsh::BorshDeserialize; + use borsh_ext::BorshSerializeExt; use namada_core::ledger::eth_bridge::storage::bridge_pool::{ get_key_from_hash, get_nonce_key, }; @@ -281,7 +281,7 @@ mod test_apply_bp_roots_to_storage { &KeccakHash([1; 32]), 100.into(), ); - let value = BlockHeight(101).try_to_vec().expect("Test failed"); + let value = BlockHeight(101).serialize_to_vec(); wl_storage .storage .block @@ -289,10 +289,7 @@ mod test_apply_bp_roots_to_storage { .update(&get_key_from_hash(&KeccakHash([1; 32])), value) .expect("Test failed"); wl_storage - .write_bytes( - &get_nonce_key(), - Uint::from(42).try_to_vec().expect("Test failed"), - ) + .write_bytes(&get_nonce_key(), Uint::from(42).serialize_to_vec()) .expect("Test failed"); TestPackage { validators: [validator_a, validator_b, validator_c], diff --git a/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs b/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs index d878a56d11..fa2be67104 100644 --- a/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs +++ b/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs @@ -564,7 +564,7 @@ mod tests { use std::collections::HashMap; use assert_matches::assert_matches; - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use eyre::Result; use namada_core::ledger::eth_bridge::storage::bridge_pool::get_pending_key; use namada_core::ledger::parameters::{ @@ -702,7 +702,7 @@ mod tests { let key = get_pending_key(&transfer); wl_storage .storage - .write(&key, transfer.try_to_vec().expect("Test failed")) + .write(&key, transfer.serialize_to_vec()) .expect("Test failed"); pending_transfers.push(transfer); @@ -743,10 +743,7 @@ mod tests { let payer_key = balance_key(&transfer.gas_fee.token, &payer); let payer_balance = Amount::from(0); wl_storage - .write_bytes( - &payer_key, - payer_balance.try_to_vec().expect("Test failed"), - ) + .write_bytes(&payer_key, payer_balance.serialize_to_vec()) .expect("Test failed"); let escrow_key = balance_key(&transfer.gas_fee.token, &BRIDGE_POOL_ADDRESS); @@ -761,36 +758,24 @@ mod tests { let sender_key = balance_key(&nam(), &transfer.transfer.sender); let sender_balance = Amount::from(0); wl_storage - .write_bytes( - &sender_key, - sender_balance.try_to_vec().expect("Test failed"), - ) + .write_bytes(&sender_key, sender_balance.serialize_to_vec()) .expect("Test failed"); let escrow_key = balance_key(&nam(), &BRIDGE_ADDRESS); let escrow_balance = Amount::from(10); wl_storage - .write_bytes( - &escrow_key, - escrow_balance.try_to_vec().expect("Test failed"), - ) + .write_bytes(&escrow_key, escrow_balance.serialize_to_vec()) .expect("Test failed"); } else { let token = transfer.token_address(); let sender_key = balance_key(&token, &transfer.transfer.sender); let sender_balance = Amount::from(0); wl_storage - .write_bytes( - &sender_key, - sender_balance.try_to_vec().expect("Test failed"), - ) + .write_bytes(&sender_key, sender_balance.serialize_to_vec()) .expect("Test failed"); let escrow_key = balance_key(&token, &BRIDGE_POOL_ADDRESS); let escrow_balance = Amount::from(10); wl_storage - .write_bytes( - &escrow_key, - escrow_balance.try_to_vec().expect("Test failed"), - ) + .write_bytes(&escrow_key, escrow_balance.serialize_to_vec()) .expect("Test failed"); update::amount( wl_storage, @@ -1162,7 +1147,7 @@ mod tests { let key = get_pending_key(&transfer); wl_storage .storage - .write(&key, transfer.try_to_vec().expect("Test failed")) + .write(&key, transfer.serialize_to_vec()) .expect("Test failed"); wl_storage .storage diff --git a/ethereum_bridge/src/protocol/transactions/read.rs b/ethereum_bridge/src/protocol/transactions/read.rs index 550be149ca..257c045e33 100644 --- a/ethereum_bridge/src/protocol/transactions/read.rs +++ b/ethereum_bridge/src/protocol/transactions/read.rs @@ -55,7 +55,7 @@ where #[cfg(test)] mod tests { use assert_matches::assert_matches; - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use namada_core::ledger::storage::testing::TestWlStorage; use namada_core::ledger::storage_api::StorageWrite; use namada_core::types::storage; @@ -81,7 +81,7 @@ mod tests { let amount = Amount::from(1_000_000); let mut fake_storage = TestWlStorage::default(); fake_storage - .write_bytes(&key, amount.try_to_vec().unwrap()) + .write_bytes(&key, amount.serialize_to_vec()) .unwrap(); let amt = read::amount_or_default(&fake_storage, &key).unwrap(); diff --git a/ethereum_bridge/src/protocol/transactions/update.rs b/ethereum_bridge/src/protocol/transactions/update.rs index 8316a72df4..d14c20ec35 100644 --- a/ethereum_bridge/src/protocol/transactions/update.rs +++ b/ethereum_bridge/src/protocol/transactions/update.rs @@ -18,7 +18,7 @@ where { let mut amount = super::read::amount_or_default(wl_storage, key)?; update(&mut amount); - wl_storage.write_bytes(key, amount.try_to_vec()?)?; + wl_storage.write_bytes(key, borsh::to_vec(&amount)?)?; Ok(amount) } @@ -35,13 +35,14 @@ where { let mut value = super::read::value(wl_storage, key)?; update(&mut value); - wl_storage.write_bytes(key, value.try_to_vec()?)?; + wl_storage.write_bytes(key, borsh::to_vec(&value)?)?; Ok(value) } #[cfg(test)] mod tests { - use borsh::{BorshDeserialize, BorshSerialize}; + use borsh::BorshDeserialize; + use borsh_ext::BorshSerializeExt; use eyre::{eyre, Result}; use namada_core::ledger::storage::testing::TestWlStorage; use namada_core::ledger::storage_api::{StorageRead, StorageWrite}; @@ -52,9 +53,9 @@ mod tests { fn test_value() -> Result<()> { let key = storage::Key::parse("some arbitrary key") .expect("could not set up test"); - let value = 21; + let value = 21i32; let mut wl_storage = TestWlStorage::default(); - let serialized = value.try_to_vec().expect("could not set up test"); + let serialized = value.serialize_to_vec(); wl_storage .write_bytes(&key, serialized) .expect("could not set up test"); diff --git a/ethereum_bridge/src/protocol/transactions/votes/storage.rs b/ethereum_bridge/src/protocol/transactions/votes/storage.rs index 832797ae1b..fe43c37c80 100644 --- a/ethereum_bridge/src/protocol/transactions/votes/storage.rs +++ b/ethereum_bridge/src/protocol/transactions/votes/storage.rs @@ -1,4 +1,5 @@ use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use eyre::{Result, WrapErr}; use namada_core::hints; use namada_core::ledger::storage::{ @@ -23,16 +24,19 @@ where H: 'static + StorageHasher + Sync, T: BorshSerialize, { - wl_storage.write_bytes(&keys.body(), &body.try_to_vec()?)?; - wl_storage.write_bytes(&keys.seen(), &tally.seen.try_to_vec()?)?; - wl_storage.write_bytes(&keys.seen_by(), &tally.seen_by.try_to_vec()?)?; + wl_storage.write_bytes(&keys.body(), &body.serialize_to_vec())?; + wl_storage.write_bytes(&keys.seen(), &tally.seen.serialize_to_vec())?; wl_storage - .write_bytes(&keys.voting_power(), &tally.voting_power.try_to_vec()?)?; + .write_bytes(&keys.seen_by(), &tally.seen_by.serialize_to_vec())?; + wl_storage.write_bytes( + &keys.voting_power(), + &tally.voting_power.serialize_to_vec(), + )?; if !already_present { // add the current epoch for the inserted event wl_storage.write_bytes( &keys.voting_started_epoch(), - &wl_storage.storage.get_current_epoch().0.try_to_vec()?, + &wl_storage.storage.get_current_epoch().0.serialize_to_vec(), )?; } Ok(()) @@ -205,28 +209,18 @@ mod tests { assert!(result.is_ok()); let body = wl_storage.read_bytes(&keys.body()).unwrap(); - assert_eq!(body, Some(event.try_to_vec().unwrap())); + assert_eq!(body, Some(event.serialize_to_vec())); let seen = wl_storage.read_bytes(&keys.seen()).unwrap(); - assert_eq!(seen, Some(tally.seen.try_to_vec().unwrap())); + assert_eq!(seen, Some(tally.seen.serialize_to_vec())); let seen_by = wl_storage.read_bytes(&keys.seen_by()).unwrap(); - assert_eq!(seen_by, Some(tally.seen_by.try_to_vec().unwrap())); + assert_eq!(seen_by, Some(tally.seen_by.serialize_to_vec())); let voting_power = wl_storage.read_bytes(&keys.voting_power()).unwrap(); - assert_eq!( - voting_power, - Some(tally.voting_power.try_to_vec().unwrap()) - ); + assert_eq!(voting_power, Some(tally.voting_power.serialize_to_vec())); let epoch = wl_storage.read_bytes(&keys.voting_started_epoch()).unwrap(); assert_eq!( epoch, - Some( - wl_storage - .storage - .get_current_epoch() - .0 - .try_to_vec() - .unwrap() - ) + Some(wl_storage.storage.get_current_epoch().0.serialize_to_vec()) ); } @@ -249,29 +243,24 @@ mod tests { seen: false, }; wl_storage - .write_bytes(&keys.body(), &event.try_to_vec().unwrap()) + .write_bytes(&keys.body(), &event.serialize_to_vec()) .unwrap(); wl_storage - .write_bytes(&keys.seen(), &tally.seen.try_to_vec().unwrap()) + .write_bytes(&keys.seen(), &tally.seen.serialize_to_vec()) .unwrap(); wl_storage - .write_bytes(&keys.seen_by(), &tally.seen_by.try_to_vec().unwrap()) + .write_bytes(&keys.seen_by(), &tally.seen_by.serialize_to_vec()) .unwrap(); wl_storage .write_bytes( &keys.voting_power(), - &tally.voting_power.try_to_vec().unwrap(), + &tally.voting_power.serialize_to_vec(), ) .unwrap(); wl_storage .write_bytes( &keys.voting_started_epoch(), - &wl_storage - .storage - .get_block_height() - .0 - .try_to_vec() - .unwrap(), + &wl_storage.storage.get_block_height().0.serialize_to_vec(), ) .unwrap(); diff --git a/ethereum_bridge/src/storage/vote_tallies.rs b/ethereum_bridge/src/storage/vote_tallies.rs index ec03c498d6..edb60114e8 100644 --- a/ethereum_bridge/src/storage/vote_tallies.rs +++ b/ethereum_bridge/src/storage/vote_tallies.rs @@ -1,6 +1,6 @@ //! Functionality for accessing keys to do with tallying votes -use std::io::Write; +use std::io::{Read, Write}; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; @@ -199,11 +199,11 @@ impl BorshSerialize for BridgePoolRoot { } impl BorshDeserialize for BridgePoolRoot { - fn deserialize(buf: &mut &[u8]) -> std::io::Result { - as BorshDeserialize>::deserialize( - buf, + fn deserialize_reader(reader: &mut R) -> std::io::Result { + as BorshDeserialize>::deserialize_reader( + reader, ) - .map(BridgePoolRoot) + .map(BridgePoolRoot) } } diff --git a/ethereum_bridge/src/test_utils.rs b/ethereum_bridge/src/test_utils.rs index 9c24e9edfa..4d2283ad8e 100644 --- a/ethereum_bridge/src/test_utils.rs +++ b/ethereum_bridge/src/test_utils.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use std::num::NonZeroU64; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use namada_core::ledger::eth_bridge::storage::bridge_pool::get_key_from_hash; use namada_core::ledger::eth_bridge::storage::whitelist; use namada_core::ledger::storage::mockdb::MockDBWriteBatch; @@ -241,7 +241,7 @@ pub fn commit_bridge_pool_root_at_height( root: &KeccakHash, height: BlockHeight, ) { - let value = height.try_to_vec().expect("Encoding failed"); + let value = height.serialize_to_vec(); storage .block .tree diff --git a/ethereum_bridge/src/vp.rs b/ethereum_bridge/src/vp.rs index 1c06de83a1..ed678ff03b 100644 --- a/ethereum_bridge/src/vp.rs +++ b/ethereum_bridge/src/vp.rs @@ -1,4 +1,4 @@ -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use namada_core::ledger::storage::{self as ledger_storage, StorageHasher}; use namada_core::ledger::storage_api::StorageWrite; use namada_core::types::token::{balance_key, Amount}; @@ -17,12 +17,7 @@ where &namada_core::ledger::eth_bridge::ADDRESS, ); wl_storage - .write_bytes( - &escrow_key, - Amount::default() - .try_to_vec() - .expect("Serializing an amount shouldn't fail."), - ) + .write_bytes(&escrow_key, Amount::default().serialize_to_vec()) .expect( "Initializing the escrow balance of the Ethereum Bridge VP \ shouldn't fail.", diff --git a/proof_of_stake/src/pos_queries.rs b/proof_of_stake/src/pos_queries.rs index 190548570b..a629afce73 100644 --- a/proof_of_stake/src/pos_queries.rs +++ b/proof_of_stake/src/pos_queries.rs @@ -1,7 +1,7 @@ //! Storage API for querying data about Proof-of-stake related //! data. This includes validator and epoch related data. -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; use namada_core::ledger::parameters::storage::get_max_proposal_bytes_key; use namada_core::ledger::parameters::EpochDuration; use namada_core::ledger::storage::WlStorage; @@ -172,9 +172,8 @@ where pk: &key::common::PublicKey, epoch: Option, ) -> Result { - let pk_bytes = pk - .try_to_vec() - .expect("Serializing public key should not fail"); + let pk_bytes = + borsh::to_vec(pk).expect("Serializing public key should not fail"); let epoch = epoch .unwrap_or_else(|| self.wl_storage.storage.get_current_epoch().0); self.get_consensus_validators(Some(epoch)) diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 100db5949b..f9df559c8a 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -74,6 +74,7 @@ testing = [ async-trait = {version = "0.1.51", optional = true} bimap.workspace = true borsh.workspace = true +borsh-ext.workspace = true circular-queue.workspace = true data-encoding.workspace = true derivation-path.workspace = true diff --git a/sdk/src/eth_bridge/bridge_pool.rs b/sdk/src/eth_bridge/bridge_pool.rs index 31d996906b..a73767cf5e 100644 --- a/sdk/src/eth_bridge/bridge_pool.rs +++ b/sdk/src/eth_bridge/bridge_pool.rs @@ -5,7 +5,7 @@ use std::cmp::Ordering; use std::collections::HashMap; use std::sync::Arc; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use ethbridge_bridge_contract::Bridge; use ethers::providers::Middleware; use futures::future::FutureExt; @@ -477,7 +477,7 @@ async fn construct_bridge_pool_proof<'a>( } } - let data = args.try_to_vec().unwrap(); + let data = args.serialize_to_vec(); let response = RPC .shell() .eth_bridge() diff --git a/sdk/src/masp.rs b/sdk/src/masp.rs index a860839e3a..09a1adff8c 100644 --- a/sdk/src/masp.rs +++ b/sdk/src/masp.rs @@ -10,6 +10,7 @@ use std::path::PathBuf; // use async_std::io::prelude::WriteExt; // use async_std::io::{self}; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use itertools::Either; use masp_primitives::asset_type::AssetType; #[cfg(feature = "mainnet")] @@ -69,7 +70,9 @@ use sha2::Digest; use thiserror::Error; use crate::args::InputAmount; -use crate::error::{EncodingError, Error, PinnedBalanceError, QueryError}; +#[cfg(feature = "testing")] +use crate::error::EncodingError; +use crate::error::{Error, PinnedBalanceError, QueryError}; use crate::io::Io; use crate::proto::Tx; use crate::queries::Client; @@ -570,7 +573,7 @@ pub type TransactionDelta = HashMap; #[derive(BorshSerialize, BorshDeserialize, Debug)] pub struct ShieldedContext { /// Location where this shielded context is saved - #[borsh_skip] + #[borsh(skip)] pub utils: U, /// The last transaction index to be processed in this context pub last_txidx: u64, @@ -1617,12 +1620,8 @@ impl ShieldedContext { "source address should be transparent".to_string(), ) })? - .try_to_vec() - .map_err(|_| { - Error::from(EncodingError::Encode( - "source address".to_string(), - )) - })?; + .serialize_to_vec(); + let hash = ripemd::Ripemd160::digest(sha2::Sha256::digest( source_enc.as_ref(), )); @@ -1666,12 +1665,7 @@ impl ShieldedContext { "source address should be transparent".to_string(), ) })? - .try_to_vec() - .map_err(|_| { - Error::from(EncodingError::Encode( - "target address".to_string(), - )) - })?; + .serialize_to_vec(); let hash = ripemd::Ripemd160::digest(sha2::Sha256::digest( target_enc.as_ref(), )); @@ -1762,10 +1756,9 @@ impl ShieldedContext { let builder_clone = builder.clone().map_builder(WalletMap); #[cfg(feature = "testing")] - let builder_bytes = BorshSerialize::try_to_vec(&builder_clone) - .map_err(|e| { - Error::from(EncodingError::Conversion(e.to_string())) - })?; + let builder_bytes = borsh::to_vec(&builder_clone).map_err(|e| { + Error::from(EncodingError::Conversion(e.to_string())) + })?; let build_transfer = |prover: LocalTxProver| -> Result< ShieldedTransfer, @@ -1827,12 +1820,9 @@ impl ShieldedContext { context.shielded().await.utils.local_tx_prover(), )?; if let LoadOrSaveProofs::Save = load_or_save { - let built_bytes = BorshSerialize::try_to_vec(&built) - .map_err(|e| { - Error::from(EncodingError::Conversion( - e.to_string(), - )) - })?; + let built_bytes = borsh::to_vec(&built).map_err(|e| { + Error::from(EncodingError::Conversion(e.to_string())) + })?; tokio::fs::write(&saved_filepath, built_bytes) .await .map_err(|e| Error::Other(e.to_string()))?; @@ -2002,12 +1992,8 @@ pub fn make_asset_type( ) -> Result { // Typestamp the chosen token with the current epoch let token_bytes = match epoch { - None => (token, denom) - .try_to_vec() - .map_err(|e| Error::from(EncodingError::Encode(e.to_string())))?, - Some(epoch) => (token, denom, epoch.0) - .try_to_vec() - .map_err(|e| Error::from(EncodingError::Encode(e.to_string())))?, + None => (token, denom).serialize_to_vec(), + Some(epoch) => (token, denom, epoch.0).serialize_to_vec(), }; // Generate the unique asset identifier from the unique token address AssetType::new(token_bytes.as_ref()) @@ -2157,7 +2143,7 @@ pub mod fs { #[derive(Debug, BorshSerialize, BorshDeserialize, Clone)] /// An implementation of ShieldedUtils for standard filesystems pub struct FsShieldedUtils { - #[borsh_skip] + #[borsh(skip)] context_dir: PathBuf, } diff --git a/sdk/src/queries/router.rs b/sdk/src/queries/router.rs index 9783d21309..1251972608 100644 --- a/sdk/src/queries/router.rs +++ b/sdk/src/queries/router.rs @@ -90,7 +90,7 @@ macro_rules! handle_match { // queries::Storage`, you're probably missing the marker `(sub _)` let data = $handle($ctx, $( $matched_args ),* )?; // Encode the returned data with borsh - let data = borsh::BorshSerialize::try_to_vec(&data).into_storage_result()?; + let data = borsh::to_vec(&data).into_storage_result()?; return Ok($crate::queries::EncodedResponseQuery { data, info: Default::default(), @@ -834,9 +834,9 @@ macro_rules! router { /// ``` #[cfg(test)] mod test_rpc_handlers { - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use namada_core::ledger::storage::{DBIter, StorageHasher, DB}; - use namada_core::ledger::storage_api::{self, ResultExt}; + use namada_core::ledger::storage_api; use namada_core::types::storage::Epoch; use namada_core::types::token; @@ -949,7 +949,7 @@ mod test_rpc_handlers { D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { - let data = "c".to_owned().try_to_vec().into_storage_result()?; + let data = "c".to_owned().serialize_to_vec(); Ok(ResponseQuery { data, ..ResponseQuery::default() diff --git a/sdk/src/queries/shell.rs b/sdk/src/queries/shell.rs index 22ba39feda..ec7db2ca67 100644 --- a/sdk/src/queries/shell.rs +++ b/sdk/src/queries/shell.rs @@ -1,6 +1,7 @@ pub(super) mod eth_bridge; -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; +use borsh_ext::BorshSerializeExt; use masp_primitives::asset_type::AssetType; use masp_primitives::merkle_tree::MerklePath; use masp_primitives::sapling::Node; @@ -325,7 +326,7 @@ where } else { None }; - let data = data.try_to_vec().into_storage_result()?; + let data = data.serialize_to_vec(); Ok(EncodedResponseQuery { data, proof, diff --git a/sdk/src/queries/shell/eth_bridge.rs b/sdk/src/queries/shell/eth_bridge.rs index c9c820ed5a..47234f0cd9 100644 --- a/sdk/src/queries/shell/eth_bridge.rs +++ b/sdk/src/queries/shell/eth_bridge.rs @@ -5,6 +5,7 @@ use std::collections::HashMap; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use namada_core::ledger::eth_bridge::storage::bridge_pool::get_key_from_hash; use namada_core::ledger::storage::merkle_tree::StoreRef; use namada_core::ledger::storage::{DBIter, StorageHasher, StoreType, DB}; @@ -434,7 +435,7 @@ where )), appendices: with_appendix.then_some(appendices), }; - let data = rsp.try_to_vec().into_storage_result()?; + let data = rsp.serialize_to_vec(); Ok(EncodedResponseQuery { data, ..Default::default() @@ -680,7 +681,6 @@ mod test_ethbridge_router { use std::collections::BTreeMap; use assert_matches::assert_matches; - use borsh::BorshSerialize; use namada_core::ledger::eth_bridge::storage::bridge_pool::{ get_pending_key, get_signed_root_key, BridgePoolTree, }; @@ -924,7 +924,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer), - transfer.try_to_vec().expect("Test failed"), + transfer.serialize_to_vec(), ) .expect("Test failed"); @@ -967,7 +967,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer), - transfer.try_to_vec().expect("Test failed"), + transfer.serialize_to_vec(), ) .expect("Test failed"); @@ -986,7 +986,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer2), - transfer2.try_to_vec().expect("Test failed"), + transfer2.serialize_to_vec(), ) .expect("Test failed"); @@ -1032,7 +1032,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer), - transfer.try_to_vec().expect("Test failed"), + transfer.serialize_to_vec(), ) .expect("Test failed"); @@ -1053,7 +1053,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer2), - transfer2.try_to_vec().expect("Test failed"), + transfer2.serialize_to_vec(), ) .expect("Test failed"); @@ -1062,9 +1062,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_signed_root_key(), - (signed_root.clone(), BlockHeight::from(0)) - .try_to_vec() - .unwrap(), + (signed_root.clone(), BlockHeight::from(0)).serialize_to_vec(), ) .expect("Test failed"); @@ -1083,8 +1081,7 @@ mod test_ethbridge_router { relayer: Cow::Owned(bertha_address()), with_appendix: false, } - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ), None, false, @@ -1150,7 +1147,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer), - transfer.try_to_vec().expect("Test failed"), + transfer.serialize_to_vec(), ) .expect("Test failed"); @@ -1175,7 +1172,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer2), - transfer2.try_to_vec().expect("Test failed"), + transfer2.serialize_to_vec(), ) .expect("Test failed"); @@ -1184,7 +1181,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_signed_root_key(), - (signed_root, BlockHeight::from(0)).try_to_vec().unwrap(), + (signed_root, BlockHeight::from(0)).serialize_to_vec(), ) .expect("Test failed"); @@ -1208,8 +1205,7 @@ mod test_ethbridge_router { relayer: Cow::Owned(bertha_address()), with_appendix: false, } - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ), None, false, @@ -1246,7 +1242,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer), - transfer.try_to_vec().expect("Test failed"), + transfer.serialize_to_vec(), ) .expect("Test failed"); @@ -1267,7 +1263,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer2), - transfer2.try_to_vec().expect("Test failed"), + transfer2.serialize_to_vec(), ) .expect("Test failed"); @@ -1276,7 +1272,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_signed_root_key(), - (signed_root, BlockHeight::from(0)).try_to_vec().unwrap(), + (signed_root, BlockHeight::from(0)).serialize_to_vec(), ) .expect("Test failed"); @@ -1320,7 +1316,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer), - transfer.try_to_vec().expect("Test failed"), + transfer.serialize_to_vec(), ) .expect("Test failed"); @@ -1335,10 +1331,7 @@ mod test_ethbridge_router { let voting_power = FractionalVotingPower::HALF; client .wl_storage - .write_bytes( - ð_msg_key.body(), - eth_event.try_to_vec().expect("Test failed"), - ) + .write_bytes(ð_msg_key.body(), eth_event.serialize_to_vec()) .expect("Test failed"); client .wl_storage @@ -1348,8 +1341,7 @@ mod test_ethbridge_router { 0.into(), voting_power * dummy_validator_stake, )]) - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ) .expect("Test failed"); client @@ -1371,7 +1363,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer2), - transfer2.try_to_vec().expect("Test failed"), + transfer2.serialize_to_vec(), ) .expect("Test failed"); @@ -1423,7 +1415,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer), - transfer.try_to_vec().expect("Test failed"), + transfer.serialize_to_vec(), ) .expect("Test failed"); @@ -1444,7 +1436,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_pending_key(&transfer2), - transfer2.try_to_vec().expect("Test failed"), + transfer2.serialize_to_vec(), ) .expect("Test failed"); @@ -1453,7 +1445,7 @@ mod test_ethbridge_router { .wl_storage .write_bytes( &get_signed_root_key(), - (signed_root, BlockHeight::from(0)).try_to_vec().unwrap(), + (signed_root, BlockHeight::from(0)).serialize_to_vec(), ) .expect("Test failed"); @@ -1472,8 +1464,7 @@ mod test_ethbridge_router { relayer: Cow::Owned(bertha_address()), with_appendix: false, } - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ), None, false, @@ -1499,8 +1490,7 @@ mod test_ethbridge_router { relayer: Cow::Owned(bertha_address()), with_appendix: false, } - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ), None, false, diff --git a/sdk/src/signing.rs b/sdk/src/signing.rs index db2aab3482..d9b6d18854 100644 --- a/sdk/src/signing.rs +++ b/sdk/src/signing.rs @@ -2,7 +2,8 @@ use std::collections::{BTreeMap, HashMap}; use std::path::PathBuf; -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXLOWER; use itertools::Itertools; use masp_primitives::asset_type::AssetType; @@ -863,9 +864,7 @@ pub async fn to_ledger_vector<'a>( .collect(); let mut tv = LedgerVector { - blob: HEXLOWER.encode(&tx.try_to_vec().map_err(|_| { - Error::Other("unable to serialize transaction".to_string()) - })?), + blob: HEXLOWER.encode(&tx.serialize_to_vec()), index: 0, valid: true, name: "Custom 0".to_string(), diff --git a/sdk/src/tx.rs b/sdk/src/tx.rs index 00402aa46e..b3abe954d3 100644 --- a/sdk/src/tx.rs +++ b/sdk/src/tx.rs @@ -2134,8 +2134,6 @@ where } fn proposal_to_vec(proposal: OnChainProposal) -> Result> { - proposal - .content - .try_to_vec() + borsh::to_vec(&proposal.content) .map_err(|e| Error::from(EncodingError::Conversion(e.to_string()))) } diff --git a/sdk/src/wallet/keys.rs b/sdk/src/wallet/keys.rs index a8d267c898..079f165246 100644 --- a/sdk/src/wallet/keys.rs +++ b/sdk/src/wallet/keys.rs @@ -5,6 +5,7 @@ use std::marker::PhantomData; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use data_encoding::HEXLOWER; use orion::{aead, kdf}; use serde::{Deserialize, Serialize}; @@ -201,9 +202,7 @@ impl EncryptedKeypair { let salt = encryption_salt(); let encryption_key = encryption_key(&salt, &password); - let data = keypair - .try_to_vec() - .expect("Serializing keypair shouldn't fail"); + let data = keypair.serialize_to_vec(); let encrypted_keypair = aead::seal(&encryption_key, &data) .expect("Encryption of data shouldn't fail"); diff --git a/sdk/src/wallet/mod.rs b/sdk/src/wallet/mod.rs index 4ee3e13947..67d5a11f86 100644 --- a/sdk/src/wallet/mod.rs +++ b/sdk/src/wallet/mod.rs @@ -203,7 +203,7 @@ pub mod fs { /// For a non-interactive filesystem based wallet #[derive(Debug, BorshSerialize, BorshDeserialize, Clone)] pub struct FsWalletUtils { - #[borsh_skip] + #[borsh(skip)] store_dir: PathBuf, } diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 0c6d903ddd..648f7e0b39 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -111,6 +111,7 @@ namada_ethereum_bridge = {path = "../ethereum_bridge", default-features = false} async-trait = {version = "0.1.51", optional = true} bimap.workspace = true borsh.workspace = true +borsh-ext.workspace = true circular-queue.workspace = true clru.workspace = true data-encoding.workspace = true diff --git a/shared/src/ledger/mod.rs b/shared/src/ledger/mod.rs index 676d57190f..3ccb4afb88 100644 --- a/shared/src/ledger/mod.rs +++ b/shared/src/ledger/mod.rs @@ -35,7 +35,7 @@ where H: 'static + StorageHasher + Sync, CA: 'static + WasmCacheAccess + Sync, { - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use namada_core::ledger::gas::{Gas, GasMetering, TxGasMeter}; use namada_core::ledger::storage::TempWlStorage; use namada_core::proto::Tx; @@ -126,7 +126,7 @@ where data.gas_used = cumulated_gas; // NOTE: the keys changed by the wrapper transaction (if any) are not // returned from this function - let data = data.try_to_vec().into_storage_result()?; + let data = data.serialize_to_vec(); Ok(EncodedResponseQuery { data, proof: None, @@ -136,7 +136,8 @@ where #[cfg(test)] mod test { - use borsh::{BorshDeserialize, BorshSerialize}; + use borsh::BorshDeserialize; + use borsh_ext::BorshSerializeExt; use namada_core::ledger::storage::testing::TestWlStorage; use namada_core::ledger::storage_api::{self, StorageWrite}; use namada_core::types::hash::Hash; @@ -285,7 +286,7 @@ mod test { client .wl_storage .storage - .write(&len_key, (tx_no_op.len() as u64).try_to_vec().unwrap()) + .write(&len_key, (tx_no_op.len() as u64).serialize_to_vec()) .unwrap(); // Request last committed epoch diff --git a/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs b/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs index 5efea15ac5..6d07f5a613 100644 --- a/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs +++ b/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs @@ -641,7 +641,8 @@ where mod test_bridge_pool_vp { use std::env::temp_dir; - use borsh::BorshSerialize; + use borsh::BorshDeserialize; + use borsh_ext::BorshSerializeExt; use namada_core::ledger::eth_bridge::storage::bridge_pool::get_signed_root_key; use namada_core::ledger::gas::TxGasMeter; use namada_core::types::address; @@ -756,11 +757,11 @@ mod test_bridge_pool_vp { let mut writelog = WriteLog::default(); // setup the initial bridge pool storage writelog - .write(&get_signed_root_key(), Hash([0; 32]).try_to_vec().unwrap()) + .write(&get_signed_root_key(), Hash([0; 32]).serialize_to_vec()) .expect("Test failed"); let transfer = initial_pool(); writelog - .write(&get_pending_key(&transfer), transfer.try_to_vec().unwrap()) + .write(&get_pending_key(&transfer), transfer.serialize_to_vec()) .expect("Test failed"); // whitelist wnam let key = whitelist::Key { @@ -769,7 +770,7 @@ mod test_bridge_pool_vp { } .into(); writelog - .write(&key, true.try_to_vec().unwrap()) + .write(&key, true.serialize_to_vec()) .expect("Test failed"); let key = whitelist::Key { asset: wnam(), @@ -777,7 +778,7 @@ mod test_bridge_pool_vp { } .into(); writelog - .write(&key, Amount::max().try_to_vec().unwrap()) + .write(&key, Amount::max().serialize_to_vec()) .expect("Test failed"); // set up users with ERC20 and NUT balances update_balances( @@ -843,10 +844,7 @@ mod test_bridge_pool_vp { // write the changes to the log let account_key = balance_key(&nam(), &balance.owner); write_log - .write( - &account_key, - updated_balance.try_to_vec().expect("Test failed"), - ) + .write(&account_key, updated_balance.serialize_to_vec()) .expect("Test failed"); // changed keys @@ -889,10 +887,10 @@ mod test_bridge_pool_vp { // write the changes to the log write_log - .write(&account_key, new_gas_balance.try_to_vec().unwrap()) + .write(&account_key, new_gas_balance.serialize_to_vec()) .expect("Test failed"); write_log - .write(&token_key, new_token_balance.try_to_vec().unwrap()) + .write(&token_key, new_token_balance.serialize_to_vec()) .expect("Test failed"); // return the keys changed @@ -1059,7 +1057,7 @@ mod test_bridge_pool_vp { |transfer, log| { log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) @@ -1080,7 +1078,7 @@ mod test_bridge_pool_vp { |transfer, log| { log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) @@ -1101,7 +1099,7 @@ mod test_bridge_pool_vp { |transfer, log| { log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) @@ -1122,7 +1120,7 @@ mod test_bridge_pool_vp { |transfer, log| { log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) @@ -1144,7 +1142,7 @@ mod test_bridge_pool_vp { |transfer, log| { log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) @@ -1165,7 +1163,7 @@ mod test_bridge_pool_vp { |transfer, log| { log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) @@ -1186,7 +1184,7 @@ mod test_bridge_pool_vp { |transfer, log| { log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) @@ -1207,7 +1205,7 @@ mod test_bridge_pool_vp { |transfer, log| { log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) @@ -1254,7 +1252,7 @@ mod test_bridge_pool_vp { payer: bertha_address(), }, }; - log.write(&get_pending_key(transfer), t.try_to_vec().unwrap()) + log.write(&get_pending_key(transfer), t.serialize_to_vec()) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) }, @@ -1286,7 +1284,7 @@ mod test_bridge_pool_vp { payer: bertha_address(), }, }; - log.write(&get_pending_key(&t), transfer.try_to_vec().unwrap()) + log.write(&get_pending_key(&t), transfer.serialize_to_vec()) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) }, @@ -1306,7 +1304,7 @@ mod test_bridge_pool_vp { |transfer, log| { log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([ @@ -1333,10 +1331,7 @@ mod test_bridge_pool_vp { let mut keys_changed = { wl_storage .write_log - .write( - &get_pending_key(&transfer), - transfer.try_to_vec().unwrap(), - ) + .write(&get_pending_key(&transfer), transfer.serialize_to_vec()) .unwrap(); BTreeSet::from([get_pending_key(&transfer)]) }; @@ -1418,10 +1413,7 @@ mod test_bridge_pool_vp { let mut keys_changed = { wl_storage .write_log - .write( - &get_pending_key(&transfer), - transfer.try_to_vec().unwrap(), - ) + .write(&get_pending_key(&transfer), transfer.serialize_to_vec()) .unwrap(); BTreeSet::from([get_pending_key(&transfer)]) }; @@ -1486,10 +1478,7 @@ mod test_bridge_pool_vp { let mut keys_changed = { wl_storage .write_log - .write( - &get_pending_key(&transfer), - transfer.try_to_vec().unwrap(), - ) + .write(&get_pending_key(&transfer), transfer.serialize_to_vec()) .unwrap(); BTreeSet::from([get_pending_key(&transfer)]) }; @@ -1500,9 +1489,7 @@ mod test_bridge_pool_vp { .write_log .write( &account_key, - Amount::from(BERTHA_WEALTH - 200) - .try_to_vec() - .expect("Test failed"), + Amount::from(BERTHA_WEALTH - 200).serialize_to_vec(), ) .expect("Test failed"); assert!(keys_changed.insert(account_key)); @@ -1511,9 +1498,7 @@ mod test_bridge_pool_vp { .write_log .write( &bp_account_key, - Amount::from(ESCROWED_AMOUNT + 100) - .try_to_vec() - .expect("Test failed"), + Amount::from(ESCROWED_AMOUNT + 100).serialize_to_vec(), ) .expect("Test failed"); assert!(keys_changed.insert(bp_account_key)); @@ -1521,9 +1506,7 @@ mod test_bridge_pool_vp { .write_log .write( &eb_account_key, - Amount::from(ESCROWED_AMOUNT + 100) - .try_to_vec() - .expect("Test failed"), + Amount::from(ESCROWED_AMOUNT + 100).serialize_to_vec(), ) .expect("Test failed"); assert!(keys_changed.insert(eb_account_key)); @@ -1580,10 +1563,7 @@ mod test_bridge_pool_vp { let keys_changed = { wl_storage .write_log - .write( - &get_pending_key(&transfer), - transfer.try_to_vec().unwrap(), - ) + .write(&get_pending_key(&transfer), transfer.serialize_to_vec()) .unwrap(); BTreeSet::from([get_pending_key(&transfer)]) }; @@ -1594,9 +1574,7 @@ mod test_bridge_pool_vp { .write_log .write( &account_key, - Amount::from(BERTHA_WEALTH - 200) - .try_to_vec() - .expect("Test failed"), + Amount::from(BERTHA_WEALTH - 200).serialize_to_vec(), ) .expect("Test failed"); let bp_account_key = balance_key(&nam(), &BRIDGE_POOL_ADDRESS); @@ -1604,17 +1582,12 @@ mod test_bridge_pool_vp { .write_log .write( &bp_account_key, - Amount::from(ESCROWED_AMOUNT + 100) - .try_to_vec() - .expect("Test failed"), + Amount::from(ESCROWED_AMOUNT + 100).serialize_to_vec(), ) .expect("Test failed"); wl_storage .write_log - .write( - &eb_account_key, - Amount::from(10).try_to_vec().expect("Test failed"), - ) + .write(&eb_account_key, Amount::from(10).serialize_to_vec()) .expect("Test failed"); let verifiers = BTreeSet::default(); @@ -1649,10 +1622,7 @@ mod test_bridge_pool_vp { let eb_account_key = balance_key(&nam(), &Address::Internal(InternalAddress::EthBridge)); wl_storage - .write_bytes( - &eb_account_key, - Amount::default().try_to_vec().expect("Test failed"), - ) + .write_bytes(&eb_account_key, Amount::default().serialize_to_vec()) .expect("Test failed"); // initialize the gas payers account let gas_payer_balance_key = @@ -1660,9 +1630,7 @@ mod test_bridge_pool_vp { wl_storage .write_bytes( &gas_payer_balance_key, - Amount::from(BERTHA_WEALTH) - .try_to_vec() - .expect("Test failed"), + Amount::from(BERTHA_WEALTH).serialize_to_vec(), ) .expect("Test failed"); wl_storage.write_log.commit_tx(); @@ -1688,10 +1656,7 @@ mod test_bridge_pool_vp { let keys_changed = { wl_storage .write_log - .write( - &get_pending_key(&transfer), - transfer.try_to_vec().unwrap(), - ) + .write(&get_pending_key(&transfer), transfer.serialize_to_vec()) .unwrap(); BTreeSet::from([get_pending_key(&transfer)]) }; @@ -1702,18 +1667,14 @@ mod test_bridge_pool_vp { .write_log .write( &account_key, - Amount::from(BERTHA_WEALTH - 100) - .try_to_vec() - .expect("Test failed"), + Amount::from(BERTHA_WEALTH - 100).serialize_to_vec(), ) .expect("Test failed"); wl_storage .write_log .write( &gas_payer_balance_key, - Amount::from(BERTHA_WEALTH - 100) - .try_to_vec() - .expect("Test failed"), + Amount::from(BERTHA_WEALTH - 100).serialize_to_vec(), ) .expect("Test failed"); let bp_account_key = balance_key(&nam(), &BRIDGE_POOL_ADDRESS); @@ -1721,17 +1682,12 @@ mod test_bridge_pool_vp { .write_log .write( &bp_account_key, - Amount::from(ESCROWED_AMOUNT + 100) - .try_to_vec() - .expect("Test failed"), + Amount::from(ESCROWED_AMOUNT + 100).serialize_to_vec(), ) .expect("Test failed"); wl_storage .write_log - .write( - &eb_account_key, - Amount::from(10).try_to_vec().expect("Test failed"), - ) + .write(&eb_account_key, Amount::from(10).serialize_to_vec()) .expect("Test failed"); let verifiers = BTreeSet::default(); // create the data to be given to the vp @@ -1780,10 +1736,7 @@ mod test_bridge_pool_vp { let mut keys_changed = { wl_storage .write_log - .write( - &get_pending_key(&transfer), - transfer.try_to_vec().unwrap(), - ) + .write(&get_pending_key(&transfer), transfer.serialize_to_vec()) .unwrap(); BTreeSet::from([get_pending_key(&transfer)]) }; @@ -1868,7 +1821,7 @@ mod test_bridge_pool_vp { transfer.transfer.asset = wnam(); log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) @@ -1890,7 +1843,7 @@ mod test_bridge_pool_vp { transfer.transfer.asset = wnam(); log.write( &get_pending_key(transfer), - transfer.try_to_vec().unwrap(), + transfer.serialize_to_vec(), ) .unwrap(); BTreeSet::from([get_pending_key(transfer)]) diff --git a/shared/src/ledger/native_vp/ethereum_bridge/nut.rs b/shared/src/ledger/native_vp/ethereum_bridge/nut.rs index 1f7f313521..6dbb79d788 100644 --- a/shared/src/ledger/native_vp/ethereum_bridge/nut.rs +++ b/shared/src/ledger/native_vp/ethereum_bridge/nut.rs @@ -121,7 +121,7 @@ mod test_nuts { use std::env::temp_dir; use assert_matches::assert_matches; - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use namada_core::ledger::storage::testing::TestWlStorage; use namada_core::ledger::storage_api::StorageWrite; use namada_core::types::address::testing::arb_non_internal_address; @@ -157,13 +157,13 @@ mod test_nuts { wl.write_log .write( &src_balance_key, - Amount::from(100_u64).try_to_vec().expect("Test failed"), + Amount::from(100_u64).serialize_to_vec(), ) .expect("Test failed"); wl.write_log .write( &dst_balance_key, - Amount::from(200_u64).try_to_vec().expect("Test failed"), + Amount::from(200_u64).serialize_to_vec(), ) .expect("Test failed"); diff --git a/shared/src/ledger/native_vp/ethereum_bridge/vp.rs b/shared/src/ledger/native_vp/ethereum_bridge/vp.rs index 4d006229a1..9f5f6dd19c 100644 --- a/shared/src/ledger/native_vp/ethereum_bridge/vp.rs +++ b/shared/src/ledger/native_vp/ethereum_bridge/vp.rs @@ -164,7 +164,7 @@ mod tests { use std::default::Default; use std::env::temp_dir; - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use namada_core::ledger::eth_bridge; use namada_core::ledger::eth_bridge::storage::bridge_pool::BRIDGE_POOL_ADDRESS; use namada_core::ledger::eth_bridge::storage::wrapped_erc20s; @@ -220,8 +220,7 @@ mod tests { .write_bytes( &balance_key, Amount::from(ARBITRARY_OWNER_A_INITIAL_BALANCE) - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ) .expect("Test failed"); @@ -365,8 +364,7 @@ mod tests { .write( &account_key, Amount::from(ARBITRARY_OWNER_A_INITIAL_BALANCE - ESCROW_AMOUNT) - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ) .expect("Test failed"); @@ -379,8 +377,7 @@ mod tests { Amount::from( BRIDGE_POOL_ESCROW_INITIAL_BALANCE + ESCROW_AMOUNT, ) - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ) .expect("Test failed"); @@ -417,8 +414,7 @@ mod tests { .write( &account_key, Amount::from(ARBITRARY_OWNER_A_INITIAL_BALANCE - ESCROW_AMOUNT) - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ) .expect("Test failed"); @@ -429,8 +425,7 @@ mod tests { .write( &escrow_key, Amount::from(BRIDGE_POOL_ESCROW_INITIAL_BALANCE) - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ) .expect("Test failed"); @@ -468,8 +463,7 @@ mod tests { .write( &account_key, Amount::from(ARBITRARY_OWNER_A_INITIAL_BALANCE - ESCROW_AMOUNT) - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ) .expect("Test failed"); @@ -482,8 +476,7 @@ mod tests { Amount::from( BRIDGE_POOL_ESCROW_INITIAL_BALANCE + ESCROW_AMOUNT, ) - .try_to_vec() - .expect("Test failed"), + .serialize_to_vec(), ) .expect("Test failed"); diff --git a/shared/src/ledger/native_vp/ibc/context.rs b/shared/src/ledger/native_vp/ibc/context.rs index 5af2afebf7..519e1ae233 100644 --- a/shared/src/ledger/native_vp/ibc/context.rs +++ b/shared/src/ledger/native_vp/ibc/context.rs @@ -2,7 +2,7 @@ use std::collections::{BTreeSet, HashMap, HashSet}; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use namada_core::ledger::ibc::storage::is_ibc_key; use namada_core::ledger::ibc::{IbcCommonContext, IbcStorageContext}; use namada_core::ledger::storage::write_log::StorageModification; @@ -150,14 +150,8 @@ where .unwrap_or_default(); dest_bal.receive(&amount.amount); - self.write( - &src_key, - src_bal.try_to_vec().expect("encoding shouldn't failed"), - )?; - self.write( - &dest_key, - dest_bal.try_to_vec().expect("encoding shouldn't failed"), - ) + self.write(&src_key, src_bal.serialize_to_vec())?; + self.write(&dest_key, dest_bal.serialize_to_vec()) } fn mint_token( @@ -182,21 +176,13 @@ where .unwrap_or_default(); minted_bal.receive(&amount.amount); - self.write( - &target_key, - target_bal.try_to_vec().expect("encoding shouldn't failed"), - )?; - self.write( - &minted_key, - minted_bal.try_to_vec().expect("encoding shouldn't failed"), - )?; + self.write(&target_key, target_bal.serialize_to_vec())?; + self.write(&minted_key, minted_bal.serialize_to_vec())?; let minter_key = token::minter_key(token); self.write( &minter_key, - Address::Internal(InternalAddress::Ibc) - .try_to_vec() - .expect("encoding shouldn't failed"), + Address::Internal(InternalAddress::Ibc).serialize_to_vec(), ) } @@ -222,14 +208,8 @@ where .unwrap_or_default(); minted_bal.spend(&amount.amount); - self.write( - &target_key, - target_bal.try_to_vec().expect("encoding shouldn't failed"), - )?; - self.write( - &minted_key, - minted_bal.try_to_vec().expect("encoding shouldn't failed"), - ) + self.write(&target_key, target_bal.serialize_to_vec())?; + self.write(&minted_key, minted_bal.serialize_to_vec()) } /// Get the current height of this chain diff --git a/shared/src/ledger/native_vp/ibc/mod.rs b/shared/src/ledger/native_vp/ibc/mod.rs index 3b6521905b..f370e79823 100644 --- a/shared/src/ledger/native_vp/ibc/mod.rs +++ b/shared/src/ledger/native_vp/ibc/mod.rs @@ -291,7 +291,7 @@ mod tests { use std::convert::TryFrom; use std::str::FromStr; - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use namada_core::ledger::gas::TxGasMeter; use prost::Message; use sha2::Digest; @@ -423,7 +423,7 @@ mod tests { }; wl_storage .write_log - .write(&epoch_duration_key, epoch_duration.try_to_vec().unwrap()) + .write(&epoch_duration_key, epoch_duration.serialize_to_vec()) .expect("write failed"); // max_expected_time_per_block let time = DurationSecs::from(Duration::new(60, 0)); @@ -1004,7 +1004,7 @@ mod tests { // client connection list let client_conn_key = client_connections_key(&msg.client_id_on_a); let conn_list = conn_id.to_string(); - let bytes = conn_list.try_to_vec().expect("encoding failed"); + let bytes = conn_list.serialize_to_vec(); wl_storage .write_log .write(&client_conn_key, bytes) @@ -1115,7 +1115,7 @@ mod tests { // client connection list let client_conn_key = client_connections_key(&msg.client_id_on_a); let conn_list = conn_id.to_string(); - let bytes = conn_list.try_to_vec().expect("encoding failed"); + let bytes = conn_list.serialize_to_vec(); wl_storage .write_log .write(&client_conn_key, bytes) @@ -1230,7 +1230,7 @@ mod tests { // client connection list let client_conn_key = client_connections_key(&msg.client_id_on_b); let conn_list = conn_id.to_string(); - let bytes = conn_list.try_to_vec().expect("encoding failed"); + let bytes = conn_list.serialize_to_vec(); wl_storage .write_log .write(&client_conn_key, bytes) @@ -1981,7 +1981,7 @@ mod tests { let amount = Amount::native_whole(100); wl_storage .write_log - .write(&balance_key, amount.try_to_vec().unwrap()) + .write(&balance_key, amount.serialize_to_vec()) .expect("write failed"); wl_storage.write_log.commit_tx(); wl_storage.commit_block().expect("commit failed"); @@ -2192,7 +2192,7 @@ mod tests { )); let trace_hash = calc_hash(coin.denom.to_string()); let denom_key = ibc_denom_key(&trace_hash); - let bytes = coin.denom.to_string().try_to_vec().unwrap(); + let bytes = coin.denom.to_string().serialize_to_vec(); wl_storage .write_log .write(&denom_key, bytes) @@ -2455,7 +2455,7 @@ mod tests { let amount = Amount::native_whole(100); wl_storage .write_log - .write(&balance_key, amount.try_to_vec().unwrap()) + .write(&balance_key, amount.serialize_to_vec()) .expect("write failed"); // commitment let transfer_msg = MsgTransfer { @@ -2606,7 +2606,7 @@ mod tests { let amount = Amount::native_whole(100); wl_storage .write_log - .write(&balance_key, amount.try_to_vec().unwrap()) + .write(&balance_key, amount.serialize_to_vec()) .expect("write failed"); // commitment let sender = established_address_1(); diff --git a/shared/src/ledger/native_vp/multitoken.rs b/shared/src/ledger/native_vp/multitoken.rs index 564024fd8f..d3782c9548 100644 --- a/shared/src/ledger/native_vp/multitoken.rs +++ b/shared/src/ledger/native_vp/multitoken.rs @@ -139,7 +139,7 @@ where mod tests { use std::collections::BTreeSet; - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use namada_core::ledger::gas::TxGasMeter; use super::*; @@ -187,14 +187,14 @@ mod tests { let amount = Amount::native_whole(100); wl_storage .storage - .write(&sender_key, amount.try_to_vec().unwrap()) + .write(&sender_key, amount.serialize_to_vec()) .expect("write failed"); // transfer 10 let amount = Amount::native_whole(90); wl_storage .write_log - .write(&sender_key, amount.try_to_vec().unwrap()) + .write(&sender_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(sender_key); let receiver = established_address_2(); @@ -202,7 +202,7 @@ mod tests { let amount = Amount::native_whole(10); wl_storage .write_log - .write(&receiver_key, amount.try_to_vec().unwrap()) + .write(&receiver_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(receiver_key); @@ -243,14 +243,14 @@ mod tests { let amount = Amount::native_whole(100); wl_storage .storage - .write(&sender_key, amount.try_to_vec().unwrap()) + .write(&sender_key, amount.serialize_to_vec()) .expect("write failed"); // transfer 10 let amount = Amount::native_whole(90); wl_storage .write_log - .write(&sender_key, amount.try_to_vec().unwrap()) + .write(&sender_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(sender_key); let receiver = established_address_2(); @@ -259,7 +259,7 @@ mod tests { let amount = Amount::native_whole(100); wl_storage .write_log - .write(&receiver_key, amount.try_to_vec().unwrap()) + .write(&receiver_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(receiver_key); @@ -303,14 +303,14 @@ mod tests { let amount = Amount::native_whole(100); wl_storage .write_log - .write(&target_key, amount.try_to_vec().unwrap()) + .write(&target_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(target_key); let minted_key = minted_balance_key(&token); let amount = Amount::native_whole(100); wl_storage .write_log - .write(&minted_key, amount.try_to_vec().unwrap()) + .write(&minted_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(minted_key); @@ -319,7 +319,7 @@ mod tests { let minter_key = minter_key(&token); wl_storage .write_log - .write(&minter_key, minter.try_to_vec().unwrap()) + .write(&minter_key, minter.serialize_to_vec()) .expect("write failed"); keys_changed.insert(minter_key); @@ -363,14 +363,14 @@ mod tests { let amount = Amount::native_whole(1000); wl_storage .write_log - .write(&target_key, amount.try_to_vec().unwrap()) + .write(&target_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(target_key); let minted_key = minted_balance_key(&nam()); let amount = Amount::native_whole(100); wl_storage .write_log - .write(&minted_key, amount.try_to_vec().unwrap()) + .write(&minted_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(minted_key); @@ -379,7 +379,7 @@ mod tests { let minter_key = minter_key(&nam()); wl_storage .write_log - .write(&minter_key, minter.try_to_vec().unwrap()) + .write(&minter_key, minter.serialize_to_vec()) .expect("write failed"); keys_changed.insert(minter_key); @@ -425,14 +425,14 @@ mod tests { let amount = Amount::native_whole(100); wl_storage .write_log - .write(&target_key, amount.try_to_vec().unwrap()) + .write(&target_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(target_key); let minted_key = minted_balance_key(&token); let amount = Amount::native_whole(100); wl_storage .write_log - .write(&minted_key, amount.try_to_vec().unwrap()) + .write(&minted_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(minted_key); @@ -478,14 +478,14 @@ mod tests { let amount = Amount::native_whole(100); wl_storage .write_log - .write(&target_key, amount.try_to_vec().unwrap()) + .write(&target_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(target_key); let minted_key = minted_balance_key(&token); let amount = Amount::native_whole(100); wl_storage .write_log - .write(&minted_key, amount.try_to_vec().unwrap()) + .write(&minted_key, amount.serialize_to_vec()) .expect("write failed"); keys_changed.insert(minted_key); @@ -494,7 +494,7 @@ mod tests { let minter_key = minter_key(&token); wl_storage .write_log - .write(&minter_key, minter.try_to_vec().unwrap()) + .write(&minter_key, minter.serialize_to_vec()) .expect("write failed"); keys_changed.insert(minter_key); @@ -535,7 +535,7 @@ mod tests { let minter = established_address_1(); wl_storage .write_log - .write(&minter_key, minter.try_to_vec().unwrap()) + .write(&minter_key, minter.serialize_to_vec()) .expect("write failed"); keys_changed.insert(minter_key); @@ -580,7 +580,7 @@ mod tests { .unwrap(); wl_storage .write_log - .write(&key, 0.try_to_vec().unwrap()) + .write(&key, 0.serialize_to_vec()) .expect("write failed"); keys_changed.insert(key); diff --git a/shared/src/ledger/protocol/mod.rs b/shared/src/ledger/protocol/mod.rs index a23b026eea..6100f0cd56 100644 --- a/shared/src/ledger/protocol/mod.rs +++ b/shared/src/ledger/protocol/mod.rs @@ -2,7 +2,7 @@ use std::collections::BTreeSet; use std::panic; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use eyre::{eyre, WrapErr}; use masp_primitives::transaction::Transaction; use namada_core::ledger::gas::TxGasMeter; @@ -510,12 +510,12 @@ where Some(new_dest_balance) => { wl_storage .write_log_mut() - .write(&src_key, new_src_balance.try_to_vec().unwrap()) + .write(&src_key, new_src_balance.serialize_to_vec()) .map_err(|e| Error::FeeError(e.to_string()))?; - match wl_storage.write_log_mut().write( - &dest_key, - new_dest_balance.try_to_vec().unwrap(), - ) { + match wl_storage + .write_log_mut() + .write(&dest_key, new_dest_balance.serialize_to_vec()) + { Ok(_) => Ok(()), Err(e) => Err(Error::FeeError(e.to_string())), } diff --git a/shared/src/vm/host_env.rs b/shared/src/vm/host_env.rs index 5229c65908..3a5a9bf6ab 100644 --- a/shared/src/vm/host_env.rs +++ b/shared/src/vm/host_env.rs @@ -5,6 +5,7 @@ use std::convert::TryInto; use std::num::TryFromIntError; use borsh::{BorshDeserialize, BorshSerialize}; +use borsh_ext::BorshSerializeExt; use namada_core::ledger::gas::{GasMetering, TxGasMeter}; use namada_core::types::internal::KeyVal; use thiserror::Error; @@ -727,11 +728,10 @@ where tx_charge_gas(env, iter_gas + log_gas)?; match log_val { Some(write_log::StorageModification::Write { ref value }) => { - let key_val = KeyVal { + let key_val = borsh::to_vec(&KeyVal { key, val: value.clone(), - } - .try_to_vec() + }) .map_err(TxRuntimeError::EncodingError)?; let len: i64 = key_val .len() @@ -750,11 +750,10 @@ where continue; } Some(write_log::StorageModification::Temp { ref value }) => { - let key_val = KeyVal { + let key_val = borsh::to_vec(&KeyVal { key, val: value.clone(), - } - .try_to_vec() + }) .map_err(TxRuntimeError::EncodingError)?; let len: i64 = key_val .len() @@ -765,8 +764,7 @@ where return Ok(len); } None => { - let key_val = KeyVal { key, val } - .try_to_vec() + let key_val = borsh::to_vec(&KeyVal { key, val }) .map_err(TxRuntimeError::EncodingError)?; let len: i64 = key_val .len() @@ -995,7 +993,7 @@ where for event in write_log.get_ibc_events() { if event.event_type == event_type { let value = - event.try_to_vec().map_err(TxRuntimeError::EncodingError)?; + borsh::to_vec(event).map_err(TxRuntimeError::EncodingError)?; let len: i64 = value .len() .try_into() @@ -1341,8 +1339,7 @@ where if let Some(iter) = iterators.get_mut(iter_id) { let gas_meter = unsafe { env.ctx.gas_meter.get() }; if let Some((key, val)) = vp_host_fns::iter_next(gas_meter, iter)? { - let key_val = KeyVal { key, val } - .try_to_vec() + let key_val = borsh::to_vec(&KeyVal { key, val }) .map_err(vp_host_fns::RuntimeError::EncodingError)?; let len: i64 = key_val .len() @@ -1452,8 +1449,7 @@ where let code_hash = Hash::try_from(&code_hash[..]) .map_err(|e| TxRuntimeError::InvalidVpCodeHash(e.to_string()))?; let (addr, gas) = write_log.init_account(&storage.address_gen, code_hash); - let addr_bytes = - addr.try_to_vec().map_err(TxRuntimeError::EncodingError)?; + let addr_bytes = addr.serialize_to_vec(); tx_charge_gas(env, gas)?; let gas = env .memory @@ -1616,8 +1612,7 @@ where .map_err(TxRuntimeError::StorageError)?; Ok(match header { Some(h) => { - let value = - h.try_to_vec().map_err(TxRuntimeError::EncodingError)?; + let value = h.serialize_to_vec(); let len: i64 = value .len() .try_into() @@ -1692,9 +1687,7 @@ where vp_host_fns::add_gas(gas_meter, gas)?; Ok(match header { Some(h) => { - let value = h - .try_to_vec() - .map_err(vp_host_fns::RuntimeError::EncodingError)?; + let value = h.serialize_to_vec(); let len: i64 = value .len() .try_into() @@ -2391,7 +2384,7 @@ where H: StorageHasher, CA: WasmCacheAccess, { - let bytes = val.try_to_vec().map_err(TxRuntimeError::EncodingError)?; + let bytes = borsh::to_vec(val).map_err(TxRuntimeError::EncodingError)?; namada_core::ledger::ibc::IbcStorageContext::write(ctx, key, bytes)?; Ok(()) } diff --git a/shared/src/vm/wasm/memory.rs b/shared/src/vm/wasm/memory.rs index 3e0c7975c9..9b04160556 100644 --- a/shared/src/vm/wasm/memory.rs +++ b/shared/src/vm/wasm/memory.rs @@ -5,7 +5,7 @@ use std::ptr::NonNull; use std::str::Utf8Error; use std::sync::Arc; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use namada_core::ledger::gas::VM_MEMORY_ACCESS_GAS_PER_BYTE; use thiserror::Error; use wasmer::{ @@ -86,7 +86,7 @@ pub fn write_tx_inputs( tx_data: &Tx, ) -> Result { let tx_data_ptr = 0; - let tx_data_bytes = tx_data.try_to_vec().map_err(Error::EncodingError)?; + let tx_data_bytes = tx_data.serialize_to_vec(); let tx_data_len = tx_data_bytes.len() as _; write_memory_bytes(memory, tx_data_ptr, tx_data_bytes)?; @@ -129,20 +129,18 @@ pub fn write_vp_inputs( }: VpInput, ) -> Result { let addr_ptr = 0; - let addr_bytes = addr.try_to_vec().map_err(Error::EncodingError)?; + let addr_bytes = addr.serialize_to_vec(); let addr_len = addr_bytes.len() as _; - let data_bytes = data.try_to_vec().map_err(Error::EncodingError)?; + let data_bytes = data.serialize_to_vec(); let data_ptr = addr_ptr + addr_len; let data_len = data_bytes.len() as _; - let keys_changed_bytes = - keys_changed.try_to_vec().map_err(Error::EncodingError)?; + let keys_changed_bytes = keys_changed.serialize_to_vec(); let keys_changed_ptr = data_ptr + data_len; let keys_changed_len = keys_changed_bytes.len() as _; - let verifiers_bytes = - verifiers.try_to_vec().map_err(Error::EncodingError)?; + let verifiers_bytes = verifiers.serialize_to_vec(); let verifiers_ptr = keys_changed_ptr + keys_changed_len; let verifiers_len = verifiers_bytes.len() as _; diff --git a/shared/src/vm/wasm/run.rs b/shared/src/vm/wasm/run.rs index 7678ceb434..9740469b95 100644 --- a/shared/src/vm/wasm/run.rs +++ b/shared/src/vm/wasm/run.rs @@ -552,7 +552,7 @@ fn get_gas_rules() -> wasm_instrument::gas_metering::ConstantCostRules { #[cfg(test)] mod tests { - use borsh::BorshSerialize; + use borsh_ext::BorshSerializeExt; use itertools::Either; use namada_test_utils::TestWasms; use test_log::test; @@ -631,7 +631,7 @@ mod tests { let code_hash = Hash::sha256(&tx_code); let key = Key::wasm_code(&code_hash); let len_key = Key::wasm_code_len(&code_hash); - let code_len = (tx_code.len() as u64).try_to_vec().unwrap(); + let code_len = (tx_code.len() as u64).serialize_to_vec(); write_log.write(&key, tx_code.clone()).unwrap(); write_log.write(&len_key, code_len).unwrap(); @@ -640,7 +640,7 @@ mod tests { // Allocating `2^23` (8 MiB) should be below the memory limit and // shouldn't fail - let tx_data = 2_usize.pow(23).try_to_vec().unwrap(); + let tx_data = 2_usize.pow(23).serialize_to_vec(); let (mut vp_cache, _) = wasm::compilation_cache::common::testing::cache(); let (mut tx_cache, _) = @@ -661,7 +661,7 @@ mod tests { // Allocating `2^24` (16 MiB) should be above the memory limit and // should fail - let tx_data = 2_usize.pow(24).try_to_vec().unwrap(); + let tx_data = 2_usize.pow(24).serialize_to_vec(); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.set_code(Code::new(tx_code)); outer_tx.set_data(Data::new(tx_data)); @@ -700,7 +700,7 @@ mod tests { let code_hash = Hash::sha256(&vp_eval); let key = Key::wasm_code(&code_hash); let len_key = Key::wasm_code_len(&code_hash); - let code_len = (vp_eval.len() as u64).try_to_vec().unwrap(); + let code_len = (vp_eval.len() as u64).serialize_to_vec(); storage.write(&key, vp_eval).unwrap(); storage.write(&len_key, code_len).unwrap(); // This code will allocate memory of the given size @@ -709,7 +709,7 @@ mod tests { let limit_code_hash = Hash::sha256(&vp_memory_limit); let key = Key::wasm_code(&limit_code_hash); let len_key = Key::wasm_code_len(&limit_code_hash); - let code_len = (vp_memory_limit.len() as u64).try_to_vec().unwrap(); + let code_len = (vp_memory_limit.len() as u64).serialize_to_vec(); storage.write(&key, vp_memory_limit).unwrap(); storage.write(&len_key, code_len).unwrap(); @@ -718,7 +718,7 @@ mod tests { // Allocating `2^23` (8 MiB) should be below the memory limit and // shouldn't fail - let input = 2_usize.pow(23).try_to_vec().unwrap(); + let input = 2_usize.pow(23).serialize_to_vec(); let mut tx = Tx::new(storage.chain_id.clone(), None); tx.add_code(vec![]).add_serialized_data(input); @@ -751,7 +751,7 @@ mod tests { // Allocating `2^24` (16 MiB) should be above the memory limit and // should fail - let input = 2_usize.pow(24).try_to_vec().unwrap(); + let input = 2_usize.pow(24).serialize_to_vec(); let mut tx = Tx::new(storage.chain_id.clone(), None); tx.add_code(vec![]).add_data(input); @@ -801,7 +801,7 @@ mod tests { let vp_code = TestWasms::VpMemoryLimit.read_bytes(); // store the wasm code let code_hash = Hash::sha256(&vp_code); - let code_len = (vp_code.len() as u64).try_to_vec().unwrap(); + let code_len = (vp_code.len() as u64).serialize_to_vec(); let key = Key::wasm_code(&code_hash); let len_key = Key::wasm_code_len(&code_hash); storage.write(&key, vp_code).unwrap(); @@ -812,7 +812,7 @@ mod tests { // Allocating `2^23` (8 MiB) should be below the memory limit and // shouldn't fail - let tx_data = 2_usize.pow(23).try_to_vec().unwrap(); + let tx_data = 2_usize.pow(23).serialize_to_vec(); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = storage.chain_id.clone(); outer_tx.set_data(Data::new(tx_data)); @@ -834,7 +834,7 @@ mod tests { // Allocating `2^24` (16 MiB) should be above the memory limit and // should fail - let tx_data = 2_usize.pow(24).try_to_vec().unwrap(); + let tx_data = 2_usize.pow(24).serialize_to_vec(); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = storage.chain_id.clone(); outer_tx.set_data(Data::new(tx_data)); @@ -869,7 +869,7 @@ mod tests { let code_hash = Hash::sha256(&tx_no_op); let key = Key::wasm_code(&code_hash); let len_key = Key::wasm_code_len(&code_hash); - let code_len = (tx_no_op.len() as u64).try_to_vec().unwrap(); + let code_len = (tx_no_op.len() as u64).serialize_to_vec(); write_log.write(&key, tx_no_op.clone()).unwrap(); write_log.write(&len_key, code_len).unwrap(); @@ -934,7 +934,7 @@ mod tests { let code_hash = Hash::sha256(&vp_code); let key = Key::wasm_code(&code_hash); let len_key = Key::wasm_code_len(&code_hash); - let code_len = (vp_code.len() as u64).try_to_vec().unwrap(); + let code_len = (vp_code.len() as u64).serialize_to_vec(); storage.write(&key, vp_code).unwrap(); storage.write(&len_key, code_len).unwrap(); @@ -996,7 +996,7 @@ mod tests { let tx_read_key = TestWasms::TxReadStorageKey.read_bytes(); // store the wasm code let code_hash = Hash::sha256(&tx_read_key); - let code_len = (tx_read_key.len() as u64).try_to_vec().unwrap(); + let code_len = (tx_read_key.len() as u64).serialize_to_vec(); let key = Key::wasm_code(&code_hash); let len_key = Key::wasm_code_len(&code_hash); write_log.write(&key, tx_read_key.clone()).unwrap(); @@ -1012,8 +1012,8 @@ mod tests { // Write the value that should be read by the tx into the storage. When // writing directly to storage, the value has to be encoded with // Borsh. - storage.write(&key, value.try_to_vec().unwrap()).unwrap(); - let tx_data = key.try_to_vec().unwrap(); + storage.write(&key, value.serialize_to_vec()).unwrap(); + let tx_data = key.serialize_to_vec(); let (mut vp_cache, _) = wasm::compilation_cache::common::testing::cache(); let (mut tx_cache, _) = @@ -1053,7 +1053,7 @@ mod tests { let vp_read_key = TestWasms::VpReadStorageKey.read_bytes(); // store the wasm code let code_hash = Hash::sha256(&vp_read_key); - let code_len = (vp_read_key.len() as u64).try_to_vec().unwrap(); + let code_len = (vp_read_key.len() as u64).serialize_to_vec(); let key = Key::wasm_code(&code_hash); let len_key = Key::wasm_code_len(&code_hash); storage.write(&key, vp_read_key).unwrap(); @@ -1069,8 +1069,8 @@ mod tests { // Write the value that should be read by the tx into the storage. When // writing directly to storage, the value has to be encoded with // Borsh. - storage.write(&key, value.try_to_vec().unwrap()).unwrap(); - let tx_data = key.try_to_vec().unwrap(); + storage.write(&key, value.serialize_to_vec()).unwrap(); + let tx_data = key.serialize_to_vec(); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = storage.chain_id.clone(); outer_tx.set_data(Data::new(tx_data)); @@ -1113,7 +1113,7 @@ mod tests { let vp_eval = TestWasms::VpEval.read_bytes(); // store the wasm code let code_hash = Hash::sha256(&vp_eval); - let code_len = (vp_eval.len() as u64).try_to_vec().unwrap(); + let code_len = (vp_eval.len() as u64).serialize_to_vec(); let key = Key::wasm_code(&code_hash); let len_key = Key::wasm_code_len(&code_hash); storage.write(&key, vp_eval).unwrap(); @@ -1122,7 +1122,7 @@ mod tests { let vp_read_key = TestWasms::VpReadStorageKey.read_bytes(); // store the wasm code let read_code_hash = Hash::sha256(&vp_read_key); - let code_len = (vp_read_key.len() as u64).try_to_vec().unwrap(); + let code_len = (vp_read_key.len() as u64).serialize_to_vec(); let key = Key::wasm_code(&read_code_hash); let len_key = Key::wasm_code_len(&read_code_hash); storage.write(&key, vp_read_key).unwrap(); @@ -1138,8 +1138,8 @@ mod tests { // Write the value that should be read by the tx into the storage. When // writing directly to storage, the value has to be encoded with // Borsh. - storage.write(&key, value.try_to_vec().unwrap()).unwrap(); - let input = 2_usize.pow(23).try_to_vec().unwrap(); + storage.write(&key, value.serialize_to_vec()).unwrap(); + let input = 2_usize.pow(23).serialize_to_vec(); let mut tx = Tx::new(storage.chain_id.clone(), None); tx.add_code(vec![]).add_serialized_data(input); @@ -1216,7 +1216,7 @@ mod tests { // store the tx code let code_hash = Hash::sha256(&tx_code); - let code_len = (tx_code.len() as u64).try_to_vec().unwrap(); + let code_len = (tx_code.len() as u64).serialize_to_vec(); let key = Key::wasm_code(&code_hash); let len_key = Key::wasm_code_len(&code_hash); write_log.write(&key, tx_code).unwrap(); @@ -1279,7 +1279,7 @@ mod tests { let (vp_cache, _) = wasm::compilation_cache::common::testing::cache(); // store the vp code let code_hash = Hash::sha256(&vp_code); - let code_len = (vp_code.len() as u64).try_to_vec().unwrap(); + let code_len = (vp_code.len() as u64).serialize_to_vec(); let key = Key::wasm_code(&code_hash); let len_key = Key::wasm_code_len(&code_hash); storage.write(&key, vp_code).unwrap(); diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index 8e0a9c6719..3b81ee176e 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml @@ -14,5 +14,5 @@ version.workspace = true [dependencies] namada_core = { path = "../core", default-features = false, features = ["abciplus"] } -borsh = "0.9.0" +borsh.workspace = true strum = {version = "0.24", features = ["derive"]} diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 5ab740b9ca..2c21ea9d97 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -59,6 +59,7 @@ tracing.workspace = true namada_apps = {path = "../apps", features = ["testing"]} assert_cmd.workspace = true borsh.workspace = true +borsh-ext.workspace = true color-eyre.workspace = true data-encoding.workspace = true # NOTE: enable "print" feature to see output from builds ran by e2e tests diff --git a/tests/src/e2e/eth_bridge_tests/helpers.rs b/tests/src/e2e/eth_bridge_tests/helpers.rs index a52273366c..04047a1722 100644 --- a/tests/src/e2e/eth_bridge_tests/helpers.rs +++ b/tests/src/e2e/eth_bridge_tests/helpers.rs @@ -55,7 +55,7 @@ impl EventsEndpointClient { /// Sends an Ethereum event to the Namada node. Returns `Ok` iff the event /// was successfully sent. pub async fn send(&mut self, event: &EthereumEvent) -> Result<()> { - let event = event.try_to_vec()?; + let event = event.serialize_to_vec()?; let req = Request::builder() .method(Method::POST) diff --git a/tests/src/e2e/ledger_tests.rs b/tests/src/e2e/ledger_tests.rs index 7bfbf12e2b..8d9af9a96e 100644 --- a/tests/src/e2e/ledger_tests.rs +++ b/tests/src/e2e/ledger_tests.rs @@ -16,7 +16,7 @@ use std::str::FromStr; use std::sync::Arc; use std::time::{Duration, Instant}; -use borsh::BorshSerialize; +use borsh_ext::BorshSerializeExt; use color_eyre::eyre::Result; use data_encoding::HEXLOWER; use namada::types::address::Address; @@ -436,8 +436,7 @@ fn ledger_txs_and_queries() -> Result<()> { key: None, shielded: None, } - .try_to_vec() - .unwrap(); + .serialize_to_vec(); let tx_data_path = test.test_dir.path().join("tx.data"); std::fs::write(&tx_data_path, transfer).unwrap(); let tx_data_path = tx_data_path.to_string_lossy(); @@ -664,7 +663,7 @@ fn ledger_txs_and_queries() -> Result<()> { &validator_one_rpc, ], // expect hex encoded of borsh encoded bytes - HEXLOWER.encode(&christel_balance.try_to_vec().unwrap()), + HEXLOWER.encode(&christel_balance.serialize_to_vec()), ), ]; for (query_args, expected) in &query_args_and_expected_response { diff --git a/tests/src/e2e/multitoken_tests/helpers.rs b/tests/src/e2e/multitoken_tests/helpers.rs index 7ce90bcc87..0856691dd5 100644 --- a/tests/src/e2e/multitoken_tests/helpers.rs +++ b/tests/src/e2e/multitoken_tests/helpers.rs @@ -102,9 +102,9 @@ pub fn mint_red_tokens( test, TxWriteData { key: red_balance_key, - value: amount.try_to_vec()?, + value: amount.serialize_to_vec()?, } - .try_to_vec()?, + .serialize_to_vec()?, )?; let tx_data_path = tx_data_path.to_string_lossy().to_string(); diff --git a/tests/src/native_vp/eth_bridge_pool.rs b/tests/src/native_vp/eth_bridge_pool.rs index 6fc304f909..3de46fc84b 100644 --- a/tests/src/native_vp/eth_bridge_pool.rs +++ b/tests/src/native_vp/eth_bridge_pool.rs @@ -2,7 +2,8 @@ mod test_bridge_pool_vp { use std::path::PathBuf; - use borsh::{BorshDeserialize, BorshSerialize}; + use borsh::BorshDeserialize; + use borsh_ext::BorshSerializeExt; use namada::core::ledger::eth_bridge::storage::bridge_pool::BRIDGE_POOL_ADDRESS; use namada::ledger::native_vp::ethereum_bridge::bridge_pool_vp::BridgePoolVp; use namada::proto::Tx; @@ -124,7 +125,7 @@ mod test_bridge_pool_vp { } fn create_tx(transfer: PendingTransfer, keypair: &common::SecretKey) -> Tx { - let data = transfer.try_to_vec().expect("Test failed"); + let data = transfer.serialize_to_vec(); let wasm_code = wasm_loader::read_wasm_or_exit(wasm_dir(), ADD_TRANSFER_WASM); diff --git a/tests/src/vm_host_env/ibc.rs b/tests/src/vm_host_env/ibc.rs index b8d88961ea..25f8d09fcf 100644 --- a/tests/src/vm_host_env/ibc.rs +++ b/tests/src/vm_host_env/ibc.rs @@ -85,7 +85,7 @@ use namada::types::token::{self, Amount, DenominatedAmount}; use namada::vm::{wasm, WasmCacheRwAccess}; use namada_core::ledger::gas::TxGasMeter; use namada_test_utils::TestWasms; -use namada_tx_prelude::BorshSerialize; +use namada_tx_prelude::borsh_ext::BorshSerializeExt; use crate::tx::*; @@ -243,11 +243,11 @@ pub fn init_storage() -> (Address, Address) { tx_host_env::with(|env| { env.wl_storage .storage - .write(&denom_key, &token_denom.try_to_vec().unwrap()) + .write(&denom_key, &token_denom.serialize_to_vec()) .unwrap(); env.wl_storage .storage - .write(&key, &init_bal.try_to_vec().unwrap()) + .write(&key, &init_bal.serialize_to_vec()) .unwrap(); }); @@ -257,7 +257,7 @@ pub fn init_storage() -> (Address, Address) { min_num_of_blocks: 10, min_duration: DurationSecs(100), }; - let bytes = epoch_duration.try_to_vec().unwrap(); + let bytes = epoch_duration.serialize_to_vec(); tx_host_env::with(|env| { env.wl_storage.storage.write(&key, &bytes).unwrap(); }); diff --git a/tests/src/vm_host_env/mod.rs b/tests/src/vm_host_env/mod.rs index 68ebd76dff..e95513364e 100644 --- a/tests/src/vm_host_env/mod.rs +++ b/tests/src/vm_host_env/mod.rs @@ -21,6 +21,7 @@ mod tests { use std::collections::BTreeSet; use std::panic; + use borsh_ext::BorshSerializeExt; use itertools::Itertools; use namada::ibc::core::Msg; use namada::ledger::ibc::storage as ibc_storage; @@ -41,9 +42,7 @@ mod tests { use namada_test_utils::TestWasms; use namada_tx_prelude::address::InternalAddress; use namada_tx_prelude::chain::ChainId; - use namada_tx_prelude::{ - Address, BorshSerialize, StorageRead, StorageWrite, - }; + use namada_tx_prelude::{Address, StorageRead, StorageWrite}; use namada_vp_prelude::account::AccountPublicKeysMap; use namada_vp_prelude::VpEnv; use prost::Message; @@ -577,7 +576,7 @@ mod tests { // evaluating the VP template which always returns `true` should pass let code = TestWasms::VpAlwaysTrue.read_bytes(); let code_hash = Hash::sha256(&code); - let code_len = (code.len() as u64).try_to_vec().unwrap(); + let code_len = (code.len() as u64).serialize_to_vec(); vp_host_env::with(|env| { // store wasm codes let key = Key::wasm_code(&code_hash); @@ -600,7 +599,7 @@ mod tests { // pass let code = TestWasms::VpAlwaysFalse.read_bytes(); let code_hash = Hash::sha256(&code); - let code_len = (code.len() as u64).try_to_vec().unwrap(); + let code_len = (code.len() as u64).serialize_to_vec(); vp_host_env::with(|env| { // store wasm codes let key = Key::wasm_code(&code_hash); @@ -1250,20 +1249,18 @@ mod tests { let ibc_token = ibc_storage::ibc_token(&denom); let balance_key = token::balance_key(&ibc_token, &sender); let init_bal = Amount::from_u64(100); - writes.insert(balance_key.clone(), init_bal.try_to_vec().unwrap()); + writes.insert(balance_key.clone(), init_bal.serialize_to_vec()); let minted_key = token::minted_balance_key(&ibc_token); - writes.insert(minted_key.clone(), init_bal.try_to_vec().unwrap()); + writes.insert(minted_key.clone(), init_bal.serialize_to_vec()); let minter_key = token::minter_key(&ibc_token); writes.insert( minter_key, - Address::Internal(InternalAddress::Ibc) - .try_to_vec() - .unwrap(), + Address::Internal(InternalAddress::Ibc).serialize_to_vec(), ); // original denom let hash = ibc_storage::calc_hash(&denom); let denom_key = ibc_storage::ibc_denom_key(hash); - writes.insert(denom_key, denom.try_to_vec().unwrap()); + writes.insert(denom_key, denom.serialize_to_vec()); writes.into_iter().for_each(|(key, val)| { tx_host_env::with(|env| { env.wl_storage @@ -1505,8 +1502,7 @@ mod tests { ); let val = Amount::from_uint(100, ibc::ANY_DENOMINATION) .unwrap() - .try_to_vec() - .unwrap(); + .serialize_to_vec(); tx_host_env::with(|env| { env.wl_storage .storage @@ -1608,7 +1604,7 @@ mod tests { denom, &address::Address::Internal(address::InternalAddress::Ibc), ); - let val = Amount::from_u64(100).try_to_vec().unwrap(); + let val = Amount::from_u64(100).serialize_to_vec(); tx_host_env::with(|env| { env.wl_storage .storage diff --git a/tests/src/vm_host_env/tx.rs b/tests/src/vm_host_env/tx.rs index 582b668b79..6bf46c96c1 100644 --- a/tests/src/vm_host_env/tx.rs +++ b/tests/src/vm_host_env/tx.rs @@ -18,7 +18,8 @@ use namada::vm::prefix_iter::PrefixIterators; use namada::vm::wasm::run::Error; use namada::vm::wasm::{self, TxCache, VpCache}; use namada::vm::{self, WasmCacheRwAccess}; -use namada_tx_prelude::{storage_api, BorshSerialize, Ctx}; +use namada_tx_prelude::borsh_ext::BorshSerializeExt; +use namada_tx_prelude::{storage_api, Ctx}; use namada_vp_prelude::key::common; use tempfile::TempDir; @@ -186,7 +187,7 @@ impl TestTxEnv { let storage_key = key::threshold_key(address); self.wl_storage .storage - .write(&storage_key, threshold.try_to_vec().unwrap()) + .write(&storage_key, threshold.serialize_to_vec()) .unwrap(); } @@ -216,7 +217,7 @@ impl TestTxEnv { let storage_key = token::balance_key(token, target); self.wl_storage .storage - .write(&storage_key, amount.try_to_vec().unwrap()) + .write(&storage_key, amount.serialize_to_vec()) .unwrap(); } diff --git a/tx_prelude/Cargo.toml b/tx_prelude/Cargo.toml index 5fa5d24d68..981b9c0c79 100644 --- a/tx_prelude/Cargo.toml +++ b/tx_prelude/Cargo.toml @@ -26,6 +26,7 @@ namada_macros = {path = "../macros"} namada_proof_of_stake = {path = "../proof_of_stake", default-features = false} namada_vm_env = {path = "../vm_env", default-features = false} borsh.workspace = true +borsh-ext.workspace = true masp_primitives.workspace = true sha2.workspace = true thiserror.workspace = true diff --git a/tx_prelude/src/lib.rs b/tx_prelude/src/lib.rs index 87d91e07a3..fc11d301a5 100644 --- a/tx_prelude/src/lib.rs +++ b/tx_prelude/src/lib.rs @@ -17,6 +17,8 @@ use core::slice; use std::marker::PhantomData; pub use borsh::{BorshDeserialize, BorshSerialize}; +pub use borsh_ext; +use borsh_ext::BorshSerializeExt; pub use namada_core::ledger::eth_bridge; pub use namada_core::ledger::governance::storage as gov_storage; pub use namada_core::ledger::parameters::storage as parameters_storage; @@ -248,7 +250,7 @@ impl TxEnv for Ctx { key: &storage::Key, val: T, ) -> Result<(), Error> { - let buf = val.try_to_vec().unwrap(); + let buf = val.serialize_to_vec(); self.write_bytes_temp(key, buf) } @@ -319,7 +321,7 @@ impl TxEnv for Ctx { } fn emit_ibc_event(&mut self, event: &ibc::IbcEvent) -> Result<(), Error> { - let event = BorshSerialize::try_to_vec(event).unwrap(); + let event = borsh::to_vec(event).unwrap(); unsafe { namada_tx_emit_ibc_event(event.as_ptr() as _, event.len() as _) }; diff --git a/vp_prelude/Cargo.toml b/vp_prelude/Cargo.toml index ecffd8eaa4..5384395b22 100644 --- a/vp_prelude/Cargo.toml +++ b/vp_prelude/Cargo.toml @@ -26,5 +26,6 @@ namada_macros = {path = "../macros"} namada_proof_of_stake = {path = "../proof_of_stake", default-features = false} namada_vm_env = {path = "../vm_env", default-features = false} borsh.workspace = true +borsh-ext.workspace = true sha2.workspace = true thiserror.workspace = true diff --git a/vp_prelude/src/lib.rs b/vp_prelude/src/lib.rs index 0962628363..9a9244c3a0 100644 --- a/vp_prelude/src/lib.rs +++ b/vp_prelude/src/lib.rs @@ -14,6 +14,8 @@ use std::convert::TryFrom; use std::marker::PhantomData; pub use borsh::{BorshDeserialize, BorshSerialize}; +pub use borsh_ext; +use borsh_ext::BorshSerializeExt; pub use namada_core::ledger::governance::storage as gov_storage; pub use namada_core::ledger::parameters; pub use namada_core::ledger::pgf::storage as pgf_storage; @@ -91,10 +93,10 @@ pub fn verify_signatures(ctx: &Ctx, tx: &Tx, owner: &Address) -> VpResult { let targets = [*tx.data_sechash(), *tx.code_sechash()]; // Serialize parameters - let max_signatures = max_signatures_per_transaction.try_to_vec().unwrap(); - let public_keys_map = public_keys_index_map.try_to_vec().unwrap(); - let targets = targets.try_to_vec().unwrap(); - let signer = owner.try_to_vec().unwrap(); + let max_signatures = max_signatures_per_transaction.serialize_to_vec(); + let public_keys_map = public_keys_index_map.serialize_to_vec(); + let targets = targets.serialize_to_vec(); + let signer = owner.serialize_to_vec(); let valid = unsafe { namada_vp_verify_tx_section_signature( @@ -305,7 +307,7 @@ impl<'view> VpEnv<'view> for Ctx { } fn eval(&self, vp_code_hash: Hash, input_data: Tx) -> Result { - let input_data_bytes = BorshSerialize::try_to_vec(&input_data).unwrap(); + let input_data_bytes = borsh::to_vec(&input_data).unwrap(); let result = unsafe { namada_vp_eval( vp_code_hash.0.as_ptr() as _, diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 936d316b62..d29e22cdb1 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -37,18 +37,6 @@ dependencies = [ "generic-array 0.14.7", ] -[[package]] -name = "aes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" -dependencies = [ - "cfg-if 1.0.0", - "cipher 0.3.0", - "cpufeatures", - "opaque-debug 0.3.0", -] - [[package]] name = "aes" version = "0.8.3" @@ -377,15 +365,15 @@ checksum = "cf9ff0bbfd639f15c74af777d81383cf53efb7c93613f6cab67c6c11e05bbf8b" [[package]] name = "bellman" -version = "0.13.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4dd656ef4fdf7debb6d87d4dd92642fcbcdb78cbf6600c13e25c87e4d1a3807" +checksum = "9afceed28bac7f9f5a508bca8aeeff51cdfa4770c0b967ac55c621e2ddfd6171" dependencies = [ "bitvec 1.0.1", "blake2s_simd", "byteorder", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "pairing", "rand_core 0.6.4", "subtle 2.4.1", @@ -411,14 +399,14 @@ dependencies = [ [[package]] name = "bip0039" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0830ae4cc96b0617cc912970c2b17e89456fecbf55e8eed53a956f37ab50c41" +checksum = "bef0f0152ec5cf17f49a5866afaa3439816207fd4f0a224c0211ffaf5e278426" dependencies = [ - "hmac 0.11.0", - "pbkdf2 0.9.0", + "hmac 0.12.1", + "pbkdf2 0.10.1", "rand 0.8.5", - "sha2 0.9.9", + "sha2 0.10.6", "unicode-normalization", "zeroize", ] @@ -517,7 +505,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ - "block-padding 0.1.5", + "block-padding", "byte-tools", "byteorder", "generic-array 0.12.4", @@ -541,16 +529,6 @@ dependencies = [ "generic-array 0.14.7", ] -[[package]] -name = "block-modes" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb03d1bed155d89dce0f845b7899b18a9a163e148fd004e1c28421a783e2d8e" -dependencies = [ - "block-padding 0.2.1", - "cipher 0.3.0", -] - [[package]] name = "block-padding" version = "0.1.5" @@ -560,20 +538,14 @@ dependencies = [ "byte-tools", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "bls12_381" -version = "0.7.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3c196a77437e7cc2fb515ce413a6401291578b5afc8ecb29a3c7ab957f05941" +checksum = "d7bc6d6292be3a19e6379786dac800f551e5865a5bb51ebbe3064ab80433f403" dependencies = [ - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "pairing", "rand_core 0.6.4", "subtle 2.4.1", @@ -581,10 +553,11 @@ dependencies = [ [[package]] name = "borsh" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" dependencies = [ - "borsh-derive 0.9.4", + "borsh-derive 0.9.3", "hashbrown 0.11.2", ] @@ -598,13 +571,24 @@ dependencies = [ "hashbrown 0.12.3", ] +[[package]] +name = "borsh" +version = "1.0.0-alpha.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41898277107b0d3f027593697912977397eba6ac39a55bdd2eb02c1d5d5013b5" +dependencies = [ + "borsh-derive 1.0.0-alpha.4", + "cfg_aliases", +] + [[package]] name = "borsh-derive" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" dependencies = [ - "borsh-derive-internal 0.9.4", - "borsh-schema-derive-internal 0.9.4", + "borsh-derive-internal 0.9.3", + "borsh-schema-derive-internal 0.9.3", "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.109", @@ -623,10 +607,25 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-derive" +version = "1.0.0-alpha.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413cb435569fe499e89235f758304e0e7198016baa351d8f5827ea0f40526ce0" +dependencies = [ + "once_cell", + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 2.0.16", + "syn_derive", +] + [[package]] name = "borsh-derive-internal" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" dependencies = [ "proc-macro2", "quote", @@ -644,10 +643,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-ext" +version = "1.0.0-alpha.4" +source = "git+https://github.com/heliaxdev/borsh-ext?tag=v1.0.0-alpha.4#6bebf357002f96574ac37a28f547b6c88e91b799" +dependencies = [ + "borsh 1.0.0-alpha.4", +] + [[package]] name = "borsh-schema-derive-internal" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" dependencies = [ "proc-macro2", "quote", @@ -761,6 +769,15 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher 0.4.4", +] + [[package]] name = "cc" version = "1.0.79" @@ -779,6 +796,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chacha20" version = "0.8.2" @@ -1200,16 +1223,6 @@ dependencies = [ "subtle 2.4.1", ] -[[package]] -name = "crypto-mac" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" -dependencies = [ - "generic-array 0.14.7", - "subtle 2.4.1", -] - [[package]] name = "ct-codecs" version = "1.1.1" @@ -1508,9 +1521,9 @@ dependencies = [ "base16ct", "crypto-bigint", "digest 0.10.6", - "ff 0.13.0", + "ff", "generic-array 0.14.7", - "group 0.13.0", + "group", "pkcs8", "rand_core 0.6.4", "sec1", @@ -1629,7 +1642,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fda3bf123be441da5260717e0661c25a2fd9cb2b2c1d20bf2e05580047158ab" dependencies = [ - "aes 0.8.3", + "aes", "ctr", "digest 0.10.6", "hex", @@ -1987,14 +2000,14 @@ dependencies = [ "bincode", "blake2", "blake2b_simd", - "borsh 0.9.4", + "borsh 0.9.3", "digest 0.10.6", "ed25519-dalek", "either", "ferveo-common", "group-threshold-cryptography", "hex", - "itertools", + "itertools 0.10.5", "measure_time", "miracl_core", "num 0.4.0", @@ -2021,23 +2034,13 @@ dependencies = [ "serde_bytes", ] -[[package]] -name = "ff" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" -dependencies = [ - "bitvec 1.0.1", - "rand_core 0.6.4", - "subtle 2.4.1", -] - [[package]] name = "ff" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ + "bitvec 1.0.1", "rand_core 0.6.4", "subtle 2.4.1", ] @@ -2087,12 +2090,12 @@ dependencies = [ [[package]] name = "fpe" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd910db5f9ca4dc3116f8c46367825807aa2b942f72565f16b4be0b208a00a9e" +checksum = "26c4b37de5ae15812a764c958297cfc50f5c010438f60c6ce75d11b802abd404" dependencies = [ - "block-modes", - "cipher 0.3.0", + "cbc", + "cipher 0.4.4", "libm", "num-bigint 0.4.3", "num-integer", @@ -2298,25 +2301,14 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "group" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" -dependencies = [ - "ff 0.12.1", - "memuse", - "rand_core 0.6.4", - "subtle 2.4.1", -] - [[package]] name = "group" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "ff 0.13.0", + "ff", + "memuse", "rand_core 0.6.4", "subtle 2.4.1", ] @@ -2336,7 +2328,7 @@ dependencies = [ "blake2b_simd", "chacha20 0.8.2", "hex", - "itertools", + "itertools 0.10.5", "miracl_core", "rand 0.8.5", "rand_core 0.6.4", @@ -2495,16 +2487,6 @@ dependencies = [ "digest 0.9.0", ] -[[package]] -name = "hmac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" -dependencies = [ - "crypto-mac 0.11.1", - "digest 0.9.0", -] - [[package]] name = "hmac" version = "0.12.1" @@ -2795,10 +2777,10 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "index-set" -version = "0.7.1" -source = "git+https://github.com/heliaxdev/index-set?tag=v0.7.1#dc24cdbbe3664514d59f1a4c4031863fc565f1c2" +version = "0.8.0" +source = "git+https://github.com/heliaxdev/index-set?tag=v0.8.0#0c218cc300c1bb7a1acf34f21b6e9d489df5fda8" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "serde", ] @@ -2891,6 +2873,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.6" @@ -2908,14 +2899,14 @@ dependencies = [ [[package]] name = "jubjub" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a575df5f985fe1cd5b2b05664ff6accfc46559032b954529fd225a2168d27b0f" +checksum = "8499f7a74008aafbecb2a2e608a3e13e4dd3e84df198b604451efe93f2de6e61" dependencies = [ "bitvec 1.0.1", "bls12_381", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "rand_core 0.6.4", "subtle 2.4.1", ] @@ -3049,9 +3040,9 @@ dependencies = [ [[package]] name = "masp_note_encryption" version = "0.2.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=449a7295fe24d96456ece24c223ca9eb76b0e6ba#449a7295fe24d96456ece24c223ca9eb76b0e6ba" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "chacha20 0.9.1", "chacha20poly1305", "cipher 0.4.4", @@ -3062,19 +3053,19 @@ dependencies = [ [[package]] name = "masp_primitives" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=449a7295fe24d96456ece24c223ca9eb76b0e6ba#449a7295fe24d96456ece24c223ca9eb76b0e6ba" dependencies = [ - "aes 0.7.5", + "aes", "bip0039", "bitvec 1.0.1", "blake2b_simd", "blake2s_simd", "bls12_381", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "byteorder", - "ff 0.12.1", + "ff", "fpe", - "group 0.12.1", + "group", "hex", "incrementalmerkletree", "jubjub", @@ -3085,7 +3076,7 @@ dependencies = [ "num-traits", "rand 0.8.5", "rand_core 0.6.4", - "sha2 0.9.9", + "sha2 0.10.6", "subtle 2.4.1", "zcash_encoding", ] @@ -3093,15 +3084,15 @@ dependencies = [ [[package]] name = "masp_proofs" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=449a7295fe24d96456ece24c223ca9eb76b0e6ba#449a7295fe24d96456ece24c223ca9eb76b0e6ba" dependencies = [ "bellman", "blake2b_simd", "bls12_381", "directories", "getrandom 0.2.9", - "group 0.12.1", - "itertools", + "group", + "itertools 0.11.0", "jubjub", "lazy_static", "masp_primitives", @@ -3263,7 +3254,8 @@ version = "0.23.0" dependencies = [ "async-trait", "bimap", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "circular-queue", "clru", "data-encoding", @@ -3273,7 +3265,7 @@ dependencies = [ "ethers", "eyre", "futures", - "itertools", + "itertools 0.10.5", "loupe", "masp_primitives", "masp_proofs", @@ -3325,7 +3317,8 @@ dependencies = [ "ark-ec", "ark-serialize", "bech32 0.8.1", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "chrono", "data-encoding", "derivative", @@ -3341,7 +3334,7 @@ dependencies = [ "ics23", "impl-num-traits", "index-set", - "itertools", + "itertools 0.10.5", "k256", "masp_primitives", "namada_macros", @@ -3374,10 +3367,11 @@ dependencies = [ name = "namada_ethereum_bridge" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "ethers", "eyre", - "itertools", + "itertools 0.10.5", "namada_core", "namada_macros", "namada_proof_of_stake", @@ -3403,7 +3397,7 @@ dependencies = [ name = "namada_proof_of_stake" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "data-encoding", "derivative", "namada_core", @@ -3419,14 +3413,15 @@ version = "0.23.0" dependencies = [ "async-trait", "bimap", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "circular-queue", "data-encoding", "derivation-path", "ethbridge-bridge-contract", "ethers", "futures", - "itertools", + "itertools 0.10.5", "masp_primitives", "masp_proofs", "namada_core", @@ -3460,7 +3455,7 @@ dependencies = [ name = "namada_test_utils" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "namada_core", "strum", ] @@ -3500,7 +3495,8 @@ dependencies = [ name = "namada_tx_prelude" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "masp_primitives", "namada_core", "namada_macros", @@ -3514,7 +3510,7 @@ dependencies = [ name = "namada_vm_env" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "masp_primitives", "namada_core", ] @@ -3523,7 +3519,8 @@ dependencies = [ name = "namada_vp_prelude" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "namada_core", "namada_macros", "namada_proof_of_stake", @@ -3536,7 +3533,7 @@ dependencies = [ name = "namada_wasm" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "getrandom 0.2.9", "masp_primitives", "namada", @@ -3761,9 +3758,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "opaque-debug" @@ -3828,11 +3825,11 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" [[package]] name = "pairing" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "135590d8bdba2b31346f9cd1fb2a912329f5135e832a4f422942eb6ead8b6b3b" +checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" dependencies = [ - "group 0.12.1", + "group", ] [[package]] @@ -3912,6 +3909,19 @@ dependencies = [ "subtle 2.4.1", ] +[[package]] +name = "pasta_curves" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e57598f73cc7e1b2ac63c79c517b31a0877cd7c402cdcaa311b5208de7a095" +dependencies = [ + "ff", + "group", + "rand 0.8.5", + "static_assertions", + "subtle 2.4.1", +] + [[package]] name = "paste" version = "1.0.12" @@ -3929,11 +3939,11 @@ dependencies = [ [[package]] name = "pbkdf2" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f05894bce6a1ba4be299d0c5f29563e08af2bc18bb7d48313113bed71e904739" +checksum = "271779f35b581956db91a3e55737327a03aa051e90b1c47aeb189508533adfd7" dependencies = [ - "crypto-mac 0.11.1", + "digest 0.10.6", "password-hash", ] @@ -4202,7 +4212,7 @@ checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", "heck", - "itertools", + "itertools 0.10.5", "lazy_static", "log", "multimap", @@ -4223,7 +4233,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.5", "proc-macro2", "quote", "syn 1.0.109", @@ -4390,21 +4400,36 @@ dependencies = [ ] [[package]] -name = "redjubjub" -version = "0.5.0" +name = "reddsa" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6039ff156887caf92df308cbaccdc058c9d3155a913da046add6e48c4cdbd91d" +checksum = "78a5191930e84973293aa5f532b513404460cd2216c1cfb76d08748c15b40b02" dependencies = [ "blake2b_simd", "byteorder", - "digest 0.9.0", + "group", + "hex", "jubjub", + "pasta_curves", "rand_core 0.6.4", "serde", "thiserror", "zeroize", ] +[[package]] +name = "redjubjub" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a60db2c3bc9c6fd1e8631fee75abc008841d27144be744951d6b9b75f9b569c" +dependencies = [ + "rand_core 0.6.4", + "reddsa", + "serde", + "thiserror", + "zeroize", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -5175,9 +5200,9 @@ dependencies = [ [[package]] name = "sparse-merkle-tree" version = "0.3.1-pre" -source = "git+https://github.com/heliaxdev/sparse-merkle-tree?rev=e086b235ed6e68929bf73f617dd61cd17b000a56#e086b235ed6e68929bf73f617dd61cd17b000a56" +source = "git+https://github.com/heliaxdev/sparse-merkle-tree?rev=df7ec062e7c40d5e76b136064e9aaf8bd2490750#df7ec062e7c40d5e76b136064e9aaf8bd2490750" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "cfg-if 1.0.0", "ics23", "sha2 0.9.9", @@ -5301,6 +5326,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6eef0000c4a12ecdfd7873ea84a8b5aab5e44db72e38e07b028a25386f29a5" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.16", +] + [[package]] name = "tap" version = "1.0.1" @@ -5771,7 +5808,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" name = "tx_template" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "getrandom 0.2.9", "namada_tests", "namada_tx_prelude", @@ -5894,7 +5931,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "vp_template" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "getrandom 0.2.9", "namada_tests", "namada_vp_prelude", @@ -6674,8 +6711,8 @@ dependencies = [ [[package]] name = "zcash_encoding" -version = "0.0.0" -source = "git+https://github.com/zcash/librustzcash?rev=43c18d0#43c18d000fcbe45363b2d53585d5102841eff99e" +version = "0.2.0" +source = "git+https://github.com/zcash/librustzcash?rev=bd7f9d7#bd7f9d7c3ce5cfd14af169ffe0e1c5c903162f46" dependencies = [ "byteorder", "nonempty", diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 8453ea48ca..c4cb182c1a 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -7,13 +7,6 @@ members = [ "vp_template", ] -[patch.crates-io] -# TODO temp patch for , and more tba. -borsh = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} -borsh-derive = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} -borsh-derive-internal = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} -borsh-schema-derive-internal = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} - [profile.release] # smaller and faster wasm (https://rustwasm.github.io/book/reference/code-size.html#compiling-with-link-time-optimizations-lto) lto = true diff --git a/wasm/tx_template/Cargo.toml b/wasm/tx_template/Cargo.toml index 31865b3818..dbccfaba16 100644 --- a/wasm/tx_template/Cargo.toml +++ b/wasm/tx_template/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib"] [dependencies] namada_tx_prelude = {path = "../../tx_prelude"} -borsh = "0.9.0" +borsh = "1.0.0-alpha.4" wee_alloc = "0.4.5" getrandom = { version = "0.2", features = ["custom"] } diff --git a/wasm/vp_template/Cargo.toml b/wasm/vp_template/Cargo.toml index 9566c6de63..3e8b64262d 100644 --- a/wasm/vp_template/Cargo.toml +++ b/wasm/vp_template/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib"] [dependencies] namada_vp_prelude = {path = "../../vp_prelude"} -borsh = "0.9.0" +borsh = "1.0.0-alpha.4" wee_alloc = "0.4.5" getrandom = { version = "0.2", features = ["custom"] } diff --git a/wasm/wasm_source/Cargo.toml b/wasm/wasm_source/Cargo.toml index 81f07ba049..82ccc18a31 100644 --- a/wasm/wasm_source/Cargo.toml +++ b/wasm/wasm_source/Cargo.toml @@ -38,12 +38,12 @@ vp_validator = ["namada_vp_prelude", "once_cell"] [dependencies] namada_tx_prelude = {path = "../../tx_prelude", optional = true} namada_vp_prelude = {path = "../../vp_prelude", optional = true} -borsh = "0.9.0" +borsh = "1.0.0-alpha.4" once_cell = {version = "1.8.0", optional = true} wee_alloc = "0.4.5" getrandom = { version = "0.2", features = ["custom"] } # branch = "murisi/namada-integration" -masp_primitives = { git = "https://github.com/anoma/masp", rev = "50acc5028fbcd52a05970fe7991c7850ab04358e", optional = true } +masp_primitives = { git = "https://github.com/anoma/masp", rev = "449a7295fe24d96456ece24c223ca9eb76b0e6ba", optional = true } ripemd = "0.1" [dev-dependencies] diff --git a/wasm/wasm_source/src/tx_bond.rs b/wasm/wasm_source/src/tx_bond.rs index 3453747161..775e7d0e91 100644 --- a/wasm/wasm_source/src/tx_bond.rs +++ b/wasm/wasm_source/src/tx_bond.rs @@ -32,6 +32,7 @@ mod tests { arb_established_address, arb_non_internal_address, }; use namada_tx_prelude::address::InternalAddress; + use namada_tx_prelude::borsh_ext::BorshSerializeExt; use namada_tx_prelude::chain::ChainId; use namada_tx_prelude::key::testing::arb_common_keypair; use namada_tx_prelude::key::RefTo; @@ -106,7 +107,7 @@ mod tests { }); let tx_code = vec![]; - let tx_data = bond.try_to_vec().unwrap(); + let tx_data = bond.serialize_to_vec(); let mut tx = Tx::new(ChainId::default(), None); tx.add_code(tx_code) .add_serialized_data(tx_data) diff --git a/wasm/wasm_source/src/tx_bridge_pool.rs b/wasm/wasm_source/src/tx_bridge_pool.rs index 88d757998f..7354fb654a 100644 --- a/wasm/wasm_source/src/tx_bridge_pool.rs +++ b/wasm/wasm_source/src/tx_bridge_pool.rs @@ -1,8 +1,9 @@ //! A tx for adding a transfer request across the Ethereum bridge //! into the bridge pool. -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; use eth_bridge::storage::{bridge_pool, native_erc20_key}; use eth_bridge_pool::{GasFee, PendingTransfer, TransferToEthereum}; +use namada_tx_prelude::borsh_ext::BorshSerializeExt; use namada_tx_prelude::*; #[transaction(gas = 100000)] @@ -64,7 +65,7 @@ fn apply_tx(ctx: &mut Ctx, signed: Tx) -> TxResult { log_string("Escrow succeeded"); // add transfer into the pool let pending_key = bridge_pool::get_pending_key(&transfer); - ctx.write_bytes(&pending_key, transfer.try_to_vec().unwrap()) + ctx.write_bytes(&pending_key, transfer.serialize_to_vec()) .wrap_err("Could not write transfer to bridge pool")?; Ok(()) } diff --git a/wasm/wasm_source/src/tx_change_validator_commission.rs b/wasm/wasm_source/src/tx_change_validator_commission.rs index c1e1b35226..581d9d8dcf 100644 --- a/wasm/wasm_source/src/tx_change_validator_commission.rs +++ b/wasm/wasm_source/src/tx_change_validator_commission.rs @@ -28,6 +28,7 @@ mod tests { use namada_tests::native_vp::TestNativeVpEnv; use namada_tests::tx::*; use namada_tx_prelude::address::testing::arb_established_address; + use namada_tx_prelude::borsh_ext::BorshSerializeExt; use namada_tx_prelude::chain::ChainId; use namada_tx_prelude::key::testing::arb_common_keypair; use namada_tx_prelude::key::RefTo; @@ -85,7 +86,7 @@ mod tests { init_pos(&genesis_validators[..], &pos_params, Epoch(0)); let tx_code = vec![]; - let tx_data = commission_change.try_to_vec().unwrap(); + let tx_data = commission_change.serialize_to_vec(); let mut tx = Tx::new(ChainId::default(), None); tx.add_code(tx_code) .add_serialized_data(tx_data) diff --git a/wasm/wasm_source/src/tx_unbond.rs b/wasm/wasm_source/src/tx_unbond.rs index 7e08c0dcda..7ca5f46ebf 100644 --- a/wasm/wasm_source/src/tx_unbond.rs +++ b/wasm/wasm_source/src/tx_unbond.rs @@ -30,6 +30,7 @@ mod tests { use namada_tests::native_vp::TestNativeVpEnv; use namada_tests::tx::*; use namada_tx_prelude::address::InternalAddress; + use namada_tx_prelude::borsh_ext::BorshSerializeExt; use namada_tx_prelude::chain::ChainId; use namada_tx_prelude::key::testing::arb_common_keypair; use namada_tx_prelude::key::RefTo; @@ -125,7 +126,7 @@ mod tests { tx_host_env::commit_tx_and_block(); let tx_code = vec![]; - let tx_data = unbond.try_to_vec().unwrap(); + let tx_data = unbond.serialize_to_vec(); let mut tx = Tx::new(ChainId::default(), None); tx.add_code(tx_code) .add_serialized_data(tx_data) diff --git a/wasm/wasm_source/src/tx_withdraw.rs b/wasm/wasm_source/src/tx_withdraw.rs index c8fa649c43..d9f47dba23 100644 --- a/wasm/wasm_source/src/tx_withdraw.rs +++ b/wasm/wasm_source/src/tx_withdraw.rs @@ -32,6 +32,7 @@ mod tests { arb_established_address, arb_non_internal_address, }; use namada_tx_prelude::address::InternalAddress; + use namada_tx_prelude::borsh_ext::BorshSerializeExt; use namada_tx_prelude::chain::ChainId; use namada_tx_prelude::key::testing::arb_common_keypair; use namada_tx_prelude::key::RefTo; @@ -169,7 +170,7 @@ mod tests { ); let tx_code = vec![]; - let tx_data = withdraw.try_to_vec().unwrap(); + let tx_data = withdraw.serialize_to_vec(); let mut tx = Tx::new(ChainId::default(), None); tx.add_code(tx_code) .add_serialized_data(tx_data) diff --git a/wasm/wasm_source/src/vp_masp.rs b/wasm/wasm_source/src/vp_masp.rs index cb66211118..b33d367c1c 100644 --- a/wasm/wasm_source/src/vp_masp.rs +++ b/wasm/wasm_source/src/vp_masp.rs @@ -4,6 +4,7 @@ use masp_primitives::asset_type::AssetType; use masp_primitives::transaction::components::I128Sum; /// Multi-asset shielded pool VP. use namada_vp_prelude::address::masp; +use namada_vp_prelude::borsh_ext::BorshSerializeExt; use namada_vp_prelude::storage::Epoch; use namada_vp_prelude::*; use ripemd::{Digest, Ripemd160}; @@ -16,9 +17,7 @@ fn asset_type_from_epoched_address( denom: token::MaspDenom, ) -> AssetType { // Timestamp the chosen token with the current epoch - let token_bytes = (token, denom, epoch.0) - .try_to_vec() - .expect("token should serialize"); + let token_bytes = (token, denom, epoch.0).serialize_to_vec(); // Generate the unique asset identifier from the unique token address AssetType::new(token_bytes.as_ref()).expect("unable to create asset type") } @@ -208,10 +207,7 @@ fn validate_tx( transparent_tx_pool -= transp_amt; // Satisfies 4. - let target_enc = transfer - .target - .try_to_vec() - .expect("target address encoding"); + let target_enc = transfer.target.serialize_to_vec(); let hash = Ripemd160::digest(sha256(&target_enc).0.as_slice()); @@ -267,7 +263,7 @@ fn validate_tx( _ => {} } // Do the expensive proof verification in the VM at the end. - ctx.verify_masp(shielded_tx.try_to_vec().unwrap()) + ctx.verify_masp(shielded_tx.serialize_to_vec()) } else { reject() } diff --git a/wasm/wasm_source/src/vp_testnet_faucet.rs b/wasm/wasm_source/src/vp_testnet_faucet.rs index 7298c0b126..088297ece8 100644 --- a/wasm/wasm_source/src/vp_testnet_faucet.rs +++ b/wasm/wasm_source/src/vp_testnet_faucet.rs @@ -118,6 +118,7 @@ mod tests { use namada_tests::vp::*; use namada_tx_prelude::{StorageWrite, TxEnv}; use namada_vp_prelude::account::AccountPublicKeysMap; + use namada_vp_prelude::borsh_ext::BorshSerializeExt; use namada_vp_prelude::key::RefTo; use proptest::prelude::*; use storage::testing::arb_account_storage_key_no_vp; @@ -376,7 +377,7 @@ mod tests { // Construct a PoW solution like a client would let challenge = testnet_pow::Challenge::new(&mut tx_env.wl_storage, &vp_owner, target.clone()).unwrap(); let solution = challenge.solve(); - let solution_bytes = solution.try_to_vec().unwrap(); + let solution_bytes = solution.serialize_to_vec(); let amount = token::DenominatedAmount { amount, diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index 8a4fdec901..a1386faf3f 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -37,18 +37,6 @@ dependencies = [ "generic-array 0.14.7", ] -[[package]] -name = "aes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" -dependencies = [ - "cfg-if 1.0.0", - "cipher 0.3.0", - "cpufeatures", - "opaque-debug 0.3.0", -] - [[package]] name = "aes" version = "0.8.3" @@ -377,15 +365,15 @@ checksum = "cf9ff0bbfd639f15c74af777d81383cf53efb7c93613f6cab67c6c11e05bbf8b" [[package]] name = "bellman" -version = "0.13.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4dd656ef4fdf7debb6d87d4dd92642fcbcdb78cbf6600c13e25c87e4d1a3807" +checksum = "9afceed28bac7f9f5a508bca8aeeff51cdfa4770c0b967ac55c621e2ddfd6171" dependencies = [ "bitvec 1.0.1", "blake2s_simd", "byteorder", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "pairing", "rand_core 0.6.4", "subtle 2.4.1", @@ -411,14 +399,14 @@ dependencies = [ [[package]] name = "bip0039" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0830ae4cc96b0617cc912970c2b17e89456fecbf55e8eed53a956f37ab50c41" +checksum = "bef0f0152ec5cf17f49a5866afaa3439816207fd4f0a224c0211ffaf5e278426" dependencies = [ - "hmac 0.11.0", - "pbkdf2 0.9.0", + "hmac 0.12.1", + "pbkdf2 0.10.1", "rand 0.8.5", - "sha2 0.9.9", + "sha2 0.10.6", "unicode-normalization", "zeroize", ] @@ -517,7 +505,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ - "block-padding 0.1.5", + "block-padding", "byte-tools", "byteorder", "generic-array 0.12.4", @@ -541,16 +529,6 @@ dependencies = [ "generic-array 0.14.7", ] -[[package]] -name = "block-modes" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb03d1bed155d89dce0f845b7899b18a9a163e148fd004e1c28421a783e2d8e" -dependencies = [ - "block-padding 0.2.1", - "cipher 0.3.0", -] - [[package]] name = "block-padding" version = "0.1.5" @@ -560,20 +538,14 @@ dependencies = [ "byte-tools", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "bls12_381" -version = "0.7.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3c196a77437e7cc2fb515ce413a6401291578b5afc8ecb29a3c7ab957f05941" +checksum = "d7bc6d6292be3a19e6379786dac800f551e5865a5bb51ebbe3064ab80433f403" dependencies = [ - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "pairing", "rand_core 0.6.4", "subtle 2.4.1", @@ -581,10 +553,11 @@ dependencies = [ [[package]] name = "borsh" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" dependencies = [ - "borsh-derive 0.9.4", + "borsh-derive 0.9.3", "hashbrown 0.11.2", ] @@ -598,13 +571,24 @@ dependencies = [ "hashbrown 0.12.3", ] +[[package]] +name = "borsh" +version = "1.0.0-alpha.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41898277107b0d3f027593697912977397eba6ac39a55bdd2eb02c1d5d5013b5" +dependencies = [ + "borsh-derive 1.0.0-alpha.4", + "cfg_aliases", +] + [[package]] name = "borsh-derive" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" dependencies = [ - "borsh-derive-internal 0.9.4", - "borsh-schema-derive-internal 0.9.4", + "borsh-derive-internal 0.9.3", + "borsh-schema-derive-internal 0.9.3", "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.109", @@ -623,10 +607,25 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-derive" +version = "1.0.0-alpha.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413cb435569fe499e89235f758304e0e7198016baa351d8f5827ea0f40526ce0" +dependencies = [ + "once_cell", + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 2.0.16", + "syn_derive", +] + [[package]] name = "borsh-derive-internal" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" dependencies = [ "proc-macro2", "quote", @@ -644,10 +643,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-ext" +version = "1.0.0-alpha.4" +source = "git+https://github.com/heliaxdev/borsh-ext?tag=v1.0.0-alpha.4#6bebf357002f96574ac37a28f547b6c88e91b799" +dependencies = [ + "borsh 1.0.0-alpha.4", +] + [[package]] name = "borsh-schema-derive-internal" -version = "0.9.4" -source = "git+https://github.com/heliaxdev/borsh-rs.git?rev=cd5223e5103c4f139e0c54cf8259b7ec5ec4073a#cd5223e5103c4f139e0c54cf8259b7ec5ec4073a" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" dependencies = [ "proc-macro2", "quote", @@ -761,6 +769,15 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher 0.4.4", +] + [[package]] name = "cc" version = "1.0.79" @@ -779,6 +796,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chacha20" version = "0.8.2" @@ -1200,16 +1223,6 @@ dependencies = [ "subtle 2.4.1", ] -[[package]] -name = "crypto-mac" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" -dependencies = [ - "generic-array 0.14.7", - "subtle 2.4.1", -] - [[package]] name = "ct-codecs" version = "1.1.1" @@ -1508,9 +1521,9 @@ dependencies = [ "base16ct", "crypto-bigint", "digest 0.10.6", - "ff 0.13.0", + "ff", "generic-array 0.14.7", - "group 0.13.0", + "group", "pkcs8", "rand_core 0.6.4", "sec1", @@ -1629,7 +1642,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fda3bf123be441da5260717e0661c25a2fd9cb2b2c1d20bf2e05580047158ab" dependencies = [ - "aes 0.8.3", + "aes", "ctr", "digest 0.10.6", "hex", @@ -1987,14 +2000,14 @@ dependencies = [ "bincode", "blake2", "blake2b_simd", - "borsh 0.9.4", + "borsh 0.9.3", "digest 0.10.6", "ed25519-dalek", "either", "ferveo-common", "group-threshold-cryptography", "hex", - "itertools", + "itertools 0.10.5", "measure_time", "miracl_core", "num 0.4.0", @@ -2021,23 +2034,13 @@ dependencies = [ "serde_bytes", ] -[[package]] -name = "ff" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" -dependencies = [ - "bitvec 1.0.1", - "rand_core 0.6.4", - "subtle 2.4.1", -] - [[package]] name = "ff" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ + "bitvec 1.0.1", "rand_core 0.6.4", "subtle 2.4.1", ] @@ -2087,12 +2090,12 @@ dependencies = [ [[package]] name = "fpe" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd910db5f9ca4dc3116f8c46367825807aa2b942f72565f16b4be0b208a00a9e" +checksum = "26c4b37de5ae15812a764c958297cfc50f5c010438f60c6ce75d11b802abd404" dependencies = [ - "block-modes", - "cipher 0.3.0", + "cbc", + "cipher 0.4.4", "libm", "num-bigint 0.4.3", "num-integer", @@ -2298,25 +2301,14 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "group" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" -dependencies = [ - "ff 0.12.1", - "memuse", - "rand_core 0.6.4", - "subtle 2.4.1", -] - [[package]] name = "group" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "ff 0.13.0", + "ff", + "memuse", "rand_core 0.6.4", "subtle 2.4.1", ] @@ -2336,7 +2328,7 @@ dependencies = [ "blake2b_simd", "chacha20 0.8.2", "hex", - "itertools", + "itertools 0.10.5", "miracl_core", "rand 0.8.5", "rand_core 0.6.4", @@ -2495,16 +2487,6 @@ dependencies = [ "digest 0.9.0", ] -[[package]] -name = "hmac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" -dependencies = [ - "crypto-mac 0.11.1", - "digest 0.9.0", -] - [[package]] name = "hmac" version = "0.12.1" @@ -2795,10 +2777,10 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "index-set" -version = "0.7.1" -source = "git+https://github.com/heliaxdev/index-set?tag=v0.7.1#dc24cdbbe3664514d59f1a4c4031863fc565f1c2" +version = "0.8.0" +source = "git+https://github.com/heliaxdev/index-set?tag=v0.8.0#0c218cc300c1bb7a1acf34f21b6e9d489df5fda8" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "serde", ] @@ -2891,6 +2873,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.6" @@ -2908,14 +2899,14 @@ dependencies = [ [[package]] name = "jubjub" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a575df5f985fe1cd5b2b05664ff6accfc46559032b954529fd225a2168d27b0f" +checksum = "8499f7a74008aafbecb2a2e608a3e13e4dd3e84df198b604451efe93f2de6e61" dependencies = [ "bitvec 1.0.1", "bls12_381", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "rand_core 0.6.4", "subtle 2.4.1", ] @@ -3049,9 +3040,9 @@ dependencies = [ [[package]] name = "masp_note_encryption" version = "0.2.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=449a7295fe24d96456ece24c223ca9eb76b0e6ba#449a7295fe24d96456ece24c223ca9eb76b0e6ba" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "chacha20 0.9.1", "chacha20poly1305", "cipher 0.4.4", @@ -3062,19 +3053,19 @@ dependencies = [ [[package]] name = "masp_primitives" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=449a7295fe24d96456ece24c223ca9eb76b0e6ba#449a7295fe24d96456ece24c223ca9eb76b0e6ba" dependencies = [ - "aes 0.7.5", + "aes", "bip0039", "bitvec 1.0.1", "blake2b_simd", "blake2s_simd", "bls12_381", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "byteorder", - "ff 0.12.1", + "ff", "fpe", - "group 0.12.1", + "group", "hex", "incrementalmerkletree", "jubjub", @@ -3085,7 +3076,7 @@ dependencies = [ "num-traits", "rand 0.8.5", "rand_core 0.6.4", - "sha2 0.9.9", + "sha2 0.10.6", "subtle 2.4.1", "zcash_encoding", ] @@ -3093,15 +3084,15 @@ dependencies = [ [[package]] name = "masp_proofs" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=449a7295fe24d96456ece24c223ca9eb76b0e6ba#449a7295fe24d96456ece24c223ca9eb76b0e6ba" dependencies = [ "bellman", "blake2b_simd", "bls12_381", "directories", "getrandom 0.2.9", - "group 0.12.1", - "itertools", + "group", + "itertools 0.11.0", "jubjub", "lazy_static", "masp_primitives", @@ -3263,7 +3254,8 @@ version = "0.23.0" dependencies = [ "async-trait", "bimap", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "circular-queue", "clru", "data-encoding", @@ -3273,7 +3265,7 @@ dependencies = [ "ethers", "eyre", "futures", - "itertools", + "itertools 0.10.5", "loupe", "masp_primitives", "masp_proofs", @@ -3325,7 +3317,8 @@ dependencies = [ "ark-ec", "ark-serialize", "bech32 0.8.1", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "chrono", "data-encoding", "derivative", @@ -3341,7 +3334,7 @@ dependencies = [ "ics23", "impl-num-traits", "index-set", - "itertools", + "itertools 0.10.5", "k256", "masp_primitives", "namada_macros", @@ -3374,10 +3367,11 @@ dependencies = [ name = "namada_ethereum_bridge" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "ethers", "eyre", - "itertools", + "itertools 0.10.5", "namada_core", "namada_macros", "namada_proof_of_stake", @@ -3403,7 +3397,7 @@ dependencies = [ name = "namada_proof_of_stake" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "data-encoding", "derivative", "namada_core", @@ -3419,14 +3413,15 @@ version = "0.23.0" dependencies = [ "async-trait", "bimap", - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "circular-queue", "data-encoding", "derivation-path", "ethbridge-bridge-contract", "ethers", "futures", - "itertools", + "itertools 0.10.5", "masp_primitives", "masp_proofs", "namada_core", @@ -3460,7 +3455,7 @@ dependencies = [ name = "namada_test_utils" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "namada_core", "strum", ] @@ -3500,7 +3495,8 @@ dependencies = [ name = "namada_tx_prelude" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "masp_primitives", "namada_core", "namada_macros", @@ -3514,7 +3510,7 @@ dependencies = [ name = "namada_vm_env" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "masp_primitives", "namada_core", ] @@ -3523,7 +3519,8 @@ dependencies = [ name = "namada_vp_prelude" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", + "borsh-ext", "namada_core", "namada_macros", "namada_proof_of_stake", @@ -3536,7 +3533,7 @@ dependencies = [ name = "namada_wasm_for_tests" version = "0.23.0" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "getrandom 0.2.9", "namada_test_utils", "namada_tests", @@ -3754,9 +3751,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "opaque-debug" @@ -3821,11 +3818,11 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" [[package]] name = "pairing" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "135590d8bdba2b31346f9cd1fb2a912329f5135e832a4f422942eb6ead8b6b3b" +checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" dependencies = [ - "group 0.12.1", + "group", ] [[package]] @@ -3905,6 +3902,19 @@ dependencies = [ "subtle 2.4.1", ] +[[package]] +name = "pasta_curves" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e57598f73cc7e1b2ac63c79c517b31a0877cd7c402cdcaa311b5208de7a095" +dependencies = [ + "ff", + "group", + "rand 0.8.5", + "static_assertions", + "subtle 2.4.1", +] + [[package]] name = "paste" version = "1.0.12" @@ -3922,11 +3932,11 @@ dependencies = [ [[package]] name = "pbkdf2" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f05894bce6a1ba4be299d0c5f29563e08af2bc18bb7d48313113bed71e904739" +checksum = "271779f35b581956db91a3e55737327a03aa051e90b1c47aeb189508533adfd7" dependencies = [ - "crypto-mac 0.11.1", + "digest 0.10.6", "password-hash", ] @@ -4195,7 +4205,7 @@ checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", "heck", - "itertools", + "itertools 0.10.5", "lazy_static", "log", "multimap", @@ -4216,7 +4226,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.5", "proc-macro2", "quote", "syn 1.0.109", @@ -4383,21 +4393,36 @@ dependencies = [ ] [[package]] -name = "redjubjub" -version = "0.5.0" +name = "reddsa" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6039ff156887caf92df308cbaccdc058c9d3155a913da046add6e48c4cdbd91d" +checksum = "78a5191930e84973293aa5f532b513404460cd2216c1cfb76d08748c15b40b02" dependencies = [ "blake2b_simd", "byteorder", - "digest 0.9.0", + "group", + "hex", "jubjub", + "pasta_curves", "rand_core 0.6.4", "serde", "thiserror", "zeroize", ] +[[package]] +name = "redjubjub" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a60db2c3bc9c6fd1e8631fee75abc008841d27144be744951d6b9b75f9b569c" +dependencies = [ + "rand_core 0.6.4", + "reddsa", + "serde", + "thiserror", + "zeroize", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -5168,9 +5193,9 @@ dependencies = [ [[package]] name = "sparse-merkle-tree" version = "0.3.1-pre" -source = "git+https://github.com/heliaxdev/sparse-merkle-tree?rev=e086b235ed6e68929bf73f617dd61cd17b000a56#e086b235ed6e68929bf73f617dd61cd17b000a56" +source = "git+https://github.com/heliaxdev/sparse-merkle-tree?rev=df7ec062e7c40d5e76b136064e9aaf8bd2490750#df7ec062e7c40d5e76b136064e9aaf8bd2490750" dependencies = [ - "borsh 0.9.4", + "borsh 1.0.0-alpha.4", "cfg-if 1.0.0", "ics23", "sha2 0.9.9", @@ -5294,6 +5319,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6eef0000c4a12ecdfd7873ea84a8b5aab5e44db72e38e07b028a25386f29a5" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.16", +] + [[package]] name = "tap" version = "1.0.1" @@ -6645,8 +6682,8 @@ dependencies = [ [[package]] name = "zcash_encoding" -version = "0.0.0" -source = "git+https://github.com/zcash/librustzcash?rev=43c18d0#43c18d000fcbe45363b2d53585d5102841eff99e" +version = "0.2.0" +source = "git+https://github.com/zcash/librustzcash?rev=bd7f9d7#bd7f9d7c3ce5cfd14af169ffe0e1c5c903162f46" dependencies = [ "byteorder", "nonempty", diff --git a/wasm_for_tests/wasm_source/Cargo.toml b/wasm_for_tests/wasm_source/Cargo.toml index de8e3ce99a..07ae535c61 100644 --- a/wasm_for_tests/wasm_source/Cargo.toml +++ b/wasm_for_tests/wasm_source/Cargo.toml @@ -27,17 +27,10 @@ tx_proposal_code = [] namada_test_utils = {path = "../../test_utils"} namada_tx_prelude = {path = "../../tx_prelude"} namada_vp_prelude = {path = "../../vp_prelude"} -borsh = "0.9.1" +borsh = "1.0.0-alpha.4" wee_alloc = "0.4.5" getrandom = { version = "0.2", features = ["custom"] } -[patch.crates-io] -# TODO temp patch for , and more tba. -borsh = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} -borsh-derive = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} -borsh-derive-internal = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} -borsh-schema-derive-internal = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"} - [dev-dependencies] namada_tests = {path = "../../tests"}