Skip to content

Commit

Permalink
Improved dust attack detection in Trezor V2 plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
eprbell committed Feb 18, 2024
1 parent 4e15332 commit 8e894aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/dali/abstract_input_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

class AbstractInputPlugin:
ISSUES_URL: str = "https://github.com/eprbell/dali-rp2/issues"
# This is a list of tokens that are associated to possible dust attacks.
_POSSIBLE_DUST_ATTACKERS = {"RSWAP.NET"}

def __init__(
self,
Expand Down
8 changes: 6 additions & 2 deletions src/dali/plugin/input/csv/trezor_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class InputPlugin(AbstractInputPlugin):
__TRANSACTION_ID_INDEX: int = 4
__FEE_INDEX: int = 5
__AMOUNT_INDEX: int = 9
__AMOUNT_UNIT: int = 10

__DELIMITER = ";"

Expand Down Expand Up @@ -82,11 +83,14 @@ def load(self, country: AbstractCountry) -> List[AbstractTransaction]:
transaction_type: str = line[self.__TYPE_INDEX]
spot_price: str = Keyword.UNKNOWN.value
crypto_hash: str = line[self.__TRANSACTION_ID_INDEX]
fee_number: RP2Decimal = RP2Decimal(line[self.__FEE_INDEX])
fee_number: RP2Decimal = RP2Decimal(line[self.__FEE_INDEX]) if line[self.__FEE_INDEX] else ZERO
amount_number: RP2Decimal = RP2Decimal(line[self.__AMOUNT_INDEX])

if amount_number == ZERO and fee_number > ZERO:
self.__logger.warning("Possible dusting attack (fee > 0, total = 0): %s", raw_data)
self.__logger.warning("Possible dusting attack (fee > 0, total = 0), skipping transaction: %s", raw_data)
continue
if line[self.__AMOUNT_UNIT] in self._POSSIBLE_DUST_ATTACKERS:
self.__logger.warning("Possible dusting attack (amount unit %s is suspicious), skipping transaction: %s", line[self.__AMOUNT_UNIT], raw_data)
continue
if transaction_type in {_RECV, _SENT}:
result.append(
Expand Down

0 comments on commit 8e894aa

Please sign in to comment.