Bitcoin Forum
September 19, 2020, 03:29:22 AM *
News: Latest Bitcoin Core release: 0.20.0 [Torrent]
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Development & Technical Discussion / Assurance contracts on: September 18, 2012, 06:04:55 PM
Hello everyone,

After seeing Mike Hearn's talk at the conference I wanted to play a bit with some of that stuff so I started working on an assurance contracts proof of concept.

Using bitcoin 0.7 and the raw transaction API I got this working on testnet-in-a-box. I haven't tried this on the main bitcoin network.

This is a small python script that does three things:

1) Creating a new assurance contract.
$ python createcontract miA6bqrz9thieUpd5rZmHe1XpTmY6DLjot 7500000000
Contract tx:
Amount:  75
To:  miA6bqrz9thieUpd5rZmHe1XpTmY6DLjot

2) Adding pledges (this should be done by the various people wanting to pledge some bitcoins):
$ python pledge 01000000000100eb08bf010000001976a9141cf69384eb6b27a8161b59577f41310a93b9c14388ac00000000 5000000000
Sent 50BTC to address n21Nw4ikZrURVxaydZwYrPmdDyd8J8ZdQw
(private key: cVNe9DSbZPe71pzwWpRbiR1n4NQ2Bdqi67g7HGiJCzARtX66nefY)
TXId: 0ae14dc7c016d8bce090cfaa2eb88ce1e2818f24d3372c5682118ff5a68e8200

TXOut: 0ae14dc7c016d8bce090cfaa2eb88ce1e2818f24d3372c5682118ff5a68e8200:0
Signing transaction...

Signed input:

3) The person that made that contract needs to collect all inputs from everyone and put them in a single text file.
If there are enough pledges they can be combined and the final transaction sent to the bitcoin network.
$ python finalize 01000000000100eb08bf010000001976a9141cf69384eb6b27a8161b59577f41310a93b9c14388ac00000000 inputs
Sending raw tx...

This is still very much a proof of concept: command line application, having to share inputs, big strings that needs to be copied around, ... But it works Smiley

The code is on
Parts of it are copied from bitcoin-python, pynode and pywallet.

I think the next thing for this is to divide it in a server/client model: a server that holds assurance contracts and a client that allows people to pledge bitcoins to one of those contract and send a signed input over.
2  Economy / Goods / giftcard on: August 31, 2012, 04:28:46 PM
Hello all,

I'm looking to purchase a gift card from for an amount of 25.

I used to use, but they stopped this Sad

Any other similar service like this? Or anyone willing to purchase me one? If so, please let me know how many bitcoins you want. We can go through an escrow (not sure about what escrow services are there though) or if you look trustworthy then I can send the bitcoins first.

If you want to do this but can't read French I can show you how to do it, the site is very similar to the one.

3  Economy / Gambling / A fun little betting game :) Win one bitcoin and possibly even more! on: June 10, 2012, 03:54:39 PM

I thought of a fun little game and I want to try it out in practice.

