Author

Topic: Blockchain scripting contest (Read 2156 times)

hero member
Activity: 797
Merit: 1017
March 27, 2014, 08:37:07 AM
#17
Thread moved & new stage opened!

https://bitcointalksearch.org/topic/m.5931067
newbie
Activity: 26
Merit: 0
March 27, 2014, 04:24:23 AM
#16
I guess I unterstood this now, waiting for the competition today Smiley
hero member
Activity: 797
Merit: 1017
March 26, 2014, 04:53:40 PM
#15
Ok I'm pretty sure I have a basic understanding of this. Throw your blockchain witchcraft at me! Tongue

Great! Next stage is scheduled for tomorrow at around 14:00 GMT. Don't miss it!
hero member
Activity: 797
Merit: 1017
March 26, 2014, 04:51:54 PM
#14
A more clear explanation of what's happening in the script.

StackOperationComment
x,y(scriptSig)scriptSig get executed, 2 numbers are pushed into the stack
x,y,x,yOP_2DUPThe first 2 values in the stack get duplicated
x,y,x+yOP_ADDThe first 2 values in the stack are added and the sum is pushed in the stack
x,y,x+y,8OP_8the number 8 is pushed in the stack
x,y OP_EQUALVERIFYThe first 2 values in the stack are tested, the script fails if they aren't equal (so, x+y=8)
x-yOP_SUBThe first 2 values in the stack are subtracted and the difference is pushed in the stack
x-y,2OP_2the number 2 is pushed in the stack
?OP_EQUALThe first 2 values in the stack are tested, if equal the number 1 gets pushed in the stack, 0 otherwise
?(final check)The first value in the stack must be not 0 or null. So, the previous test must be true, thus x-y=2

hero member
Activity: 854
Merit: 658
rgbkey.github.io/pgp.txt
March 26, 2014, 04:41:02 PM
#13
Ok I'm pretty sure I have a basic understanding of this. Throw your blockchain witchcraft at me! Tongue
hero member
Activity: 854
Merit: 658
rgbkey.github.io/pgp.txt
March 26, 2014, 04:29:07 PM
#12
That's great but my brain is crying.

EDIT: Think I get it now.
hero member
Activity: 797
Merit: 1017
March 26, 2014, 04:11:05 PM
#11
Sure, that's my idea.

Actually, since someone probably already sent the winning transaction, i'll give out the solution now.

first, let's solve the first half of the problem. Here's the scriptPubKey object of this first trial:

  OP_2DUP OP_ADD OP_8 OP_EQUALVERIFY OP_SUB OP_2 OP_EQUAL

I'll explain it under the assumption that you roughly know what a stack-based calculator is. Also, please refer to the script wiki page as a reference for the commands used in the scripts.

As the bitcoin protocol requires, you have to find a scriptSig that, when concatenated with the above script and executed, is considered valid. That is, the first stack item at the end of the script execution is not 0 or null, no verification fails and no illegal or invalidating operation is performed. Let's see what the scriptPubKey do.

OP_2DUP duplicates the first 2 values in the stack as they are. This suggests that the scriptSig, which gets evaluated right before this instruction, must yeld at least two values, let's call them x and y.

OP_ADD takes the first 2 values in the stack, adds them and pushes the result in the stack

OP_8 pushes the number 8 in the stack

OP_EQUALVERIFY tests the first 2 values in the stacks to be equal, and invalidates the transaction if they aren't. Since the first value is 8 (we just pushed it in the last instruction) the one before that, which is the sum of the 2 variables "x" and "y" in the scriptSig, must be 8 as well. So, we can assert that x+y=8

OP_SUB, OP_2 and OP_EQUAL make a similar thing, calculating the difference between the other 2 numbers in the stack which, thanks to the OP_2DUP at the beginning of the script, are still the 2 variables from the scriptSig. this tell us that x-y=2

So, we have x+y=8 and x-y=2. Solving this simple math problem gives x=5 and y=3, and thus the scriptSig simply is "OP_5 OP_3".


Now, to create the custom transaction that spends that output. There are a number of different methods to achieve this, but my tool of choice is brainwallet.org tx builder. Since the input of this transaction won't be address-based, you can safely ignore the private key and source address field. Set the "Destination address" to one of your addresses to have a template going, then click on the "Json transaction" button on the top of the form. Now, you have to manually change the parameters of the "in" section to connect the output from the test transaction. In the bitcoin protocol, a txout is defined by the hash of the transaction that created it and the ID of the txout inside that transaction. As wrote above, the hash of the transaction is ab149362ea4e119d2bc5211b35083c23ec41842af6bbc2ff3c5f1e55941199cc and the ID of the relevant txout is 0 (that is, the first entry in the txout list). Enter those values in the "hash" and "n" fields in the "in" section, overwriting the default values. Now you have to enter the scriptSig you desumed above: scroll to the scriptSig field, delete the bogus values you'll find there and just write "OP_5 OP_3". Almost done, all left is the amount of btc: the tx builder fails to detect the amount of BTC in non-standard transactions, so you'll have to set it manually. The amount of BTC available are 5 mBTC, or 0.005 btc. However, don't forget miner fees! Set the amount to 0.0049, so that 0.1 mBTC goes to eligius for the trouble of including your transaction in the blockchain.

Done, you don't even have to re-sign the transaction, because no signature verification is done. The raw transaction is ready, you can check it to be correct using the "signrawtransaction" RPC code in bitcoin: it should return a "complete":true parameter that tells you that it's ready to be broadcast. However, since someone already did that, trying to push the transaction through the eligius service will result in a failure because it will refuse to accept a double-spend transaction. Be quicker next time Cheesy

Real life applications of this script:

Next to none. The only objective of this stage is to help understanding how the bitcoin scripting mechanism works and to familiarize with the tools needed to build a transaction with custom scripts.
hero member
Activity: 854
Merit: 658
rgbkey.github.io/pgp.txt
March 26, 2014, 03:14:17 PM
#10
I'm interested in this stuff, but even after half an hour of looking at wiki pages I barely understand anything more than I did when I started. If your goal is to teach people, could you explain the process after someone successfully claims the first one?
member
Activity: 84
Merit: 10
March 26, 2014, 02:45:25 PM
#9
I understand that I'm supposed to use that, but I don't know how. Can you explain how I can submit a custom scriptSig for the transaction you gave?
hero member
Activity: 797
Merit: 1017
March 26, 2014, 02:29:34 PM
#8
Again, from the toolchain links in the OP:

Quote
Raw transaction generator: http://brainwallet.org/#tx

member
Activity: 84
Merit: 10
March 26, 2014, 02:08:53 PM
#7
However, I'm getting reports that eligius is refusing correct solutions, so probably the output has already been claimed.

For what it's worth, blockchain.info shows the output as unclaimed still. I understand that I have to use the tool to push the transaction, but how do I construct the raw transaction now that I know the scriptSig.
hero member
Activity: 797
Merit: 1017
March 26, 2014, 01:06:01 PM
#6
However, I'm getting reports that eligius is refusing correct solutions, so probably the output has already been claimed.
hero member
Activity: 797
Merit: 1017
March 26, 2014, 12:58:36 PM
#5
As it's a non-standard transaction, you'll need to give personally the transaction to the pools that accept them, and eligius is the only one I know. They have a nice tool that lets you push a raw transaction directly via web.
member
Activity: 84
Merit: 10
March 26, 2014, 12:15:07 PM
#4
Are you sure that the scriptPubKey is correct? Doesn't OP_EQUALVERIFY need to be at the end?

Never mind, I realized my mistake and solved the puzzle. Do I have to have bitcoin-qt to submit the answer?
hero member
Activity: 797
Merit: 1017
March 26, 2014, 10:54:43 AM
#3
1st trial

Funding transaction/output: ab149362ea4e119d2bc5211b35083c23ec41842af6bbc2ff3c5f1e55941199cc, n=0

Claimable amount: 5 mBTC (remember to reserve at least 0.1mBTC for transaction fees)

scriptPubKey to solve:

Code:
OP_2DUP OP_ADD OP_8 OP_EQUALVERIFY OP_SUB OP_2 OP_EQUAL

Difficulty level: easy

State: Probably claimed, but unconfirmed.

EDIT: Seems like someone managed to send a valid transaction to eligius, which is now blocking anyone from sending a different transaction that uses the same output. You can check the validity of your transaction using the signrawtransaction RPC call in bitcoin, or by posting it here.

EDIT2: Detailed solution posted here
hero member
Activity: 797
Merit: 1017
March 26, 2014, 10:54:14 AM
#2
reserved
hero member
Activity: 797
Merit: 1017
March 26, 2014, 10:54:03 AM
#1
This blockchain scripting contest is a way to raise awareness about the possibilities and powers of the scripting mechanism integrated in the Bitcoin protocol.

Every trial will be about a non-standard transaction output (scriptPubKey) broadcast by me and funded with a given amount. Objective of the trial is to find an appropriate script (scriptSig) that will succesfully resolve the stacked scripts, as requested by the bitcoin protocol. The amount in the tx output is the award of the trial and can be claimed at will.

The difficulty of the trials will increase in each step.

Recommended Toolchain:

Documentation: Transactions, Raw Transactions API, Scripts and OPcodes reference.

Have fun!

PS: Any amount sent to the address 1JHCn9wLLXHc4yfo968FrT259Um2hzeUpy will be used to fund the next trials.


First Stage: (Probably) claimed! https://bitcointalksearch.org/topic/m.5913898
Second Stage: Open on new thread! https://bitcointalksearch.org/topic/m.5931091
Jump to: