News for hackers. Stuff that matters.
Re:GG-flip: simplest and most efficient ways to flip the sig... by dahart on Saturday January 20, 2018 @06:33PM (#16196028)
> The final lib size is few GBs, so distribution may become a problem.

Hahaha!

I admit to being slow; I missed the above sentence the first time, and I actually skimmed the whole thing and made it here to the comments before realizing it was a joke. Reading it again, there are quite a few gems I missed the first time, it's quite funny.

BTW check the linked thread on Reddit for more hilarity https://www.reddit.com/r/shittyprogramming/comments/7n35m7/h...

Re:GG-flip: simplest and most efficient ways to flip the sig... by IncRnd on Monday January 22, 2018 @04:16PM (#16207977)
Bitcoin Client, Critical Unflipper Vulnerability Steals Coins

https://news.ycombinator.com/item?id=16206743

Apparently, the Federal Government, Amazon, Google, and Facebook have known about the security issues of directly using unary negation without the gg-flip table driven approach for some time.

The link claims Shodan found over 20,000 vulnerable government servers and to apply gg-flip immediately.

Re:GG-flip: simplest and most efficient ways to flip the sig... by emmelaich on Saturday January 20, 2018 @10:23PM (#16196723)
Look at his other repos too, particularly rockstar.
Re:GG-flip: simplest and most efficient ways to flip the sig... by justin_vanw on Saturday January 20, 2018 @08:12PM (#16196354)
>>GG Flip is a Golang library which generates the Javascript sign flip library. I preferred Go because lack of generics seemed like a good design choice.

God help us if this isn't satire.

Re:GG-flip: simplest and most efficient ways to flip the sig... by simooooo on Monday January 22, 2018 @02:52AM (#16202639)
Considering the context of the whole article. It's hilarious
Re:GG-flip: simplest and most efficient ways to flip the sig... by Stratoscope on Sunday January 21, 2018 @05:26AM (#16197513)
I think Stack Flip is the optimal solution, as it requires very little code and can handle any number, even values the code has never encountered before. The library simply calls out to a web service that posts the question on Stack Overflow.

It should only take a few seconds for someone to post the answer. And the service will then upvote the answer, thus motivating Stack Overflow users to keep providing those results.

Re:GG-flip: simplest and most efficient ways to flip the sig... by johnfn on Saturday January 20, 2018 @07:47PM (#16196291)
Maybe this is a problem we could use ethereum smart contracts to solve. Actually, is flipping a number even in P? Verification is easy - just compare against the negative - but I'm not sure if flipping the number can be done in polynomial time, enumerating all cases (as OP has done) aside.
Re:GG-flip: simplest and most efficient ways to flip the sig... by avinassh on Sunday January 21, 2018 @06:27AM (#16197675)
Thanks for this idea, I will explore this further.

(author here)

Re:GG-flip: simplest and most efficient ways to flip the sig... by krisives on Sunday January 21, 2018 @06:46AM (#16197727)
Make sure it has machine learning please!
Re:GG-flip: simplest and most efficient ways to flip the sig... by maweki on Sunday January 21, 2018 @04:44AM (#16197455)
I wholeheartedly believed that the first approach was a popular npm library.
Re:GG-flip: simplest and most efficient ways to flip the sig... by avinassh on Sunday January 21, 2018 @06:27AM (#16197676)
soon, it will be!

(author here)

Re:GG-flip: simplest and most efficient ways to flip the sig... by perl4ever on Saturday January 20, 2018 @09:22PM (#16196552)
The obvious solution would be x = ~x + 1, right? And don't even bother if x is the minimum signed integer.
Re:GG-flip: simplest and most efficient ways to flip the sig... by Ono-Sendai on Saturday January 20, 2018 @09:43PM (#16196610)
The usual/obvious solution is to flip the sign bit. (for floating point numbers). I think you're right for two's complement integers.
Re:GG-flip: simplest and most efficient ways to flip the sig... by perl4ever on Saturday January 20, 2018 @10:21PM (#16196716)
I was kidding...but I was also thinking of the thread where people were discussing big vs little endian and the idea that since nobody uses big endian any more, it's not necessary to allow for it.
Re:GG-flip: simplest and most efficient ways to flip the sig... by OskarS on Sunday January 21, 2018 @06:05AM (#16197612)
Endianess only matters for how numbers are stored in memory, but operations like bitshifts, boolean operations and arithmetic happen after the number has been loaded into a processor register, so endianess doesn't matter.

Even if that wasn't the case, flipping a two's complement integer requires only negation and addition (as you showed), and those don't really depend on data layout.

Re:GG-flip: simplest and most efficient ways to flip the sig... by gugagore on Sunday January 21, 2018 @08:00AM (#16197892)
> and those don't really depend on data layout.

Not sure I understood this, but 01+09 = 10 and 10+90 = 100 and 10 ≠ fix_endianness(100)

Re:GG-flip: simplest and most efficient ways to flip the sig... by rkeene2 on Sunday January 21, 2018 @01:33PM (#16199270)
10!=01 and 09!=90

The endian-ness is only the in-memory layout of the bits and has nothing to do with how VALUES are treated. 1+9=10, regardless of how those values are stored, similarly 1<<9=512, regardless of how the CPU internally arranges those bits. The same holds true for inverting the value, the internal arrangement of the bits is irrelevant.

Really you only care about endianness when you fail to treat numbers as numbers, for example by treating them as bytes.

Re:GG-flip: simplest and most efficient ways to flip the sig... by dlahoda on Saturday January 20, 2018 @03:59PM (#16195406)
Good solution. It grounds me even more to start learning Go lang.
Re:GG-flip: simplest and most efficient ways to flip the sig... by joosteto on Saturday January 20, 2018 @04:03PM (#16195417)
So what if x > MAXNUMBER/2 ?

Also, how can this be faster than x=0-x; ?

Re:GG-flip: simplest and most efficient ways to flip the sig... by infogulch on Saturday January 20, 2018 @04:10PM (#16195444)
This took me a second to realize this is satire too.
Re:GG-flip: simplest and most efficient ways to flip the sig... by jwilk on Saturday January 20, 2018 @04:11PM (#16195448)
It's a joke. And yeah, it gives wrong answers for some numbers.

BTW, JS has unary minus, so you can write:

    x = -x
Re:GG-flip: simplest and most efficient ways to flip the sig... by IncRnd on Sunday January 21, 2018 @12:35PM (#16198978)
I think the author chose a more efficient table-driven approach, due to the extra 0 in your 0-x expression.
Re:GG-flip: simplest and most efficient ways to flip the sig... by kingo55 on Saturday January 20, 2018 @05:17PM (#16195719)
The real joke was that he was interested in Bitcoin cash.
Re:GG-flip: simplest and most efficient ways to flip the sig... by IncRnd on Saturday January 20, 2018 @11:28PM (#16196851)
Is this a joke?

Two's complement: flips the bits and add one

FP: flip the sign bit

OR....

x=-x

Re:GG-flip: simplest and most efficient ways to flip the sig... by jschwartzi on Sunday January 21, 2018 @09:46AM (#16198210)
There are several security issues related to usage of the negation operator that make it undesirable to use in this situation. The solution presented in the article avoids those holes. It also has the advantage that a switch statement is more explicit than use of a language facility.
Re:GG-flip: simplest and most efficient ways to flip the sig... by IncRnd on Sunday January 21, 2018 @12:32PM (#16198951)
Nice, but you really should give some examples, too. Something like:

The Bitcoin client's use of unary negation has caused traders to lose $32.49 Billion over the last three week period, according to a recent study by Price Waterhouse Cooper. From a similar accounting produced by the US Office of Management and Budget, HODLers lost an amazing $1.479 Trillion - That's Trillion with a "T"!

A table-driven Unary NOT solves the issues caused by the use of Bitwise NOTs and direct operator use. To that end, we submitted a pull request. After 4 weeks of repeatedly sending the same pull request to the BC team (and being ignored), we are now disclosing this Bitcoin Client issue for everyone to see. Remember to patch this use in your Bitcoin Client, or your funds may be stolen! If you need to use an editor for this fix, and do not normally program, the use of SED will speed up your client edits tremendously. https://www.gnu.org/software/sed/manual/sed.html*

Now that this critical issue has been disclosed, we strongly urge all Bitcoin users to patch immediately, or their funds will likely be summarily depleted within a week.

Re:GG-flip: simplest and most efficient ways to flip the sig... by krisives on Sunday January 21, 2018 @06:47AM (#16197729)
It does have an enterprise edition!
Re:GG-flip: simplest and most efficient ways to flip the sig... by IncRnd on Sunday January 21, 2018 @12:38PM (#16198992)
Excellent! That solves the distribution problem, due to the size of the release. Nobody will notice anything off, in enterprise deployments.
Re:GG-flip: simplest and most efficient ways to flip the sig... by vidanay on Saturday January 20, 2018 @03:47PM (#16195339)
Sounds suspiciously like a LUT
Re:GG-flip: simplest and most efficient ways to flip the sig... by jonsen on Saturday January 20, 2018 @03:53PM (#16195374)
Re:GG-flip: simplest and most efficient ways to flip the sig... by jwilk on Sunday January 21, 2018 @11:11AM (#16198551)
Re:GG-flip: simplest and most efficient ways to flip the sig... by matthberg on Saturday January 20, 2018 @05:09PM (#16195681)
A satirically unneeded look-up table, but yeah, pretty much!
Re:GG-flip: simplest and most efficient ways to flip the sig... by make3 on Sunday January 21, 2018 @10:05AM (#16198287)
what.. why..