ÓÅ·¢¹ú¼ÊÍøÕ¾¹ÙÍøADLab£ºÒÔÌ«·»ÖÇÄܺÏÔ¼¶à¸ö¹¥»÷°¸ÀýÆÊÎö
Ðû²¼Ê±¼ä 2018-08-25Ò»¡¢Ê¹ÓÃOraclize·þÎñµÄÊèºö
ΪÁ˽«Çø¿éÁ´ÊÖÒÕÓ¦Óõ½ÏßÏ£¬ÀýÈ罫·É»úÑÓÎóÏÕ¡¢Êý×ÖÇ®±Ò¶Ò»»µÈÓªÒµÉÏÁ´£¬Çø¿éÁ´ÐèÒª¾ßÓлá¼ûÁ´ÍâÊý¾ÝµÄÄÜÁ¦¡£¿ÉÊÇÈôÊÇÖÇÄܺÏÔ¼Ö±½Ó´ÓÍⲿ·þÎñ»ñÈ¡Êý¾Ý£¬ÓÉÓÚÍøÂçÑÓ³Ù£¬½Úµã´¦Öóͷ£ËÙÂʵÈÖÖÖÖÔµ¹ÊÔÓÉ£¬»áµ¼ÖÂÿ¸ö½áµã»ñÈ¡µÄÊý¾Ý²î±ð£¬Ê¹Çø¿éÁ´µÄ¹²Ê¶»úÖÆʧЧ¡£
ÏÖÓеĽâ¾ö¼Æ»®ÊÇʹÓõÚÈý·½·¢ËÍÇø¿éÁ´µÄÉúÒ⣬ÉúÒâ»áͬ²½µ½Ã¿¸ö½Úµã£¬´Ó¶ø°ü¹ÜÊý¾ÝµÄÒ»ÖÂÐÔ¡£OraclizeÊÇÒ»¸öÔ¤ÑÔ»ú£¬ÎªÒÔÌ«·»µÈÇø¿éÁ´ÌṩÊý¾Ý·þÎñ£¬Ëü×ÔÁ¦ÓÚÇø¿éÁ´ÏµÍ³Ö®Í⣬ÊÇÒ»ÆäÖÐÐÄ»¯µÄµÚÈý·½¡£Oraclize¿ÉÒÔÌṩµÄÊý¾Ý»á¼û·þÎñ°üÀ¨Ëæ»úÊý¡¢URL»á¼û¡¢IPFSµÈ¡£OraclizeµÄ¼Ü¹¹ÈçͼËùʾ£º

Oraclize²»ÊÇÁ´ÉÏÖ±½Ó¿ÉÒÔŲÓõĺ¯Êý£¬¶øÊÇÒ»¸öÁ´ÍâµÄʵÌ塣ΪÁËץȡÍⲿÊý¾Ý£¬ÒÔÌ«·»ÖÇÄܺÏÔ¼ÐèÒª·¢ËÍÒ»¸öÅÌÎÊÇëÇó¸øOraclize£¬µ±Oraclize¼àÌýµ½Á´ÉÏÓÐÏà¹ØÇëÇóʱ£¬Á¬Ã¦¶Ô»¥ÁªÍøÉϵÄ×ÊÔ´Ìᳫ»á¼û£¬È»ºóŲÓúÏÔ¼ÖеĻص÷º¯Êý__callback½«ÅÌÎÊЧ¹û·µ»ØÇø¿éÁ´¡£
ÀýÈ磬ÓÃÃÀÔª¶Ò»»ÒÔÌ«±ÒµÄÖÇÄܺÏÔ¼µÄÊý¾ÝÅÌÎÊÓï¾äÈçÏ£º

¼àÌýµ½ÇëÇóºó£¬Oraclize»á»á¼ûURL»ñµÃÅÌÎÊЧ¹û£¬È»ºóŲÓÃ__callbackµÄº¯Êý£¬Oraclize·µ»ØµÄÊý¾Ýͨ¹ý__callbackº¯Êý²ÎÊý´«»ØÖÇÄܺÏÔ¼¡£ÉÏͼÖк¯ÊýŲÓõIJÎÊý[3]Öеġ°3334312e3533¡±¼´ÎªÆäʱµÄ»ãÂÊ£º1ETH = $341.53£¬ËæºóÖÇÄܺÏÔ¼»áƾ֤Õâ¸öÅÌÎÊЧ¹û¾ÙÐкóÐøµÄÂß¼´¦Öóͷ£¡£

