Repository: rotki/rotki

Issue:
Tried to read 32 bytes.  Only got 31 bytes during transaction decoding
## Problem Definition

A user saw this while decoding their transactions.

```
[02/06/2022 02:50:40 AEST] ERROR rotkehlchen.greenlets Greenlet with id 140595538382512: decode 500 evm trasactions died with exception: Tried to read 32 bytes.  Only got 31 bytes.
Exception Name: <class 'eth_abi.exceptions.InsufficientDataBytes'>
Exception Info: Tried to read 32 bytes.  Only got 31 bytes
Traceback:
   File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "rotkehlchen/chain/ethereum/decoding/decoder.py", line 253, in get_and_decode_undecoded_transactions
  File "rotkehlchen/chain/ethereum/decoding/decoder.py", line 286, in decode_transaction_hashes
  File "rotkehlchen/chain/ethereum/decoding/decoder.py", line 323, in get_or_decode_transaction_events
  File "rotkehlchen/chain/ethereum/decoding/decoder.py", line 235, in decode_transaction
  File "rotkehlchen/chain/ethereum/decoding/decoder.py", line 173, in try_all_rules
  File "rotkehlchen/chain/ethereum/decoding/decoder.py", line 500, in _maybe_decode_erc20_721_transfer
  File "rotkehlchen/assets/utils.py", line 72, in get_or_create_ethereum_token
  File "rotkehlchen/chain/ethereum/manager.py", line 1223, in get_basic_contract_info
  File "rotkehlchen/chain/ethereum/manager.py", line 1224, in <listcomp>
  File "rotkehlchen/chain/ethereum/contracts.py", line 86, in decode
  File "eth_abi/codec.py", line 181, in decode_abi
  File "eth_abi/decoding.py", line 127, in __call__
  File "eth_utils/functional.py", line 45, in inner
  File "eth_abi/decoding.py", line 173, in decode
  File "eth_abi/decoding.py", line 127, in __call__
  File "eth_abi/decoding.py", line 145, in decode
  File "eth_abi/decoding.py", line 127, in __call__
  File "eth_abi/decoding.py", line 198, in decode
  File "eth_abi/decoding.py", line 513, in read_data_from_stream
  File "eth_abi/decoding.py", line 127, in __call__
  File "eth_abi/decoding.py", line 198, in decode
  File "eth_abi/decoding.py", line 305, in read_data_from_stream

[02/06/2022 02:50:40 AEST] ERROR rotkehlchen.user_messages Greenlet with id 140595538382512: decode 500 evm trasactions died with exception: Tried to read 32 bytes.  Only got 31 bytes. Check the logs for more details
```

The full logs have been given to us but not posted here for privacy reasons.

## Task

Figure it out and fix it.


Discussion:

Resolving patch:
diff --git a/rotkehlchen/assets/spam_assets.py b/rotkehlchen/assets/spam_assets.py
--- a/rotkehlchen/assets/spam_assets.py
+++ b/rotkehlchen/assets/spam_assets.py
@@ -125,6 +125,11 @@
         'symbol': 'Luna Token',
         'decimals': 18,
     },
+    string_to_ethereum_address('0x3baB61Ad5D103Bb5b203C9092Eb3a5e11677a5D0'): {
+        'name': 'ETH2Dao.net',
+        'symbol': 'ETH2DAO.net',
+        'decimals': 18,
+    },
 }
 
 
diff --git a/rotkehlchen/chain/ethereum/manager.py b/rotkehlchen/chain/ethereum/manager.py
--- a/rotkehlchen/chain/ethereum/manager.py
+++ b/rotkehlchen/chain/ethereum/manager.py
@@ -15,6 +15,7 @@
     normal_name_to_hash,
     normalize_name,
 )
+from eth_abi.exceptions import InsufficientDataBytes
 from eth_typing import BlockNumber, HexStr
 from web3 import HTTPProvider, Web3
 from web3._utils.abi import get_abi_output_types
@@ -267,7 +268,15 @@ def __init__(
             'https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks',
         )
         # A cache for the erc20 contract info to not requery same one
-        self.contract_info_cache: Dict[ChecksumEthAddress, Dict[str, Any]] = {}
+        self.contract_info_cache: Dict[ChecksumEthAddress, Dict[str, Any]] = {
+            # hard coding contract info we know can't be queried properly
+            # https://github.com/rotki/rotki/issues/4420
+            string_to_ethereum_address('0xECF8F87f810EcF450940c9f60066b4a7a501d6A7'): {
+                'name': 'Old Wrapped Ether',
+                'symbol': 'WETH',
+                'decimals': 18,
+            },
+        }
 
     def connected_to_any_web3(self) -> bool:
         return (
@@ -1225,11 +1234,14 @@ def get_basic_contract_info(self, address: ChecksumEthAddress) -> Dict[str, Any]
                 if x[0] and len(x[1]) else None
                 for (x, method_name) in zip(output, properties)
             ]
-        except OverflowError as e:
+        except (OverflowError, InsufficientDataBytes) as e:
             # This can happen when contract follows the ERC20 standard methods
-            # but name and symbol return bytes instead of string. UNIV1 LP is in this case
+            # but name and symbol return bytes instead of string. UNIV1 LP is such a case
+            # It can also happen if the method is missing and they are all hitting
+            # the fallback function. old WETH contract is such a case
             log.error(
-                f'{address} failed to decode as ERC20 token. Trying UNIV1 LP token. {str(e)}',
+                f'{address} failed to decode as ERC20 token. '
+                f'Trying with token ABI using bytes. {str(e)}',
             )
             contract = EthereumContract(address=address, abi=UNIV1_LP_ABI, deployed_block=0)
             decoded = [


Test patch:
diff --git a/frontend/app/tests/e2e/specs/settings.spec.ts b/frontend/app/tests/e2e/specs/settings.spec.ts
--- a/frontend/app/tests/e2e/specs/settings.spec.ts
+++ b/frontend/app/tests/e2e/specs/settings.spec.ts
@@ -143,7 +143,7 @@ describe('settings', () => {
           '.accounting-settings__asset-to-ignore',
           '1CR'
         );
-        pageAccounting.ignoredAssetCount('20');
+        pageAccounting.ignoredAssetCount('21');
       });
       it('remove an ignored asset, validate UI message, and confirm count is 3', () => {
         pageAccounting.remIgnoredAsset('1SG');
@@ -151,7 +151,7 @@ describe('settings', () => {
           '.accounting-settings__ignored-assets',
           '1SG'
         );
-        pageAccounting.ignoredAssetCount('19');
+        pageAccounting.ignoredAssetCount('20');
       });
     });
   });
@@ -192,7 +192,7 @@ describe('settings', () => {
         '.accounting-settings__taxfree-period',
         'false'
       );
-      pageAccounting.ignoredAssetCount('19');
+      pageAccounting.ignoredAssetCount('20');
     });
   });
 });