Skip to content

Commit 82b6049

Browse files
authored
Work for V2 (#1)
* Partial work on v2 * Add Free Rider challenge * Change package scripts * Add Puppet v2 * Ease wording * Limit ETH in climber * Further cleanup before release
1 parent 6797353 commit 82b6049

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+10702
-21286
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
This file was deleted.

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ node_modules
22
build
33
contracts/attacker-contracts/*.sol
44
*.solved.js
5-
cache
5+
cache
6+
.openzeppelin
7+
.vscode
8+
artifacts
9+
cache

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
3+
## v2.0.0
4+
5+
- Refactor testing environment. Now using Hardhat, Ethers and Waffle. This should give players a better debugging experience, and allow them to familiarize with up-to-date JavaScript tooling for smart contract testing.
6+
- New levels:
7+
- Backdoor
8+
- Climber
9+
- Free Rider
10+
- Puppet v2
11+
- New integrations with Gnosis Safe wallets, Uniswap v2, WETH9 and the upgradebale version of OpenZeppelin Contracts.
12+
- Tweaks in existing challenges after community feedback
13+
- Upgraded most contracts to Solidity 0.8
14+
- Changes in internal libraries around low-level calls and transfers of ETH. Now mostly using OpenZeppelin Contracts utilities.
15+
- In existing Puppet and The Rewarder challenges, better encapsulate issues to avoid repetitions.
16+
- Reorganization of some files
17+
- Changed from `npm` to `yarn` as dependency manager
18+
19+
## v1.0.0
20+
21+
Initial version

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2020
3+
Copyright (c) 2021 Damn Vulnerable DeFi
44

55
Permission is hereby granted, free of charge, to any person obtaining
66
a copy of this software and associated documentation files (the

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
![](cover.png)
22

3-
**A set of challenges to hack implementations of DeFi in Ethereum.** Featuring flash loans, oracles, governance, NFTs, lending pools, and more!
3+
**A set of challenges to hack implementations of DeFi in Ethereum.**
44

5-
Created by [@tinchoabbate](https://twitter.com/tinchoabbate) at OpenZeppelin
5+
Featuring flash loans, price oracles, governance, NFTs, lending pools, smart contract wallets, timelocks, and more!
66

7-
## Play
8-
9-
Visit [damnvulnerabledefi.xyz](https://damnvulnerabledefi.xyz)!
7+
Created by [@tinchoabbate](https://twitter.com/tinchoabbate)
108

11-
## Troubleshooting
9+
## Play
1210

13-
- Some users have reported [issues](https://github.com/OpenZeppelin/damn-vulnerable-defi/issues/1) with specific versions of node. I have succesfully installed all dependencies, and executed all challenges, with version `v12.20.0`. If you're using a different version of node and are having problems during the setup, try switching to version `v12.20.0`.
14-
- Some users have reported [issues](https://github.com/OpenZeppelin/damn-vulnerable-defi/pull/4) with the timeout set in the `package.json` file for "The Rewarder" challenge. If you're having trouble executing your exploit for this challenge, try increasing the timeout.
11+
Visit [damnvulnerabledefi.xyz](https://damnvulnerabledefi.xyz)
1512

1613
## Disclaimer
1714

buidler.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

build-uniswap-v1/UniswapV1Exchange.json

Lines changed: 482 additions & 7 deletions
Large diffs are not rendered by default.
Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,81 @@
11
{
2-
"contractName": "UniswapV1Factory",
3-
"abi": [{"name":"NewExchange","inputs":[{"type":"address","name":"token","indexed":true},{"type":"address","name":"exchange","indexed":true}],"anonymous":false,"type":"event"},{"name":"initializeFactory","outputs":[],"inputs":[{"type":"address","name":"template"}],"constant":false,"payable":false,"type":"function","gas":35725},{"name":"createExchange","outputs":[{"type":"address","name":"out"}],"inputs":[{"type":"address","name":"token"}],"constant":false,"payable":false,"type":"function","gas":187911},{"name":"getExchange","outputs":[{"type":"address","name":"out"}],"inputs":[{"type":"address","name":"token"}],"constant":true,"payable":false,"type":"function","gas":715},{"name":"getToken","outputs":[{"type":"address","name":"out"}],"inputs":[{"type":"address","name":"exchange"}],"constant":true,"payable":false,"type":"function","gas":745},{"name":"getTokenWithId","outputs":[{"type":"address","name":"out"}],"inputs":[{"type":"uint256","name":"token_id"}],"constant":true,"payable":false,"type":"function","gas":736},{"name":"exchangeTemplate","outputs":[{"type":"address","name":"out"}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":633},{"name":"tokenCount","outputs":[{"type":"uint256","name":"out"}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":663}],
4-
"bytecode": "0x6103f056600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a05263538a3f0e60005114156100ed57602060046101403734156100b457600080fd5b60043560205181106100c557600080fd5b50600054156100d357600080fd5b60006101405114156100e457600080fd5b61014051600055005b631648f38e60005114156102bf576020600461014037341561010e57600080fd5b600435602051811061011f57600080fd5b50600061014051141561013157600080fd5b6000600054141561014157600080fd5b60026101405160e05260c052604060c020541561015d57600080fd5b7f602e600c600039602e6000f33660006000376110006000366000730000000000610180526c010000000000000000000000006000540261019b527f5af41558576110006000f30000000000000000000000000000000000000000006101af5260406101806000f0806101cf57600080fd5b61016052610160513b6101e157600080fd5b610160513014156101f157600080fd5b6000600060246366d3820361022052610140516102405261023c6000610160515af161021c57600080fd5b6101605160026101405160e05260c052604060c020556101405160036101605160e05260c052604060c02055600154600160015401101561025c57600080fd5b6001600154016102a0526102a0516001556101405160046102a05160e05260c052604060c0205561016051610140517f9d42cb017eb05bd8944ab536a8b35bc68085931dd5f4356489801453923953f960006000a36101605160005260206000f3005b6306f2bf62600051141561030e57602060046101403734156102e057600080fd5b60043560205181106102f157600080fd5b5060026101405160e05260c052604060c0205460005260206000f3005b6359770438600051141561035d576020600461014037341561032f57600080fd5b600435602051811061034057600080fd5b5060036101405160e05260c052604060c0205460005260206000f3005b63aa65a6c0600051141561039a576020600461014037341561037e57600080fd5b60046101405160e05260c052604060c0205460005260206000f3005b631c2bbd1860005114156103c05734156103b357600080fd5b60005460005260206000f3005b639f181b5e60005114156103e65734156103d957600080fd5b60015460005260206000f3005b60006000fd5b6100046103f0036100046000396100046103f0036000f3",
5-
"compiler": {
6-
"name": "vyper",
7-
"version": "0.1.0b4"
2+
"abi": [
3+
{
4+
"name": "NewExchange",
5+
"inputs": [
6+
{ "type": "address", "name": "token", "indexed": true },
7+
{ "type": "address", "name": "exchange", "indexed": true }
8+
],
9+
"anonymous": false,
10+
"type": "event"
11+
},
12+
{
13+
"name": "initializeFactory",
14+
"outputs": [],
15+
"inputs": [{ "type": "address", "name": "template" }],
16+
"constant": false,
17+
"payable": false,
18+
"type": "function",
19+
"gas": 35725
20+
},
21+
{
22+
"name": "createExchange",
23+
"outputs": [{ "type": "address", "name": "out" }],
24+
"inputs": [{ "type": "address", "name": "token" }],
25+
"constant": false,
26+
"payable": false,
27+
"type": "function",
28+
"gas": 187911
29+
},
30+
{
31+
"name": "getExchange",
32+
"outputs": [{ "type": "address", "name": "out" }],
33+
"inputs": [{ "type": "address", "name": "token" }],
34+
"constant": true,
35+
"payable": false,
36+
"type": "function",
37+
"gas": 715
38+
},
39+
{
40+
"name": "getToken",
41+
"outputs": [{ "type": "address", "name": "out" }],
42+
"inputs": [{ "type": "address", "name": "exchange" }],
43+
"constant": true,
44+
"payable": false,
45+
"type": "function",
46+
"gas": 745
47+
},
48+
{
49+
"name": "getTokenWithId",
50+
"outputs": [{ "type": "address", "name": "out" }],
51+
"inputs": [{ "type": "uint256", "name": "token_id" }],
52+
"constant": true,
53+
"payable": false,
54+
"type": "function",
55+
"gas": 736
56+
},
57+
{
58+
"name": "exchangeTemplate",
59+
"outputs": [{ "type": "address", "name": "out" }],
60+
"inputs": [],
61+
"constant": true,
62+
"payable": false,
63+
"type": "function",
64+
"gas": 633
65+
},
66+
{
67+
"name": "tokenCount",
68+
"outputs": [{ "type": "uint256", "name": "out" }],
69+
"inputs": [],
70+
"constant": true,
71+
"payable": false,
72+
"type": "function",
73+
"gas": 663
74+
}
75+
],
76+
"evm": {
77+
"bytecode": {
78+
"object": "6103f056600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a05263538a3f0e60005114156100ed57602060046101403734156100b457600080fd5b60043560205181106100c557600080fd5b50600054156100d357600080fd5b60006101405114156100e457600080fd5b61014051600055005b631648f38e60005114156102bf576020600461014037341561010e57600080fd5b600435602051811061011f57600080fd5b50600061014051141561013157600080fd5b6000600054141561014157600080fd5b60026101405160e05260c052604060c020541561015d57600080fd5b7f602e600c600039602e6000f33660006000376110006000366000730000000000610180526c010000000000000000000000006000540261019b527f5af41558576110006000f30000000000000000000000000000000000000000006101af5260406101806000f0806101cf57600080fd5b61016052610160513b6101e157600080fd5b610160513014156101f157600080fd5b6000600060246366d3820361022052610140516102405261023c6000610160515af161021c57600080fd5b6101605160026101405160e05260c052604060c020556101405160036101605160e05260c052604060c02055600154600160015401101561025c57600080fd5b6001600154016102a0526102a0516001556101405160046102a05160e05260c052604060c0205561016051610140517f9d42cb017eb05bd8944ab536a8b35bc68085931dd5f4356489801453923953f960006000a36101605160005260206000f3005b6306f2bf62600051141561030e57602060046101403734156102e057600080fd5b60043560205181106102f157600080fd5b5060026101405160e05260c052604060c0205460005260206000f3005b6359770438600051141561035d576020600461014037341561032f57600080fd5b600435602051811061034057600080fd5b5060036101405160e05260c052604060c0205460005260206000f3005b63aa65a6c0600051141561039a576020600461014037341561037e57600080fd5b60046101405160e05260c052604060c0205460005260206000f3005b631c2bbd1860005114156103c05734156103b357600080fd5b60005460005260206000f3005b639f181b5e60005114156103e65734156103d957600080fd5b60015460005260206000f3005b60006000fd5b6100046103f0036100046000396100046103f0036000f3"
79+
}
880
}
981
}

contracts/DamnValuableNFT.sol

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
5+
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
6+
import "@openzeppelin/contracts/access/AccessControl.sol";
7+
import "@openzeppelin/contracts/utils/Counters.sol";
8+
9+
/**
10+
* @title DamnValuableNFT
11+
* @author Damn Vulnerable DeFi (https://damnvulnerabledefi.xyz)
12+
* @notice Implementation of a mintable and burnable NFT with role-based access controls
13+
*/
14+
contract DamnValuableNFT is ERC721, ERC721Burnable, AccessControl {
15+
using Counters for Counters.Counter;
16+
17+
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
18+
Counters.Counter private _tokenIdCounter;
19+
20+
constructor() ERC721("DamnValuableNFT", "DVNFT") {
21+
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
22+
_setupRole(MINTER_ROLE, msg.sender);
23+
}
24+
25+
function safeMint(address to) public onlyRole(MINTER_ROLE) returns (uint256) {
26+
uint256 tokenId = _tokenIdCounter.current();
27+
_safeMint(to, tokenId);
28+
_tokenIdCounter.increment();
29+
return tokenId;
30+
}
31+
32+
function supportsInterface(bytes4 interfaceId)
33+
public
34+
view
35+
override(ERC721, AccessControl)
36+
returns (bool)
37+
{
38+
return super.supportsInterface(interfaceId);
39+
}
40+
}

contracts/DamnValuableToken.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
pragma solidity ^0.6.0;
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
24

35
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
46

7+
/**
8+
* @title DamnValuableToken
9+
* @author Damn Vulnerable DeFi (https://damnvulnerabledefi.xyz)
10+
*/
511
contract DamnValuableToken is ERC20 {
612

713
// Decimals are set to 18 by default in `ERC20`
8-
constructor() public ERC20("DamnValuableToken", "DVT") {
9-
_mint(msg.sender, 2**256 - 1);
14+
constructor() ERC20("DamnValuableToken", "DVT") {
15+
_mint(msg.sender, type(uint256).max);
1016
}
1117
}

0 commit comments

Comments
 (0)