The goal of the game is simple:
I transfer some bitcoins to an address and publish that address. Afterwards everyone can place a bid by transferring bitcoins to that address.
After some time, when the game closes, the person that placed the highest bid will win the whole balance of that address, minus a fee (I'll go with 2.5%).

I put up 1BTC on address abc123. Afterwards the following bets happen:
-Player A transfers 0.01
-Player B transfers 0.05
-Player A transfers 0.50
-Player C transfers 1.00
-Player B transfers 1.10
and there are no more bets after this. Player B wins and he gets the sum (= 3.66 BTC) minus the fee of 2.5%. So he wins 3.5685 BTC

So, anyone up for playing this? Smiley

I'll start with the following address: 1CoMXvhsHuu3PuxVs9ZbEu7a8jPqY2dsFH.

The person that gets the highest bid by 2012-06-10 20:00 GMT wins Smiley

Good luck!

Important notes:
  • I'll use one of the input addresses to send the prize to. So please use the official bitcoin client or another client / wallet website where you control the addresses. If you don't do can still play, but please PM me with your transaction ID at the same time you sent your transactions.
  • Bets lower than 0.01 will not be accepted.

If anyone have any questions, be sure to ask Smiley
4  Economy / Marketplace / Weekend in London on: June 06, 2012, 05:16:24 PM
Hi everyone,

I'm looking to spend a weekend in London the 14th and the 15th of July but I still need a place to stay at.

Instead of looking for a hotel I'm going to ask here and see if anyone can help me out:
Is anyone able to provide a sleeping place for one night on the Saturday?

I'll be arriving on Saturday and leaving again on Sunday. Only thing I'm looking for is a place to sleep at (a bed, a couch, doesn't matter really) and a bathroom so I can shower in the morning.

London is a bit of a big city and I don't know my way there. Most of my weekend will be spent in or around Hyde Park, so somewhere close to that would be ideal. And hopefully easy to find with public transport. I might be getting late back on Saturday, I have no idea, so keep that in mind.

I'm not sure what else to mention, I'm a bit of a quiet guy. I'll be coming from Belgium (by train). If you want to know anything, feel free to ask!

Please let me know (PM or post in this thread) if you can help me out and how many bitcoins you want!

Thanks Smiley

5  Other / Off-topic / Suggest me a book! on: July 08, 2011, 08:20:22 PM
Hello everyone,

I've always had an interest in cryptography but so far I've only learned about general concepts and did not try to understand the maths hidden behind them.

To solve this problem, I bought two books: Applied Cryptography and Elliptic Curves: Number Theory and Cryptography.

I started reading that second book only to find out that, unlike programming books, I can't just read them and understand what is written, as my maths knowledge is too small for that. Which is not really unsurprising as in high school, while I was good at maths, I only did the bare minimum to pass (who likes studying when you're that young!) and I didn't have any maths in college...

So, what I am looking for are book(s) to help me improve my math skills from basically high school level. Preferably the kind of maths that will be useful for me to understand more about cryptography. I can't be really be more specific though as I don't actually know what I need.

The books themselves should ideally fulfill the following criteria:
  • Written in a fun style, so no boring school books.
  • Language: English or Dutch. Or if the book is really good, it can be French too.
  • Has to have exercises with solutions.
  • Where possible, it has to show examples of actual uses of that kind of math.

I know this is a bit vague, which is why I'm asking this instead of googling around.

If you have any suggestions, please do share them! Smiley
6  Bitcoin / Development & Technical Discussion / Transaction verification in Python (with M2Crypto) on: June 16, 2011, 09:19:53 PM
Hey everyone,

I've been playing around with Python and bitcoin and while there are some implementations of the network protocol floating around on the web, I haven't found anything that can parse and run scripts from transactions and verify if they're valid.

After messing around, I've made a (really horribly) script that, given two linked transactions, checks that the second transaction is allowed to redeem the referenced output from the first transaction.

import binascii
import hashlib
import M2Crypto
import structures

#Transaction 2 uses an output from Transaction 1
#Transaction 1:
#Transaction 2:

tx1raw= '\x01\x00\x00\x00\x02\x0f{\x7f\xb8mL\xf6F\x05\x8eA\xd3\xb0\x07\x18?\xdfysn\xd1\x9b*th\xab\xc5\xbd\x04\xb1n\x91\x00\x00\x00\x00\x8cI0F\x02!\x00\xb2\xee9\xd2\xfc\xc2\xe5TJW\xc3\x0f{NI\xcf\xb8""fm\x03O\xb9\x0e"4\x8e\x17\xe2\x8e\x0f\x02!\x00\xdb\x91\xc3\x19\x9c\xc7\xb4\x1dMz\xfc\xe0\xcc\xb4\xce\xb4$\xb9GmQ\xc0aBX=\xafS\xce\n\x9bf\x01A\x04\xc3"\x15\xa9\t0\x11\xbd<A(:\xce=\x00,f`w\xb2J`[<\xfc\x8fq\x01\x9a\x0fC\xdff\xf3\x89\xf3\xd9\xa6!\x88\xa4\x94\xb8i\xdc~_\x9d\xff\xc9\x8av\xd3\x08\x8a!\xe9\xb78\xec\x9e\xba\x98\xcb\xff\xff\xff\xff\x97\x00A%R\x8f{^\xd34e\xca\xaa\xe0!\xc0\xb8\x15\xf3\xe6\xa3pvA\xd5\xa0\xbc\xa4?\xc1II\x01\x00\x00\x00\x8aG0D\x02 3\xd0,.\x89o\x1a\x12RH\x8dSL\xfb\x08\xab\xf3\xe7\xea\x90\xab\xa7\xbaoW\xab\xf1\x89\xce\xf1\xd87\x02 \x05f\x8duP\x13\xb0\xe5\x9a*\xf5\x14_\x10\xef\xe6.\xa7\x16\xd33&\x8b\x0bZ>\xfb\xd8-\x149\xbe\x01A\x04\xc3"\x15\xa9\t0\x11\xbd<A(:\xce=\x00,f`w\xb2J`[<\xfc\x8fq\x01\x9a\x0fC\xdff\xf3\x89\xf3\xd9\xa6!\x88\xa4\x94\xb8i\xdc~_\x9d\xff\xc9\x8av\xd3\x08\x8a!\xe9\xb78\xec\x9e\xba\x98\xcb\xff\xff\xff\xff\x01\x00\xc2\xeb\x0b\x00\x00\x00\x00\x19v\xa9\x14\x02\xbfK(\x89\xc6\xad\xa8\x19\x0c%.p\xbd\xe1\xa1\x90\x9f\x96\x17\x88\xac\x00\x00\x00\x00'
tx2raw= "\x01\x00\x00\x00\x030\xf3p\x1f\x9b\xc4dU/pIW\x91\x04\x08\x17\xcewz\xd5\xed\xe1nR\x9f\xcd\x0c\x0e\x94\x91V\x94\x00\x00\x00\x00\x8cI0F\x02!\x00\xf5tk\x0b%OZ7\xe7RQE\x9cz#\xb6\xdf\xcb\x86\x8a\xc7F~\xdd\x9ao\xdd\x1d\x96\x98q\xbe\x02!\x00\x88\x94\x8a\xea)\xb6\x91a\xca4\x1cI\xc0&\x86\xa8\x1d\x8c\xbbs\x94\x0f\x91\x7f\xa0\xedqThm>[\x01A\x04G\xd4\x90V\x1f9l\x8a\x9e\xfc\x14Hk\xc1\x98\x88K\xa1\x83y\xbc\xac.\x0b\xe2\xd8RQ4\xabt/0\x1a\x9a\xca6`n])\xaa#\x8a\x9e)\x93\x001PB=\xf6\x92Ecd-J\xfe\x9b\xf4\xfe(\xff\xff\xff\xffr\x14+\xf7hl\xe9,m\xe5\xb73e\xbf\xb9\xd5\x9b\xb6\x0c,\x80\x98-YX\xc1\xe6\xa3\xb0\x8e\xa6\x89\x00\x00\x00\x00JI0F\x02!\x00\xbc\xe4:\xd3\xac\xbcy\xb0$~T\xc8\xc9\x1e\xac\x1c\xf9\x03u\x05\x00\x0e\x01\xd1\xfd\x81\x18T\xd8[\xc2\x1a\x02!\x00\x99*oo/\xebob\xd3po;\x9a\xaa\xb8\x8d\x9f\x112\x95j\x1d\xff\xa9&\xcdUn\xd5S`\xdf\x01\xff\xff\xff\xff\xd2\x81(\xbb\xb6 |\x1c=\nc\x0c\xc6\x19\xdc~{\xeaV\xac\x19\xa1\xda\xb1'\xc6,x\xfa\x1bc,\x00\x00\x00\x00IH0E\x02  \x97W6\x81aSw\x08\xfd)\xd8\x9b\xb1\xe9\xd6H\x00yI\xec\xfd\xedx\x9bQ\xa9c$\xcbe\x18\x02!\x00\xcd\x0f|0!9\x16H+n\x16m\x8aO+\x98\x1fw~\xb1\x84\xcd\x8aI_\x1b=6\x90\xfb\xbf-\x01\xff\xff\xff\xff\x01\x00\xa6\xf7_\x02\x00\x00\x00\x19v\xa9\x14\x9e5\xd9<w\x92\xbd\xca\xadV\x97\xdd\xeb\xf0CS\xd9\xa5\xe1\x96\x88\xac\x00\x00\x00\x00"

tx1 = structures.Tx.deserialize(tx1raw)[0]
tx2 = structures.Tx.deserialize(tx2raw)[0]

#We're going to check that the first input of Tx2 is correctly redeemed

def run_script(script, stack):
    while script:
        opcode = ord(script.pop(0))
        if opcode <= 75:
            value = ""
            for x in xrange(0, opcode):
                value += script.pop(0)
        elif opcode == 118:
        elif opcode == 169:
            #The input is hashed twice: first with SHA-256 and then with RIPEMD-160.
            value = stack.pop()
            value = hashlib.sha256(value).digest()
            ripemd ='ripemd160')
            value = ripemd.digest()
        elif opcode == 136:
            v1 = stack.pop()
            v2 = stack.pop()
            if v1 != v2:
                raise Exception()
        elif opcode == 172:

            #1. the public key and the signature are popped from the stack, in that order.
            pubkey = stack.pop()
            signature = stack.pop()
            #2. A new subscript is created from the instruction from the most recent OP_CODESEPARATOR to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)
            #(we don't do the OP_CODESEPARATOR thing yet...)
            subscript = tx1.txout[0].script
            #3. the signature is deleted from subscript
            subscript = subscript.replace(chr(len(signature)) + signature, "")

            #4. The hashtype is removed from the last byte of the sig and stored
            hashtype = signature[-1]
            signature = signature[:-1]
            #5. A deep copy is made of the current transaction (hereby referred to txCopy)
            #(we do this by serializing and deserialing this transaction again...)
            txCopy = structures.Tx.deserialize(tx2.serialize())[0]
            #6. All OP_CODESEPARATORS are removed from subScript
            #(we don't do this yet...)
            #7. The scripts for all transaction inputs in txCopy are set to empty scripts
            for txin in txCopy.txins:
                txin.script = ""
            #8. The script for the current transaction input in txCopy is set to subScript
            #We're checking the first input
            txCopy.txins[0].script = subscript

            #An array of bytes is constructed from the serialized txCopy + four bytes for the hash type.
            #This array is sha256 hashed twice, then the public key is used to to check the supplied
            #signature against the hash.
            #Load the public key. I have no idea what this magical string does...
            pkey = pubkey[::-1] + "0042030a0004812b050601023dce48862a070610305630".decode("hex")
            pkey = M2Crypto.EC.pub_key_from_der(pkey[::-1])
            #Serialize the transaction and add the hashtype to the end as an int
            txhash = txCopy.serialize() + "\x01\x00\x00\x00"
            #And sha256 it twice
            txhash = hashlib.sha256(hashlib.sha256(txhash).digest()).digest()
            if pkey.verify_dsa_asn1(txhash, signature):
