On 02/06/2014 11:03 AM, i go bananas
wrote:
I don't know the specifics, but I think both cryptography and
finance are areas where the feature of "everything is a float"
actually gets in the way. In either case you cannot afford to lose
precision.
But you can prototype some of the features of a cryptocurrency in
Pd. For example, Bitcoin uses the hashcash algorithm to verify each
block of the transaction database. (If I understand it correctly
it's like brute-forcing SHA256 keys, although they never completely
succeed.) The miners basically start a counter, do a mathematical
function on the value plus the previous value from the last entry in
the transaction database, and finally check if the output has a
certain number of leading zeros.
If you ignore for the moment the counter and the mathematical
function, you can see how the process works. Attached is a patch
that just keeps spitting out pseudo-random numbers between 0 and 1
until all of the [random] objects happen to output zeros. It's
essentially like a slot machine that keeps playing until you win.
Now notice that when you hook up another [random] to the chain you
double the average time it takes to find a "winner". Add enough
[random] objects to the chain and you will quickly hit a point where
you can't compute a "winner" at all (even if you change the patch to
compute answers as fast as possible).
Bitcoin's "block difficulty" uses the same principle. The software
has a hardcoded rule that it should take 10 minutes to find a
"winner". But instead of using a bunch of binary values, it uses a
single number and requires the "winner" to be below a certain value
(which is equivalent to counting the leading zeros in the
representation of the number). Over a certain number of days it
measures the average time it takes the network to compute a
"winner". If it's way less than 10 minutes on average then the
software automatically does the equivalent of adding a [random] to
the patch to make it twice as hard. If it takes too long then the
software removes a [random]. The actual algo is probably more
sophisticated but that's what it boils down to.
Now, let's say you hook up 50 [random] objects in that patch and
happen to find a "winner". That'd be pretty spectacular, but how do
you convince everyone that you are being truthful about your claim?
This is where the hashing function and the counter come into play.
Instead of the attached patch, imagine a [hash] abstraction that
takes a counter value in the left inlet and the previous transaction
hash in the right inlet. It will output a seemingly unrelated
number in response to the input, but that number will be unique to
the input you give it (or so close to unique that we can just call
it unique). That's what a hashing function does. So you
essentially do the same thing you did above, except you're looking
for leading zeros in a single number rather than the collective
output of a bunch of [random] objects.
When you hit a "winner" you then broadcast your counter value and
the new transactions to the rest of the network to add to the
database. The rest of the network already has the previous entries
in the transaction database, so they can take those with your
counter value and verify that the resulting hash actually has the
correct number of leading zeros. Then everyone starts working on
the next "winner". And why do they do that instead of trying to lie
and say they were the one that actually found the "winner"? Because
the first new transaction in the database is the real winner giving
50 bitcoins to themselves, and that transaction uses public key
cryptography to ensure that it can't be forged or changed.
One last thing-- the hashing function is designed so that it's
extremely difficult (read: impossible) to start with a hash value
that has the required number of leading zeros and work backwards to
figure out the right counter value. Like a slot machine, you have
to just keep trying until win. And just like a slot machine, if
someone can figure out how get a winner without putting in the same
work/money everybody else does, then the entire system breaks down.
-Jonathan