• Mark Tyneway's avatar
    contracts-bedrock: prevent overflows in ResourceMetering · 75080ba4
    Mark Tyneway authored
    When multiplying a uint64 and uint128 and assigning to
    a uint256, the solidity checked math applies to the
    types of the numbers being multiplied. This means that
    solidity catches an overflow when the result of larger than
    a uint128 even though its assigned to a uint256.
    This PR uses unchecked math to prevent this kind of overflow
    instead of casting the values to uint256 because it is
    safe to use unchecked math here. The following inequality
    always holds true, which shows that it is safe:
    
    ``` solidity
    type(uint64).max * type(uint128).max < type(uint256).max
    ```
    75080ba4
ResourceMetering.sol 7.02 KB