Skip to content

Commit 2fc20d4

Browse files
committed
Nits
1 parent 2b72050 commit 2fc20d4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

contracts/utils/Panic.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ pragma solidity ^0.8.20;
55
/**
66
* @dev Helper library for emitting standardized panic codes.
77
*
8+
* ```solidity
9+
* contract Example {
10+
* using Panic for uint256;
11+
*
12+
* // Use any of the declared internal constants
13+
* function foo() { Panic.GENERIC.panic(); }
14+
*
15+
* // Alternatively
16+
* function foo() { Panic.panic(Panic.GENERIC); }
17+
* }
18+
* ```
19+
*
820
* Follows the list from libsolutil: https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h
921
*/
1022
// slither-disable-next-line unused-state
@@ -30,6 +42,8 @@ library Panic {
3042
/// @dev calling invalid internal function
3143
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
3244

45+
/// @dev Reverts with a panic code. Recommended to use with
46+
/// the internal constants with predefined codes.
3347
function panic(uint256 code) internal pure {
3448
/// @solidity memory-safe-assembly
3549
assembly {

contracts/utils/math/Math.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ library Math {
331331
mstore(add(ptr, 0x80), e)
332332
mstore(add(ptr, 0xa0), m)
333333

334+
// Given the result < m, it's guaranteed to fit in 32 bytes,
335+
// so we can use the memory scratch space located at offset 0.
334336
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
335337
result := mload(0x00)
336338
}

0 commit comments

Comments
 (0)