III Cse C & BC Answer Key
III Cse C & BC Answer Key
(Accredited by NBA)
SEMESTER – VII
522CIT02 – CRYPTOGRAPHY AND BLOCK CHAIN DEVELOPMENT
UNIT TEST – III ANSWER KEY
PART – A
1. Define ledger. Name some common types of ledger.
A Ledger Is Decentralized And Distributed Among Network Participants. It Records All
Transactions Chronologically And Transparently, Ensuring That Data Cannot Be Altered
Once It Is Recorded.
Common Types of Ledgers:
• Public Ledger
• Private Ledger
• Consortium or Federated Ledger
• Permissioned Ledger
3. What is ethereum?
Ethereum is a decentralized, open-source blockchain platform that enables the creation of
smart contracts and decentralized applications (dApps). It uses its native cryptocurrency,
Ether (ETH), to power transactions. Ethereum supports various applications like DeFi, NFTs,
and DAOs, making it a foundational layer for decentralized projects.
4. Differentiate Externally Owned Account (EOA) and Smart Contract Account (SCA) in
Ethereum.
Aspect Externally Owned Account Externally Owned Account
(EOA) (EOA)
Controlled By • A private key (human • Code (smart contract
or external entity) logic)
By using blockchain we can track orders and payments from end to end.
Types of Blockchain
There are 4 types of blockchain:
• Public Blockchain.
• Private Blockchain.
• Hybrid Blockchain.
• Consortium Blockchain.
1. Public Blockchain
These blockchains are completely open to following the idea of decentralization. They don’t
have any restrictions, anyone having a computer and internet can participate in the network.
• As the name is public this blockchain is open to the public, which means it is not
owned by anyone.
• Anyone having internet and a computer with good hardware can participate in this
public blockchain.
• All the computer in the network hold the copy of other nodes or block present in the
network
• In this public blockchain, we can also perform verification of transactions or records
Advantages:
• Trustable: There are algorithms to detect no fraud. Participants need not worry about
the other nodes in the network
• Secure: This blockchain is large in size as it is open to the public. In a large size,
there is greater distribution of records
• Anonymous Nature: It is a secure platform to make your transaction properly at the
same time, you are not required to reveal your name and identity in order to
participate.
• Decentralized: There is no single platform that maintains the network, instead every
user has a copy of the ledger.
Disadvantages:
• Processing: The rate of the transaction process is very slow, due to its large size.
Verification of each node is a very time-consuming process.
• Energy Consumption: Proof of work is high energy-consuming. It requires good
computer hardware to participate in the network
• Acceptance: No central authority is there so governments are facing the issue to
implement the technology faster.
Use Cases: Public Blockchain is secured with proof of work or proof of stake they can be
used to displace traditional financial systems. The more advanced side of this blockchain is
the smart contract that enabled this blockchain to support decentralization. Examples of
public blockchain are Bitcoin, Ethereum.
2. Private Blockchain
These blockchains are not as decentralized as the public blockchain only selected nodes can
participate in the process, making it more secure than the others.
• Speed: The rate of the transaction is high, due to its small size. Verification of each
node is less time-consuming.
• Scalability: We can modify the scalability. The size of the network can be decided
manually.
• Privacy: It has increased the level of privacy for confidentiality reasons as the
businesses required.
• Balanced: It is more balanced as only some user has the access to the transaction
which improves the performance of the network.
Disadvantages:
• Security- The number of nodes in this type is limited so chances of manipulation are
there. These blockchains are more vulnerable.
• Centralized- Trust building is one of the main disadvantages due to its central nature.
Organizations can use this for malpractices.
• Count- Since there are few nodes if nodes go offline the entire system of blockchain
can be endangered.
Use Cases: With proper security and maintenance, this blockchain is a great asset to secure
information without exposing it to the public eye. Therefore companies use them for internal
auditing, voting, and asset management. An example of private blockchains is Hyperledger,
Corda.
3. Hybrid Blockchain
It is the mixed content of the private and public blockchain, where some part is controlled by
some organization and other makes are made visible as a public blockchain.
• Ecosystem: Most advantageous thing about this blockchain is its hybrid nature. It
cannot be hacked as 51% of users don’t have access to the network
• Cost: Transactions are cheap as only a few nodes verify the transaction. All the nodes
don’t carry the verification hence less computational cost.
• Architecture: It is highly customizable and still maintains integrity, security, and
transparency.
• Operations: It can choose the participants in the blockchain and decide which
transaction can be made public.
Disadvantages:
4. Consortium Blockchain
It is a creative approach that solves the needs of the organization. This blockchain validates
the transaction and also initiates or receives transactions.
• Speed: A limited number of users make verification fast. The high speed makes this
more usable for organizations.
• Authority: Multiple organizations can take part and make it decentralized at every
level. Decentralized authority, makes it more secure.
• Privacy: The information of the checked blocks is unknown to the public view. but
any member belonging to the blockchain can access it.
• Flexible: There is much divergence in the flexibility of the blockchain. Since it is not
a very large decision can be taken faster.
Disadvantages:
• Approval: All the members approve the protocol making it less flexible. Since one or
more organizations are involved there can be differences in the vision of interest.
• Transparency: It can be hacked if the organization becomes corrupt. Organizations
may hide information from the users.
• Vulnerability: If few nodes are getting compromised there is a greater chance of
vulnerability in this blockchain
Use Cases: It has high potential in businesses, banks, and other payment processors. Food
tracking of the organizations frequently collaborates with their sectors making it a federated
solution ideal for their use. Examples of consortium Blockchain are Tendermint and
Multichain.
7. How blocks are created in blockchain and describe its structure in detail.
In a blockchain, blocks are created through a process called mining (in Proof of Work
systems) or validation (in Proof of Stake systems). These blocks are data containers that store
transactions and are linked together in a chronological order to form a chain. Let's break down
the process and the structure of blocks in detail:
1. Block Creation Process:
• Transaction Pool: Users initiate transactions, which are collected into a pool of
unconfirmed or pending transactions.
• Mining/Validation:
o In Proof of Work (PoW): Miners compete to solve a complex cryptographic
puzzle (finding a nonce) to validate a block of transactions. Once a miner
finds the correct solution, the block is considered valid and added to the
chain.
o In Proof of Stake (PoS): Validators are chosen to propose a block based on
the number of coins they hold and are willing to "stake" as collateral. The
selected validator creates and proposes the next block.
• Consensus Mechanism: After a block is proposed, it is broadcasted to the network.
Other nodes in the blockchain network must agree on its validity through a consensus
mechanism like PoW, PoS, or others (like Delegated PoS, Byzantine Fault
Tolerance).
• Block Added to Blockchain: Once validated, the new block is added to the chain,
with a reference to the previous block.
2. Structure of a Blockchain Block:
A blockchain block consists of several components, and the structure may vary
depending on the specific blockchain (like Bitcoin, Ethereum, etc.), but the core
elements are generally as follows:
a) Block Header:
• Previous Block Hash: This is the hash of the previous block’s header. It
ensures that the blocks are linked in chronological order and makes the
blockchain tamper-resistant.
• Merkle Root: The root of the Merkle Tree (or Hash Tree), which is a
structure used to efficiently verify the integrity of transactions. It summarizes
all transactions in the block.
• Timestamp: The time when the block was created.
• Nonce: A number that miners manipulate in PoW systems to solve the
cryptographic puzzle.
• Difficulty Target: A value that indicates how difficult it is to mine a new
block, adjusting over time to ensure consistent block creation intervals (in
PoW systems).
• Version: Indicates which version of the blockchain protocol is being used.
b) Block Body:
• Transaction List: Contains the list of all transactions included in the block.
Each transaction records details like sender, receiver, amount, and
cryptographic signatures.
• Coinbase Transaction (in PoW systems): The first transaction in the block,
which awards the miner who successfully mined the block with a block
reward.
3. How Blocks Are Linked Together:
• Each block contains the hash of the previous block’s header. This linking forms a
continuous chain of blocks, ensuring that any change to a block would require
altering all subsequent blocks, which would require re-mining or re-validating the
entire chain—a computationally infeasible task, especially in large, decentralized
networks.
• This immutability is what makes blockchain secure and resistant to tampering.
4. Example of a Block Structure (in Bitcoin):
Block Header:
• Previous Block Hash: 0000000000000000001c75edb15...
• Merkle Root: 8d6f6a08cd50cdb4380037e3d2060a...
• Timestamp: 1640995200 (Unix time)
• Nonce: 2083236893
• Difficulty: 000000000000000000100000000000...
Block Body:
• Transactions: A list of all the transactions in this block.
o Transaction 1: Coinbase transaction (miner's reward)
o Transaction 2: User transaction from address A to address B
o ...
5. Final Points:
• Chain Growth: New blocks are added roughly every 10 minutes (in Bitcoin)
or other intervals depending on the blockchain system.
• Immutability: Once a block is added to the chain, it is computationally
impractical to alter it.
• Decentralization: Blocks are distributed across a decentralized network of
nodes, ensuring transparency and trust.
8. What is Ethereum mining and how does it contribute to the security and operation of
the Ethereum blockchain?
Ethereum mining is the process through which new blocks are added to the Ethereum
blockchain, similar to how Bitcoin mining works. However, Ethereum uses a different
approach and consensus mechanism, making its mining process unique.
1. Ethereum Mining Process:
Ethereum mining, until Ethereum 2.0 (now fully transitioned to Proof of Stake), was
based on a Proof of Work (PoW) consensus algorithm called Ethash. The mining
process involves the following steps:
• Transaction Pool: Ethereum transactions are broadcast to the network and collected
into a pool of pending transactions.
• Block Creation: Miners collect these transactions and package them into a candidate
block.
• Solving the Cryptographic Puzzle: Miners use computational power to solve a
complex cryptographic puzzle, which requires finding a specific nonce (a random
number) that, when combined with other data in the block, produces a hash value
below a predetermined difficulty target. The difficulty adjusts dynamically to control
the time between blocks (about 12–15 seconds on Ethereum).
• Block Validation: Once a miner finds a valid nonce, the block is broadcast to the
network for validation. Other nodes verify the solution and the transactions in the
block.
• Block Reward: The miner who successfully solves the puzzle and adds the new
block is rewarded with Ether (ETH), along with the transaction fees from the
transactions included in the block.
2. How Ethereum Mining Contributes to Security:
Mining plays a critical role in securing the Ethereum network through several key
mechanisms:
a) Decentralization:
• Miners are distributed across the network globally, ensuring that no
single entity has control over the entire network. This decentralization is
crucial for the security and integrity of Ethereum, as it prevents malicious
actors from easily altering or controlling the network.
b) Consensus and Immutability:
• Mining ensures that consensus is reached across all nodes on the network.
The Proof of Work mechanism requires that a majority of miners agree on the
state of the blockchain before a new block can be added.
• Once a block is added, it is computationally expensive to modify or alter it
because an attacker would have to redo the mining for that block and all
subsequent blocks. This makes the blockchain immutable and resistant to
tampering.
c) Sybil Resistance:
• Sybil attacks involve an entity creating multiple fake identities to gain
influence over a network. Proof of Work mining requires significant
computational resources, making it prohibitively expensive for an
attacker to control enough mining power to subvert the network. This
ensures that only genuine nodes participate in validating transactions.
d) Chain Integrity and Prevention of Double Spending:
• Ethereum mining ensures that once a transaction is confirmed and included in
a block, it cannot be reversed without enormous computational effort. This
protects against double-spending, where an attacker might attempt to use the
same funds in two different transactions.
• Miners confirm the validity of transactions, preventing malicious transactions
from being included in blocks.
3. Ethereum Mining's Role in Network Operation:
In addition to security, Ethereum mining plays a key role in maintaining the operation
of the network:
a) Block Creation and Transaction Processing:
• Mining ensures that blocks are created at regular intervals (about every 12–15
seconds), maintaining a steady flow of new blocks. This ensures that
transactions are confirmed promptly.
• Each block contains a list of transactions, and miners are incentivized to
include as many transactions as possible through gas fees. Users pay these
gas fees to have their transactions processed faster.
b) Issuance of New Ether (ETH):
• Mining also contributes to the issuance of new ETH. Every time a block
is mined, the miner receives a block reward (in ETH). This process of
issuing new Ether ensures that the cryptocurrency supply grows over
time, while transaction fees also incentivize miner participation.
c) Execution of Smart Contracts:
• Ethereum differs from Bitcoin in that it allows for the execution of smart
contracts. When transactions involving smart contracts are included in a
block, miners execute the contract code, and the network reaches
consensus on the contract's outcome. This enables decentralized
applications (dApps) to function on Ethereum.
4. Transition to Ethereum 2.0 and Proof of Stake (PoS):
With the full implementation of Ethereum 2.0, the Ethereum network has
transitioned from PoW to a Proof of Stake (PoS) consensus mechanism. In PoS, mining is no
longer required, and the process of securing the network and adding new blocks is handled by
validators who "stake" their ETH as collateral. This transition reduces energy consumption
and increases scalability while still providing robust security.
9. Explore the features of array, enum and struct in solidity with example.
In Solidity, arrays, enums, and structs are powerful data types that help in organizing and
structuring data efficiently. Each of these has distinct characteristics and use cases. Let’s
explore each one with examples:
1. Arrays in Solidity:
An array in Solidity is a collection of elements of the same type. Arrays can be either fixed-
size or dynamic.
Types of Arrays:
• Fixed-size Arrays: The length of the array is fixed and determined at compile time.
• Dynamic Arrays: The size of the array can grow or shrink at runtime.
Features of Arrays:
• Arrays can hold multiple elements of the same type.
• Arrays can be multi-dimensional.
• Solidity supports both dynamic and fixed-size arrays.
Example:
solidity
Copy code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract ArrayExample {
// Fixed-size array
uint[5] public fixedArray = [1, 2, 3, 4, 5];
// Dynamic array
uint[] public dynamicArray;
2. Enums in Solidity:
Enums (short for enumerations) are user-defined types that consist of a set of named
constants, representing integral values. Enums help in making the code more readable by
replacing integers with meaningful names.
Features of Enums:
• Useful for representing a set of related values, such as states or actions.
• The first value in the enum is represented by 0, the second by 1, and so on.
• The default value for an enum is its first value.
Example:
solidity
Copy code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract EnumExample {
// Define an enum with states
enum Status { Pending, Shipped, Delivered, Canceled }
3. Structs in Solidity:
Structs are custom data types that allow you to group different data types together. They are
useful for modeling more complex entities like records or objects.
Features of Structs:
• A struct can contain variables of different types.
• It allows grouping related data into a single entity.
• Can be nested and used within arrays or mappings.
Example:
solidity
Copy code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract StructExample {
// Define a struct
struct Person {
string name;
uint age;
bool isActive;
}
10. Describe the architecture of Ethereum in detail, focusing on its key components and
how they interact?
Ethereum’s architecture is built to support a decentralized platform for smart contracts and
decentralized applications (dApps). Its design extends beyond simple cryptocurrency
transactions, enabling programmable contracts and code execution. Let’s dive into the
architecture of Ethereum and examine its key components and how they interact.
Key Components of Ethereum Architecture:
1. Ethereum Virtual Machine (EVM)
2. Smart Contracts
3. Accounts
4. Ethereum Blockchain
5. Ether (ETH)
6. Gas
7. Consensus Mechanism
8. Nodes and Clients
9. Decentralized Applications (dApps)
2. Smart Contracts:
Smart contracts are self-executing contracts with the terms of the agreement directly written
into code. They automatically enforce the rules and regulations set by the developer.
Interaction with EVM:
• Developers write smart contracts using high-level languages like Solidity.
• The code is compiled into EVM bytecode, which runs on the Ethereum Virtual
Machine.
• Smart contracts are stored on the blockchain and can interact with other contracts,
send transactions, or manage states.
3. Accounts:
Ethereum’s architecture supports two types of accounts, which hold the state and manage
ownership of ether and smart contracts:
Types of Accounts:
• Externally Owned Accounts (EOAs): These are controlled by private keys.
Users or entities control EOAs, and they are the source of most transactions.
EOAs can initiate the execution of smart contracts.
• Contract Accounts (Smart Contract Accounts): These are controlled by
code. A contract account contains the code (smart contract) and can execute it
when triggered by a transaction from an EOA.
Interaction:
• EOAs initiate transactions.
• Contract accounts execute code in response to transactions and can interact
with other contracts or EOAs.
4. Ethereum Blockchain:
The Ethereum blockchain is a decentralized ledger that stores all transactions, smart contracts,
and states. Each block in Ethereum includes:
• Block Header: Metadata like the previous block’s hash, nonce, timestamp, etc.
• Transactions: Lists of transactions, including both ether transfers and smart contract
invocations.
• State: Information about the state of accounts, balances, and smart contracts.
Interaction with Other Components:
• The blockchain stores all the data (transactions, smart contract code, and state).
• Each new block is verified and appended to the chain by miners (in Proof of Work) or
validators (in Proof of Stake).
5. Ether (ETH):
Ether (ETH) is the native cryptocurrency of Ethereum. It serves two primary purposes:
• Store of Value: Ether is used as currency within the Ethereum network for payments
and other transactions.
• Gas Fees: Ether is used to pay for computational resources consumed during smart
contract execution and transactions.
Interaction with Other Components:
• Ether is transferred between accounts in transactions.
• It’s used as gas to pay for smart contract execution and transaction processing.
6. Gas:
Gas is a measure of the amount of computational effort required to execute operations on the
Ethereum network. Every transaction or operation (such as executing a smart contract)
requires gas. Gas is paid in Ether.
Interaction:
• Gas Limit: Each transaction has a maximum gas limit, set by the sender.
• Gas Price: The amount of ether per unit of gas the sender is willing to pay.
• Miners (in PoW) or validators (in PoS) prioritize transactions with higher gas prices
since they receive the gas fees as a reward.
• If a transaction runs out of gas during execution, it is reverted, but the gas is still
consumed.
7. Consensus Mechanism:
Ethereum initially used a Proof of Work (PoW) consensus mechanism, but has transitioned to
Proof of Stake (PoS) with Ethereum 2.0 (also known as the Beacon Chain). The consensus
mechanism ensures that all nodes in the network agree on the state of the blockchain.
Interaction:
• PoW (before Ethereum 2.0): Miners solved cryptographic puzzles to add new
blocks and secure the network. Miners were rewarded with ETH for their work.
• PoS (Ethereum 2.0): Validators are chosen to create new blocks based on the
amount of ETH they stake as collateral. Validators are rewarded with ETH for their
participation.