NethermindEth / warp

Warp - Bringing Solidity to Starknet at warp speed. Warp is a Solidity to Cairo Compiler, this allows teams to write/migrate Solidity to Cairo for easy onboarding into the StarkNet ecosystem.
https://nethermind.io/warp/
Apache License 2.0
754 stars 70 forks source link

Implement unsafe math operators transpilation #1030

Open piwonskp opened 1 year ago

piwonskp commented 1 year ago

In solidity you can use unsafe operators by putting them in an unchecked block:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract UncheckedMath {
    function add(uint x, uint y) external pure returns (uint) {
        // 22291 gas
        // return x + y;

        // 22103 gas
        unchecked {
            return x + y;
        }
    }
}

Cairo 1 got functions implementing unsafe operations in https://github.com/starkware-libs/cairo/blob/9c3cb9633a9ef8595b3ee041a00b37b84d964af7/corelib/src/integer.cairo#L30.