Skip to content

Commit

Permalink
Merge pull request #134 from CoinFabrik/122-write-assert-violation-do…
Browse files Browse the repository at this point in the history
…cumentation

122 write assert violation documentation
  • Loading branch information
arturoBeccar authored Apr 18, 2024
2 parents c29fdcb + de1bb5c commit 663d14d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 63 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ Visit [Scout's website](https://coinfabrik.github.io/scout-soroban/) to view the
| [dos-unbounded-operation](https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/dos-unbounded-operation) | DoS due to unbounded operation. | [1](https://github.com/CoinFabrik/scout-soroban/tree/main/test-cases/dos-unbounded-operation/dos-unbounded-operation-1), [2](https://github.com/CoinFabrik/scout-soroban/tree/main/test-cases/dos-unbounded-operation/dos-unbounded-operation-2), [3](https://github.com/CoinFabrik/scout-soroban/tree/main/test-cases/dos-unbounded-operation/dos-unbounded-operation-3) | Medium |
| [soroban-version](https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/soroban-version) | Using an old version of Soroban can be dangerous, as it may have bugs or security issues. Use the latest version available. | [1](https://github.com/CoinFabrik/scout-soroban/tree/main/test-cases/soroban-version/soroban-version-1) | Enhancement |
| [unused-return-enum](https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/unused-return-enum) | Return enum from a function is not completely used. | [1](https://github.com/CoinFabrik/scout-soroban/tree/main/test-cases/unused-return-enum/unused-return-enum-1), [2](https://github.com/CoinFabrik/scout-soroban/tree/main/test-cases/unused-return-enum/unused-return-enum-2) | Minor |
[iterators-over-indexing](https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/iterators-over-indexing) |Iterating with hardcoded indexes is slower than using an iterator. Also, if the index is out of bounds, it will panic. | [1](https://github.com/CoinFabrik/scout-soroban/tree/main/test-cases/iterators-over-indexing-1), | Enhancement |
| [iterators-over-indexing](https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/iterators-over-indexing) |Iterating with hardcoded indexes is slower than using an iterator. Also, if the index is out of bounds, it will panic. | [1](https://github.com/CoinFabrik/scout-soroban/tree/main/test-cases/iterators-over-indexing-1) | Enhancement |
| [assert-violation](https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/assert-violation) | Avoid the usage of the macro assert!, it can panic.| [1](https://github.com/CoinFabrik/scout-soroban/tree/main/test-cases/assert-violation/assert-violation-1) | Enhancement |


## Tests

Expand Down
60 changes: 0 additions & 60 deletions detectors/unprotected-mapping-operation/README.md

This file was deleted.

33 changes: 33 additions & 0 deletions docs/docs/detectors/15-assert-violation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Assert violation

### What it does​

Checks for `assert!` macro usage.

### Why is this bad?​

The `assert!` macro can cause the contract to panic.

### Example​

```rust
pub fn assert_if_greater_than_10(_env: Env, value: u128) -> bool {
assert!(value <= 10, "value should be less than 10");
true
}

```
Use instead:

```rust
pub fn assert_if_greater_than_10(_env: Env, value: u128) -> Result<bool, AVError> {
if value <= 10 {
Ok(true)
} else {
Err(AVError::GreaterThan10)
}
}
```
### Implementation

The detector's implementation can be found at [this link](https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/assert-violation).
10 changes: 8 additions & 2 deletions docs/docs/vulnerabilities/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ definition of the `Result` type enum consists of two variants: Ok and Err. If
any of the variants is not used, the code could be simplified or it could imply
a bug.

We put this vulnerability under the [Validations and error handling category](#vulnerability-categories)
with a Minor severity.
We put this vulnerability under the [Validations and error handling category](#vulnerability-categories) with a Minor severity.

### Iterators-over-indexing

Expand All @@ -211,3 +210,10 @@ This could lead to potential integer overflow vulnerabilities, which would trigg

This vulnerability falls under the [Best practices](#vulnerability-categories) category and has an Enhancement severity.

### Assert violation

The assert! macro is used in Rust to ensure that a certain condition holds true at a certain point in your code. The `assert!` macro can cause the contract to panic. Therefore, the detector suggests replacing `assert!` constructs with `Error` enum structures.

This vulnerability falls under the category [Validations and error handling](#vulnerability-categories) and has an Enhancement severity.


0 comments on commit 663d14d

Please sign in to comment.