From 2fa335ee33baa4ecf385cdce33379c4a169c3b3d Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Thu, 17 Oct 2024 17:31:06 -0400 Subject: [PATCH 1/6] Pashov L-06 --- .../positionDescriptor bytecode size.snap | 2 +- src/libraries/SafeCurrencyMetadata.sol | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.forge-snapshots/positionDescriptor bytecode size.snap b/.forge-snapshots/positionDescriptor bytecode size.snap index 702b832f..558ac848 100644 --- a/.forge-snapshots/positionDescriptor bytecode size.snap +++ b/.forge-snapshots/positionDescriptor bytecode size.snap @@ -1 +1 @@ -31074 \ No newline at end of file +31181 \ No newline at end of file diff --git a/src/libraries/SafeCurrencyMetadata.sol b/src/libraries/SafeCurrencyMetadata.sol index 029244aa..90b26b00 100644 --- a/src/libraries/SafeCurrencyMetadata.sol +++ b/src/libraries/SafeCurrencyMetadata.sol @@ -11,6 +11,8 @@ import {AddressStringUtil} from "./AddressStringUtil.sol"; library SafeCurrencyMetadata { using CurrencyLibrary for Currency; + uint8 constant MAX_SYMBOL_LENGTH = 6; + /// @notice attempts to extract the token symbol. if it does not implement symbol, returns a symbol derived from the address /// @param currency The currency /// @param nativeLabel The native label @@ -25,6 +27,9 @@ library SafeCurrencyMetadata { // fallback to 6 uppercase hex of address return addressToSymbol(currencyAddress); } + if (bytes(symbol).length > MAX_SYMBOL_LENGTH) { + return truncateSymbol(symbol); + } return symbol; } @@ -92,4 +97,16 @@ library SafeCurrencyMetadata { } return ""; } + + /// @notice truncates the symbol to the MAX_SYMBOL_LENGTH + /// @param str the symbol + /// @return the truncated symbol + function truncateSymbol(string memory str) internal pure returns (string memory) { + bytes memory strBytes = bytes(str); + bytes memory truncatedBytes = new bytes(MAX_SYMBOL_LENGTH); + for (uint256 i = 0; i < MAX_SYMBOL_LENGTH; i++) { + truncatedBytes[i] = strBytes[i]; + } + return string(truncatedBytes); + } } From 1d5ed9352cb9a2e4bc54fa9dd2f225eea71c1e43 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Mon, 21 Oct 2024 17:30:16 -0400 Subject: [PATCH 2/6] change max length to 12 instead of 6 --- .forge-snapshots/positionDescriptor bytecode size.snap | 2 +- src/libraries/SafeCurrencyMetadata.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.forge-snapshots/positionDescriptor bytecode size.snap b/.forge-snapshots/positionDescriptor bytecode size.snap index 558ac848..a9dda5b9 100644 --- a/.forge-snapshots/positionDescriptor bytecode size.snap +++ b/.forge-snapshots/positionDescriptor bytecode size.snap @@ -1 +1 @@ -31181 \ No newline at end of file +31250 \ No newline at end of file diff --git a/src/libraries/SafeCurrencyMetadata.sol b/src/libraries/SafeCurrencyMetadata.sol index 90b26b00..74c9eb40 100644 --- a/src/libraries/SafeCurrencyMetadata.sol +++ b/src/libraries/SafeCurrencyMetadata.sol @@ -11,7 +11,7 @@ import {AddressStringUtil} from "./AddressStringUtil.sol"; library SafeCurrencyMetadata { using CurrencyLibrary for Currency; - uint8 constant MAX_SYMBOL_LENGTH = 6; + uint8 constant MAX_SYMBOL_LENGTH = 12; /// @notice attempts to extract the token symbol. if it does not implement symbol, returns a symbol derived from the address /// @param currency The currency From 9f41e1baee5b3f7a6daf1594d1950adc26e3effd Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Mon, 28 Oct 2024 11:47:13 -0400 Subject: [PATCH 3/6] test file --- test/libraries/SafeCurrencyMetadata.t.sol | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/libraries/SafeCurrencyMetadata.t.sol diff --git a/test/libraries/SafeCurrencyMetadata.t.sol b/test/libraries/SafeCurrencyMetadata.t.sol new file mode 100644 index 00000000..02c407ca --- /dev/null +++ b/test/libraries/SafeCurrencyMetadata.t.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.24; + +import "forge-std/Test.sol"; +import {SafeCurrencyMetadata} from "../../src/libraries/SafeCurrencyMetadata.sol"; + +contract SafeCurrencyMetadataTest is Test { + + function test_truncateSymbol_succeeds() public pure { + // 12 characters + assertEq(SafeCurrencyMetadata.truncateSymbol("123456789012"), "123456789012"); + // 13 characters + assertEq(SafeCurrencyMetadata.truncateSymbol("1234567890123"), "123456789012"); + // 14 characters + assertEq(SafeCurrencyMetadata.truncateSymbol("12345678901234"), "123456789012"); + } + +} \ No newline at end of file From ad52b77efd43132164bcb6bff696df26d012bf61 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Mon, 28 Oct 2024 11:49:40 -0400 Subject: [PATCH 4/6] format --- test/libraries/SafeCurrencyMetadata.t.sol | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/libraries/SafeCurrencyMetadata.t.sol b/test/libraries/SafeCurrencyMetadata.t.sol index 02c407ca..15f6e0f5 100644 --- a/test/libraries/SafeCurrencyMetadata.t.sol +++ b/test/libraries/SafeCurrencyMetadata.t.sol @@ -5,7 +5,6 @@ import "forge-std/Test.sol"; import {SafeCurrencyMetadata} from "../../src/libraries/SafeCurrencyMetadata.sol"; contract SafeCurrencyMetadataTest is Test { - function test_truncateSymbol_succeeds() public pure { // 12 characters assertEq(SafeCurrencyMetadata.truncateSymbol("123456789012"), "123456789012"); @@ -14,5 +13,4 @@ contract SafeCurrencyMetadataTest is Test { // 14 characters assertEq(SafeCurrencyMetadata.truncateSymbol("12345678901234"), "123456789012"); } - -} \ No newline at end of file +} From b96180ea0a3d5413f39e51d5347a9d32b8508a77 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Mon, 28 Oct 2024 16:29:18 -0400 Subject: [PATCH 5/6] fix bytecode --- .forge-snapshots/positionDescriptor bytecode size.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forge-snapshots/positionDescriptor bytecode size.snap b/.forge-snapshots/positionDescriptor bytecode size.snap index 0ae7110a..6f097d73 100644 --- a/.forge-snapshots/positionDescriptor bytecode size.snap +++ b/.forge-snapshots/positionDescriptor bytecode size.snap @@ -1 +1 @@ -31738 \ No newline at end of file +31619 \ No newline at end of file From ea73362c741594ba829e2e9e124d6802cc561ea6 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Tue, 29 Oct 2024 10:54:51 -0400 Subject: [PATCH 6/6] comment --- src/libraries/SafeCurrencyMetadata.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/SafeCurrencyMetadata.sol b/src/libraries/SafeCurrencyMetadata.sol index 74c9eb40..b220bf29 100644 --- a/src/libraries/SafeCurrencyMetadata.sol +++ b/src/libraries/SafeCurrencyMetadata.sol @@ -99,6 +99,7 @@ library SafeCurrencyMetadata { } /// @notice truncates the symbol to the MAX_SYMBOL_LENGTH + /// @dev assumes the string is already longer than MAX_SYMBOL_LENGTH (or the same) /// @param str the symbol /// @return the truncated symbol function truncateSymbol(string memory str) internal pure returns (string memory) {