Skip to content

Commit

Permalink
lib byte fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
k-xo committed May 11, 2023
1 parent ed9989a commit bdbcf40
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libraries/LibBytes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ library LibBytes {
require(reserves[0] <= type(uint128).max, "ByteStorage: too large");
require(reserves[1] <= type(uint128).max, "ByteStorage: too large");
assembly {
sstore(slot, add(shl(128, mload(add(reserves, 32))), shr(128, shl(128, mload(add(reserves, 64))))))
sstore(slot, add(shr(128, mload(add(reserves, 32))), shl(128, mload(add(reserves, 64)))))
}
} else {
uint maxI = reserves.length / 2; // number of fully-packed slots
Expand All @@ -53,8 +53,8 @@ library LibBytes {
sstore(
add(slot, mul(i, 32)),
add(
shl(128, mload(add(reserves, add(iByte, 32)))),
shr(128, shl(128, mload(add(reserves, add(iByte, 64)))))
shr(128, mload(add(reserves, add(iByte, 32)))),
shl(128, mload(add(reserves, add(iByte, 64))))
)
)
}
Expand All @@ -67,7 +67,10 @@ library LibBytes {
assembly {
sstore(
add(slot, mul(maxI, 32)),
add(shl(128, mload(add(reserves, add(iByte, 32)))), shr(128, shl(128, sload(add(slot, maxI)))))
add(
shr(128, mload(add(reserves, add(iByte, 32)))),
shl(128, shl(128, sload(add(slot, mul(maxI, 32)))))
)
)
}
}
Expand Down

0 comments on commit bdbcf40

Please sign in to comment.