1¡¢¹¥»÷°¸Àý£ºSIGMA (0x03AF37073258B08FfFF303e9E07E8a0B7bfc4fd9)
SIGMAºÏԼʹÓÃÁËOraclize·þÎñÅÌÎÊ»ãÂÊ¡£¸ÃºÏÔ¼µÄ__callback»Øµ÷º¯ÊýÈçÏ£º

ÓÉÓÚ__callbackº¯ÊýÖб£´æÕûÊýÒç³ö£¬µ¼ÖÂownerµÄ´ú±ÒÓà¶î±»ÏÂÒç³ÉÒ»¸öºÜ´óµÄÖµ£¬µ¼Ö´ú±ÒÔö·¢¡£´Ó´ú±Ò·Ý¶îÅÅÃû¿ÉÒÔ¿´³ö¹¥»÷ÕßµÄÕË»§µØµãΪ0x2ef045a75b967054791c23ab93fbc52cc0a35c80£¬¶ø¸ÃµØµã²¢²»Êǽ¨ÉèºÏÔ¼µÄÕË»§µØµã(0xC7e92D8997359863a8F15FE87C0812D7A3a8F770)¡£

¸ú×ÙTransactions£¬·¢Ã÷0xC7e92D8997359863a8F15FE87C0812D7A3a8F770µ÷transfer_ownership½«ºÏÔ¼µÄownerÉèÖÃΪ0x2ef045a75b967054791c23ab93fbc52cc0a35c80¡£

Õë¶ÔÕâ¸öÎó²îÊÇ·ñʹÓÃSafeMath¾Í¿ÉÒÔ½â¾öÁËÄØ£¿ÃÕµ×ÊÇ·ñ¶¨µÄ¡£ÔÚOraclizeŲÓÃ__callback֮ǰ£¬ÓÐÓû§¶ÔÅÌÎʺ¯ÊýµÄŲÓ㬲¢ÇÒÕâ¸öŲÓÃÆÆ·ÑÒÔÌ«±Ò¡£

ʹÓÃSafeMathµÄÇéÐÎÏ£¬±¬·¢Òç³öµÄÊÂÎñ»á»Ø¹ö£¬µ«±¾ÀýÖÐÄܹ»»Ø¹öµÄÖ»ÓÐOraclize¶Ô__callbackº¯ÊýŲÓõÄÊÂÎñ£¬¶ø֮ǰÓû§ÆÆ·ÑÒÔÌ«±Ò±¬·¢µÄÊÂÎñÔòÎÞ·¨»Ø¹ö¡£Õâ¸öÕ÷ÏóµÄ»ù´¡Ôµ¹ÊÔÓÉÊÇOraclizeÊÇÒ»¸ö×ÔÁ¦µÄʵÌ壬µ¼ÖÂÂß¼ÉÏÓ¦¸ÃÍêÕûµÄÒ»¸ö²Ù×÷±»Ö§½â³ÉÁËÁ½¸öÊÂÎñ¡£Òò´Ë£¬Í¨¹ýOraclizeÓëÁ´ÏÂÊý¾Ý½»»¥Ê±Ö»ÄÜÔ½·¢Ð¡ÐÄ£¬´úÂë±àдÐèÒªÔ½·¢ÉóÉ÷¡£
¶þ¡¢ÅÓÊÏ´ú±ÒºÏÔ¼Îó²î
ÒÔÌ«·»ÖÇÄܺÏÔ¼ÖлìÔÓ½øÁ˲»ÉÙÅÓÊÏȦÌ׺ÏÔ¼£¬ËûÃÇÏòͶ×ÊÕßÔÊÐí£¬ÈôÊÇÄãÏòijºÏԼͶ×ÊÒ»±ÊÒÔÌ«·»£¬Ëü¾Í»áÒÔÒ»¸ö¸ß»Ø±¨ÂÊ»ØÔùÄã¸ü¶àµÄÒÔÌ«±Ò£¬È»¶ø¸ß»Ø±¨Ö»ÄÜ´ÓºóÐøµÄͶ×ÊÕßÄÇÀïÔ´Ô´Ò»Ö±µØÎüÊÕ×ʽðÒÔ·´Ïì¸øÇ°ÃæµÄͶ×ÊÕß¡£
1¡¢¹¥»÷°¸Àý£ºETHX( 0x1c98eea5fe5e15d77feeabc0dfcfad32314fd481)
ETHXÊÇÒ»¸öµä·¶µÄÅÓÊÏ´ú±ÒºÏÔ¼¡£¸ÃºÏÔ¼¿ÉÒÔ¿´³ÉÐéÄâ±ÒÉúÒâËù£¬µ«Ö»ÓÐETHºÍETHX (ERC20 token)ÉúÒâ¶Ô£¬Ã¿´ÎÉúÒ⣬¶¼ÓÐ5%µÄtoken·ÖÅɸøÕû¸öƽ̨µÄÒÑÓеÄtoken³ÖÓÐÕߣ¬Òò´Ëtoken³ÖÓÐÕßÔÚ³Ö±Òʱ´ú£¬½«»áÖ±½Ó׬ȡйºÖÃÕߺ;ÉÅ×ÊÛÕßµÄÊÖÐø·Ñ¡£´ÓETHXºÏÔ¼´úÂë¿ÉÒÔ¿´³ö£¬¸ÃºÏÔ¼¶ÔtransferFromº¯Êý¾ÙÐÐÁËÀ©Õ¹£¬transferFromº¯ÊýÊ×ÏȾÙÐÐallowanceÏÞ¶îÅжϣ¬È»ºóŲÓÃÁË×Ô½ç˵µÄtransferTokensº¯ÊýÀ´Íê³ÉתÕË¡£

ÔÚtransferTokensº¯ÊýÖУ¬µ±toÕË»§µØµã²»¼´ÊǺÏÔ¼µØµã£¬ÓÉÓÚÊÂÏȶÔfromÕË»§¶î¶È¾ÙÐÐÁËÇå¾²¼ì²é£¬ÒòÒÔºóÃæÁÙfromÕË»§µÄbalanceÔËËã²»»á±¬·¢Òç³ö¡£

µ±toÕË»§µØµã¼´ÊǺÏÔ¼µØµãʱ£¬ÔòŲÓÃsellº¯Êý£¬sellº¯ÊýÖÐÓÉÓÚ´úÂë±àдʧÎ󣬹ýʧµÄ½«fromд³Émsg.sender£¬¶Ômsg.senderµÄ¶î¶È¾ÙÐÐÁ˼õ·¨²Ù×÷£¬¶øÔÚ¼õ·¨²Ù×÷ǰûÓоÙÐÐÇå¾²¼ì²é£¬Òò´Ë±£´æÒç³öÎó²î¡£

ΪÁËÍê³É¶ÔÕâ¸öÒç³öÎó²îµÄ¹¥»÷£¬¹¥»÷ÕßÐèÒª2¸öÕË»§A¡¢B£¬ÆäÖÐAÕË»§´ú±ÒÓà¶î²»Îª0£¬BÕË»§´ú±ÒΪ0¡£
? AÕË»§Å²ÓÃapprove¸øBÊÚȨһ²¿·ÖתÕ˶î¶È£¬¼ÙÉèÊÚȨ¶î¶ÈΪ1£»
? BÕË»§Å²ÓÃtransferFrom£¬´ÓAÕË»§×ª1µ¥Î»´ú±Òµ½ÖÇÄܺÏÔ¼£»transferFromŲÓÃsellº¯Êýʱ´¥·¢ÕûÊýÒç³ö£¬¼´0-1=2^255¡£BÕË»§ÔÚÓà¶îΪ0µÄÇéÐÎÏ»ñµÃÁË×î´ó¶î¶ÈµÄtoken¡£
ÔÚETHXºÏÔ¼¹¥»÷Á´ÖУ¬¹¥»÷ÕßʹÓÃÁËÁ½¸öÕË»§µØµã£¬»®·ÖΪ£º
0x423b1404f51a2cdae57e597181da0a4ca4492f30
0x17a6e289e16b788505903cc7cf966f5e33dd1b94
Ê×ÏÈ£¬0x17a6e289e16b788505903cc7cf966f5e33dd1b94ŲÓÃapprove¸ø0x423b1404f51a2cdae57e597181da0a4ca4492f30ÊÚȨתÕ˶î¶È£¬²ÎÊývalue=1¡£

È»ºó£¬0x423b1404f51a2cdae57e597181da0a4ca4492f30ŲÓÃtransferFromÒªÁ죬´ÓÕË»§0x17a6e289e16b788505903cc7cf966f5e33dd1b94ÏòETHXºÏÔ¼µØµã0x1c98eea5fe5e15d77feeabc0dfcfad32314fd481 תÒÆ1¸öToken¡£

ŲÓÃÇ°£¬balance(0x423b1404f51a2cdae57e597181da0a4ca4492f30)=0¡£Å²Óúó£¬Òç³öºóbalance(0x423b1404f51a2cdae57e597181da0a4ca4492f30)=2^255¡£
¼à¿Øƽ̨ÏÔʾÒѾ±»¹¥»÷µÄͬÀà´ú±ÒºÏÔ¼ÈçÏÂ±í£º

Èý¡¢SafeMathʹÓò»µ±
ÒÔÌ«·»ÐéÄâ»úEVM½ç˵ÎÞ·ûºÅÕûÊýΪuint256£¬¿ÉÒÔÌåÏÖÒ»¸ö256λµÄ´óÕûÊý£¬µ«²¢Ã»ÓÐÌṩÒç³öµÄ¼ì²â»úÖÆ¡£OpenZepplineÊÇÒ»¸öµÚÈý·½ÖÇÄܺÏÔ¼¿â£¬ÊµÏÖÁËÒ»Ì×SafeMath¿âÀ´¼ì²âÒç³ö¡£Æä´úÂëÈçÏ£º

SafeMathʹÓÃÄÚ½¨µÄrequire»òassertÀ´¼ì²éÔËËãÊÇ·ñ±¬·¢Òç³ö£¬ÈôÊDZ¬·¢ÁËÒç³ö£¬requireºÍassertÖаüÀ¨µÄ´úÂë»áʹ¸ÃÊÂÎñ»Ø¹ö¡£µ«ÓÐЩ¿ª·¢Õß²»¿ÉÍêÈ«Ã÷È·SafeMathÄ£°æ´úÂ룬µ¼ÖºÏÔ¼´úÂëÖÐÈÔÈ»±£´æÎó²î¡£
1¡¢¹¥»÷°¸Àý£ºUCN (0x6EF5B9ae723Fe059Cac71aD620495575d19dAc42)

UCN£¨http://www.saveunicoins.com/Unicorn/index.html£©ÊÇÒ»¸öÖÇÄܺÏÔ¼DAppÓ¦Ó᣺ÏÔ¼´úÂëÔÚSafeMath¿âÖÐ×¢ÊÍassertÓï¾ä£¬Òò´ËSafeMathº¯ÊýµÈͬÓÚÖ±½Ó¾ÙÐÐËãÊõÔËË㣬ûÓÐÈκÎÇå¾²¼ì²é¡£²¢ÇÒÔÚtransferFromº¯ÊýÖУ¬×¢ÊÍÖÐÉùÃ÷subº¯ÊýÊÇÇå¾²µÄ£¬²»ÖªµÀÕâÊÇ¿ª·¢Ö°Ô±µÄÊèºöÕվɾÓÐÄÁôϵĺóÃÅ¡£

ÓÉÓÚsubº¯ÊýµÈͬÓÚËãÊõÔËË㣬balances[_from] = balances[_from].sub(_value);
±£´æÕûÊýÏÂÒçÎó²î£¬¿ÉÒÔʹµÃÕË»§Óà¶îÄð³ÉÒ»¸ö¼«´óÖµ¡£
2¡¢¹¥»÷°¸Àý£ºEMVC£¨0xd3F5056D9a112cA81B0e6f9f47F3285AA44c6AAA£©
EMVC£¨http://crypto7.biz/£©ºÏÔ¼´úÂëÔÚSafeMath¿âÖÐʹÓÃÁËÒ»¸ö×Ô½ç˵µÄassertÀ´È¡´úÄÚ½¨µÄassert¡£ÔÚassertº¯ÊýÖУ¬ÈôÊDzÎÊýassertionΪfalseÔòÖ±½Óreturn£¬²¢Ã»ÓоÙÐÐÒì³£´¦Öóͷ£¡£Òò´ËSafeMathº¯ÊýµÈͬÓÚÖ±½Ó¾ÙÐÐËãÊõÔËË㣬ûÓÐÈκÎÇå¾²¼ì²é¡£

¹¥»÷Õß¿ÉÒÔʹÓÃtransferº¯ÊýÉèÖÃí§ÒâÕË»§Óà¶îΪí§ÒâÖµ¡£

ËÄ¡¢×ܽá
µ±ÖÇÄܺÏԼҪʵÏÖ¸ü¶à¹¦Ð§Ê±£¬´úÂë»áÏìÓ¦±äµÃÔ½·¢ÖØ´ó£¬ÓëERC20±ê×¼´úÂëµÄ²î±ðÒ²Ô½À´Ô½´ó£¬Òò¶øDZÔÚµÄÎó²îÃæÄ¿Ô½·¢¶àÑù¡£ÎªÁË°ü¹ÜÖÇÄܺÏÔ¼µÄÇå¾²£¬³ý×ñÕÕÇå¾²¿ª·¢ÔÔò¡¢Æ¾Ö¤¡°Check Lists¡±¾ÙÐлùÏß¼ì²éÍ⣬»¹ÐèҪʵÑé¸üÉîÈëÏ꾡µÄÉó¼Æ¡£