´ÓsolidityÓïÑÔÌØÕ÷Éî¶È½â¶ÁÒÔÌ«·»ÖÇÄܺÏÔ¼Îó²îÔÀíºÍ¹¥»÷ʹÓÃ
Ðû²¼Ê±¼ä 2018-08-02Ëæ×ÅÇø¿éÁ´¡¢ÒÔÌ«·»ÊÖÒÕµÄÐËÆðºÍÒ»Ö±³ÉÊ죬Çå¾²ÎÊÌâÒ²ËæÖ®¶øÀ´£¬½ñÄêÖÇÄܺÏÔ¼Îó²îÒѾÈöà¸öÇø¿éÁ´ÏîÄ¿¼Ûֵ˲¼ä¹éÁã¡£ÖÇÄܺÏÔ¼µÄ¿ª·¢ÓïÑÔ¡¢Éè¼Æģʽ¡¢ÔËÐлúÖƶ¼Óë¹Å°åÓ¦ÓÃÓнϴó²î±ð£¬Ëü¼ÈÓйŰåµÄÇ徲Σº¦(ÈçÕûÊýÒç³öµÈ)£¬ÓÖÓÐÆæÒìµÄÐÂÐÍΣº¦(Èç˽ÓбäÁ¿²»¡°Ë½ÓС±ºÍÌØÊâÀàÐͱäÁ¿ÁýÕÖµÈ)¡£Ñз¢Ö°Ô±ÈôÊDz»¿ÉÉî¿ÌÃ÷È·ÕâЩ½¹µãÔÀí£¬ÔòºÜÈÝÒ×±àд³ö±£´æÎó²îµÄÖÇÄܺÏÔ¼£»¶ñÒâºÏÔ¼Ò²¿ÉÒÔͨ¹ýÕâÖÖÒªÁìÁôÏÂÒþ²ØÎó²î£¬ÓÕƺÏԼͶ×ÊÈ˲¢°µµØÀïÊո±¾ÎÄÒÔWCTF2018µÄÒ»µÀÖÇÄܺÏÔ¼Îó²îÈüÌâ[1]ΪÀý£¬´ÓsolidityÓïÑÔÌØÕ÷³ö·¢£¬Éî¶È½â¶ÁÒÔÌ«·»ÖÇÄܺÏÔ¼Îó²îÔÀíºÍ¹¥»÷ʹÓá£
2 Îó²îºÏÔ¼ÆÊÎö
¸ÃºÏÔ¼ÊÇÒ»¸öÒøÐÐÀàºÏÔ¼£¬Óû§¿ÉÒÔ´æÈëethµ½¸ÃºÏÔ¼£¬²¢ÔÚ´æÈëµ½ÆÚÖ®ºóÈ¡³ö¡£ÔÌâ¶Ô¸ÃºÏÔ¼ÐÎòÈçÏ£º

¸ÃºÏÔ¼Öб£´æÎó²î£¬¹¥»÷ÕßʹÓÃÎó²î¿ÉÒÔ͵ȡºÏÔ¼ÖеÄËùÓÐÓà¶î¡£Îó²îÉæ¼°µ½ÕûÊýÒç³ö¡¢±äÁ¿ÁýÕÖÒÔ¼°ÓɱäÁ¿ÁýÕÖµ¼ÖµıäÁ¿Ï໥ӰÏì¡£
ºÏÔ¼Ô´ÂëÈçÏ£º

ÒªÌáÈ¡ºÏÔ¼µÄËùÓкÏÔ¼Óà¶î£¬confiscate º¯ÊýÊÇÒªº¦£¬µ«¸Ãº¯ÊýŲÓÃÀֳɱØÐèÖª×㣺
? msg.sender == owner
? secret == _secret
? now >= balances[account].deposit_term + 1 years
¹¥»÷Õß¿ÉÒÔͨ¹ýºÏÔ¼´æ´¢»á¼û¡¢ÕûÊýÒç³öºÍ±äÁ¿ÁýÕÖÀ´ÒÀ´Î½á¹¹ÉÏÊöÌõ¼þ¡£
2.1 solidityÈ«¾Ö±äÁ¿´æ´¢
ÔÚBelluminarBankºÏÔ¼ÖУ¬Ò»¹²ÓÐ4¸öÈ«¾Ö±äÁ¿£¬»®·ÖÊÇbalances¡¢head¡¢owner¡¢secrete¡£ËüÃǵÄĬÈÏ»á¼ûÊôÐÔÊÇprivate£¬¿´ÉÏÈ¥Ö»ÓкÏÔ¼×Ô¼ºÄܹ»»á¼ûÕâЩ±äÁ¿¡£ÊÂʵÉÏ£¬ºÏÔ¼µÄËùÓбäÁ¿Êý¾Ý¶¼ÊǹûÕæ´æ´¢ÔÚÁ´ÉϵÄÇø¿éÖУ¬ÈκÎÈ˶¼¿ÉÒÔͨ¹ý»á¼û´æ´¢Êý¾ÝÀ´»ñµÃÕâЩ±äÁ¿µÄÖµ[2]¡£ÔÚsolidityÓïÑÔÖУ¬È«¾Ö±äÁ¿¶¼´æ´¢ÔÚstorageÖУ¬Æ¾Ö¤solidityµÄ±äÁ¿´æ´¢¹æÔò£¬¶¨³¤µÄ±äÁ¿ÔÚstorageÖÐÊÇ˳Ðò´æ´¢µÄ£¬Êý×é±äÁ¿ÔÚstorageÖÐÆäË÷ÒýλÖôæ·ÅµÄÊÇÆäÊý×鳤¶È£¨°Ý¼û[3]£©¡£¸ÃºÏÔ¼storageÖеıäÁ¿´æ´¢½á¹¹ÈçÏ£º
Òò´Ë£¬secrete²¢²»ÊÇÒ»¸ö²»¿É»ñÈ¡µÄ˽ÓÐÊý¾Ý£¬¹¥»÷ÕßÖ»ÐèÒª»á¼û¸ÃºÏÔ¼storageÖеÄÊý¾Ý¾Í¿ÉÒԽṹconfiscate º¯ÊýµÄsecret == _secretÌõ¼þ¡£
2.2 solidityÈ«¾Ö±äÁ¿ÁýÕÖ
BelluminarBankºÏÔ¼ÖеÄconfiscateº¯ÊýÒªÇóŲÓÃÕß±ØÐèÊǺÏÔ¼ÓµÓÐÕ߲ſÉÒÔ¾ÙÐÐÓà¶îÌáÈ¡²Ù×÷£¬¿´ÉÏÈ¥¹¥»÷ÕßÊÇÎÞ·¨ÌáÈ¡µÄ¡£È»¶ø£¬ÓÉÓÚsolidityÓïÑԵľֲ¿±äÁ¿´æ´¢ÌØÕ÷£¬µ¼Ö±¾ºÏÔ¼µÄowner±äÁ¿¿ÉÒÔ±»Ð޸ģ¬ÁýÕÖÎÊÌâ·ºÆðÔÚ invest º¯ÊýÖС£
Ê×ÏÈÀ´¿´solidity¾Ö²¿±äÁ¿ÁýÕÖÈ«¾ÖstorageµÄÎÊÌâ¡£solidityÓïÑԵıäÁ¿´æ´¢ÓÐÒ»¸öÌØÕ÷£¬¼´Êý×é¡¢Ó³Éä¡¢½á¹¹ÌåÀàÐ͵ľֲ¿±äÁ¿Ä¬ÈÏÊÇÒýÓúÏÔ¼µÄstorage [4]£¬¶øÈ«¾Ö±äÁ¿Ä¬ÈÏ´æ´¢ÔÚstorageÖС£Òò´Ë£¬ÈôÊÇÕâЩ¾Ö²¿±äÁ¿Î´±»³õʼ»¯£¬ÔòËüÃǽ«Ö±½ÓÖ¸Ïòstorage£¬ÐÞ¸ÄÕâЩ±äÁ¿¾ÍÊÇÔÚÐÞ¸ÄÈ«¾Ö±äÁ¿¡£
ÒÔÈçϵļòÆÓºÏÔ¼testΪÀý£¬º¯Êýtest1Öнç˵ÁËÒ»¸ö¾Ö²¿½á¹¹Ìå±äÁ¿x£¬¿ÉÊÇûÓжÔÆä¾ÙÐгõʼ»¯¡£Æ¾Ö¤solidityµÄ±äÁ¿´æ´¢¹æÔò£¬Õâʱ¼äxÊÇ´æ´¢ÔÚstorageÖеģ¬²¢ÇÒÊÇ´ÓË÷Òý0×îÏÈ£¬ÄÇô¶ÔÆä³ÉÔ±±äÁ¿x,y¸³ÖµÖ®ºó£¬Ç¡Ç¡ÁýÕÖÁËÈ«¾Ö±äÁ¿aºÍb¡£ÓÐÐËȤ¿ÉÒÔÔÚ remix ÖÐÔÚÏ߶Ա¾ºÏÔ¼¾ÙÐе÷ÊÔ¡£
pragma solidity 0.4.24;
contract test {
struct aa{
uint x;
uint y;
}
uint public a = 4;
uint public b = 6;
function test1() returns (uint){
aa x;
x.x = 9;
x.y = 7;
}
}
ÔÚinvestº¯ÊýµÄelse·ÖÖ§ÖУ¬Ê¹ÓÃÁËÒ»¸ö¾Ö²¿½á¹¹±äÁ¿investment¡£¸Ã¾Ö²¿±äÁ¿ÔÚÄ¿½ñÖ´ÐзÖÖ§Öв¢Ã»Óб»³õʼ»¯£¬Ä¬ÈÏÖ¸ÏòºÏÔ¼µÄstorage¡£Ö´ÐÐÖжԸñäÁ¿µÄ³ÉÔ±¸³Öµ¾Í»áÖ±½ÓÁýÕÖÈ«¾Ö±äÁ¿£¬ÁýÕÖ¹ØϵΪ£º

