You are on page 1of 12

19F0217_8B_ASSIGNMENT

04
BlockChain

19F0217
M SHAHID IMRAN
8B
Q1: Difference between Web3, Web4 and Web5.
Answer:
Web3: Web3 (also known as Web 3.0) is an idea for a new iteration of the World Wide
Web which incorporates concepts such as decentralization, blockchain technologies, and
token-based economics. Web3 has become a catch-all term for the vision of a new, better
internet. Web3 uses blockchains, cryptocurrencies, and NFTs to give power back to the users
in the form of ownership. Platforms and apps built on Web3 won’t be owned by a central
gatekeeper, but rather by users, who will earn their ownership stake by helping to develop
and maintain those services. Web3 is decentralized, permissionless, and trustless.

Figure 1: Web3 Basic Dapp Architecture

Web4: Web 4.0 is the fourth generation of the World Wide Web. It is characterized by
increased user interaction and collaboration and more seamless integration between the
physical and virtual worlds. Some of the features of Web 4.0 include social networking,
blogs, wikis, folksonomies, user-generated content, and mashups. it helps us to better
connect with each other. Web 4.0 also allows for more personalized experiences. With
increased user interaction and collaboration, we can create experiences that are tailored
specifically for us. This can be anything from finding new music to exploring different
cultures. In short, Web4 may involve more sophisticated AI technologies, such as natural
language processing, computer vision, and machine learning. It may also include more
immersive and interactive experiences, such as virtual and augmented reality.
Page 1 of 12
Figure 2: Web 4 App Architecture

Web5: Web5 will bring things in better way then web3 and web4. It will help to enable the
DWP. The Decentralized Web Platform (DWP) enables developers to write Decentralized
Web Apps (DWAs) using Decentralized Identifiers (DIDs) and Decentralized Web Nodes
(DWNs), returning ownership and control over identity and data to individuals. Some people
use it to talk about a web that works with everything in our lives, like our houses, cars,
bodies, and minds. To do this, we would need an extremely smart computer and it would
have to be able to work with other computers in a way that we can't even think of right now.

Figure 3: Web5 Decenterilized Web Network


Q2: What is Geth?
Answer: Geth (go-ethereum) is a Go implementation of Ethereum - a gateway into the decentralized
web. Geth has been a core part of Ethereum since the very beginning. Geth was one of the original
Ethereum implementations making it the most battle-hardened and tested client. Geth is an
Ethereum execution client meaning it handles transactions, deployment and execution of smart
contracts and contains an embedded computer known as the Ethereum Virtual Machine. Running
Geth alongside a consensus client turns a computer into an Ethereum node. Geth provides a
command-line interface that allows users to create and manage Ethereum accounts, send
and receive ether and other tokens, deploy, and interact with smart contracts, and query
blockchain data. It also supports the Ethereum JSON-RPC API, which enables developers to
build decentralized applications on top of the Ethereum network.

Page 2 of 12
Figure 4: Geth testing Interface

Q3: What is Metaverse?


Answer: The "metaverse" is a hypothetical iteration of the Internet as a single, universal, and
immersive virtual world that is facilitated using virtual reality (VR) and augmented
reality (AR) headsets. The Metaverse is the idea that there will be an interoperable virtual
reality in which humans will become avatars. The Metaverse is the new internet, an
unfolding past the flat World Wide Web we've come to know. It will connect people all over
the world, create a plane for building and engaging-in activities, and unleash the collective
imagination and creative might of communities across the globe.

Figure 5: Metaverse Revolutionization

Page 3 of 12
Q4: What is Zero Knowledge Proof?
Answer: A zero-knowledge proof or zero-knowledge protocol is a method by which one
party (the prover) can prove to another party (the verifier) that a given statement is true
while the prover avoids conveying any additional information apart from the fact that the
statement is indeed true. The essence of zero-knowledge proofs is that it is trivial to prove
that one possesses knowledge of certain information by simply revealing it; the challenge is
to prove such possession without revealing the information itself or any additional
information. If proving a statement requires that the prover possess some secret
information, then the verifier will not be able to prove the statement to anyone else without
possessing the secret information. The statement being proved must include the assertion
that the prover has such knowledge, but without including or transmitting the knowledge
itself in the assertion. Otherwise, the statement would not be proved in zero-knowledge
because it provides the verifier with additional information about the statement by the end
of the protocol.

Figure 6: Zero knowledge Proog

Q5: What is zkEVM?


Answer: A zero-knowledge Ethereum Virtual Machine (zkEVM) is a virtual machine that
generates zero knowledge proof to verify the correctness of programs. ZkEVMs are designed to
execute smart contracts in a manner that supports zero-knowledge technology. A zkEVM is an
EVM-compatible virtual machine that supports zero-knowledge proof computation. Unlike
regular virtual machines, a zkEVM proves the correctness of program execution, including
the validity of inputs and outputs used in the operation.

Figure 7: zkEVM Basic Architecture

Page 4 of 12
Q6: What is an internet computer? why we Deploy a Dapp on Internet Computer? Write all
steps involved in deployment of a Dapp on internet computer.
Answer:
Internet Computer: The Internet Computer is a blockchain-based decentralized platform
that aims to create a new kind of internet where software can be run directly on the
network, rather than on centralized servers. It is designed to provide a scalable, secure, and
efficient environment for building and deploying decentralized applications with high
performance and interoperability.
why we Deploy a Dapp on Internet Computer?
Scalability: The Internet Computer is designed to provide unlimited scalability for DApps,
enabling them to handle massive amounts of data and users without sacrificing performance
or reliability.
Interoperability: The Internet Computer supports a wide range of programming languages
and frameworks, making it easier for developers to create DApps that can interact with each
other and with other blockchain networks.
Security: The Internet Computer provides a highly secure environment for DApps, with built-
in features such as end-to-end encryption, tamper-proof storage, and secure communication
protocols.
Decentralization: The Internet Computer is a decentralized platform, which means that
DApps can run without the need for centralized servers or intermediaries. This can reduce
costs and dependencies on third-party services and infrastructure.
Write all steps involved in deployment of a DApp on internet computer.
1. Development: Develop the DApp using programming languages and frameworks that
are compatible with the Internet Computer, such as Motoko, Rust, or WebAssembly.
2. Compilation: Compile the code into WebAssembly bytecode or other formats that
can be executed on the Internet Computer.
3. Deployment: Deploy the DApp to the Internet Computer using the appropriate tools
and protocols, such as the DFINITY Canister SDK, the Internet Identity SDK, or the
Internet Computer API.
4. Testing: Test the DApp to ensure that it functions correctly and meets the desired
specifications, using tools such as the Internet Computer Network Nervous System
(NNS) and the Internet Computer Canister Development Kit (CDK).
5. Security: Ensure that the DApp is secure and resilient against attacks, by following
best practices such as code review, penetration testing, and regular updates.
6. Maintenance: Continuously monitor and maintain the DApp to ensure that it
remains up-to-date, compatible with new versions of the Internet Computer, and
responsive to user feedback.
Q7: What is Smart Contract Security?
Answer: Smart contract security refers to the security principles and practices used by
developers, users, and exchanges when creating or interacting with smart contracts.
Blockchain is a dynamic industry worth billions of dollars. Bad actors often seek

Page 5 of 12
vulnerabilities in smart contracts to make a quick buck. These vulnerabilities may lead to all
the funds being drained from a smart contract wallet.
Part 2: Smart Contracts
Q1: Write a program that generates a multi-signature Bitcoin transaction.
Code:
// SPDX-License-Identifier: MIT License
pragma solidity ^0.8.0;
contract MultiSigBitcoinTransaction {
    address public owner1;
    address public owner2;
    address public owner3;
    uint public requiredSignatures;
    struct Transaction {
        uint amount;
        address payable to;
        bool owner1Signed;
        bool owner2Signed;
        bool owner3Signed;
    }
    Transaction[] public transactions;
    constructor(address _owner1, address _owner2, address _owner3, uint
_requiredSignatures) {
        owner1 = _owner1;
        owner2 = _owner2;
        owner3 = _owner3;
        requiredSignatures = _requiredSignatures;
    }
    function submitTransaction(uint _amount, address payable _to) public {
        require(msg.sender == owner1 || msg.sender == owner2 || msg.sender ==
owner3, "You are not authorized to submit a transaction");
        transactions.push(Transaction(_amount, _to, false, false, false));
    }
    function signTransaction(uint _transactionId) public {
        require(msg.sender == owner1 || msg.sender == owner2 || msg.sender ==
owner3, "You are not authorized to sign this transaction");
        Transaction storage transaction = transactions[_transactionId];
        if (msg.sender == owner1) {
            require(!transaction.owner1Signed, "You have already signed this
transaction");
            transaction.owner1Signed = true;
        } else if (msg.sender == owner2) {
            require(!transaction.owner2Signed, "You have already signed this
transaction");
            transaction.owner2Signed = true;
        } else if (msg.sender == owner3) {
            require(!transaction.owner3Signed, "You have already signed this
transaction");
            transaction.owner3Signed = true;

Page 6 of 12
        }
        if (transaction.owner1Signed && transaction.owner2Signed &&
transaction.owner3Signed) {
            executeTransaction(_transactionId);
        }
    }
    function executeTransaction(uint _transactionId) private {
        Transaction storage transaction = transactions[_transactionId];
        require(transaction.owner1Signed && transaction.owner2Signed &&
transaction.owner3Signed, "Transaction has not been fully signed");
        payable(transaction.to).transfer(transaction.amount);
    }
}
Output:

Explanation:
Code:
address public owner1;
address public owner2;
address public owner3;
uint public requiredSignatures;
Explanation:
Here we declare some state variables for the contract. We define three address variables
owner1, owner2, and owner3 to store the addresses of the owners who are authorized to
sign transactions. We also define a uint variable requiredSignatures which stores the number
of required signatures for a transaction to be executed.

Page 7 of 12
Code:
struct Transaction {
uint amount;
address payable to;
bool owner1Signed;
bool owner2Signed;
bool owner3Signed;
}
Explanation:
This is a struct called Transaction, which represents a transaction that can be signed by the owners. It
has four variables - the amount of the transaction, the address it is being sent to, and three boolean
variables (owner1Signed, owner2Signed, owner3Signed) to keep track of which owners have signed
off on the transaction.

Code:
function submitTransaction(uint _amount, address payable _to) public {
require(msg.sender == owner1 || msg.sender == owner2 || msg.sender == owner3,
"You are not authorized to submit a transaction");
transactions.push(Transaction(_amount, _to, false, false, false));
}
Explanation:
This function allows an owner to submit a new transaction to the contract. It takes two parameters -
the amount of the transaction and the address it is being sent to. The function checks that the caller
is one of the authorized owners, and then creates a new Transaction struct and adds it to the
transactions array.

Code:
function signTransaction(uint _transactionId) public {
require(msg.sender == owner1 || msg.sender == owner2 || msg.sender == owner3, "You are
not authorized to sign this transaction");
Transaction storage transaction = transactions[_transactionId];

if (msg.sender == owner1) {
require(!transaction.owner1Signed, "You have already signed this transaction");
transaction.owner1Signed = true;
} else if (msg.sender == owner2) {
require(!transaction.owner2Signed, "You have already signed this transaction");
transaction.owner2Signed = true;
} else if (msg.sender == owner3) {
require(!transaction.owner3Signed, "You have already signed this transaction");
transaction.owner3Signed = true;
}
}
Explanation:
The signTransaction function is used by the owners to sign a transaction that has been submitted to
the contract. It takes one parameter - the index of the transaction in the transactions array that the
owner wants to sign.

Page 8 of 12
The first line of the function checks that the caller is one of the authorized owners, using the same
require statement as the submitTransaction function. If the caller is not one of the authorized
owners, the function will throw an error and revert the transaction.

Next, the function retrieves the Transaction struct from the transactions array using the
_transactionId parameter. It does this by using the storage keyword to create a reference to the
Transaction struct in storage, rather than creating a new copy of the struct in memory.

The function then checks which owner is signing the transaction using an if-else statement. If the
owner has already signed the transaction, the function will throw an error and revert the transaction.
Otherwise, the function will update the appropriate boolean variable (owner1Signed, owner2Signed,
or owner3Signed) to true to indicate that the owner has signed the transaction.

Finally, the function checks if all three owners have signed the transaction by checking the values of
the owner1Signed, owner2Signed, and owner3Signed variables. If all three are true, the function
calls the executeTransaction function to execute the transaction with the specified index in the
transactions array.

Overall, this signTransaction function ensures that only authorized owners can sign transactions and
that a transaction can only be executed when all three owners have signed it.

Q2: Write a program that implements a proof-of-authority consensus algorithm.


Code:
// SPDX-License-Identifier: MIT License
pragma solidity ^0.8.0;
contract ProofOfAuthority {   
    uint private currentBlockNumber;
    bytes32 private currentBlockHash;
    address[] private authorities;
    mapping(address => uint) private authorityWeights;
    uint private currentAuthorityIndex;
    address[]
_authorities=[0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db,0x5B38Da6a701c568545d
CfcB03FcB875f56beddC4];
    uint[] _weights=[1,1];   
    constructor() {
        require(_authorities.length == _weights.length, "Invalid input");     
        for (uint i = 0; i < _authorities.length; i++) {
            authorities.push(_authorities[i]);
            authorityWeights[_authorities[i]] = _weights[i];
        }       
        currentAuthorityIndex = 0;
    }   
    function addBlock(bytes32 _blockHash) public returns(bool) {
        require(msg.sender == authorities[currentAuthorityIndex],
"Unauthorized");       
        currentBlockNumber++;
        currentBlockHash = _blockHash;       
        currentAuthorityIndex = (currentAuthorityIndex + 1) %
authorities.length;       

Page 9 of 12
        return true;
    }   
    function getCurrentBlockNumber() public view returns(uint) {
        return currentBlockNumber;
    }   
    function getCurrentBlockHash() public view returns(bytes32) {
        return currentBlockHash;
    }   
    function getCurrentAuthority() public view returns(address) {
        return authorities[currentAuthorityIndex];
    }  
}
Output:

Explanation:
Code:
uint private currentBlockNumber;
bytes32 private currentBlockHash;
address[] private authorities;
mapping(address => uint) private authorityWeights;
uint private currentAuthorityIndex;
Explanation:
These are the state variables of the ProofOfAuthority smart contract.

currentBlockNumber and currentBlockHash are used to keep track of the current state of the
blockchain. authorities is an array of addresses representing the authorities that are allowed to add
new blocks to the blockchain.

authorityWeights is a mapping that associates each authority with a weight, which can be used to
prioritize their contributions.

currentAuthorityIndex is an integer that tracks the index of the current authority in the authorities
array.

Code:

Page 10 of 12
address[]
_authorities=[0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db,0x5B38Da6a701c568545dCfcB03
FcB875f56beddC4];
uint[] _weights=[1,1];

constructor() {
require(_authorities.length == _weights.length, "Invalid input");

for (uint i = 0; i < _authorities.length; i++) {


authorities.push(_authorities[i]);
authorityWeights[_authorities[i]] = _weights[i];
}

currentAuthorityIndex = 0;
}
Explanation:
This is the constructor of the ProofOfAuthority smart contract. It initializes the authorities and
authorityWeights state variables with the _authorities and _weights arrays, respectively.

The require statement checks that the lengths of the two arrays are equal, which is necessary for
them to correspond correctly.

The for loop iterates through the _authorities array and populates the authorities and
authorityWeights mappings with the corresponding addresses and weights.

Finally, the currentAuthorityIndex is initialized to zero, which corresponds to the first authority in the
authorities array.

Code:
function addBlock(bytes32 _blockHash) public returns(bool) {
require(msg.sender == authorities[currentAuthorityIndex], "Unauthorized");

currentBlockNumber++;
currentBlockHash = _blockHash;

currentAuthorityIndex = (currentAuthorityIndex + 1) % authorities.length;

return true;
}
Explanation:
This function adds a new block to the blockchain. It first checks that the caller is the current
authority, which is determined by the currentAuthorityIndex variable.

If the caller is authorized, the function increments the currentBlockNumber variable, updates the
currentBlockHash with the provided _blockHash, and updates the currentAuthorityIndex to the next
authority in the authorities array.

Finally, the function returns true to indicate that the block was successfully added.

Page 11 of 12

You might also like