• Stars
    star
    1,957
  • Rank 23,689 (Top 0.5 %)
  • Language
    Rust
  • Created over 3 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C++ `std::unique_ptr` that represents each object as an NFT on the Ethereum blockchain

C++ std::unique_ptr that represents each object as an NFT on the Ethereum blockchain.

Build nft_ptr Follow us: worthdoingbadly.com | @zhuowei | @[email protected]

Example: moving between two nft_ptrs

  auto ptr1 = make_nft<Cow>();
  nft_ptr<Animal> ptr2;

  ptr2 = std::move(ptr1);

This transfers the Non-Fungible Token 0x7faa4bc09c90, representing the Cow's memory address, from ptr1 (OpenSea, Etherscan) to ptr2 (OpenSea, Etherscan).

screenshot of OpenSea Trading History showing token transfer

[2021-04-09T01:59:48Z INFO  nft_ptr_lib] Transferring 0x7faa4bc09c90 (Cow) to 0x7ffee35a7890 (0x1564b0a7c258fc88a96aa9fe1c513101883abb13) from 0x7ffee35a78a8 (0x9ed6006c6f3bb20737bdbe88cc6aa0de00597fef) at PC=0x10c65a946 (main (example.cpp:33))
[2021-04-09T02:00:15Z INFO  nft_ptr_lib] Transaction: 0xcbe06fdd54bd9d221993c875022fe2960128874811a25075d692cc638a28f290
[2021-04-09T02:00:15Z INFO  nft_ptr_lib] https://testnets.opensea.io/assets/goerli/0x90eaf0ab2c6455a9b794f9dcf97839fa25b4ce2d/0x7faa4bc09c90

After the transfer, ptr1 is set to null, and ptr2 contains the new object, just like std::unique_ptr:

  std::cout << "Moved: ptr1 = " << ptr1.get() << " ptr2 = " << ptr2.get()
            << std::endl;
  ptr2->MakeNoise();
  Moved: ptr1 = 0x0 ptr2 = 0x7faa4bc09c90
  Moo!

Example: constructing an nft_ptr and minting an NFT

  auto ptr1 = make_nft<Cow>();

This:

  • initializes the nft_ptr runtime
  • creates the first nft_ptr<Cow>
  • transfers ownership of the newly created Cow* to the nft_ptr

First, it creates an ERC-721 smart contract that represents each memory address as a Non-Fungible Token.

[2021-04-09T01:57:48Z INFO  nft_ptr_lib] Connected to network id 5
[2021-04-09T01:57:48Z INFO  nft_ptr_lib] Account: 0xd54b39c6bb7774aba2be4b49dc2667332b737909
[2021-04-09T01:57:48Z INFO  nft_ptr_lib] https://goerli.etherscan.io/address/0xd54b39c6bb7774aba2be4b49dc2667332b737909
[2021-04-09T01:57:48Z INFO  nft_ptr_lib] Deploying NFT contract!
[2021-04-09T01:58:18Z INFO  nft_ptr_lib] Token contract deployed at 0x90eaf0ab2c6455a9b794f9dcf97839fa25b4ce2d
[2021-04-09T01:58:18Z INFO  nft_ptr_lib] https://goerli.etherscan.io/token/0x90eaf0ab2c6455a9b794f9dcf97839fa25b4ce2d

Next, it creates another smart contract, that represents the nft_ptr<Cow> instance which can own NftPtr tokens:

[2021-04-09T01:58:18Z INFO  nft_ptr_lib] Deploying contract for nft_ptr 7ffee35a78a8 Cow main (example.cpp:25)
[2021-04-09T01:58:48Z INFO  nft_ptr_lib] Deployed contract for nft_ptr 7ffee35a78a8 Cow main (example.cpp:25) at 0x9ed6006c6f3bb20737bdbe88cc6aa0de00597fef
[2021-04-09T01:58:48Z INFO  nft_ptr_lib] https://goerli.etherscan.io/token/0x9ed6006c6f3bb20737bdbe88cc6aa0de00597fef

Finally, it calls new Cow(), and mints an NFT for this memory address, owned by the new nft_ptr<Cow>.

[2021-04-09T01:58:48Z INFO  nft_ptr_lib] Transferring 0x7faa4bc09c90 (Cow) to 0x7ffee35a78a8 (0x9ed6006c6f3bb20737bdbe88cc6aa0de00597fef) from 0x0 (0xd54b39c6bb7774aba2be4b49dc2667332b737909) at PC=0x10c65a76f (main (example.cpp:25))
[2021-04-09T01:59:18Z INFO  nft_ptr_lib] Transaction: 0x0a148cee1abe8d4b5721996ea3a107c87b526ded155dc2e3895f1f42983bd2e8
[2021-04-09T01:59:18Z INFO  nft_ptr_lib] https://testnets.opensea.io/assets/goerli/0x90eaf0ab2c6455a9b794f9dcf97839fa25b4ce2d/0x7faa4bc09c90

