3

I would like to count script step by step, but I have problem with it.

For example, I have such transaction:

{
    "locktime": 0,
    "txid": "c0fdb774710943d8dbb5f823c00394452fb1a1d63a3a7a9fb8de41299b37f090",
    "version": 1,
    "vin": [
        {
        "scriptSig": {
            "asm": "3045022074f35af390c41ef1f5395d11f6041cf55a6d7dab0acdac8ee746c1f2de7a43b3022100b3dc3d916b557d378268a856b8f9a98b9afaf45442f5c9d726fce343de835a5801 02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f",
            "hex": "483045022074f35af390c41ef1f5395d11f6041cf55a6d7dab0acdac8ee746c1f2de7a43b3022100b3dc3d916b557d378268a856b8f9a98b9afaf45442f5c9d726fce343de835a58012102c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f"
        },
        "sequence": 4294967295,
        "txid": "e1142c945b73826b552407916c13402fb873fb1d3f7c16fa561367aaddd076a7",
        "vout": 0
        }
    ],
    "vout": [
        {
        "n": 0,
        "scriptPubKey": {
            "addresses": [
            "1PQnDVEi2u4e8rFmE3d9J51eQz8cQXpybC"
            ],
            "asm": "OP_DUP OP_HASH160 f5d214041d44860c8c08202a9e4263fc47a2fe88 OP_EQUALVERIFY OP_CHECKSIG",
            "hex": "76a9145e4ff47ceb3a51cdf7ddd80afc4acc5a692dac2d88ac",
            "reqSigs": 1,
            "type": "pubkeyhash"
        },
        "value": 0.58407
        }
    ]
}

First of all I put on the stack

3045022074f35af390c41ef1f5395d11f6041cf55a6d7dab0acdac8ee746c1f2de7a43b3022100b3dc3d916b557d378268a856b8f9a98b9afaf45442f5c9d726fce343de835a5801

and

02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f

and I start execute script, so

  • after OP_DUP the stack looks like:

    3045022074f35af390c41ef1f5395d11f6041cf55a6d7dab0acdac8ee746c1f2de7a43b3022100b3dc3d916b557d378268a856b8f9a98b9afaf45442f5c9d726fce343de835a5801
    02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f
    02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f
    
  • to execute OP_HASH160, I get the first element on the top of stack, change hex to bytes, count Hash160 using formula: Hash160(x) = RIPEMD160(SHA256(x)) and put new value on stack. In Javascript it looks like

    CryptoJS.RIPEMD160(hexToBytes(CryptoJS.SHA256(hexToBytes("02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f")).toString())).toString()
    

and it returns value "38ef3b4b7f01ea41e2013d4b77f63c998967efc9", so the new value of stack is:

    3045022074f35af390c41ef1f5395d11f6041cf55a6d7dab0acdac8ee746c1f2de7a43b3022100b3dc3d916b557d378268a856b8f9a98b9afaf45442f5c9d726fce343de835a5801
    02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f
    38ef3b4b7f01ea41e2013d4b77f63c998967efc9
  • the next step of counting script is putting f5d214041d44860c8c08202a9e4263fc47a2fe88 on the stack

    3045022074f35af390c41ef1f5395d11f6041cf55a6d7dab0acdac8ee746c1f2de7a43b3022100b3dc3d916b557d378268a856b8f9a98b9afaf45442f5c9d726fce343de835a5801
    02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f
    38ef3b4b7f01ea41e2013d4b77f63c998967efc9
    f5d214041d44860c8c08202a9e4263fc47a2fe88
    

And now, I should check if 38ef3b4b7f01ea41e2013d4b77f63c998967efc9 is equal f5d214041d44860c8c08202a9e4263fc47a2fe88 and I get of course false.

What am I doing wrong? I got the same problem with all transactions, which I checked, so probably I don't understand how scripts work or how OP_HASH160 is counted.

2

Thank you for answer! :) Could you tell one more thing? How can I get proper output script? I thought that I have all information needed to count in this transaction. If I have for example this transaction link , what should I do? What scriptPubKey shoud I use?

Dont get scared by the wall of Text following, I just want to make it as understandable as I can:

Give this TX-Data:

{
  "txid": "1ea183203c2a2b8db9a84b0d90bfc0b072f0484ec6536b95f69733ae251a3288",
  "version": 2,
  "locktime": 0,
  "tx-comment": "",
  "vin": [
    {
      "txid": "8094704e00978c58f3d51d6c44b460af6c04dac86ef1b79c202208e5c65d0a50",
      "vout": 0,
      "scriptSig": {
        "asm": "304402205474316eb33e1c61e4fa099a0a99d9448e0ffa380b1da8d894e0101fd0eecf7e02206b4bd7498894eb626b1ab1945ddff720b240e8d992e756ff9711a7390951d8a501 03e1cc71fe608be3fa01247476d6fbb758c14af7fa269b151e202f4a2e5a530022",
        "hex": "47304402205474316eb33e1c61e4fa099a0a99d9448e0ffa380b1da8d894e0101fd0eecf7e02206b4bd7498894eb626b1ab1945ddff720b240e8d992e756ff9711a7390951d8a5012103e1cc71fe608be3fa01247476d6fbb758c14af7fa269b151e202f4a2e5a530022"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 1.3491183,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 9aa813b6983a609ebb5992408457dbb814824124 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9149aa813b6983a609ebb5992408457dbb81482412488ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "FKvrsYB5dR2xSW1ujUXq7RLdiUxoZHEH58"
        ]
      }
    },
    {
      "value": 1.59661273,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 3ea405431679a7d51fb5da6106cb91f4a1d066ec OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9143ea405431679a7d51fb5da6106cb91f4a1d066ec88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "FBYKr3SGVWMrbHngSGVua1LiCN2GYQV8Lp"
        ]
      }
    }
  ]
}

This Transaction got one input:

 "vin": [
        {
          "txid": "8094704e00978c58f3d51d6c44b460af6c04dac86ef1b79c202208e5c65d0a50",
          "vout": 0,
          "scriptSig": {
            "asm": "304402205474316eb33e1c61e4fa099a0a99d9448e0ffa380b1da8d894e0101fd0eecf7e02206b4bd7498894eb626b1ab1945ddff720b240e8d992e756ff9711a7390951d8a501 03e1cc71fe608be3fa01247476d6fbb758c14af7fa269b151e202f4a2e5a530022",
            "hex": "47304402205474316eb33e1c61e4fa099a0a99d9448e0ffa380b1da8d894e0101fd0eecf7e02206b4bd7498894eb626b1ab1945ddff720b240e8d992e756ff9711a7390951d8a5012103e1cc71fe608be3fa01247476d6fbb758c14af7fa269b151e202f4a2e5a530022"
          },
          "sequence": 4294967295
        }
      ]

This input is refering to an output from a previous transaction:

"txid": "8094704e00978c58f3d51d6c44b460af6c04dac86ef1b79c202208e5c65d0a50"
"vout": 0

This is the point where you get your scriptPubKey from. Input:

"vout": [
    {
      "value": 3.04573103,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 a0207d9ea622db7f63b70223ba4dea67c260a91b OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914a0207d9ea622db7f63b70223ba4dea67c260a91b88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "FLRnVzFCvGbKEpbjsFBSRejBHEcpbKScAe"
        ]
      }
    },
    {
      "value": 29.93357942,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 5eecec983a2105c049b4d1c1a43287ee07bd075f OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9145eecec983a2105c049b4d1c1a43287ee07bd075f88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "FEV2oce6qUAq9zYfJeBMVZTk6qeJfvkQ7n"
        ]
      }
    }
  ]

There are two outputs. The right one is:

"n": 0

because the reference was:

"vout": 0

And here is the Script you need:

"asm": "OP_DUP OP_HASH160 a0207d9ea622db7f63b70223ba4dea67c260a91b OP_EQUALVERIFY OP_CHECKSIG"
"hex": "76a914a0207d9ea622db7f63b70223ba4dea67c260a91b88ac"

Back to your original Transaction and its outputs:

"vout": [
    {
      "value": 1.3491183,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 9aa813b6983a609ebb5992408457dbb814824124 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9149aa813b6983a609ebb5992408457dbb81482412488ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "FKvrsYB5dR2xSW1ujUXq7RLdiUxoZHEH58"
        ]
      }
    },
    {
      "value": 1.59661273,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 3ea405431679a7d51fb5da6106cb91f4a1d066ec OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9143ea405431679a7d51fb5da6106cb91f4a1d066ec88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "FBYKr3SGVWMrbHngSGVua1LiCN2GYQV8Lp"
        ]
      }
    }
  ]

Those are not needed for checking the inputs of your transaction. They will be needed for the next Transaction spending your coins from this transaction.

I hope I dont confuse you, and if i did we can propably use chat or so.

  • @me.ex Nice to hear that i could help you, maybe you can mark the answer as correct;) – Dennis Kriechel Jun 16 '14 at 18:22
2

Use www.webbtc.com

It has a feature to execute scripts step-by-step

for example

http://webbtc.com/script/b8eccf259d051b75f1e5c0f524b125dea0575cce2cca2db16790506d39001961:0

  • This site seems pretty awesome, thx for clue. – Dennis Kriechel Jun 8 '14 at 16:36
1

You are using the wrong output-script. The output-script you are using is the one you would need for spending the bitcoins send in this transaction.

You need to use the outputscript which the input is refering to:

"txid": "e1142c945b73826b552407916c13402fb873fb1d3f7c16fa561367aaddd076a7",
"vout": 0

which is: 76a9145e4ff47ceb3a51cdf7ddd80afc4acc5a692dac2d88ac

So I checked your json and noticed that:

"asm": "OP_DUP OP_HASH160 f5d214041d44860c8c08202a9e4263fc47a2fe88 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a9145e4ff47ceb3a51cdf7ddd80afc4acc5a692dac2d88ac",

looking at the hex value and print it out as human readable:

76a9145e4ff47ceb3a51cdf7ddd80afc4acc5a692dac2d88ac = OP_DUP OP_HASH160 5e4ff47ceb3a51cdf7ddd80afc4acc5a692dac2d OP_EQUALVERIFY OP_CHECKSIG 

you see its different to the asm value:

f5d214041d44860c8c08202a9e4263fc47a2fe88           = 1PQnDVEi2u4e8rFmE3d9J51eQz8cQXpybC
76a9145e4ff47ceb3a51cdf7ddd80afc4acc5a692dac2d88ac = 19bgJQVTweVk5umYme3Xe5VYTnySRp1Yi9

As you can see those are two different bitcoin-addresses in there. If you use the hex value as script you should be fine.

  • Thank you for answer! :) Could you tell one more thing? How can I get proper output script? I thought that I have all information needed to count in this transaction. If I have for example this transaction link , what should I do? What scriptPubKey shoud I use? – me.ex Jun 8 '14 at 11:18
  • Just wrote a another answer because i cant get it all in a comment ;) – Dennis Kriechel Jun 8 '14 at 11:49

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.