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
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.