Hacker News new | past | comments | ask | show | jobs | submit login
std::unique_ptr implementation backed by Ethereum NFTs (github.com/zhuowei)
559 points by abhorrence on April 11, 2021 | hide | past | favorite | 84 comments



Joking aside, their white paper (https://raw.githubusercontent.com/zhuowei/nft_ptr/main/white...) is a must-read.


Thank you. I must say that this is the ONLY white paper I managed to understand, ever. Very concise. Kudos to the authors. I wish we had more like this.


As are their benchmarks

> nft_ptr has negligible performance overhead compared to std::unique_ptr, as shown by this benchmark on our example program:

std::unique_ptr 0.005 seconds

nft_ptr 3 minutes


I loved this section of the readme - I nearly choked I was laughing so hard.

That said, I don't really think 3 minutes is that terrible for what it's doing. But man the phrasing there tickled me.


It would be nice to have energy consumption benchmarks too...


And only one of these options costs $100s in gas fees.


I was tempted to open an issue:

Printing on green paper did not make it white.


Do it! Bug: printing the white paper on colored paper does not work as expected



Maybe I'm too young, but I had no idea the phrase only originated in 1994


The presence of a white paper gives any project the luster of pseudo-academic rigor.


Did I just got hacked reading this “white paper”?


I just wanted to use a one word reply, but that might have lacked the context. So I will say, good job :)


zajebisty


"For a limited time, you can buy any Git commit from this repository as a Non-Fungible Token on my Content-First Multimedia Proof-of-Authority revision-controlled realtime collaborative private enterprise blockchain (a shared Google Doc)."

Made my day.


This is one of the most subtley funny things I’ve ever seen on H.N, specifically because the target audience is so small. You have to understand both C++ memory management and what an NFT is.


And it’s written in rust!


Wow, I thought for sure it was a punchline, but no:

> written in rust for the hipster cred.

I'm probably a founding member of the Rust Evangelism Strike Force but stuff like this seems ... way overboard. Almost like a Poe's Law demonstration - it's hard to determine whether it's satire or not.


These are my favorite coding projects. No business case, no practicality for non-developers (or developers for that matter), no long term support, no problem solving. Just a love/hate letter to software and the absurdity it brings to our world.


I assume you're very familiar with Tom7, and in particular his SIGBOVIK submissions, but just in case: Tom7!

(Good starting point for anyone who's not: https://m.youtube.com/watch?v=HLRdruqQfRk )


You may enjoy DOS Subsystem for Linux: https://github.com/haileysome/doslinux


I get the sense from other comments in this thread that I did indeed miss the point - it is satire. Just a little too subtle IMO.


> Just a little too subtle IMO.

Direct quote from the linked page:

> As we all know, adding blockchain to a problem automatically makes it simple, transparent, and cryptographically secure.


Or:

> nft_ptr has negligible performance overhead compared to std::unique_ptr, as shown by this benchmark on our example program:

  Implementation        Runtime
  std::unique_ptr       0.005 seconds
  nft_ptr               3 minutes


Of course it's satire; one of the most absurdist forms of satire is finding something ridiculous yet taken seriously, and treating it far more seriously than that.

Of course it's written in Rust.


It’s still a punchline


They should have called out the usage of Nocode to create the white paper


> Future steps

> nft_ptr instances are themselves ERC-20 tokens with 0 supply, for forward compatibility with our next library, nft_shared_ptr.

> nft_shared_ptr will implement reference counting with security by selling shares to the owned object until the SEC complains.

The whole repo is a goldmine but this really had me in stitches.


I'd love to see how they'll implement nft_weak_ptr and its creation from and conversion to a nft_shared_ptr :).


Aside from the brilliant satire, it’s worth pointing to the “What I Learned” section of the readme:

  how C++ smart pointers are implemented
  how to implement a Non-Fungible Token
  how the Ethereum ecosystem has evolved since I wrote my last smart contract in 2017
  how to integrate my previous Solidity, Truffle, and Ganache workflow with new tools such as OpenZeppelin and hosted wallets
  how to write a (trivial) program in Rust without fighting the borrow checker once
  how to use rust-web3, serde_json, and the openssl crates
  how to call Rust from C
I often struggle with deciding what to build as a practice project when I want to learn a new skill, and this is a good reminder that “humor” is an acceptable answer. Using a satirical project to learn how smart pointers are implemented is genius.


The author has an excellent reply to a question on twitter

>> What are the gas prices like for copying a pointer?

> Copying an nft_ptr is illegal. Moving an nft_ptr takes 87,169 gas: https://goerli.etherscan.io/tx/0xcbe06fdd54bd9d221993c875022... at mainnet gas prices of ~100 Gwei, equal to 0.0087169 ETH, or $18.69 USD. (This was intentionally written to waste resources for no benefit, just like cryptocurrencies themselves)

> The C++ "as-if" rule means the compiler is allowed to optimize away the move, but it still needs to charge the $18.


> Made with by a Blockchain Expert who wrote like 100 lines of Solidity in 2017 (which didn't work)

This made me chuckle.


A masterfully executed satire!

The paranoid part of me worries this will be used for real in the future.

The thing with building abstractions is, once you cover enough pieces to make a complete abstraction, people might run away with it and build castles on top, completely ignoring that the abstraction is implemented in terms of a joke. And once enough software is built on it, it'll be easier to start optimizing the joke to work faster than to get rid of it...

(Also, I don't see any mention what happens to the NFT when the nft_ptr goes out of scope.)


Your second paragraph paints a pretty grim scenario. Has this ever happened before? Someone building castles on a joke abstraction?


Flask was originally an April fools joke with what the author thought was a silly design. It is now widely used, including in production systems at my company.

http://mitsuhiko.pocoo.org/flask-pycon-2011.pdf


In case anyone wants a video of the original talk: https://archive.org/details/pyvideo_440___opening-the-flask


Lol this isn't grim at all. As far as I understand, they came up with a pretty good architecture as a joke.


Javascript?


Dogecoin?


What infrastructure in made on top of dogecoin? I feel like everyone uses it as a joke coin.


I was wondering if it was a joke, until I saw the white paper.


That’s the problem with all the idiotic blockchain projects around at the moment. I was only ninety percent sure it was a joke until about halfway through when the performance chart confirmed it but it is only slightly more ridiculous than several “legitimate” projects.


From the readme: "As we all know, adding blockchain to a problem automatically makes it simple, transparent, and cryptographically secure."


Sadly that's pretty realistic as far as blockchain project author statements go.


The benchmarks showing negligible performance differences also gave it away.


Hmm, 994 bytes; that’s rather small, wonder what’s in it?—

Ah.


ok, u got me - it was clearly a parody, but the whitepaper made me check and it took a few seconds to click. Love ur work!


To be fair, the paper is white.


Just look at the results from the “example program“ for benchmarking.


WARNING: This code is not safe to store secrets with.

From the readme:

> others may view the NFT/use the object, but only the owner can transfer/destroy the NFT/object. > absolutely no protection against just pirating the image represented by the NFT/copying the pointer out of the unique_ptr

I would open an issue to support RFC 8959 and refuse to mint NFTs with secret-token URIs, but I think instead I will learn how to mint an NFT of RFC 8959.


If you like this kind of humor, I'd recommend following Zhouwei Zhang on twitter[1] (not affiliated). His posts, I think, resonates well with HN's audience.

[1]: https://twitter.com/zhuowei


Considering unique_ptr is not zero cost, this is fair game I say.


With clang you can make a unique_ptr that is though. It just cannot be used for the std one as that would break existing code. But clang has an attribute [[clang::trivial_abi]] and with that the cost really is zero compared to a pointer.


> Non-Fungible Tokens and std::unique_ptr have the exact same semantics:

> [...] absolutely no protection against just pirating the image represented by the NFT/copying the pointer out of the unique_ptr

Perfect!


"You can also help by going full r/roastme on my code: this is only my second Rust project, and I would appreciate guidance on my journey to carcinization."

This is a very clever joke, so let me dissect it:

The "carcinization" is a callout to, I presume, xkcd 2314 ( https://xkcd.com/2314/ ), about how crustaceans tend to repeatedly evolve into crabs, and xkcd 2418 ( https://xkcd.com/2418/ ), which makes the claim that any conversation with Randall evolves towards the topic of carcinization.

A cutesy nickname for Rust fans is "Rustaceans". (Rust-aceans, like crustaceans.) With some creativity, we may then see the process of becoming an experienced Rust user as another instance of carcinization, especially given the similarity between xkcd's "metacarcinization" and the way that rustaceans, as fans are wont to do, tend to find a way to make the conversation about Rust.


> The "carcinization" is a callout to, I presume, xkcd 2314 ( https://xkcd.com/2314/ ), about how crustaceans tend to repeatedly evolve into crabs

That’s not an xkcd joke though, it’s an actual observation of evolutionary biology, first published in 1916.


Correct, but I suspect most geeks who know the term know it from xkcd, and that supports the additional metajoke about changing the topic to talk about Rust.


That's an expensive operation.


Was curious about this. If implemented, exactly how expensive would it get in the first 24h (assuming ETH at $2000USD)?


Depends how often the pointer is moved. According to the author’s Twitter at the time they were asked each move cost $18.69.


Sorry, I know my question depends on a lot of variables.

I’m just looking for a “sanity check” example, but I only have a vague notion of pointer being a reference to a spot in memory, as well as knowing that doing transactions on the ETH network incurs fees.

Are there any “power user” examples? Like, how much would it cost to run `ls` on a folder of 200 files, or encoding a video with `ffmpeg` (or insert proper example here since I don’t know where `unique_ptr` is used lol)


A lot :)

If you've ever programmed, imagine kinda-sorta one move per argument per time you call a function. Like `console.log(foo, bar)` would be two moves. (This isn't literally true, it over counts a bit). Ffmpeg would be in the tens of thousands of moves for encoding a short video, maybe? They don't use unique_ptr, so it's hard to do a counterfactual.

An imperfect analogy is this is like nails/screws when building a house.


> - void Seal::MakeSound() { std::cout << "Ow, ow, ow!" << std::endl; }


"As we all know, adding blockchain to a problem automatically makes it simple, transparent, and cryptographically secure."


And you thought memory management was expensive _before_!


Actually it's cheaper this way, because you can sell the NFT to fund the operation. Before, you had to pay for everything it ran on!


That's why everyone loves JavaScript so much. You don't have to pay for the electricity your code burns, your users do.


I wonder if it's possible to run a linux vm (ala jslinux) in browser, connect them to the network via a proxy to allow the apps inside the linux vm to make arbitrary connections (I think I saw a jslinux clone that uses some form of proxy to allow tcp access from inside the vm, but forgot the name), then run a kubernetes worker node in them. Then you can try to make the page viral somehow and then enjoy your huge and free kubernetes cluster!


I have a sinking suspicion that Facebook's Messenger webapp is doing exactly that - its UI has been very laggy for me in the past months, and the issue persists through refreshes, browser reboots and system reboots.

It's the only thing that makes sense. I mean, they couldn't have screwed up a chat client that badly...


They don't have the same depth of experience in developing chat apps as some other bay area companies.


It's a bit complictated, requiring npm and cargo and c++. But still, a "hello world" demonstration like this is very valuable. It wouldn't surprise me if real projects use this as a starting point.


This is the hardest I've laughed all year. Mad props to the author for poking fun while doing a very cool (and crazy) project.

Don't know why but the deadpan humor here really reminds me of reading Bill Bryson.


Technical side-note: Are NFTs free to create and/or use? Or do they require contribution of processing power and/or paying "the Network" for it using your own ETH?


Kind of, you can use a development network to which you can get free tokens to pay the gas fees.


People are regularly paying $75-$250USD in gas fees to mint individual NFTs


Making pointers on mainnet is expensive these days, I was able to stand up a Ganache testnet so that my pointers are created faster and at lower cost. Fantastic library.


I hope someone turns this into an NFT, to complete the circle.


> how to write a (trivial) program in Rust without fighting the borrow checker once

curiously apt, yet true...


This is great; now I feel like I have to rewrite programmerspoop.com in Rust to keep up.


The Andy Kaufman of programmers


It's thread-safe.


I logged into GitHub on mobile just to star this.


Technology gone berzerk.


Well yes, but it's a joke specifically making fun of that, so it's not really berserk itself.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: