[Ethereum] Does the unchecked { … } block apply only to the current function


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?

Best Answer

Looking at the documentation for Solidity 0.8.0 it doesn't seem so like the unchecked block in bar disables the safety checks in foo..

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


Related Topic