10多年的软件开发经验,包括大数据、AI等领域,熟悉Go、Java、Python等语言使用,最近学习rust语言,目前从事技术管理、架构师相关工作

Subscribe to web3zoom


<100 subscribers
<100 subscribers
描述:
合约初始化时,执行构造函数,构造函数书写错误将会给合约带来重大安全漏洞。
0.4.22 版本之前的Solidity 使用合约名称创建构造函数,0.4.22 版本之后使用contractor创建构造函数。
漏洞合约:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
contract NotInitialized {
address public owner;
bool public initialized;
mapping (address => uint256) funds;
function constructor1() external {
owner = msg.sender;
initialized = true;
}
function start() external payable {
require(initialized);
funds[msg.sender] = msg.value;
}
}
由于书写错误,将构造函数书写成一般函数,导致状态变量没有初始化。
真正执行的空的构造函数,始终没有初始化变量。
防范措施:
检查编译器版本,并以正确的形式书写构造函数;
描述:
合约初始化时,执行构造函数,构造函数书写错误将会给合约带来重大安全漏洞。
0.4.22 版本之前的Solidity 使用合约名称创建构造函数,0.4.22 版本之后使用contractor创建构造函数。
漏洞合约:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
contract NotInitialized {
address public owner;
bool public initialized;
mapping (address => uint256) funds;
function constructor1() external {
owner = msg.sender;
initialized = true;
}
function start() external payable {
require(initialized);
funds[msg.sender] = msg.value;
}
}
由于书写错误,将构造函数书写成一般函数,导致状态变量没有初始化。
真正执行的空的构造函数,始终没有初始化变量。
防范措施:
检查编译器版本,并以正确的形式书写构造函数;
Share Dialog
Share Dialog
No activity yet