Skip to content

Commit 647a056

Browse files
add dependencies
0 parents  commit 647a056

12 files changed

+8662
-0
lines changed

.env.example

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ALCHEMY_API_KEY=
2+
MNEMONIC=
3+
FORK=false
4+
TENDERLY_ACCESS_TOKEN=
5+
ETHERSCAN_API_KEY=
6+
BLOCK_NUMBER=

.eslintignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
contracts/
2+
typechain/
3+
cache/
4+
artifacts/
5+
node_modules/

.eslintrc.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"es6": true,
5+
"mocha": true
6+
},
7+
"extends": ["eslint:recommended"],
8+
"plugins": [],
9+
"globals": {
10+
"Atomics": "readonly",
11+
"SharedArrayBuffer": "readonly"
12+
},
13+
"parserOptions": {
14+
"ecmaVersion": 2019
15+
},
16+
"root": true,
17+
"rules": {
18+
"no-unused-vars": "off"
19+
}
20+
}

.gitignore

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
node_modules/
2+
3+
# env variables
4+
.env
5+
6+
# log
7+
*.log
8+
9+
# hardhat
10+
artifacts/
11+
cache/
12+
typechain/
13+
typechain-types/
14+
deployments/
15+
16+
flattened/
17+
18+
# hardhat-dependency-compiler
19+
hardhat-dependency-compiler/
20+
21+
# macOS
22+
.DS_Store
23+
24+
# Coverage
25+
coverage
26+
coverage.json
27+
28+
hints.md

.mocharc.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict"
2+
process.env.TS_NODE_FILES = true
3+
module.exports = {
4+
"allow-uncaught": true,
5+
diff: true,
6+
extension: ["ts"],
7+
recursive: true,
8+
reporter: "spec",
9+
require: ["ts-node/register", "hardhat/register"],
10+
slow: 300,
11+
spec: "test/**/*.test.**",
12+
timeout: 20000,
13+
ui: "bdd",
14+
watch: false,
15+
"watch-files": ["contracts/**/*.sol", "test/**/*.ts"],
16+
}

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
typechain/
2+
cache/
3+
artifacts/
4+
typechain-types/

.prettierrc

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"endOfLine": "auto",
3+
"bracketSpacing": true,
4+
"overrides": [
5+
{
6+
"files": "*.sol",
7+
"options": {
8+
"tabWidth": 4,
9+
"singleQuote": false,
10+
"explicitTypes": "always"
11+
}
12+
},
13+
{
14+
"files": "*.{js,ts}",
15+
"options": {
16+
"arrowParens": "avoid",
17+
"tabWidth": 2,
18+
"singleQuote": true,
19+
"semi": false
20+
}
21+
}
22+
]
23+
}

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Smart Contracts Vulns Hacking
2+
3+
## Getting Started
4+
5+
### Setup
6+
7+
`yarn`
8+
9+
To run testing on the forking main net, set the APIKEY and mnemonic.
10+
you need access to an archive node like the free ones from [Alchemy](https://alchemyapi.io/).
11+
```
12+
ALCHEMY_API_KEY=
13+
MNEMONIC=
14+
BLOCK_NUMBER=
15+
FORK=false
16+
```
17+
18+
### Compiling
19+
20+
`yarn compile`
21+
22+
### Replaying hack
23+
24+
The hacks are implemented as hardhat tests and can therefore be run as:
25+
26+
`yarn hardhat test test/<name>.ts`
27+
28+
### Debugging transactions with tenderly
29+
30+
Set up `tenderly.yaml` in the repo root and follow [this article](http://blog.tenderly.co/level-up-your-smart-contract-productivity-using-hardhat-and-tenderly/).
31+
32+
TLDR:
33+
34+
```bash
35+
# run this in second terminal
36+
npx hardhat node
37+
# run test against local network
38+
npx hardhat test test/foo.js --network local
39+
# you want an actual tx id which means the tx may not fail in eth_estimateGas already
40+
# therefore hardcode some gas values
41+
# {value: ethers.utils.parseEther(`100`), gasLimit: `15000000`, gasPrice: ethers.utils.parseUnits(`200`, 9) }
42+
# the (failed) tx hash appears on the CLI after "eth_sendTransaction"
43+
# --force is required to skip gas estimation check in tenderly
44+
tenderly export <txHash> --force
45+
```

hardhat.config.ts

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import "dotenv/config"
2+
import { HardhatUserConfig } from "hardhat/config"
3+
import "@typechain/hardhat"
4+
import "@nomiclabs/hardhat-waffle"
5+
import "@nomiclabs/hardhat-ethers"
6+
7+
const ALCHEMY_API_KEY = process.env.ALCHEMY_API_KEY
8+
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY
9+
const BLOCK_NUMBER = process.env.BLOCK_NUMBER
10+
const MNEMONIC = process.env.MNEMONIC
11+
const FORK = process.env.FORK
12+
13+
if (FORK && !ALCHEMY_API_KEY) throw new Error("ALCHEMY_API_KEY_NOT_FOUND")
14+
15+
/**
16+
* @type import('hardhat/config').HardhatUserConfig
17+
*/
18+
const config: HardhatUserConfig = {
19+
defaultNetwork: "hardhat",
20+
networks: {
21+
local: {
22+
url: "http://127.0.0.1:8545",
23+
},
24+
hardhat: {
25+
forking:
26+
{
27+
enabled: FORK === "true",
28+
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_API_KEY}`,
29+
blockNumber: BLOCK_NUMBER ? Number(BLOCK_NUMBER) : undefined
30+
}
31+
},
32+
mainnet: {
33+
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_API_KEY}`,
34+
chainId: 1,
35+
},
36+
},
37+
solidity: {
38+
compilers: [
39+
{
40+
version: "0.8.10",
41+
settings: {
42+
optimizer: {
43+
enabled: true,
44+
runs: 200,
45+
},
46+
// outputSelection: {
47+
// '*': {
48+
// '*': ['storageLayout']
49+
// }
50+
// }
51+
},
52+
},
53+
{
54+
version: "0.7.6",
55+
settings: {
56+
optimizer: {
57+
enabled: true,
58+
runs: 200,
59+
}
60+
},
61+
},
62+
],
63+
},
64+
paths: {
65+
sources: "./contracts",
66+
tests: "./test",
67+
cache: "./cache",
68+
artifacts: "./artifacts",
69+
},
70+
}
71+
72+
export default config

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "sol-challenge",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"author": "massun-onibakuchi",
6+
"license": "MIT",
7+
"dependencies": {
8+
"@openzeppelin/contracts": "^4.6.0",
9+
"hardhat": "^2.8.0"
10+
},
11+
"devDependencies": {
12+
"@nomiclabs/hardhat-ethers": "^2.0.3",
13+
"@nomiclabs/hardhat-waffle": "^2.0.1",
14+
"@typechain/ethers-v5": "^8.0.5",
15+
"@typechain/hardhat": "^3.1.0",
16+
"@types/mocha": "^9.0.0",
17+
"@types/node": "^17.0.7",
18+
"chai": "^4.3.4",
19+
"dotenv": "^10.0.0",
20+
"eslint": "^8.6.0",
21+
"ethereum-waffle": "^3.4.0",
22+
"ethers": "^5.5.2",
23+
"prettier": "^2.5.1",
24+
"prettier-plugin-solidity": "^1.0.0-beta.19",
25+
"ts-node": "^10.4.0",
26+
"typechain": "^6.1.0",
27+
"typescript": "^4.5.4"
28+
},
29+
"scripts": {
30+
"compile": "hardhat compile",
31+
"console": "hardhat console",
32+
"test": "yarn hardhat test",
33+
"typechain": "hardhat typechain",
34+
"chain": "hardhat node",
35+
"deploy": "hardhat deploy",
36+
"lint": "prettier --list-different 'contracts/**/*.sol' && prettier -c 'test/**/*.ts'",
37+
"format:sol": "prettier --write 'contracts/**/*.sol'",
38+
"format:ts": "prettier --write 'test/**/*.ts'",
39+
"format": "yarn format:sol && yarn format:ts"
40+
}
41+
}

tsconfig.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2018",
4+
"module": "commonjs",
5+
"lib": ["es2018"],
6+
"sourceMap": false,
7+
"removeComments": false,
8+
"downlevelIteration": true,
9+
"strict": true,
10+
"noImplicitAny": false,
11+
"strictNullChecks": false,
12+
"strictFunctionTypes": false,
13+
"strictBindCallApply": false,
14+
"strictPropertyInitialization": false,
15+
"noImplicitThis": false,
16+
"moduleResolution": "node",
17+
"esModuleInterop": true,
18+
"resolveJsonModule": true,
19+
"skipLibCheck": true,
20+
"forceConsistentCasingInFileNames": true
21+
},
22+
"include": ["./hardhat.config.ts", "./scripts", "./deploy", "./test"],
23+
"exclude": [],
24+
"files": ["./hardhat.config.ts"]
25+
}

0 commit comments

Comments
 (0)