EVM
EVM
The Ethereum Virtual Machine (EVM) is key to the Ethereum blockchain, allowing
smart contracts and decentralized applications (DApps) to run.
When developers write smart contracts in Solidity, the EVM runs them, manages
changes, and executes transactions based on the rules.
It uses gas to manage computing power and keep things fair.
The Ethereum Virtual Machine (EVM) is a decentralized system that runs smart contracts
on the Ethereum network.
It runs Ethereum accounts and smart contracts, allowing developers to create apps
without needing a central authority.
Decentralization: The EVM runs across many nodes, meaning no one controls how
contracts run.
Turing Completeness: The EVM can perform any computation that can be described with
an algorithm, as long as there are enough resources.
Smart Contract Execution: The EVM executes a deployed smart contract, processing
inputs and managing state changes on the blockchain.
Gas Mechanism: Each operation in the EVM needs "gas," a measure of computing effort.
Users pay gas fees to encourage miners to process transactions.
Isolation: Each smart contract runs separately, so one contract's execution doesn't affect
another.
State Management: The EVM keeps track of the current state of all accounts and
contracts on the Ethereum network.
Purpose of EVM
Execution of Smart Contracts: The EVM runs smart contracts, automating transactions
without trust issues.
Decentralization: The EVM runs on a distributed network, ensuring no single entity
controls contract execution, increasing trust and security.
State Management: The EVM keeps track of all accounts and contracts' states, ensuring
consistency.
Resource Management: The gas system regulates resource usage, preventing misuse
and ensuring fairness.
Compatibility: The EVM allows developers to use languages like Solidity to create apps
that run on Ethereum, simplifying development.
Turing Completeness: The EVM can perform any algorithmic computation, offering
flexibility for various applications.
Security: The EVM isolates contracts to prevent interference, enhancing security.
Stack-Based Architecture: The EVM uses a stack to manage data, with up to 1024
items for calculations.
Memory: The EVM has temporary memory that is cleared after each transaction.
Persistent State: Each contract has its own storage on the blockchain to keep its state
between transactions.
Global State: The EVM tracks all accounts, contracts, and their balances.
Instruction Set: The EVM uses predefined operations (opcodes) to process data and
interact with memory/storage.
Gas Management: Each operation uses gas, which prevents excessive resource use and
protects the network.
Execution Environment: The EVM ensures consistent contract execution, producing the
same result on all nodes.
Interoperability: Other blockchains can use the EVM to run Ethereum-compatible smart
contracts.
SOLIDITY
Ethereum
A smart contract is a computer program that sends digital money or items when rules are
followed.
A smart contract is like a regular contract, but it also makes sure the rules are followed
automatically.
Smart contracts are computer programs that follow the instructions given by their creators
exactly.
Just like regular contracts are enforced by law, smart contracts are enforced by computer
code.
The Bitcoin network was the first to use smart contracts to send value from one person to
another.
The smart contract makes sure the sender has enough value before transferring it.
Later, Ethereum became more powerful because it allowed developers to create custom
contracts using a flexible programming language.
Bitcoin contracts used a basic language, which limited what they could do.
Common smart contract platforms include Ethereum, Solana, Polkadot, and Hyperledger
Fabric.
Features of Smart Contracts
Distributed: Everyone on the network has a copy, and no one can change it alone.
Deterministic: The outcome is always the same if the conditions are met.
Immutable: Once created, it can't be changed, only removed if necessary.
Autonomy: No third parties are involved; the contract runs on the network.
Customizable: The contract can be customized before launch.
Transparent: The contract's code is visible to everyone on the blockchain.
Trustless: No third parties are needed to verify the contract's actions.
Self-verifying: The contract checks if conditions are met automatically.
Self-enforcing: The contract enforces the rules when conditions are met.
DAOs are democratic organizations where voting power is given by a smart contract.
DAOs are democratic organizations where voting power is given by a smart contract.
There is no executive or president in a DAO.
The organization's operations and asset distribution are managed by blockchain rules in
the contract's code.
An example of this type of smart contract is VitaDAO, which uses technology to support
a community focused on scientific research.
Application logic contracts (ALCs) are codes that handle and connect with several other
blockchain contracts.
It allows devices to interact with each other, such as integrating blockchain and the
Internet of Things (IoT).
These are signed between computers and contracts, instead of between people or
organizations like other smart contracts.
1. Identify Agreement: Parties agree on goals, like business processes or asset swaps.
2. Set Conditions: Smart contracts start when conditions like market changes or GPS
locations are met.
3. Code Business Logic: A program is made to run automatically when conditions are met.
4. Encryption and Blockchain: Encryption ensures secure messaging and verification.
5. Execution and Processing: After agreement, the code runs, and results are recorded.
6. Network Updates: After execution, all nodes update their ledgers, and the record is
permanently added to the blockchain.
Applications of Smart Contracts
Real Estate: Smart contracts can reduce fees paid to middlemen by transferring
apartment ownership once the agreed payment is made to the seller’s account.
Vehicle Ownership: A smart contract can track vehicle maintenance and ownership. For
example, it could require maintenance every six months, with penalties for non-
compliance.
Music Industry: Smart contracts can record music ownership and automatically pay
royalties when the song is used commercially, also helping to resolve ownership disputes.
Government Elections: Once votes are logged on a blockchain, it’s almost impossible to
alter the results, increasing trust in the election process.
Management: Smart contracts can automate and streamline decisions in management,
ensuring transparency and efficiency. For example, triggering raw material supply when
production reaches a certain amount.
Healthcare: Smart contracts can prevent fraud by automating healthcare payments.
Treatments are recorded, and patients can’t leave the hospital until the bill is paid.
1. Reentrancy Attack: An attacker repeatedly calls a contract’s function before the first
call finishes, draining its funds or causing errors.
2. Front-Running Attack: An attacker intercepts and modifies a pending transaction,
paying a higher gas fee to get their transaction executed first.
3. Denial of Service (DoS) Attack: Overloading the contract with requests, causing it to
become unresponsive or fail.
4. Integer Overflow/Underflow Attack: Manipulating number values to cause unexpected
results by exceeding or going below limits.
5. Unsecured Use of tx.origin: Using tx.origin for access control, making it easier for
attackers to trick users into calling malicious contracts.
6. Timestamp Dependence Attack: Manipulating block timestamps to exploit contract
behavior that depends on time.
7. Unprotected Selfdestruct Function: An attacker can destroy a contract by triggering the
selfdestruct function if it’s not protected.
8. Gas Limit and Loops Attack: Exploiting contracts with loops or inefficient code to use
too much gas, causing failures or delays.
9. Cross-Contract Vulnerability: Weaknesses when contracts interact, which can be
exploited if not properly secured.
10. Flash Loan Attack: Borrowing large amounts of crypto without collateral to exploit
weaknesses in decentralized protocols in one transaction.
11. Short Address Attack: Exploiting contracts that don’t validate address lengths, causing
errors or exploits.
12. Uninitialized Variables Attack: Exploiting contracts with uninitialized variables that
cause unexpected behavior.
13. Delegatecall Attack: Using delegatecall to execute malicious code from another
contract, leading to vulnerabilities.
14. Storage Collision Attack: When multiple contracts share storage slots, one can
overwrite data, causing errors or breaking logic.
15. Function Visibility Attack: Making sensitive functions public or external, allowing
unauthorized access or manipulation.
16. Block Gas Limit Attack: Forcing a contract to exceed the gas limit, causing transactions
to fail or block other transactions.
17. Malicious Contract Deployment: Deploying contracts with hidden vulnerabilities or
malicious code to steal funds or cause harm.
18. Oracle Manipulation Attack: Manipulating external data provided to a smart contract,
such as price feeds or weather data.
19. Governance Attack: Exploiting decentralized governance to manipulate decisions or
control the network.
20. Bridge Attack: Exploiting weaknesses in cross-chain bridges to steal funds or alter
transactions.
UNIT-5
The "Cave of Ali Baba" analogy is often used to explain Zero-Knowledge Proofs (ZKPs) in a
simplified and intuitive way. Let's break it down step-by-step:
The Setup
The Cave: Imagine a cave with two doors, A and B. These doors are connected by a
tunnel, but one of the doors (let's say, Door A) has a hidden secret passage that allows a
person to travel between both doors without going through the tunnel.
You (the Prover): You know which door (A or B) has the secret passage, but your goal
is to prove this knowledge without revealing which door it is.
Your Friend (the Verifier): They stand outside the cave and want to verify that you
know the secret passage without learning which door has it.
The Problem
The main challenge here is that you want to prove to your friend that you know which
door has the secret passage (and thus can exit from either door when asked) without
revealing which door it is. This is the essence of a Zero-Knowledge Proof: Prove your
knowledge without revealing any additional information.
After several rounds, your friend becomes convinced that you know the secret passage
because you consistently exit through the correct door, even when they call for a door
different from the one you initially entered.
However, they still don’t know which door has the secret passage. They only know
that you are able to move between the two doors at will, but they don’t learn anything
about which specific door contains the secret passage.
Thus, you’ve proven your knowledge (the secret passage) without revealing the secret —
that's what makes this a Zero-Knowledge Proof. You prove you know the secret without
disclosing any information about the secret itself.
Key Takeaways
Zero-Knowledge: The verifier is convinced you know the secret, but they don’t learn
any new information.
Security: The more rounds the process repeats, the more confident the verifier becomes
that you know the secret passage, but they never learn which door it is.
Features:
Completeness:
If a statement is true, an honest prover can successfully convince an honest verifier.
This means that if the prover knows the secret and the statement is true, the verifier will
be convinced of its validity.
Soundness:
If a statement is false, a dishonest prover cannot convince an honest verifier.
This property prevents cheating or misrepresentation.
Zero-Knowledge:
The verifier only learns whether the statement is true, without gaining any additional
details.
The proof only confirms the statement's truth without revealing any underlying
information.
zk-SNARKs
zk-SNARKs are a cryptographic system that allows one party to prove to another that
they know a secret without exposing the secret itself.
They are known for their efficiency, providing small proof sizes and fast verification
times.
zk-SNARKs are commonly used in cryptocurrencies like Zcash to achieve privacy and
scalability.
zk-STARKs
1. Privacy-Preserving Transactions
Example: Zcash uses zk-SNARKs to allow private transactions where sender, receiver,
and amount are hidden, but still verified by the network.
Benefit: Maintains user privacy without sacrificing security.
2. Scalability Solutions
zk-Rollups: Aggregate many transactions off-chain and use a ZKP to prove their validity
on-chain (e.g., zkSync, StarkNet).
Benefit: Reduces on-chain data, lowers gas fees, and increases throughput.
Use Case: Proving someone is over 18 or holds a specific credential without revealing
their full identity.
Benefit: Enables compliance (like KYC) without exposing sensitive data.
4. Secure Voting
Use Case: Prove that a vote was cast correctly without revealing who voted for whom.
Benefit: Increases trust in blockchain-based voting systems.
Use Case: Prove access rights to smart contracts or systems without revealing the access
key or password.
Benefit: Enhances security and reduces risk of leaks.
6. Cross-Chain Communication
Use Case: Prove events happened on one chain to another chain without revealing
sensitive details.
Benefit: Enables private and secure interoperability between blockchains.
Here are some real-world examples of how Zero-Knowledge Proofs (ZKPs) are being used in
blockchain and beyond:
1. Zcash – Privacy-Preserving Cryptocurrency
Projects:
o zkSync
o StarkNet
o Polygon zkEVM
Use of ZKPs: zk-SNARKs / zk-STARKs
Purpose: Bundles thousands of transactions off-chain, then posts a single ZKP to the
Ethereum mainnet.
Impact: Greatly increases transaction throughput and lowers gas fees.
Use Case: Voters can prove they voted and that their vote was valid without revealing
who they voted for.
Example Project: Semaphore by the Ethereum Foundation
Impact: Enables anonymous yet verifiable voting on-chain.
zk-SNARKs
zk-SNARKs are a cryptographic system that allows one party to prove to another that
they know a secret without exposing the secret itself.
They are known for their efficiency, providing small proof sizes and fast verification
times.
zk-SNARKs are commonly used in cryptocurrencies like Zcash to achieve privacy and
scalability.
APPLICATIONS
zk-SNARKs (Zero-Knowledge Succinct Non-Interactive Arguments of Knowledge) help
blockchains be more private and efficient. Here's a simpler breakdown:
Privacy: zk-SNARKs let someone prove they know something (like a valid transaction)
without showing the actual information. So, sensitive data stays private but is still
verified.
Scalability: zk-SNARKs make it faster to check if data is correct by not needing to
process all the details. This keeps the blockchain efficient and helps it scale better.
This is done using small, quick proofs that don’t require back-and-forth communication,
making it easy and fast to verify transactions and calculations.
1. Private Transactions: Cryptos like Zcash use zk-SNARKs to hide transaction details
while ensuring they’re valid.
2. Rollups: zk-SNARKs process transactions off-chain and verify them on-chain with one
proof, making things faster and cheaper.
3. Scalability: zk-SNARKs combine many transactions into one proof, improving
blockchain efficiency.
4. Anonymous Payments: zk-SNARKs keep identities and transaction details private in
payment channels.
5. zkVMs: zk-SNARKs run computations without revealing any data.
6. Secure Voting: zk-SNARKs let users prove they voted without showing how or for
whom.
7. Confidential Finance: zk-SNARKs keep financial services private, like lending or DeFi.
8. Identity Verification: zk-SNARKs let users prove who they are without revealing
personal details.
9. Data Integrity: zk-SNARKs verify data is accurate without showing the actual data.
10. Compliance: zk-SNARKs prove legal compliance without sharing sensitive information.
11. Software Updates: zk-SNARKs ensure software updates are valid without exposing
private code.
12. Biometric Verification: zk-SNARKs allow users to prove identity with biometrics,
keeping data private.
Zero-Knowledge Proof (ZKP) protocols allow one party to prove they know something without
revealing the actual information. These protocols ensure privacy while confirming validity.
There are different types of ZKPs, each with specific use cases:
4. zk-STARKs:
5. Bulletproofs:
6. Sigma Protocols:
7. Fiat-Shamir Heuristic:
Use Cases:
ZKPs are powerful tools for protecting privacy while ensuring security in various applications.
Here’s a structured summary of various Zero-Knowledge Proof (ZKP) protocols and their use
cases:
3. Bulletproofs
4. zk-Rollups
6. Halo
7. Groth16
9. zkLedger
11. Nightfall
Z CASH
Zcash Features
Privacy:
Functionality:
Bitcoin-Based Code: Zcash is built on Bitcoin’s code but with added privacy features
and the same 21 million coin limit.
Proof-of-Work (PoW): Like Bitcoin, Zcash uses miners to validate transactions through
complex problem-solving.
Fast & Low Fees: Zcash offers quicker transactions and lower fees than Bitcoin.
Self-Funded Development: Developers are paid by the network to keep improving
Zcash.
Zcash Foundation: A non-profit group that helps manage and upgrade the protocol.
Private Messages: Users can send encrypted messages with their transactions.
User Control: As a decentralized network, users fully control their Zcash.
Open Access: Anyone with internet access can use Zcash.
Working of Zcash:
Use Cases:
Challenges:
Regulatory Scrutiny: Governments may investigate privacy coins for potential misuse.
Competition: Competes with other privacy coins like Monero and Dash.
EATHEREUM WALLETS (UNIT-4)
Types of Wallets
There are several types of Ethereum wallets, each offering different levels of security, user-
friendliness, and control over your private keys. The main types of Ethereum wallets are:
1. Software Wallets
These are applications or software that you can install on your computer or mobile device. They
offer convenience but may be less secure compared to hardware wallets.
2. Hardware Wallets
These are physical devices that store your private keys offline. They are considered one of the
most secure options for storing Ethereum.
3. Web Wallets
Web wallets are accessed through your web browser. These are generally easy to use but depend
on the security of the service provider.
4. Paper Wallets
A paper wallet is a physical document that contains your private and public keys. It’s considered
highly secure because it's offline, but it can be easily lost or damaged.
5. Cold Wallets
These are wallets that are not connected to the internet, such as hardware wallets and paper
wallets. They are used for long-term storage, making them immune to online attacks.
6. Hot Wallets
Hot wallets are connected to the internet and can be accessed anytime, which makes them
convenient for daily transactions. However, they can be vulnerable to hacks.
7. Multisignature Wallets
These wallets require more than one private key to authorize a transaction, offering an extra layer
of security. Multisig wallets are commonly used for organizational or group purposes.
Each type of wallet offers different trade-offs in terms of convenience, security, and control over
your Ethereum assets. For most everyday users, software or mobile wallets like MetaMask or
Trust Wallet work well. For those looking for maximum security, hardware wallets like Ledger
or Trezor are recommended.
Here are some additional Ethereum wallets, each with different features:
1. MyEtherWallet (MEW)
A web wallet that lets you control your keys and interact with Ethereum.
2. Coinbase Wallet
3. MetaMask
4. Trust Wallet
A mobile wallet for Ethereum and other cryptos with dApp support.
5. ZenGo
6. Argent
7. Exodus
8. ImToken
A mobile wallet for Ethereum and ERC-20 tokens with dApp support.
9. BlockFi Wallet
10. Fortmatic
11. Keeper
These wallets offer different levels of convenience, security, and features for various users. For
instance, Trust Wallet is great for mobile users, while Exodus and MetaMask are popular for
DeFi and desktop use.
Features :
Software Wallets
Hardware Wallets
Other Options