Last active
October 30, 2020 07:15
-
-
Save gitmarek/3593fbd9eecbbbebcdc0 to your computer and use it in GitHub Desktop.
Pycoin does not validate Gavin Andresen's test multisig transaction (https://gist.github.com/gavinandresen/3966071)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python3 | |
import sys | |
from pycoin.tx import Tx, TxIn, TxOut | |
from pycoin.tx.Tx import SIGHASH_ALL | |
from pycoin.key import Key | |
from pycoin.tx.script.vm import parse_signature_blob | |
from pycoin.encoding import * | |
from pycoin.serialize import * | |
# Gavin Andresen's multisig test | |
# https://gist.github.com/gavinandresen/3966071 | |
# tx0 = funding tx, id: 3c9018e8d5615c306d72397f8f5eef44308c98fb576a88e030c25456b4f3a7ac | |
# url: https://blockchain.info/rawtx/3c9018e8d5615c306d72397f8f5eef44308c98fb576a88e030c25456b4f3a7ac?format=hex | |
# tx1 = spending tx, id: 837dea37ddc8b1e3ce646f1a656e79bbd8cc7f558ac56a169626d649ebe2a3ba | |
# url: https://blockchain.info/rawtx/837dea37ddc8b1e3ce646f1a656e79bbd8cc7f558ac56a169626d649ebe2a3ba?format=hex | |
tx_HEX = [ | |
'010000000189632848f99722915727c5c75da8db2dbf194342a0429828f66ff88fab2af7d6000000008b483045022100abbc8a73fe2054480bda3f3281da2d0c51e2841391abd4c09f4f908a2034c18d02205bc9e4d68eafb918f3e9662338647a4419c0de1a650ab8983f1d216e2a31d8e30141046f55d7adeff6011c7eac294fe540c57830be80e9355c83869c9260a4b8bf4767a66bacbd70b804dc63d5beeb14180292ad7f3b083372b1d02d7a37dd97ff5c9effffffff0140420f000000000017a914f815b036d9bbbce5e9f2a00abd1bf3dc91e955108700000000', | |
'0100000001aca7f3b45654c230e0886a57fb988c3044ef5e8f7f39726d305c61d5e818903c00000000fd5d010048304502200187af928e9d155c4b1ac9c1c9118153239aba76774f775d7c1f9c3e106ff33c0221008822b0f658edec22274d0b6ae9de10ebf2da06b1bbdaaba4e50eb078f39e3d78014730440220795f0f4f5941a77ae032ecb9e33753788d7eb5cb0c78d805575d6b00a1d9bfed02203e1f4ad9332d1416ae01e27038e945bc9db59c732728a383a6f1ed2fb99da7a4014cc952410491bba2510912a5bd37da1fb5b1673010e43d2c6d812c514e91bfa9f2eb129e1c183329db55bd868e209aac2fbc02cb33d98fe74bf23f0c235d6126b1d8334f864104865c40293a680cb9c020e7b1e106d8c1916d3cef99aa431a56d253e69256dac09ef122b1a986818a7cb624532f062c1d1f8722084861c5c3291ccffef4ec687441048d2455d2403e08708fc1f556002f1b6cd83f992d085097f9974ab08a28838f07896fbab08f39495e15fa6fad6edbfb1e754e35fa1c7844c41f322a1863d4621353aeffffffff0140420f00000000001976a914ae56b4db13554d321c402db3961187aed1bbed5b88ac00000000' | |
] | |
tx_LIST=[Tx.tx_from_hex(tx) for tx in tx_HEX] | |
tx_DB=dict((tx.hash(), tx) for tx in tx_LIST) | |
tx1 = tx_LIST[1] | |
print("# tx1.as_hex():\n%s" % tx1.as_hex()) | |
tx1.unspents_from_db(tx_DB) | |
if not tx1.is_signature_ok(0): | |
print("# tx1.is_signature_ok(0): False. That's bad.") | |
else: | |
print("OK.") | |
sys.exit(0) | |
print("# Try to regenerate the transaction.") | |
# Private keys | |
priv_keys = \ | |
['5JaTXbAUmfPYZFRwrYaALK48fN6sFJp4rHqq2QSXs8ucfpE4yQU', | |
'5JFjmGo5Fww9p8gvx48qBYDJNAzR9pmH5S389axMtDyPT8ddqmw', | |
'5Jb7fCeh1Wtm4yBBg3q3XbT6B525i17kVhy3vMC9AqfR6FH2qGk' | |
] | |
keys = [ Key.from_text(s) for s in priv_keys] | |
# Raw, unsigned transaction from Gavin's gist. | |
tx_tmp=Tx.tx_from_hex('0100000001aca7f3b45654c230e0886a57fb988c3044ef5e8f7f39726d305c61d5e818903c0000000000ffffffff0140420f00000000001976a914ae56b4db13554d321c402db3961187aed1bbed5b88ac00000000') | |
redeem_script=h2b('52410491bba2510912a5bd37da1fb5b1673010e43d2c6d812c514e91bfa9f2eb129e1c183329db55bd868e209aac2fbc02cb33d98fe74bf23f0c235d6126b1d8334f864104865c40293a680cb9c020e7b1e106d8c1916d3cef99aa431a56d253e69256dac09ef122b1a986818a7cb624532f062c1d1f8722084861c5c3291ccffef4ec687441048d2455d2403e08708fc1f556002f1b6cd83f992d085097f9974ab08a28838f07896fbab08f39495e15fa6fad6edbfb1e754e35fa1c7844c41f322a1863d4621353ae') | |
p2sh_lookup = {hash160(redeem_script): redeem_script} | |
# Construct hash160_lookup dictionary for two keys Gavin used to sign his transaction | |
hash160_lookup= {k.hash160(): (k.secret_exponent(), k.public_pair(), True) for k in keys[:-1]} | |
tx_tmp.unspents_from_db(tx_DB) | |
tx_tmp.sign(hash160_lookup, hash_type=SIGHASH_ALL, p2sh_lookup=p2sh_lookup) | |
print("# tx_tmp.as_hex():\n%s" % tx_tmp.as_hex()) | |
if tx_tmp.is_signature_ok(0): | |
print("# tx_tmp.is_signature_ok(0): True") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment