Skip to content

Commit 6b80f2b

Browse files
committed
Merge branch 'master' into secure-contact
2 parents 489bb4d + 690de88 commit 6b80f2b

File tree

41 files changed

+1319
-55
lines changed

Some content is hidden

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

41 files changed

+1319
-55
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
- uses: actions/checkout@v4
2323
with:
2424
fetch-depth: 0
25+
submodules: true
2526
- name: Install mdbook
2627
run: |
2728
cargo install --git https://github.com/montyly/mdBook.git mdbook || true

.github/workflows/lint_format.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
steps:
1414
- name: Checkout repository
1515
uses: actions/checkout@v4
16+
with:
17+
submodules: true
1618

1719
- name: Set up Node.js
1820
uses: actions/setup-node@v3
@@ -23,6 +25,13 @@ jobs:
2325
run: |
2426
npm ci
2527
28+
- name: Remove Medusa uncessary files
29+
run: |
30+
rm -rf program-analysis/medusa/chain
31+
rm -rf program-analysis/medusa/compilation
32+
rm -rf program-analysis/medusa/fuzzing
33+
rm program-analysis/medusa/docs/theme/highlight.js
34+
2635
- name: Run lint
2736
run: |
2837
npm run lint:format

.github/workflows/lint_links.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v4
23+
with:
24+
submodules: recursive
2325
- uses: gaurav-nelson/github-action-markdown-link-check@v1
2426
with:
2527
use-quiet-mode: "yes"
2628
check-modified-files-only: ${{ (github.event_name == 'pull_request' && 'yes') || 'no' }}
29+
submodules: true

