This month, with Secret Network upgrading their main net with secret contracts, it seems like a good opportunity to explore Rust blockchains that are using a completely different privacy-preserving technology: secure enclaves. Rustblockchain development continued at its typical blistering pace, and again it’s impossible to follow everything going on.
This month we see continued advancement in zero-knowledge computing, an obvious focus from the entire blockchain industry on the Devi phenomenon, and new hackathons with opportunities for Rust developers. This month, we’re seeing a bunch of interesting Rustblockchain and crypto projects.
Along with NEAR, Nervous, and Enigma (and probably others), this continues an encouraging trend of blockchains enabling smart contracts in Rust. A beginner-friendly tutorial on how to build hardcore blockchain infrastructure in Substrate, an open source framework.
This is where your bank account has a total balance that gets credited or debited per transaction. Bitcoin offers a fundamentally different ledger model called To, or Unspent Transaction Outputs.
In other words, the spending permission is tied to the money, not an account number. Cryptography is the underlying mechanism that allows only Bob, and not anyone else, to spend his Utmost.
This has the benefit of locking in the transaction output details, to prevent network level tampering. Later on, the blockchain will verify that Alice did indeed authorize all the details of this entire transaction.
Substrate is Rust based and compiles to a binary instruction format called Web Assembly (Was). Out of the box, you get core blockchain components like a distributed database, a peer-to-peer networking layer, and various consensus mechanisms we can choose from.
Open up the project in your favorite Rust compatible IDE. File, which is where you’ll build most of your Bitcoin To logic.
Create the transaction signatures that will allow users of your Bitcoin blockchain to spend Utmost. Note, we'll be implementing a few helper functions for this spend transaction logic shortly.
Note, in step 2, you are already emitting this event after every successful spend transaction. In this section, we’ll get into the cryptographic security of our chain and implement To transaction logic.
This function builds a genesis storage key/value store according to the code we wrote back in step 1 during In this section, you’ll change how your network prioritizes incoming transactions & handles an annoying To race condition that Bitcoin experiences.
Nodes that heard from Bob but not from Alice yet, will reject his transaction since To B doesn’t yet exist in their blockchain state. But Bob’s transaction IS valid, so this error due to this race condition is not ideal.
Ideally, we can queue up valid transactions a network pool and wait until prerequisite conditions are satisfied. Luckily Substrate enables a single API call for you to change transaction ordering logic.
The transaction pool will hold on to race-UTXOs until this condition is satisfied for a certain period of time. Function, append the following configuration to set up your test net with seed data / Utmost.
For a more detailed walkthrough & line-by-line explanation of the above, check out this final part of the video accompaniment. In this tutorial, you learned how to change the underlying ledger model and built a Bitcoin chain on Substrate.
Read my stories Building data privacy @Paritytech. Tags Join Hacker Noon Create your free account to unlock your custom reading experience.
It is known as a “safe, concurrent, practical language.” It’s similar to C++, but has better memory safety while still maintaining its performance. This is a “singly-linked list” In blockchain, the pointer is the hash of the header of the proceeding block.
Cryptographic hash functions put the Crypto in front of Cryptocurrency. This does not reflect the best practices of Rust by splitting up your file into many small parts (modularization).
They have headers with an array of 32 bytes (for the 256-bit SHA-256 hash algorithm), time, and body. We also have to make it so that we can reate a new block, and set its prev_block_hash to the hash of the headers of for our blockchain.
They all compete to be the first one in the network to find a hash with a numeric value that is lower than the “target”. If it isn’t, make the nonce one value higher (this changes the header), and run the hashing function again until it (or some other miner) finds the hash that wins.
To control the number of new blocks made per minute, if there’s a boost in hashing power, the difficulty can be raised to slow this down and vice versa. This method uses the num-bigint for taking care larger numbers It uses bit-wise logical operations to make a target Each hex digit will encode 4-bits, so we multiply DIFFICULTY by 4.
It takes in the headers, adds the nonce, proceeds in hashing. Let’s update our function to perform the hashing when new blocks are made.
In a true, properly set up Rust “crate”, this represents main.rs file. We parse (go through) and print the blockchain ’s contents in a pretty way.