-
Notifications
You must be signed in to change notification settings - Fork 725
[WIP] zPIV Encryption #413
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
[WIP] zPIV Encryption #413
Conversation
1476995 to
71b7c70
Compare
Currently zPIV is stored as plaintext. Created new class CZerocoinCrypter which implements the AES256CBC routine same as CCrypter, but operated over a CBigNum inplace. This allows for CZerocoinMint to initialize and set key data for CZerocoinCrypter on construction. The cipher is derived from a pub/priv keypair that the wallet owns.
71b7c70 to
021fb50
Compare
|
Currently hitting Segfault on -reindex. Currently working toward a solution |
rejectedpromise
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently segfaulting and putting testnet DB into errorstate
|
progress update: I forgot to check for InitialChainSync ;) Will reopen if full sync and no error minting/spending |
presstab
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Havent run it yet, looks like some cool code. Hoping to run it soon.
src/primitives/zerocoin.cpp
Outdated
| } | ||
|
|
||
| //inialize IV for 32 bytes | ||
| vector<unsigned char> chIV(crypter.KEY_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should follow our current naming conventions. A vector will start with v and camel case after. A vector of unsigned chars should start with vch. Descriptive names are also a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function appears to use no member variables of CZeromint at all (plus it uses a global pointer) so I wonder why it is not a free function or part of the CWallet class. Personally I would have added this, Encrypt and Decrypt as separate functions so there would be separate plain CZeromint objects and encrypted objects. I don't see the benefit of encrypting an object if the un-encrypted member variables are still accessible. However, with separate objects you can dispose of the un-encrypted ones in favor of the encrypted (once they've been encrypted) or vice-versa. This may just be a lack of understanding of the bigger picture here but it just doesn't seem like a good separation of concerns. Hope this is clear. So essentially a separate layer or separate encrypted objects that is all done outside of this class
src/primitives/zerocoin.cpp
Outdated
| if(!crypter.Decrypt(serialNumber) || | ||
| !crypter.Decrypt(randomness)) { | ||
|
|
||
| LogPrintf("%s : failed to encrypt zerocoin mint\n", __func__); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in log print
src/rpcwallet.cpp
Outdated
| for (CZerocoinMint mint : vMintsToUpdate) { | ||
|
|
||
| if(pwalletMain->IsCrypted() && !mint.Encrypt()){ | ||
| LogPrintf("Error: encryption of mint failed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be beneficial to add context to these logs so that if there is a failure to mint we know where exactly in the code it is happening. Also you need to terminate the string with \n.
src/rpcwallet.cpp
Outdated
| denomination = libzerocoin::IntToZerocoinDenomination(params[1].get_int()); | ||
| list<CZerocoinMint> listMints = walletdb.ListMintedCoins(!fIncludeSpent, false, false); | ||
|
|
||
| for(CZerocoinMint mint : listMints) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like bad form to have two identical for loops right next to each other. Any particular reason not to decrypt the mint within the loop a few lines below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop below was const objects. Wasn't sure if there is reasoning around when to treat the objects as constants and when to treat them as mutable. Is there any particular reason in the loop below it is marked const?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's marked const since there is no need to change the object itself. Thus code is clearer as to what is going on. Now you are decrypting, so you could either remove the 'const' restriction or have Decrypt make new object. BTW, shouldn't the error message be "Decryption of mint failed?"
src/walletdb.cpp
Outdated
| CZerocoinMint mint; | ||
| ssValue >> mint; | ||
|
|
||
| if(pwalletMain->IsCrypted() && !mint.Decrypt()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want to decrypt the coins everytime we get the list of mints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does pwalletMain->IsCrypted() returning false not terminate the statement?
src/zerocoincrypter.cpp
Outdated
| @@ -0,0 +1,79 @@ | |||
| // | |||
| // Created by rejectedpromise on 11/25/17. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this with the PIVX Devlopers copyright heading.
src/zerocoincrypter.h
Outdated
| @@ -0,0 +1,61 @@ | |||
| // | |||
| // Created by rejectedpromise on 11/25/17. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace
|
Reopen. Still may have problems with DB on -reindex causing runaway exception. BE WARNED. |
|
May also be problems in logic for syncing after encryptions have happened |
|
Just off the top of my head, I think this should bump the wallet |
Move cryption functionality into crypter, and crypting same time as is currently implemented in wallet. Discarding plain mints and returning ciphered copies. Crashing on open of wallet.
| CMakeLists.txt | ||
| cmake-build-debug | ||
| db4/ | ||
| db-4* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
|
Where are we on this?? |
|
Current status of ezPIV:
Still debugging issues with reading and writing to disk |
… to vMasterKey for encryption Log statements in new methods for debugging no guarantees on no segfaults during zerocoin minting on this commit
|
What is the current status of this. Still waiting for this so that I can finish deterministic zpiv. |
…rocoin_encryption_tests.cpp Haven't tested live on testnet yet, but think it should be working properly through wallet::CCryptoKeyStore Crypto actions should happen automatically, as with the wallet priv keys, and while unlocked (walletpassphrase kept in memory) decrypts crypted mints that are stored in a private map in CCryptoKeyStore Hoping to get some good testnet runs tomorrow
59697a1 to
25df082
Compare
src/crypter.cpp
Outdated
| return false; | ||
|
|
||
| // vector<unsigned char> x(vchPlaintext.begin(), vchPlaintext.end()); | ||
| // CBigNum t(x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
src/crypter.cpp
Outdated
|
|
||
| vchCiphertext.resize(nCLen + nFLen); | ||
|
|
||
| //CBigNum y(vchCiphertext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
| vector<unsigned char> key(vMasterKey.begin(), vMasterKey.end()); | ||
| vector<unsigned char> plain(vchPlaintext.begin(), vchPlaintext.end()); | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove spaces
src/crypter.cpp
Outdated
| // if (!fKeySet) | ||
| // return false; | ||
| // | ||
| // //already encrypted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
src/crypter.cpp
Outdated
|
|
||
| fUseCrypto = true; | ||
| BOOST_FOREACH (KeyMap::value_type& mKey, mapKeys) { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove space
|
|
||
| public: | ||
| enum CryptionMethod { | ||
| ENC, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
| enum ZerocoinSecrets { | ||
| SERIAL, | ||
| RANDOM | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
src/rpcwallet.cpp
Outdated
| mint.SetHeight(nHeight); | ||
|
|
||
| // if(pwalletMain->IsCrypted() && !mint.Encrypt()){ | ||
| // LogPrintf("Error: encryption of mint failed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
|
@presstab hoping to get it up on testnet tomorrow to do some live runs |
|
Status update: @Fuzzbawls I do not think this would require a version bump, as it should be backwards compatible, as it hooks up to the current encryption scheme and uses the walletpassphrase same as the private keys, therefore not requiring bump AFAIK |
…let for encryption
Fuzzbawls
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few changes needed from what I can see at a glance, otherwise great progress!
| #include <boost/assign/list_of.hpp> | ||
|
|
||
| #include <univalue.h> | ||
| //#include <univalue.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, think your IDE was giving you some unique errors if was needed.
#include <univalue.h> should be enough.
| #include "../sync.h" | ||
| #include "../main.h" | ||
| #include "../crypter.h" | ||
| #include "../wallet.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not digging the relative includes here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, nice catch. I have just recently configured CMakeLists.txt in CLion to work off of absolute paths. Forgot to actually crawl through and change all the relatives 👍
| ss << zerocoinMint.GetValue(); | ||
| uint256 hash = Hash(ss.begin(), ss.end()); | ||
|
|
||
| LogPrintf("pub: %s\nserial: %s\nrand: %s\ncrypted: %b\n", zerocoinMint.GetValue().ToString(16), zerocoinMint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest making this a LogPrint("zero", ...); instead of a LogPrintf() to reduce log spam.
Status updateFailing on block indexing since trying to read serials from walletDB, checking for spent/owned/etc., while they are still encrypted ( Initial approachKeep a list of serial hashes in pwallet to enable checking if serial is owned by this wallet, without having to expose private data. |
|
pulled into 3.1.0 |
Currently, zPIV mints are stored, unencrypted in wallet. Functionality has been rerouted through CWallet -> CCryptoKeyStore to enable access to the master wallet passphrase when wallet unlocked. zPIV mints are then encrypted the same way that wallets private keys are before saving to wallet.