I am researching about Factory contract to clone existing contracts, First is the implementation present at https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol. I don't know what these 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000 and 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000 meant to do.
The other implementations just use the new keyword to make an instance of deployed smart contracts. What's the difference between the two approaches? How the code from optionality actually works? Is this implementation also works in new solidity versions ^0.6.0.
function createClone(address target) internal returns (address result) {
bytes20 targetBytes = bytes20(target);
assembly {
let clone := mload(0x40)
mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(clone, 0x14), targetBytes)
mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
result := create(0, clone, 0x37)
}