Commit Graph

339 Commits

Author SHA1 Message Date
Kris Nuttycombe 6b8ecc8a31 Reset Orchard wallet state when rescanning from below NU5 activation. 2022-03-07 19:05:00 -07:00
Kris Nuttycombe b78c2732ab Record when notes are detected as being spent in the Orchard wallet. 2022-03-07 19:04:58 -07:00
Daira Hopwood 9b20105413 Tweak the wording of the fallback messages when the terminal cannot be automatically cleared.
Co-authored-by: Kris Nuttycombe <kris@electriccoin.co>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-03-07 19:34:31 +00:00
Daira Hopwood 6fb943d0f6 Refactor use of `export_path` as suggested.
Co-authored-by: Sean Bowe <sean@electriccoin.co>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-03-07 19:33:27 +00:00
Daira Hopwood 6f5efcbb0f Improved error handling.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-03-07 18:39:23 +00:00
Daira Hopwood 25792cba93 Move `wallet_tool.rs` from `src/rust/src` into `src/rust/bin`.
Also add a brief description of `zcashd-wallet-tool` to `src/rust/README.md`.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-03-07 18:39:23 +00:00
Daira Hopwood 8ec0d854b9 Add some text about choosing location of the physical backup.
Add TODO for better handling of file not found and permission errors.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-03-07 18:39:23 +00:00
Daira Hopwood a36fceca70 Make a zcashd-wallet-tool executable.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-03-07 18:39:23 +00:00
sasha 0e6b004a64 make librustzcash_init_zksnark_params idempotent 2022-03-05 21:51:27 -08:00
Jack Grigg b5ce94d16c rust: Fix clippy lint 2022-03-01 01:35:46 +00:00
Jack Grigg 701a7875a7 Regenerate `TxDigests` after rebuilding tx with Orchard bundle
In zcash/zcash/pull/5544 we added an FFI method specific to the Orchard
part of the transaction builder, to enable passing the Orchard bundle on
the Rust side directly instead of using a partial serialization. We
passed the remainder of the transaction to the Rust side by serializing,
as we similarly do in `SignatureHash`. We then decomposed the parsed
transaction on the Rust side to insert the Orchard bundle. However, we
then used the `TxDigests` that was derived from the parsed transaction,
not the reconstructed one, which meant we produced an invalid sighash
when building Orchard-containing transactions.
2022-02-25 00:52:52 +00:00
Jack Grigg d4078c8d25 Select Orchard receivers preferentially from UAs
The addition of `OrchardRawAddress` to `RecipientAddress` drives most of
the changes in this commit, which enable `z_sendmany` to send funds to
addresses in the Orchard pool once NU5 activates.
2022-02-25 00:52:52 +00:00
Jack Grigg 235fde5193 Add mappings from Orchard receivers to IVKs to the wallet
We add the Orchard change address mapping on account creation, as we
only ever generate a single change address internally. External Orchard
receivers are added to the map when `z_getaddressforaccount` is called.

This commit also fixes two bugs in the handling of Orchard internal IVKs.
When adding a full viewing key to the Orchard (Rust) wallet, we need to
derive both the internal and external IVKs (and map them to the external
FVK so we effectively never expose the internal FVK). We were only
deriving the external IVK, meaning that trying to add the Orchard change
address to the wallet should have failed. However, in a separate bug the
C++ internal IVK derivation method was calling the Rust external IVK
derivation function, meaning that we were effectively using the external
Orchard address at index 0 _as_ the change Orchard address.
2022-02-24 02:17:19 +00:00
Kris Nuttycombe 3c84ed604e Remove OrchardSpendingKey serialization code
Orchard spending keys now live exclusively on the Rust side, and will be
serialized there as part of the Orchard wallet serialization.
2022-02-22 21:08:10 +00:00
Kris Nuttycombe 258f0fc72f Add Orchard components to unified full viewing keys
Co-authored-by: Jack Grigg <jack@z.cash>
2022-02-22 21:08:10 +00:00
Kris Nuttycombe 1a1522a4f1 Add Orchard components to unified address
Co-authored-by: Jack Grigg <jack@z.cash>
2022-02-21 17:04:27 +00:00
Kris Nuttycombe 1969add228 Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2022-02-18 17:45:50 -07:00
Kris Nuttycombe 66890866d6 Remove txid field from TxNotes 2022-02-18 17:07:47 -07:00
Kris Nuttycombe dcf7f46260 Add test for Orchard wallet note detection.
This tests the following operations:
* add a spending key to the wallet
* add notes from the Orchard bundle component of a transaction to the
  wallet
* detect notes in the wallet that correspond to the spending key
* verify that notes that are not ours are not mistakenly labeled
  as ours
2022-02-17 17:50:17 -07:00
Kris Nuttycombe 4c53499f11 Add GetFilteredNotes to Orchard wallet. 2022-02-17 17:50:17 -07:00
Kris Nuttycombe 6587b2ed86 Add Rust backend for Orchard components of the wallet.
Co-authored-by: str4d <thestr4d@gmail.com>
2022-02-17 17:50:17 -07:00
Jack Grigg e9625d2483 Enforce length constraints on allPrevOutputs 2022-02-17 22:41:41 +00:00
Jack Grigg da755c2ae8 Make `TransactionBuilder::AddOrchardOutput` memo optional
This replaces the previous use of the `NO_MEMO` constant, instead
passing the optionality through to Rust for handling.
2022-02-16 13:39:40 +00:00
Jack Grigg 96d6ee0b8f Update ZIP 244 implementation
This brings in the changes that align the transparent parts of ZIP 244
with BIP 341.
2022-02-16 03:29:42 +00:00
Jack Grigg 2da0856e6f Add Orchard recipient support to the transaction builder
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2022-02-15 23:28:55 +00:00
Kris Nuttycombe b1ab30c8d9 Rename sapling-specific zip32 FFI methods.
Also addresses a couple of other minor comments from code review.
2022-02-12 15:24:48 -07:00
Kris Nuttycombe cf271473eb Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: str4d <thestr4d@gmail.com>
2022-02-07 16:52:31 -07:00
Kris Nuttycombe 13ee447a42 Merge branch 'test_wallet_listreceived' into feature/wallet_unified_addresses-z_sendmany 2022-02-07 15:08:35 -07:00
Kris Nuttycombe b46d85976d Implement derivation of the internal Sapling spending key. 2022-01-27 21:27:43 -07:00
Kris Nuttycombe 3ddbe1fa06 Implement OVK selection for z_sendmany. 2022-01-27 21:27:43 -07:00
Kris Nuttycombe bdcb12e445 Add a first-class type for transparent full viewing keys. 2022-01-27 21:27:43 -07:00
Kris Nuttycombe c21ffff790 Add correct selection of change addresses to z_sendmany
This also alters `TransactionBuilder::SendChangeTo` to take a
`libzcash::ChangeAddress` value and thus avoids the invalid
t-addr case of CTxDestination.
2022-01-27 21:27:43 -07:00
Jack Grigg 714f14168c rust: Add missing checks for transparent UFVK items 2022-01-18 21:32:33 +00:00
Jack Grigg 9b61806cc6 rust: Add missing checks for shielded UFVK items 2022-01-18 21:32:32 +00:00
Jack Grigg f2e0a8d1f3 rust: Add missing Orchard receiver check in UA parsing
We didn't add it at the time because the necessary API did not exist in
the `orchard` crate. The API has since been added.
2022-01-18 21:31:52 +00:00
Larry Ruane bc1af5fc2d mining: submitblock: log detailed equihash solution error 2022-01-11 12:52:30 -07:00
Daira Hopwood 0e073a53ee Replace call to drop with zeroization.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-01-10 02:39:25 +00:00
Daira Hopwood 4f7d15508f Avoid a warning by explicitly calling drop.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-01-09 23:54:35 +00:00
Kris Nuttycombe fe777c5624 Fix encoding order of unified addresses. 2022-01-05 18:30:06 -07:00
Kris Nuttycombe 98967e2ec7 Merge remote-tracking branch 'upstream/master' into feature/wallet_unified_addresses 2022-01-05 18:20:31 -07:00
Kris Nuttycombe 5d07a8ae79 Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-12-30 10:53:51 -07:00
Kris Nuttycombe 900cd50741 Rename `ZcashdUnifiedSpendingKeyMetadata` -> `ZcashdUnifiedAccount`
Also, fix a couple of minor documentation issues and
make UA generation tests a little more robust.
2021-12-22 16:09:17 -07:00
Kris Nuttycombe 735ecd0906 Apply suggestions from code review
Co-authored-by: str4d <jack@electriccoin.co>
2021-12-22 15:57:47 -07:00
Kris Nuttycombe 0dcdc28a38 Add CWallet::GetUnifiedForReceiver 2021-12-22 15:57:47 -07:00
Jack Grigg d85bfb4744 Migrate to latest revisions of Zcash Rust crates 2021-12-18 01:44:27 +00:00
Jack Grigg 1b7a031e7b rust: Remove misleading log message
We use the `zcash_address` crate to parse Unified Addresses (which we
currently do nothing with). That crate returns an `UnsupportedAddress`
error for unhandled address kinds, which we were previously logging.
However, we _do_ support the other address kinds; we just parse them in
the C++ code.

