Skip to content

Add coin purchase memo support#1785

Merged
cedwies merged 1 commit intoBitBoxSwiss:masterfrom
cedwies:cedwies/coin-purchase-memo
Feb 26, 2026
Merged

Add coin purchase memo support#1785
cedwies merged 1 commit intoBitBoxSwiss:masterfrom
cedwies:cedwies/coin-purchase-memo

Conversation

@cedwies
Copy link
Collaborator

@cedwies cedwies commented Feb 11, 2026

Gate CoinPurchase handling behind a new app-swap feature to limit to BitBox Multi.

One could decide to not gate behind a feature (also including it in BTC only version) since this adds negligible binary size, introduces no new attack surface (receiving aCoinPurchaseMemo requires a valid signature from a known identity), and the protobuf type cannot be cfg-gated anyway since it is generated code.

I chose the strict way and gated behind a new feature, but it may be discussed.

@cedwies cedwies marked this pull request as ready for review February 11, 2026 10:32
@cedwies cedwies requested a review from benma February 11, 2026 10:32
@benma
Copy link
Collaborator

benma commented Feb 11, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 514a062418

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cedwies cedwies force-pushed the cedwies/coin-purchase-memo branch from 24a5edf to ed19d60 Compare February 13, 2026 17:13
@cedwies
Copy link
Collaborator Author

cedwies commented Feb 13, 2026

Added address derivation field (only eth for now).
I used a dummy derivation path in the tests, so they verify that the field is excluded for the sighash

@cedwies cedwies requested a review from benma February 13, 2026 17:14
@benma
Copy link
Collaborator

benma commented Feb 15, 2026

Added address derivation field (only eth for now). I used a dummy derivation path in the tests, so they verify that the field is excluded for the sighash

Nice! How about adding validation of it to fn validate in payment_request.rs?

@cedwies cedwies force-pushed the cedwies/coin-purchase-memo branch from b666068 to 1438ce7 Compare February 16, 2026 20:09
@cedwies
Copy link
Collaborator Author

cedwies commented Feb 16, 2026

To validate the eth keypath I made is_valid_keypath_address(keypath: &[u32]) available. Modified Cargo.toml because app-swap should only be available with app-ethereum. Otherwise, if only app-swap is enabled and not app-ethereum, the code will not compile.

@cedwies cedwies force-pushed the cedwies/coin-purchase-memo branch 3 times, most recently from d87fe65 to 3d9dd9e Compare February 19, 2026 15:27
@cedwies cedwies requested a review from benma February 19, 2026 16:22
@cedwies
Copy link
Collaborator Author

cedwies commented Feb 19, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d9dd9e9e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +86 to 87
// TODO: add CoinPurchaseMemo arm when SwapKit UI is finalized
_ => return Err(Error::InvalidInput),

Choose a reason for hiding this comment

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

P1 Badge Accept CoinPurchaseMemo in payment request UI

The new memo type is still funneled into the default rejection path, so any payment request containing coin_purchase_memo is rejected during user_verify() before validate() runs in the BTC signing flow. This makes the added coin-purchase path unusable in practice (including builds with app-ethereum), because the transaction is aborted as invalid input instead of proceeding with the new verification logic.

Useful? React with 👍 / 👎.

}
}
#[cfg(not(feature = "app-ethereum"))]
return Err(ValidationError::Other);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add ::Disabled and map it to Error::Disabled in signtx.rs?

@@ -23,6 +23,19 @@ use pb::eth_response::Response;

use core::convert::TryInto;

pub(crate) fn derive_address(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add unit tests please.

@cedwies cedwies force-pushed the cedwies/coin-purchase-memo branch from f91a5e4 to d3da007 Compare February 25, 2026 10:28
@cedwies
Copy link
Collaborator Author

cedwies commented Feb 25, 2026

  • Added 2 unit tests for derive_address()
  • Introduced AddressMismatch and Disabled error.
  • switched from _hal to unused_variables (not for _eth)

Ready to review again

Copy link
Collaborator

@benma benma left a comment

Choose a reason for hiding this comment

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

utACK

if !keypath::is_valid_keypath_address(keypath) {
return Err(Error::InvalidInput);
}
let pubkey = crate::keystore::get_xpub_twice(hal, keypath)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mabye not worth optimizing now, but to verify the address in a payment request, deriving the xpub once is enough, as a derivation error (bit flip) will be caught and not have any bad consequence.

@@ -94,6 +94,10 @@ pub async fn user_verify(
pub enum ValidationError {
UnknownRecipient,
InvalidSignature,
#[cfg(feature = "app-ethereum")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a compiler warning/error without this guard here and below? You can leave it, but imho it's fine to also not guard, as it will change whenever a new coin is supported in the coinpurchase memo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CI complains because when app-ethereum is disabled and AddressMismatch is never constructed.

@cedwies cedwies force-pushed the cedwies/coin-purchase-memo branch from d3da007 to 1074610 Compare February 26, 2026 09:01
@cedwies
Copy link
Collaborator Author

cedwies commented Feb 26, 2026

Squashed, no change.

@cedwies cedwies merged commit b24d457 into BitBoxSwiss:master Feb 26, 2026
37 checks passed
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.

2 participants