Advance Sustainable Science. Engineering and Technology (ASSET) Vol. No. January 2024, pp. 02401018-01 02401018-08 ISSN: 2715-4211 DOI: https://doi. org/10. 26877/asset. The Implementation and Analysis of The Proof of Work Consensus in Blockchain Alvin Christian Davidson Therry*. Rizka Ardiansyah. Muhammad Yazdi Pusadan. Yuri Yudhaswana Joefrie. Anita Ahmad Kasim Information Technology Department. Faculty of Engineering. Tadulako University. Jl. Soekarno Hatta No KM 9 Palu 94148. Central Sulawesi. Indonesia *alvintherry20@gmail. Abstract. Communication in peer-to-peer (P2P) networks presents challenges in maintaining security, data integrity, and decentralization. Consensus mechanisms play a crucial role in addressing these challenges by validating data and ensuring that each entity has synchronized data without intermediaries. This research focuses on the implementation and analysis of the Proof of Work (PoW) consensus mechanism, widely used in blockchain, to enhance understanding of its functions, benefits, and workings or flow. This research, conducted using the Go programming language, successfully implements Proof of Work (PoW) as a security measure, ensuring data integrity, and preventing manipulation. Through black-box testing, this research confirms the functionality and reliability of the implemented Proof of Work (PoW) These findings contribute to a deeper understanding of consensus mechanisms, offering insights to optimize blockchain protocols and foster trust among entities. This research highlights the relevance of sustainable Proof of Work (PoW) in blockchain technology, emphasizing its role in enhancing security and ensuring data integrity in decentralized networks. Keywords: Blockchain. Consensus. Proof of Work. Security. Decentralized (Received 2023-12-20. Accepted 2023-12-27. Available Online by 2024-01-. Introduction The development of blockchain usage in recent years has experienced a very significant increase across various fields. This significant increase is because blockchain offers several advantages and solutions to some problems in different sectors. Blockchain is a distributed database technology that operates through a peer-to-peer (P2P) network, meaning the database is distributed among all entities in the network, and communication between entities occurs directly without intermediaries . , . Communication through peer-to-peer (P2P) networks poses significant challenges in maintaining security, data integrity, consistency, and decentralization. A mechanism is needed to validate and prevent data falsification and manipulation, ensuring that each entity has identical and synchronized copies of the database without intermediaries . Ae. This mechanism is called consensus. Consensus is a key in blockchain that operates on each entity within the network. Consensus functions to validate data before it is added as a new block to the blockchain, ensuring that each entity has synchronized data and without intermediaries . Ae. Consensus is a solution to existing challenges of maintaining security, data integrity, consistency, and decentralization in the blockchain. Proof of Work (PoW) is one of the most widely used consensus today and is also known as the first consensus applied in blockchain. One example of the use of Proof of Work (PoW) is in the Bitcoin network, which aims to verify and secure transactions and create new blocks in the blockchain by harnessing computational power. This research aims to implement and analyze Proof of Work (PoW) consensus on blockchain. The results of this research are expected to increase knowledge and insight about consensus, especially about proof of work and its implementation in blockchain. To guide readers through the content of this paper, the following is the structure that will be followed. The next section will delve into the Methods, discussing the research type employed and the system development undertaken. Subsequently, the paper will move on to the Results and Discussion section, covering planning, analysis, system design, prototype, implementation, and system testing. The paper will conclude with a summary and suggestive recommendations for future developments in this field. Methods Research Type This research employs exploratory research. Exploratory research is a type of scientific investigation conducted to explore a topic without specific hypotheses. This research aims to broaden insights and gain a deeper understanding of a topic that is not well explored, thus providing a foundation for future research . System Development The system development is carried out using the prototype method. This method is chosen because it allows for easy changes and adjustments during the development process, making it flexible and providing a visual or interactive representation of the system's flow before development begins. This representation enables developers to see and understand the system's requirements better throughout the design process and allows for development adjustments . The main technology used in developing the system is the Go programming language. The Go programming language creates the blockchain and Proof of Work (PoW) consensus due to several advantages that support blockchain, such as fast performance, parallelism, clean and easily understandable syntax, efficiency in resource usage, and more . Supporting technologies include BadgerDB, gRPC, and Docker. BadgerDB is a key-value database for each blockchain entity because it is designed with high performance, storage efficiency, and other features. gRPC for communication between blockchain entities due to its advantages that align with communication needs in blockchain, including efficiency, lightweight, strong security and authentication, using Protocol Buffers (Probu. , asynchronous communication, and more. Docker to run multiple services in the blockchain network, simplifying the configuration process. Results and Discussion Planning At this stage, the process begins with identifying issues and conducting a literature review on security and decentralization systems within the blockchain. This leads to the consensus mechanisms as a solution to these problems. Based on these issues, the researcher aims to implement and analyze the Proof of Work (PoW) consensus within the blockchain to gain a deeper understanding and further insights into consensus, especially Proof of Work (PoW), within the blockchain. Analysis At this stage, the process involves analyzing aspects related to consensus. The main focus is on the functions and benefits of consensus in blockchain, the workings or flow of Proof of Work (PoW), and the strengths and weaknesses of Proof of Work (PoW). Based on the analysis conducted, consensus in blockchain functions as a fundamental mechanism to achieve agreement among distributed entities, ensuring the validity and consistency of transactions. It prevents data tampering and secures the integrity of decentralized data. Proof of Work (PoW) is a consensus algorithm in which entities solve complex mathematical puzzles, validate transactions, and add blocks to the blockchain. Its strength lies in providing robust security, decentralization, and a proven track record in networks. However, the energyintensive computations of Proof of Work (PoW) raise environmental concerns. Despite these weaknesses. Proof of Work (PoW) remains a reliable and secure consensus mechanism. System Design During this stage, the implementation of the Proof of Work (PoW) consensus in blockchain is The system design starts when an entity receives data to be added as a new block. This data, along with the prev hash, nonce, and difficulty, undergoes hashing using the SHA256 algorithm. Prev hash is the hash of the previous block. Nonce is a value that can be changed by the entity to achieve the desired hash value. Difficulty is the level of difficulty that an entity must overcome to add a new block to the blockchain. Subsequently, validation occurs by checking if the resulting hash of the block is less than the target value. If true, a new block is added and disseminated to other entities in the blockchain If false, the process iterates by incrementing the nonce and repeating the hashing and validation steps until a valid node is found . Ae. The system design can be seen in Figure 1. Figure 1. Design System Prototype This stage aims to implement the proof of work consensus flow, which involves hashing and validation to add a new block to the blockchain through prototype design, enhancing the understanding of system requirements. Implementation In this stage, the system design is implemented in the form of code using the Go programming Go is a programming language developed by Google, commonly used on the server side, and possesses several advantages such as simple syntax, fast compilation, automatic memory management, and more . NewBlock function is responsible for adding a new block to the blockchain. Within this function, an instance of the Block struct is created, the NewProof function is called to determine the target, the Run method of the instance is used to perform hashing and validate the new block, and the instance of the block is returned. The NewBlock function can be seen in Figure 2. Figure 2. NewBlock Function NewProof is a constructor method to create a consensus instance, in this case is the main logic of the ProofOfWork consensus algorithm. The purpose is to determine the target, which is the value that entities must achieve to validate a block, typically in binary units . , . In this function, an instance of the target is created using the big. Int data type, the Lsh method is employed to shift bits from the specified value, an instance of pow is created from the ProofOfWork struct, and the pow instance is The NewProof Function can be seen in Figure 3. Figure 3. NewProof Function initData method of the pow instance is aims to concatenate several byte slices, namely PrevHash and Data from the pow instance, along with nonce and Difficulty, into a single byte slice without any separator characters. Nonce is a value that entities can modify to achieve the desired hash value. generally, the nonce is less than the target. Meanwhile. Difficulty represents the level of difficulty that entities must overcome to add a new block to the blockchain. The greater the difficulty value, the higher the difficulty level, and vice versa . Ae. The InitData method can be seen in Figure 4. Figure 4. InitData Method Run method of the pow instance serves to hash the byte slice data that has been combined through the initData method of the pow instance and validate whether the hash of the new block is less than the If true, it is considered valid. otherwise, if false, it means it is not valid. In such cases, the nonce is incremented, and the process repeats with hashing and validation until a valid node is found. The Run method can be seen in Figure 5. Figure 5. Run Method System Testing This stage is crucial for testing the created system to determine if it operates effectively and to identify and reduce potential errors. System testing employs the black box method, a software testing approach that focuses on the functionality of the system . The challenge faced during system testing using black box testing is the limitation of computational resources for testing Proof of Work (PoW) consensus with high difficulty because if the difficulty increases, the computational energy required for the computation also increases. The System Testing Results can be seen in Table 1. Table 1. System Testing Results Test Case Hash Algoritm Description Hash a slice of bytes with the SHA256 Algorithm. Result Success Validate New Block Validation of the block hash is less than the target. the validation is successful, it will be added to the However, if the validation fails, the nonce will be incremented, followed by hashing and validation again. Success Add New Block If the block validation is successful, the block will be added to the blockchain and disseminated to other entities in the blockchain network. Success Edit Block If there is a change in data within the blockchain, the validation in the consensus will become invalid, and the blockchain of the entity will self-correct by copying the blockchain from other entities. Success Delete Block If there is a deletion in data within the blockchain, the validation in the consensus will become invalid, and the blockchain of the entity will self-correct by copying the blockchain from other entities. Success Conclusion Based on the results of the system testing, this research successfully implemented the proof of work consensus in the blockchain using the go programming language. In this system, the consensus functions as a security measure and ensures data integrity by operating on every entity in the blockchain network to validate each transaction. This prevents manipulation and forgery of data and assists each entity in having accurate data through distribution without intermediaries or third parties, thus maintaining a decentralized system. System testing conducted through black box testing confirms the functionality and reliability of the implemented proof of work consensus. This research contributes to a deeper understanding of the functions and benefits of the proof of work consensus in the blockchain. By delving into the nuanced dynamics of this consensus mechanism, the study offers perspectives for optimizing blockchain protocols and fostering trust among network participants These findings underscore the continued relevance of proof of work in the evolving landscape of blockchain technology and its potential implications for future advancements in distributed ledger systems and emphasize the role of this consensus mechanism in enhancing security and ensuring data integrity in the blockchain network. For future research, it is recommended to explore alternative consensus mechanisms and their implications for blockchain systems. Additionally, investigating scalability issues and energy efficiency related to proof of work could provide valuable insights for the development and improvement of blockchain technology. A highly suggested area for potential exploration is to investigate the development and implications of alternative consensus mechanisms, such as Proof of Stake (PoS). Delegated Proof of Stake (DPoS), or other new protocols. This exploration can offer valuable insights into enhancing the sustainability and efficiency of blockchain systems. Moreover, researching scalability challenges and proposing innovative solutions to address them will be crucial to accommodate the growing demands of blockchain networks. Overall, this research lays the foundation for further exploration and refinement of consensus mechanisms in the dynamic field of blockchain. References