More examples

A full example program can be found at example/example.cpp, along with a sample of its output when run.

A longer example, which shows using nft_ptr with function calls and STL containers, can be found at example/long_example.cpp along with its output.

Why?

  • Biggest issue facing $125 billion security industry: Memory safety.

  • The world's largest codebases are written in C++

    • Browsers, operating systems, databases, financial systems
  • C++ memory management is hard to understand, opaque, and not secure

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

  • Thus, we extend std::unique_ptr, the most popular C++ smart pointer used for memory management, with blockchain support

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

    • each token/object is unique, not fungible with other tokens/objects
    • each token/object is owned by one owner/unique_ptr
    • 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
  • Written in Rust for the hipster cred.

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

For more information, please read our white paper.

Performance

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

What works

  • Deploying ERC-721 smart contract on program start
  • Create smart contract for each nft_ptr instance
  • Call smart contract to create token when a pointer is transferred into an nft_ptr
  • Transfer token when pointer moved between nft_ptrs

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.

Obligatory system diagrams

How we call from C++ to Rust to Solidity:

+-----+              +------+              +--------+        +---------------+
|     |  extern "C"  |      |  rust-web3   |        |        |               |
| C++ +------------->| Rust +------------->| Wallet +------->| NFT Contracts |
|     |              |      |              |        |        |               |
+-----+              +------+              +--------+        +---------------+

How the NftPtrToken contract and the NftPtrOwner contracts interact:

+-------------+          +-------------------+
| NftPtrToken |          | NftPtrOwner       |
|             | Owns     |                   |
| 0x41414141<--+---------+ nft_ptr<Animal>   |
|             |          +-------------------+
|             |
|             | Owns     +-------------------+
| 0x42424242<--+---------+ NftPtrOwner       |
|             |          |                   |
|             |          | nft_ptr<Animal>   |
| (1 instance |          +-------------------+
| per program)|          ...
|             |
+-------------+       (1 instance per nft_ptr)

Sponsor development

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).

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.

What I learned

  • 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

Building

All instructions tested on macOS 11.2.1.

You need:

cd contracts
npm install
truffle compile
./dumpbytecode
cd ../impl
rustup override set nightly
cargo build
cd ../example
./build.sh

Testing (local blockchain)

Download and run Ganache to setup a private local blockchain. Then, run

cd example
RUST_BACKTRACE=1 RUST_LOG=info ./example

Testing (Görli testnet)

To run this against a public test blockchain, the easiest way is to use a hosted node.

Create a new keystore file on MyEtherWallet and get some Görli test ethers from the Görli faucet.

Do not use an existing wallet or password! nft_ptr is very insecure; do not re-use a wallet or a password you care about, even for these worthless fake test ethers.

Run the example using your new keystore and a hosted node:

RUST_BACKTRACE=1 RUST_LOG=info NFT_PTR_HTTP="https://nodes.mewapi.io/rpc/goerli" \
NFT_PTR_NUM_CONFIRMATIONS=1 \
NFT_PTR_KEYSTORE="/path/to/your/MewWallet.keystore" \
NFT_PTR_PASSWORD="sample password" \
exec ./example

Testing (Görli testnet + local lite node)

You can also run the example against a local lite node.

Download Geth and start a lite node connected to the Görli testnet:

./geth --goerli --syncmode light

Stop Geth and import your testnet wallet:

cp ~/Downloads/MewWallet.keystore ~/Library/Ethereum/goerli/keystore/

Restart Geth and unlock your testnet wallet: This is insecure!

./geth --goerli --syncmode light --unlock 0x<address> --http --allow-insecure-unlock

Enter your password, then hit Enter. It should say

Unlocked account                         address=0x<address>

Finally run with local HTTP transport:

cd example
./run.sh

More Repositories

1

MCPELauncher

Source code for BlockLauncher, a launcher that patches Minecraft for Android
Java
654
star
2

WDBRemoveThreeAppLimit

Objective-C
510
star
3

MacDirtyCowDemo

Get root on macOS 13.0.1 with CVE-2022-46689 (macOS equivalent of the Dirty Cow bug), using the testcase extracted from Apple's XNU source.
C
366
star
4

VisionOSStereoScreenshots

Take 3D stereoscopic screenshots in the visionOS emulator.
M
340
star
5

Boardwalk

Source code for Boardwalk, a Minecraft Java Edition launcher for Android (not actively developed)
Java
339
star
6

RaspberryJuice

A plugin for Bukkit implementing the Minecraft Pi API
Java
326
star
7

MarzipanTool

