0

Just saw good question on Telegram:

So I working on an algorithm that would download and process bitcoin blocks, specifically the transactions in them. I want to take every output address of every transaction in a block and query my database if any users own this address as their deposit address. Initially I thought an output can only have one address and so I can just credit the person who owns it with the amount of that output. But now I found out that an output can actually have multiple addresses to it and thats called multisig. I don’t really understand the concept of this. So what if a person uses his deposit address that I’ve given them as first address and they also use another address of their own as second address in a single output? Can they use that output with their address to waste it so then so I lose the money they deposited?

0

No, when multiple entities create a multisig address together, it's still a single address. It's merely that the locking script that holds the funds needs more than one signature to allow funds to be sent. So, when you're writing an indexer, you can likely get away at first with simply not distinguish singlesig and multisig addresses.

0

Take a look at this transaction

055f9c6dc094cf21fa224e1eb4a54ee3cc44ae9daa8aa47f98df5c73c48997f9 (Bitcoin mainnet)

(https://www.blockchain.com/btc/tx/055f9c6dc094cf21fa224e1eb4a54ee3cc44ae9daa8aa47f98df5c73c48997f9)

However, the web explorers fail to present these properly, so here's what you get if you decode it with your own node:

{
    "txid": "055f9c6dc094cf21fa224e1eb4a54ee3cc44ae9daa8aa47f98df5c73c48997f9",
    "version": 1,
    "locktime": 0,
    "vin": [
        {
            "txid": "b187426f2fdd5a7ac2f49d822f68e07f48486ee53a8a45de2494f12acb37a0d8",
            "vout": 3,
            "scriptSig": {
                "asm": "3046022100d78c31a20fa11533475be893b229eb4d252e600dcc2a0735d360c541b6aec813022100e3eaa72c915ef47d94ccbd18c2ba6d9ae5b98be6e9fbf968d4bbbb003e06d68701 030e001332b43924be343986cca3df669f57b0dedd120990e727787f8dea50fdbc"
            },
            "sequence": 4294967295,
            "n": 0,
            "addr": "1FrbMcddiM1v3HMpUqygjZYCamBykWCWao",
            "valueSat": 1114144,
            "value": 0.01114144,
            "doubleSpentTxID": null
        }
    ],
    "vout": [
        {
            "value": "0.00010860",
            "n": 0,
            "scriptPubKey": {
                "asm": "1 030e001332b43924be343986cca3df669f57b0dedd120990e727787f8dea50fdbc 20434e545250525459000000140001a9e0e85838b5000000174876e800010053b6 2 OP_CHECKMULTISIG",
                "reqSigs": 1,
                "type": "multisig",
                "addresses": [
                    "1FrbMcddiM1v3HMpUqygjZYCamBykWCWao",
                    "1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E"
                ]
            }
        },
        {
            "value": "0.00010860",
            "n": 1,
            "scriptPubKey": {
                "asm": "1 030e001332b43924be343986cca3df669f57b0dedd120990e727787f8dea50fdbc 20a3c3000000000000000000000000000000000000000000000000000000000000 2 OP_CHECKMULTISIG",
                "reqSigs": 1,
                "type": "multisig",
                "addresses": [
                    "1FrbMcddiM1v3HMpUqygjZYCamBykWCWao",
                    "1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E"
                ]
            }
        },
        {
            "value": "0.00010860",
            "n": 2,
            "scriptPubKey": {
                "asm": "1 030e001332b43924be343986cca3df669f57b0dedd120990e727787f8dea50fdbc 100000000000000000000000000000000000000000000000000000000000000000 2 OP_CHECKMULTISIG",
                "reqSigs": 1,
                "type": "multisig",
                "addresses": [
                    "1FrbMcddiM1v3HMpUqygjZYCamBykWCWao",
                    "1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E"
                ]
            }
        },
        {
            "value": "0.01061564",
            "n": 3,
            "scriptPubKey": {
                "asm": "OP_DUP OP_HASH160 a2f2d251cc06ec1e789800127e3fa6ed9e515651 OP_EQUALVERIFY OP_CHECKSIG",
                "reqSigs": 1,
                "type": "pubkeyhash",
                "addresses": [
                    "1FrbMcddiM1v3HMpUqygjZYCamBykWCWao"
                ]
            }
        }
    ],
    "blockhash": "0000000000000000491fdff68a1c99de7798278a791e461b8d5bebdd9df9de46",
    "confirmations": 1,
    "time": 1401911255,
    "blocktime": 1401911255,
    "valueOut": 0.01094144,
    "size": 433,
    "valueIn": 0.01114144,
    "fees": 0.0002
}

I'm actually the person who asked this question and after lots of research, I'm pretty sure this kind of transaction can not occur in a scenario when you give your users unique bitcoin addresses for deposits. I think this will only happen when the addresses were intentionally made multisig, however, I'm not sure how and why.

I've done a small experiment where I've made a testnet multisig address and sent some funds to it. I were expecting it to act exactly like in the transaction above, however, it didn't. I think the reason for it is because there has to be a different type of script and I want to know what is it and how to work with it.

Here's what I did:

First I've created 2 new addresses.

index@LAPTOP-QHUBB7MI:~$ btc getnewaddress
2MsTYs9Ymsh332Ctou3dyxVe5PoTW4fLp2o
index@LAPTOP-QHUBB7MI:~$ btc getnewaddress
2N2yDtoRTChgrD675GJ12JE3wXzk3hMzgoP

Then I got their public keys using the getaddressinfo rpc.

index@LAPTOP-QHUBB7MI:~$ btc getaddressinfo 2MsTYs9Ymsh332Ctou3dyxVe5PoTW4fLp2o
{
  "address": "2MsTYs9Ymsh332Ctou3dyxVe5PoTW4fLp2o",
  "scriptPubKey": "a9140254bfce5627cc6267eb2aaa75dce00f03bc13dc87",
  "ismine": true,
  "solvable": true,
  ...
  "pubkey": "02d01d8e315567fb3571f31d86eb53d21729c6072751276d0c2617d787d48b2af8",
  ...

}
index@LAPTOP-QHUBB7MI:~$ btc getaddressinfo 2N2yDtoRTChgrD675GJ12JE3wXzk3hMzgoP
{
  "address": "2N2yDtoRTChgrD675GJ12JE3wXzk3hMzgoP",
  "scriptPubKey": "a9146aaa8606a93804de00e4e91c683dbfd5e1caa7d887",
  "ismine": true,
  "solvable": true,
  ...
  "pubkey": "0236240c39790e770bc0c378bebb1a86d2ac24f835b6e81e69c623262b1f0e0326",
  ...
}

Then I created the multisig address.

index@LAPTOP-QHUBB7MI:~$ btc createmultisig 1 '["0236240c39790e770bc0c378bebb1a86d2ac24f835b6e81e69c623262b1f0e0326", "02d01d8e315567fb3571f31d86eb53d21729c6072751276d0c2617d787d48b2af8"]'
{
  "address": "2Mu6J8iXwzCgWxJzVNkzfQ8yZwJ92YWW6es",
  "redeemScript": "51210236240c39790e770bc0c378bebb1a86d2ac24f835b6e81e69c623262b1f0e03262102d01d8e315567fb3571f31d86eb53d21729c6072751276d0c2617d787d48b2af852ae"
}

Finally, I sent some bitcoin to the address.

index@LAPTOP-QHUBB7MI:~$ btc sendtoaddress 2Mu6J8iXwzCgWxJzVNkzfQ8yZwJ92YWW6es 0.00999744
1373fd7a2da3199e0f4ead0a5456266b52263356a86b726882dbc03da1625ed1

I decoded that transaction (Testnet) and got this

{
  "txid": "1373fd7a2da3199e0f4ead0a5456266b52263356a86b726882dbc03da1625ed1",
  "hash": "290a0ec0c306a4485a7099c1f7813d9f9a741a9b4fcc68c5decc68de5ddb1b14",
  "version": 2,
  "size": 338,
  "vsize": 173,
  "weight": 692,
  "locktime": 1572217,
  "vin": [
    {
      "txid": "7e57de9ce9797e8c5face7c3ed7ce89eb3107b05e00c129f336cebc1b1113dcb",
      "vout": 1,
      "scriptSig": {
        "asm": "00205a010c52d33bfac812f62f2cb7f917a3b84f67c66c1ac9ac1701c7caa4e5da7c",
        "hex": "2200205a010c52d33bfac812f62f2cb7f917a3b84f67c66c1ac9ac1701c7caa4e5da7c"
      },
      "txinwitness": [
        "",
        "304402206b7f9fcdf972a2aaa6a734e921d1f76b3da3a0f7a98e2bf3657241ed0cc4433a022040b1f0f31b6231ff73465986c3379ce15cbf2b33e28b09460aac8812d8e9826801",
        "304402200ffeeb246535a312f33c05652f9ef5d696fd26883659e6429731e5f0416be9fc022067a5852e99f96c5def0f7288b9a7ba567e3df258fd79071a60694580ac3de1fc01",
        "522103a8f863c198bfa005273ae53d9db239e3be2cabcd5cbf34f52318795166f5cdff2102cff91271435f4f121aa90f3babc5551090f862575e5eb12429acb8e6daf4d8cd52ae"
      ],
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 0.00999744,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 143ff7e3677973ecd914d8d134efde5adff4a96b OP_EQUAL",
        "hex": "a914143ff7e3677973ecd914d8d134efde5adff4a96b87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2Mu6J8iXwzCgWxJzVNkzfQ8yZwJ92YWW6es"
        ]
      }
    }
  ]
}

Which is a totally normal-looking one.

Even though I'm almost certain this won't happen in the scenario I described, I want I final confirmation from someone who understands how these transaction work and explain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.