FINS5547-无代写
时间:2023-04-10
Special Topics in Ethereum
FINS5547 – Cryptocurrency and Decentralised Finance
2023 Semester 1
Q&A - Why hold stablecoins over USD?
● No access to US banking system when situated in hyperinflating economy.
○ Majority of DeFi ecosystem is permissionless.
● Enticing DeFi yield opportunities:
Aave v2 Deposit Annual Percentage rate
(USDC) - YieldSamurai
Aave v2 Deposit Annual Percentage rate
(USDT) - YieldSamurai
Crypto Bulletin
sourcesource
This lecture…
● Scalability (Alternative L1s and L2 solutions)
○ Blockchain tri-lemma problem (Decentralisation, Scalability, Security)
○ L1 sharding scaling solution
○ L2 scaling solution(s)
○ Bridging & Wrapped Token variants
● In-class Practical Exercise:
○ Deploy your own ERC20 Token
○ Create a AMM for it
Different constructs within DeFi
From: “SoK: Decentralized Finance (DeFi)
2021”
Understanding the DeFi “Stack”
● Layer 5: the aggregation layer
● Layer 4: the application layer
● Layer 3: the protocol layer
● Layer 2: the asset layer
● Layer 1: the settlement layer
Source: Schär, Fabian. (2021). Decentralized Finance: On
Blockchain- and Smart Contract-Based Financial Markets. Federal
Reserve Bank of St. Louis Review.

