1

关于安全数学留空问题.

 2 years ago
source link: https://learnblockchain.cn/question/2642
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
关于安全数学留空问题. | 登链社区 | 技术问答

关于安全数学留空问题.

function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

我只想要c而不想要bool该怎么写来着?突然忘记了.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK