BCSkill (Block chain skill )
区块链中文技术社区

只讨论区块链底层技术
遵守一切相关法律政策!

EOS智能合约禁止更新,监管升级权限

最近EOS版的Fomo 3D狼人杀游戏骗局引发了大家对EOS智能合约的安全性的大讨论。
和以太坊智能合约的不可升级不同,EOS智能合约可升级,因而保存在智能合约中的数据称不上去中心化,因为智能合约的管理员可偷偷的升级智能合约来修改合约里的任何数据。最直接的示例是EOS代币,代币分发给用户后,用户的代币持有量仍旧可以被管理员修改,那这个持有量是不安全的。由于智能合约可升级,开发者往往也没有了开源的动力,因为反正可以升级,开源又有什么意义呢?你此时看到的源码下一刻就可能被修改掉了。所以说目前所有涉及到资金的EOS代币及智能合约大家都要小心。

干掉升级

那智能合约的中心化如何来解决呢?难道EOS的智能合约只是个玩偶?显然不是,解决的方法只有一个,就是“自宫”,开发人员自己禁用掉合约的升级功能,核心就是是更改智能合约账号的权限,就像EOS启动阶段eosio.system智能合约的权限变更一样(具体可看我的文章)将智能合约权限更改为权威多签权限(eosio, eosio.prods)或者未知私钥对应的公钥。所以说其实官方已经给出了示例的,只是开发人员没跟上。

权威多签权限eosio.prods

21个超级节点多签管理权限

未知私钥

比如EOS1111111111111111111111111111111114T1Anm这个公钥,它的公钥是0值加检验数据生成的,任何人都不知道它的私钥。这个公钥在超级节点竞选时临时用过,当时只有genisisblock生产区块,eosio.system智能合约处于临时冻结状态。

组建第三方权威认证机构(DAppStore)

智能合约将权限转交给第三方权威认证机构DAppStore,该机构由顶尖技术和生态大佬组成,采取投票方式是否同意某一智能合约升级。
比如该权限,智能合约拥有者账号拥有100张投票权,第三方权威机构有100张投票权(100个成员),所以必须得到智能合约拥有者同意且50%第三方权威认证机构票数认可(即150张票)才可以升级

代码开源

自宫之后,才能谈开源,目前eospark已经支持智能合约源码验证,开发者可以将源码发布到eospark验证。这样用户能看到合约的代码,且永远是这个代码。

升级功能什么时候用

既然智能合约都要去掉升级功能,那还要升级功能干嘛?其实可以这样用

  • 只要服务不涉及到资金的智能合约可以使用
  • 测试阶段使用。测试阶段收集反馈,发现有问题通过升级解决。运行一段时间后,固化智能合约。

转载自:blog.csdn.net/itleaks

可以获取账户所以 actions 的主网 rpc 地址

root@iZj6cgy98yiuluw41gz0aoZ:~# cleos -u http://eu1.eosdac.io get actions bcskillsurou
#  seq  when                              contract::action => receiver      trx id...   args

发帖时可用。
数据来源: eosfans

安装EOSTracker 获取 EOS MongoDB 数据

本篇文章演示基于EOS Tracker获取和展示EOS MongoDb 数据。
所需的EOS Tracker为一修改版本,支持MongoDb,原版发帖时只支持MySql。

安装php 7.2

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2

安装PHP扩展

sudo apt-get install php7.2-mongodb
sudo apt-get install php7.2-cli
sudo apt-get install php7.2-xml
sudo apt-get install php7.2-mbstring php7.2-intl php7.2-redis -y
apt-get install composer

获取代码

git clone https://github.com/FeeSimple/eos-tracker.git

开始部署EOS Tracker API

进入eos-tracker/eos-tracker-api,更新安装EOS Tracker API子项目
composer update
composer install
修改MongDB for eos-tracker-api的配置文件
app/config/parameters.yml

# This file is auto-generated during the composer install parameters:
secret: 123 //一般默认为空
mongodb_server: 'mongodb://localhost:27017'
db_name: EOStest
开始运行
php bin/console server:run 0.0.0.0:8000

开始部署EOS Tracker前端项目

进入eos-tracker/eos-tracker-frontend
安装项目依赖

npm i
npm install -g @angular/cli@6.0.8

EOS Tracker是一个基于Angular4的前端,连接到EOS Tracker API。
用于与eos-tracker-api交互的eos-tracker-frontend的配置文件:

src/environments/environment.ts

    export const environment = {
        production: false,
        walletUrl: '//www.bcskill.com',
        appName: 'EOS Tracker',
        logoUrl: '/assets/logo.png',
        apiUrl: '//www.bcskill.com:8000', //修改为与上面API地址和端口一致
        blockchainUrl: '//rpc.bcskill.com:8888' //修改为已同步全部EOS区块的RPC服务器地址
    };

开始启动

ng serve --host 0.0.0.0 --port 4200

常见问题

  • Cannot read property 'write' of undefined
    npm uninstall -g @angular/cli
    npm install -g @angular/cli@6.0.8
  • add-apt-repository: command not found
    sudo apt-get install python-software-properties
    sudo apt-get update
    sudo apt install software-properties-common 
    sudo apt-get update

    参考:stackoverflow

  • ubuntu npm 升级到新版
    (打开连接)

Ubuntu 安装 Mongodb 3+

方式一:从apt-get安装

  1. 添加mongodb签名到APT
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
  2. 创建/etc/apt/sources.list.d/mongodb-org-3.2.list文件并写入命令
    echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
  3. 更新软件源列表
    sudo apt-get update
  4. 安装mongodb(默认是安装稳定版)
    sudo apt-get install -y mongodb-org

    或者安装指定版本:

    sudo apt-get install -y mongodb-org=3.2.9 mongodb-org-server=3.2.9 mongodb-org-shell=3.2.9 mongodb-org-mongos=3.2.9 mongodb-org-tools=3.2.9

