In pancakeswap when depositing into a vault they check if the address is a contract. "It prevents contract from being targetted" - What is this supposed to mean?
Does allowing the contracts to interact with the contract create a security risk? Or are they just trying to prevent third parties from building upon their contracts?
Anyone has idea why is this neccesary?
modifier notContract() {
require(!_isContract(msg.sender), "contract not allowed");
require(msg.sender == tx.origin, "proxy contract not allowed");
_;
}
/**
* @notice Deposits funds into the Cake Vault
* @dev Only possible when contract not paused.
* @param _amount: number of tokens to deposit (in CAKE)
*/
function deposit(uint256 _amount) external whenNotPaused notContract { ... }
/**
* @notice Checks if address is a contract
* @dev It prevents contract from being targetted
*/
function _isContract(address addr) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(addr)
}
return size > 0;
}
Full source code https://bscscan.com/address/0xa80240eb5d7e05d3f250cf000eec0891d00b51cc#code