Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

ERC223: 防止转账黑洞

杨小公子君莫邪
85 0 0
以太坊的智能合约和普通用户的地址是被一样对待的,没法判断一个地址是智能合约还是普通用户。当你误操作向一个智能合约转账,就真的转过去了,然后 token 就丢了。
  D6 w7 Q; W' G4 F9 a* S. Y& H9 M6 \+ y2 F: V( L( R, C
There 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.2 o) M" m" Z8 E
https://stackoverflow.com/a/37670490/7218912; m, u: @, i7 j( S
( l% U6 ]  I1 {5 ~
有时候确实有需要向智能合约转账:
! J" h. ^/ [  S: [% D
  • 给智能合约转 Ether,作为 gas;
  • 比如向 bancor 的智能合约转 token 抵押在那里,转进去的 token 在卖出操作时会转出;
    * y1 j' o5 z4 }8 u! N6 c

    9 r/ i3 U. J; z5 f$ [但是大多数 smart contract 的 token 是不能转出的,只要合约里没写转出的逻辑,就不能转出。以太坊将智能合约看做是独立的个体,没人知道它的私钥,给不支持转出的智能合约转 token 就等于销毁了。. d+ w* M2 j( _# ^* E8 ^3 _7 F6 G* g
    当我们要转账时,会转到交易方的地址,不会闲着没事给智能合约转 token。但是这种事情仍然会发生,不断有人给 EOSTokenContract 转 EOS(见下图),EOSTokenContract 账户下现在有 154,834 EOS,价值 $1,176,738.4(价格 $7.6)。类似的,QtumTokenContract 账户下现在有 22,293 QTUM,价值 $158,280.3(价格 $7.1)。* A: \- H- A4 Q% h: z0 X
    这些 token 都都都都销毁了 (⊙?⊙)
    2 q3 W* h( X* w0 P4 J7 k4 T( R' H( Y$ g
    Dexaran 认识到了这个问题," A0 V5 N0 `( r  k+ z
    $ H* h5 T$ \. ]' S
    Contracts that are not designed to work with tokens must reject incoming token transactions. Otherwise, each token becomes a potential token trap.: J' J6 d9 c. |; `9 H  I- @
    ERC20 token standard issues.(google docs)
    * r+ t! X5 }$ Q% E; c% D& E& n
    & `' @' v4 k  b
    并在 github 创建了一个 issue。
    4 f+ Y& w& L2 u8 N! HtokenFallback 函数,当转账到不能转出的智能合约地址时,将自动取消。
      ~+ y: T# l2 r. ]* f% V* l0 |contract ERC223 {
    + U% M4 T& j9 H5 G* z8 n5 ^* a  function transfer(address to, uint value, bytes data) {: F8 J6 w& w8 f6 u& f9 t1 Y* ~
            uint codeLength;9 g, r% k, o7 {: X
            assembly {
    / @1 h1 a' n- F- g            codeLength := extcodesize(_to)2 ?7 |* E, S: {5 S1 f: ~8 s
            }  q/ q: C3 N% b+ o& b, \4 z; U
            balances[msg.sender] = balances[msg.sender].sub(_value);
    : j' R( Y6 c0 y! f  U        balances[_to] = balances[_to].add(_value);
    1 G# o7 c& G3 r& m. ^- E        if(codeLength>0) {! p+ Z! z1 o0 g2 k' Y) U
                // Require proper transaction handling.6 O) s  G* T" ~' z8 _) c
                ERC223Receiver receiver = ERC223Receiver(_to);! i  G2 _) W' s2 q+ M% i: \
                receiver.tokenFallback(msg.sender, _value, _data);
    # F$ c( f" `( f3 E        }% N( K5 P. E5 j1 f" t# v$ ^
        }
    0 {) u# D6 y+ T; \2 ~: _$ o$ Q# j}
    . ]9 O3 ~- `; K  r7 ~2 {7 c/ n【todo】:代码解释7 i/ [- |% @0 b' L, k

    4 R% n: y+ m2 Q3 rThe biggest change is that ERC223 no longer allow token to be transferred to a contract that does not allow token to be withdrawn.
    ! {7 \" t: F' n- bhttps://medium.com/cryptomover/what-are-erc20-and-erc223-tokens-307badcca5a
    - l# f6 O- Q* f4 M1 f0 I
  • BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
    声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    成为第一个吐槽的人

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

      0

    • 关注

      0

    • 主题

      13