Skip to content

Commit 90db92c

Browse files
authored
🐞 Fix LibString.packTwo() (#1510)
* 🐞 Fix packTwo * f fmt * T * T * fix typo
1 parent 95408a3 commit 90db92c

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

β€Žfoundry.tomlβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ fs_permissions = [{ access = "read", path = "./test/data"}]
1515
remappings = [
1616
"forge-std=test/utils/forge-std/"
1717
]
18+
# remove memory-safe-assembly warning from compiler
19+
ignored_error_codes = [2424,8429,4591]
1820

1921
[profile.pre_global_structs]
2022
skip = ["*/g/*", "*/*7702*", "*/*BlockHashLib*", "*/*Transient*", "*/ext/ithaca/*", "*/ext/zksync/*"]
@@ -46,6 +48,9 @@ remappings = [
4648
"forge-std=test/utils/forge-std/"
4749
]
4850

51+
[lint]
52+
lint_on_build = false
53+
4954
[fmt]
5055
line_length = 100 # While we allow up to 120, we lint at 100 for readability.
5156
ignore = ["src/accounts/EIP7702Proxy.sol"]

β€Žsrc/utils/LibString.solβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ library LibString {
926926
result := mul(
927927
or( // Load the length and the bytes of `a` and `b`.
928928
shl(shl(3, sub(0x1f, aLen)), mload(add(a, aLen))),
929-
mload(sub(add(b, 0x1e), aLen))
929+
shr(shl(3, add(aLen, 1)), mload(add(b, 0x1f)))
930930
),
931931
// `totalLen != 0 && totalLen < 31`. Abuses underflow.
932932
// Assumes that the lengths are valid and within the block gas limit.

β€Žsrc/utils/g/LibString.solβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ library LibString {
930930
result := mul(
931931
or( // Load the length and the bytes of `a` and `b`.
932932
shl(shl(3, sub(0x1f, aLen)), mload(add(a, aLen))),
933-
mload(sub(add(b, 0x1e), aLen))
933+
shr(shl(3, add(aLen, 1)), mload(add(b, 0x1f)))
934934
),
935935
// `totalLen != 0 && totalLen < 31`. Abuses underflow.
936936
// Assumes that the lengths are valid and within the block gas limit.

β€Žtest/LibString.t.solβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,14 @@ contract LibStringTest is SoladyTest {
14561456
testStringPackAndUnpackTwo("abcdefghijklmnopqrstuvwxyzABCD", "");
14571457
testStringPackAndUnpackTwo("The strongest community I've ever seen", "NGL");
14581458
testStringPackAndUnpackTwo("", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
1459+
testStringPackAndUnpackTwo(
1460+
"01234567890123456789012345678901_search_search_search_search_search_search_23456789012345678901234567890123456789_search_search_search_search_search_search",
1461+
""
1462+
);
1463+
testStringPackAndUnpackTwoDifferential(
1464+
"01234567890123456789012345678901_search_search_search_search_search_search_23456789012345678901234567890123456789_search_search_search_search_search_search",
1465+
""
1466+
);
14591467
}
14601468
}
14611469

0 commit comments

Comments
Β (0)