From f3d9b31a1a40700399ad0195ff4ac6123d0891bf Mon Sep 17 00:00:00 2001 From: POTHURI HARIKA <cb.en.p2cys21018@cb.students.amrita.edu> Date: Thu, 15 Jun 2023 12:25:40 +0530 Subject: [PATCH] Upload New File --- .../Solidity/Rules/SOLIDITY_SAFEMATH.md | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Tools/SmartCheck/Solidity/Rules/SOLIDITY_SAFEMATH.md diff --git a/Tools/SmartCheck/Solidity/Rules/SOLIDITY_SAFEMATH.md b/Tools/SmartCheck/Solidity/Rules/SOLIDITY_SAFEMATH.md new file mode 100644 index 0000000..10e6155 --- /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 + + +``` -- GitLab