Skip to content

Commit

Permalink
Merge pull request #83 from 0xSandyy/Divide-By-Zero
Browse files Browse the repository at this point in the history
Divide by zero vulnerability added to DoS revert.
  • Loading branch information
kadenzipfel authored Jun 18, 2024
2 parents d1930ea + 731f5df commit bd630f9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vulnerabilities/dos-revert.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ It's important to take caution in enforcing expected contract balances of tokens

Consider, for example, a contract which expects the Ether balance to be 0 for the first deposit to allow for custom accounting logic. An attacker may forcibly send Ether to the contract before the first deposit, causing all deposits to revert.

### Divide by Zero
In solidity if the contract attempts to perform division when the denominator is ``zero``, the call reverts. Thus, the denominator should be always checked before division to prevent DoS revert.
```solidity
function foo(uint num, uint den) public pure returns(uint result) {
result = num / den; // if den = 0, the execution reverts
}
```

### Sources

- https://consensys.github.io/smart-contract-best-practices/attacks/denial-of-service/
Expand Down

0 comments on commit bd630f9

Please sign in to comment.