diff --git a/Tools/SmartCheck/Solidity/Rules/SOLIDITY_SAFEMATH.md b/Tools/SmartCheck/Solidity/Rules/SOLIDITY_SAFEMATH.md new file mode 100644 index 0000000000000000000000000000000000000000..10e61552d631afb7ef168982be980e9052f9ab6a --- /dev/null +++ b/Tools/SmartCheck/Solidity/Rules/SOLIDITY_SAFEMATH.md @@ -0,0 +1,60 @@ +# Analysis of Smart Contract Security Vulnerabilities and Tools  +     <br/>    <br/> + <br/> + + +## SOLIDITY_SAFEMATH +### Rule Description +<p> + <code>SafeMath</code> library is used. +</p> + +### Solidity-Rules + +  + +``` +usingForDeclaration[identifier[matches(text()[1], "^SafeMath$", "i")]] +``` + +### Sample Code + +``` +pragma solidity 0.4.24; + +library SafeMath { + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } +} + +contract MyToken { + // <yes> <report> SOLIDITY_SAFEMATH 837cac + using SafeMath for uint256; + + function sub(uint a, uint b) public returns(uint) { + return(a.sub(b)); + } +} +``` + +### Abstract Syntax Tree + +[Click Here](https://astexplorer.net/#/gist/6d119342ef1d67adbea057d4787442cd/3e3ec2fdbe24bb0b1ae2d58e1a9a3b7465dd0f69) to view the AST for the above code. Code generated from AST Explorer using _solidity-parser-antlr-0.4.11_ + + +### Code Result + +``` +SOLIDITY_SAFEMATH +patternId: 837cac +severity: 1 +line: 12 +column: 4 +content: usingSafeMathforuint256; + +SOLIDITY_SAFEMATH :1 + + +```