Bsides Ahmedabad - Dark Side of DeFi
Bsides Ahmedabad - Dark Side of DeFi
Bsides Ahmedabad - Dark Side of DeFi
Who are we
ArbazKiraak 0xrudrapratap
@immunefi-team/community-challenges
https://immunefi.medium.com
Agenda
○ Logged in as victim.
Missing Random Nonce
When a cryptographic signature intended for a single use is permitted to be replayed repeatedly, leads to
signature replay attacks.
Applications that generate signatures but do not use a random nonce to generate the signatures are vulnerable to
replay attacks.
If an application only verifies the user-supplied signature without validating whether the provided message and signature
are the same as those required by the application to generate JWT tokens, an authentication bypass could happen.
Validator Arbitrary accepts any message hash
source: coindesk
Decentralized finance (DeFi)
● It’s lets users buy and sell assets and perform financial services as a form
of investment or financing without middleman.
02 Griefing vulnerability
01 STATIC - CALL
02 DELEGATE-CALL
Re-entrancy attack (call method)
0 5 0
SAVE STATE
CONTRACT-A CONTRACT-B
1 ….. 0
Storage layout
● Using this method, contract can preserve the storage state while using the logic of contract.
The proxy contract redirects all the calls it receives to an logic contract, whose address is
stored in its (Contract A’s) storage.
The proxy contract runs Contract B’s code as its own, modifying the storage and balance
of Contract A.
Types of Proxies Patterns
1. Transparent Proxy Pattern (TPP)
By calling the upgrade function, the storage slot on the proxy contract is updated to point to a
new logic contract.
Uninitialized proxy bug
● Lot of developers often leave the contracts uninitialized. This is not an problem in
most cases, but problematic when it leads to some major changes like: granting
ownership to the caller.
● This bug can lead to the self-destruction of the logic contract, which could render
the proxy contracts useless.
CALL DELEGATE CALL
Normal Workflow.
CALL
Its storage and code are erased from the
DELEGATE CALL blockchain.
( PROXY)
Proxy contract is bricked.
( DATA )
UUPS pattern uninitialized proxy bug
Wormhole bridge protocol : Attacker can held the entire protocol for ransom ($1.8 billion)
$10M Bounty : https://medium.com/immunefi/wormhole-uninitialized-proxy-bugfix-review-90250c41a43a
POC: https://github.com/immunefi-team/wormhole-uninitialized
Push vs Pull Pattern
NFT AUCTION 20
D
BI
0$
0$
10
0$
BI
10
ND
D
FU
RE
(USER-1) (USER-2)
https://github.com/immunefi-team/community-challenges/blob/master/contracts/vulnerable/Auction.sol
Auction Workflow (Push vs Pull)
NFT AUCTION 1. Malicious user deploys Evil contract containing exception
condition to revert any incoming calls.
20
UN
D
0$
BI
NFT AUCTION
BI
RE
0$
D
10
CT
JE
RE
(USER)
( EVIL )
20
BI
0$
0$
10
0$
oy
BI
10
D
pl
AI
De
CL
(ATTACKER)
(USER-1) (USER-2)
Push Pattern
Pull Pattern
Spot Price Dependency
Price Oracles
P(y) = Y / X
● Manipulating the large volume with flash loan (considering high liquidity)
● Exploiting on borrowing platform as example. (spot price dependency)
Spot Price Dependency Example
10 ETH,
100k USDT ETH/USDT
Supply 1 ETH querying price of 1 ETH
ETH/USDT
10 ETH,
100k USDT querying price of 1 ETH
Supply 8 ETH
$10k
8 ETH Borrow 72K USDT ORACLE
VAULT
Hard choices, but better than spot price
● M-of-N Reporters
○ Averaging the price between the multiple AMM products like Uniswap,
MakerDAO, Balancer etc , and offchain oracle’s like chainlink.
Who wants to become a Web3 Hacker?
Useful links to get you started
● https://medium.com/immunefi/hacking-the-blockchain-an-ultimate-guide-4
f34b33c6e8b
● https://solidity-by-example.org
● https://github.com/ethereumbook/ethereumbook
● https://github.com/OffcierCia/DeFi-Developer-Road-Map
● https://www.damnvulnerabledefi.xyz
● https://cmichel.io/how-to-become-a-smart-contract-auditor/
● https://ethernaut.openzeppelin.com/
● https://github.com/immunefi-team/community-challenges