Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

ERC223: 防止转账黑洞

杨小公子君莫邪
143 0 0
以太坊的智能合约和普通用户的地址是被一样对待的,没法判断一个地址是智能合约还是普通用户。当你误操作向一个智能合约转账,就真的转过去了,然后 token 就丢了。$ L3 c& v! t0 O5 s) }# R$ n; v

9 B; @+ z1 u- M! _4 iThere 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.# T$ w, j, Z9 x+ l1 i( K
https://stackoverflow.com/a/37670490/72189121 R2 b) q* z$ s4 Q5 @8 y/ Z% v# d

- B: P9 q; E' U& k' u5 P( p! u/ g$ ?! R有时候确实有需要向智能合约转账:* H% s5 R( f! s  ^2 u8 X: H) D! T
  • 给智能合约转 Ether,作为 gas;
  • 比如向 bancor 的智能合约转 token 抵押在那里,转进去的 token 在卖出操作时会转出;  ^& {9 Q4 K: A, C: ~

    / W% _! |3 N, i; A# l但是大多数 smart contract 的 token 是不能转出的,只要合约里没写转出的逻辑,就不能转出。以太坊将智能合约看做是独立的个体,没人知道它的私钥,给不支持转出的智能合约转 token 就等于销毁了。
    : g) N; ]# P2 I/ K% O6 k当我们要转账时,会转到交易方的地址,不会闲着没事给智能合约转 token。但是这种事情仍然会发生,不断有人给 EOSTokenContract 转 EOS(见下图),EOSTokenContract 账户下现在有 154,834 EOS,价值 $1,176,738.4(价格 $7.6)。类似的,QtumTokenContract 账户下现在有 22,293 QTUM,价值 $158,280.3(价格 $7.1)。2 v1 ~6 N2 Q' g7 o- z2 p
    这些 token 都都都都销毁了 (⊙?⊙)
    1 g3 C% f% S% s6 C) y
    / L* n  |8 a" K! M% d. qDexaran 认识到了这个问题,0 O( d2 S% W- n* T/ |

    & U8 m. o7 Q5 U) @* b7 ZContracts that are not designed to work with tokens must reject incoming token transactions. Otherwise, each token becomes a potential token trap.$ D. N% K% g5 c4 C0 p2 a& [3 d
    ERC20 token standard issues.(google docs)& M5 g, p* |4 ?
    + R$ W1 H4 N- F' |/ H
    并在 github 创建了一个 issue。
    , g) O6 k. Y+ R, v- x+ L" ?1 GtokenFallback 函数,当转账到不能转出的智能合约地址时,将自动取消。
    ) ]! [6 l% S) J1 N9 Z. h2 ucontract ERC223 {
    * O$ i. M9 Y# `4 M; e# `) O, }  function transfer(address to, uint value, bytes data) {. N& H0 R% T) [, x7 ^9 M+ [
            uint codeLength;
    / z4 j( R, L& I; j- b: A        assembly {4 d9 [& `$ V' Y2 ~
                codeLength := extcodesize(_to)5 }. L3 j/ x: m7 Y/ D8 [& c
            }+ g# E4 b& ]7 b. k# d- x
            balances[msg.sender] = balances[msg.sender].sub(_value);
    2 e1 j' i- l$ X+ E' p# a        balances[_to] = balances[_to].add(_value);! G9 A2 K+ i3 {( w$ f
            if(codeLength>0) {
    % a6 p5 C9 o9 J. ~- ~, u! n            // Require proper transaction handling., A" Z/ p6 W  Q# f) l! R
                ERC223Receiver receiver = ERC223Receiver(_to);) \' A) x& c% V
                receiver.tokenFallback(msg.sender, _value, _data);: P$ p, J1 }( Y1 }9 n9 H
            }2 d# z* e& h% r7 ?: B/ h( o
        }
    $ r; R* }& O9 N3 W* \0 P}
    , s: h- N$ w: I【todo】:代码解释4 p5 y, X. }4 ]. B% \/ X4 N& c

    8 P2 I+ N% e4 q. \% iThe biggest change is that ERC223 no longer allow token to be transferred to a contract that does not allow token to be withdrawn.  [; G; R2 Q2 N* X/ b8 H! F: ]
    https://medium.com/cryptomover/what-are-erc20-and-erc223-tokens-307badcca5a! @; O* a2 S5 {/ N- z+ i% Z8 N, b
  • BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
    声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    成为第一个吐槽的人

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

      0

    • 关注

      0

    • 主题

      13