
{"id":41214,"date":"2025-02-03T11:25:15","date_gmt":"2025-02-03T11:25:15","guid":{"rendered":"https:\/\/mycryptomania.com\/?p=41214"},"modified":"2025-02-03T11:25:15","modified_gmt":"2025-02-03T11:25:15","slug":"rust-for-blockchain","status":"publish","type":"post","link":"https:\/\/mycryptomania.com\/?p=41214","title":{"rendered":"Rust for Blockchain"},"content":{"rendered":"<h4>Why Rust are the most used (Popular) Programming Language in Blockchain\u00a0?<\/h4>\n<h3>What Programming Language for Blockchain<\/h3>\n<p>So what does a programming language for blockchain actually mean\u00a0?<\/p>\n<p>The number one, would be <strong>writing web front ends for like Web3 apps or DeFi apps<\/strong> or something like that, that\u2019s <strong>NOT where Rust is popular these days<\/strong>. So you see a lot of <strong>JavaScript there has eaten the world<\/strong> and it\u2019s just ubiquitous because it\u2019s ubiquitous it\u2019s so popular for every anything running in a web\u00a0browser.The second thing, where a programming language comes into play with blockchain is writing <strong>the actual code of the blockchain validators. <\/strong>So that means the code that\u2019s <strong>running on a smart contract \/ blockchain is executed by so many validators and the software for that validator that needs to be written somehow and Rust is popular in that field<\/strong> so that was number\u00a0two.The number three, is <strong>writing the actual smart contracts<\/strong>, so writing <strong>the Dapps (decentralized apps) that run on top of a smart contract blockchain there you need a programming language as well<\/strong> and <strong>Rust is gaining a lot of traction in that field<\/strong> as\u00a0well.<\/p>\n<h4>Explaination why blockchain need validators.<\/h4>\n<p>So what\u2019s a blockchain, it means it\u2019s something that\u2019s not 100% centralized, so you have lots of validators that validate transactions, so blocks are being produced by someone who gets lucky and gets to produce a block at a certain point in time, but then there\u2019s others that witness that and validate that block, and there is so many validators it could be, just tens of validators in like highly centralized blockchains such as BSC, but it can be thousands of validators in highly decentralized blockchains such as Solana, which has one of the highest Nakamoto coefficients in the industry, the Nakamoto coefficient is measuring the decentralization of a blockchain, but also other blockchains have High degrees of decentralization.<\/p>\n<h3>Why Rust than other Programming Language<\/h3>\n<p>So let\u2019s talk about why Rust, and what are actually the features, what\u2019s different with Rust than with other programming languages.<\/p>\n<h4><em>The Validator Concerns<\/em><\/h4>\n<p>If you think about that validator software and the smart contract software and you remember that blockchains are about potentially thousands of validators, running the same code over and over again just to validate that though the one validator that produced the block has done the right thing, so all the others need to replay that and execute the same code just in order to validate\u00a0it.<\/p>\n<p>So if we think about with a lot of validator,The <strong><em>performance<\/em><\/strong> is really important in blockchain.<\/p>\n<h4><em>The Scaling\u00a0Concerns<\/em><\/h4>\n<p>And then if you also think about blockchain\u2019s vision, the public blockchains are there to make a meaningful change to society and get the world away from that centralized Winner Takes all kind of mode to a more community-owned Community controlled owner our own data mode which the blockchain stands for, if we want to make that meaningful change to society, we have to get a lot of people and eventually billions of people get on board with the blockchain. That means the blockchain needs to scale, there\u2019s no point in something that can do a hundred transactions per second and then you have to Silo it into layer twos with ZK proofs and stuff like that, which are great things, but they are not kind of that worldwide scaling in just one layer and Global price Discovery and stuff like that we want to\u00a0do.<\/p>\n<p>So if we want to scale that whole\u00a0thingThat means both the code and the validator and also the code in the smart contracts, they need to be\u00a0fast.<\/p>\n<p>So that means having like interpreted programming languages and even if they have just-in-time compilers and stuff, it\u2019s probably not the right\u00a0choice.<\/p>\n<p>You want to have a programming language that\u2019s close enough to the hardware to be as fast as possible.So that\u2019s where Rust comes into\u00a0play.<\/p>\n<h4><em>The Programming Safety\u00a0Concerns<\/em><\/h4>\n<p>If you think of Hardware programming close to the hardware other languages such as C or C++ come to mind as well, Rust is kind of a modern version of these C or C++ things, and it has an additional feature or that\u2019s called <strong>Safety<\/strong>, so all the problems that there have been classically a lot of problems with C and C++ programs called memory leaks, so that means you allocate some memory then the programmer forgets to de-allocate it, and frankly it is tough to get the code correct that in all circumstances and in all branches that the code executes you do the right thing, and properly deallocate what you\u2019ve allocated before and stuff like that, and these memory leaks are just crazy stuff most of the time, they are to blame when you need to reboot your PC or something because some and in modern operating systems of course it has been greatly reduced but I think 10\u201320 years back with Windows and everything, it crashed all the time just because the apps had memory leaks and we cannot afford that in a blockchain.<\/p>\n<p>It has to the blockchain has to be a 100% reliable, we don\u2019t want it down or anything like\u00a0that.So it has to be a safe programming language, and it has to be safe in concurrency mode as\u00a0well.<\/p>\n<h4><em>The Concurrency and Pararellism<\/em><\/h4>\n<p>So if we do things in parallel and if we want to scale, we need to do things in parallel, we cannot just do one thing after the other we have to do as many things in parallel as we can in order to make that whole thing scalable but when things run concurrently,<\/p>\n<p>And by the way there\u2019s a subtle difference between concurrency and parallelism,<\/p>\n<p>So parallel means we have different Hardware that actually runs in real parallel.And concurrency, just means it seems like it\u2019s in parallel but under the hood it\u2019s kind of time sliced, so we only have one piece of one several\u00a0threads.<\/p>\n<p>But whether it\u2019s concurrency or whether it\u2019s parallelism, it is hard to write code that is safe, when it\u2019s comes to concurrency, Rust helps there, and it is tough to write code in Rust that is not time Save, so that\u2019s a great advantage of Rust, which many blockchain developers feel attracted to, you need that safe code that also runs safely in concurrent environments you needed performant.<\/p>\n<p>And there is one feature that is quite unique, if you get all these three performance, and then safety, and concurrent environments, and then number three is not having a garbage collection.<\/p>\n<h4>The Garbage Collection<\/h4>\n<p>So all these there are so many other programming languages that want to avoid those memory leaks that I talked about in the beginning of this video, and in order to avoid the memory leaks like the programming language manages the memory itself, so you the programmer doesn\u2019t have to allocate the memory himself and then or herself obviously and deallocate it.<\/p>\n<p>The programming language does it for them, but then there might be variables or data in memory that becomes unusable, just has aged and it\u2019s not accessible anymore in the code anyway, so it can be deleted, so then these programming languages let the memory run full and when the memory threatens to come under pressure, they stop the world right they stop all your program that the developer has developed, and then they run a garbage collection trying to find pieces in memory that are not needed anymore, and can be disposed of and they stopped the world, it\u2019s kind of unacceptable in anything that\u2019s close to real-time environments, not saying that blockchains are necessarily always real-time applications, but garbage collection doesn\u2019t work in real time, that garbage collection also is not really advantageous in blockchain environments, because you want some predictability.<\/p>\n<p>Think about the block times or slot times in Solana which is 400 milliseconds, it\u2019s just 0.4 seconds, it\u2019s like boom boom boom, every garbage collection and we never know in advance how long the garbage collection takes right it can take 40 milliseconds, but in some cases it can take 2 seconds, and that\u2019s not what we\u00a0want.<\/p>\n<p>So if we want a programming language that\u2019s fast, because it\u2019s close to the hardware, it needs to be compiled, it needs to be type safe, it needs to be safe, with regards to concurrency, and have no garbage collection, then the air gets really-really thin.<\/p>\n<p>Try to figure it out, you can do C or C++ Assembly Language, which all of them are low level older languages, that all have their advantages but also they don\u2019t feel modern, and having modern C++ is it has so many issues and just writing everything in C is really low level, you don\u2019t have high level constructs or stuff like\u00a0that.<\/p>\n<p>So I think Rust is kind of the only choice and there is another programming language emerging right now that\u2019s built on top of Rust, it\u2019s called\u00a0Move.<\/p>\n<h4><em>Rust Family of Languages<\/em><\/h4>\n<p>It\u2019s the Move language and that\u2019s just built as kind of a subset of Rust and has some special features, that make these Move semantics that originated in Rust, Rust has the Move semantics, so you Move ownership of of a block of memory of a variable from one place to the others, just to make sure that there is no shared ownership, and then you have a concurrency conflict, that\u2019s going to be avoided, so that\u2019s <strong>why Rust came up with these this unique Move semantics.<\/strong><\/p>\n<p>And that\u2019s taken to the extreme in that programming language called Move it\u2019s being adopted by some modern blockchains, such as <strong>Aptos<\/strong> or <strong>Sui<\/strong>, so that\u2019s also a great language, it\u2019s also supported by Solana recently, so you can write smart contracts in Move, but I would consider that kind, like kind of the rust family of languages.<\/p>\n<h3>Summary<\/h3>\n<p>Rust is programming language that\u2019s fast, because it\u2019s close to the hardware, it\u2019s compiled, it\u2019s type safe, it\u2019s safe with regards to concurrency, and have no garbage collection, then the air gets really-really thin. So that was my little overview on why Rust is so popular in the blockchain community.<\/p>\n<p>References:<\/p>\n<p>Youtube: <a href=\"https:\/\/www.youtube.com\/watch?v=qT_pvH4UoK8\">The Rust language is popular in crypto. But why tho?\u200a\u2014\u200aBlockchain Bernie<\/a><\/p>\n<p><a href=\"https:\/\/medium.com\/coinmonks\/rust-for-blockchain-916dee623e87\">Rust for Blockchain<\/a> was originally published in <a href=\"https:\/\/medium.com\/coinmonks\">Coinmonks<\/a> on Medium, where people are continuing the conversation by highlighting and responding to this story.<\/p>","protected":false},"excerpt":{"rendered":"<p>Why Rust are the most used (Popular) Programming Language in Blockchain\u00a0? What Programming Language for Blockchain So what does a programming language for blockchain actually mean\u00a0? The number one, would be writing web front ends for like Web3 apps or DeFi apps or something like that, that\u2019s NOT where Rust is popular these days. So [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-41214","post","type-post","status-publish","format-standard","hentry","category-interesting"],"_links":{"self":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts\/41214"}],"collection":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=41214"}],"version-history":[{"count":0,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts\/41214\/revisions"}],"wp:attachment":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=41214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=41214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=41214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}