Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- [Forks <> CIPs](./learn_evm/cips_forks.md)
- [Upgrades <> TIPs](./learn_evm/tips_upgrades.md)
- [Forks <> BEPs](./learn_evm/beps_forks.md)
- [Not so smart contracts]()
- [Not so smart contracts](./not-so-smart-contracts/README.md)
- [Algorand](./not-so-smart-contracts/algorand/README.md)
- [Rekeying](./not-so-smart-contracts/algorand/rekeying/README.md)
- [Unchecked Transaction Fees](./not-so-smart-contracts/algorand/unchecked_transaction_fee/README.md)
Expand Down
33 changes: 16 additions & 17 deletions learn_evm/evm_opcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The gas information is a work in progress. If an asterisk is in the Gas column,
| [`0x55`](#sstore) | SSTORE | Save word to storage | - | 20000** |
| [`0x56`](#jump) | JUMP | Alter the program counter | - | 8 |
| [`0x57`](#jumpi) | JUMPI | Conditionally alter the program counter | - | 10 |
| [`0x58`](#getpc) | GETPC | Get the value of the program counter prior to the increment | - | 2 |
| [`0x58`](#pc) | PC | Get the value of the program counter prior to the increment | - | 2 |
| [`0x59`](#msize) | MSIZE | Get the size of active memory in bytes | - | 2 |
| [`0x5a`](#gas) | GAS | Get the amount of available gas, including the corresponding reduction for the cost of this instruction | - | 2 |
| [`0x5b`](#jumpdest) | JUMPDEST | Mark a valid destination for jumps | - | 1 |
Expand Down Expand Up @@ -149,19 +149,19 @@ The gas information is a work in progress. If an asterisk is in the Gas column,
| [`0xa3`](#log3) | LOG3 | Append log record with three topics | - | 1500 |
| [`0xa4`](#log4) | LOG4 | Append log record with four topics | - | 1875 |
| `0xa5` - `0xaf` | Unused | - |
| [`0xb0`](#jumpto) | JUMPTO | Tentative [libevmasm has different numbers](https://github.com/ethereum/solidity/blob/c61610302aa2bfa029715b534719d25fe3949059/libevmasm/Instruction.h#L176)| [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| [`0xb1`](#jumpif) | JUMPIF | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| [`0xb2`](#jumpsub) | JUMPSUB | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| [`0xb4`](#jumpsubv) | JUMPSUBV | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| [`0xb5`](#beginsub) | BEGINSUB | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| [`0xb6`](#begindata) | BEGINDATA | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| [`0xb8`](#returnsub) | RETURNSUB | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| [`0xb9`](#putlocal) | PUTLOCAL | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| [`0xba`](#getlocal) | GETLOCAL | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| `0xb0` | JUMPTO | Tentative [libevmasm has different numbers](https://github.com/ethereum/solidity/blob/c61610302aa2bfa029715b534719d25fe3949059/libevmasm/Instruction.h#L176)| [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| `0xb1` | JUMPIF | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| `0xb2` | JUMPSUB | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| `0xb4` | JUMPSUBV | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| `0xb5` | BEGINSUB | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| `0xb6` | BEGINDATA | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| `0xb8` | RETURNSUB | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| `0xb9` | PUTLOCAL | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| `0xba` | GETLOCAL | Tentative | [EIP 615](https://github.com/ethereum/EIPs/blob/606405b5ab7aa28d8191958504e8aad4649666c9/EIPS/eip-615.md) |
| `0xbb` - `0xe0` | Unused | - |
| [`0xe1`](#sloadbytes) | SLOADBYTES | Only referenced in pyethereum | - | - |
| [`0xe2`](#sstorebytes) | SSTOREBYTES | Only referenced in pyethereum | - | - |
| [`0xe3`](#ssize) | SSIZE | Only referenced in pyethereum | - | - |
| `0xe1` | SLOADBYTES | Only referenced in pyethereum | - | - |
| `0xe2` | SSTOREBYTES | Only referenced in pyethereum | - | - |
| `0xe3` | SSIZE | Only referenced in pyethereum | - | - |
| `0xe4` - `0xef` | Unused | - |
| [`0xf0`](#create) | CREATE | Create a new account with associated code | - | 32000 |
| [`0xf1`](#call) | CALL | Message-call into an account | - | Complicated |
Expand All @@ -172,9 +172,8 @@ The gas information is a work in progress. If an asterisk is in the Gas column,
| `0xf6` - `0xf9` | Unused | - | - |
| [`0xfa`](#staticcall) | STATICCALL | Similar to CALL, but does not modify state | - | 40 |
| `0xfb` | Unused | - | - |
| [`0xfc`](#txexecgas) | TXEXECGAS | Not in yellow paper FIXME | - | - |
| [`0xfd`](#revert) | REVERT | Stop execution and revert state changes, without consuming all provided gas and providing a reason | - | 0 |
| [`0xfe`](#invalid) | INVALID | Designated invalid instruction | - | 0 |
| `0xfe` | INVALID | Designated invalid instruction | - | 0 |
| [`0xff`](#selfdestruct) | SELFDESTRUCT | Halt execution and register account for later deletion | - | 5000* |

## Instruction Details
Expand Down Expand Up @@ -262,7 +261,7 @@ c = (a + b) % m
c = (a * b) % m

-----
### EXT
### EXP
**0x0a**

(a, b, m) => (c)
Expand Down Expand Up @@ -408,7 +407,7 @@ res = value >> shift
value: int256

-----
### SHA3
### KECCAK256
**0x20**

(offset, len) => (hash)
Expand Down
6 changes: 3 additions & 3 deletions program-analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ The broad areas that are frequently relevant for smart contracts include:
Component | Tools | Examples
--- | --- | --- |
State machine | Echidna, Manticore |
Access control | Slither, Echidna, Manticore | [Slither exercise 2](https://github.com/crytic/building-secure-contracts/blob/master/program-analysis/slither/exercise2.md), [Echidna exercise 2](https://github.com/crytic/building-secure-contracts/blob/master/program-analysis/echidna/Exercise-2.md)
Arithmetic operations | Manticore, Echidna | [Echidna exercise 1](https://github.com/crytic/building-secure-contracts/blob/master/program-analysis/echidna/Exercise-1.md), [Manticore exercises 1 - 3](https://github.com/crytic/building-secure-contracts/tree/master/program-analysis/manticore/exercises)
Inheritance correctness | Slither | [Slither exercise 1](https://github.com/crytic/building-secure-contracts/blob/master/program-analysis/slither/exercise1.md)
Access control | Slither, Echidna, Manticore | [Slither exercise 2](./slither/exercise2.md), [Echidna exercise 2](./echidna/exercises/Exercise-2.md)
Arithmetic operations | Manticore, Echidna | [Echidna exercise 1](./echidna/exercises/Exercise-1.md), [Manticore exercises 1 - 3](./manticore/exercises)
Inheritance correctness | Slither | [Slither exercise 1](./slither/exercise1.md)
External interactions | Manticore, Echidna |
Standard conformance | Slither, Echidna, Manticore | [`slither-erc`](https://github.com/crytic/slither/wiki/ERC-Conformance)

Expand Down
2 changes: 1 addition & 1 deletion program-analysis/echidna/exercises/Exercise-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ We recommend to first try without reading the following hints. The hints are in

- Remember that sometimes you have to supply the test contract with Ether. Read more in [the Echidna wiki](https://github.com/crytic/echidna/wiki/Config) and look at [the default config setup](https://github.com/crytic/echidna/blob/master/tests/solidity/basic/default.yaml).
- The invariant that we are looking for is "the balance of the receiver contract can not decrease"
- Read what is the [multi abi option](https://github.com/crytic/building-secure-contracts/blob/master/program-analysis/echidna/common-testing-approaches.md#external-testing)
- Read what is the [multi abi option](../basic/common-testing-approaches.md#external-testing)
- A template is provided in [contracts/naive-receiver/NaiveReceiverEchidna.sol](https://github.com/crytic/damn-vulnerable-defi-echidna/blob/hints/contracts/naive-receiver/NaiveReceiverEchidna.sol)
- A config file is provided in [naivereceiver.yaml](https://github.com/crytic/damn-vulnerable-defi-echidna/blob/hints/naivereceiver.yaml)

Expand Down
2 changes: 1 addition & 1 deletion program-analysis/echidna/exercises/Exercise-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Only the following contracts are relevant:
We recommend to first try without reading the following hints. The hints are in the [`hints` branch](https://github.com/crytic/damn-vulnerable-defi-echidna/tree/hints).

- The invariant that we are looking for is "Flash loan can always be made"
- Read what is the [multi abi option](https://github.com/crytic/building-secure-contracts/blob/master/program-analysis/echidna/common-testing-approaches.md#external-testing)
- Read what is the [multi abi option](../basic/common-testing-approaches.md#external-testing)
- The `receiveTokens` callback function must be implemented
- A template is provided in [contracts/unstoppable/UnstoppableEchidna.sol](https://github.com/crytic/damn-vulnerable-defi-echidna/blob/hints/contracts/unstoppable/UnstoppableEchidna.sol)
- A config file is provided in [unstoppable.yaml](https://github.com/crytic/damn-vulnerable-defi-echidna/blob/hints/unstoppable.yaml)
Expand Down
2 changes: 1 addition & 1 deletion program-analysis/echidna/exercises/Exercise-8.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Only the following contracts are relevant:
We recommend to first try without reading the following hints. The hints are in the [`hints` branch](https://github.com/crytic/damn-vulnerable-defi-echidna/tree/hints).

- The invariant that we are looking for is "an attacker cannot get almost whole amount of rewards"
- Read what is the [multi abi option](https://github.com/crytic/building-secure-contracts/blob/master/program-analysis/echidna/common-testing-approaches.md#external-testing)
- Read what is the [multi abi option](../basic/common-testing-approaches.md#external-testing)
- A config file is provided in [the-rewarder.yaml](https://github.com/crytic/damn-vulnerable-defi-echidna/blob/solutions/the-rewarder.yaml)

## Solution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ As `f()` contains two paths, a DSE will construct two differents path predicates
- Path 1: `a == 65`
- Path 2: `Not (a == 65)`

Each path predicate is a mathematical formula that can be given to a so-called [SMT solver](https://github.com/crytic/building-secure-contracts/blob/master/program-analysis/manticore/symbolic-execution-introduction.md), which will try to solve the equation. For `Path 1`, the solver will say that the path can be explored with `a = 65`. For `Path 2`, the solver can give `a` any value other than 65, for example `a = 0`.
Each path predicate is a mathematical formula that can be given to a so-called `SMT solver`, which will try to solve the equation. For `Path 1`, the solver will say that the path can be explored with `a = 65`. For `Path 2`, the solver can give `a` any value other than 65, for example `a = 0`.

### Verifying properties
Manticore allows a full control over all the execution of each path. As a result, it allows to add arbirtray contraints to almost anything. This control allows for the creation of properties on the contract.
Expand Down