Closes zcash/zcash#5321.
2021-12-16 22:22:05 +00:00
Kris Nuttycombe 1e18410b55 Apply suggestions from code review
Co-authored-by: str4d <jack@electriccoin.co>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-12-14 13:02:41 -07:00
Kris Nuttycombe d1890ebd24 Apply suggestions from code review
Co-authored-by: str4d <jack@electriccoin.co>
2021-12-13 21:03:36 -07:00
Kris Nuttycombe 6cccc4ad3c Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-12-13 18:53:27 -07:00
Kris Nuttycombe 8ae8ddd7d1 Add tests for ufvk roundtrip serialization. 2021-12-13 18:53:27 -07:00
Kris Nuttycombe 22cd218e83 Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-12-13 18:53:27 -07:00
Kris Nuttycombe 217c56811d Add UnifiedFullViewingKey type.
This type is backed by the `zcash_address` implementaion of
unified full viewing keys. It is intended for serialization
and parsing of UFVKs, and provides conversion functions that
allow for construction to and from ZcashdUnifiedFullViewingKey
values.
2021-12-13 18:53:27 -07:00
Kris Nuttycombe c78887a148 Add Rust FFI components for unified full viewing keys. 2021-12-13 18:53:27 -07:00
Kris Nuttycombe 4257abd328 Adds SaplingDiversifiableFullViewingKey
Adds SaplingDiversifiableFullViewingKey as a superclass of
SaplingExtendedFullViewingKey, and reduces the Sapling component
of UnifiedFullViewingKey to the new intermediate type. This
permits deserialization from the data that will be present
in the serialized form of the Sapling component of a UFVK.
2021-12-13 18:53:25 -07:00
Kris Nuttycombe 640f31463f Update to ufvk zcash_address build. 2021-12-13 18:51:15 -07:00
Kris Nuttycombe 782c705cb1 Remove Orchard spending key equality implementation. 2021-11-29 14:26:25 -07:00
Kris Nuttycombe bde245d8bc
Remove incorrect FFI method documentation.
Co-authored-by: str4d <jack@electriccoin.co>
2021-11-29 13:08:30 -07:00
Kris Nuttycombe 6ee0dea218 Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-11-26 08:41:52 -07:00
Kris Nuttycombe 59a4c84112 Adds Orchard Address, IncomingViewingKey, FullViewingKey, and SpendingKey types. 2021-11-24 19:08:17 -07:00
Kris Nuttycombe 9202b127d0 Merge remote-tracking branch 'upstream/master' into feature/wallet_orchard 2021-11-23 18:38:07 -07:00
Kris Nuttycombe f49f4c73d8 Rename OrchardMerkleTree -> OrchardMerkleFrontier
Remove IncrementalSinsemillaTree; this will be replaced by
a more full-featured OrchardWallet type which embeds the
incremental merkle tree used in wallet operations.
2021-11-23 07:27:34 -07:00
str4d f8e99e7ba5
Merge pull request #5373 from ZcashFoundation/lib-zcash-script-sigops
Add legacy sigops counts to the zcash_script library API
2021-11-22 16:03:48 +00:00
Jack Grigg 675e489aff rust: Move `incremental_sinsemilla_tree_ffi` into crate root
Having this be a submodule of `orchard_ffi` while following Rust 2018
module structure made it impossible to use the `include!` macro on
`orchard_ffi.rs`, which is exactly what the `zcash_script` crate does.
See this comment for details:
    https://github.com/rust-lang/rust/issues/50132#issuecomment-969450868

To resolve this, we restructure the FFI library crate to only have FFI
methods in "leaf" module files.
2021-11-18 11:40:16 +00:00
Dimitris Apostolou e05c1ddf8a
Fix typos 2021-11-14 16:27:09 +02:00
Kris Nuttycombe 67557df165 Use SecureString for mnemonic phrase. 2021-10-30 08:26:59 -06:00
Kris Nuttycombe 666d135e2e Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-10-19 11:48:02 -06:00
Kris Nuttycombe daf443c9e6 Update librustzcash dependency version. 2021-10-19 11:48:02 -06:00
Kris Nuttycombe 8883ae8b9e Add support for externally searching for valid Sapling diversifiers.
In order to support generation of unified addresses, it needs
to be possible for the code generating a unified address to search
the space of Sapling diversifiers to obtain a valid diversifier.

