首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >合同双重执行问题(使用SafeMath不是问题)

合同双重执行问题(使用SafeMath不是问题)
EN

Ethereum用户
提问于 2018-07-11 12:02:55
回答 1查看 119关注 0票数 -3

让我们说,每次用户pay_in到合同,我们+1,贡献者的数量和每个人,withdrew,我们将-1,竞争对手的数目。

在签订了一份合同之后,很显然,如果用户想要足够快地执行withdrew函数,他们就可以得到大量的conterbuters。

想知道是否有办法防止这种情况发生。

请注意:

我意识到溢出问题和Mathsafe库的使用。然而,在代码中使用数学安全库在计算上是昂贵的,如果用户计数可以从100增加到97,它也不会有帮助。提供一个用户在完成前两个转换之前执行代码3次。因此,我不认为这是一个溢出问题。

更新:以下是简化的图书馆函数

代码语言:javascript
复制
/**
 * Deposit
**/
function deposit(Store storage self) public {
    require(msg.value > 0);
    address user = msg.sender;
    // we already have the user down as Contributor
    if(self.contributor[user].ether_in<=0)
        self.numContributors++;
    self.contributor[user].ether_in += msg.value;
    self.ether_in += msg.value;
}
/**
 * withdraw
**/
function withdraw(Store storage self) internal {
    address user = msg.sender;
    require(self.contributor[user].ether_in>0);
    ether_out = self.contributor[user].ether_in;
    self.numContributors--;
    user.transfer(ether_out);
    self.contributor[user].ether_in = 0
}

**联系**

代码语言:javascript
复制
import './lib'
contract SimplifiedMainContract {

    using Lib for Lib.Store;
    Lib.Store private store;

    function deposit() public payable {
        store.deposit();
    }

    function withdraw() public {
        store.withdraw();
    }

}
EN

回答 1

Ethereum用户

发布于 2018-07-11 12:09:56

您应该搜索变量中的溢出/溢出,并在需要这样计算的地方使用SafeMath库,因为稳健性还没有内置的检查这类事情。

票数 3
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/53160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档