News for hackers. Stuff that matters.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by miohtama on Monday November 07, 2022 @10:07AM (#33506736)
The originally hack was caused by the fact that Silk Road was running PHP on MySQL without transaction isolation. Many early crypto exchanges had similar withdrawal bugs as they were running on LAMP stacks - MySQL has been notoriosly famous for having lax transaction isolation. Sometimes you could overwithdraw just by hitting refresh fast enough in a web browser.

If you deal with money use PostgreSQL + SERIALIZABLE transaction isolation level to be sure.

More in PostgreSQL documentation https://www.postgresql.org/docs/current/transaction-iso.html

Also Zhong was 22 years old script kiddie when he hacked Silk Road. Any smart criminal would have left United States long time ago if you sit on the top of $3B stash.

Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by Scoundreller on Monday November 07, 2022 @10:17AM (#33506874)
And failed to even depend on bitcoin’s double-spend protections. He deposited and was able to withdraw those deposits within seconds: before any block was confirmed on the blockchain.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by xyzzy4747 on Monday November 07, 2022 @10:32AM (#33507085)
As someone who very briefly poked around Silk Road at the time (just created an account), and as someone who has used PHP with the LAMP stack occasionally over the years, I am completely unsurprised. Race conditions can be pretty tricky to prevent in PHP, since the state is contained within different threads that can’t trivially communicate with each other. You need to be proficient with global state mutation such as via Redis or SQL.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by pmontra on Monday November 07, 2022 @10:42AM (#33507230)
Well, the database is there to manage and defend the data if only properly instructed to do so (CHECK constraints, locking, serialization.)
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by xyzzy4747 on Monday November 07, 2022 @10:48AM (#33507332)
True, but it’s still not trivial, unless you’ve thought of the race condition problems in advance. My guess is that instead of keeping all the withdrawal logic in a comprehensive DB transaction with good constraint checking, the code was broken up into multiple sequential PHP statements with transactions of simpler SQL (which is likely easier from a coding perspective) and with insufficient locking. This is the easier way to code it if you haven’t thought of or heard about race condition issues.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by pmontra on Monday November 07, 2022 @11:28AM (#33507978)
Yes, I'm sure that's what happened. The money withdrawal scenario is the classic example for locking in any database programming classroom but not everybody went through that or remembers it.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by ilyt on Monday November 07, 2022 @10:59AM (#33507517)
Even if you're not 100% sure in your DB code you can do defense in depth approach and have the code that does the money operations do some checking too.

Even executing queued operations with few seconds delay allow you to notice say a series of withdrawals putting account in negative

Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by Scoundreller on Monday November 07, 2022 @12:23PM (#33508923)
Yeah, and it’s Bitcoin withdrawals, nobody expects it to be anywhere near instant. I doubt the market place set its transaction fees very high either.

But then you have to create a queue that only runs 1 transaction per second. I guess another imperfect but simpler way is to create a batch file of transactions, execute hourly, but randomize or sort the sequence in a way to make sure related transactions aren’t executed together.

Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by amalcon on Monday November 07, 2022 @10:48AM (#33507327)
At the same time, this is like... data integrity 101. For future reference if you want to build a system that manipulates valuable information (such as monetary accounts), and you've never done anything like that before:

Please pick a database (relational or otherwise) with ACID transactions and replication, buy at least two different textbooks on that specific database, read both, do any exercises they suggest, and then decide whether you still want to build that system. If yes, then cool: don't hold me responsible if anything goes wrong, but you need to learn somehow.

Yes, it's possible to build systems like that on non-ACID-compliant databases, or without using the ACID functionality. It's much harder, though, and you really must understand what you're giving up in order to have a reasonable chance of success.

Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by xyzzy4747 on Monday November 07, 2022 @11:05AM (#33507625)
Probably the code had logic such as the following, which from an amateur perspective, seems to work. After all, the first check prevents the withdrawal if the account balance is too low, so what could go wrong?

  $balance = sql_query(“SELECT balance FROM accounts WHERE account_id = “ . $account_id);
  if ($withdrawal_amount < $balance) {
    withdraw_funds($account_id, $withdrawal_amount);
  }
The correct solution of course requires putting the checks in an ACID transaction along with the account balance updating. This requires more work upfront (SQL is harder to write than PHP) and an impatient amateur coder probably didn’t think of it. Also I’m guessing they didn’t properly index all the DB columns and this made transactions take longer which exacerbates race conditions.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by lmm on Monday November 07, 2022 @08:28PM (#33514925)
IMO this is backwards advice. Traditional relational databases with ACID go to great lengths to create the illusion that there's a single, global state, and that's what leads to people doing things like check-and-set that seem to work. You're far better off using a non-ACID database, simply because incorrect approaches will fail more visibly and more often. Ultimately you do the same amount of work either way, but using a non-ACID database forces you to do it upfront rather than letting you silently mostly succeed with a fundamentally broken data model.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by BoorishBears on Monday November 07, 2022 @09:12PM (#33515178)
This is a really optimistic take...

Realistically your DB of choice will probably try and tackle ACID half-heartedly because it's what devs expect, and that will lull you into the same false sense of security.

Many "eventually consistent" DBs will still have some concept that uses the word "transaction" that works like one until it doesn't (see DynamoDB and multi-region gotchas)

Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by miohtama on Tuesday November 08, 2022 @09:46AM (#33519507)
Your comment is not true for high quality databases like PostgrSQL. Check-and-set just works on the correct isolation level. There is no isolation, your transaction will fail and be rolled back.

If you are new to the subject there are extensive reports available from Jepsten, one of the leading names in distributed system and ACID anomaly testing and research.

https://jepsen.io/

Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by lmm on Tuesday November 08, 2022 @04:16PM (#33524420)
> Check-and-set just works on the correct isolation level.

Which is not the default one.

> There is no isolation, your transaction will fail and be rolled back.

How so? Isn't it more likely you'll silently corrupt your data?

Even if it does fail noisily, this is a condition you're unlikely to hit in testing, so you'll probably be dealing with it in production.

Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by deweller on Monday November 07, 2022 @10:44AM (#33507270)
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by herpderperator on Monday November 07, 2022 @05:59PM (#33513745)
...how modern are we talking? SERIALIZABLE existed over a decade ago. It's mentioned here in a 2009 post.[0]

[0] https://ronaldbradford.com/blog/understanding-mysql-innodb-t...

Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by hamiltonians on Monday November 07, 2022 @10:53AM (#33507422)
they would have arrested him overseas too
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by TheRealDunkirk on Monday November 07, 2022 @11:02AM (#33507583)
Yeah, look no further than the example of Kim Dotcom.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by swalsh on Monday November 07, 2022 @01:01PM (#33509508)
A lot of the early Bitcoin stuff was toys which became something more than toys faster than the people running it could transform the toy infrastructure at it's core. In most cases, they didn't have the experience necessary to make it something better. Mt Gox was just a reused domain and was origionally an exchange for Magic the Gathering!
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by spiorf on Monday November 07, 2022 @01:53PM (#33510384)
Can confirm. Did a double withdrawal (of about 10$ at the time) on an exchange years ago by blocking a POST request and firing two at the same time.

I alerted the exchange operator and he let me keep the 10$.

Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by Beaver117 on Monday November 07, 2022 @05:57PM (#33513723)
It wasnt worth anywhere near billions when he stole it. It wouldn't have been worth that much until very recently
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by miohtama on Monday November 07, 2022 @06:18PM (#33513910)
It was around 50k - 250k USD in 2012.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by swellguy on Monday November 07, 2022 @06:57PM (#33514281)
Sorry, you lost me at PHP on MySQL for financial transactions. That's hilarious.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by ipaddr on Monday November 07, 2022 @10:14PM (#33515516)
PHP isn't the issue here. Repeatly posting to any page normally would result in no security issue. If the balance is checked before each withdraw each request would be processed. Better method is a request is written to a transaction table and processed in sequence.
Re:US Attorney Announces $3.36B Cryptocurrency Seizure in Co... by srcreigh on Monday November 07, 2022 @09:41PM (#33515331)
Can anyone explain how a serialization anomaly as described in PG docs can result in a double withdrawal?

Seems to me that REPEATABLE READ mode should be sufficient, but I'm not sure.