From 5a8cd44fbca5bbac613fe5e4a75e64635a45e2f2 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 16 Sep 2024 13:36:49 -0500 Subject: [PATCH] feat: implement `wagyu-zcash-parameters` crate --- librustzcash-wrapper/Cargo.lock | 51 +++++++++++++++++++++++++++++++++ librustzcash-wrapper/Cargo.toml | 1 + librustzcash-wrapper/src/lib.rs | 11 ++++--- src/C/Zcash.chs | 2 -- src/ZcashHaskell/Utils.hs | 6 +--- test/Spec.hs | 5 +++- zcash-haskell.cabal | 1 + 7 files changed, 63 insertions(+), 14 deletions(-) diff --git a/librustzcash-wrapper/Cargo.lock b/librustzcash-wrapper/Cargo.lock index 53583a4..e74b7c7 100644 --- a/librustzcash-wrapper/Cargo.lock +++ b/librustzcash-wrapper/Cargo.lock @@ -1395,6 +1395,7 @@ dependencies = [ "rand_core", "sapling-crypto", "secp256k1", + "wagyu-zcash-parameters", "zcash_address 0.2.0", "zcash_client_backend", "zcash_note_encryption", @@ -1746,6 +1747,56 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wagyu-zcash-parameters" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c904628658374e651288f000934c33ef738b2d8b3e65d4100b70b395dbe2bb" +dependencies = [ + "wagyu-zcash-parameters-1", + "wagyu-zcash-parameters-2", + "wagyu-zcash-parameters-3", + "wagyu-zcash-parameters-4", + "wagyu-zcash-parameters-5", + "wagyu-zcash-parameters-6", +] + +[[package]] +name = "wagyu-zcash-parameters-1" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bf2e21bb027d3f8428c60d6a720b54a08bf6ce4e6f834ef8e0d38bb5695da8" + +[[package]] +name = "wagyu-zcash-parameters-2" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a616ab2e51e74cc48995d476e94de810fb16fc73815f390bf2941b046cc9ba2c" + +[[package]] +name = "wagyu-zcash-parameters-3" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14da1e2e958ff93c0830ee68e91884069253bf3462a67831b02b367be75d6147" + +[[package]] +name = "wagyu-zcash-parameters-4" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f058aeef03a2070e8666ffb5d1057d8bb10313b204a254a6e6103eb958e9a6d6" + +[[package]] +name = "wagyu-zcash-parameters-5" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ffe916b30e608c032ae1b734f02574a3e12ec19ab5cc5562208d679efe4969d" + +[[package]] +name = "wagyu-zcash-parameters-6" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7b6d5a78adc3e8f198e9cd730f219a695431467f7ec29dcfc63ade885feebe1" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/librustzcash-wrapper/Cargo.toml b/librustzcash-wrapper/Cargo.toml index b8b2b37..abb27b5 100644 --- a/librustzcash-wrapper/Cargo.toml +++ b/librustzcash-wrapper/Cargo.toml @@ -23,6 +23,7 @@ incrementalmerkletree = "0.5.0" secp256k1 = "0.26.0" jubjub = "0.10.0" rand_core = { version = "0.6.4", features = ["getrandom"]} +wagyu-zcash-parameters = "0.2.0" [features] diff --git a/librustzcash-wrapper/src/lib.rs b/librustzcash-wrapper/src/lib.rs index 7397401..be36e38 100644 --- a/librustzcash-wrapper/src/lib.rs +++ b/librustzcash-wrapper/src/lib.rs @@ -167,6 +167,8 @@ use bech32::{ Bech32m }; +use wagyu_zcash_parameters::load_sapling_parameters; + pub enum RW {} pub const RW: PhantomData = PhantomData; @@ -1637,10 +1639,6 @@ pub extern "C" fn rust_wrapper_create_transaction( o_input_len: usize, out_list: *const u8, out_list_len: usize, - sapspend: *const u8, - sapspend_len: usize, - sapoutput: *const u8, - sapoutput_len: usize, net: bool, bl_height: u32, build: bool, @@ -1796,10 +1794,11 @@ pub extern "C" fn rust_wrapper_create_transaction( } } if build { - let spend_params_in: Vec = marshall_from_haskell_var(sapspend, sapspend_len, RW); + let (spend_params_in, output_params_in) = load_sapling_parameters(); + //let spend_params_in: Vec = marshall_from_haskell_var(sapspend, sapspend_len, RW); let spend_params_reader = Cursor::new(spend_params_in); let spend_prover = SpendParameters::read(spend_params_reader, false).unwrap(); - let output_params_in: Vec = marshall_from_haskell_var(sapoutput, sapoutput_len, RW); + //let output_params_in: Vec = marshall_from_haskell_var(sapoutput, sapoutput_len, RW); let output_params_reader = Cursor::new(output_params_in); let output_prover = OutputParameters::read(output_params_reader, false).unwrap(); let result = if net { diff --git a/src/C/Zcash.chs b/src/C/Zcash.chs index 0f35be4..bc75ee4 100644 --- a/src/C/Zcash.chs +++ b/src/C/Zcash.chs @@ -283,8 +283,6 @@ import ZcashHaskell.Types , toBorshVar* `[SaplingTxSpend]'& , toBorshVar* `[OrchardTxSpend]'& , toBorshVar* `[OutgoingNote]'& - , toBorshVar* `BS.ByteString'& - , toBorshVar* `BS.ByteString'& , `Bool' , `Word64' , `Bool' diff --git a/src/ZcashHaskell/Utils.hs b/src/ZcashHaskell/Utils.hs index 0f67ed7..e7e1aae 100644 --- a/src/ZcashHaskell/Utils.hs +++ b/src/ZcashHaskell/Utils.hs @@ -129,13 +129,11 @@ createTransaction :: -> [SaplingTxSpend] -- ^ the list of Sapling notes to spend -> [OrchardTxSpend] -- ^ the list of Orchard notes to spend -> [OutgoingNote] -- ^ the list of outgoing notes, including change notes - -> SaplingSpendParams -- ^ the Sapling circuit spending parameters - -> SaplingOutputParams -- ^ the Sapling circuit output parameters -> ZcashNet -- ^ the network to be used -> Int -- ^ target block height -> Bool -- ^ True to build, False to estimate fee -> Either TxError HexString -createTransaction sapAnchor orchAnchor tSpend sSpend oSpend outgoing sParams oParams znet bh build = +createTransaction sapAnchor orchAnchor tSpend sSpend oSpend outgoing znet bh build = processResult $! txResult where processResult :: HexString -> Either TxError HexString @@ -168,8 +166,6 @@ createTransaction sapAnchor orchAnchor tSpend sSpend oSpend outgoing sParams oPa sSpend oSpend outgoing - (sapSParams sParams) - (sapOParams oParams) (znet == MainNet) (fromIntegral bh) build diff --git a/test/Spec.hs b/test/Spec.hs index 67ca3ce..ac4581e 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -40,6 +40,7 @@ import GHC.Float.RealFracMethods (properFractionDoubleInteger) import Haskoin.Crypto.Hash (ripemd160) import Haskoin.Crypto.Keys.Extended import Haskoin.Transaction.Common +import Network.HTTP.Simple (Response(..)) import Test.HUnit import Test.Hspec import Test.Hspec.QuickCheck @@ -82,6 +83,8 @@ import ZcashHaskell.Types , RawTxOut(..) , RawTxResponse(..) , RawZebraTx(..) + , RpcError(..) + , RpcResponse(..) , SaplingAddress(..) , SaplingBundle(..) , SaplingCommitmentTree(..) @@ -1179,7 +1182,7 @@ main = do updateOrchardWitness wit cmxs `shouldBe` OrchardWitness (hexString - "016225b41339a00dd764b452fca190a0245e7118224965942e3a6d798365c34631001f0000011d6f5da3f619bfaab957fc643c17eb144db0101c90f422da2fcbe0e80d74412e000000000001746e6bc066a10e7f80a9ff8993dcb25c819edd64f2ca10ac248ef7848d41450500011e6191f91b3fceb62dc881a156e1b9d2e88e09dca25093cf9c4936c8869fb41a013bf8b923e4187754e85175748d9cce4824a6787e4258977b5bfe1ba59012c032000001f3bbdc62260c4fca5c84bf3487246d4542da48eeeec8ec40c1029b6908eef83c00000000000000000000000000000000040e02c864db8b574f165f616d48e2f12eb25099b5c90186af26d9e50f5058863e0504bfbc12edc35e05042c16bbfb8fed591f01f18fe128eeb57f2c456c9eb222d6d261c549e95d9007bce4c6ae0b86bc865711cdd9f0fa92e2d5b5e149b51f3be127df3b1d2372adf6c811b2e456c1d64d0e9eb167a995f9c6b66a03c9cbda250101c094201bae3b4ef582a3e8654f65a72fbd41e20e1ec9a43d3f4101afc868731e0002010cfb50d8c877eb39e9c07082a032dd99d34be7c19fa7f30e9fecf5f14736240f019df5b9366d0f21caa678d1567390b5bfd3cfa0438271bcfe301b5558a2863301") + "016225b41339a00dd764b452fca190a0245e7118224965942e3a6d798365c34631001f0000011d6f5da3f619bfaab957fc643c17eb144db0101c90f422da2fcbe0e80d74412e000000000001746e6bc066a10e7f80a9ff8993dcb25c819edd64f2ca10ac248ef7848d41450500011e6191f91b3fceb62dc881a156e1b9d2e88e09dca25093cf9c4936c8869fb41a013bf8b923e4187754e85175748d9cce4824a6787e4258977b5bfe1ba59012c032000001f3bbdc62260c4fca5c84bf3487246d4542da48eeeec8ec40c1029b6908eef83c00000000000000000000000000000000040e02c864db8b574f165f616d48e2f12eb25099b5c90186af26d9e50f5058863e0504bfbc12edc35e05042c16bbfb8fed591f01f18fe128eeb57f2c456c9eb222d6d261c549e95d9007bce4c6ae0b86bc865711cdd9f0fa92e2d5b5e149b51f3be127df3b1d2372adf6c811b2e456c1d64d0e9eb167a995f9c6b66a03c9cbda250101c094201bae3b4ef582a3e8654f65a72fbd41e20e1ec9a43d3f4101afc868731e01ac20b8170b008888c19fc6e16f5e30a5ef1653e5219d0cd0c9353c3aa8f7982302010cfb50d8c877eb39e9c07082a032dd99d34be7c19fa7f30e9fecf5f14736240f019df5b9366d0f21caa678d1567390b5bfd3cfa0438271bcfe301b5558a2863301") -- | Properties prop_PhraseLength :: Property diff --git a/zcash-haskell.cabal b/zcash-haskell.cabal index b521e58..cd61471 100644 --- a/zcash-haskell.cabal +++ b/zcash-haskell.cabal @@ -86,5 +86,6 @@ test-suite zcash-haskell-test , binary , cryptonite , secp256k1-haskell + , http-conduit pkgconfig-depends: rustzcash_wrapper default-language: Haskell2010