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

Changes to handle invalid coin(s) in privacy-wallet-service. #3002

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

snehal-das
Copy link
Contributor

@snehal-das snehal-das commented Apr 25, 2023

  • Problem Overview
    Current privacy library does not handle invalid coins gracefully. The logic of claiming coins is modified to handle this scenario.

  • Testing Done
    Testcase: Create a scenario where an invalid coin is transferred to a user. Observe how the invalid coin is handled at the recipient's end.
    Observation: The invalid coin is no longer reported to the DApp, the user does not notice any issue and future transactions are synced successfully.

@snehal-das snehal-das changed the title Draft: Initial changes to handle invalid coin(s) in transfer Changes to handle invalid coin(s) in privacy-wallet-service. Apr 26, 2023
@snehal-das
Copy link
Contributor Author

Changes to the privacy-wallet-service is complete and tested to work as expected. Changing status from draft to ready for merge.

@bandatarunkumar bandatarunkumar marked this pull request as ready for review April 26, 2023 11:32
@bandatarunkumar bandatarunkumar requested a review from a team as a code owner April 26, 2023 11:32
@@ -275,14 +275,16 @@ ::grpc::Status PrivacyWalletServiceImpl::handleUserClaimCoinsRequest(::grpc::Ser
response->set_err(err_msg);
return grpc::Status(grpc::StatusCode::ABORTED, err_msg);
}
} catch (const libutt::api::operations::InvalidCoinsInTransfer& e) {
std::cout << e.what() << std::endl;
response->mutable_claim_coins_response()->set_warning(e.what());
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, shouldn't we return false in the succ?
Also, I would suggest returning the invalid nullifiers and the reply.
Finally, we need to expose a way for the user to remove these invalid coins, otherwise it won't be able to proceed (the invalid coins will be chose over and over again)

Copy link
Contributor Author

@snehal-das snehal-das Apr 27, 2023

Choose a reason for hiding this comment

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

In this case, shouldn't we return false in the succ?

Technically, the recipent was able to claim coins received. Reporting back false after claiming all valid coins seems incorrect to me. The more correct approach seems to be to return true with a warning.

Also, I would suggest returning the invalid nullifiers and the reply.

I didn't want the dapp to handle the invalid coins, but this is something that can be implemented. I'll discuss with you in more detail.

@@ -447,9 +447,13 @@ void User::updateTransferTx(const Transaction& tx, const TxOutputSigs& sigs) {

// Claim coins
auto claimedCoins = pImpl_->client_->claimCoins(uttTx, pImpl_->params_, sigs);

bool invalidCoinsInTransfer(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

use the regular convention here
either invalidCoinsInTransfer = false or invalidCoinsInTransfer{false}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update in the next commit.

for (auto& coin : claimedCoins) {
if (!pImpl_->client_->validate(coin)) throw std::runtime_error("Invalid normal coin in transfer!");
if (!pImpl_->client_->validate(coin)) {
logdbg_user << "Invalid coin found; coin details: " << dbgPrintCoins({coin}) << endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

why not throw the exception here?
(and then you don't need invalidCoinsInTransfer)

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 idea is to prevent prematurely exiting from the function. The recipient should be able to claim coins received after the invalid coin, so I am letting it process all coins before raising the exception.

@snehal-das
Copy link
Contributor Author

I am not able to edit the reviewers list, the only option I see is to mention the person here.

@bsenthilr, @yontyon Please take a look and add your thoughts.

Some items pending are:

  1. Add a proper error response instead of sending back an error string.
  2. Correct the initialisation of invalidCoinsInTransfer.
  3. Look for better options for error reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants