Challenges from Capture the ether on hardhat.
- Clone this repo.
- Complete the challenges on
./test/
. - Verify the result running
yarn test
.
- Deploy a contract
- Call me
- Choose a nickname
- Guess the number
- Guess the secret number
- Guess the random number
- Guess the new number
- Predict the future
- Predict the block hash
- Token sale
- Token whale
- Retirement fund
- Mapping
- Donation
- Fifty years
- Fuzzy identity
- Public Key
- Account Takeover
- Assume ownership
- Token bank
The warmup challenges are intended to get you familiar with the way Capture the Ether works and the tools you need to use.
To complete this challenge, you need to deploy a new contract on hardhat.
- Contract: ./contracts/DeployChallenge.sol
- Test File: ./test/01-DeployAContract.test.ts
- Run it with
yarn deploy-a-contract
To complete this challenge, all you need to do is call the function named callme
.
- Contract: ./contracts/CallMeChallenge.sol
- Test File: ./test/02-CallMe.test.ts
- Run it with
yarn call-me
To complete this challenge you need to track your nickname on the Capture the Ether contract.
- Contract: ./contracts/NicknameChallenge.sol
- Test File: ./test/03-ChooseANickname.test.ts
- Run it with
yarn choose-a-nickname
Feeling lucky? These challenges will show how hard it is to run a fair lottery.
I’m thinking of a number. All you have to do is guess it.
- Contract: ./contracts/GuessTheNumberChallenge.sol
- Test File: ./test/04-GuessTheNumber.test.ts
- Run it with
yarn guess-the-number
Putting the answer in the code makes things a little too easy.
This time I’ve only stored the hash of the number. Good luck reversing a cryptographic hash!
- Contract: ./contracts/GuessTheSecretNumberChallenge.sol
- Test File: ./test/05-GuessTheSecretNumber.test.ts
- Run it with
yarn guess-the-secret-number
This time the number is generated based on a couple fairly random sources.
- Contract: ./contracts/GuessTheRandomNumberChallenge.sol
- Test File: ./test/06-GuessTheRandomNumber.test.ts
- Run it with
yarn guess-the-random-number
The number is now generated on-demand when a guess is made.
- Contract: ./contracts/GuessTheNewNumberChallenge.sol
- Test File: ./test/07-GuessTheNewNumber.test.ts
- Run it with
yarn guess-the-new-number
This time, you have to lock in your guess before the random number is generated. To give you a sporting chance, there are only ten possible answers.
Note that it is indeed possible to solve this challenge without losing any ether.
- Contract: ./contracts/PredictTheFutureChallenge.sol
- Test File: ./test/08-PredictTheFuture.test.ts
- Run it with
yarn predict-the-future
Guessing an 8-bit number is apparently too easy. This time, you need to predict the entire 256-bit block hash for a future block.
- Contract: ./contracts/PredictTheBlockHashChallenge.sol
- Test File: ./test/09-PredictTheBlockHash.test.ts
- Run it with
yarn predict-the-block-hash
These challenges use a variety of techniques, but they all involve a bit of math.
This token contract allows you to buy and sell tokens at an even exchange rate of 1 token per ether.
The contract starts off with a balance of 1 ether. See if you can take some of that away.
- Contract: ./contracts/TokenSaleChallenge.sol
- Test File: ./test/10-TokenSale.test.ts
- Run it with
yarn token-sale
This ERC20-compatible token is hard to acquire. There’s a fixed supply of 1,000 tokens, all of which are yours to start with.
Find a way to accumulate at least 1,000,000 tokens to solve this challenge.
- Contract: ./contracts/TokenWhaleChallenge.sol
- Test File: ./test/11-TokenWhale.test.ts
- Run it with
yarn token-whale
This retirement fund is what economists call a commitment device. I’m trying to make sure I hold on to 1 ether for retirement.
I’ve committed 1 ether to the contract below, and I won’t withdraw it until 10 years have passed. If I do withdraw early, 10% of my ether goes to the beneficiary (you!).
I really don’t want you to have 0.1 of my ether, so I’m resolved to leave those funds alone until 10 years from now. Good luck!
- Contract: ./contracts/RetirementFundChallenge.sol
- Test File: ./test/12-RetirementFund.test.ts
- Run it with
yarn retirement-fund
Who needs mappings? I’ve created a contract that can store key/value pairs using just an array.
- Contract: ./contracts/MappingChallenge.sol
- Test File: ./test/13-Mapping.test.ts
- Run it with
yarn mapping
A candidate you don’t like is accepting campaign contributions via the smart contract below.
To complete this challenge, steal the candidate’s ether.
- Contract: ./contracts/DonationChallenge.sol
- Test File: ./test/14-Donation.test.ts
- Run it with
yarn donation
This contract locks away ether. The initial ether is locked away until 50 years has passed, and subsequent contributions are locked until even later.
All you have to do to complete this challenge is wait 50 years and withdraw the ether. If you’re not that patient, you’ll need to combine several techniques to hack this contract.
- Contract: ./contracts/FiftyYearsChallenge.sol
- Test File: ./test/15-FiftyYears.test.ts
- Run it with
yarn fifty-years
These challenges test your understanding of Ethereum accounts.
This contract can only be used by me (smarx). I don’t trust myself to remember my private key, so I’ve made it so whatever address I’m using in the future will work:
- I always use a wallet contract that returns “smarx” if you ask its name.
- Everything I write has bad code in it, so my address always includes the hex string badc0de.
To complete this challenge, steal my identity!
- Contract: ./contracts/FuzzyIdentityChallenge.sol
- Test File: ./test/16-FuzzyIdentity.test.ts
- Run it with
yarn fuzzy-identity
Recall that an address is the last 20 bytes of the keccak-256 hash of the address’s public key.
To complete this challenge, find the public key for the owner's account.
- Contract: ./contracts/PublicKeyChallenge.sol
- Test File: ./test/17-PublicKey.test.ts
- Run it with
yarn public-key
To complete this challenge, send a transaction from the owner's account.
- Contract: ./contracts/AccountTakeoverChallenge.sol
- Test File: ./test/18-AccountTakeover.test.ts
- Run it with
yarn account-takeover
These challenges defy categorization.
To complete this challenge, become the owner.
- Contract: ./contracts/AssumeOwnershipChallenge.sol
- Test File: ./test/19-AssumeOwnership.test.ts
- Run it with
yarn assume-ownership
I created a token bank. It allows anyone to deposit tokens by transferring them to the bank and then to withdraw those tokens later. It uses ERC 223 to accept the incoming tokens.
The bank deploys a token called “Simple ERC223 Token” and assigns half the tokens to me and half to you. You win this challenge if you can empty the bank.
- Contract: ./contracts/TokenBankChallenge.sol
- Test File: ./test/20-TokenBank.test.ts
- Run it with
yarn token-bank
Built by @SMARX