Historically, invalid diviersifiers were simply skipped, so we retain
this behavior when obtaining a Sapling address from the legacy HD seed.
2021-10-19 11:48:02 -06:00
Jack Grigg 03ecb13300 rust: Skip running the Orchard batch validator on an empty batch
An empty batch will always succeed, but costs a 2-base multi-scaler
multiplication.
2021-09-22 14:52:47 +01:00
Jack Grigg f9a1986e43 rust: Move Orchard batch logic into BatchValidator methods 2021-09-22 12:36:01 +01:00
Jack Grigg 2aa9f766b2 Migrate to latest revisions of orchard and the zcash_* crates 2021-09-17 03:56:32 +01:00
Jack Grigg 710a5f8a9e Migrate to latest revisions of Zcash Rust crates 2021-09-15 00:35:53 +01:00
Kris Nuttycombe b8e86ddc44 Fix clippy complaints. 2021-08-24 09:54:01 -06:00
Kris Nuttycombe a61318ec85 Use manual serialization for Merkle frontiers rather than bincode. 2021-08-24 09:47:04 -06:00
Daira Hopwood fc3ea09b89 Avoid need to cast away const in the C caller of zip339_free_phrase.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-08-20 02:41:56 +01:00
Daira Hopwood 52ed61157f ZIP 339 support.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-08-13 21:09:35 +01:00
Jack Grigg 5bb339824d cargo fmt 2021-07-30 19:08:18 +01:00
str4d 037bfa32f3 Track lengths when copying receiver data from C++ to Rust
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-30 01:38:38 +01:00
str4d 5675a4eed4
Fix typo in method documentation
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-19 12:44:05 +01:00
Jack Grigg 612f250814 Pass network type through to UA address handling logic 2021-07-13 13:40:13 +01:00
Jack Grigg 776e9c5a4b Add support for decoding and encoding Unified Addresses 2021-07-13 03:22:47 +01:00
Kris Nuttycombe a4847132fa Apply suggestions from code review 2021-07-09 10:44:59 -06:00
Kris Nuttycombe e588d1d790 Update Orchard commitment tree hashes to use total MerkleCRH^Orchard. 2021-07-09 10:40:49 -06:00
Homu c34162d6dd Auto merge of #5225 - LarryRuane:2021-06-v5-transaction, r=str4d
Implement v5 transaction consensus rules

Part of zcash/zcash#5196.
2021-07-01 12:37:17 +00:00
Kris Nuttycombe 7a2be88768 ZIP 213: Add checks to support Orchard shielded coinbase outputs. 2021-07-01 12:42:37 +01:00
Larry Ruane 66de454a20 ZIP 225: v5 transaction check rules 2021-07-01 12:41:25 +01:00
Jack Grigg 8ad7371800 Include Orchard bundle in transaction dynamic usage 2021-06-29 15:05:46 +01:00
Kris Nuttycombe 572719fca6 Apply suggestions from code review
Use const pointers wherever possible.

Co-authored-by: str4d <jack@electriccoin.co>
2021-06-28 17:37:32 -06:00
Kris Nuttycombe 5550dbe1b8 Fix implmentation of OrchardMerkleTree.DynamicMemoryUsage 2021-06-28 16:33:40 -06:00
Kris Nuttycombe 8ee8c9f6ab Consistently panic on null commitment tree pointers.
Orchard commitment tree pointers should never be null.
2021-06-28 15:27:21 -06:00
Kris Nuttycombe d46dbd9ea4 Apply style suggestions. 2021-06-28 14:49:39 -06:00
Kris Nuttycombe d533d3ccbf Fix header guards for incremental_sinsemilla_tree.h 2021-06-28 13:54:15 -06:00
Kris Nuttycombe a3214285c2 Apply suggestions from code review
Co-authored-by: str4d <jack@electriccoin.co>
2021-06-28 13:54:15 -06:00
Kris Nuttycombe 0a1e845681 Documentation cleanup. 2021-06-23 16:17:53 -06:00
Kris Nuttycombe 13fd4c9a1c Add Orchard merkle tree anchor tests. 2021-06-23 16:06:30 -06:00
Kris Nuttycombe 0c1a5878ad Check nullifiers length against bundle actions length. 2021-06-23 16:06:30 -06:00
Kris Nuttycombe 437b8c488a Orchard changes to coins & consensus. 2021-06-23 16:06:30 -06:00
Kris Nuttycombe 68ce7e4828 Implement the Rust side of the incremental merkle tree FFI. 2021-06-23 16:06:30 -06:00
Jack Grigg 1072cd4e3e Check Orchard bundle-specific consensus rules, i.e. proofs
We are already checking the other bundle-specific consensus rules:
- Encodings are checked during transaction parsing.
- Signatures are batch-validated.