stack = []
run_script(list(tx2.txins[0].script), stack)
run_script(list(tx1.txout[0].script), stack)

print stack

This code needs which is my implementation of the (de)serialization of the various bitcoin messages.

The above script is really messy and more a quick proof-of-concept than anything else. Using it like that will be harmful for the bitcoin network as it is far from fully implemented and misses some small details.
The script checks that input 1 from this transaction is valid with the referenced transaction.

My biggest problem was with M2Crypto: it doesn't seem to implement o2i_ECPublicKey from openssl, which is used by bitcoin to set the public key. I also looked at using pyOpenssl and pycrypto, but it looks like neither of these libraries can handle elliptic curve cryptography...

To make M2Crypto work for this I had to use some magic, which I'm really not happy about:
pkey = pubkey[::-1] + "0042030a0004812b050601023dce48862a070610305630".decode("hex")
pkey = M2Crypto.EC.pub_key_from_der(pkey[::-1])
As you can see, I need to add a fixed string in order to load the public key. Without this it fails to load it and I get an exception (ValueError: Received a NULL pointer.)
This string I got by making new public/private key pairs with M2Crypto and printing them out: I noticed that this part is fixed and never changes. I assume this string defines the parameters used (NID_secp256k)

Anyways, I hope this is useful to someone. Feel free to use this code for anything, but keep in mind that it is horrible and needs lots of cleaning up.

