zellic-audit
Initial commit
f998fcd
raw
history blame
3.43 kB
// This contract is part of Zellic’s smart contract dataset, which is a collection of publicly available contract code gathered as of March 2023.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library LSSVMPairCloner {
/**
* @notice Checks if a contract is a clone of a LSSVMPairETH.
* @dev Only checks the runtime bytecode, does not check the extra data.
* @param factory the factory that deployed the clone
* @param implementation the LSSVMPairETH implementation contract
* @param query the contract to check
* @return result True if the contract is a clone, false otherwise
*/
function isETHPairClone(
address factory,
address implementation,
address query
) internal view returns (bool result) {
// solhint-disable-next-line no-inline-assembly
assembly {
let ptr := mload(0x40)
mstore(
ptr,
hex"3d_3d_3d_3d_36_3d_3d_37_60_3d_60_35_36_39_36_60_3d_01_3d_73_00_00_00_00_00_00_00_00_00_00_00_00"
)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(
add(ptr, 0x28),
hex"5a_f4_3d_3d_93_80_3e_60_33_57_fd_5b_f3_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00"
)
mstore(add(ptr, 0x35), shl(0x60, factory))
// compare expected bytecode with that of the queried contract
let other := add(ptr, 0x49)
extcodecopy(query, other, 0, 0x49)
result := and(
eq(mload(ptr), mload(other)),
and(
eq(mload(add(ptr, 0x20)), mload(add(other, 0x20))),
eq(mload(add(ptr, 0x29)), mload(add(other, 0x29)))
)
)
}
}
/**
* @notice Checks if a contract is a clone of a LSSVMPairERC20.
* @dev Only checks the runtime bytecode, does not check the extra data.
* @param implementation the LSSVMPairERC20 implementation contract
* @param query the contract to check
* @return result True if the contract is a clone, false otherwise
*/
function isERC20PairClone(
address factory,
address implementation,
address query
) internal view returns (bool result) {
// solhint-disable-next-line no-inline-assembly
assembly {
let ptr := mload(0x40)
mstore(
ptr,
hex"3d_3d_3d_3d_36_3d_3d_37_60_51_60_35_36_39_36_60_51_01_3d_73_00_00_00_00_00_00_00_00_00_00_00_00"
)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(
add(ptr, 0x28),
hex"5a_f4_3d_3d_93_80_3e_60_33_57_fd_5b_f3_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00"
)
mstore(add(ptr, 0x35), shl(0x60, factory))
// compare expected bytecode with that of the queried contract
let other := add(ptr, 0x49)
extcodecopy(query, other, 0, 0x49)
result := and(
eq(mload(ptr), mload(other)),
and(
eq(mload(add(ptr, 0x20)), mload(add(other, 0x20))),
eq(mload(add(ptr, 0x29)), mload(add(other, 0x29)))
)
)
}
}
}