*Not to be confused with Ethereum Layer 2 solutions:
These are like layer 1.5 in this diagram.
Designing Blockchains: Scalability Trilemma
Designing blockchains is hard, we want it to:
● Be quick: Have our transactions processed as quick as possible (immediate).
● Be powerful: Process as many transactions as possible at one given time.
● Be decentralised: Have no singular owner that can control the chain.
● Be safe: Have our transactions processed securely.
● Be available: Ensure it cannot be shut down and that it’s still usable.
Designing Blockchains: Scalability Trilemma
https://vitalik.ca/general/2021/04/07/sharding.html
Designing Blockchains: Scalability Trilemma
https://vitalik.ca/general/2021/04/07/sharding.html
The chain can process more
transactions than a single regular
node (think: a consumer laptop) can
verify.
Designing Blockchains: Scalability Trilemma
https://vitalik.ca/general/2021/04/07/sharding.html
The chain can process more
transactions than a single regular
node (think: a consumer laptop) can
verify.
The chain can run without any trust
dependencies on a small group of
large centralized actors. This is
typically interpreted to mean that
there should not be any trust (or even
honest-majority assumption) of a set
of nodes that you cannot join with just
a consumer laptop.
Designing Blockchains: Scalability Trilemma
https://vitalik.ca/general/2021/04/07/sharding.html
The chain can process more
transactions than a single regular
node (think: a consumer laptop) can
verify.
The chain can run without any trust
dependencies on a small group of
large centralized actors. This is
typically interpreted to mean that
there should not be any trust (or even
honest-majority assumption) of a set
of nodes that you cannot join with just
a consumer laptop.
The chain can resist a large percentage of
participating nodes trying to attack it (ideally
50%; anything above 25% is fine, 5% is
definitely not fine).
Approaches that don’t quite solve it:
● Traditional blockchains (Decentralization + Security)
○ E.g. Bitcoin, Litecoin, Ethereum, etc
○ Rely on all full nodes to verify all transactions.
● High TPS Chains (Security + Scalability)
○ E.g. Proof-of-Authority chains, DPoS chains, …
○ Rely on a small selected group to run consensus.
● Multi-chain (Decentralization + Scalability)
○ E.g. think of Ethereum and Bitcoin trading together
○ Fault on one chain can ripple out and cause effects to other chains.
○ Attacker only needs to break consensus in one of the chains to cause damages outwards.
Designing Blockchains: Scalability Trilemma
Designing Blockchains: Scalability Trilemma
Proof-of-*
Fork
Choice /
Consensus
Execution Storage
How blocks are
formed.
How miners and
validators are
selected.
What block to
choose if fork.
How transactions
are processed.
Virtual Machine,
etc.
Data structures,
how/where it is
stored.
Hardware? Data
design?
Components that go into a blockchain (high level)
Cool.. seems difficult.
How fix?
Enter: Sharding
✅ Decentralized
✅ Scalable
✅ Secure
First off… what is sharding?
Sharding (decentralized + secure + scalable)
H E L L O
H E L L O
H E L L O
On blockchains?
Sharding (decentralized + secure + scalable)
Global state
● Chains running in parallel, coordinating with
each other.
● Selected committees run the shards and
assist with the global state.
● Designs:
○ Some execute transactions in parallel on different
shards.
○ Others use shards for storing the data.
Sharding (decentralized + secure + scalable)
Traditional
Sharded
(coordination chain)
(e.g: Ethereum Beacon Chain)
Shard
1
Coordination
Chain
(special
shard)
Shard
2
Nodes selection to validate the shards
Enter: Layer 2
(building on top of Layer 1)
Scaling
Examples
Layer 2
Layer 1
Main chain
(E.g. ETH chain, Bitcoin)
Layer 2
Separate chain(s) running
transactions.
Uses layer 1 for
settlement Settlements on
main chain
Layer 2
Layer 1
Main chain
(E.g. ETH chain, Bitcoin)
Layer 2
Separate chain(s) running
transactions.
Uses layer 1 for
settlement Settlements on
main chain
(rollup)
● Net “state change” is calculated on L2
● Processed as one bulk transaction on
L1 (main chain)
● Chains that are operating separately to the
main blockchain.
● Performs actions at different speeds to the
layer 1 infrastructure.
● Regularly bundles (rollup) and
communicates to finalise the changes that
happened.
● General chains OR application specific.
○ E.g. zkSpace is a layer 2 AMM DEX + marketplace
Layer 2
L1 L2
Rollup
(Ethereum) (Optimism)
* If Ethereum forks, destination chain will fork with Ethereum.
Layer 2: Rollups
Optimistic
● Execute transactions in
separate chain.
● Roll up and bundle all tx
changes and send to
layer 1.
● Assume valid
(optimistic), but use
‘waiting period’ to wait
for any fraud proofs to
challenge validity.
Examples:
● General:
○ Arbitrum
○ Optimism
● Application:
○ Loopring
○ zkSpace
○ Aztec
Zero-Knowledge (zk)
● Perform all actions and
computations in separate
chain.
● Roll up and compute a
‘zero-knowledge proof’ to
prove the computation of
the transactions without
revealing details.
● Send rollup proof to layer
one that can be verified.
Layer 2: Rollups (Arbitrum Nitro)
https://developer.arbitrum.io/inside-arbitrum-nitro
These seem cool, how do I interact with these
layer 2 chains?
Bridges
● Think of what a physical bridge does in the world
○ Connects two locations together.
● A blockchain bridge is used to connect two chains together.
● Similar to a currency exchange platform, the bridge is used to convert assets
to be used on other chains.
Bridges
Ethereum Arbitrum
?
1 ETH
Bridges
Ethereum Arbitrum
1 ETH
10 ETH
*note: often there may be multiple contracts to
mint/burn on the relevant chains
Bridge
Contracts
Bridges
Ethereum Arbitrum
1 ETH
10 ETH
*note: often there may be multiple contracts to
mint/burn on the relevant chains
Bridge
Contracts
Bridges
Ethereum Arbitrum
11 ETH
*note: often there may be multiple contracts to
mint/burn on the relevant chains
Bridge
Contracts
Bridges
Ethereum Arbitrum
1 ETH
11 ETH
*note: often there may be multiple contracts to
mint/burn on the relevant chains
Bridge
Contracts
Bridges
Ethereum Arbitrum
11 ETH
0.5 ETH
Perform tx for 0.5ETH
*note: often there may be multiple contracts to
mint/burn on the relevant chains
Bridge
Contracts
Bridges
Ethereum Arbitrum
11 ETH
0.5 ETH
Withdraw
*note: often there may be multiple contracts to
mint/burn on the relevant chains
Bridge
Contracts
Bridges
Ethereum Arbitrum
10.5 ETH
Withdraw
0.5 ETH
*note: often there may be multiple contracts to
mint/burn on the relevant chains
Bridge
Contracts
Type of Bridges
Trusted Bridge (Custodial)
● Users place trust in a central entity.
● Users give control up of the assets and
rely on bridge operator reputation.
● Example: WBTC (wrapped bitcoin)
custody by BitGo [source]
Trustless Bridge (Non-custodial)
● Operate using a smart contract or
protocol.
● Security of bridge relies on underlying
blockchains and contract code.
● Example: Solana wormhole bridge
[source]
Chain A Chain BTrusted
Entity
Chain A Chain B
Contracts + Protocols
Bridges and Wrapped Tokens
● Minting:
a. User locks coin/asset into contract OR sends to custodian.
b. Equivalent amount of wrapped tokens are minted on the other chain.
● Burning:
a. User burns the wrapped tokens.
b. The locked coin/asset is transferred back to the user.
Bridge: Wormhole Example (ETH ERC20 → SOL SPL)
https://solana.com/news/wormhole---solana-ethereum-bridge
Bridge: Wormhole Example (SOL SPL → ETH ERC20)
https://solana.com/news/wormhole---solana-ethereum-bridge
Bridges and Wrapped Tokens
● Wrapped tokens allow using different currencies or tokens on other blockchains.
● Wrapped tokens are pegged 1:1 with the original asset
○ E.g. 1 WBTC =~ 1 BTC
● Goal is to introduce more interoperability between blockchains.
● DEXs usually run on smart contract platforms.
○ Need to ‘wrap’ coins to trade with chains that don’t (e.g. BTC → wBTC).
● Examples:
○ WBTC - wrapped bitcoin for use on the Ethereum chain.
○ WETH - ERC20 equivalent of ETH for use on layer 2 and other DeFi applications.
○ WBNB - Wrapped tokens on the BNB Smart Chain and can be traded for
Wrapped Assets: Fragmentation
There is no rules saying an asset can only be wrapped by one protocol or represented
by only one bridge.
BitGo Bridge
Threshold Bridge
renVM Bridge
.
.
.
Bitcoin Blockchain Ethereum Blockchain
WBTC
tBTC
renBTC
Wrapped Bitcoin on Ethereum
Supply of Bitcoin on Ethereum (3yrs outdated set)
dune
BTC variants on Curve
WBTC & tBTC
WBTC (~150k circulating supply)
● Launched Jan, 2019.
● Centralised custodian holds all bitcoin.
● Minting/Issuance of WBTC ERC20 is
handled by a DAO comprising of 17 DeFi
members.
tBTC v2 (~500 circulating supply)
● Launched Jan, 2023.
● Bitcoin is stored in shared wallet among
threshold token stakers.
● New bitcoin wallet comprising of 100
stakers periodically created.
● Collectively must produce 51/100
signatures to move funds.
Bridges: Risks
● Trusting a protocol/third party to facilitate cross-chain activity.
○ Smart contract - bugs, exploits, malicious strategies …
○ Third party/custodian - holding and releasing assets, censorship, …
● Over $1.9 billion was stolen in cross-chain hacks in the first half of 2022.
● Notable Bridge Hacks:
Axie Infinity
$625 Million
Polynetwork
$610 Million
(returned)
Wormhole
$320 Million
Axie Infinity – Ronin Bridge Hack
● March 2022
● Identified to have links to North Korean
cryptocurrency hacker groups
● At stage in interview process, engineer
received a PDF file containing the
exploitative code.
● Enabled hackers to corrupt four Sky
Mavis validators and one Axie DAO
validator.
● Bridge required 5/9 multi-sig.
L2Beat
Provides transparency of risks about the
current state of bridges & L2s.
Key fields:
● Validated by – Who’s checking messaging sent by
the bridge
● Type – Token (Escrow+Mint) versus Liquidity
Network (Using LPs & swaps)
l2beat.com
Practical Exercise - Deploying your own ERC20
1) Navigate to https://remix.ethereum.org/
2) Create a new file called something.sol
3) Navigate to openzeppelin ERC20 docs
4) Copypasta sample code into something.sol
a) Amend the code to contain the token name and ticker you wish for.
Practical Exercise - Deploying your own ERC20
5) Navigate the panel on the left hand side and click “Solidity Compiler”.
Proceed to “Compile something.sol”
NOTE: Ensure the compiler version is set to “0.8.18+commit.87f61d96”
Practical Exercise - Deploying your own ERC20
6) Navigate the panel on the left hand side and click
“Deploy & Run Transaction”.
7) Select “Injected Provider - MetaMask” as environment
(Ensure that you’re connected to Goerli testnet)
8) Specify the total supply of your token, and then click
‘Deploy’ and sign transaction.
essay、essay代写