0% found this document useful (0 votes)
57 views17 pages

Mehnat

Uploaded by

cmpn.20102b0008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views17 pages

Mehnat

Uploaded by

cmpn.20102b0008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Assignment 5: Explain fixed and dynamic arrays in solidity

Fixed and dynamic arrays are two fundamental data structures in Solidity, the
programming language used to develop smart contracts on the Ethereum blockchain.
They both serve the purpose of storing collections of data, but they differ in their
flexibility and memory allocation.

Fixed Arrays

Fixed arrays, as the name suggests, have a predetermined size specified at the time of
declaration. This means that the number of elements the array can hold is fixed and
cannot be changed during runtime. Once initialized, a fixed array's length remains
constant.

Advantages of Fixed Arrays:


• Memory efficiency: Fixed arrays are memory-efficient when the size of the data
collection is known beforehand. They allocate memory for the specified number
of elements, preventing unnecessary memory usage.
• Predictable gas costs: Operations on fixed arrays have predictable gas costs, as
the array's size is known. This makes them suitable for scenarios where gas
optimization is crucial.
Disadvantages of Fixed Arrays:
• Limited flexibility: Fixed arrays lack flexibility when the size of the data collection
is not predetermined. They cannot be resized to accommodate more or fewer
elements.
• Potential for out-of-bounds errors: Attempting to access elements beyond the
fixed size of the array can lead to out-of-bounds errors.
Dynamic Arrays

Dynamic arrays, on the contrary, have their size determined at runtime. This means that
the number of elements they can hold can be dynamically adjusted as needed. Dynamic
arrays grow and shrink as elements are added or removed.

Advantages of Dynamic Arrays:


• Flexibility: Dynamic arrays offer flexibility in accommodating data collections of
varying sizes. They can grow or shrink as needed, adapting to the changing
requirements of the application.
• Suitable for unknown data sizes: Dynamic arrays are ideal for situations where
the exact size of the data collection is unknown or may change over time.
Disadvantages of Dynamic Arrays:
• Less memory efficient: Dynamic arrays may allocate more memory than
necessary, as they reserve space for potential additions. This can be an issue for
memory-constrained environments.
• Variable gas costs: Operations on dynamic arrays can have variable gas costs,
depending on the current size of the array. This makes gas optimization more
challenging.
Choosing the Right Array Type

The choice between fixed and dynamic arrays depends on the specific requirements of
the smart contract. If the size of the data collection is known and unlikely to change,
fixed arrays offer memory efficiency and predictable gas costs. However, if the data
collection's size is uncertain or may vary, dynamic arrays provide the flexibility to adapt
to changing needs.
Assignment 6:
Assignment 7:

Differentiate between blockchain frameworks and give real world applications of any 3 frameworks.
Assignment 8:
Assignment 9

Give 4 real world applications for RAFT and PAXOS algorithm in blockchain

RAFT Algorithm Applications:

1. Distributed Databases: RAFT ensures data consistency and replication across


multiple nodes in distributed databases like Apache Cassandra and etcd. It
maintains a single leader to accept updates and propagates those updates to the
followers, ensuring all nodes maintain consistent data copies.

2. Distributed File Systems: In distributed file systems like HDFS and Cloud
Spanner, RAFT maintains data integrity and enables efficient access in large-
scale distributed environments. It ensures that all nodes agree on the location
and content of the data, preventing data inconsistencies and enabling efficient
file operations.

3. Container Orchestration: RAFT plays a crucial role in container orchestration


platforms like Kubernetes, where it manages cluster state through etcd. It
ensures consistent coordination and resource management across containerized
applications, enabling seamless scaling and deployment of containers.

4. Log Replication Systems: RAFT is widely used in log replication systems, such
as Apache Kafka and Apache ZooKeeper, to maintain a consistent and durable
log of events across multiple servers. It ensures that all nodes agree on the order
and content of the log entries, enabling reliable and consistent data replication.

