Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

ERC223: 防止转账黑洞

杨小公子君莫邪
169 0 0
以太坊的智能合约和普通用户的地址是被一样对待的,没法判断一个地址是智能合约还是普通用户。当你误操作向一个智能合约转账,就真的转过去了,然后 token 就丢了。9 [7 X0 j. J' X
3 L8 z% l6 F* t" W
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.9 X3 O( D3 E" w2 W
https://stackoverflow.com/a/37670490/7218912
5 Q0 S/ G+ z0 u
) C& [% d% F7 Q6 q* U/ \. @$ t
有时候确实有需要向智能合约转账:
) e& s. T! C. u3 X# @4 o, W3 T
  • 给智能合约转 Ether,作为 gas;
  • 比如向 bancor 的智能合约转 token 抵押在那里,转进去的 token 在卖出操作时会转出;; U: b; j3 u- T0 m; B
    4 i% s& \/ P0 c4 H
    但是大多数 smart contract 的 token 是不能转出的,只要合约里没写转出的逻辑,就不能转出。以太坊将智能合约看做是独立的个体,没人知道它的私钥,给不支持转出的智能合约转 token 就等于销毁了。
    7 @: B" m' r5 e' d4 l- Z当我们要转账时,会转到交易方的地址,不会闲着没事给智能合约转 token。但是这种事情仍然会发生,不断有人给 EOSTokenContract 转 EOS(见下图),EOSTokenContract 账户下现在有 154,834 EOS,价值 $1,176,738.4(价格 $7.6)。类似的,QtumTokenContract 账户下现在有 22,293 QTUM,价值 $158,280.3(价格 $7.1)。
    2 l! Q" _) W0 ~6 Z1 D这些 token 都都都都销毁了 (⊙?⊙)
    ) G8 q7 w% H$ C) l2 y5 A0 p" r0 T5 C6 W8 ?9 s, x
    Dexaran 认识到了这个问题,4 ]1 r  J2 D$ }; z1 |, H

    8 a7 \/ @3 @& n4 ~3 p, A% lContracts that are not designed to work with tokens must reject incoming token transactions. Otherwise, each token becomes a potential token trap.
    ! Y( N* p% }4 ^ERC20 token standard issues.(google docs)
    % ]( r7 x! S) c) \  ?

    6 O" W  M* s5 s+ |- w# p) q$ J并在 github 创建了一个 issue。
    1 Y0 t3 l, I0 j* S2 Y, l& `6 PtokenFallback 函数,当转账到不能转出的智能合约地址时,将自动取消。
    " V% L6 \/ K3 R4 R0 v4 A* u& ncontract ERC223 {
    + H* @- P* o) q  function transfer(address to, uint value, bytes data) {
    $ k, Z6 B# W" n        uint codeLength;* l6 ?, O( _9 Z4 C; a
            assembly {* O' G  s6 O; F/ l. q+ [) |9 z. m. X
                codeLength := extcodesize(_to)
    . k3 S, W) P% z" {  i% f        }
    3 d: U) b" R$ f' x3 r+ y        balances[msg.sender] = balances[msg.sender].sub(_value);
    4 V* p, u5 ]# X/ C" U; ^" N        balances[_to] = balances[_to].add(_value);
    8 K9 a0 c+ v: K9 G. _9 z' P        if(codeLength>0) {, a  R" H) D) A1 q( ?3 s  F$ u- S
                // Require proper transaction handling.
    2 \( Q/ _( O1 a7 A            ERC223Receiver receiver = ERC223Receiver(_to);* x/ c+ y& X! Y" {: l" z+ s
                receiver.tokenFallback(msg.sender, _value, _data);. G$ H2 a+ V! W1 g8 D
            }
    . N1 ^; \4 o9 [    }
    & T. l  Z% j0 A; c9 j; Z}; t. c& h- X% D+ Y
    【todo】:代码解释9 K5 N5 X. [, D4 R

    * Q+ K. `  u& k$ D$ [5 EThe biggest change is that ERC223 no longer allow token to be transferred to a contract that does not allow token to be withdrawn.9 \. ^! H1 r9 M" O0 A. k
    https://medium.com/cryptomover/what-are-erc20-and-erc223-tokens-307badcca5a
    ' z% y& C- `% f9 E5 r
  • BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
    声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    成为第一个吐槽的人

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

      0

    • 关注

      0

    • 主题

      13