Closes zcash/zcash#5195.
2021-06-21 18:33:57 +01:00
Jack Grigg 9ad5b75b30 rust: Load Orchard circuit parameters at startup 2021-06-21 18:33:57 +01:00
Jack Grigg 509e7c7d79 Implement Orchard pool value tracking
The ZIP 209 rules preventing the Sprout and Sapling pool values from
going negative, are extended to the Orchard pool.
2021-06-21 01:40:49 +01:00
Jack Grigg 3efa9cb75e rust: Document some requirements for history tree FFI methods 2021-06-20 22:42:58 +01:00
Jack Grigg 16317bc6af Use V2 history trees from NU5 onward 2021-06-18 12:35:53 +01:00
Jack Grigg b1d3335ef6 rust: Move history tree FFI declarations into a separate header 2021-06-18 12:35:53 +01:00
Jack Grigg 3192820dbc rust: Migrate to zcash_history with versioned trees 2021-06-18 12:35:53 +01:00
Jack Grigg fbeb9412f2 rust: Move history tree FFI logic into a module 2021-06-18 12:35:53 +01:00
Kris Nuttycombe f14651b56b Update transaction auth commitments for pre-v5 transactions.
As specified in https://github.com/zcash/zips/pull/520

Fixes #5218
2021-06-15 08:21:46 -06:00
Jack Grigg af1b9c15bb Implement Orchard authorization batch validator
- Currently, only RedPallas signatures are batch-validated. We can extend
  this validator to cover Halo 2 proofs in the future.

- Signatures in a batch are not retried individually if the batch fails:
  - For per-transaction batching (when adding to the mempool), we don't
    care which signature within the transaction failed.
  - For per-block batching, we currently don't care which transaction
    failed. We might do so in future, at which point this behaviour can
    be easily changed.
2021-06-14 22:47:00 +01:00
str4d 7195b72ce2 rust: Explicitly return null hash for pre-v5 auth digests
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-14 17:48:53 +01:00
Jack Grigg 1bbdadadc3 rust: Documentation improvements to FFI methods 2021-06-14 17:39:33 +01:00
Jack Grigg cfa7d6bf73 test: Generate valid Sapling types
The C++ parser only requires the various Sapling components to be 32-byte
arrays. The Rust parser enforces stricter type checks at parse time, and
we now unconditionally parse with the Rust parser for deriving txids.
2021-06-13 07:57:39 +01:00
Jack Grigg 0b8a348c2b ZIP 244 signature digests 2021-06-12 20:03:53 +01:00
Jack Grigg bd1fd2eaca ZIP 244 transaction digests 2021-06-12 20:03:53 +01:00
Jack Grigg 36874e7f07 rust: Document read_callback_t and write_callback_t 2021-06-11 23:03:26 +01:00
Jack Grigg bfc77d571e v5 transaction format parser
The majority of the parser is in C++, but Orchard bundles are parsed
exclusively by Rust.

The ZIP 244 test vectors are brought in here so we can start by testing
round-trip serialization.
2021-06-10 22:11:42 +01:00
Jack Grigg e6dd9550e1 rust: Enable C++ streams to be passed into Rust code 2021-06-10 22:11:41 +01:00
Jack Grigg 0be07bb70c Implement ZIP 216 consensus rules
In addition to the specified consensus rules, we unconditionally enable
ZIP 216 in the following situations:

- Wallet code
  - Transaction building
  - Nullifiers for wallet notes
- Tests
- Benchmarks

Closes zcash/zcash#5201.
2021-06-10 11:36:12 +01:00
Jack Grigg 3d6c1e4426 metrics 0.16 and metrics-exporter-prometheus 0.5
Includes the allowlist logic that we upstreamed.
2021-06-06 00:53:19 +01:00
Jack Grigg 419275c4f5 Migrate to latest zcash_* crates
This includes the ff 0.10 dependency stack.
2021-06-06 00:53:19 +01:00
Jack Grigg 83eef40f4c rust: Add license header to metrics_ffi::prometheus 2021-03-31 09:19:17 +13:00
Jack Grigg 78b83fd6e9 metrics: Enable gauges with fully-static labels 2021-03-30 15:12:36 +13:00
Jack Grigg d08cdbe5f7 metrics: Implement IP access control on Prometheus scrape endpoint 2021-03-30 15:12:08 +13:00
Jack Grigg 1e5f9284c0 rust: Check for invalid UTF-8 in -prometheusmetrics argument 2021-03-30 15:12:08 +13:00
Jack Grigg 523f969654 rust: Use consistent include guards in header files 2021-03-30 15:12:08 +13:00
Jack Grigg 92e75de46f metrics: Add support for labels
Given that label values may be dynamic, any metrics callsite with labels
can't be stored statically. Instead, we contruct a fresh metrics Key each
time we hit a metric with labels (if a metrics recorder is installed).
2021-03-30 15:12:08 +13:00
Jack Grigg 7a96af8260 rust: Move helper macros into rust/helpers.h 2021-03-30 15:12:08 +13:00
Jack Grigg 37b42d8a41 tracing: Merge TracingSpanFields macro into TracingSpan
Leverages the VA_OPT macro library, which is a polyfill for __VA_OPT__
on non-C++20 platforms, to enable TracingSpan to support optional fields.

