
BasicCoin, a cryptocurrency in less than 600 lines of Python - dbbolton
https://github.com/zack-bitcoin/basiccoin
======
roasbeef
600 lines, however the codebase is quite unreadable. Typically, code written
in python is rather readable and easy to follow, but this is heavily condensed
and somehow completely void of any sort of pythonic code. Programs are the
communication of thoughts between fellow software writers, readability should
be your #1 priority.

~~~
kylnew
Yeah. The author says they are following pep8 but I thought spaces between
functions was part of those guidelines. Definitely trying hard to reduce the
lines below 600. Yet I feel like if the bragging rights had been "under 1000
lines" we still would be equally interested.

~~~
meowface
Very little of this follows PEP8. The code appears to have been written as
tersely as possible, even in cases where it would have utterly no effect on
the 600 SLOC limit.

------
limmeau
Wouldn't it be even easier to just use Git for most of the heavy lifting?

\- Ledger is a file in a Git repo

\- Blocks are confirmed by committing them with a SHA1 with sufficiently many
leading zeros (adjust a nonce in the commit msg until it fits)

\- Some bot accepts all pull requests into the Github repo that are fast-
forward and whose commits have sufficiently many leading 0s (possibly after
confirming that the booking is valid ;)

We could call that... oh I don't know, DvcsCoin or so.

~~~
philtar
'gitcoin'

Perfect name.

Knowing HN this is gonna be a show HN in a couple of days and rewritten in 10
lines of js a week after that.

~~~
zachlatta
This was a challenge in Stripe CTF3. As mentioned by aljungberg, see
[https://github.com/ctfs/write-ups/tree/master/stripe-
ctf3/le...](https://github.com/ctfs/write-ups/tree/master/stripe-ctf3/level1)

------
kordless
Millions of currencies. I was standing at the back of the room when Andreas
said that and I was like, yeah, I can see it.

The blockchains deliver trusted communication of stored work to us. The
network has value in and of that function alone. That I can verify you have
thing of X value and I have thing of Y value and that the ratio of X to Y is
such as established by these market APIs/feeds. Which themselves are running
on a trusted computing platform that is a fair and accurate representation of
what is what in this world, up to a point.

That there will be a million blockchains working together in a mishmash of
interconnected markets, is no more difficult than imagining a million seperate
computer networks, each of which is using a private address block
10.0.0.0/24\. Some things are meant to be highly distributed, some are not.

Why would you ever expect a cryptocurrency based on the thesis of high
distribution to ever be a singleton itself?

~~~
roasbeef
See Sidechains[0], and Treechains[1]. But as always, without the proper
incentives a block chain is unsustainable and vulnerable.

[0]:
[http://sourceforge.net/p/bitcoin/mailman/message/32108143/](http://sourceforge.net/p/bitcoin/mailman/message/32108143/)

[1]: [https://www.mail-archive.com/bitcoin-
development@lists.sourc...](https://www.mail-archive.com/bitcoin-
development@lists.sourceforge.net/msg04388.html)

------
rabino
Unless I'm missing something, the only advantage of it being only 600 lines of
code is for educational purposes. But condensing the code in such way to
reduce line count goes against such objective. Any other reason to advertise
brevity in LoC?

~~~
maaku
Fewer points of failure for consensus.

Of course, being written in a dynamic interpretive language goes against that.

~~~
kordless
We'll do it in 600 lines of assembler!

~~~
maaku
That would be vastly better.

------
sakai
Honest suggestion: Change the tagline to "less than 1000 lines" or exclude the
GUI or whatever, but don't just not include line breaks anywhere.

You have 7 very sensible, and indeed admirable, style guidelines and while no
line breaks only clearly violates one of them (PEP8), it's not really in the
spirit of the others either. I opened gui.py and immediately was overwhelmed,
rather than compelled to dive in and digest your small codebase.

~~~
cpach
As someone more accustomed to Lisp than Python I must say the lack of extra
line breaks didn't feel so weird to me :)

------
btmorex
Basically unreadable. Not sure what you were going for, but I think it was the
wrong thing.

Off the top of my head:

1.) There's no reason not to use newlines. They have no chance of introducing
bugs in any reasonable language and they aid readability.

2.) You're using closures all over place and I haven't checked every
occurrence, but I strongly suspect that almost all of them are unnecessary and
unhelpful. Closures are not free in terms of code complexity. Use them only
when necessary.

