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
8 changes: 4 additions & 4 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ FixedPointMathLibTest:testSqrt(uint256) (runs: 256, μ: 997, ~: 1013)
FixedPointMathLibTest:testSqrtBack(uint256) (runs: 256, μ: 15210, ~: 340)
FixedPointMathLibTest:testSqrtBackHashed(uint256) (runs: 256, μ: 59066, ~: 59500)
FixedPointMathLibTest:testSqrtBackHashedSingle() (gas: 58937)
LibStringTest:testDifferentiallyFuzzToString(uint256,bytes) (runs: 256, μ: 20875, ~: 8988)
LibStringTest:testDifferentiallyFuzzToStringInt(int256,bytes) (runs: 256, μ: 20129, ~: 8360)
LibStringTest:testDifferentiallyFuzzToString(uint256,bytes) (runs: 256, μ: 20892, ~: 8988)
LibStringTest:testDifferentiallyFuzzToStringInt(int256,bytes) (runs: 256, μ: 20081, ~: 8356)
LibStringTest:testToString() (gas: 10069)
LibStringTest:testToStringDirty() (gas: 8145)
LibStringTest:testToStringIntNegative() (gas: 11096)
LibStringTest:testToStringIntPositive() (gas: 10509)
LibStringTest:testToStringIntNegative() (gas: 9634)
LibStringTest:testToStringIntPositive() (gas: 10481)
LibStringTest:testToStringOverwrite() (gas: 506)
MerkleProofLibTest:testValidProofSupplied() (gas: 2153)
MerkleProofLibTest:testVerifyEmptyMerkleProofSuppliedLeafAndRootDifferent() (gas: 1458)
Expand Down
2 changes: 1 addition & 1 deletion lib/ds-test
Submodule ds-test updated 1 files
+15 −0 package.json
19 changes: 17 additions & 2 deletions src/utils/LibString.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@ pragma solidity >=0.8.0;
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/LibString.sol)
/// @author Modified from Solady (https://github.com/Vectorized/solady/blob/main/src/utils/LibString.sol)
library LibString {
function toString(int256 value) internal pure returns (string memory) {
function toString(int256 value) internal pure returns (string memory str) {
if (value >= 0) return toString(uint256(value));

unchecked {
return value >= 0 ? toString(uint256(value)) : string(abi.encodePacked("-", toString(uint256(-value))));
str = toString(uint256(-value));

/// @solidity memory-safe-assembly
assembly {
// Note: This is only safe because we over-allocate memory
// and write the string from right to left in toString(uint256),
// and thus can be sure that sub(str, 1) is an unused memory location.

let length := mload(str) // Load the string length.
// Put the - character at the start of the string contents.
mstore(str, 45) // 45 is the ASCII code for the - character.
str := sub(str, 1) // Move back the string pointer by a byte.
mstore(str, add(length, 1)) // Update the string length.
}
}
}

Expand Down