And if anyone feels like improving it, go for it Smiley

Edit: I forgot to mention that this only validates standard transactions to another bitcoin address.
7  Bitcoin / Development & Technical Discussion / Some questions about scripts on: May 17, 2011, 11:28:36 AM
Hi everyone,

I've been looking at the script parts now of the Bitcoin protocol and have the following questions about it:

1) Right now there are only two (I think) different scripts whitelisted and it's not possible to do custom scripts. If a miner starts accepting transactions with non-standard scripts and creates a new block using them, will they also be accepted by the Bitcoin client?

I'm guessing they will, because the transactions being in a block already means they are valid transactions. I'm just asking for confirmation.

2) If I create a nonstandard transaction, with a valid and normal TxIn but with a special TxOut that has a script that always evaluate to true, everyone will be able to claim those bitcoins and use them for their own needs. In this situation, I'm assuming the first person that has a transaction in a valid block will be the "winner" and all the others that tried to use those coins will have their transactions never confirmed?

8  Other / Obsolete (selling) / Selling: Wii with 4 games [Europe only] on: May 07, 2011, 07:13:22 PM
Hello everyone,

I'm willing to sell my Wii with a couple of games because I never play on it anymore.

The whole package comes with:
  • Wii with the various cables and manuals
  • One wiimote
  • Wii sports game
  • Manhunt 2
  • Mad World
  • Prince of Persia: Rival Swords

I'm asking 50BTC for this, which includes shipping to Europe (I'm from Belgium). The shipping can take around one-two weeks.
I won't sell to anyone outside Europe: I don't think the Wii would work with something else than PAL tv's and the shipping would be way too expensive.

As this is my first post on here and that no one knows me and I don't have any trust, I'm willing to use an escrow service like ClearCoin to make it safer for the buyer.

Here are some pictures:

If you're interested, or have any questions, please post here or drop me a pm!

Pages: [1]
Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!