Source: https://github.com/willwray/VA_OPT
License: Boost Software License, Version 1.0
2021-03-30 15:12:08 +13:00
Jack Grigg a79ffa3b50 rust: Add a Prometheus metrics exporter
The -prometheusmetrics=host_name:port config option enables the metrics
exporter.
2021-03-30 15:12:07 +13:00
Jack Grigg 8482ed6356 rust: Implement FFI interface to metrics crate 2021-03-30 15:11:17 +13:00
Jack Grigg 2e12078cfc depends: Update Rust to 1.51.0 2021-03-27 11:47:34 +13:00
Jack Grigg 8393b3da88 rust: zcash_{primitives, proofs} 0.5.0 2021-03-27 11:47:25 +13:00
Jack Grigg 79f531c485 rust: Use renamed broken_intra_doc_links lint 2021-01-04 16:40:18 +00:00
Kris Nuttycombe 8cdac686eb Don't log to stdout if a file logger is configured.
This fixes an error introduced in 5dce316.
2020-12-18 22:20:04 -07:00
Jack Grigg 5dce316f10 tracing: Simplify init logic using optional layers
The layer creation itself looks a bit more complex, but this is due to
how altering the presence of timestamps changes the type signature of the
formatter. The main improvements are that we now only initialise the
registry in a single location, and the log filter reload handle has a
single type signature (whereas previously its type signature depended on
the configuration).

Requires a minimum of tracing-subscriber 0.2.12, which added this feature.

Part of zcash/zcash#4668.
2020-12-18 19:42:09 +00:00
Jack Grigg c97665f397 tracing: Remove unnecessary tracing_init_inner internal function
This became unnecessary in 25d2e6e3c3.
2020-12-18 19:42:09 +00:00
Dimitris Apostolou f459e43dc9
Update links 2020-12-13 11:24:44 +02:00
Jack Grigg c3a91be479 Switch to ed25519-zebra for consensus signature checks
ed25519-zebra can validate all signatures pre-Canopy, and now that Canopy
is active on mainnet, we don't need to worry about consensus divergence.
2020-12-04 03:42:16 +00:00
Jack Grigg 25dafc3872 lint: Apply include guard style to src/rust/include 2020-11-09 23:06:21 +00:00
Jack Grigg 508aadd2f3 FFI: Merge librustzcash_init_zksnark_params variants into one function
Rust 1.39.0 added support for attributes on function parameters.

Closes #4651.
2020-10-08 22:50:57 +01:00
Jack Grigg 0f3baaba71 tracing: Correctly override tracing::Span move constructors 2020-09-24 15:58:19 +01:00
Jack Grigg 02b7d2afa2 blake2b: Allow consuming partial BLAKE2b output
Some consumers were relying on the libsodium behaviour that the output
length was not checked against the configured hash output length.
blake2b_simd::Hash::as_bytes returns a correctly-sized slice, which we
were then failing to copy into the consumer's buffer. Instead of
requiring the consumer to provide a full-length buffer and then truncate
the output themselves (likely causing a double-copy, as we don't have
nice slices in C++), we instead allow the consumer to consume up to the
maximum output.
2020-09-24 15:58:19 +01:00
Jack Grigg 2d172e121f Replace libsodium's crypto_generichash_blake2b with blake2b_simd 2020-09-24 15:58:14 +01:00
Jack Grigg 6c1204b228 FFI: Rename r to rcm 2020-08-25 17:30:38 +01:00
Jack Grigg fbe54c4b6c FFI: Rename to librustzcash_sapling_compute_cmu
Part of zcash/zcash#3446.
2020-08-25 17:25:00 +01:00
Jack Grigg bb1e1e57a7 FFI: Migrate to bls12_381 and jubjub crates 2020-08-25 13:07:22 +01:00
Jack Grigg 3fd409433b FFI: Remove circuit parameter hashes from librustzcash_init_zksnark_params
These were hard-coded into the underlying zcash_proofs::load_parameters
function.

