安全问题

1.可能的错误

智能合约终止

限制转账限额 限制速率

有效途径来进行bug修复和提升

2.谨慎发布智能合约

对智能合约进行彻底的测试 并在任何新的攻击手法被发现后及时制止

赏金计划和审计合约

3.合约的简介

确保智能合约逻辑简单

确保合约和函数模块化

4.保持更新

在任何新发现的漏洞之前进行修复

利用最新技术

5.潜在特性

可能会调用同名函数

漏洞

溢出漏洞

typedef struct acnts {

account_name name0;

account_name name1;

account_name name2;

account_name name3;

} account_names;

void transfer(symbol_name symbol, account_name from, account_names to, uint64_t balance)

{

require_auth(from);

account fromaccount;

require_recipient(from);
require_recipient(to.name0);
require_recipient(to.name1);
require_recipient(to.name2);
require_recipient(to.name3); eosio_assert(is_balance_within_range(balance), "invalid balance");
eosio_assert(balance > 0, "must transfer positive balance"); uint64_t amount = balance * 4; //乘法溢出 int itr = db_find_i64(_self, symbol, N(table), from);
eosio_assert(itr >= 0, "Sub-- wrong name");
db_get_i64(itr, &fromaccount, (account));
eosio_assert(fromaccount.balance >= amount, "overdrawn balance"); sub_balance(symbol, from, amount); add_balance(symbol, to.name0, balance);
add_balance(symbol, to.name1, balance);
add_balance(symbol, to.name2, balance);
add_balance(symbol, to.name3, balance);

}

提示 使用assert进行检查 而不是把balance提出来进行运算

权限校验

严格判断入参函数和实际调用使得否一致

void token::transfer( account_name from,

account_name to,

asset quantity,

string memo )

{

eosio_assert( from != to, "cannot transfer to self" );

eosio_assert( is_account( to ), "to account does not exist");

auto sym = quantity.symbol.name();

stats statstable( _self, sym );

const auto& st = statstable.get( sym );

require_recipient( from );
require_recipient( to ); eosio_assert( quantity.is_valid(), "invalid quantity" );
eosio_assert( quantity.amount > 0, "must transfer positive quantity" );
eosio_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
eosio_assert( memo.size() <= 256, "memo has more than 256 bytes" ); auto payer = has_auth( to ) ? to : from; sub_balance( from, quantity );
add_balance( to, quantity, payer );

}

提示:检验资产转出账户和调用账户是否一致

确保每一个action和code满足关联要求

// extend from EOSIO_ABI

define EOSIO_ABI_EX( TYPE, MEMBERS ) \

extern "C" {

void apply( uint64_t receiver, uint64_t code, uint64_t action ) {

auto self = receiver;

if( action == N(onerror)) {

/* onerror is only valid if it is for the "eosio" code account and authorized by "eosio"'s "active permission /

eosio_assert(code == N(eosio), "onerror action's are only valid from the "eosio" system account");

}

if( code == self || code == N(eosio.token) || action == N(onerror) ) {

TYPE thiscontract( self );

switch( action ) {

EOSIO_API( TYPE, MEMBERS )

}

/
does not allow destructor of thiscontract to run: eosio_exit(0); */

}

}

}

EOSIO_ABI_EX(eosio::charity, (hi)(transfer))

提示:关键检查

相关文章:

eosbet被盗事件合约分析

被盗合约 受攻击代码

有问题的合约代码

// extend from EOSIO_ABI, because we need to listen to incoming eosio.token transfers

define EOSIO_ABI_EX( TYPE, MEMBERS ) \

extern "C" {

void apply( uint64_t receiver, uint64_t code, uint64_t action ) {

auto self = receiver;

if( action == N(onerror)) {

/* onerror is only valid if it is for the "eosio" code account and authorized by "eosio"'s "active permission /

eosio_assert(code == N(eosio), "onerror action's are only valid from the "eosio" system account");

}

if( code == self || code == N(eosio.token) || action == N(onerror) ) {

TYPE thiscontract( self );

switch( action ) {

EOSIO_API( TYPE, MEMBERS )

}

/
does not allow destructor of thiscontract to run: eosio_exit(0); */

}

}

}

问题原因:

由于abi转发器允许下注而不将eos转移到合同中。

修改措施:

1.去掉错误判断

2.过滤传入操作 只将eosio.token的行为传入合同

提醒:

更强大的代码测试

至少两次审计

资金监控

