Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

ERC223: 防止转账黑洞

杨小公子君莫邪
142 0 0
以太坊的智能合约和普通用户的地址是被一样对待的,没法判断一个地址是智能合约还是普通用户。当你误操作向一个智能合约转账,就真的转过去了,然后 token 就丢了。
5 a2 W: s6 M. N' S/ _  V  b& I
) j5 W" H! c( S9 z: c6 _! FThere 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.) _/ ^4 Y' H3 [1 x3 z$ `
https://stackoverflow.com/a/37670490/72189125 X3 ?, f+ |. h
* |2 A5 p/ D3 o
有时候确实有需要向智能合约转账:0 T& V: ^  p! z2 V
  • 给智能合约转 Ether,作为 gas;
  • 比如向 bancor 的智能合约转 token 抵押在那里,转进去的 token 在卖出操作时会转出;, X  s' d( X7 ?& @/ x" g

    & O6 D, B& s" A, J但是大多数 smart contract 的 token 是不能转出的,只要合约里没写转出的逻辑,就不能转出。以太坊将智能合约看做是独立的个体,没人知道它的私钥,给不支持转出的智能合约转 token 就等于销毁了。
    5 E* W( b) Y9 g当我们要转账时,会转到交易方的地址,不会闲着没事给智能合约转 token。但是这种事情仍然会发生,不断有人给 EOSTokenContract 转 EOS(见下图),EOSTokenContract 账户下现在有 154,834 EOS,价值 $1,176,738.4(价格 $7.6)。类似的,QtumTokenContract 账户下现在有 22,293 QTUM,价值 $158,280.3(价格 $7.1)。; a% u0 s# r) ~4 `
    这些 token 都都都都销毁了 (⊙?⊙)" u: k4 f0 f/ N& }
    * @2 a" m+ J* Z  O6 i, x
    Dexaran 认识到了这个问题,
    1 _3 E9 {8 R' c4 U, Q$ q; I
    ; b) C6 X% }) f6 iContracts that are not designed to work with tokens must reject incoming token transactions. Otherwise, each token becomes a potential token trap.
    7 v4 W7 J! H0 Y5 e+ A7 B9 pERC20 token standard issues.(google docs)  o* ?5 {5 U) K* x& M
    % S$ ~2 Z. g9 ]+ \
    并在 github 创建了一个 issue。* }  \' W9 ?9 N# D
    tokenFallback 函数,当转账到不能转出的智能合约地址时,将自动取消。
    7 g5 D: Q% m1 Z; [5 R0 ~contract ERC223 {! N4 a/ O" l) T' l
      function transfer(address to, uint value, bytes data) {
    ) ]' R0 t3 w: f0 ^5 T" n" j, M        uint codeLength;
    / J1 e4 z* g4 z4 ~        assembly {
    + {  P( k/ p) N- u6 j            codeLength := extcodesize(_to)
    & \6 K9 R% {5 R# C5 W        }- |8 O, b1 c: [2 A* X+ d5 m
            balances[msg.sender] = balances[msg.sender].sub(_value);/ h7 u0 v; z1 q9 p7 u
            balances[_to] = balances[_to].add(_value);
    . M1 ?: w! n8 S2 }4 f% [" `        if(codeLength>0) {
    % E5 k  ?, C/ D( L9 \+ i3 Q            // Require proper transaction handling.5 @% T/ X/ U4 h
                ERC223Receiver receiver = ERC223Receiver(_to);8 E* A' Y( O! B7 i
                receiver.tokenFallback(msg.sender, _value, _data);
    0 O4 U; V! I6 X( A( ^7 n0 y7 `1 Y        }9 i: _9 E- q2 s. C: E
        }
    + F) g8 }9 B  z}
    % h; C8 I8 W0 b& |- a9 Y& G2 d【todo】:代码解释
    2 R% [5 B1 L( d3 A& y
    & t& M) F/ \3 ^9 V% EThe biggest change is that ERC223 no longer allow token to be transferred to a contract that does not allow token to be withdrawn.7 M; _/ y! h4 ^; |
    https://medium.com/cryptomover/what-are-erc20-and-erc223-tokens-307badcca5a
    4 W0 c6 l/ T  z6 _7 N8 F9 q
  • BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
    声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    成为第一个吐槽的人

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

      0

    • 关注

      0

    • 主题

      13