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

fix: validate addresses during tx broadcast #5440

Merged
merged 12 commits into from
Oct 10, 2023
Merged

Conversation

woodenfurniture
Copy link
Member

@woodenfurniture woodenfurniture commented Oct 10, 2023

Description

Adds validation to TXs during broadcast. Includes in-memory caching and request deduplication to minimise impact of rate limits. Also removes initial implementation address validation.

Pull Request Type

  • 🐛 Bug fix (Non-breaking Change: Fixes an issue)
  • 🛠️ Chore (Non-breaking Change: Doc updates, pkg upgrades, typos, etc..)
  • 💅 New Feature (Breaking/Non-breaking Change)

Issue (if applicable)

closes #5438

Risk

Risk of broken trades, staking, sends etc. Affects all chains.

Testing

Check transactions are correctly transmitted across the app.

Engineering

Operations

Screenshots (if applicable)

Successful trade with single deduped validation request, not validating the contract address as though it's a receiver
image

Successful trade for manual receive address, 2 validation requests - 1 for sender, 1 for receiver
image

@woodenfurniture woodenfurniture marked this pull request as ready for review October 10, 2023 04:44
@woodenfurniture woodenfurniture requested a review from a team as a code owner October 10, 2023 04:44
@gomesalexandre gomesalexandre self-requested a review October 10, 2023 07:29
Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

A few comments/q. but conceptual stamp pending functional review

Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

First pass, tested locally with native.

EVM token self-send

image image

Since EVM chains are account-based and the sender and receiver are the same, I believe we shouldn't be validating here in case of self-send?

EVM native asset self-send

image image

Since EVM chains are account-based and the sender and receiver are the same, I believe we shouldn't be validating here in case of self-send?

UTXO self-send

image

Note, we're currently validating the send address using the xpub which we can't do for privacy reasons (and wouldn't validate anything):

image

Same-chain trade - confirmed the XHR isn't made to validate the address

image

Cross-chain trade

image

Trade went through, however, only the sender address was checked against (the first request is a preflight OPTIONS), not the receiver address.

ATOM self-send

image

Since ATOM is account-based and the sender and receiver are the same, I believe we shouldn't be validating here in case of self-send?

Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

Retested locally:

  • Self-send - UTXOs use the receiver address as an address to verify (not the xpub)
image
  • Self-send - UTXOs use the sender address as an address to verify (not the xpub)
image
  • EVM self-send - address is verified on the first check, and is only verified on the sender side (since it's already cached by the time we get to the receiver side branch)
image
  • EVM trades - address is verified (again, only once since it only needs to be on one side)
image
  • EVM -> UTXO THOR trade
image image
  • UTXO -> UTXO THOR trade
image image image image

@gomesalexandre gomesalexandre enabled auto-merge (squash) October 10, 2023 13:59
@kaladinlight
Copy link
Contributor

First thought is that build transaction is a better place to put this logic as we have most of the data available here to do the address validation. For cosmossdk we have all of the data available we are using to build the messages and wouldn't require updating the chain adapter api. For utxos we would have access to all of the inputs being used to build the send transaction (we aren't currently validating all of the input addresses which we should be doing). For evms it is a bit more difficult due to the input data embedding addresses though. It would be easy to handle the standard send transaction, but the build custom tx would probably still need addresses passed in (specifically for the swap transactions).

Main thing missing is the utxo input/output address validation. The other thought is just if we could do this without changing the chain adapter api or at least isolate it to buildCustomTx. Thoughts?

@woodenfurniture
Copy link
Member Author

First thought is that build transaction is a better place to put this logic as we have most of the data available here to do the address validation. For cosmossdk we have all of the data available we are using to build the messages and wouldn't require updating the chain adapter api. For utxos we would have access to all of the inputs being used to build the send transaction (we aren't currently validating all of the input addresses which we should be doing). For evms it is a bit more difficult due to the input data embedding addresses though. It would be easy to handle the standard send transaction, but the build custom tx would probably still need addresses passed in (specifically for the swap transactions).

Main thing missing is the utxo input/output address validation. The other thought is just if we could do this without changing the chain adapter api or at least isolate it to buildCustomTx. Thoughts?

100% agree, will action in follow-up in the spirit of getting this partially implemented sooner

@gomesalexandre gomesalexandre merged commit 3c27504 into develop Oct 10, 2023
3 checks passed
@gomesalexandre gomesalexandre deleted the validate-addresses branch October 10, 2023 21:21
woodenfurniture added a commit that referenced this pull request Oct 12, 2023
woodenfurniture added a commit that referenced this pull request Oct 12, 2023
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.

Stop scam sending
3 participants