hirosystems / chainhook

Extract transactions from Stacks and Bitcoin and build event driven re-org resistant indexers and databases.
GNU General Public License v3.0
158 stars 65 forks source link

OP_RETURN starting with"!a" is not found when OP_RETURN !aĆ[a+UQ{d^½2 is present #385

Closed timstackblock closed 1 year ago

timstackblock commented 1 year ago

Describe the bug There seems to be a bug when looking for an OP_RETURN starting with"!a" . Chainhook returns 0 actions triggered as the OP_RETURN starting with"!a" is not found when OP_RETURN !aĆ[a+UQ{d^½2 is present

Transaction ID https://mempool.space/tx/6b9736710c061a3cef8c2cdcd46cee433c7df028ac1b71ab96dd388a2309816f Block# 801219 Time stamp 2023-08-01 10:50

As you can see the blocks are scanned but it cannot find the OP_RETURN starting with "!a"

Screenshot 2023-08-15 at 9 33 43 AM

Here is the OP_RETURN screen shot below !aĆ[a+UQ{d^½2

Screenshot 2023-08-15 at 9 28 20 AM

Here is the predicate where I am looking for OP_RETURNS that start with "!a"

{
  "uuid": "1",
  "name": "Hello Ordinals",
  "chain": "bitcoin",
  "version": 1,
  "networks": {
    "mainnet": {
      "start_block": 801220,
      "end_block": 801230,
      "if_this": {
        "scope": "outputs",
        "op_return": {
          "starts_with": "!a"
        }
        },
        "then_that": {
          "file_append": {
            "path": "automate/tests/bitcoin-predicates/OpReturn/OpReturn-file-result.json"
          }
        }
      }
    }
qustavo commented 1 year ago

As far as I can see mempool.space makes a subjective interpretation of the OP_RETURN's data section. Compare the output you get from mempool.space with the one from blockstream.info:

mempool.space !aĆ[a+UQ{d^½2
blockstream.info �!���a��Ć�[a+���U��Q����{�d^½��2�

I think that mempool.space is stripping any non-printable character, but I can't confirm.

That being said, the OP_RETURN matchers are not properly implemented in Chainhook's code yet. They are just matching an output script against the pattern defined by the predicate [1]. Implementation wise I think the matcher needs to:

1: https://github.com/hirosystems/chainhook/blob/59040eb4ea60fa3d4b82ce4ac843f1e71a174461/components/chainhook-sdk/src/chainhooks/bitcoin/mod.rs#L309