Skip to content

Commit

Permalink
fix(protocol): resolve conflict (#17504)
Browse files Browse the repository at this point in the history
Co-authored-by: Keszey Dániel <[email protected]>
  • Loading branch information
adaki2004 and Keszey Dániel authored Jun 6, 2024
1 parent 9e504d2 commit a2daec6
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions packages/protocol/contracts/libs/LibBytes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@ pragma solidity 0.8.24;
library LibBytes {
error INNER_ERROR(bytes innerError);

// Taken from:
// https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/PolygonZkEVMBridge.sol#L835-L860
// Function body taken from:
// https://github.com/clober-dex/core/blob/main/contracts/utils/BoringERC20.sol#L17-L33
/// @notice Function to convert returned data to string
/// returns 'NOT_VALID_ENCODING' as fallback value.
/// returns '' as fallback value.
function toString(bytes memory _data) internal pure returns (string memory) {
if (_data.length >= 64) {
return abi.decode(_data, (string));
} else if (_data.length == 32) {
// Since the strings on bytes32 are encoded left-right, check the first zero in the data
uint256 nonZeroBytes;
while (nonZeroBytes < 32 && _data[nonZeroBytes] != 0) {
++nonZeroBytes;
uint8 i = 0;
while (i < 32 && _data[i] != 0) {
i++;
}

// If the first one is 0, we do not handle the encoding
if (nonZeroBytes == 0) return "";

// Create a byte array with nonZeroBytes length
bytes memory bytesArray = new bytes(nonZeroBytes);
for (uint256 i; i < nonZeroBytes; ++i) {
bytes memory bytesArray = new bytes(i);
for (i = 0; i < 32 && _data[i] != 0; i++) {
bytesArray[i] = _data[i];
}
return string(bytesArray);
Expand Down

0 comments on commit a2daec6

Please sign in to comment.