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 Bitcoin P2TR, P2WSH, P2SH, P2PKH address types #1942

Merged
merged 21 commits into from
Apr 1, 2024

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Mar 25, 2024

Description

  1. Currently we only support sending to P2WPKH address. Need to support P2TR/P2PKH/P2SH/P2WSH.
  2. Currently we only support receiving BTC from P2WPKH address. Need to support P2TR/P2PKH/P2SH/P2WSH.

WIP:

  • backport AddressTaproot type that fulfills the btcutil.Address interface
  • add P2TR output
  • add P2PKH output
  • add P2SH output
  • add P2WSH output
  • read P2TR sender
  • read P2SH sender
  • read P2PKH sender
  • read P2WSH sender

Closes:
1626
1627
1773

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Include instructions and any relevant details so others can reproduce.

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Checklist:

  • I have added unit tests that prove my fix feature works

@ws4charlie ws4charlie changed the title Feat support taproot feat: support Bitcoin P2TR, P2WSH, P2SH, P2PKH address types Mar 25, 2024
@ws4charlie ws4charlie marked this pull request as draft March 25, 2024 18:39
Copy link

github-actions bot commented Mar 26, 2024

!!!WARNING!!!
nosec detected in the following files: zetaclient/bitcoin/fee.go, zetaclient/bitcoin/fee_test.go, e2e/e2etests/e2etests.go, zetaclient/bitcoin/bitcoin_client.go, zetaclient/bitcoin/bitcoin_client_test.go, zetaclient/bitcoin/bitcoin_signer.go, zetaclient/bitcoin/bitcoin_signer_test.go, zetaclient/bitcoin/inbound_tracker.go, zetaclient/bitcoin/utils.go

Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.

Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.

Pay extra attention to the way #nosec is being used in the files listed above.

@github-actions github-actions bot added the nosec label Mar 26, 2024
@lumtis
Copy link
Member

lumtis commented Mar 26, 2024

Any difference with #1842?
The other one can maybe be closed then

@ws4charlie ws4charlie marked this pull request as ready for review March 27, 2024 00:29
Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

We have withdraw E2E tests. Just to make sure, there is no deposit tests to do because it has nothing to do with the wallet address format?

Needs #1953 merged to run the E2E tests

common/address.go Show resolved Hide resolved
x/crosschain/keeper/evm_hooks_test.go Outdated Show resolved Hide resolved
zetaclient/bitcoin/bitcoin_client.go Show resolved Hide resolved
zetaclient/bitcoin/bitcoin_client_test.go Outdated Show resolved Hide resolved
zetaclient/bitcoin/bitcoin_signer.go Outdated Show resolved Hide resolved
zetaclient/bitcoin/fee.go Outdated Show resolved Hide resolved
zetaclient/bitcoin/txscript.go Outdated Show resolved Hide resolved
zetaclient/bitcoin/txscript.go Outdated Show resolved Hide resolved
zetaclient/testutils/stub/tss_signer.go Show resolved Hide resolved
zetaclient/testutils/testdata.go Outdated Show resolved Hide resolved
@ws4charlie ws4charlie requested a review from a team as a code owner March 27, 2024 14:22
@github-actions github-actions bot added the ci Changes to CI pipeline or github actions label Mar 27, 2024
@ws4charlie
Copy link
Contributor Author

We have withdraw E2E tests. Just to make sure, there is no deposit tests to do because it has nothing to do with the wallet address format?

Needs #1953 merged to run the E2E tests

There is no deposit tests to do?
Yes, there is no deposit tests. The incoming tx's output format (to TSS address) has already been defined long long ago and never changed.

Then what was added for incoming txs?
What added in the PR is the ability to parse 4 more additional types of depositors' address: P2TR P2WSH P2PKH P2SH. This incurred a bit code refactor and the intx sender address parsing method GetSenderAddressByVin which is covered in unit tests and live tests.

Copy link
Contributor

@kevinssgh kevinssgh left a comment

Choose a reason for hiding this comment

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

Overall looks good, left some comments.

common/bitcoin/address_taproot.go Show resolved Hide resolved
zetaclient/bitcoin/bitcoin_client.go Outdated Show resolved Hide resolved
zetaclient/bitcoin/bitcoin_client.go Outdated Show resolved Hide resolved
zetaclient/bitcoin/bitcoin_client.go Outdated Show resolved Hide resolved
zetaclient/bitcoin/bitcoin_client.go Show resolved Hide resolved
zetaclient/bitcoin/bitcoin_signer.go Show resolved Hide resolved
zetaclient/bitcoin/fee.go Outdated Show resolved Hide resolved
zetaclient/bitcoin/fee.go Outdated Show resolved Hide resolved
zetaclient/bitcoin/txscript.go Outdated Show resolved Hide resolved
Copy link
Member

@lumtis lumtis 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 to me. Thanks for addressing the comments.
Added suggestions for some additional tests

common/bitcoin/address_taproot.go Show resolved Hide resolved
common/bitcoin/address_taproot.go Show resolved Hide resolved
common/bitcoin/address_taproot.go Show resolved Hide resolved
Copy link
Contributor

@kevinssgh kevinssgh 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

@ws4charlie ws4charlie merged commit e9c1365 into v16.0.0 Apr 1, 2024
18 checks passed
@ws4charlie ws4charlie deleted the feat-support-taproot branch April 1, 2024 17:44
@ws4charlie ws4charlie restored the feat-support-taproot branch April 3, 2024 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli ci Changes to CI pipeline or github actions nosec
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants