# 状态逻辑隐藏

By [web3zoom](https://paragraph.com/@web3zoom) · 2025-11-16

---

描述：

在合约继承时，子合约忽视父合约中的“隐藏的”状态变量或者函数逻辑，导致合约整体的执行漏洞。例如，覆盖父合约中的“隐藏变量”， 包含不安全的“隐藏函数”，都可能引起合约系统严重的安全问题。

隐藏变量：

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.5.17;
    
    contract Parent{
        string public status = "Contract Parent";
    
        function getStatus() public view returns(string memory){
            return status;
        }
    }
    
    contract Child is Parent {
        string public status = "Contract Child";
    }
    

在solidity 0.5.17 版本中， 子合约继承父合约的status的状态变量。在0.6 版本之上变量隐藏不被允许，编译无法通过。

---

*Originally published on [web3zoom](https://paragraph.com/@web3zoom/kXgCT0ylVVp6DCwiawZT)*
