智能合约安全与设计决策
智能合约安全
1. 利用提取模式修改合约
可以使用提取模式对 BecomeTheKing 合约进行修改,代码如下:
pragma solidity ^0.4.24;
contract BecomeTheKing {
address currentKing;
uint highestBid;
mapping(address => uint) balances;
// Function to withdraw previous bids
function withdraw() public {
uint balance = balances[msg.sender];
require(balance > 0);
balances[msg.sender] = 0;
msg.sender.transfer(balance);
}
function() public payable {
require(msg.value > highestBid);
// Save the previous bid for withdrawal
balances[msg.sender] = highestBid;
currentKing = msg.sender;
highestBid = msg.value;
}
}
超级会员免费看
订阅专栏 解锁全文
1230

被折叠的 条评论
为什么被折叠?



