Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

ERC223: 防止转账黑洞

杨小公子君莫邪
100 0 0
以太坊的智能合约和普通用户的地址是被一样对待的,没法判断一个地址是智能合约还是普通用户。当你误操作向一个智能合约转账,就真的转过去了,然后 token 就丢了。
3 r$ s0 ], s1 I. F0 R) O/ d# l$ Q
* o: c8 O4 e& C( CThere is no way in solidity to check if an address is a contract. One of the goals of Ethereum is for humans and smart contracts to both be treated equally.
: O( B. T/ e$ |$ z5 ehttps://stackoverflow.com/a/37670490/7218912, z. C& p3 Z5 I6 w: a, Q9 d3 p

) x' D9 e7 V4 b% H4 F# R有时候确实有需要向智能合约转账:1 f8 s6 ~( X6 j$ v& A0 l1 T. j& ^1 B
  • 给智能合约转 Ether,作为 gas;
  • 比如向 bancor 的智能合约转 token 抵押在那里,转进去的 token 在卖出操作时会转出;
    ! k3 w, j* R3 X5 ~& ?8 Y
    & q& f* i0 U: H; K) w
    但是大多数 smart contract 的 token 是不能转出的,只要合约里没写转出的逻辑,就不能转出。以太坊将智能合约看做是独立的个体,没人知道它的私钥,给不支持转出的智能合约转 token 就等于销毁了。
    0 p/ h- e. C. @% e9 ~当我们要转账时,会转到交易方的地址,不会闲着没事给智能合约转 token。但是这种事情仍然会发生,不断有人给 EOSTokenContract 转 EOS(见下图),EOSTokenContract 账户下现在有 154,834 EOS,价值 $1,176,738.4(价格 $7.6)。类似的,QtumTokenContract 账户下现在有 22,293 QTUM,价值 $158,280.3(价格 $7.1)。
    + N3 M& Q% E* N) {1 C2 Y这些 token 都都都都销毁了 (⊙?⊙)& P: `5 s# W2 x- F5 s# T4 \
    % Y7 q1 s& Q! |
    Dexaran 认识到了这个问题,! h& \/ T  k: B6 c% ~

    9 m" n  o+ |( q' R0 \+ h! CContracts that are not designed to work with tokens must reject incoming token transactions. Otherwise, each token becomes a potential token trap.: Z9 y6 {4 y1 [" B; x
    ERC20 token standard issues.(google docs)
    + U! W1 Z7 j9 g0 Y

    + C) b8 u6 p0 C" Q$ a并在 github 创建了一个 issue。
    . z* I& F/ w3 btokenFallback 函数,当转账到不能转出的智能合约地址时,将自动取消。' D# h! C4 V: L' ?) G) o2 Z3 k
    contract ERC223 {, L/ u+ Z* B9 @6 d: H
      function transfer(address to, uint value, bytes data) {
    8 W8 k; p! K2 q7 i6 X        uint codeLength;
    : J5 l2 N! R+ q; B6 C) j        assembly {) @) ?& N; @' Z
                codeLength := extcodesize(_to)
    1 y+ S1 s' t9 |4 Z* o        }
    " D! d6 m: G( c  H        balances[msg.sender] = balances[msg.sender].sub(_value);
    2 Z* a! l4 u/ E0 Y+ v- D        balances[_to] = balances[_to].add(_value);, S; Q0 i1 X/ T0 Z4 i" d- h
            if(codeLength>0) {
    / [5 Q" m, F! {5 Y            // Require proper transaction handling.
    / a' p8 ~: s9 N0 v8 S# U            ERC223Receiver receiver = ERC223Receiver(_to);) g* W0 ^% d4 [* B2 R  m
                receiver.tokenFallback(msg.sender, _value, _data);
    # U0 {# ^! ~6 S! g1 c        }
    3 ?& x8 R. u- ]" t    }9 L2 A" c' P; W# U% ~
    }+ d/ Y4 Q7 r5 _/ j1 l$ k/ B
    【todo】:代码解释
    ) b: p" X1 n7 w' a: ]* q! t/ H
    - G9 e4 ?; J/ ]1 J9 N; s2 bThe biggest change is that ERC223 no longer allow token to be transferred to a contract that does not allow token to be withdrawn.* h" p8 f1 i- e! h: F2 t$ |* h. m
    https://medium.com/cryptomover/what-are-erc20-and-erc223-tokens-307badcca5a
    6 Z! U8 Z! E- r4 A7 b" ?
  • BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
    声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    成为第一个吐槽的人

    杨小公子君莫邪 初中生
    • 粉丝

      0

    • 关注

      0

    • 主题

      13