diff --git a/src/utils/CREATE3.sol b/src/utils/CREATE3.sol index 96e5554c..0d5b341e 100644 --- a/src/utils/CREATE3.sol +++ b/src/utils/CREATE3.sol @@ -42,6 +42,7 @@ library CREATE3 { bytes memory proxyChildBytecode = PROXY_BYTECODE; address proxy; + /// @solidity memory-safe-assembly assembly { // Deploy a new contract with our pre-made bytecode via CREATE2. // We start 32 bytes into the code to avoid copying the byte length. diff --git a/src/utils/FixedPointMathLib.sol b/src/utils/FixedPointMathLib.sol index 364268c2..68877227 100644 --- a/src/utils/FixedPointMathLib.sol +++ b/src/utils/FixedPointMathLib.sol @@ -38,6 +38,7 @@ library FixedPointMathLib { uint256 y, uint256 denominator ) internal pure returns (uint256 z) { + /// @solidity memory-safe-assembly assembly { // Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y)) if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) { @@ -54,6 +55,7 @@ library FixedPointMathLib { uint256 y, uint256 denominator ) internal pure returns (uint256 z) { + /// @solidity memory-safe-assembly assembly { // Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y)) if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) { @@ -71,6 +73,7 @@ library FixedPointMathLib { uint256 n, uint256 scalar ) internal pure returns (uint256 z) { + /// @solidity memory-safe-assembly assembly { switch x case 0 { @@ -159,6 +162,7 @@ library FixedPointMathLib { //////////////////////////////////////////////////////////////*/ function sqrt(uint256 x) internal pure returns (uint256 z) { + /// @solidity memory-safe-assembly assembly { let y := x // We start y at x, which will help us make our initial estimate. @@ -223,6 +227,7 @@ library FixedPointMathLib { } function unsafeMod(uint256 x, uint256 y) internal pure returns (uint256 z) { + /// @solidity memory-safe-assembly assembly { // Mod x by y. Note this will return // 0 instead of reverting if y is zero. @@ -231,6 +236,7 @@ library FixedPointMathLib { } function unsafeDiv(uint256 x, uint256 y) internal pure returns (uint256 r) { + /// @solidity memory-safe-assembly assembly { // Divide x by y. Note this will return // 0 instead of reverting if y is zero. @@ -239,6 +245,7 @@ library FixedPointMathLib { } function unsafeDivUp(uint256 x, uint256 y) internal pure returns (uint256 z) { + /// @solidity memory-safe-assembly assembly { // Add 1 to x * y if x % y > 0. Note this will // return 0 instead of reverting if y is zero. diff --git a/src/utils/LibString.sol b/src/utils/LibString.sol index 5752a156..b69ccdf7 100644 --- a/src/utils/LibString.sol +++ b/src/utils/LibString.sol @@ -6,6 +6,7 @@ pragma solidity >=0.8.0; /// @author Modified from Solady (https://github.com/Vectorized/solady/blob/main/src/utils/LibString.sol) library LibString { function toString(uint256 value) internal pure returns (string memory str) { + /// @solidity memory-safe-assembly assembly { // The maximum value of a uint256 contains 78 digits (1 byte per digit), but we allocate 160 bytes // to keep the free memory pointer word aligned. We'll need 1 word for the length, 1 word for the diff --git a/src/utils/MerkleProofLib.sol b/src/utils/MerkleProofLib.sol index ceef023c..8fd7cbd7 100644 --- a/src/utils/MerkleProofLib.sol +++ b/src/utils/MerkleProofLib.sol @@ -10,6 +10,7 @@ library MerkleProofLib { bytes32 root, bytes32 leaf ) internal pure returns (bool isValid) { + /// @solidity memory-safe-assembly assembly { if proof.length { // Left shifting by 5 is like multiplying by 32. diff --git a/src/utils/SSTORE2.sol b/src/utils/SSTORE2.sol index 467a93fa..23d69803 100644 --- a/src/utils/SSTORE2.sol +++ b/src/utils/SSTORE2.sol @@ -34,6 +34,7 @@ library SSTORE2 { runtimeCode // The bytecode we want the contract to have after deployment. Capped at 1 byte less than the code size limit. ); + /// @solidity memory-safe-assembly assembly { // Deploy a new contract with the generated creation code. // We start 32 bytes into the code to avoid copying the byte length. @@ -79,6 +80,7 @@ library SSTORE2 { uint256 start, uint256 size ) private view returns (bytes memory data) { + /// @solidity memory-safe-assembly assembly { // Get a pointer to some free memory. data := mload(0x40) diff --git a/src/utils/SafeTransferLib.sol b/src/utils/SafeTransferLib.sol index d08d1b84..7080fd83 100644 --- a/src/utils/SafeTransferLib.sol +++ b/src/utils/SafeTransferLib.sol @@ -15,6 +15,7 @@ library SafeTransferLib { function safeTransferETH(address to, uint256 amount) internal { bool success; + /// @solidity memory-safe-assembly assembly { // Transfer the ETH and store if it succeeded or not. success := call(gas(), to, amount, 0, 0, 0, 0) @@ -35,6 +36,7 @@ library SafeTransferLib { ) internal { bool success; + /// @solidity memory-safe-assembly assembly { // Get a pointer to some free memory. let freeMemoryPointer := mload(0x40) @@ -67,6 +69,7 @@ library SafeTransferLib { ) internal { bool success; + /// @solidity memory-safe-assembly assembly { // Get a pointer to some free memory. let freeMemoryPointer := mload(0x40) @@ -98,6 +101,7 @@ library SafeTransferLib { ) internal { bool success; + /// @solidity memory-safe-assembly assembly { // Get a pointer to some free memory. let freeMemoryPointer := mload(0x40) diff --git a/src/utils/SignedWadMath.sol b/src/utils/SignedWadMath.sol index c694cda5..69239d2c 100644 --- a/src/utils/SignedWadMath.sol +++ b/src/utils/SignedWadMath.sol @@ -7,6 +7,7 @@ pragma solidity >=0.8.0; /// @dev Will not revert on overflow, only use where overflow is not possible. function toWadUnsafe(uint256 x) pure returns (int256 r) { + /// @solidity memory-safe-assembly assembly { // Multiply x by 1e18. r := mul(x, 1000000000000000000) @@ -17,6 +18,7 @@ function toWadUnsafe(uint256 x) pure returns (int256 r) { /// @dev Will not revert on overflow, only use where overflow is not possible. /// @dev Not meant for negative second amounts, it assumes x is positive. function toDaysWadUnsafe(uint256 x) pure returns (int256 r) { + /// @solidity memory-safe-assembly assembly { // Multiply x by 1e18 and then divide it by 86400. r := div(mul(x, 1000000000000000000), 86400) @@ -27,6 +29,7 @@ function toDaysWadUnsafe(uint256 x) pure returns (int256 r) { /// @dev Will not revert on overflow, only use where overflow is not possible. /// @dev Not meant for negative day amounts, it assumes x is positive. function fromDaysWadUnsafe(int256 x) pure returns (uint256 r) { + /// @solidity memory-safe-assembly assembly { // Multiply x by 86400 and then divide it by 1e18. r := div(mul(x, 86400), 1000000000000000000) @@ -35,6 +38,7 @@ function fromDaysWadUnsafe(int256 x) pure returns (uint256 r) { /// @dev Will not revert on overflow, only use where overflow is not possible. function unsafeWadMul(int256 x, int256 y) pure returns (int256 r) { + /// @solidity memory-safe-assembly assembly { // Multiply x by y and divide by 1e18. r := sdiv(mul(x, y), 1000000000000000000) @@ -44,6 +48,7 @@ function unsafeWadMul(int256 x, int256 y) pure returns (int256 r) { /// @dev Will return 0 instead of reverting if y is zero and will /// not revert on overflow, only use where overflow is not possible. function unsafeWadDiv(int256 x, int256 y) pure returns (int256 r) { + /// @solidity memory-safe-assembly assembly { // Multiply x by 1e18 and divide it by y. r := sdiv(mul(x, 1000000000000000000), y) @@ -51,6 +56,7 @@ function unsafeWadDiv(int256 x, int256 y) pure returns (int256 r) { } function wadMul(int256 x, int256 y) pure returns (int256 r) { + /// @solidity memory-safe-assembly assembly { // Store x * y in r for now. r := mul(x, y) @@ -66,6 +72,7 @@ function wadMul(int256 x, int256 y) pure returns (int256 r) { } function wadDiv(int256 x, int256 y) pure returns (int256 r) { + /// @solidity memory-safe-assembly assembly { // Store x * 1e18 in r for now. r := mul(x, 1000000000000000000) @@ -119,6 +126,7 @@ function wadExp(int256 x) pure returns (int256 r) { q = ((q * x) >> 96) - 14423608567350463180887372962807573; q = ((q * x) >> 96) + 26449188498355588339934803723976023; + /// @solidity memory-safe-assembly assembly { // Div in assembly because solidity adds a zero check despite the unchecked. // The q polynomial won't have zeros in the domain as all its roots are complex. @@ -147,6 +155,7 @@ function wadLn(int256 x) pure returns (int256 r) { // ln(x * C) = ln(x) + ln(C), we can simply do nothing here // and add ln(2**96 / 10**18) at the end. + /// @solidity memory-safe-assembly assembly { r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) @@ -183,6 +192,7 @@ function wadLn(int256 x) pure returns (int256 r) { q = ((q * x) >> 96) + 204048457590392012362485061816622; q = ((q * x) >> 96) + 31853899698501571402653359427138; q = ((q * x) >> 96) + 909429971244387300277376558375; + /// @solidity memory-safe-assembly assembly { // Div in assembly because solidity adds a zero check despite the unchecked. // The q polynomial is known not to have zeros in the domain. @@ -211,6 +221,7 @@ function wadLn(int256 x) pure returns (int256 r) { /// @dev Will return 0 instead of reverting if y is zero. function unsafeDiv(int256 x, int256 y) pure returns (int256 r) { + /// @solidity memory-safe-assembly assembly { // Divide x by y. r := sdiv(x, y)