ͬʱ£¬ÔÚ±äÁ¿ÁýÕÖ֮ǰ±ØÐèÖª×ãÈçÏÂÌõ¼þ£¬¼´´æ¿îÏÞÆÚÊÇ×îÄ©Ò»¸ö´æ¿î¼Í¼µÄÏÞÆÚºóÒ»Ä꣺deposit_term >= balances[balances.length - 1].deposit_term + 1 years¡£ÓÉÓÚdeposit_termÊÇÓû§ÌṩµÄ£¬ÇáËɾͿÉÒÔÖª×ã¡£
ÒÔÊÇ£¬Í¨¹ýÈ«ÐĽṹinvestº¯ÊýµÄ²ÎÊý¾Í¿ÉÒÔÁýÕÖstroageÖеÄsender£¬´Ó¶ø¸Ä±ä¸ÃºÏÔ¼µÄÓµÓÐÕßΪ¹¥»÷Õߣ¬Í»ÆÆconfiscate º¯ÊýµÄmsg.sender == ownerÏÞÖÆ¡£
2.3 ÕûÊýÒç³ö
ÔÚBelluminarBankºÏÔ¼Ô´ÂëµÄconfiscateº¯ÊýÉÐÓÐÁíÍâÒ»¸öÈçϵÄʱ¼äÏÞÖÆ£¬¼´±ØÐèÔÚ´æ¿îÂúÒ»Äêºó²Å»ªÌáÈ¡£¬now >= balances[account].deposit_term + 1 years¡£
ÉÏÒ»½ÚÓÃÓÚÈ«¾Ö±äÁ¿ÁýÕֵĴæ¿î²Ù×÷ʹµÃbalancesÖÐ×îÄ©Ò»¸ö´æ´¢¼Í¼µÄÏÞÆÚÒѾÊÇ1Äêºó£¬¼´¹¥»÷ÕßÖÁÉÙÔÚ2Äêºó²Å»ªÅ²ÓÃconfiscateº¯Êý¾ÙÐÐÌá¿î¡£Óë´Ëͬʱ£¬deposit_termÔÚ¸³Öµ¸ø¾Ö²¿±äÁ¿µÄʱ¼ä»á°ÑÈ«¾Ö±äÁ¿headÁýÕÖΪ³¬´óµÄÊý£¬ÕâҲʹµÃºóÐøµÄfor (uint256 i = head; i <= account; i++)Ñ»·´¦Öóͷ£ÎÞ·¨ÌáÈ¡ËùÓеĴæ¿î£¬ÓÉÓÚhead²»Îª0¡£
ÏÔÈ»£¬±ØÐè°ÑheadÁýÕÖΪ0²Å»ªÌáÈ¡ËùÓеĴæ¿î£¬¼´investº¯ÊýµÄdeposit_term²ÎÊý±ØÐèΪ0¡£µ«ÈôÊǸòÎÊýΪ0£¬ÓÖÎÞ·¨Öª×ãinvestº¯ÊýµÄÈ«¾Ö±äÁ¿ÁýÕÖÖ´ÐеÄÌõ¼þdeposit_term >= balances[balances.length - 1].deposit_term + 1 years¡£
×ÐϸÆÊÎö¿É·¢Ã÷£¬ÈôÊÇbalances[balances.length - 1].deposit_term+ 1 yearsÇ¡Ç¡¼´ÊÇ0£¬ÔòÉÏÊöµÄÌõ¼þºãΪÕæ¡£ÏÔÈ»£¬balances[balances.length - 1].deposit_termֻҪȡֵΪ(uint256_max ¨C 1 years + 1)£¬¾Í»áµ¼ÖÂÏà¼ÓºóµÄֵΪuint256_max+1¡£Õâ¸öЧ¹û»áÁè¼Ýuint256µÄ±í´ï¿Õ¼ä£¬±¬·¢Òç³öµ¼ÖÂ×îºóµÄֵΪ0¡£
Òò´Ë£¬¹¥»÷ÕßÏÈ×öµÚÒ»´Î´æ¿î£¬°Ñbalances×îºóÒ»ÏîµÄdeposit_termÉèÖÃΪÌØÊâÖµ£»È»ºó×öµÚ¶þ´Î´æ¿î£¬deposit_term´«Èë0Öµ£¬¾ÍÄÜ´¥·¢ÕûÊýÒç³ö£¬Èƹý±äÁ¿ÁýÕÖÌõ¼þÏÞÖƲ¢ÐÞ¸ÄheadΪ0Öµ¡£
2.4 ¡°±äÁ¿¾À²ø¡±µÄ¸±×÷ÓÃ
ÔÚÈ«¾Ö±äÁ¿ÁýÕÖÖУ¬ºÜÈÝÒ×±¬·¢¡°±äÁ¿¾À²ø¡±Õ÷Ï󣬴Ӷø´¥·¢Ò»Ð©ÈÝÒ×±»ºöÊӵĸ±×÷Óá£ÕâÀïÒÔÒ»¸ö¼òÆÓºÏÔ¼testΪÀý£¬º¯ÊýtestArrayÖÐÒÀÈ»±£´æ½á¹¹Ìå¾Ö²¿±äÁ¿aÁýÕÖÈ«¾Ö±äÁ¿xµÄÇéÐΡ£µ«ÓÉÓÚxÊÇÊý×é±äÁ¿£¬ÆäÖ±½ÓË÷ÒýµÄstorage´æ´¢Î»Öýö´æ´¢ÆäÊý×鳤¶È£¬Ò²¾ÍÊÇa.xÖ»»áÁýÕÖxµÄÊý¾Ý³¤¶È£¬¶øa.y½«ÁýÕÖ±äÁ¿num¡£
ÔÚtestArrayº¯ÊýÖУ¬¸³Öµ²Ù×÷a.x = 5ʱ£¬ÓÉÓÚx.lengthÓë±äÁ¿a.x´¦ÓÚͳһ´æ´¢Î»Ö㬸³ÖµºóÊý×éxµÄ³¤¶ÈÄð³ÉÁË5¡£½ÓÏÂÀ´£¬¸³Öµa.y£¬²¢½«±äÁ¿a¼ÓÈëµ½Êý×éx¡£ÒÔÊDZäÁ¿aÏÖʵÉϼÓÈëµ½ÁËÊý×éxË÷ÒýΪ5µÄλÖá£ÈôÊǵ÷ÊÔtestArrayº¯ÊýÖ´ÐУ¬»á·¢Ã÷ÔÚº¯ÊýÖ´ÐÐÍê±ÏÖ®ºó£¬x[5].x = 6, x[5].y = 7¡£
ÕâÊÇΪʲôÄØ£¿ÏÔ×Å´úÂëÖи³ÖµÐ´µÄÊÇ a.x = 5£¬a.y = 7¡£Õâ¾ÍÊÇÈ«¾Ö±äÁ¿xºÍ¾Ö²¿±äÁ¿aÐγÉÁË¡°¾À²ø¡±£¬Ê×ÏÈÊǾֲ¿±äÁ¿aÐ޸ĵ¼ÖÂÈ«¾Ö±äÁ¿x¸Ä±ä£¬È»ºóÊÇÈ«¾Ö±äÁ¿xÐ޸ĵ¼ÖÂϳ¡²¿±äÁ¿Ð޸ģ¬×îºó°ÑÐ޸ĺóµÄ¾Ö²¿±äÁ¿ÓÖ´æ´¢µ½Ð޸ĺóµÄÈ«¾Ö±äÁ¿¡£ÕâÀï¼´ÊÇ£¬¸³Öµ²Ù×÷a.x = 5ʱ£¬°ÑÊý×éxµÄ³¤¶ÈÄð³ÉÁË5; ½ÓÏÂÀ´x.push²Ù×÷£¬ÏÖʵÉÏÊÇÏȽ«¸ÃÊý×éxµÄ³¤¶È¼Ó1£¬´Ëʱa.x = 6; ×îºóÔÙ°Ña.x = 6, a.y=7¼ÓÈëµ½x[5]¡£ÒÔÊÇ£¬´æÈëÊý¾ÝµÄx¾ÍÊÇÐÂÊý×éµÄ³¤¶È6¡£
pragma solidity 0.4.24;
contract test {
struct aa{
uint x;
uint y;
}
aa [] x;
uint public num = 4;
function testArray() returns (uint){
aa a;
a.x = 5;
a.y = 7;
x.push(a);
}
}
3 Îó²îʹÓ÷½·¨
ÔÚµÚ2½ÚÖжԺÏÔ¼ BelluminarBank±£´æµÄ¼¸¸öÎó²î¾ÙÐÐÁËÆÊÎö£¬ÏÂÃ潫˵Ã÷ÔõÑùʹÓÃÕâ¸öÎó²îÌáÈ¡ºÏÔ¼µÄËùÓÐÓà¶î£¬ÕâÀïÔÚRemixÔÚÏß±àÒëÇéÐÎÖа²ÅŸúÏÔ¼£¬²¢ÑÝʾÆäʹÓ÷½·¨¡£
Ê×ÏÈ°²ÅźÏÔ¼£¬ÔÚ°²ÅŲÎÊýÖÐÉèÖÃsecrete Ϊ¡°0x01¡±£¬deposit_termΪ1000£¬msg.valueΪ 31337 wei¡£
°²ÅźÏÔ¼ºó£¬ºÏÔ¼µÄÈ«¾Ö±äÁ¿ÈçÏÂͼËùʾ£º

ÕâÑù£¬ºÏÔ¼ÏÖÔÚµÄÓà¶îÊÇ 31337 wei£¬ºÏÔ¼ÓµÓÐÕߵĵصãΪ£º0xca35b7d915458ef54 0ade6068dfe2f44e8fa733c¡£
ÏÂÃæ×îÏÈÐèÒª½á¹¹Ìõ¼þʹµÃ¹¥»÷Õß¿ÉÒÔÀÖ³ÉŲÓÃconfiscateº¯Êý¡£
°ì·¨1: ÁýÕÖowner²¢½á¹¹ÕûÊýÒç³öÌõ¼þ
ÒªÏëת×ߺÏÔ¼Óà¶î£¬Ê×ÏȱØÐèÐ޸ĺÏÔ¼µÄowner¡£Ê¹Óþֲ¿½á¹¹Ìå investment Ð޸ĺÏÔ¼owner£¬ÐèÖª×ãÌõ¼þ£º
£¨1£©account < head or account >= balances.length
£¨2£©deposit_term >= balances[balances.length ¨C 1].deposit_term + 1 years
ÉèÖù¥»÷Õߣ¨0x1472¡160C£©µÄinvestŲÓòÎÊýÈçÏ£º
? msg.value = 1 wei (ÓÉÓÚÔÚºÏÔ¼³õʼ»¯Ê±ownerÒѾ´æÈëÒ»±Ê½ð¶î£¬ÒÔÊÇ´ËʱbalancesÊý×鳤¶ÈΪ1£¬ÎªÁ˲»¸Ä±äbalancesÊý×鳤¶È£¬ÕâÀïÒÀÈ»½«ÆäÉèÖÃΪ1 we i
? depositsit_term = 2^256 - 1 years = 115792089237316195423570985008687907853269984665640564039457584007913098103936 £¨ÔÚ°ì·¨2ÖÐÐèҪʹÓÃÕâ¸öÊýÖµ½á¹¹Òç³ö£¬Í¬Ê±Õâ¸öÖµ¿ÉÒÔʹԴÂëÖÐ require Ìõ¼þ»ñµÃÖª×㣩
? account = 1 (Öª×ãÌõ¼þ account >= balances.length)
ŲÓÃÖ®ºó£¬ÐµĴæ¿î¼Í¼Êý¾Ý½«´æ·ÅÔÚbalancesÊý×éË÷ÒýΪ1µÄλÖᣴËʱµÄbalancesÊý×éÇéÐκÍÈ«¾Östorage±äÁ¿ÇéÐÎÈçÏÂͼËùʾ¡£

¿ÉÒÔ·¢Ã÷£¬ownerÒѾÐÞ¸ÄΪ¹¥»÷Õߵص㣬ͬʱhead±»´«ÈëµÄdeposit_termÁýÕÖΪһ¸ö³¬´óÖµ¡£
¶øÌáÈ¡Óà¶îÊÇ´ÓbalancesÊý×éÖÐheadË÷Òý×îÏȵĴæ¿î¼Í¼×îÏÈÅÌËãÊý¶îµÄ¡£ÏÔÈ»£¬ÎªÁËÌáÈ¡µ½ºÏÔ¼ownerµÄÓà¶î£¬¼´balances[0]ÕË»§µÄÓà¶î£¬head±ØÐè±»ÁýÕÖΪ0¡£Òò´Ë£¬ÐèÒª¾ÙÐеڶþ´Îstorage±äÁ¿ÁýÕÖ£¬ÐÞ¸Ähead¡£
°ì·¨2: »Ö¸´head²¢Èƹýdeposit_termÏÞÖÆ
¼ÌÐøÉèÖù¥»÷ÕßŲÓÃinvestµÄ²ÎÊý£º
? msg.value = 2wei (ͬÑù°ü¹ÜbalancesµÄ³¤¶ÈÁýÕÖºó²»·ºÆð¹ýʧ)
? deposit_term = 0: »Ö¸´head
? account = 2 (Öª×ãÌõ¼þ account >= balances.length ¼´¿É)
ÓÉÓÚÔÚ°ì·¨ 1 ÖУ¬ÒѾ½«balances[1].deposit_term ÉèÖÃΪ 2^256 -1 years£¬Òò´ËÔÚµÚ¶þ´ÎŲÓà invest º¯Êýʱ£¬ÓÉÓÚbalances[balances.length - 1].deposit_term + 1 years¡±Òç³öΪ0Öª×ãÁËrequireÌõ¼þ£¬ÒÔÊÇ¿ÉÒÔÀֳɾÙÐеڶþ´ÎÁýÕÖ¡£
ÕâÑù¼´Öª×ãÁËŲÓÃconfiscateº¯ÊýµÄÌõ¼þmsg.sender == owner£¬Í¨¹ý¶ÁÈ¡storageºÜÈÝÒ×»ñµÃsecrete£¬Ìõ¼þsecret == _secret Ò²¿ÉÒÔÖª×㣬ͬʱ»¹ÖØÐÂÁýÕÖÁËheadʹ֮±äΪ0 ¡£
ÁýÕÖÖ®ºóÈ«¾Östorage±äÁ¿ºÍbalancesÊý×éÈçÏÂͼËùʾ£º

¿ÉÒÔ·¢Ã÷headÒѾÐÞ¸ÄΪ0ÁË¡£
ÏÖÔÚÀ´¿´¿´µÚÈý¸öÌõ¼þ£º
now >= balances[account].deposit_term + 1 years
accountÊÇ´«ÈëµÄÊý¾Ý£¬ÏÖÔÚºÏÔ¼ÖÐaccountÊýĿΪ3¡£ÔÚÇ°ÃæµÄinvestŲÓÃºó£¬ balances[2].deposit_term = 0¡£ ÏÔÈ»Ìõ¼þ now >= balances[2].deposit_term + 1 years ½¨É裬ÒÔÊÇÔÚ»Ö¸´headÊý¾ÝµÄͬʱ£¬Ò²ÈƹýÁËconfiscateº¯ÊýÖйØÓÚ´æ¿îÏÞÆÚµÄÅжϡ£½ÓÏÂÀ´Ö»ÒªÅ²Óú¯Êýconfiscateʱ£¬ÉèÖÃaccount Ϊ 2£¬±ã¿Éʹʱ¼äÅжÏÌõ¼þÖª×㣬ͬʱҲÄÜÌáÈ¡ËùÓÐÕË»§µÄÓà¶î¡£
°ì·¨3: ÔöÌíºÏÔ¼Óà¶î
¾ÓÉ°ì·¨1ºÍ°ì·¨2£¬Ëƺõ¹¥»÷ÕßÒѾ¿ÉÒÔŲÓÃconfiscateº¯ÊýÌáÈ¡ËùÓÐÓà¶îÁË£¬È»¶øÏÖʵÉÏÊDz»¿ÉµÄ¡£ÉúÒâ»á±¬·¢»Ø¹ö£¬ÕâÊÇΪʲôÄØ£¿
×ÐϸÆÊÎöÇ°ÃæµÄÊý¾Ý¾Í»á·¢Ã÷£¬°ì·¨1ÖÐmsg.valueΪ 1 wei£¬¿ÉÊÇ×îºóbalancesÊý×éÖеÄbalances[1].amount È´Äð³ÉÁË 2 wei¡£ÕâÊÇÓÉÓÚ±äÁ¿ÁýÕÖÀú³ÌÖб¬·¢ÁË¡°¾À²ø¡±¸±×÷Óã¬ÓÉÓÚmsg.valueÁýÕÖbalancesÊý×éµÄ³¤¶È£¬balances¸üÐÂÇ°ÔöÌíÁËÊý×鳤¶È£¬Êý×鳤¶ÈÓָıäÁËmsg.value£¬×îºóµ¼Ö´æÈëµÄamountÄð³ÉÁËеÄÊý×鳤¶È£¬¼´2¡£
ÒÔÊÇ£¬Ã¿´ÎŲÓÃinvestº¯Êý¾ÙÐбäÁ¿ÁýÕÖ£¬´æ¿î¼Í¼µÄÕËÄ¿½ð¶î¶¼±ÈŲÓÃÕßÏÖʵ֧¸¶µÄmsg.value´ó¡£ÏÂͼÊÇÁ½´ÎŲÓÃinvestÖ®ºóµÄbalancesÊý×éÇéÐΡ£

´ÓͼÖпÉÒÔ¿´³ö£¬´æ¿î¼Í¼ÖеÄÕËÃæÖµ»á±ÈÏÖʵÉúÒâµÄmsg.value¶à 1 wei¡£Í¨¹ýconfiscateº¯ÊýÅÌËã»ñµÃµÄËùÓÐÕË»§×ܶîΪ31342 wei£¬¶øÏÖʵµÄºÏÔ¼ÕË»§×ÜÓà¶îΪ 31340 wei¡£

ΪÁËÄܹ»½«ºÏÔ¼ÖÐËùÓÐÓà¶îÌáÈ¡³öÀ´£¬ÐèÒªÔöÌíºÏÔ¼µÄÕæʵÓà¶î£¬Ê¹Æäͬ´æ¿î¼Í¼ÖеÄÓà¶îÏàµÈ¡£È»¶ø£¬Í¨¹ýinvest·½·¨ÔöÌíµÄÓà¶î¶¼»á±»¼ÆÈëÕËÃæÓà¶î£¬ÄÇôÔõôÔÚÇ·ºà¹ýinvestº¯ÊýµÄÇéÐÎÏÂÔöÌíºÏÔ¼µÄÕæʵÓà¶îÄØ£¿
ÃÕµ×ÊÇselfdestructº¯Êý¡£
selfdestructº¯Êý»á½«¸ÃºÏÔ¼µÄÓà¶îתµ½Ö¸¶¨ÕË»§£¬È»ºó´ÓÇø¿éÁ´ÖÐÏú»Ù¸ÃºÏÔ¼µÄ´úÂëºÍstorage¡£¸Ãº¯ÊýµÄ¹Ù·½ÎĵµËµÃ÷[5]ÈçÏ£º

Òò´Ë£¬¿ÉÒԽṹһ¸öºÏÔ¼£¬È»ºóÔÚºÏÔ¼ÖÐŲÓÃselfdestructº¯Êý½«ºÏÔ¼µÄÓà¶îת¸øBelluminarBankºÏÔ¼¡£Îª´Ë£¬½á¹¹ÈçϺÏÔ¼£º
contract donar{
function donar() public payable{
selfdestruct(contractAddr);
}
}
¸ÃºÏÔ¼½¨ÉèºóÂíÉÏÏú»Ù£¬Í¬Ê±½«×Ô¼ºµÄÓà¶îת¸øÒøÐкÏÔ¼¡£
ÔÚ remix ÖÐ ±àÒë¸ÃºÏÔ¼£¬Í¬Ê±½« contractAddrÌ滻ΪÒøÐкÏÔ¼µØµã¡£È»ºó ÔÚdeploy¸ÃºÏԼʱ£¬ÉèÖà msg.value Ϊ2 wei¡£µ±ºÏÔ¼½¨ÉèÓÖÏú»ÙÖ®ºó£¬ÆäÓà¶î£¨2wei£©½«×ª¸øÒøÐÐÕË»§£¬Ê¹ÒøÐкÏÔ¼µÄÕËÃæÓà¶îºÍÏÖʵÓà¶îÒ»Ö£¬ÕâÑùconfiscateº¯ÊýŲÓþÍÄܹ»×¼È·Ö´ÐС£
DonarºÏÔ¼°²ÅÅÉèÖÃÈçÏ£º

ºÏÔ¼°²ÅÅÍêÖ®ºó£¬BelluminarBank ºÏÔ¼Óà¶îÈçÏÂͼ£º

°ì·¨4£ºÅ²ÓÃconfiscateÌáÈ¡ºÏÔ¼Óà¶î
¾ÓÉÉÏÃæµÄ²Ù×÷Ö®ºó£¬ÉèÖÃconfiscateº¯ÊýµÄ²ÎÊýΪ[2£¬¡°0x01¡±]¼´¿É½«ºÏÔ¼µÄËùÓÐÓà¶îת×ß¡£
²Î¿¼Á´½Ó£º
¡¾1¡¿https://github.com/beched/ctf/tree/master/2018/wctf-belluminar
¡¾2¡¿https://solidity.readthedocs.io/en/v0.4.24/security-considerations.html#private-information-and-randomness
¡¾3¡¿https://medium.com/aigang-network/how-to-read-ethereum-contract-storage-44252c8af925
¡¾4¡¿ http://solidity.readthedocs.io/en/v0.4.24/frequently-asked-questions.html
¡¾5¡¿https://solidity.readthedocs.io/en/v0.4.24/introduction-to-smart-contracts.html?highlight=selfdestruct