Search code examples
ethereumsolidityopenzeppelin

Solidity, Can Attacker bypass a internal functions?


I'm thinking about my smart contract and want to have a secure contract. But I really don't know that internal functions are safe or not. This is a very BASIC contract that uses OpenZeppelin contracts:

contract MyContract is ERC20 {
    constructor () ERC20("test", "test") {    
        _mint(msg.sender, 1000);
    }
}

_mint is an internal function from Openzeppelin ERC20 contract. Can someone deploy another contract and call the MyContract _mint() function? If yes, How can we secure it?


Solution

  • The function _mint() from ERC20 is internal.

    Internal functions can only be called within the contract or by the contracts inherited from the current one.

    That means that no other contract can call MyContract._mint(), you can only call _mint() from inside MyContract.