Web3 - The Technical Details
This is part 5 of my series, The Black Purposes of Web3, where I post my undergraduate thesis in sections. Read the series intro.
This post corresponds to the technical section ("Technical Details") of chapter 4 ("Web3: The Values, the Tech, and the Media"). It is the most technical in the series and is adapted very closely from my thesis. I've maintained the technical depth because I believe understanding how Web3 works is important for evaluating its claims.
Now that we've covered what Web3 promises, let's look at how it actually works. This gets into blockchain technology, smart contracts, and the architecture of decentralized applications.
The Blockchain
The principle of trustlessness associated with Web3 lies in the blockchain technology it is built on. A blockchain is an immutable, decentralized, distributed ledger of transactions that requires community consensus to validate each transaction. More specifically, the data structure "maintains a list of transactions that are authenticated using public key cryptography and linked using a hash function."[1]
Blockchains are essentially linked lists of blocks, which contain transactional information, that use hash pointers between blocks rather than regular pointers found in typical linked lists.[2] Each block contains a header, which is where the hash pointer is actually found, and some data, which is where the transactions are stored. A hash pointer is the cryptographic hash of the block's entire parent, or the block that was added to the chain immediately prior to any given block. The "chain" of blocks is formed as each block contains a hash pointer to its parent, so they are linked together.[3] Because each block contains a hash pointer to its parent block, and that hash pointer itself is a hash of all of the parent block's data, blockchains are tamper-evident.[2] If someone tried to manipulate the data of a block, it would be apparent to other peers on the network who can validate the data of any block using the hash pointer to the most recent block. When the data of one block changes, the cryptographic hash of each block after it changes, so changes in data are traceable and transparent.
Tamper-evidence and hash pointers are important for the consensus protocols used on different blockchains to create the decentralized ledger. One example of a consensus protocol is the Proof of Work (PoW) algorithm, used on the Bitcoin blockchain. Satoshi Nakamoto is the pseudonym for the creator or creators of Bitcoin who proposed using a combination of the PoW algorithm and the longest chain rule, now commonly known as the Nakamoto consensus.[4]
As Nakamoto defined, "proof-of-work involves scanning for a value that when hashed, such as with SHA-256, the hash begins with a number of zero bits."[5] This requires a certain amount of "work," or CPU computing power, to create this value that can be verified by executing a hash computation, and the amount of work needed increases exponentially with the number of 0 bits required.[5] PoW is implemented by maintaining a nonce value in each block that is incremented until the block's hash value satisfies the requirements of the target value. Since the target value requires a specific amount of zero bits, a significant amount of computational power is needed to try enough nonce values to satisfy this hash puzzle. Once someone finds the value that satisfies the puzzle, the nonce serves as the "proof of work."[4] After the correct nonce and value have been found, if someone wanted to change the block, they would have to redo the work to find another nonce that satisfies the puzzle, because changing the data of a block changes its hash. Furthermore, all of the work for the previous blocks would have to be completed again as well just to change one block.
In addition, the Nakamoto consensus is based on the idea that the longest chain of blocks in the chain represents the most amount of computational work done, since it required the highest number of hash puzzles to be solved. In this way, the longest chain represents the majority decision of the network as a method of arriving at consensus, because "if a majority of CPU power is controlled by honest nodes, the honest chain will grow the fastest and outpace any competing chains."[5] "Honest" nodes are those that follow the consensus protocols in an attempt to keep the blockchain pure, and they are incentivized by the coin or token native to that blockchain. As a reflection of the amount of work invested in it, the longest chain also has a greater amount of rewards associated with it, since each new block contains a new coin offering for following transactions and blocks.[5]
It is important to note that PoW is only one blockchain consensus algorithm. Another popular, though newer, consensus mechanism is Proof of Stake (PoS). Instead of proving the amount of work done to add a block to the chain, this algorithm checks for proof of investment in the system via collateral.[6] With PoS, a node must hold and stake enough cryptocurrency tokens to be able to earn the transaction fees associated with validating a block and adding it to the blockchain. Nodes with greater amounts of staked tokens have a higher chance of being selected to have the privilege of completing this validation process.[7] In this way, the monetary gain is awarded to nodes with higher stake in the system rather than higher computing power. PoS is used by Ethereum and other prominent blockchains, and it is known primarily for being far more energy-efficient than blockchains like Bitcoin that rely on PoW, since computing power is not the deciding factor.
Web3 Applications
There are multiple applications of blockchain technology that exist in the Web3 ecosystem, and the goal is for them to work together seamlessly due to a similar underlying architecture. In addition to the foundation of the blockchain, another part of this architecture is smart contracts.
Smart contracts are pieces of code that facilitate the operations of applications, agreements, and events in Web3. Often written in the programming language Solidity, they are programs that detail different aspects of an application or process and run only when certain preconditions are met based on "if/then" statements in the code.[8] After the contract is written, it is deployed to the blockchain to execute any necessary computations and store relevant states, like the state of the blockchain.[9] Like everything else on the blockchain, smart contracts and their outcomes are immutable, and they can help carry out the functions of other Web3 applications.
One of these applications is non-fungible tokens, or NFTs. An NFT is a type of cryptocurrency, derived from Ethereum smart contracts, but different from other currencies like Bitcoin where all coins are equivalent and can be traded one-for-one. Instead, NFTs each have their own unique value and other identifiers that can be verified on the blockchain using their smart contracts, allowing for differentiation. Artists and creators find this characteristic particularly useful for artistic and intellectual property (IP) protection, because they are able to "easily prove the existence and ownership of digital assets in the form of videos, images, arts, event ticket, etc," and "can also earn royalties each time of a successful trade on any NFT market or by peer-to-peer exchanging."[10] With NFTs, creators can monetize and maintain ownership of their art in an advanced way.
Decentralized Finance, or DeFi, is a significant aspect of Web3, though it can be seen as an entire field of its own. DeFi is a decentralized alternative to traditional finance, which is heavily regulated by centralized institutions, such as governments and banks, and has been scrutinized and deemed untrustworthy by some. Financial applications in DeFi are built on the blockchain as well and make use of smart contracts to carry out economic activities such as buying/selling, exchanging, and borrowing/lending.[11] The use of smart contracts removes the need for centralized authorities to mediate or enforce financial operations, and thus removes the need to trust an institution, although it still requires trust in algorithmic intermediaries like blockchain mechanisms and smart contracts.
Another key aspect of DeFi is the users' ability to directly own their assets, rather than relinquishing ownership to institutions and entrusting them to handle assets correctly.[12] Of course, this requires the user to handle their own assets correctly, which is a source of risk in the DeFi space. Additionally, like other things on the blockchain, and unlike traditional finance, DeFi is permissionless and openly auditable, such that anyone can participate in transactions (rather than only entities trusted and approved by institutions) and the execution logic of all financial instruments and processes are transparent to anyone looking at the blockchain.[11] As a part of the Web3 ecosystem, users will be able to conduct financial tasks using DeFi applications, which will be able to interact with other Web3 applications seamlessly due to shared state and underlying technology.
Interacting with Web3 and any of its capabilities requires the use of decentralized applications, or "dapps." A dapp is any "application built on a decentralized network that combines a smart contract and a frontend user interface"[13] and can be seen as the overall tangible components of Web3 analogous to the webpages, applications, and platforms of the current web. The dapp performs its functionality based on the logic written in the smart contract code, which is open and accessible for anyone to investigate on the blockchain. This way, anyone can view the code that runs applications and can potentially use code similar to what someone else has written.
In addition to this open source characteristic, some other key features of decentralized applications are an internal cryptocurrency support via tokens to verify and incentivize providers and consumers, decentralized consensus, and no central point of failure, since all parts of the application are hosted and executed on the distributed blockchain system.[14] Currently, many of the most popular dapps are in the categories of DeFi (decentralized exchanges, borrowing/lending), gaming, NFT marketplaces, and other media. Some examples are: Uniswap, one of the top platforms for exchanging cryptocurrency tokens; Axie Infinity, an "NFT-based game known for its in-play virtual economy" and one of the most popular gaming dapps; and OpenSea, one of the largest decentralized NFT marketplaces where users can buy, sell, and mint NFTs.
The Technical Architecture
To carry out the functions of Web3, the technological architecture of decentralized applications differs from the traditional webpages and platforms in Web 2.0, mainly in terms of the backend. At a high level, the basic components of a Web 2.0 application are the database to store any necessary data, backend code for handling functionality, and frontend code for handling the user interface logic. All of these components are stored on a centralized server and sent to users using a browser and the Internet.[15]
Web3 applications, on the other hand, do not have a centralized server where its components are stored. The Ethereum blockchain is currently the leading blockchain that Web3 developers build their dapps on, so most of the current applications have a similar architecture.[15] Instead of the traditional components and server of Web 2.0 applications, these dapps primarily make use of the blockchain, the Ethereum Virtual Machine (EVM), smart contracts, and front end code.[15] The Ethereum blockchain is a distributed, peer-to-peer network of nodes that verifies and executes the smart contract code. The EVM is a state machine that processes and executes the state changes defined in the smart contracts after the contracts have been compiled into bytecode, which allows developers to choose high-level languages to write the contracts in.[15]
To reflect the functions of the application to the user, the frontend code needs to communicate with the smart contracts on the backend. However, since the blockchain is decentralized, each node in the network maintains a copy of all of the states and smart contract code on the EVM, so it is necessary for the frontend code to interact with a node in the blockchain.[16] It can be difficult and costly to independently set up a full node that runs the entire Ethereum blockchain software, especially as a dapp scales, so many developers choose to use nodes provided by third-party services, called "providers."[16] Providers like Alchemy, QuickNode, and Infura allow users to connect to its provided node and read the state stored on the blockchain, and their JSON-RPC specification "ensures that there's a uniform set of methods when frontend applications want to interact with the blockchain."[15]
To query a dapp and read the state of the blockchain, one only needs to be connected to a node, but in order to dynamically interact with a dapp and write to the blockchain, a user must "sign" the transaction using their cryptocurrency wallet and private key using a service like MetaMask. MetaMask is a cryptocurrency wallet that allows users to interact with the Ethereum blockchain and its decentralized applications. It holds any cryptocurrency tokens and allows users to sign transactions to validate their identity using a private key, which is assigned to the user's wallet when created. Whenever the frontend of a dapp requires the user to sign a transaction, MetaMask is used within the browser.
In terms of storage for the application's data, storing data directly on the blockchain is expensive, especially as the number of users increases. This is because adding state to the EVM adds to the cost for each node maintaining it, so users would usually be expected to pay a fee whenever they add data to the blockchain.[15] Expecting this of users is not the best experience for using an application, so developers can opt for an off-chain, decentralized data storage solution such as InterPlanetary File System (IPFS) or Swarm.[15] Similar to other components, these solutions distribute and store data in a peer-to-peer network with the help of built-in incentive structures that reward nodes for storing and retrieving data.[15]
Both application data and frontend code can be stored using these decentralized methods. All of these components involved in dapps for the purpose of decentralization, as well as additional elements not included in Figure 4.2 that serve to increase the level of decentralization, contribute to the difficulty of building and scaling dapps on Ethereum. There is maintenance difficulty, significant performance overhead, network congestion, and a resulting poorer user experience involved with Web3 applications. These are wellknown drawbacks of dapp development, and though there are some developing solutions, some users and developers simply view these as tradeoffs in the overall goal of a trustless system.
The ideas about Web3 and cryptocurrency ("crypto," "Bitcoin," etc.) are often conflated in discussion and in part for good reason. As previously mentioned, cryptocurrencies are the method of incentive for participants in blockchain's peer-to-peer network to validate and verify the information on the blockchain. It is a way to ensure, without any centralized authority or regulator, that the majority of users are incentivized to follow the consensus protocols to maintain its security and validity. When network users follow these rules, there are built-in protocols that reward them with certain amount of cryptocurrency native to that blockchain. Since the components of Web3 are built upon and rely on the security and validity of the blockchain state, it is overall inherently tied to cryptocurrencies. However, the purpose of this research is not to discuss cryptocurrency, but the Web3 ecosystem of technologies together, since there are broader uses and separate discussions surrounding cryptocurrency on its own. For the purposes of this research, I will use the broad understanding of Web3 as a collection of decentralized applications, similar to the way we can understand Web 2.0 as a collection of online applications, webpages, and platforms.
References
1. Z. Zheng et al., "Blockchain challenges and opportunities: A survey," International Journal of Web and Grid Services, vol. 14, no. 4, pp. 352-375, 2018.
2. A. Narayanan, J. Bonneau, E. Felten, A. Miller, and S. Goldfeder, Bitcoin and Cryptocurrency Technologies. Princeton University Press, 2016.
3. S. Nakamoto, "Bitcoin: A Peer-to-Peer Electronic Cash System," 2008.
4. J. Garay, A. Kiayias, and N. Leonardos, "The Bitcoin Backbone Protocol: Analysis and Applications," in Advances in Cryptology - EUROCRYPT 2015.
5. S. Nakamoto, "Bitcoin: A Peer-to-Peer Electronic Cash System," 2008.
6. S. King and S. Nadal, "PPCoin: Peer-to-Peer Crypto-Currency with Proof-of-Stake," 2012.
7. Ethereum Foundation, "Proof-of-Stake."
8. Ethereum Foundation, "Smart Contracts."
9. Ethereum Foundation, "Introduction to Smart Contracts."
10. Q. Wang et al., "Non-Fungible Token (NFT): Overview, Evaluation, Opportunities and Challenges," arXiv preprint, 2021.
11. S. Chen et al., "Understanding Security Issues in the NFT Ecosystem," arXiv preprint, 2022.
12. Ethereum Foundation, "Decentralized Finance (DeFi)."
13. Ethereum Foundation, "Introduction to dapps."
14. A. Pîrjan and D. M. Petroşanu, "The Impact of Blockchain Technology on the Music Industry," in Proceedings of the International Conference on Business Excellence, 2018.
15. P. Preethi Kasireddy, "The Architecture of a Web 3.0 Application," 2021.
16. Ethereum Foundation, "Nodes and Clients."