Skip to content

Commit

Permalink
fix(protocol): fix bug in LibBytesUtils.toBytes32 (TKO-07) (#15565)
Browse files Browse the repository at this point in the history
Co-authored-by: Brecht Devos <Brechtp.Devos@gmail.com>
  • Loading branch information
dantaik and Brechtpd committed Jan 29, 2024
1 parent b2176d3 commit 6def8a3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
13 changes: 0 additions & 13 deletions packages/protocol/contracts/thirdparty/LibBytesUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,6 @@ library LibBytesUtils {
return slice(_bytes, _start, _bytes.length - _start);
}

function toBytes32(bytes memory _bytes) internal pure returns (bytes32) {
if (_bytes.length < 32) {
bytes32 ret;
assembly {
ret := mload(add(_bytes, 32))
}
return ret;
}

return abi.decode(_bytes, (bytes32)); // will truncate if input length >
// 32 bytes
}

function toNibbles(bytes memory _bytes) internal pure returns (bytes memory) {
bytes memory nibbles = new bytes(_bytes.length * 2);

Expand Down
7 changes: 2 additions & 5 deletions packages/protocol/contracts/thirdparty/LibMerkleTrie.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ library LibMerkleTrie {
);
} else {
// Nodes smaller than 31 bytes aren't hashed.
require(
LibBytesUtils.toBytes32(currentNode.encoded) == currentNodeID,
"Invalid internal node hash"
);
require(bytes32(currentNode.encoded) == currentNodeID, "Invalid internal node hash");
}

if (currentNode.decoded.length == BRANCH_NODE_LENGTH) {
Expand Down Expand Up @@ -275,7 +272,7 @@ library LibMerkleTrie {
nodeID = LibRLPReader.readBytes(_node);
}

return LibBytesUtils.toBytes32(nodeID);
return bytes32(nodeID);
}

/**
Expand Down

0 comments on commit 6def8a3

Please sign in to comment.