# Analysis of Smart Contract Security Vulnerabilities and Tools       <br/>    <br/>  <br/>  ## SOLIDITY_REVERT_REQUIRE ### Rule Description <p>Using the construction <code>if (condition) {revert();}</code> instead of <code>require(condition);</code></p> ### Solidity-Rules   ``` ifStatement[statement[not(descendant::ifStatement)]//throwRevertStatement] ``` ### Sample Code ``` contract f{ function a(){ // <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12 if (x>y) { revert(); } } modifier atStage(Stages _stage) { // <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12 if (stage != _stage) revert(); _; } } contract f{ function a(){ // <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12 if (x>y) { throw; } if (tokensToSend > 0) { allocatedTokens -= tokensToSend; // <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12 if (!token.issue(msg.sender, tokensToSend)) { revert(); } } if (ethToSend > 0) { allocatedEth -= ethToSend; // <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12 if (!msg.sender.send(ethToSend)) { revert(); } } if (stage == Stages.PresaleStarted) { buyPresale(receiver); } // <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12 else if (stage == Stages.MainSaleStarted) { buyMainSale(receiver); } else { revert(); } // <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12 if(!ico_ended) { eth_received = Add(eth_received, msg.value); } else { revert(); } } } ``` ### Abstract Syntax Tree [Click Here](https://astexplorer.net/#/gist/aa0b52bca154c4266d720f6ed8b0abd5/c89a3def722472c09a5b696db1888775e031aeb2) to view the AST for the above code. Code generated from AST Explorer using _solidity-parser-antlr-0.4.11_ ### Code Result ``` SOLIDITY_DEPRECATED_CONSTRUCTIONS patternId: 49bd2a severity: 1 line: 16 column: 19 content: throw ruleId: SOLIDITY_REVERT_REQUIRE patternId: c56b12 severity: 1 line: 4 column: 8 content: if(x>y){revert();} ruleId: SOLIDITY_REVERT_REQUIRE patternId: c56b12 severity: 1 line: 8 column: 8 content: if(stage!=_stage)revert(); ruleId: SOLIDITY_REVERT_REQUIRE patternId: c56b12 severity: 1 line: 16 column: 8 content: if(x>y){throw;} ruleId: SOLIDITY_REVERT_REQUIRE patternId: c56b12 severity: 1 line: 20 column: 12 content: if(!token.issue(msg.sender,tokensToSend)){revert();} ruleId: SOLIDITY_REVERT_REQUIRE patternId: c56b12 severity: 1 line: 27 column: 12 content: if(!msg.sender.send(ethToSend)){revert();} ruleId: SOLIDITY_REVERT_REQUIRE patternId: c56b12 severity: 1 line: 35 column: 13 content: if(stage==Stages.MainSaleStarted){buyMainSale(receiver);}else{revert();} ruleId: SOLIDITY_REVERT_REQUIRE patternId: c56b12 severity: 1 line: 41 column: 8 content: if(!ico_ended){eth_received=Add(eth_received,msg.value);}else{revert();} ruleId: SOLIDITY_SEND patternId: 430636 severity: 1 line: 27 column: 28 content: send(ethToSend) ruleId: SOLIDITY_VISIBILITY patternId: 910067 severity: 1 line: 2 column: 4 content: functiona(){if(x>y){revert();}} ruleId: SOLIDITY_VISIBILITY patternId: 910067 severity: 1 line: 14 column: 4 content: functiona(){if(x>y){throw;}if(tokensToSend>0){allocatedTokens-=tokensToSend;if(!token.issue(msg.sender,tokensToSend)){revert();}}if(ethToSend>0){allocatedEth-=ethToSend;if(!msg.sender.send(ethToSend)){revert();}}if(stage==Stages.PresaleStarted){buyPresale(receiver);}elseif(stage==Stages.MainSaleStarted){buyMainSale(receiver);}else{revert();}if(!ico_ended){eth_received=Add(eth_received,msg.value);}else{revert();}} SOLIDITY_VISIBILITY :2 SOLIDITY_DEPRECATED_CONSTRUCTIONS :1 SOLIDITY_REVERT_REQUIRE :7 SOLIDITY_SEND :1 ```