eos智能合约开发最佳实践的更多相关文章

  1. EOS智能合约开发(四):智能合约部署及调试(附编程示例)

    EOS智能合约开发(一):EOS环境搭建和创建节点 EOS智能合约开发(二):EOS创建和管理钱包 EOS智能合约开发(三):EOS创建和管理账号 部署智能合约的示例代码如下: $ cleos set ...

  2. EOS智能合约开发(三):EOS创建和管理账号

    没有看前面文章的小伙伴可以看一下 EOS智能合约开发(一):EOS环境搭建和启动节点 EOS智能合约开发(二):EOS创建和管理钱包 创建好钱包.密钥之后,接下来你就可以创建账号了,账号是什么?账号保 ...

  3. eos 智能合约开发体验

    eos编译安装 eos 特性 数据存储 eos投票智能合约开发 eos投票智能合约部署测试 注意避坑 eos编译安装 ERROR: Could not find a package configura ...

  4. EOS智能合约开发(二):EOS创建和管理钱包

    上节介绍了EOS智能合约开发之EOS环境搭建及启动节点 那么,节点启动后我们要做的第一件事儿是什么呢?就是我们首先要有账号,但是有账号的前提是什么呢?倒不是先创建账号,而是先要有自己的一组私钥,有了私 ...

  5. EOS智能合约开发(一):EOS环境搭建和启动节点

    EOS和以太坊很像,EOS很明确的说明它就是一个区块链的操作系统,BM在博客中也是说过的. 可以这样比喻,EOS就相当于内置激励系统的Windows/Linux/MacOS,这是它的一个定位. 包括以 ...

  6. 【精解】EOS智能合约演练

    EOS,智能合约,abi,wasm,cleos,eosiocpp,开发调试,钱包,账户,签名权限 热身 本文旨在针对EOS智能合约进行一个完整的实操演练,过程中深入熟悉掌握整个EOS智能合约的流程,过 ...

  7. NEO智能合约开发(二)再续不可能的任务

      NEO智能合约开发中,应用合约比较简单,是的你没看错,应用合约比较简单. 应用合约三部曲,发布.调用.看结果.除了看结果工具比较缺乏,发布调用neogui最起码可以支撑你测试.   鉴权合约比较麻 ...

  8. EOS智能合约存储实例讲解

    EOS智能合约存储实例 智能合约中的基础功能之一是token在某种规则下转移.以EOS提供的token.cpp为例,定义了eos token的数据结构:typedef eos::token<ui ...

  9. Hyperledger Fabric 智能合约开发及 fabric-sdk-go/fabric-gateway 使用示例

    前言 在上个实验 Hyperledger Fabric 多组织多排序节点部署在多个主机上 中,我们已经实现了多组织多排序节点部署在多个主机上,但到目前为止,我们所有的实验都只是研究了联盟链的网络配置方 ...

随机推荐

  1. Grub4dos boot

    Grub4dos 0.4.6a http://grub4dos.chenall.net/ Ghost11.5 bcdedit bcdedit /create /d "Grub4dos&quo ...

  2. PHP中级程序员常见面试题

    1).写一个函数,从一个标准url里取出文件的扩展名,需要取出php或.php <?php $a="http://www.test.com.cn:88/abc/de/fg.php?id ...

  3. MongoDB如何释放空闲空间?

    当我们从MongoDB中删除文档或集合时,MongoDB并不会将已经占用了的磁盘空间释放,它会一直维护已经占用了磁盘空间的数据文件,尽管数据文件中可能存在大大小小的空记录列表(empty record ...

  4. flume搭建新手测试环境

    硬件环境: 腾讯云,两台服务器8G 双核 软件环境: flume1.8.jdk1.8,centos6 第一次搭建也是各种找文件,只知道flume是日志抓取服务,也听说了非常稳定强大的服务,正好公司需要 ...

  5. Flume:source和sink

    Flume – 初识flume.source和sink 目录基本概念常用源 Source常用sink 基本概念  什么叫flume? 分布式,可靠的大量日志收集.聚合和移动工具.  events ...

  6. c语言:矩阵相乘-矩阵相加 新手练习1

    #include<stdio.h> #include<stdlib.h> #include<time.h> #include<string.h> voi ...

  7. linux mint系统 cinnamon桌面 发大镜功能

    让我来告诉迷途中的你cinnamon桌面一个好用的功能. 选择设置 选择窗口 -> 选择行为 看那个窗口移动和调整大小的特殊键 Alt 好了按住alt在滑动滑轮 世界不一样了 对于小屏幕高分辨率 ...

  8. 9-客户端集成IdentityServer

    1-创建客户端的webapi项目 E:\coding\netcore\IdentityServerSample>dotnet new webapi --name IdentityCredenti ...

  9. NoSQL入门第五天——Java连接与整合操作

    一.测试联通 1.新建个web工程 2.导入jar:当然实际使用的时候肯定是通过maven来构建(如果有机会,可以尝试学习gradle进行构建) 3.建个测试类:好久没开eclipse了,希望后面可以 ...

  10. 成都Uber优步司机奖励政策(3月4日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...