PAXOS Algorithm Applications:

1. Blockchain Networks: PAXOS is a core consensus algorithm in blockchain


technology, enabling networks like Hyperledger Fabric and Burrow to achieve
agreement on the order and validity of transactions. It ensures that all nodes
agree on the current state of the blockchain, preventing double-spending and
maintaining the integrity of the ledger.

2. Distributed Systems with High Availability Requirements: PAXOS is well-suited


for distributed systems where high availability and fault tolerance are critical,
such as financial systems and e-commerce platforms. It ensures data integrity
and consistency even in the face of node failures, providing a robust foundation
for mission-critical applications.

3. Replication Systems: PAXOS is used in replication systems, such as Ceph and


GlusterFS, to replicate data across multiple servers for high availability and fault
tolerance. It ensures that all replicas maintain consistent data copies, enabling
seamless failover and data recovery in case of server failures.

4. Distributed Coordination Services: PAXOS is employed in distributed


coordination services, such as Apache Curator and etcd, to provide a consistent
and reliable coordination mechanism for distributed applications. It ensures that
all nodes agree on the current state of the coordination data, enabling efficient
resource management and task scheduling across the distributed system.
Assignment 10:

Explain supply chain management case study using hyperledger


Assignment 11:

Explain working of defi in finance system and how it is beneficial as compared to traditional.
Assignment 12:

Q.1 Program for assert, require and revert keywords in error handling.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ErrorHandlingExample {
function withdraw(uint256 amount) public {
assert(balances[msg.sender] >= amount);
balances[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
}

function withdraw(uint256 amount) public {


require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
if (!msg.sender.send(amount)) {
revert("Failed to send funds");
}
}

function transfer(address recipient, uint256 amount) public {


require(amount > 0, "Amount must be greater than 0");
balances[msg.sender] -= amount;
balances[recipient] += amount;
}
}

Q.2 Check a website etherscan.io and explain any five functionalities of it in detail.

etherscan.io is a popular blockchain explorer for the Ethereum blockchain, providing


users with various tools and information related to Ethereum transactions, addresses,
and smart contracts. Keep in mind that the website may have undergone changes or
updates since then, so it's advisable to verify the current functionalities on etherscan.io.
Here are five common functionalities that were available as of my last update:

1. Blockchain Explorer:
- Etherscan allows users to explore the Ethereum blockchain by providing a user-
friendly interface to browse through blocks, transactions, and addresses. Users can
enter a specific block number, transaction hash, or Ethereum address to retrieve
detailed information about it. This functionality is essential for tracking and verifying
transactions on the Ethereum network.

2. Transaction Details:
- For any given transaction, Etherscan provides a comprehensive set of details. This
includes information such as the sender and recipient addresses, transaction status,
gas used, gas price, and the transaction hash. It also displays the contract address if
the transaction involves a smart contract.

3. Address Information:
- Users can look up detailed information about Ethereum addresses using Etherscan.
This includes the balance of Ether and any ERC-20 tokens associated with the address,
as well as the list of transactions sent and received. It provides a transparent view of an
address's activity on the Ethereum network.

4. Token Tracker:
- Etherscan includes a token tracker feature that allows users to explore and monitor
ERC-20 and ERC-721 tokens. Users can view token contract details, including the total
supply, holders, and recent transfers. This feature is particularly useful for tracking the
distribution and movement of various tokens on the Ethereum blockchain.

5. Smart Contract Interaction:


- Etherscan enables users to explore and interact with smart contracts deployed on
the Ethereum blockchain. Users can view the contract source code, ABI (Application
Binary Interface), and contract creation details. Additionally, Etherscan facilitates the
verification of smart contract source code, adding transparency and trust to the
Ethereum ecosystem.
Q.3 Drawbacks of 3BFT and 4BFT and how they are resolved using PBFT in tabular form.

You might also like