Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zcash_client_sqlite crate #246

Merged
merged 21 commits into from Jul 9, 2020
Merged

zcash_client_sqlite crate #246

merged 21 commits into from Jul 9, 2020

Conversation

str4d
Copy link
Contributor

@str4d str4d commented Jun 25, 2020

My note-spending-v7 branch is pretty stable at this point, and now being depended on more widely (after the ECC wallet was recently open-sourced). I rebased my branch on current master to fix merge conflicts (due to recent refactors), but it's otherwise unaltered.

Closes #71.

Copy link
Contributor

@gmale gmale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this still have the commit to set activation heights for the Heartwood network upgrade? I'm not seeing that commit in the history. Nor do I see the related changes in this PR but it could be all this new-fangled github UI throwing me off.

Perhaps that needs to be (or has been) applied to the zcash_primitives crate as a separate PR?

@str4d
Copy link
Contributor Author

str4d commented Jun 25, 2020

@gmale that commit was separately applied in #239.

@str4d str4d force-pushed the zcash_client_sqlite branch 7 times, most recently from edfa9c1 to dbd3122 Compare June 26, 2020 12:17
Requires bumping the MSRV to 1.40.0 because libsqlite3-sys uses features
introduced in that version. remove_dir_all can similarly be unpinned.
@codecov
Copy link

codecov bot commented Jun 26, 2020

Codecov Report

Merging #246 into master will decrease coverage by 0.26%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #246      +/-   ##
==========================================
- Coverage   34.71%   34.45%   -0.27%     
==========================================
  Files          95       97       +2     
  Lines       11457    11544      +87     
==========================================
  Hits         3977     3977              
- Misses       7480     7567      +87     
Impacted Files Coverage Δ
zcash_client_sqlite/src/address.rs 0.00% <0.00%> (ø)
zcash_client_sqlite/src/error.rs 0.00% <0.00%> (ø)
zcash_primitives/src/transaction/builder.rs 51.42% <0.00%> (-1.87%) ⬇️
zcash_proofs/src/prover.rs 0.00% <0.00%> (ø)
zcash_primitives/src/primitives.rs 47.32% <0.00%> (-0.90%) ⬇️
zcash_primitives/src/pedersen_hash.rs 97.91% <0.00%> (-0.05%) ⬇️
bellman/src/gadgets/boolean.rs 32.68% <0.00%> (ø)
zcash_primitives/src/note_encryption.rs 79.52% <0.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7134ab8...8c250ca. Read the comment docs.

Copy link
Contributor

@gmale gmale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK

/// let db_data = data_file.path();
/// init_data_database(&db_data).unwrap();
/// ```
pub fn init_data_database<P: AsRef<Path>>(db_data: P) -> Result<(), Error> {
Copy link
Contributor

@daira daira Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should require specifying privacy-relevant policy such as whether ovks are stored (explicitly, with no defaults).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively (or in addition), transact::create_to_address could require specifying a per-transaction policy; this is where the policy would be enforced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically, here is where the current default policy is implemented: https://github.com/zcash/librustzcash/pull/246/files#diff-0db70545aba62e450ec1e1634b293f05R104

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking request to require specifying whether ovks are stored when opening the database. This will require a version bump according to semver. I haven't reviewed the rest of the PR.

@daira
Copy link
Contributor

daira commented Jun 29, 2020

There should also be an API to delete data on transactions held by the wallet, e.g. ovks and other viewing keys, and any data cached from them. As @str4d said on Discord:

Without ovk you lose the non-change recipients and memos [if you restore from the backup seed]. You still learn how much was spent and when.

The use case here is that a wallet can have a button that someone might choose to use if they are about to go into a potentially coercive environment where data on their device could be seized (the assumption being that their backup seed is not available in the coercive environment).

@imichaelmiers
Copy link

I agree with all of this, but we should be clear on which does what. I could easily see down stream devs confusing what does what. This might result in end users deleting history but not OVK and thinking they've erased a past sensitive purchase. Or that deleting OVK erases past purchases.

Ideally there should be some policy switch with clear labels:

  1. no history
  2. (if we support this) device lcoal history file but no on chain storage.
  3. history stored on chain encrypted and undeletable , but only accessible with off device backup key. Erasing this key may lose access to money
  4. history stored on chain encrypted and undeletable, accessible from keys stored on the device.
    Erasing this key may lose access to money

@gmale
Copy link
Contributor

gmale commented Jun 29, 2020

This all touches on a much larger issue of whether librustzcash should store any state. I would propose that we not bandaid key storage and instead take a thoughtful approach to implementing #142 which returns control of data storage to the wallet.

I agree with all of this, but we should be clear on which does what.

I strongly agree with that statement. We seem to be discussing features and decisions that probably should be made at the wallet level, rather than within librustzcash. The root issue seems to be that, with this PR, librustzcash will officially manage state and we could avoid that entirely and let wallets manage state, instead.

@gmale
Copy link
Contributor

gmale commented Jun 29, 2020

The discussion here relates to the "Hide Transaction" feature request on the wallet.

@gmale gmale mentioned this pull request Jun 29, 2020
Copy link
Contributor

@pacu pacu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested. Ok!

This enables an SQLite light client to specify whether recipient history
can be recovered from the block chain (and by what outgoing viewing key)
with per-transaction granularity.
@str4d
Copy link
Contributor Author

str4d commented Jul 9, 2020

Blocking request to require specifying whether ovks are stored when opening the database.

I've implemented an outgoing viewing key usage policy for transact::create_to_transaction, which provides per-transaction granularity. Previous behaviour can be retained by using OvkPolicy::Sender.

This will require a version bump according to semver.

zcash_client_sqlite is internally still version 0.0.0, and has thus far only been used by pinning a git commit. The version bump will occur inherently when 0.1.0 is released.

There should also be an API to delete data on transactions held by the wallet, e.g. ovks and other viewing keys, and any data cached from them.

Let's implement this in a subsequent PR.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK (with particular attention to 8188fae, but I also reviewed the rest of the PR lightly).

value INTEGER NOT NULL,
rcm BLOB NOT NULL,
nf BLOB NOT NULL UNIQUE,
is_change INTEGER NOT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.sqlite.org/datatype3.html#boolean_datatype

SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true).

😢 (not a problem, but sigh).

nf BLOB NOT NULL UNIQUE,
is_change INTEGER NOT NULL,
memo BLOB,
spent INTEGER,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this also supposed to be a boolean? Why no NOT NULL?

Copy link
Contributor Author

@str4d str4d Jul 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is a foreign key to the transactions database, pointing at the transaction this note is spent in. NULL represents the "not spent" case.

zcash_client_sqlite/src/query.rs Show resolved Hide resolved
}
}

/// Returns the memo for a received note, if it is known and a valid UTF-8 string.
Copy link
Contributor

@daira daira Jul 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider filing a ticket to add APIs that get the raw memo without checking that it is valid UTF-8.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way this crate is designed (specifically that db_data is read-only outside the crate), it's expected that the caller can query the database for that information themselves.

// get re-marked as spent).
//
// Assumes that create_to_address() will never be called in parallel, which is a
// reasonable assumption for a light client such as a mobile phone.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumption should be documented in the function comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is:

Do not call this multiple times in parallel, or you will generate transactions that double-spend the same notes.

@str4d str4d merged commit d380a8c into zcash:master Jul 9, 2020
@str4d str4d deleted the zcash_client_sqlite branch July 9, 2020 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add feature flag to toggle between mainnet and testnet
5 participants