.github/workflows/medusa.yml

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
name: Run Medusa tests
2+
3+
on:
4+
push:
5+
paths:
6+
- ".github/workflows/medusa.yml"
7+
- "program-analysis/echidna/**/*.sol"
8+
- "program-analysis/echidna/**/*.yml"
9+
branches:
10+
- master
11+
pull_request:
12+
paths:
13+
- ".github/workflows/medusa.yml"
14+
- "program-analysis/echidna/**/*.sol"
15+
- "program-analysis/echidna/**/*.yml"
16+
schedule:
17+
# run CI every day even if no PRs/merges occur
18+
- cron: "0 12 * * *"
19+
20+
jobs:
21+
tests:
22+
name: ${{ matrix.name }}
23+
continue-on-error: ${{ matrix.flaky == true }}
24+
runs-on: ubuntu-22.04
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
include:
29+
- name: Exercise 1
30+
workdir: program-analysis/echidna/exercises/exercise1/
31+
files: solution.sol
32+
contract: TestToken
33+
outcome: failure
34+
expected: 'echidna_test_balance()\" failed after the following call sequence'
35+
- name: Exercise 2
36+
workdir: program-analysis/echidna/exercises/exercise2/
37+
files: solution.sol
38+
contract: TestToken
39+
outcome: failure
40+
expected: 'echidna_no_transfer()\" failed after the following call sequence'
41+
- name: Exercise 3
42+
workdir: program-analysis/echidna/exercises/exercise3/
43+
files: solution.sol
44+
contract: TestToken
45+
outcome: failure
46+
expected: 'echidna_test_balance()\" failed after the following call sequence'
47+
- name: Exercise 4
48+
workdir: program-analysis/echidna/exercises/exercise4/
49+
files: solution.sol
50+
contract: TestToken
51+
outcome: failure
52+
expected: 'transfer(address,uint256)\" resulted in an assertion failure after the following call sequence:'
53+
# - name: Exercise 5
54+
# workdir: dvdefi/
55+
# files: .
56+
# config: naivereceiver.yaml
57+
# crytic-args: --hardhat-ignore-compile
58+
# contract: NaiveReceiverEchidna
59+
# outcome: failure
60+
# expected: 'echidna_test_contract_balance:\s*failed'
61+
# - name: Exercise 6
62+
# workdir: dvdefi/
63+
# files: .
64+
# config: unstoppable.yaml
65+
# crytic-args: --hardhat-ignore-compile
66+
# contract: UnstoppableEchidna
67+
# outcome: failure
68+
# expected: 'echidna_testFlashLoan:\s*failed'
69+
# - name: Exercise 7
70+
# workdir: dvdefi/
71+
# files: .
72+
# config: sideentrance.yaml
73+
# crytic-args: --hardhat-ignore-compile
74+
# contract: SideEntranceEchidna
75+
# outcome: failure
76+
# expected: 'testPoolBalance():\s*failed'
77+
- name: TestToken
78+
workdir: program-analysis/echidna/example/
79+
files: testtoken.sol
80+
contract: TestToken
81+
outcome: failure
82+
expected: 'echidna_balance_under_1000()\" failed after the following call sequence'
83+
- name: Multi
84+
workdir: program-analysis/echidna/example/
85+
files: multi.sol
86+
contract: C
87+
config: filter.yaml
88+
outcome: failure
89+
expected: 'echidna_state4()\" failed after the following call sequence'
90+
- name: Assert
91+
workdir: program-analysis/echidna/example/
92+
files: assert.sol
93+
config: assert.yaml
94+
contract: Incrementor
95+
outcome: failure
96+
expected: 'inc(uint256)\" resulted in an assertion failure after the following call sequence'
97+
- name: PopsicleBroken
98+
workdir: program-analysis/echidna/example/
99+
files: PopsicleBroken.sol
100+
solc-version: 0.8.4
101+
contract: PopsicleBroken
102+
outcome: failure
103+
expected: 'PopsicleBroken.totalBalanceAfterTransferIsPreserved(address,uint256)\" resulted in an assertion failure after the following call sequence'
104+
- name: PopsicleFixed
105+
workdir: program-analysis/echidna/example/
106+
files: PopsicleFixed.sol
107+
solc-version: 0.8.4
108+
contract: PopsicleFixed
109+
outcome: success
110+
expected: '\[PASSED\] Assertion Test: PopsicleFixed.totalBalanceAfterTransferIsPreserved(address,uint256)'
111+
- name: TestDepositWithPermit
112+
workdir: program-analysis/echidna/example/
113+
files: TestDepositWithPermit.sol
114+
solc-version: 0.8.0
115+
config: testdeposit.yaml
116+
contract: TestDepositWithPermit
117+
outcome: success
118+
expected: '\[PASSED\] Assertion Test: TestDepositWithPermit.testERC20PermitDeposit(uint256)'
119+
# - name: MultiABI
120+
# workdir: program-analysis/echidna/example/
121+
# files: allContracts.sol
122+
# solc-version: 0.8.0
123+
# config: allContracts.yaml
124+
# contract: EchidnaTest
125+
# outcome: failure
126+
# expected: 'test_flag_is_false():\s*failed'
127+
128+
steps:
129+
- name: Checkout repository
130+
uses: actions/checkout@v4
131+
132+
- name: Checkout Damn Vulnerable DeFi solutions
133+
uses: actions/checkout@v4
134+
if: startsWith(matrix.workdir, 'dvdefi')
135+
with:
136+
repository: crytic/damn-vulnerable-defi-echidna
137+
ref: solutions
138+
path: ${{ matrix.workdir }}
139+
140+
- name: Set up Nodejs
141+
uses: actions/setup-node@v3
142+
if: startsWith(matrix.workdir, 'dvdefi')
143+
with:
144+
node-version: 16
145+
146+
- name: Install dependencies and compile
147+
if: startsWith(matrix.workdir, 'dvdefi')
148+
run: |
149+
yarn install --frozen-lockfile
150+
npx hardhat compile --force
151+
working-directory: ${{ matrix.workdir }}
152+
153+
- name: Go setup
154+
uses: actions/setup-go@v5
155+
with:
156+
go-version: "^1.18.1"
157+
158+
- name: Install medusa
159+
run: |
160+
git clone https://github.com/crytic/medusa.git
161+
cd medusa
162+
go build -o medusa -v .
163+
go install -v .
164+
sudo cp medusa /usr/bin
165+
pip install crytic-compile solc-select
166+
167+
- name: Run Medusa
168+
continue-on-error: true
169+
working-directory: ${{ matrix.workdir }}
170+
run: |
171+
solc-select install ${{ matrix.solc-version || '0.8.0' }}
172+
solc-select use ${{ matrix.solc-version || '0.8.0' }}
173+
medusa fuzz --compilation-target ${{ matrix.files }} --target-contracts ${{ matrix.contract }} --no-color --test-limit 100000 --config medusa.json > ${{ matrix.files }}.out || true
174+
175+
- name: Verify that the output is correct
176+
working-directory: ${{ matrix.workdir }}
177+
run: |
178+
if grep -q "${{ matrix.expected }}" "${{ matrix.files }}.out"; then
179+
echo "Output matches"
180+
else
181+
echo "Output mismatch. Expected something matching '${{ matrix.expected }}'. Got the following:"
182+
cat "${{ matrix.files }}.out"
183+
exit 1
184+
fi

.github/workflows/slither.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ jobs:
2929
- name: Install dependencies
3030
run: |
3131
pip install solc-select
32-
solc-select install 0.5.11
33-
solc-select use 0.5.11
3432
- name: Run Tests
3533
run: |
3634
bash program-analysis/slither/scripts/gh_action_test.sh

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "program-analysis/medusa"]
2+
path = program-analysis/medusa
3+
url = https://github.com/crytic/medusa.git

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Building Secure Smart Contracts
22

3-
![](https://github.com/crytic/building-secure-contracts/workflows/CI/badge.svg) ![](https://github.com/crytic/building-secure-contracts/workflows/Echidna/badge.svg)
3+
![](https://github.com/crytic/building-secure-contracts/actions/workflows/slither.yml/badge.svg) ![](https://github.com/crytic/building-secure-contracts/actions/workflows/echidna.yml/badge.svg) ![](https://github.com/crytic/building-secure-contracts/actions/workflows/medusa.yml/badge.svg)
44

55
Brought to you by [Trail of Bits](https://www.trailofbits.com/), this repository offers guidelines and best practices for developing secure smart contracts. Contributions are welcome, you can contribute by following our [contributing guidelines](https://github.com/crytic/building-secure-contracts/blob/master/CONTRIBUTING.md).
66

@@ -29,6 +29,7 @@ Brought to you by [Trail of Bits](https://www.trailofbits.com/), this repository
2929
- [Solana](./not-so-smart-contracts/solana)
3030
- [Program Analysis](./program-analysis): Using automated tools to secure contracts
3131
- [Echidna](./program-analysis/echidna): A fuzzer that checks your contract's properties
32+
- [Medusa](./program-analysis/medusa/docs/src): A next-gen fuzzer that checks your contract's properties
3233
- [Slither](./program-analysis/slither): A static analyzer with both CLI and scriptable interfaces
3334
- [Manticore](./program-analysis/manticore): A symbolic execution engine that proves the correctness of properties
3435
- For each tool, this training material provides:

SUMMARY.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
- [Interacting with off-chain data via FFI cheatcode](./program-analysis/echidna/advanced/interacting-with-offchain-data-via-ffi.md)
9797
- [Fuzzing tips](./program-analysis/echidna/fuzzing_tips.md)
9898
- [Frequently Asked Questions](./program-analysis/echidna/frequently_asked_questions.md)
99+
- [Configuration options](./program-analysis/echidna/configuration.md)
99100
- [Exercises](./program-analysis/echidna/exercises/README.md)
100101
- [Exercise 1](./program-analysis/echidna/exercises/Exercise-1.md)
101102
- [Exercise 2](./program-analysis/echidna/exercises/Exercise-2.md)
@@ -105,6 +106,54 @@
105106
- [Exercise 6](./program-analysis/echidna/exercises/Exercise-6.md)
106107
- [Exercise 7](./program-analysis/echidna/exercises/Exercise-7.md)
107108
- [Exercise 8](./program-analysis/echidna/exercises/Exercise-8.md)
109+
- [Medusa](./program-analysis/medusa/docs/src/README.md)
110+
- [Installation](./program-analysis/medusa/docs/src/getting_started/installation.md)
111+
- [First Steps](./program-analysis/medusa/docs/src/getting_started/first_steps.md)
112+
- [Configuration Overview](./program-analysis/medusa/docs/src/project_configuration/overview.md)
113+
- [Fuzzing Configuration](./program-analysis/medusa/docs/src/project_configuration/fuzzing_config.md)
114+
- [Testing Configuration](./program-analysis/medusa/docs/src/project_configuration/testing_config.md)
115+
- [Chain Configuration](./program-analysis/medusa/docs/src/project_configuration/chain_config.md)
116+
- [Compilation Configuration](./program-analysis/medusa/docs/src/project_configuration/compilation_config.md)
117+
- [Logging Configuration](./program-analysis/medusa/docs/src/project_configuration/logging_config.md)
118+
- [CLI Overview](./program-analysis/medusa/docs/src/cli/overview.md)
119+
- [init](./program-analysis/medusa/docs/src/cli/init.md)
120+
- [fuzz](./program-analysis/medusa/docs/src/cli/fuzz.md)
121+
- [completion](./program-analysis/medusa/docs/src/cli/completion.md)
122+
- [Testing Overview](./program-analysis/medusa/docs/src/testing/overview.md)
123+
- [The Fuzzing Lifecycle](./program-analysis/medusa/docs/src/testing/fuzzing_lifecycle.md)
124+
- [Types of Invariants](./program-analysis/medusa/docs/src/testing/invariants.md)
125+
- [Writing Function-Level Invariants](./program-analysis/medusa/docs/src/testing/writing-function-level-invariants.md)
126+
- [Writing System-Level Invariants (WIP)](./program-analysis/medusa/docs/src/testing/writing-system-level-invariants.md)
127+
- [Coverage Reports (WIP)](./program-analysis/medusa/docs/src/testing/coverage_reports.md)
128+
- [API Overview (WIP)](./program-analysis/medusa/docs/src/api/api_overview.md)
129+
- [Cheatcodes](./program-analysis/medusa/docs/src/cheatcodes/cheatcodes_overview.md)
130+
- [warp](./program-analysis/medusa/docs/src/cheatcodes/warp.md)
131+
- [roll](./program-analysis/medusa/docs/src/cheatcodes/roll.md)
132+
- [fee](./program-analysis/medusa/docs/src/cheatcodes/fee.md)
133+
- [difficulty](./program-analysis/medusa/docs/src/cheatcodes/difficulty.md)
134+
- [chainId](./program-analysis/medusa/docs/src/cheatcodes/chain_id.md)
135+
- [store](./program-analysis/medusa/docs/src/cheatcodes/store.md)
136+
- [load](./program-analysis/medusa/docs/src/cheatcodes/load.md)
137+
- [etch](./program-analysis/medusa/docs/src/cheatcodes/etch.md)
138+
- [deal](./program-analysis/medusa/docs/src/cheatcodes/deal.md)
139+
- [snapshot](./program-analysis/medusa/docs/src/cheatcodes/snapshot.md)
140+
- [getNonce](./program-analysis/medusa/docs/src/cheatcodes/get_nonce.md)
141+
- [setNonce](./program-analysis/medusa/docs/src/cheatcodes/set_nonce.md)
142+
- [coinbase](./program-analysis/medusa/docs/src/cheatcodes/coinbase.md)
143+
- [prank](./program-analysis/medusa/docs/src/cheatcodes/prank.md)
144+
- [prankHere](./program-analysis/medusa/docs/src/cheatcodes/prank_here.md)
145+
- [ffi](./program-analysis/medusa/docs/src/cheatcodes/ffi.md)
146+
- [addr](./program-analysis/medusa/docs/src/cheatcodes/addr.md)
147+
- [sign](./program-analysis/medusa/docs/src/cheatcodes/sign.md)
148+
- [toString](./program-analysis/medusa/docs/src/cheatcodes/to_string.md)
149+
- [parseBytes](./program-analysis/medusa/docs/src/cheatcodes/parse_bytes.md)
150+
- [parseBytes32](./program-analysis/medusa/docs/src/cheatcodes/parse_bytes32.md)
151+
- [parseInt](./program-analysis/medusa/docs/src/cheatcodes/parse_int.md)
152+
- [parseUint](./program-analysis/medusa/docs/src/cheatcodes/parse_uint.md)
153+
- [parseBool](./program-analysis/medusa/docs/src/cheatcodes/parse_bool.md)
154+
- [parseAddress](./program-analysis/medusa/docs/src/cheatcodes/parse_address.md)
155+
- [Console Logging](./program-analysis/medusa/docs/src/console_logging.md)
156+
- [FAQ](./program-analysis/medusa/docs/src/faq.md)
108157
- [Manticore](./program-analysis/manticore/README.md)
109158
- [Introduction to symbolic execution](./program-analysis/manticore/symbolic-execution-introduction.md):
110159
- [Running under Manticore](./program-analysis/manticore/running-under-manticore.md)
@@ -119,6 +168,7 @@
119168
- [API](./program-analysis/slither/api.md)
120169
- [Exercise 1](./program-analysis/slither/exercise1.md)
121170
- [Exercise 2](./program-analysis/slither/exercise2.md)
171+
- [Exercise 3](./program-analysis/slither/exercise3.md)
122172
- [Resources](./resources/tob_blogposts.md)
123173
- [Security contact](./resources/contact.md)
124174
- [Blog posts](./resources/tob_blogposts.md)

book.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ mathjax-support = true
2020
[output.html.fold]
2121
enable = true
2222
level = 1
23+
24+
[output.html.redirect]
25+
"medusa/index.html" = "../program-analysis/medusa/docs/src"
26+
"slither/index.html" = "../program-analysis/slither"
27+
"echidna/index.html" = "../program-analysis/echidna"

development-guidelines/incident_response.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Incident Response Recommendations
22

3-
How you respond during an incident is a direct reflection of your efforts to prepare for such an event. Each team or project's needs will vary so we provide the guidelines below as a starting point. Adherance to our guidelines can help you shift from a reactive approach to a **proactive** approach by planning with the assumption that incidents are inevitable. To fully leverage the following guidelines, consider them throughout the application development process.
3+
How you respond during an incident is a direct reflection of your efforts to prepare for such an event. Each team or project's needs will vary so we provide the guidelines below as a starting point. Adherence to our guidelines can help you shift from a reactive approach to a **proactive** approach by planning with the assumption that incidents are inevitable. To fully leverage the following guidelines, consider them throughout the application development process.
44

55
## Application Design
66

0 commit comments

Comments
 (0)