Closes zcash/zcash#4519.
2020-08-25 13:07:22 +01:00
Jack Grigg d41cf37841 ed25519: Panic (triggering abort) if nullptr passed into APIs 2020-08-20 19:00:48 +01:00
Jack Grigg efb4246ad3 Replace libsodium's crypto_sign with ed25519-zebra
crypto_sign_verify_detached is still used within the consensus rules
until Canopy activation. ed25519-zebra generates signatures that are
valid under both pre- and post-Canopy rules (for our honest usage),
so we can use it to generate transaction signatures now. Then once
Canopy activates, we can remove the remaining usages of crypto_sign.
2020-08-20 19:00:47 +01:00
Jack Grigg 1c447d85c0 Replace libsodium's randombytes_buf with rand_core::OsRng::fill_bytes 2020-08-18 21:57:06 +01:00
Homu 940fe0b3be Auto merge of #4657 - str4d:tracing-fields, r=str4d
Add support for logging fields in spans and events

Field values must be pointers to C strings, which in practice means that they
cannot be formatted inline (as the pointer must remain valid across the FFI).
This might be improved by future iterations of the macros.

`LogPrint()` is also moved to the DEBUG level, leaving `LogPrintf()` at INFO.
2020-08-17 16:23:58 +00:00
Jack Grigg 25d2e6e3c3 tracing: Rework tracing_init into a single function
This will make it possible to de-duplicate some components of the
tracing configuration. The layers themselves cannot be fully
de-duplicated due to type system constraints (a Layer wraps a
Subscriber, and is itself a Subscriber typed on the one it wraps).
2020-08-11 13:16:28 +01:00
Jack Grigg 90e86b53bf tracing: Parse log_path into an Option<Path> 2020-08-11 11:45:30 +01:00
Jack Grigg f54f9d5e06 tracing: Format field values with Display
This removes the surrounding double quotes from logged field values.
2020-08-11 01:36:08 +01:00
Jack Grigg d1e0087bd5 tracing: Add support for span fields 2020-08-11 01:36:08 +01:00
Jack Grigg 31ba572811 tracing: Add support for event fields 2020-08-11 00:51:33 +01:00
Jack Grigg 4591a4f832 tracing: Add MAP macro
Source: https://github.com/swansontec/map-macro
License: X11

Also updates contrib/debian/copyright for recent license additions.
2020-08-11 00:51:12 +01:00
Jack Grigg a7f695dbae FFI: Fix tracing log path handling on Windows
Windows uses u16 for OS strings, requiring an owned OsString when
converting to Rust. This needs to be stored in its own variable, so we
can take an immutable reference to it in Path::new.
2020-08-10 23:02:43 +01:00
Jack Grigg 2ae4985d26 tracing: Document macro arguments that MUST be static constant UTF-8 strings 2020-08-07 15:26:28 +01:00
Jack Grigg c87205e5e0 tracing: Log field values that aren't valid UTF-8
This ensures that we retain as much logged information as possible,
while still enabling us to identify field values that cause problems.
2020-08-07 15:26:28 +01:00
Jack Grigg ba831f814a rpc: Throw error in setlogfilter if filter reloading fails 2020-08-07 15:26:28 +01:00
Jack Grigg 92f18661d8 FFI: Add missing <stddef.h> includes 2020-08-07 15:26:28 +01:00
Jack Grigg f57f1c17a2 tracing: Use 'static constexpr' hack in macros
This enables us to enforce that the requisite macro parameters are
compile-time constants with static storage duration.
2020-08-07 15:26:28 +01:00
Jack Grigg cb294bbda0 FFI: Extract common codeunit types into a rust/types.h header 2020-08-07 15:26:28 +01:00
Jack Grigg aae7583cdb Add support for tracing spans 2020-08-07 15:26:28 +01:00
Jack Grigg 3f81f9be80 Add support for reloading the tracing filter
Due to tracing's extensive use of the Rust type system, we have to Box
the handle in order to pass it back across the FFI. We define a
ReloadHandle trait which exposes the necessary Handle APIs.
2020-08-07 15:08:10 +01:00
Jack Grigg 2b7d824714 Use a tracing EnvFilter directive for -debug flags 2020-08-07 15:08:10 +01:00
Jack Grigg e04da74957 FFI wrapper around tracing crate
The tracing crate is initialized with an optional log path, and will
either start a background thread for non-blocking log writing, or write
directly to standard output with ANSI encoding.

