2

Take the following code snippet:

pragma solidity ^0.8.0;

contract MyContract {
    function foo() public returns (uint256 result) {
        // do unsafe work
    }

    function bar() public returns (uint256 result) {
        unchecked {
            uint256 foo_value = foo();
            // do safe work
        }
    }

Does the unchecked block in the bar function disable the safety checks in the foo function?

1

Looking at the documentation for Solidity 0.8.0 it doesn't seem so.

The setting only affects the statements that are syntactically inside the block. Functions called from within an unchecked block do not inherit the property.

https://docs.soliditylang.org/en/v0.8.0/control-structures.html#checked-or-unchecked-arithmetic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.