Bitcoin Forum
June 25, 2019, 02:52:34 AM *
News: Latest Bitcoin Core release: 0.18.0 [Torrent] (New!)
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Blockchain scripting contest  (Read 2081 times)
rb1205
Hero Member
*****
Offline Offline

Activity: 797
Merit: 1017



View Profile
March 26, 2014, 03:54:03 PM
Last edit: March 27, 2014, 01:37:41 PM by rb1205
 #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://bitcointalk.org/index.php?topic=534734.msg5913898#msg5913898
Second Stage: Open on new thread! https://bitcointalk.org/index.php?topic=538423.msg5931091#msg5931091

1561431154
Hero Member
*
Offline Offline

Posts: 1561431154

View Profile Personal Message (Offline)

Ignore
1561431154
Reply with quote  #2

1561431154
Report to moderator
1561431154
Hero Member
*
Offline Offline

Posts: 1561431154

View Profile Personal Message (Offline)

Ignore
1561431154
Reply with quote  #2

1561431154
Report to moderator
Bitcoin Poker 3.0
The Largest Bitcoin Poker Site
Bad Beat Jackpot Available
No Limit Texas Hold'em Cash Games And Tournaments
PLAY NOW
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1561431154
Hero Member
*
Offline Offline

Posts: 1561431154

View Profile Personal Message (Offline)

Ignore
1561431154
Reply with quote  #2

1561431154
Report to moderator
1561431154
Hero Member
*
Offline Offline

Posts: 1561431154

View Profile Personal Message (Offline)

Ignore
1561431154
Reply with quote  #2

1561431154
Report to moderator
1561431154
Hero Member
*
Offline Offline

Posts: 1561431154

View Profile Personal Message (Offline)

Ignore
1561431154
Reply with quote  #2

1561431154
Report to moderator
rb1205
Hero Member
*****
Offline Offline

Activity: 797
Merit: 1017



View Profile
March 26, 2014, 03:54:14 PM
 #2

reserved

rb1205
Hero Member
*****
Offline Offline

Activity: 797
Merit: 1017



View Profile
March 26, 2014, 03:54:43 PM
Last edit: March 27, 2014, 10:47:30 AM by rb1205
 #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

9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 26, 2014, 05:15:07 PM
Last edit: March 26, 2014, 05:30:26 PM by 9inety7even
 #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?

rb1205
Hero Member
*****
Offline Offline

Activity: 797
Merit: 1017



View Profile
March 26, 2014, 05:58:36 PM
Last edit: April 02, 2014, 10:40:22 AM by rb1205
 #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.

rb1205
Hero Member
*****
Offline Offline

Activity: 797
Merit: 1017



View Profile
March 26, 2014, 06:06:01 PM
 #6

However, I'm getting reports that eligius is refusing correct solutions, so probably the output has already been claimed.

9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 26, 2014, 07: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.

rb1205
Hero Member
*****
Offline Offline

Activity: 797
Merit: 1017



View Profile
March 26, 2014, 07:29:34 PM
 #8

Again, from the toolchain links in the OP:

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


9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 26, 2014, 07: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?

RGBKey
Hero Member
*****
Offline Offline

Activity: 840
Merit: 629


rgbkey.github.io/pgp.txt


View Profile WWW
March 26, 2014, 08: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?
rb1205
Hero Member
*****
Offline Offline

Activity: 797
Merit: 1017



View Profile
March 26, 2014, 09:11:05 PM
Last edit: April 02, 2014, 09:02:10 AM by rb1205
 #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.

RGBKey
Hero Member
*****
Offline Offline

Activity: 840
Merit: 629


rgbkey.github.io/pgp.txt


View Profile WWW
March 26, 2014, 09:29:07 PM
 #12

That's great but my brain is crying.

EDIT: Think I get it now.
RGBKey
Hero Member
*****
Offline Offline

Activity: 840
Merit: 629


rgbkey.github.io/pgp.txt


View Profile WWW
March 26, 2014, 09:41:02 PM
 #13

Ok I'm pretty sure I have a basic understanding of this. Throw your blockchain witchcraft at me! Tongue
rb1205
Hero Member
*****
Offline Offline

Activity: 797
Merit: 1017



View Profile
March 26, 2014, 09: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


rb1205
Hero Member
*****
Offline Offline

Activity: 797
Merit: 1017



View Profile
March 26, 2014, 09: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!

norbertVC
Newbie
*
Offline Offline

Activity: 26
Merit: 0


View Profile
March 27, 2014, 09:24:23 AM
 #16

I guess I unterstood this now, waiting for the competition today Smiley
rb1205
Hero Member
*****
Offline Offline

Activity: 797
Merit: 1017



View Profile
March 27, 2014, 01:37:07 PM
 #17

Thread moved & new stage opened!

https://bitcointalk.org/index.php?topic=538423.msg5931067#msg5931067

Pages: [1]
  Print  
 
Jump to:  

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!