Tools for running iOSMac apps on macOS 10.14 Beta
Python
286
star
8

Xenologer

#notglass #untilnow
Shell
264
star
9

DSReality

Swift
249
star
10

marina

Understanding SwiftUI by reimplementing it to render to HTML ⛵ - you shouldn't use this, use https://github.com/swiftwebui/SwiftWebUI instead
Swift
243
star
11

ClubhouseAPI

119
star
12

HvDecompile

Decompiling macOS Hypervisor.framework by hand
Objective-C
113
star
13

hipster.house

HTML
102
star
14

CoreTrustDemo

Proof-of-concept for CVE-2022-26766 on macOS 12.3.1
C
80
star
15

MetalShaderTools

Tools and samples for understanding Apple's Metal shading language and its LLVM Bitcode shader files
LLVM
72
star
16

XNUQEMUScripts

Some scripts I made to patch iOS device trees.
Java
59
star
17

worthdoingbadly.com

My blog where I make a new coding project every Thursday.
HTML
45
star
18

PocketInvEditor

A inventory editor for Minecraft PE on Android
Java
45
star
19

MemojiCatalyst

iOS Memoji editor ported to run on macOS through Catalyst
Objective-C
45
star
20

ryujinx-ios

NOTHING USEFUL HERE; trying to see if Ryujinx's new Apple Silicon port would also runs on iOS
Swift
44
star
21

dsc_extractor_badly

Modifications to Apple's dsc_extractor to fix ObjC selector names. You don't need this.
C++
42
star
22

iOS-run-macOS-executables-tools

Failed experiment for running command line macOS tools on jailbroken iOS. There's nothing useful here.
C
39
star
23

ModPEScripts

A collection of scripts for the ModPE Script Runtime used to modify Minecraft PE
JavaScript
38
star
24

PCICrash

PCIDriverKit proof-of-concept for CVE-2022-26763
Objective-C
38
star
25

MCPELauncher-addons

Addons by myself aka 500 Internal Server Error
C++
29
star
26

GhidraLog4Shell

Java
27
star
27

DisneyPlusMetadataDownloader

pulls metadata from Disney+. Probably useless for you.
Python
25
star
28

MinecraftPEModWiki

Shell
23
star
29

Varodahn

Some code to experiment with Steam In-Home Streaming
Java
21
star
30

LearningIOSurfaceAccelerator

Learning how to use IOSurfaceAccelerator
Swift
21
star
31

SimServerAndroid

Gets SIM card ICCID/runs 3G Authentication over ADB shell
Java
21
star
32

iOSAvatarUITester

Example for using iOS's private frameworks to create Animoji/Memoji in an app
Objective-C
21
star
33

UnleashTheGoogle

DOESN'T WORK ANYMORE: Enables Dogfooding and Team Debug features of Google Search for Android
Java
20
star
34

loljava

Demonstration of the Java System.arraycopy type confusion vulnerability
Java
20
star
35

macOS-Virtualization-framework-tools

Useless tools for exploring Virtualization.framework
Objective-C
20
star
36

WDBDDISSH

DOESN'T WORK YET, PLEASE IGNORE
Shell
17
star
37

NUS-Downloader-WiiU

C#
16
star
38

VirtualizationDemo

demoing Virtualization.framework changes in macOS 12 beta
Swift
16
star
39

SimServeriOS

Runs SIM-AKA Authentication on a jailbroken iPhone for VoLTE/VoWiFi/IMS research. Exposes a http interface compatible with fasferraz/USIM-https-server
Objective-C
16
star
40

PocketInvEditor-app

The free version of PocketInvEditor. Requires the PocketInvEditor library project.
Java
16
star
41

SwitchBrowserUnlock

Unlocking the Nintendo Switch's hidden browser. Set DNS to 104.236.216.051.
15
star
42

TweetbotLoginProxy

JavaScript
15
star
43

libcorkscrew-ndk

Libcorkscrew (a stack trace printer from Android source) modified to build on the Android NDK
C
15
star
44

DecryptAppBadly

A terrible iOS app decryptor for jailbroken devices
Objective-C
14
star
45

MCPELauncher-app

This is the part that actually builds an APK for MCPELauncher
Java
14
star
46

BleachThisCode

Obfuscates C/C++ programs by replacing everything with whitespace and #define's
C++
13
star
47

wiiu-tools

Ambulance!
Python
12
star
48

FakeHVF

Useless learning project: simulates Hypervisor.framework APIs on top of Linux KVM
C
11
star
49

is_like_a

"more than just a simple ebooks bot." - @mralext20
Ruby
11
star
50

myglasscatfacts

An example for using the Google Glass MyGlass API
Java
10
star
51

nexus7-baremetal

Baremetal development for the Nexus 7 2012 (Grouper) and Nexus 6P (Angler)
C
10
star
52

