Skip to content

Instantly share code, notes, and snippets.

@Cr0wn-Gh0ul
Last active November 23, 2022 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cr0wn-Gh0ul/421a20fc27d57fe0cb314dc4018b9333 to your computer and use it in GitHub Desktop.
Save Cr0wn-Gh0ul/421a20fc27d57fe0cb314dc4018b9333 to your computer and use it in GitHub Desktop.
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;
library CalldataUtils {
function concatMemCall(bytes memory a_, bytes calldata b_)
public
pure
returns (bytes memory ret)
{
ret = new bytes(b_.length + a_.length);
assembly {
let al := mload(a_)
mstore(ret, add(al, b_.length))
let c := add(ret, 0x20)
let e := add(c, al)
for {
let cc := add(a_, 0x20)
} lt(c, e) {
c := add(c, 0x20)
cc := add(cc, 0x20)
} {
mstore(c, mload(cc))
}
calldatacopy(add(ret, add(0x20, al)), b_.offset, b_.length)
}
return ret;
}
function concatCalls(bytes calldata a_, bytes calldata b_)
public
pure
returns (bytes memory ret)
{
ret = new bytes(b_.length + a_.length);
assembly {
mstore(ret, add(b_.length, a_.length))
calldatacopy(add(ret, 0x20), a_.offset, a_.length)
calldatacopy(add(ret, add(0x20, a_.length)), b_.offset, b_.length)
}
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment