Skip to content

Commit

Permalink
add isBytesPrefixedWith fn
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit committed Nov 8, 2024
1 parent fada29c commit 60a0ddf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ethexe/contracts/src/ScaleCodec.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ library ScaleCodec {
return res;
}

// This function is supposed to be used for checking if the data is prefixed with the given prefix.
function isBytesPrefixedWith(bytes memory prefix, bytes memory data, uint256 dataOffset) public pure returns (bool) {
for (uint256 i = 0; i < prefix.length; i++) {
if (prefix[i] != data[i + dataOffset]) {
return false;
}
}
return true;
}

function bytesToBytes32(bytes memory value, uint256 offset) public pure returns (bytes32 result) {
assembly {
result := mload(add(add(value, 0x20), offset))
Expand Down

0 comments on commit 60a0ddf

Please sign in to comment.