方式二:从 .tar.gz 二进制包安装

  1. 下载最新安装包
    官网下载地址:https://www.mongodb.com/download-center?jmp=nav#community.
    curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1404-3.2.9.tgz
  2. 解压
    tar -zxvf mongodb-linux-x86_64-ubuntu1404-3.2.9.tgz
  3. 重命名并移动到安装目录(可自定义)
    sudo mv mongodb-linux-x86_64-3.0.6/ /usr/local/mongodb   # 将解压包拷贝到指定目录进行安装
  4. 创建 mongo 的数据目录
    MongoDB 默认的数据目录是 /data/db/ ,就直接使用默认的。
    sudo mkdir -p /data/db    #创建数据存储目录
    sudo chmod 755 /data/*    #赋予目录权限
  5. 启动
    mongod    #启动服务端
    mongo    #启动客户端

    配置MongoDB

    控制的配置文件在:/etc/mongodb.conf
    控制脚本在:/etc/init.d/mongodb
    MongoDB实例会把数据存放在:/var/lib/mongodb
    日志存放在:/var/log/mongodb
    默认由mongodb用户运行。
    如果如果显示目录不存在的话,需要运行下列命令指定文件夹:

    mongod --dbpath /var/lib/mongodb

    如果想要切换用户运行MongoDB的话,需要设置 /var/lib/mongodb 、 /var/log/mongodb两个目录的权限

    启动、停止、重启

    sudo service mongodb start
    sudo service mongodb stop
    sudo service mongodb restart

    通过mongodb shell测试安装结果

    mongodb

卸载MongoDB

  1. 停止MongoDB
    sudo service mongod stop
  2. 移除包文件
    sudo apt-get purge mongodb-org*
  3. 删除存放数据的目录
    sudo rm -r /var/log/mongodbsudo rm -r /var/lib/mongodb

    参考文档

    MongoDB官方文档:https://docs.mongodb.com/getting-started/shell/tutorial/install-mongodb-on-ubuntu/
    Ubuntu下MongoDB 安装教程及简单操作:http://www.linuxidc.com/Linux/2016-07/133254.htm

买卖内存的最小字节数 (token amount received from selling ram is too low)

当卖内存字节数按当时内存价格所值的EOS数,如果小于0.0001,则交易出错

root@iZj6cbx3duprxf6dasczbpZ:~# cleos system sellram dapp.exec 1
1483958ms thread-0   main.cpp:438                  create_action        ] result: {"binargs":"000040aa2b50ab490100000000000000"} arg: {"code":"eosio","action":"sellram","args":{"account":"dapp.exec","bytes":1}} 
Error 3050003: eosio_assert_message assertion failure
Error Details:
assertion failure with message: token amount received from selling ram is too low
pending console output:
void system_contract::sellram( account_name account, int64_t bytes ) {
      require_auth( account );
      eosio_assert( bytes > 0, "cannot sell negative byte" );

      user_resources_table  userres( _self, account );
      auto res_itr = userres.find( account );
      eosio_assert( res_itr != userres.end(), "no resource row" );
      eosio_assert( res_itr->ram_bytes >= bytes, "insufficient quota" );

      asset tokens_out;
      auto itr = _rammarket.find(S(4,RAMCORE));
      _rammarket.modify( itr, 0, [&]( auto& es ) {
          /// the cast to int64_t of bytes is safe because we certify bytes is <= quota which is limited by prior purchases
          tokens_out = es.convert( asset(bytes,S(0,RAM)), CORE_SYMBOL);
      });

      eosio_assert( tokens_out.amount > 1, "token amount received from selling ram is too low" );

当按EOS买内存时,如果所支出的EOS扣除0.5%手续费后的余额,按当时内存价格所购买的字节数小于1,则出错"must reserve a positive amount"

void system_contract::buyram( account_name payer, account_name receiver, asset quant )
   {
      require_auth( payer );
      eosio_assert( quant.amount > 0, "must purchase a positive amount" );

      auto fee = quant;
      fee.amount = ( fee.amount + 199 ) / 200; /// .5% fee (round up)
      // fee.amount cannot be 0 since that is only possible if quant.amount is 0 which is not allowed by the assert above.
      // If quant.amount == 1, then fee.amount == 1,
      // otherwise if quant.amount > 1, then 0 < fee.amount < quant.amount.
      auto quant_after_fee = quant;
      quant_after_fee.amount -= fee.amount;
      // quant_after_fee.amount should be > 0 if quant.amount > 1.
      // If quant.amount == 1, then quant_after_fee.amount == 0 and the next inline transfer will fail causing the buyram action to fail.

      INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)},
         { payer, N(eosio.ram), quant_after_fee, std::string("buy ram") } );

      if( fee.amount > 0 ) {
         INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)},
                                                       { payer, N(eosio.ramfee), fee, std::string("ram fee") } );
      }

      int64_t bytes_out;

      const auto& market = _rammarket.get(S(4,RAMCORE), "ram market does not exist");
      _rammarket.modify( market, 0, [&]( auto& es ) {
          bytes_out = es.convert( quant_after_fee,  S(0,RAM) ).amount;
      });

      eosio_assert( bytes_out > 0, "must reserve a positive amount" );

当按字节数买内存时,内部会先按当时内存价格计算出所需的EOS价格,如果计算出的EOS扣除0.5%手续费后的余额,按当时内存价格所购买的字节数小于1,也会出错"must reserve a positive amount"