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

Add query decrypted tx method to confidential transfers client #1950

Merged
merged 8 commits into from
Nov 21, 2024

Conversation

mj850
Copy link
Contributor

@mj850 mj850 commented Nov 20, 2024

Describe your changes and provide context

We want users to have the ability to easily query a tx hash in it's decrypted state (if they have the private key)

This PR adds a seid method seid q ct tx --from that queries a tx by it's hash, then decrypts it using the user's private key.

Testing performed to validate your change

Manual testing using the updated seid

@mj850 mj850 changed the base branch from main to feature/ct_types November 20, 2024 09:06
x/confidentialtransfers/client/cli/query.go Show resolved Hide resolved
x/confidentialtransfers/client/cli/query.go Outdated Show resolved Hide resolved
x/confidentialtransfers/client/cli/query.go Outdated Show resolved Hide resolved
}

// ApplyPendingBalanceDecrypted is the decrypted version of ApplyPendingBalance
func (r *ApplyPendingBalance) Decrypt(decryptor *elgamal.TwistedElGamal, privKey ecdsa.PrivateKey, decryptAvailableBalance bool, address string) (*ApplyPendingBalanceDecrypted, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

bool flag signals the method needs to be split in two. e.g Decrypt and DecryptWithAvailableBalance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried this but decided not to change in the end - felt a little bit awkward to have 2 methods (Decrypt and DecryptWithAvailableBalance) that do almost the same thing in this specific case, since the only use case here is:
Current:

	var result proto.Message
	switch message := sdkmsg.(type) {
	case *types.MsgInitializeAccount:
		result, err = message.Decrypt(decryptor, *privKey, decryptAvailableBalance)
	case *types.MsgWithdraw:
		result, err = message.Decrypt(decryptor, *privKey, decryptAvailableBalance)
	case *types.MsgApplyPendingBalance:
		result, err = message.Decrypt(decryptor, *privKey, decryptAvailableBalance)
	case *types.MsgTransfer:
		result, err = message.Decrypt(decryptor, *privKey, decryptAvailableBalance, address)
	case *types.MsgDeposit:
		result = message
	case *types.MsgCloseAccount:
		result = message
	default:
		return nil, false, nil

With separate methods it would become:

	var result proto.Message
	switch message := sdkmsg.(type) {
	case *types.MsgInitializeAccount:
                 if decryptAvailableBalance {
                         result, err = message.DecryptWithAvailableBalnace(decryptor, *privKey)
                 } else {
		        result, err = message.Decrypt(decryptor, *privKey)
                 }

	case *types.MsgWithdraw:
		if decryptAvailableBalance {
                         result, err = message.DecryptWithAvailableBalnace(decryptor, *privKey)
                 } else {
		        result, err = message.Decrypt(decryptor, *privKey)
                 }
	case *types.MsgApplyPendingBalance:
                 if decryptAvailableBalance {
                         result, err = message.DecryptWithAvailableBalnace(decryptor, *privKey)
                 } else {
		        result, err = message.Decrypt(decryptor, *privKey)
                 }
	case *types.MsgTransfer:
                 if decryptAvailableBalance {
                         result, err = message.DecryptWithAvailableBalnace(decryptor, *privKey)
                 } else {
		        result, err = message.Decrypt(decryptor, *privKey)
                 }
	case *types.MsgDeposit:
		result = message
	case *types.MsgCloseAccount:
		result = message
	default:
		return nil, false, nil


Point taken for future methods though I think it's a helpful idea

x/confidentialtransfers/types/apply_pending_balance.go Outdated Show resolved Hide resolved
x/confidentialtransfers/types/apply_pending_balance.go Outdated Show resolved Hide resolved
x/confidentialtransfers/types/apply_pending_balance.go Outdated Show resolved Hide resolved
x/confidentialtransfers/types/initialize_account.go Outdated Show resolved Hide resolved
x/confidentialtransfers/types/initialize_account.go Outdated Show resolved Hide resolved
@@ -205,6 +215,113 @@ func NewTransfer(
}, nil
}

// Decrypts the transfer transaction and returns the decrypted data.
// The aesKey and decryptAvailableBalance field are only used if address is the sender address of the transaction.
func (r *Transfer) Decrypt(decryptor *elgamal.TwistedElGamal, privKey ecdsa.PrivateKey, decryptAvailableBalance bool, address string) (*TransferDecrypted, error) {
Copy link
Contributor

@dssei dssei Nov 20, 2024

Choose a reason for hiding this comment

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

I think generalization in a form of Decryptable interface, leads to more complexity in current implementation and/or degraded implementation (like skipped address params in other implementation).
We may need type (sender/receiver/auditor) based implementations of Decryptable and a separate factory function to avoid types based decision in this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback - since we figured out how to parse the message type properly, I removed the Decryptable interface and just have it call Decrypt for each method.

Also split the Decrypt logic up in the Transfer class to shorten the function.

@dssei dssei self-requested a review November 21, 2024 01:17
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 1.95440% with 301 lines in your changes missing coverage. Please review.

Project coverage is 59.80%. Comparing base (81c0d5f) to head (474bbf8).
Report is 41 commits behind head on feature/ct_types.

Files with missing lines Patch % Lines
x/confidentialtransfers/types/transfer.go 0.00% 102 Missing ⚠️
...nfidentialtransfers/types/apply_pending_balance.go 0.00% 72 Missing ⚠️
x/confidentialtransfers/types/msgs.go 10.71% 50 Missing ⚠️
.../confidentialtransfers/types/initialize_account.go 0.00% 45 Missing ⚠️
x/confidentialtransfers/types/withdraw.go 0.00% 31 Missing ⚠️
x/confidentialtransfers/types/account.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                  @@
##           feature/ct_types    #1950      +/-   ##
====================================================
- Coverage             61.57%   59.80%   -1.77%     
====================================================
  Files                   263      283      +20     
  Lines                 23306    25876    +2570     
====================================================
+ Hits                  14351    15476    +1125     
- Misses                 7948     9266    +1318     
- Partials               1007     1134     +127     
Files with missing lines Coverage Δ
x/confidentialtransfers/types/account.go 0.00% <0.00%> (ø)
x/confidentialtransfers/types/withdraw.go 0.00% <0.00%> (ø)
.../confidentialtransfers/types/initialize_account.go 0.00% <0.00%> (ø)
x/confidentialtransfers/types/msgs.go 39.49% <10.71%> (ø)
...nfidentialtransfers/types/apply_pending_balance.go 0.00% <0.00%> (ø)
x/confidentialtransfers/types/transfer.go 0.00% <0.00%> (ø)

... and 5 files with indirect coverage changes

---- 🚨 Try these New Features:

@mj850 mj850 merged commit 0be3625 into feature/ct_types Nov 21, 2024
28 of 29 checks passed
@mj850 mj850 deleted the mj/queryCt branch November 21, 2024 08:38
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.

2 participants