Skip to content

Commit aaf84c1

Browse files
authored
Merge branch 'master' into montyly-patch-1
2 parents 0be0748 + bc54555 commit aaf84c1

File tree

9 files changed

+68
-36
lines changed

9 files changed

+68
-36
lines changed

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
- [How to seed Echidna with unit tests](./program-analysis/echidna/advanced/end-to-end-testing.md)
8989
- [Understanding and using `allContracts`](./program-analysis/echidna/advanced/using-all-contracts.md)
9090
- [How to fuzz contracts with external libraries](./program-analysis/echidna/advanced/working-with-libraries.md)
91+
- [How to do on-chain fuzzing with state forking](./program-analysis/echidna/advanced/state-network-forking.md)
9192
- [Interacting with off-chain data via FFI cheatcode](./program-analysis/echidna/advanced/interacting-with-offchain-data-via-ffi.md)
9293
- [Fuzzing tips](./program-analysis/echidna/fuzzing_tips.md)
9394
- [Frequently Asked Questions](./program-analysis/echidna/frequently_asked_questions.md)
Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,59 @@
1-
# Incident Response Guidelines
1+
# Incident Response Recommendations
22

3-
How you respond during an incident is a direct reflection of your efforts to prepare for such an event. 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. 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.
44

5-
## Application design
5+
## Application Design
66