C preprocessor macros are used to emulate the Rust macros natively
provided by the tracing crate. They handle the creation of static
tracing callsites, and ensure that the correct file and line number
information is used for each logging site.
2020-08-07 15:07:44 +01:00
therealyingtong 13aa74aa45
Pass HistoryNode struct to librustzcash FFI 2020-07-21 17:56:47 +08:00
Sean Bowe c3b3e07160
Change LIBSODIUM_ERROR to -1.
We only relied on success being 0 and our code was otherwise agnostic to the
actual return code in the event of failed signature verification, but this
change keeps the API consistent.
2020-07-03 09:37:34 -06:00
Sean Bowe 394947de3a
Migrate ZIP 215 test vectors to gtest suite. 2020-07-03 09:36:34 -06:00
Sean Bowe e9c065df5b
Cargo fmt 2020-06-29 09:40:35 -06:00
Sean Bowe 8918eca876
Add more exhaustive tests for ZIP 215 compatibility. 2020-06-29 09:40:34 -06:00
Sean Bowe 58250b4801
Turn return values for libsodium-like API into constants for clarity. 2020-06-29 09:36:54 -06:00
Sean Bowe f29c731915
Minor adjustments to librustzcash and tests. 2020-06-23 16:35:19 -06:00
Sean Bowe ba04450945
Remove unused curve25519-dalek dev-dependency. 2020-06-23 16:29:51 -06:00
Sean Bowe 14bdf7e811
Remove bincode crate. 2020-06-23 15:38:59 -06:00
Sean Bowe 2a3527bfe8
Add test that a weird signature successfully validates. 2020-06-23 14:31:41 -06:00
Sean Bowe 3688f508d8
Make ed25519-zebra available via librustzcash. 2020-06-22 15:58:26 -06:00
Danny Willems 332ce1a800
Use preprocessor for ENTRY_SERIALIZED_LENGTH 2020-05-15 19:50:57 +02:00
Danny Willems e465731e69
Use assert.h instead of define manually static_assert 2020-05-15 19:47:49 +02:00
Danny Willems 80fe96a04e
librustzcash: make the header C compatible 2020-05-15 19:38:41 +02:00
Jack Grigg 82fe37d22b Use a C array for HistoryEntry instead of std::array
std::vector<T> is guaranteed to store T contiguously. However, there is
no guarantee that sizeof(std::array<unsigned char, N>) == N, which
prevents us from interpreting std::vector<std::array<unsigned char, N>>
as &[[u8; N]] on the Rust side of the FFI.

Instead, we define HistoryEntry as a struct wrapping a C array, which
(as checked by static_assert) contains no padding.
2020-04-08 08:49:01 +12:00
Jack Grigg 8a658dfd33 Return the correct root from librustzcash_mmr_{append, delete}
Per https://zips.z.cash/zip-0221#tree-node-specification :

    Once the MMR has been generated, we produce hashChainHistoryRoot,
    which we define as the BLAKE2b-256 digest of the serialization of
    the root node.
2020-04-08 08:49:01 +12:00
Jack Grigg c7b2fc101d Bring in updates to librustzcash crate
Source: https://github.com/zcash/librustzcash.git
Revision: 53bd5d4724c96374c4bf94068207fcc362b01ac7
2020-03-13 14:16:45 +13:00
Jack Grigg 5fe41654bf Move root of Rust crate into repo root
This enables IDE integration to work (which requires the Cargo.toml to
be in the repo root).

"make clean" no longer runs "cargo clean", because IDE integrations hold
locks on files within the Rust build directory, and an error inside
"cargo clean" error would prevent "make clean" from completing (and
removing other files).
2020-03-06 16:49:03 +13:00
Jack Grigg 62d0af94cf rust: Adjust Cargo.toml so that it compiles
The Cargo.lock is updated to account for the Zcash Rust crates no longer
being in the same workspace. Dependencies that were not transitive
dependencies of librustzcash are also removed, but no versions change.
2020-03-06 16:24:14 +13:00
Jack Grigg 28b2a65c64 rust: Pin toolchain to 1.36.0, matching depends system 2020-03-06 16:24:14 +13:00
Jack Grigg ef81abdde3 Bring in Cargo.lock from librustzcash repo
Source: https://github.com/zcash/librustzcash.git
Revision: a57dc7f47807ea50cb0a5deec9b84b3e7da11bc0
2020-03-06 16:24:14 +13:00
Jack Grigg 443fe7d092 Bring in librustzcash crate
Source: https://github.com/zcash/librustzcash.git
Revision: a57dc7f47807ea50cb0a5deec9b84b3e7da11bc0
2020-03-06 16:24:14 +13:00