~~~
agorism
1) newlines reduce the amount of code that you can see on the page at a time.
Skipping newlines is identical to purchasing a bigger monitor.

2) Some people group similar functions into classes. I dislike classes and
prefer grouping code this way.

~~~
DavidBradbury
> Skipping newlines is identical to purchasing a bigger monitor.

Wat.

------
eordano
Very cool! Though it looks like "less than 600 lines" made you write awfully
styled code :/

------
codexon
I wish you tried to make the code readable rather than making as many 1-liners
as you could.

------
yeukhon
I am bother by the desire to get smaller and smaller. A secure implementation
will have a lot of code to verify incoming data and handle exceptions. It is
fun to learn and implement HTTP server from the raw socket module (I did that
once for my security project in my computer security class too), but if you
are just looking for a simple server that you can handle GET and POST look
into bottle.py

A single file / pip install write into setup.py and you are good to go.

This I consider as educational, which I assume is the case by the desire to go
smaller and implementing such socket server.

------
stuki
I have to say I think crypto currencies is an area where the keep it simple
approach is extremely beneficial. If it means fever optimizations, and leads
to a greater dependency on off chain transactions, so be it. For genuinely
wide spread adoption, more important than speed and transaction volumes, are
an ironclad faith in the integrity of the underlying code itself.

------
xiphias
It's awesome idea but..could you add comments? (hint: you don't need to count
the comments when counting lines of code :) it's normal to have more comments
than code for a dense code, and it make things easier to understand )

------
frantzmiccoli
The idea seems legit ; however trying to reduce the number of lines of code by
a "no skipped lines & no comments" policy is not helping the ease of
modification, which seems to be one of the target.

------
drcode
I find it depressing that someone puts into the work to make a cool library
and 2/3rds of the comments are whining about the author using the "wrong"
number of newlines and other stylistic issues.

------
shabinesh
The idea is cool and helps to learn crypto coin systems. But restricting the
number of lines of code might only make it obfuscated. :)

------
vojfox
I wonder how practical it would be to take Bitcoin Core and gradually reduce
its # of (non-blank) lines.

~~~
wyager
Sadly, the core client has the job of being capable of bootstrapping itself
starting at the genesis block and ending at the most recent block.

That means that, barring a huge design change in Bitcoin itself, the core
client has to support every single feature ever implemented in Bitcoin, no
matter how half-assed or poorly thought out.

That's why things like the way P2SH got implemented really grind my gears.
Bitcoin has a few idiosyncratic and unintuitive design additions that make it
really hard to make simple clients.

------
drcode
Can anyone figure out where in this code it determines the addresses of other
peers?

~~~
agorism
tools.py it uses pybitcointools library.

~~~
drcode
Hmm... I still don't understand...

There has to be some place(s) online where peers register their existence, to
find others to connect with.

Near as I can tell, this app doesn't have a feature for this yet. I'd argue it
isn't a cryptocurrency unless there's a mechanism for finding other peers
included in the code.

(That said, this is still an awesome proof of concept, and I'm going to work
through all the source code carefully.)

~~~
agorism
You are correct. This is the basic platform for building currencies upon. I
have not launched any genesis blocks yet.

~~~
drcode
Thanks for this library!

------
joyofdata
If I'd get one Bitcoin for every cryptocurrency that is promoted on HN, ...

------
python26rocks
This is really poor

