Secureum Book
  • 🛡️Secureum Bootcamp
    • 🛡️Secureum Bootcamp
    • 🙌Participate
    • 📜History
  • 📚LEARN
    • Introduction
      • 🔷1. Ethereum Basics
        • 1.1 Ethereum: Concept, Infrastructure & Purpose
        • 1.2 Properties of the Ethereum Infrastructure
        • 1.3 Ethereum vs. Bitcoin
        • 1.4 Ethereum Core Components
        • 1.5 Gas Metering: Solving the Halting Problem
        • 1.6 web2 vs. web3: The Paradigm Shift
        • 1.7 Decentralization
        • 1.8 Cryptography, Digital Signature & Keys
        • 1.9 Ethereum State & Account Types
        • 1.10 Transactions: Properties & Components
        • 1.11 Contract Creation
        • 1.12 Transactions, Messages & Blockchain
        • 1.13 EVM (Ethereum Virtual Machine) in Depth
        • 1.14 Transaction Reverts & Data
        • 1.15 Block Explorer
        • 1.16 Mainnet & Testnets
        • 1.17 ERCs & EIPs
        • 1.18 Legal Aspects in web3: Pseudonymity & DAOs
        • 1.19 Security in web3
        • 1.20 web2 Timescales vs. web3 Timescales
        • 1.21 Test-in-Prod. SSLDC vs. Audits
        • Summary: 101 Keypoints
      • 🌀2. Solidity
        • 2.1 Solidity: Influence, Features & Layout
        • 2.2 SPDX & Pragmas
        • 2.3 Imports
        • 2.4 Comments & NatSpec
        • 2.5 Smart Contracts
        • 2.6 State Variables: Definition, Visibility & Mutability
        • 2.7 Data Location
        • 2.8 Functions
        • 2.9 Events
        • 2.10 Solidity Typing
        • 2.11 Solidity Variables
        • 2.12 Address Type
        • 2.13 Conversions
        • 2.14 Keywords & Shorthand Operators
        • 2.15 Solidity Units
        • 2.16 Block & Transaction Properties
        • 2.17 ABI Encoding & Decoding
        • 2.18 Error Handling
        • 2.19 Mathematical & Cryptographic Functions
        • 2.20 Control Structures
        • 2.21 Style & Conventions
        • 2.22 Inheritance
        • 2.23 EVM Storage
        • 2.24 EVM Memory
        • 2.25 Inline Assembly
        • 2.26 Solidity Version Changes
        • 2.27 Security Checks
        • 2.28 OpenZeppelin Libraries
        • 2.29 DAppSys Libraries
        • 2.30 Important Protocols
        • Summary: 201 Keypoints
      • 🔏3. Security Pitfalls & Best Practices
        • 3.1 Solidity Versions
        • 3.2 Access Control
        • 3.3 Modifiers
        • 3.4 Constructor
        • 3.5 Delegatecall
        • 3.6 Reentrancy
        • 3.7 Private Data
        • 3.8 PRNG & Time
        • 3.9 Math & Logic
        • 3.10 Transaction Order Dependence
        • 3.11 ecrecover
        • 3.12 Unexpected Returns
        • 3.13 Ether Accounting
        • 3.14 Transaction Checks
        • 3.15 Delete Mappings
        • 3.16 State Modification
        • 3.17 Shadowing & Pre-declaration
        • 3.18 Gas & Costs
        • 3.19 Events
        • 3.20 Unary Expressions
        • 3.21 Addresses
        • 3.22 Assertions
        • 3.23 Keywords
        • 3.24 Visibility
        • 3.25 Inheritance
        • 3.26 Reference Parameters
        • 3.27 Arbitrary Jumps
        • 3.28 Hash Collisions & Byte Level Issues
        • 3.29 Unicode RTLO
        • 3.30 Variables
        • 3.31 Pointers
        • 3.32 Out-of-range Enum
        • 3.33 Dead Code & Redundant Statements
        • 3.34 Compiler Bugs
        • 3.35 Proxy Pitfalls
        • 3.36 Token Pitfalls
        • 3.37 Special Token Pitfalls
        • 3.38 Guarded Launch Pitfalls
        • 3.39 System Pitfalls
        • 3.40 Access Control Pitfalls
        • 3.41 Testing, Unused & Redundand Code
        • 3.42 Handling Ether
        • 3.43 Application Logic Pitfalls
        • 3.44 Saltzer & Schroeder's Design Principles
        • Summary: 201 Keypoints
      • 🗜️4. Audit Techniques & Tools
        • 4.1 Audit
        • 4.2 Analysis Techniques
        • 4.3 Specification, Documentation & Testing
        • 4.4 False Positives & Negatives
        • 4.5 Security Tools
        • 4.6 Audit Process
        • Summary: 101 Keypoints
      • ☝️5. Audit Findings
        • 5.1 Criticals
        • 5.2 Highs
        • 5.3 Mediums
        • 5.4 Lows
        • 5.5 Informationals
        • Summary: 201 Keypoints
  • 🌱CARE
    • CARE
      • CARE Reports
  • 🚩CTFs
    • A-MAZE-X CTFs
      • Secureum A-MAZE-X
      • Secureum A-MAZE-X Stanford
      • Secureum A-MAZE-X Maison de la Chimie Paris
Powered by GitBook
On this page
  • Secureum A-MAZE-X Stanford
  • A Smart Contract Security _Capture the Flag_** Workshop**
  • Instructions 🕹️
  • How to play
  • Important note
  • Challenges 🎮
  • Challenge 0: VitaToken seems safe, right?
  • Challenge 1: What a nice Lender Pool!
  • Challenge 2: it's always sunny in decentralized exchanges
  • Challenge 3: borrow, hide and seek
  • CTF Writeup 🗒️🗒️🗒️
  1. CTFs
  2. A-MAZE-X CTFs

Secureum A-MAZE-X Stanford

PreviousSecureum A-MAZE-XNextSecureum A-MAZE-X Maison de la Chimie Paris

Last updated 1 year ago

Secureum A-MAZE-X Stanford

A Smart Contract Security _Capture the Flag_** Workshop**


Instructions 🕹️

This Workshop consists in a series of challenges, of increasing difficulty, targetting different concepts and common vulnerabilities found in DeFi. The CTF is designed in different flavors for all kinds of users.


How to play

This workshop provides different flavors. Feel free to use the one you feel more comfortable with:


Important note

This set of challenges aren't set for competitive purposes. Their main objective is to showcase scenarios involving DeFi, Solidity concepts and common vulnerabilities.

Focus on learning and having fun! 😊


Challenges 🎮

Challenge 0: VitaToken seems safe, right?

Let's begin with a simple warm up. Our beloved Vitalik is the proud owner of 100 $VTLK, which is a token that follows the ERC20 token standard. Or at least that is what it seems... 😉😉😉

📌 Upon deployment, the VToken contract mints 100 $VTLK to Vitalik's address.

Is there a way for you to steal those tokens from him? 😈😈😈

🗒️ Concepts you should be familiar with (spoilers!)

The contracts that you will hack are:


Challenge 1: What a nice Lender Pool!

Secureum has raised a lot of Ether and decided to buy a bunch of InSecureumTokens ($ISEC) in order to make them available to the community via flash loans. This is made possible by means of the InSecureumLenderPool contract.

📌 Upon deployment, the InSecureumToken contract mints an initial supply of 10 $ISEC to the contract deployer.

📌 The InSecureumLenderPool contract operates with $ISEC.

📌 The contract deployer transfers all of their $ISEC to the InSecureumLenderPool contract.

📌 The idea is that anyone can deposit $ISECs to enlarge the pool's resources.

Will you be able to steal the $ISECs from the InSecureumLenderPool? 😈😈😈

🗒️ Concepts you should be familiar with (spoilers!)

The contracts that you will hack are:

Which have interactions with the following contracts:


Challenge 2: it's always sunny in decentralized exchanges

I bet you are familiar with decentralized exchanges: a magical place where one can exchange different tokens. InsecureDexLP is exactly that: a very insecure Uniswap-kind-of decentralized exchange. Recently, the $ISEC token got listed in this dex and can be traded against a not-so-popular token called $SET.

📌 Upon deployment, the InSecureumToken and SimpleERC223Token contracts mint an initial supply of tokens 10 $ISEC and 10 $SET to the contract deployer.

📌 The InsecureDexLP operates with $ISEC and $SET.

📌 The dex has an initial liquidity of 9 $ISEC and 9 $SET, provided by the contract deployer. This quantity can be increased by anyone through token deposits.

📌 Adding liquidity to the dex rewards liquidity pool tokens (LP tokens), which can be redeemed in any moment for the original funds.

📌 In the foundry implementation, the deployer graciously airdrops the challenger (you!) 1 $ISEC and 1 $SET. In the TenderlySandbox implementation, the challenger must call the exclusive claimAirdrop() functions of each of the token contracts, obtaining this way 1 $ISEC and 1 $SET.

Will you be able to drain most of InsecureDexLP's $ISEC/$SET liquidity? 😈😈😈

🗒️ Concepts you should be familiar with (spoilers!)

The contracts that you will hack are:

Which have interactions with the following contracts:


Challenge 3: borrow, hide and seek

Finally, as a conclusion to this not-so-secure ecosystem, the Secureum team built the BorrowSystemInsecureOracle lending platform where one can borrow and loan $ISEC and BoringToken ($BOR). Both tokens can be borrowed by either providing themselves or the other token as collateral.

📌 Upon deployment, the InSecureumToken and BoringToken contracts mint an initial supply of 30000 $ISEC and 20000 $BOR to the contract deployer.

📌 BorrowSystemInsecureOracle uses the InsecureDexLP to compute the $ISEC/$BOR price.

📌 The deployer adds an initial liquidity of 100 $ISEC and 100 $BOR to the InsecureDexLP.

📌 Similarly, InSecureumLenderPool contract is funded with 10000 $ISEC by the deployer.

📌 The BorrowSystemInsecureOracle contract has an initial amount of 10000 $ISEC and 10000 $BOR provided by the deployer.

📌 Users can add collateral and take loans from BorrowSystemInsecureOracle.

📌 Users may also get liquidated.

Will you be able to drain all the $ISEC from BorrowSystemInsecureOracle? 😈😈😈

🗒️ Concepts you should be familiar with (spoilers!)

The contracts that you will hack are:

Which have interactions with the following contracts:


CTF Writeup 🗒️🗒️🗒️


hosted by the Stanford University as part of built by and special thanks to , , and for reviewing, commenting and helping during the elaboration and design of this CTF Workshop

Option 1: Online through our

Option 2:

Option 3:

Option 4:

Option 5: Online through Gitpod, either using Foundry

Option 6: Online through Gitpod, using Hardhat

, especially the meaning of approving funds.

The concept of . Focus on the definition, how they work and what's their original purpose.

Solidity's .

The concept of . Focus on the constant-product formula.

such as ERC223. Focus on the fallback function provided in ERC223.

The concept of .

.

The concept of . Notice that this concept is very related to flashloans.

(this contract should be used by the attacker as part of the attack)

Follow to access this CTF's writeup by .

Follow for a more detailed walk-through for each challenge by .

Follow for another writeup using contracts in hardhat by .

🚩
Defi Security 101
eugenioclrc
luksgrin
patrickd
StErMi
tinchoabbate
Rajeev
interactive website
Online through TenderlySandbox
Locally with Foundry
Locally with Hardhat
The ERC20 token standard
VToken
flashloans
delegatecall
InSecureumLenderPool
InSecureumToken
Automatic Market Makers (AMMs)
Other token standards
reentrancy attack
InsecureDexLP
InSecureumToken
SimpleERC223Token
How DeFi lending works
price oracle attack
BorrowSystemInsecureOracle
InSecureumLenderPool
InsecureDexLP
InSecureumToken
BoringToken
this link
patrickd
this link
Matías Aereal Aeón
this link
faucet0x9a54
A-MAZE-X-Stanford-LOGO