NotifyTooth

A tool to forward notifications to Google Glass from a tethered phone.
Java
10
star
53

actions-on-google-php

Prototyping an AI Chatbot for Google Assistant for Google Home using the Actions on Google API in PHP
PHP
10
star
54

UnixTalkToInstagramProxy

A proxy to allow browsing Instagram with the Unix `talk` command. Inspired by alt text of https://xkcd.com/1810/.
Java
8
star
55

ClickFast

Android app that tricks a user into clicking a button
Java
8
star
56

scanmediaplz

Forces the Android media scanner to run
Java
8
star
57

Piplup

WIP: decompile Playdate Pulp .pdx files back to .json project files
JavaScript
7
star
58

arctic

NO LONGER WORKS THIS IS NOW USELESS DON'T BOTHER DOWNLOADING
Java
7
star
59

nyandroid-daydream

An Android daydream based on the Nyandroid easter egg from Android 4.0
Java
7
star
60

PocketMine-BLScriptEnable

Sends the enable ModPE script command to connected BlockLauncher clients
PHP
7
star
61

HackerTyper

A clone of duiker101's Hacker-Typer
C
7
star
62

MacUptimeChanger

Changes the result of macOS's `uptime` command with a kernel extension
C
6
star
63

fake-arm-macOS-sdk

Obsolete: Xcode 12 Beta's out now. -- Script that modifies Xcode 11’s macOS SDK to build for ARM
Shell
6
star
64

YoutubePlaysEverything

Twitch Plays Everything knockoff for YouTube Gaming
Python
6
star
65

PillAppSwitcher

Android app that demonstrates retrieving recent tasks through adb shell
Java
6
star
66

FFMPEGShortcutsApp

A Siri Shortcut extension that uses FFMPEG to convert an audio file into a .wav
Swift
6
star
67

Xenologer-src-glasshome

GlassHome.apk
6
star
68

vectordrawable

Backported VectorDrawable from Android 5.0 Lollipop to Android 4.1; used in Nyandroid
Java
5
star
69

Chromosphere

A launcher for Corona based games
Java
5
star
70

Colmena

No longer works. Attempt at making a web U( for Hive Social using Mastodon's web UI as a base.
HTML
5
star
71

Flappy2048

Flappy bird and 2048 at the same time
JavaScript
4
star
72

FancyTwitterNames

JavaScript
4
star
73

CompRemote-server

The server for CompRemote lite
Java
4
star
74

design

Zhuowei Zhang's design portfolio
CSS
4
star
75

MinecraftClassicDeobfuscate

Don't bother with this branch - use Steveice10's fork at https://github.com/Steveice10/MinecraftClassicDeobfuscate
Shell
4
star
76

zhuowei.github.com

HTML
4
star
77

Fait

Currently just code to interact with iOS's Lockdownd
Go
3
star
78

addongen

JavaScript
3
star
79

BitcodeEvaluation

App that dumps its own main executable, for comparing differences between original and Bitcode built code
Objective-C
3
star
80

Ironsand

Notes on testing VirtualBox's DevPlayground virtual device plugin sample on macOS
C++
3
star
81

AMDPSP_Extract

Extract AMD Secure Processor components from a BIOS image
Python
3
star
82

my-vscode-macros

My personal vscode macros used with exceedsystem/vscode-macros
JavaScript
3
star
83

unnamedL

The unnamed Android L SDK port for Nexus 7 (2012): build tools
Shell
3
star
84

CompRemote-client

The sources for CompRemote lite, a Blackberry PlayBook app
ActionScript
3
star
85

MCPIScripts

A collection of scripts for Minecraft Pi
JavaScript
3
star
86

mcpetexturenames

JavaScript
3
star
87

Mercator

Java
3
star
88

trippyvideo

JavaScript
3
star
89

AGXShaderExplorer

Objective-C
3
star
90

m3exploration

Generating adversarial avatars for m3inference with PyTorch and Foolbox
Python
3
star
91

Xenologer-src-glasssetup

Modified APKTool dump of GlassSetup.apk. Prebuilt APKs at the main Xenologer repo.
3
star
92

Keybored

Android keyboard that sends keypresses from a PC on Wi-Fi to the phone
Java
2
star
93

as3craft-classic

ActionScript
2
star
94

Xenologer-util-recolada

Sets up the Bluetooth identity socket to allow MyGlass to work
Java
2
star
95

Nyastrocat

Astrocade + Nyancat
Assembly
2
star
96

PTPatchUpdater

Java
2
star
97

MC-Android-Patch

Java
2
star
98

SGX5Dec

Useless
Python
2
star
99

MemeMaker

Image macro generator for the Apple Watch
Swift
2
star
100

Xenologer-src-glasscamera

GlassCamera.apk
2
star