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

feat: support for stealth addresses in one-sided transactions #4310

Merged

Conversation

agubarev
Copy link
Contributor

@agubarev agubarev commented Jul 14, 2022

Description

Added support of one-sided transactions with stealth addresses to the output scanner.

Motivation and Context

https://rfc.tari.com/RFC-0203_StealthAddresses.html

How Has This Been Tested?

manually, unit tests

… of one-sided transactions, with simple and stealth addresses

Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
@agubarev agubarev marked this pull request as draft July 14, 2022 10:05
agubarev and others added 7 commits July 14, 2022 13:13
Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
…esses_clean

# Conflicts:
#	base_layer/wallet/src/output_manager_service/service.rs
Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
@agubarev agubarev marked this pull request as ready for review July 15, 2022 16:52
Copy link
Collaborator

@SWvheerden SWvheerden left a comment

Choose a reason for hiding this comment

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

Looks good.

let ks = PublicKey::from_secret_key(&c) + public_key;

if &ks != provided_spending_public.as_ref() {
return None;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think return here will give the correct behaviour.
If this case here is not correct, we should not drop all other correct UTXO and return back with none. This is in the middle of an iteration, I suspect you only want to continue here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, return None is to skip, to return from filter_map closure. This function is to only find and add certain outputs, it's not supposed to pass anything through.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was also thrown by this. I think the filter_map is too large and you should probably rather use a simple for loop

base_layer/wallet/src/output_manager_service/service.rs Outdated Show resolved Hide resolved
Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
@agubarev agubarev marked this pull request as draft July 18, 2022 12:22
@agubarev agubarev marked this pull request as ready for review July 18, 2022 16:36
changed DSH label for stealth addresses to `com.tari.stealth_address`

Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
let ks = PublicKey::from_secret_key(&c) + public_key;

if &ks != provided_spending_public.as_ref() {
return None;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was also thrown by this. I think the filter_map is too large and you should probably rather use a simple for loop

// ----------------------------------------------------------------------------
// simple one-sided address
[Opcode::PushPubKey(spending_key_public)] => {
let keys = match self.resources.db.get_all_known_one_sided_payment_scripts() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Calling this db method for every output is not necessary, rather move it outside the loop

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed

Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

LGTM - just a couple of small comments

@@ -1888,97 +1891,159 @@ where
Ok(())
}

/// Attempt to scan and then rewind all of the given transaction outputs into unblinded outputs based on known
/// pubkeys
fn scan_outputs_for_one_sided_payments(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn scan_outputs_for_one_sided_payments(
/// Attempt to scan and then rewind all of the given transaction outputs into unblinded outputs based on known
/// pubkeys
fn scan_outputs_for_one_sided_payments(

// ----------------------------------------------------------------------------
// simple one-sided address
[Opcode::PushPubKey(spending_key_public)] => {
let keys = match self.resources.db.get_all_known_one_sided_payment_scripts() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed

// NOTE: [RFC 203 on Stealth Addresses](https://rfc.tari.com/RFC-0203_StealthAddresses.html)
[Opcode::PushPubKey(nonce), Opcode::Drop, Opcode::PushPubKey(scanned_pk)] => {
// computing shared secret
let c = RistrettoSecretKey::from_bytes(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let c = RistrettoSecretKey::from_bytes(
let stealth_key = PrivateKey::from_bytes(

We should use the generic types as far as possible

@hansieodendaal
Copy link
Contributor

Please add unit and cucumber tests (see Scenario: Wallet sending and receiving one-sided transactions) for one sided stealth addresses.

@Cifko
Copy link
Contributor

Cifko commented Jul 20, 2022

Please add unit and cucumber tests (see Scenario: Wallet sending and receiving one-sided transactions) for one sided stealth addresses.

This is planned in next PR, because for that we need both PRs (this is scanning, and other one is sending) to be merged.

@stringhandler
Copy link
Collaborator

Your PR has already been merged @Cifko

Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
@agubarev agubarev marked this pull request as draft July 21, 2022 06:09
agubarev and others added 8 commits July 21, 2022 09:13
# Conflicts:
#	base_layer/wallet/src/output_manager_service/service.rs
Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
…ealth_addresses_clean

# Conflicts:
#	integration_tests/features/support/wallet_steps.js
#	integration_tests/features/support/world.js
@agubarev agubarev marked this pull request as ready for review July 21, 2022 18:06
@agubarev agubarev marked this pull request as draft July 22, 2022 06:13
@@ -32,6 +32,35 @@ Feature: Wallet Transactions
Then all nodes are at height 30
Then I wait for wallet WALLET_C to have at least 1500000 uT


Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
@critical

/// # Safety
/// The `public_key_destroy()` must be called when finished with a `TariPublicKey` to prevent a memory leak
#[no_mangle]
pub unsafe extern "C" fn private_key_add(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think these are needed

Signed-off-by: Andrei Gubarev <agubarev@users.noreply.github.com>
@agubarev agubarev marked this pull request as ready for review July 22, 2022 10:53
stringhandler
stringhandler previously approved these changes Jul 25, 2022
@stringhandler stringhandler merged commit c73de62 into tari-project:development Jul 28, 2022
@agubarev agubarev deleted the stealth_addresses_clean branch July 28, 2022 12:12
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.

None yet

7 participants