7-
- **Identify the components that should/should not be**
7+
- **Identify which components should or should not be:**
88
- **Pausable**. While pausing a component can be beneficial during an incident, you must assess its potential impact on other contracts.
99
- **Migratable or upgradeable**. Discovering a bug might necessitate a [migration strategy](https://blog.trailofbits.com/2018/10/29/how-contract-migration-works/) or contract upgrade to fix the issue; note, however, that upgradeability has its own [sets of risks](https://blog.trailofbits.com/2020/12/16/breaking-aave-upgradeability/). Making all contracts upgradeable might not be the best approach.
10-
- **Decentralized**. Using decentralized components can sometimes restrict rescue measures.
11-
- **Evaluate what events are needed**. A missed event in a critical location might result in unnoticed incidents.
10+
- **Decentralized**. Using decentralized components can sometimes limit what rescue measures are possible and may require a higher amount of coordination.
11+
- **Begin to identify important system invariants**. This helps to determine what you will need to monitor and what events may be necessary to do so effectively.
12+
- **Evaluate what additional events are needed**. A missed event in a critical location might result in unnoticed incidents.
1213
- **Evaluate what components must be on-chain and off-chain**. On-chain components are generally more at risk, but off-chain components push the risks to the off-chain owner.
13-
- **Use an access control that allows fine-grained access**. Avoid setting all access controls to be available to an EOA. Opt for multisig wallets/MPC, and segregate access (e.g., the key responsible for setting fees shouldn't have access to the upgradeability feature).
14+
- **Use fine-grained access controls**. Avoid setting all access controls to be available to an EOA. Opt for multisig wallets/MPC, and avoid delegating several roles to one address (e.g., the key responsible for setting fees shouldn't have access to the upgradeability feature).
1415

1516
## Documentation
1617

17-
- **Document how to interpret abnormal events emission**. Only emitting events isn't sufficient; proper documentation is crucial, and users should be empowered to decode them.
18-
- **Document how to access wallets**. Clearly outline how to access wallets. Both the location and access procedures for every wallet should be clear and straightforward.
19-
- **Document the deployment and upgrade process**. Deployment and upgrade processes are risky and must be thoroughly documented. This should include how to test the deployment/upgrade (ex: using fork testing) and how to validate it (ex: using a post-deployment script).
20-
- **Document how to contact the users and external dependencies**. Define guidelines regarding which stakeholders to contact, including the timing and mode of communication in case of incidents.
18+
- **Assemble a runbook of common actions you may need to perform**. It's not possible or practical to exhaustively detail how you'll respond to every type of incident. But you _can_ start to document procedures for some of the more important ones as well as actions that might be common across multiple scenarios (e.g., pausing, rotating owner keys, upgrading an implementation). This can also include scripts or snippets of code to facilitate performing these actions in a reproducible manner.
19+
- **Document how to interpret events emission**. Only emitting events isn't sufficient; proper documentation is crucial, and users should be empowered to identify and decode them.
20+
- **Document how to access wallets**. Clearly outline how to access wallets with special roles in the system. This should include both the location as well as access procedures for each wallet.
21+
- **Document the deployment and upgrade process**. Deployment and upgrade processes are risky and must be thoroughly documented. This should include how to test the deployment/upgrade (e.g., using fork testing) and how to validate it (e.g., using a post-deployment script).
22+
- **Document how to contact users and external dependencies**. Define guidelines regarding which stakeholders to contact, including the timing and mode of communication in case of incidents. The right communication at the right time is key to maintaining trust.
2123

2224
## Process
2325

2426
- **Conduct periodic training and incident response exercises**. Regularly organize training sessions and incident response exercises. Such measures ensure that employees remain updated and can help highlight any flaws in the current incident response protocol.
27+
- **Remember to consider off-chain components when planning**. While much of this document is concerned with on-chain code, compromised frontends or social media accounts are also common sources of incidents.
2528
- **Identify incident owners, with at least**:
2629
- **A technical lead**. Responsible for gathering and centralizing technical data.
2730
- **A communication lead**. Tasked with internal and external communication.
2831
- **A legal lead**. Either provides legal advice or ensures the right legal entities are contacted. It might also be worth considering liaison with appropriate law enforcement agencies.
29-
- **Use automated monitoring tools**. Whether you opt for an in-house solution or third-party products, automation is key. While considering automated responses like pausing the system in the event of irregular activities, exercise caution. Without careful configuration, automatic responses might inadvertently facilitate denial-of-service (DOS) exploits.
32+
- **Use monitoring tools**. You may opt for a third-party product, an in-house solution, or a combination of both. Third-party montoring will identify more generally suspicious transactions but may not be as in tune with system-specific metrics like health factors, collateralization ratios, or if an AMM invariant starts to drift. In-house monitoring, on the other hand, requires more engineering effort to setup and maintain, but can be tailored specifically to your needs.
33+
- **Carefully consider automating certain actions based on monitoring alerts**. You may wish to automatically pause or move the system into a safer state if certain actvities are detected given how quickly some exploits are carried out. However, also keep in mind the impact and likelihood of a false positive triggering such a mechanism and how disruptive that could be.
3034

3135
## Threat Intelligence
3236

33-
- **Identify similar protocols, and stay informed of related compromises**. Being aware of vulnerabilities in similar systems can help preemptively address potential threats in your own.
34-
- **Identify dependencies, and monitor their behaviors to be alerted in case of compromise.** Follow twitter, discord, newsletter, etc.
35-
- **Maintain open communication lines with your dependencies owners**. This will help you to stay informed if one of your dependency is compromised.
36-
- **Subscribe to https://newsletter.blockthreat.io/**. BlockThreat will help you stay informed about recent incidents.
37+
- **Identify similar protocols, and stay informed of any issues affecting them**. This could include forks, implementations on other chains, or protocols in the same general class (e.g., other lending protocols). Being aware of vulnerabilities in similar systems can help preemptively address potential threats in your own.
38+
- **Identify your dependencies, and follow their communication channels to be alerted in case of an issue.** Follow their Twitter, Discord, Telegram, newsletter, etc. This includes both on-chain as well as off-chain (e.g., libraries, toolchain) dependencies.
39+
- **Maintain open communication lines with your dependencies' owners**. This will help you to stay informed if one of your dependencies is compromised.
40+
- **Subscribe to the [BlockThreat](https://newsletter.blockthreat.io/) newsletter**. BlockThreat will keep you informed about recent incidents and developments in blockchain security. The nature of blockchains means we have a culture of learning in the open so take advantage of this and learn from your peers.
3741

3842
Additionally, consider conducting a threat modeling exercise. This exercise will identify risks that an application faces at both the structural and operational level. If you're interested in undertaking such an exercise and would like to work with us, [contact us](https://www.trailofbits.com/contact/).
3943

40-
## Incident Response Plan Resources
44+
## Resources
4145

46+
- [An Incident Response Plan for Startups](https://medium.com/starting-up-security/an-incident-response-plan-for-startups-26549596b914)
47+
- A minimum viable incident response plan, a great starting point for a smaller team. Especially in combination with the Yearn example below, which is tailored a bit more for web3 teams.
48+
- [The practical guide to incident management](https://incident.io/guide)
49+
- An approachable guide for incident response. Chapter 4 includes examples for how to approach practicing your process.
50+
- [PagerDuty Incident Response](https://response.pagerduty.com/)
51+
- A _very_ detailed handbook of how PagerDuty handles incident response themselves. Some useful ideas and resources, but more practical for larger organizations.
4252
- [How to Hack the Yield Protocol](https://docs.yieldprotocol.com/#/operations/how_to_hack)
43-
- [Emergency Steps – Yearn](https://github.com/yearn/yearn-devdocs/blob/master/docs/developers/v2/EMERGENCY.md)
44-
- [Monitoring & Incident Response - Heidi Wilder (DSS 2023)](https://www.youtube.com/watch?v=TDlkkg8N0wc)
53+
- [Emergency Procedures for Yearn Finance](https://github.com/yearn/yearn-devdocs/blob/master/docs/developers/v2/EMERGENCY.md)
54+
- [Rekt pilled: What to do when your dApp gets pwned and how to stay kalm - Heidi Wilder (DSS 2023)](https://www.youtube.com/watch?v=TDlkkg8N0wc)
4555
- [Crisis Handbook - Smart Contract Hack (SEAL)](https://docs.google.com/document/d/1DaAiuGFkMEMMiIuvqhePL5aDFGHJ9Ya6D04rdaldqC0/edit)
4656

47-
### Examples of incidents retrospective
57+
### Community Incident Retrospectives
4858

4959
- [Yield Protocol](https://medium.com/yield-protocol/post-mortem-of-incident-on-august-5th-2022-7bb70dbb9ada)

learn_evm/evm_opcodes.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ The gas information is a work in progress. If an asterisk is in the Gas column,
7878
| [`0x59`](#msize) | MSIZE | Get the size of active memory in bytes | - | 2 |
7979
| [`0x5a`](#gas) | GAS | Get the amount of available gas, including the corresponding reduction for the cost of this instruction | - | 2 |
8080
| [`0x5b`](#jumpdest) | JUMPDEST | Mark a valid destination for jumps | - | 1 |
81-
| `0x5c` - `0x5f` | Unused | - |
81+
| `0x5c` - `0x5e` | Unused | - |
82+
| [`0x5f`](#push0) | PUSH0 | Place the constant value 0 on stack | [EIP-3855](https://eips.ethereum.org/EIPS/eip-3855) | 2 |
8283
| [`0x60`](#push1) | PUSH1 | Place 1 byte item on stack | - | 3 |
8384
| [`0x61`](#push2) | PUSH2 | Place 2-byte item on stack | - | 3 |
8485
| [`0x62`](#push3) | PUSH3 | Place 3-byte item on stack | - | 3 |
@@ -816,6 +817,16 @@ noop, marks a valid jump destination
816817

817818
---
818819

820+
### PUSH0
821+
822+
**0x5f**
823+
824+
The constant value 0 is pushed onto the stack.
825+
826+
() => (0)
827+
828+
---
829+
819830
### PUSH1
820831

821832
**0x60**

program-analysis/echidna/advanced/smart-contract-fuzzing-at-scale.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Once it runs, check the coverage file located in `corpus-exploration/covered.*.t
7474

7575
## 3. Initiate a continuous fuzzing campaign
7676

77-
When satisfied with the first iteration of the initialization, we can start a "continuous campaign" for exploration and testing using [echidna-parade](https://github.com/agroce/echidna-parade). Before starting, double-check your config file. For instance, if you added properties, do not forget to remove `benchmarkMode`.
77+
When satisfied with the first iteration of the initialization, we can start a "continuous campaign" for exploration and testing using [echidna-parade](https://github.com/crytic/echidna-parade). Before starting, double-check your config file. For instance, if you added properties, do not forget to remove `benchmarkMode`.
7878

7979
`echidna-parade` is a tool used to launch multiple Echidna instances simultaneously while keeping track of each corpus. Each instance will be configured to run for a specific duration, with different parameters, to maximize the chance of reaching new code.
8080

program-analysis/echidna/basic/working-with-eth.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ echidna_C_has_some_value: failed!💥
116116
Echidna has two options for using ether during a fuzzing campaign.
117117

118118
- `maxValue` to set the max amount of ether per transaction
119-
- `contractBalance` to set the initial amount of ether that the testing contract receives in the constructor.
119+
- `balanceContract` to set the initial amount of ether that the testing contract receives in the constructor.

program-analysis/echidna/exercises/Exercise-1.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ contract Token is Ownable, Pausable {
5151
mapping(address => uint256) public balances;
5252
5353
function transfer(address to, uint256 value) public whenNotPaused {
54-
balances[msg.sender] -= value;
55-
balances[to] += value;
54+
// unchecked to save gas
55+
unchecked {
56+
balances[msg.sender] -= value;
57+
balances[to] += value;
58+
}
5659
}
5760
}
5861
```
@@ -79,8 +82,8 @@ import "./token.sol";
7982
contract TestToken is Token {
8083
address echidna = tx.origin;
8184
82-
constructor() public {
83-
balances[echidna] = 10000;
85+
constructor() {
86+
balances[echidna] = 10_000;
8487
}
8588
8689
function echidna_test_balance() public view returns (bool) {

program-analysis/echidna/exercises/Exercise-2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import "./token.sol";
8484
/// echidna program-analysis/echidna/exercises/exercise2/template.sol
8585
/// ```
8686
contract TestToken is Token {
87-
constructor() public {
87+
constructor() {
8888
pause(); // pause the contract
8989
owner = address(0); // lose ownership
9090
}

program-analysis/echidna/exercises/Exercise-3.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ We will test the following contract _[token.sol](https://github.com/crytic/build
1919
```solidity
2020
pragma solidity ^0.8.0;
2121
22-
/// @notice The issues from exercises 1 and 2 are fixed.
22+
/// @notice The issues from exercise 1 and 2 are fixed.
2323
2424
contract Ownable {
2525
address public owner = msg.sender;
@@ -74,7 +74,7 @@ contract MintableToken is Token {
7474
int256 public totalMinted;
7575
int256 public totalMintable;
7676
77-
constructor(int256 totalMintable_) public {
77+
constructor(int256 totalMintable_) {
7878
totalMintable = totalMintable_;
7979
}
8080
@@ -111,7 +111,7 @@ contract TestToken is MintableToken {
111111
address echidna = msg.sender;
112112
113113
// TODO: update the constructor
114-
constructor(int256 totalMintable) public MintableToken(totalMintable) {}
114+
constructor(int256 totalMintable) MintableToken(totalMintable) {}
115115
116116
function echidna_test_balance() public view returns (bool) {
117117
// TODO: add the property

program-analysis/echidna/exercises/Exercise-4.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ contract Ownable {
2727
}
2828
2929
modifier onlyOwner() {
30-
require(msg.sender == owner, "Ownable: Caller is not the owner");
30+
require(msg.sender == owner, "Ownable: Caller is not the owner.");
3131
_;
3232
}
3333
}
@@ -48,17 +48,20 @@ contract Pausable is Ownable {
4848
}
4949
5050
modifier whenNotPaused() {
51-
require(!_paused, "Pausable: Contract is paused");
51+
require(!_paused, "Pausable: Contract is paused.");
5252
_;
5353
}
5454
}
5555
5656
contract Token is Ownable, Pausable {
5757
mapping(address => uint256) public balances;
5858
59-
function transfer(address to, uint256 value) public whenNotPaused {
60-
balances[msg.sender] -= value;
61-
balances[to] += value;
59+
function transfer(address to, uint256 value) public virtual whenNotPaused {
60+
// unchecked to save gas
61+
unchecked {
62+
balances[msg.sender] -= value;
63+
balances[to] += value;
64+
}
6265
}
6366
}
6467
```
@@ -88,6 +91,10 @@ import "./token.sol";
8891
/// solc-select use 0.8.0
8992
/// echidna program-analysis/echidna/exercises/exercise4/template.sol --contract TestToken --test-mode assertion
9093
/// ```
94+
/// or by providing a config
95+
/// ```
96+
/// echidna program-analysis/echidna/exercises/exercise4/template.sol --contract TestToken --config program-analysis/echidna/exercises/exercise4/config.yaml
97+
/// ```
9198
contract TestToken is Token {
9299
function transfer(address to, uint256 value) public {
93100
// TODO: include `assert(condition)` statements that

0 commit comments

Comments
 (0)