{"id":6287,"date":"2021-06-05T12:57:59","date_gmt":"2021-06-05T12:57:59","guid":{"rendered":"http:\/\/43.153.210.228\/\/?p=6287"},"modified":"2021-06-05T12:57:59","modified_gmt":"2021-06-05T12:57:59","slug":"%e7%9f%a5%e9%81%93%e5%88%9b%e5%ae%87%e5%8c%ba%e5%9d%97%e9%93%be%e5%ae%89%e5%85%a8%e5%ae%9e%e9%aa%8c%e5%ae%a4%ef%bd%9c%e6%b7%b1%e5%85%a5%e7%90%86%e8%a7%a3%e9%87%8d%e5%85%a5%e6%94%bb%e5%87%bb%e6%bc%8f","status":"publish","type":"post","link":"http:\/\/43.153.210.228\/?p=6287","title":{"rendered":"\u77e5\u9053\u521b\u5b87\u533a\u5757\u94fe\u5b89\u5168\u5b9e\u9a8c\u5ba4\uff5c\u6df1\u5165\u7406\u89e3\u91cd\u5165\u653b\u51fb\u6f0f\u6d1e"},"content":{"rendered":"<h3>&nbsp;<\/h3>\n<p><a href=\"https:\/\/www.chainnode.com\/user\/985070\">\u521b\u5b87\u533a\u5757\u94fe\u5b89\u5168\u5b9e\u9a8c\u5ba4<\/a> \u6c34\u624b 2021-06-03 11:09:47 <i>\u53d1\u5e03\u5728 <\/i><a href=\"https:\/\/www.chainnode.com\/forum\/61\">\u533a\u5757\u94fe\u793e\u533a<\/a> <\/p>\n<p><i><\/i> 25227 <i><\/i> 0 <\/p>\n<h4>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/8c790f28a6667e3582758b5e4871f927.jpeg\"><\/h4>\n<h4><strong>\u524d\u8a00<\/strong><\/h4>\n<p>\u667a\u80fd\u5408\u7ea6\uff08\u82f1\u6587\uff1aSmart contract \uff09\u7684\u6982\u5ff5\u4e8e 1995 \u5e74\u7531 Nick Szabo \u9996\u6b21\u63d0\u51fa\uff0c\u5b83\u662f\u4e00\u79cd\u65e8\u5728\u4ee5\u4fe1\u606f\u5316\u65b9\u5f0f\u4f20\u64ad\u3001\u9a8c\u8bc1\u6216\u6267\u884c\u5408\u540c\u7684\u8ba1\u7b97\u673a\u534f\u8bae\uff0c\u5b83\u5141\u8bb8\u5728\u6ca1\u6709\u7b2c\u4e09\u65b9\u7684\u60c5\u51b5\u4e0b\u8fdb\u884c\u53ef\u4fe1\u4ea4\u6613\uff0c\u8fd9\u4e9b\u4ea4\u6613\u53ef\u8ffd\u8e2a\u4e14\u4e0d\u53ef\u9006\u8f6c\u3002\u7136\u800c\u667a\u80fd\u5408\u7ea6\u4e5f\u5e76\u975e\u662f\u5b89\u5168\u7684\uff0c\u5176\u4e2d \u91cd\u5165 (Re-Entrance) \u653b\u51fb\u6f0f\u6d1e\u662f\u4ee5\u592a\u574a\u4e2d\u7684\u653b\u51fb\u65b9\u5f0f\u4e4b\u4e00\uff0c\u65e9\u5728 2016 \u5e74\u5c31\u56e0\u4e3a The DAO \u4e8b\u4ef6\u800c\u9020\u6210\u4e86\u4ee5\u592a\u574a\u7684\u786c\u5206\u53c9\u3002 <\/p>\n<h4><strong>\u6f0f\u6d1e\u6982\u8ff0<\/strong><\/h4>\n<p><strong><br \/><\/strong> <\/p>\n<p>\u5728\u4ee5\u592a\u574a\u4e2d\uff0c\u667a\u80fd\u5408\u7ea6\u80fd\u591f\u8c03\u7528\u5176\u4ed6\u5916\u90e8\u5408\u7ea6\u7684\u4ee3\u7801\uff0c\u7531\u4e8e\u667a\u80fd\u5408\u7ea6\u53ef\u4ee5\u8c03\u7528\u5916\u90e8\u5408\u7ea6\u6216\u8005\u53d1\u9001\u4ee5\u592a\u5e01\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u9700\u8981\u5408\u7ea6\u63d0\u4ea4\u5916\u90e8\u7684\u8c03\u7528\uff0c\u6240\u4ee5\u8fd9\u4e9b\u5408\u7ea6\u5916\u90e8\u7684\u8c03\u7528\u5c31\u53ef\u4ee5\u88ab\u653b\u51fb\u8005\u5229\u7528\u9020\u6210\u653b\u51fb\u52ab\u6301\uff0c\u4f7f\u5f97\u88ab\u653b\u51fb\u5408\u7ea6\u5728\u4efb\u610f\u4f4d\u7f6e\u91cd\u65b0\u6267\u884c\uff0c\u7ed5\u8fc7\u539f\u4ee3\u7801\u4e2d\u7684\u9650\u5236\u6761\u4ef6\uff0c\u4ece\u800c\u53d1\u751f\u91cd\u5165\u653b\u51fb\u3002\u91cd\u5165\u653b\u51fb\u672c\u8d28\u4e0a\u4e0e\u7f16\u7a0b\u91cc\u7684\u9012\u5f52\u8c03\u7528\u7c7b\u4f3c\uff0c\u6240\u4ee5\u5f53\u5408\u7ea6\u5c06\u4ee5\u592a\u5e01\u53d1\u9001\u5230\u672a\u77e5\u5730\u5740\u65f6\u5c31\u53ef\u80fd\u4f1a\u53d1\u751f\u3002 <\/p>\n<p>\u7b80\u5355\u7684\u6765\u8bf4\uff0c\u53d1\u751f\u91cd\u5165\u653b\u51fb\u6f0f\u6d1e\u7684\u6761\u4ef6\u6709 2 \u4e2a\uff1a <\/p>\n<ul>\n<li>\u8c03\u7528\u4e86\u5916\u90e8\u7684\u5408\u7ea6\u4e14\u8be5\u5408\u7ea6\u662f\u4e0d\u5b89\u5168\u7684\n<li>\u5916\u90e8\u5408\u7ea6\u7684\u51fd\u6570\u8c03\u7528\u65e9\u4e8e\u72b6\u6001\u53d8\u91cf\u7684\u4fee\u6539<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u7ed9\u51fa\u4e00\u4e2a\u7b80\u5355\u7684\u4ee3\u7801\u7247\u6bb5\u793a\u4f8b\uff1a <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/ac0ea3ffa8daa7545b5b458d296ae3c9.jpeg\"> <\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u7247\u6bb5\u5c31\u662f\u6700\u7b80\u5355\u7684\u63d0\u6b3e\u64cd\u4f5c\uff0c\u63a5\u4e0b\u6765\u4f1a\u7ed9\u5927\u5bb6\u8be6\u7ec6\u5206\u6790\u91cd\u5165\u653b\u51fb\u9020\u6210\u7684\u539f\u56e0\u3002 <\/p>\n<h4><strong>\u6f0f\u6d1e\u5206\u6790<\/strong><\/h4>\n<p>\u5728\u6b63\u5f0f\u7684\u5206\u6790\u91cd\u5165\u653b\u51fb\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u6765\u4ecb\u7ecd\u51e0\u4e2a\u91cd\u70b9\u77e5\u8bc6\u3002 <\/p>\n<h6><strong><br \/><\/strong><\/h6>\n<h6><strong>01 \u8f6c\u8d26\u65b9\u6cd5<\/strong><\/h6>\n<p>\u7531\u4e8e\u91cd\u5165\u653b\u51fb\u4f1a\u53d1\u9001\u5728\u8f6c\u8d26\u64cd\u4f5c\u65f6\uff0c\u800c Solidity \u4e2d\u5e38\u7528\u7684\u8f6c\u8d26\u65b9\u6cd5\u4e3a <\/p>\n<p>&lt;address&gt;.transfer()\uff0c&lt;address&gt;.send() \u548c &lt;address&gt;.gas().call.vale()()\uff0c\u4e0b\u9762\u5bf9\u8fd9 3 \u79cd\u8f6c\u8d26\u65b9\u6cd5\u8fdb\u884c\u8bf4\u660e\uff1a <\/p>\n<ul>\n<li>&lt;address&gt;.transfer()\uff1a\u53ea\u4f1a\u53d1\u9001 2300 gas \u8fdb\u884c\u8c03\u7528\uff0c\u5f53\u53d1\u9001\u5931\u8d25\u65f6\u4f1a\u901a\u8fc7 throw \u6765\u8fdb\u884c\u56de\u6eda\u64cd\u4f5c\uff0c\u4ece\u800c\u9632\u6b62\u4e86\u91cd\u5165\u653b\u51fb\u3002\n<li>&lt;address&gt;.send()\uff1a\u53ea\u4f1a\u53d1\u9001 2300 gas \u8fdb\u884c\u8c03\u7528\uff0c\u5f53\u53d1\u9001\u5931\u8d25\u65f6\u4f1a\u8fd4\u56de\u5e03\u5c14\u503c false\uff0c\u4ece\u800c\u9632\u6b62\u4e86\u91cd\u5165\u653b\u51fb\u3002\n<li>&lt;address&gt;.gas().call.vale()()\uff1a\u5728\u8c03\u7528\u65f6\u4f1a\u53d1\u9001\u6240\u6709\u7684 gas\uff0c\u5f53\u53d1\u9001\u5931\u8d25\u65f6\u4f1a\u8fd4\u56de\u5e03\u5c14\u503c false\uff0c\u4e0d\u80fd\u6709\u6548\u7684\u9632\u6b62\u91cd\u5165\u653b\u51fb\u3002<\/li>\n<\/ul>\n<h6>02 <strong>fallback \u51fd\u6570<\/strong><\/h6>\n<p>\u63a5\u7740\u6211\u4eec\u6765\u8bb2\u89e3\u4e0b fallback \u56de\u9000\u51fd\u6570\u3002<br \/>\u56de\u9000\u51fd\u6570 (fallback function)\uff1a\u56de\u9000\u51fd\u6570\u662f\u6bcf\u4e2a\u5408\u7ea6\u4e2d\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a\u6ca1\u6709\u540d\u5b57\u7684\u51fd\u6570\uff0c\u5e76\u4e14\u8be5\u51fd\u6570\u65e0\u53c2\u6570\uff0c\u65e0\u8fd4\u56de\u503c\uff0c\u5982\u4e0b\u6240\u793a\uff1a <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/65cd32a8047f60b584df3f8d7bb487c2.png\"> <\/p>\n<p>\u56de\u9000\u51fd\u6570\u5728\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\u4e2d\u88ab\u6267\u884c\uff1a * \u8c03\u7528\u5408\u7ea6\u65f6\u6ca1\u6709\u5339\u914d\u5230\u4efb\u4f55\u4e00\u4e2a\u51fd\u6570\uff1b * \u6ca1\u6709\u4f20\u6570\u636e\uff1b * \u667a\u80fd\u5408\u7ea6\u6536\u5230\u4ee5\u592a\u5e01\uff08\u4e3a\u4e86\u63a5\u53d7\u4ee5\u592a\u5e01\uff0cfallback \u51fd\u6570\u5fc5\u88ab\u6807\u8bb0\u4e3a payable\uff09\u3002 <\/p>\n<h6>03 <strong>\u6f0f\u6d1e\u4ee3\u7801<\/strong><\/h6>\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u5c31\u662f\u5b58\u5728\u91cd\u5165\u653b\u51fb\u7684\uff0c\u5b9e\u73b0\u7684\u662f\u4e00\u4e2a\u7c7b\u4f3c\u4e8e\u516c\u5171\u94b1\u5305\u7684\u5408\u7ea6\uff0c\u6240\u6709\u7684\u7528\u6237\u90fd\u53ef\u4ee5\u4f7f\u7528 deposit() \u5b58\u6b3e\u5230 Reentrance \u5408\u7ea6\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u4ece Reentrance \u5408\u7ea6\u4e2d\u4f7f\u7528 withdraw() \u8fdb\u884c\u63d0\u6b3e\uff0c\u5f53\u7136\u4e86\u6240\u6709\u4eba\u4e5f\u53ef\u4ee5\u4f7f\u7528 balanceof() \u67e5\u8be2\u81ea\u5df1\u6216\u8005\u5176\u4ed6\u4eba\u5728\u8be5\u5408\u7ea6\u4e2d\u7684\u4f59\u989d\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/7f28d2438f9787d059b9ba6d44511a94.png\"> <\/p>\n<p>\u9996\u5148\u4f7f\u7528\u4e00\u4e2a\u8d26\u6237 (0x5B38Da6a701c568545dCfcB03FcB875f56beddC4) \u626e\u6f14\u53d7\u5bb3\u8005\uff0c\u5c06\u8be5\u5408\u7ea6\u5728 Remix IDE \u70b9\u51fb Deploy \u6309\u94ae\u8fdb\u884c\u90e8\u7f72\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/8cb4245664b767d0e864b13569ad602e.png\"> <\/p>\n<p>\u5728\u90e8\u7f72\u5408\u7ea6\u6210\u529f\u540e\u5728 VALUE \u8bbe\u7f6e\u6846\u4e2d\u586b\u5199 5\uff0c\u5c06\u5355\u4f4d\u6539\u6210 ether\uff0c\u70b9\u51fb deposit \u5b58\u5165 5 \u4e2a\u4ee5\u592a\u5e01\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/047a526fc28cbfd141b6ec4919bd6c65.png\"> <\/p>\n<p>\u70b9\u51fb wallet \u67e5\u770b\u8be5\u5408\u7ea6\u7684\u4f59\u989d\uff0c\u53d1\u73b0\u4f59\u989d\u4e3a 5 ether\uff0c\u8bf4\u660e\u6211\u4eec\u7684\u5b58\u6b3e\u6210\u529f\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/3969b8fcd03541ac3ac889d29c61632c.png\"> <\/p>\n<p>\u800c\u4e0b\u9762\u7684\u4ee3\u7801\u5219\u662f\u9488\u5bf9\u4e0a\u9762\u5b58\u5728\u6f0f\u6d1e\u7684\u5408\u7ea6\u8fdb\u884c\u7684\u653b\u51fb\uff1a <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/b101a75a37691478b0a438d37a000ecf.png\"> <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/b29383c90bf0f68b383273320ca40df0.png\"> <\/p>\n<p>\u4f7f\u7528\u53e6\u5916\u4e00\u4e2a\u8d26\u6237 (0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2) \u626e\u6f14\u653b\u51fb\u8005\uff0c\u590d\u5236\u5b58\u5728\u6f0f\u6d1e\u7684\u5408\u7ea6\u5730\u5740\u5230 Deploy \u7684\u8bbe\u7f6e\u6846\u5185\uff0c\u70b9\u51fb Deploy \u90e8\u7f72\u4e0a\u9762\u7684\u653b\u51fb\u5408\u7ea6\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/8d0dc9b9a005e7b13e0ac4befb8c5ff6.png\"> <\/p>\n<p>\u90e8\u7f72\u6210\u529f\u540e\u5148\u8c03\u7528 wallet() \u51fd\u6570\u67e5\u770b\u653b\u51fb\u5408\u7ea6\u7684\u4f59\u989d\u4e3a 0\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/16b7265185f5610519a289bba1862925.png\"> <\/p>\n<p>\u653b\u51fb\u8005\u5148\u5b58\u6b3e 1 ether \u5230\u6f0f\u6d1e\u5408\u7ea6\u4e2d\uff0c\u8fd9\u91cc\u8bbe\u7f6e VALUE \u4e3a 1 ether\uff0c\u4e4b\u540e\u70b9\u51fb\u653b\u51fb\u5408\u7ea6\u7684 deposit \u8fdb\u884c\u5b58\u6b3e\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/f98eecd2fc168d0f84b3f9195ae28cbe.png\"> <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/48fb7fb42bd29fdc26bb2f2c45e8171d.png\"> <\/p>\n<p>\u518d\u6b21\u8c03\u7528\u5408\u7ea6\u7684 wallet \u51fd\u6570\u67e5\u770b\u6f0f\u6d1e\u5408\u7ea6\u7684\u4f59\u989d\uff0c\u53d1\u73b0\u5df2\u7ecf\u53d8\u6210\u4e86 6 ether\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/801cdf5f112431212bb5e1eed69aefe5.png\"> <\/p>\n<p>\u653b\u51fb\u8005 (0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2) \u8c03\u7528\u653b\u51fb\u5408\u7ea6\u7684 attack \u51fd\u6570\u6a21\u62df\u653b\u51fb\uff0c\u4e4b\u540e\u8c03\u7528\u88ab\u653b\u51fb\u5408\u7ea6\u7684 wallet \u51fd\u6570\u53bb\u67e5\u770b\u5408\u7ea6\u7684\u4f59\u989d\uff0c\u53d1\u73b0\u5df2\u7ecf\u5f52\u96f6\uff0c\u6b64\u65f6\u56de\u5230\u653b\u51fb\u5408\u7ea6\u67e5\u770b\u4f59\u989d\uff0c\u53d1\u73b0\u88ab\u653b\u51fb\u5408\u7ea6\u4e2d\u7684 6 ether \u5df2\u7ecf\u5168\u90e8\u63d0\u6b3e\u5230\u4e86\u653b\u51fb\u8005\u5408\u7ea6\u4e2d\uff0c\u8fd9\u5c31\u9020\u6210\u4e86\u91cd\u5165\u653b\u51fb\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/4420b2ff9a25289b4b6c621faf1c1478.png\"> <\/p>\n<h6><strong><br \/><\/strong><\/h6>\n<h6><strong>04<\/strong><strong>\u6e90\u7801\u5206\u6790<\/strong><\/h6>\n<p>\u4e0a\u9762\u8bb2\u89e3\u4e86\u5982\u4f55\u8fdb\u884c\u91cd\u5165\u653b\u51fb\u5df2\u7ecf\u6f0f\u6d1e\u539f\u56e0\uff0c\u8fd9\u91cc\u68b3\u7406\u4e86\u6f0f\u6d1e\u6e90\u7801\u548c\u653b\u51fb\u7684\u6b65\u9aa4\uff0c\u5217\u51fa\u4e86\u5173\u952e\u4ee3\u7801\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/bd4761ed90d748233a47379aa82faa5d.jpg\"> <\/p>\n<h5><strong><br \/><\/strong><\/h5>\n<h4><strong>\u76f8\u5173\u6848\u4f8b<\/strong><\/h4>\n<p><strong><br \/><\/strong> <\/p>\n<p>2016 \u5e74 6 \u6708 17 \u65e5\uff0cTheDAO \u9879\u76ee\u906d\u5230\u4e86\u91cd\u5165\u653b\u51fb\uff0c\u5bfc\u81f4\u4e86 300 \u591a\u4e07\u4e2a\u4ee5\u592a\u5e01\u88ab\u4ece TheDAO \u8d44\u4ea7\u6c60\u4e2d\u5206\u79bb\u51fa\u6765\uff0c\u800c\u653b\u51fb\u8005\u5229\u7528 TheDAO \u667a\u80fd\u5408\u7ea6\u4e2d\u7684 splitDAO() \u51fd\u6570\u91cd\u590d\u5229\u7528\u81ea\u5df1\u7684 DAO \u8d44\u4ea7\u8fdb\u884c\u91cd\u5165\u653b\u51fb\uff0c\u4e0d\u65ad\u7684\u4ece TheDAO \u9879\u76ee\u7684\u8d44\u4ea7\u6c60\u4e2d\u5c06 DAO \u8d44\u4ea7\u5206\u79bb\u51fa\u6765\u5e76\u8f6c\u79fb\u5230\u81ea\u5df1\u7684\u8d26\u6237\u4e2d\u3002 <\/p>\n<p>\u4e0b\u5217\u4ee3\u7801\u4e3a splitDAO() \u51fd\u6570\u4e2d\u7684\u90e8\u5206\u4ee3\u7801\uff0c\u6e90\u4ee3\u7801\u5728 TokenCreation.sol \u4e2d\uff0c\u5b83\u4f1a\u5c06\u4ee3\u5e01\u4ece the parent DAO \u8f6c\u79fb\u5230 the child DAO \u4e2d\u3002\u5e73\u8861\u6570\u7ec4 uint fundsToBeMoved = (balances[msg.sender] * p.splitData[0].splitBalance) \/ p.splitData[0].totalSupply \u51b3\u5b9a\u4e86\u8981\u8f6c\u79fb\u7684\u4ee3\u5e01\u6570\u91cf\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/a132f88d844592f5e25b3c3400280547.jpeg\"> <\/p>\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u5219\u662f\u8fdb\u884c\u63d0\u6b3e\u5956\u52b1\u64cd\u4f5c\uff0c\u6bcf\u6b21\u653b\u51fb\u8005\u8c03\u7528\u8fd9\u9879\u529f\u80fd\u65f6 p.splitData[0] \u90fd\u662f\u4e00\u6837\u7684\uff08\u5b83\u662f p \u7684\u4e00\u4e2a\u5c5e\u6027\uff0c\u5373\u4e00\u4e2a\u56fa\u5b9a\u7684\u503c\uff09\uff0c\u5e76\u4e14 p.splitData[0].totalSupply \u4e0e balances[msg.sender] \u7684\u503c\u7531\u4e8e\u51fd\u6570\u987a\u5e8f\u95ee\u9898\uff0c\u53d1\u751f\u5728\u4e86\u8f6c\u8d26\u64cd\u4f5c\u4e4b\u540e\uff0c\u5e76\u6ca1\u6709\u88ab\u66f4\u65b0\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/263ec02fa4890c037715d32b74ea6efd.jpeg\"> <\/p>\n<p>paidOut[_account] += reward \u66f4\u65b0\u72b6\u6001\u53d8\u91cf\u653e\u5728\u4e86\u95ee\u9898\u4ee3\u7801 payOut \u51fd\u6570\u8c03\u7528\u4e4b\u540e\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/91e0e97490a5d9de4833760bb6e00ed0.jpeg\"> <\/p>\n<p>\u5bf9_recipient \u53d1\u51fa .call.value \u8c03\u7528\uff0c\u8f6c\u8d26_amount \u4e2a Wei\uff0c.call.value \u8c03\u7528\u9ed8\u8ba4\u4f1a\u4f7f\u7528\u5f53\u524d\u5269\u4f59\u7684\u6240\u6709 gas\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/d53a1b8bccb1ba2c86bdf12bd066490d.jpeg\"> <\/p>\n<h5><strong><br \/><\/strong><\/h5>\n<h4><strong>\u89e3\u51b3\u529e\u6cd5<\/strong><\/h4>\n<p><strong><br \/><\/strong> <\/p>\n<p>\u901a\u8fc7\u4e0a\u9762\u5bf9\u91cd\u5165\u653b\u51fb\u7684\u5206\u6790\uff0c\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\u91cd\u5165\u653b\u51fb\u6f0f\u6d1e\u7684\u91cd\u70b9\u5728\u4e8e\u4f7f\u7528\u4e86 fallback \u7b49\u51fd\u6570\u56de\u8c03\u81ea\u5df1\u9020\u6210\u9012\u5f52\u8c03\u7528\u8fdb\u884c\u5faa\u73af\u8f6c\u8d26\u64cd\u4f5c\uff0c\u6240\u4ee5\u9488\u5bf9\u91cd\u5165\u653b\u51fb\u6f0f\u6d1e\u7684\u89e3\u51b3\u529e\u6cd5\u6709\u4ee5\u4e0b\u51e0\u79cd\u3002 <\/p>\n<h6><strong>01<\/strong><strong>\u4f7f\u7528\u5176\u4ed6\u8f6c\u8d26\u51fd\u6570<\/strong><\/h6>\n<p>\u5728\u8fdb\u884c\u4ee5\u592a\u5e01\u8f6c\u8d26\u53d1\u9001\u7ed9\u5916\u90e8\u5730\u5740\u65f6\u4f7f\u7528 Solidity \u5185\u7f6e\u7684 transfer() \u51fd\u6570\uff0c\u56e0\u4e3a transfer() \u8f6c\u8d26\u65f6\u53ea\u4f1a\u53d1\u9001 2300 gas \u8fdb\u884c\u8c03\u7528\uff0c\u8fd9\u5c06\u4e0d\u8db3\u4ee5\u8c03\u7528\u53e6\u4e00\u4efd\u5408\u7ea6\uff0c\u4f7f\u7528 transfer() \u91cd\u5199\u539f\u5408\u7ea6\u7684 withdraw() \u5982\u4e0b\uff1a <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/504ba1c2dafc2f058aee416739be5822.jpeg\"> <\/p>\n<h6><strong>02<\/strong><strong>\u5148\u4fee\u6539\u72b6\u6001\u53d8\u91cf<\/strong><\/h6>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u5c31\u662f\u786e\u4fdd\u72b6\u6001\u53d8\u91cf\u7684\u4fee\u6539\u8981\u65e9\u4e8e\u8f6c\u8d26\u64cd\u4f5c\uff0c\u5373 Solidity \u5b98\u65b9\u63a8\u8350\u7684\u68c0\u67e5-\u751f\u6548-\u4ea4\u4e92\u6a21\u5f0f (checks-effects-interactions)\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/5379e873fbff0d25761d6e9304a2cd74.jpeg\"> <\/p>\n<h6><strong><br \/><\/strong><\/h6>\n<h6><strong>03<\/strong><strong>\u4f7f\u7528\u4e92\u65a5\u9501<\/strong><\/h6>\n<p>\u4e92\u65a5\u9501\u5c31\u662f\u6dfb\u52a0\u4e00\u4e2a\u5728\u4ee3\u7801\u6267\u884c\u8fc7\u7a0b\u4e2d\u9501\u5b9a\u5408\u7ea6\u7684\u72b6\u6001\u53d8\u91cf\u4ee5\u9632\u6b62\u91cd\u5165\u653b\u51fb\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/appserversrc.8btc.com\/post\/96da81ee4b443ce0907a23f07c8cf4b4.jpeg\"> <\/p>\n<h6><strong><br \/><\/strong><\/h6>\n<h6><strong>04<\/strong><strong>\u4f7f\u7528 OpenZeppelin \u5b98\u65b9\u5e93<\/strong><\/h6>\n<p>OpenZeppelin \u5b98\u65b9\u5e93\u4e2d\u6709\u4e00\u4e2a\u4e13\u95e8\u9488\u5bf9\u91cd\u5165\u653b\u51fb\u7684\u5b89\u5168\u5408\u7ea6\uff1a<br \/><em><a href=\"https:\/\/github.com\/OpenZeppelin\/openzeppelin-contracts\/blob\/master\/contracts\/security\/ReentrancyGuard.sol\">https:\/\/github.com\/OpenZeppelin\/openzeppelin-contracts\/blob\/master\/contracts\/security\/ReentrancyGuard.sol<\/a><\/em> <\/p>\n<p>\/\/ SPDX-License-Identifier: MIT<br \/>pragma solidity ^0.8.0;<br \/>\/** * @dev Contract module that helps prevent reentrant calls to a function. * <br \/>* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https:\/\/blog.openzeppelin.com\/reentrancy-after-istanbul\/[Reentrancy After Istanbul]. *\/abstract contract ReentrancyGuard {&nbsp;&nbsp;&nbsp; \/\/ Booleans are more expensive than uint256 or any type that takes up a full&nbsp;&nbsp;&nbsp; \/\/ word because each write operation emits an extra SLOAD to first read the&nbsp;&nbsp;&nbsp; \/\/ slot&#8217;s contents, replace the bits taken up by the boolean, and then write&nbsp;&nbsp;&nbsp; \/\/ back. This is the compiler&#8217;s defense against contract upgrades and&nbsp;&nbsp;&nbsp; \/\/ pointer aliasing, and it cannot be disabled.<br \/>&nbsp;&nbsp;&nbsp; \/\/ The values being non-zero value makes deployment a bit more expensive,&nbsp;&nbsp;&nbsp; \/\/ but in exchange the refund on every call to nonReentrant will be lower in&nbsp;&nbsp;&nbsp; \/\/ amount. Since refunds are capped to a percentage of the total&nbsp;&nbsp;&nbsp; \/\/ transaction&#8217;s gas, it is best to keep them low in cases like this one, to&nbsp;&nbsp;&nbsp; \/\/ increase the likelihood of the full refund coming into effect.&nbsp;&nbsp;&nbsp; uint256 private constant _NOT_ENTERED = 1;&nbsp;&nbsp;&nbsp; uint256 private constant _ENTERED = 2;<br \/>&nbsp;&nbsp;&nbsp; uint256 private _status;<br \/>&nbsp;&nbsp;&nbsp; constructor () {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _status = _NOT_ENTERED;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; \/**&nbsp;&nbsp;&nbsp;&nbsp; * @dev Prevents a contract from calling itself, directly or indirectly.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Calling a `nonReentrant` function from another `nonReentrant`&nbsp;&nbsp;&nbsp;&nbsp; * function is not supported. It is possible to prevent this from happening&nbsp;&nbsp;&nbsp;&nbsp; * by making the `nonReentrant` function external, and make it call a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * `private` function that does the actual work.&nbsp;&nbsp;&nbsp;&nbsp; *\/&nbsp;&nbsp;&nbsp; modifier nonReentrant() {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ On the first call to nonReentrant, _notEntered will be true&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; require(_status != _ENTERED, &#8220;ReentrancyGuard: reentrant call&#8221;);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ Any calls to nonReentrant after this point will fail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _status = _ENTERED;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ By storing the original value once again, a refund is triggered (see&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ https:\/\/eips.ethereum.org\/EIPS\/eip-2200)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _status = _NOT_ENTERED;&nbsp;&nbsp;&nbsp; }} <\/p>\n<p><a href=\"http:\/\/43.153.210.228\/\/wp-content\/uploads\/2021\/06\/270blockchainBTCwww.qkl91.com_.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"\u65f6\u5149\u7d20\u6750-\u9999\u8f66\u7f8e\u5973  (270)blockchainBTC\u6bd4\u7279\u5e01\u533a\u5757\u94fewww.qkl91.com\" style=\"border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline\" border=\"0\" alt=\"\u65f6\u5149\u7d20\u6750-\u9999\u8f66\u7f8e\u5973  (270)blockchainBTC\u6bd4\u7279\u5e01\u533a\u5757\u94fewww.qkl91.com\" src=\"http:\/\/43.153.210.228\/\/wp-content\/uploads\/2021\/06\/270blockchainBTCwww.qkl91.com_thumb.jpg\" width=\"381\" height=\"570\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u521b\u5b87\u533a\u5757\u94fe\u5b89\u5168\u5b9e\u9a8c\u5ba4 \u6c34\u624b 2021-06-03 11:09:47 \u53d1\u5e03\u5728 \u533a\u5757\u94fe\u793e\u533a 2522 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6287","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/43.153.210.228\/index.php?rest_route=\/wp\/v2\/posts\/6287"}],"collection":[{"href":"http:\/\/43.153.210.228\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/43.153.210.228\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/43.153.210.228\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/43.153.210.228\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6287"}],"version-history":[{"count":1,"href":"http:\/\/43.153.210.228\/index.php?rest_route=\/wp\/v2\/posts\/6287\/revisions"}],"predecessor-version":[{"id":6288,"href":"http:\/\/43.153.210.228\/index.php?rest_route=\/wp\/v2\/posts\/6287\/revisions\/6288"}],"wp:attachment":[{"href":"http:\/\/43.153.210.228\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/43.153.210.228\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6287"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/43.153.210.228\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}