THE JOURNEY TO BECOMING A WORLD-CLASS RUSTACEAN-1
I went the route of ignoring Rust, while being vocal about the EVM being sufficient, and even got into fiery arguments regarding EVM vs SVM and CosmWasm. Despite the inherent flaws the Ethereum Virtual Machine possesses, I believe — and still do — that a system built specifically for an ecosystem will remain the top platform in the long run, the platform of choice for any tangible protocol built in the space. Given how intensely I defended the EVM and Solidity, its partner in crime, you might think I was somehow related to Vitalik Buterin or a major shareholder in the Ethereum Foundation. But this love was cultivated during the lockdown in 2020, and the amazement I felt the first time I looked at a cluster of Solidity codes. To me, that was the most beautiful thing I had ever seen at the time, and in no time, I made a smooth transition from my Web2 background to writing Solidity code seamlessly. A reason that can't be overstated was the similarity between this new, shiny programming language and the JavaScript I was already accustomed to at the time. The transition seemed natural and was a massive factor for me, as well as for many others who would join the wave over the next couple of years. Love is a beautiful thing, as they say, and it is even better at first sight. Unfortunately, that was not the case when I first looked at the lines of code written in Rust, the primary language for Solana development. Unlike Solidity, it just seemed like a whole lot was going on, and it didn’t seem as readable as other languages I had prior experience in.
So, as much as I like to disagree, one of the factors that fueled my passionate defence of the EVM during those arguments was the reminder of how confused and dazed I was when I actually met Mr Rust. A proper WTF moment. I said to myself, Naa, there’s still a lot to learn about in Solidity: Account Abstraction, which I will be writing about soon, Assembly using Yul, and also Auditing. It’s not all doom and gloom, though, because to justify my flight from Rust, I actually went and learnt all these and got a level of mastery in each. But I always knew my flight from Rust was a case of me avoiding the inevitable. Given the meteoric rise of the language and its importance in not just Solana Virtual Machine development, but also as one of the two key languages in Ethereum Core Development, alongside Go, avoiding Rust was shaping up to be an unwise decision in the long run. Ethereum Core Development? What is that, and is it the same as the Ethereum Virtual Machine? Isn’t Solidity the language of choice for this? How does Rust come into this? Yes, these are questions I asked myself at a point in my journey, and I’ll break it down in the way I would have liked it to be explained to me then.
The Ethereum Virtual Machine is a protocol that facilitates the development of decentralised applications on the Ethereum Blockchain. Most cryptocurrencies, Decentralised Finance exchanges, and Decentralised Autonomous Organisations are built on top of this using Solidity and, in recent times, Vyper. Now, Ethereum Core Development involves the process of creating this virtual machine that the Ethereum Blockchain runs on, this same machine that serves as a launchpad for the various dApps in existence today. It involves defining consensus using codes, execution techniques, and the gas structure. In simpler terms, the EVM is the ground floor of a bungalow, which contains TVs, a Sofa, a Bed, Wardrobes, which we can liken to dApps. Then, the foundation of this lovely house is the ETH Core Protocol. The two primary programming languages used in this field are Go (also known as Golang) and Rust. The primary reason for this is its memory management and the way ownership is handled in both.
The EVM remains popular and the leading Web3 ecosystem, and I understand why some people might feel that there seems to be no reason actually to delve into Rust. There’s still a lot to build on the EVM, and a lot more to secure for those in the Security Research path. Well, I wouldn’t be so sure. Vitalik has proposed a seismic shift from EVM to a system with very high resemblance to the SVM by 2030, and there is a massive chance that this migration will demand the use of Rust for its programs. While he has stated that existing smart contracts written in Solidity will still be compatible, it signals a massive recalibration in the future of the Ethereum Blockchain. Why will Vitalik champion this move despite being one of the leading figures for the genesis of Solidity? Well, the answer lies in the limitations of Solidity and how these limitations compound vulnerabilities and reduce throughput. For example, the Ethereum Virtual Machine operates in a sequential mode of execution, meaning that a transaction must be executed before another. In contrast, the Solana Virtual Machine runs a parallel execution mode, which means that there is no such wait.
Rust isn’t perfect, but there are built-in features that make it secure and fast. The way the concepts of ownership, borrowing, and references work makes it ideal for use in building complex systems that require high throughput. This makes it suitable for building complex systems and execution clients that are crucial for Blockchain performance and speed. Admittedly, this results in a significant tradeoff that can make the learning curve steeper than that of most programming languages; the effects of this tradeoff were what struck fear into me during our first encounter. That’s the reason why a widespread belief exists about its high barrier to entry, especially among new developers. This is also a belief that I held onto during my EVM vs. COS-Wasm argument days. There might be some truth to this, but if there is anything that can contribute to the acceleration of learning and mastering tools in this ecosystem, it’s well-structured documentation that is free of overblown jargon. Luckily, the best documentation in the entire software engineering happens to be the one written to acclimatise new engineers to the Rust language. I’m talking about the Rust Book, and finding this resource tore down the wall I had put up regarding this path and demystified this language. The Rust Book not only educated me on Rust, but it also taught me important things that happened behind the scenes with other programming languages that I had previously claimed mastery of, things that I had no prior knowledge of. Examples included how memory is allocated and deallocated, Error handling, and also how some languages check for errors during Runtime, while some do this during Compilation.
Rust is a statically typed language, which means that it expects the variable type to be defined at compile time. This enhances speed and ensures that the compiler doesn’t have to manually check and identify the data type of variables fed to it. Some other examples of statically typed languages include Solidity, Go, Typescript, C, C++, and Java, amongst others. In contrast to statically typed languages, there exists another group of languages known as dynamically typed languages. These languages ensure that type checking takes place during runtime, and they include JavaScript, PHP, Python, and others. Rust uniquely handles memory allocation, and different data types are stored in distinct locations according to their nature. Fixed-size variables are stored on the Stack, while variables that can have their size increased are stored on the Heap. The last storage destination is the Static memory, and this is usually reserved for String Literals. Variables are handled based on where they are stored, and this is a crucial element of Rust that serves as the foundation for all other aspects of the language. And we’ll be looking into this in depth in the following chapters. Rust can be very strict in enforcing its rules and ensuring that invariants are not broken, which can hinder functionalities in exceptional cases and protocols. To address this, an alternative called
Unsafe Rust is available. In this case, the developer agrees to bypass the safety features of Rust and take full responsibility for any issues that might arise as a result of this. To fully understand what Unsafe Rust entails, it is important to understand why the Standard Rust is considered Safe, so we will delve into Unsafe after gaining a measure of comprehension about the basics of Safe Rust.
This is the first entry in a series of in-depth insights into this language. I'll be sharing my findings and the intricacies that set this language apart from the rest. I’ll be comparing the data types and components that exist in the languages I’m previously familiar with, and how similar or different they are in Rust. After a certain degree of mastery in the Fundamentals of Rust, I will explore the world of the SVM and how Rust is utilised to write smart contracts that run on Solana. Finally, to conclude this introductory Chapter, it is only proper that we adhere to the law and showcase how the infamous “Hello World” would be written in Rust.
fn main() {
println!("Hello World");
}