Commit febf8804 authored by aniket-engg's avatar aniket-engg Committed by Aniket

existing commons test cases updated

parent be7805e0
import { default as category } from './categories' import { default as category } from './categories'
import { isLowLevelCallInst, isLowLevelCallInst050, isLowLevelCallcodeInst, isLowLevelDelegatecallInst, import { isLLCall, isLLDelegatecall,
isLowLevelSendInst, isLowLevelSendInst050, isLLDelegatecallInst050, lowLevelCallTypes } from './staticAnalysisCommon' isLLSend, lowLevelCallTypes } from './staticAnalysisCommon'
import { default as algorithm } from './algorithmCategories' import { default as algorithm } from './algorithmCategories'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, MemberAccessAstNode} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, MemberAccessAstNode} from './../../types'
...@@ -20,20 +20,12 @@ export default class lowLevelCalls implements AnalyzerModule { ...@@ -20,20 +20,12 @@ export default class lowLevelCalls implements AnalyzerModule {
algorithm: ModuleAlgorithm = algorithm.EXACT algorithm: ModuleAlgorithm = algorithm.EXACT
visit (node : MemberAccessAstNode): void { visit (node : MemberAccessAstNode): void {
if (isLowLevelCallInst(node)) { if (isLLCall(node)) {
this.llcNodes.push({node: node, type: lowLevelCallTypes.CALL}) this.llcNodes.push({node: node, type: lowLevelCallTypes.CALL})
} else if (isLowLevelCallInst050(node)) { } else if (isLLDelegatecall(node)) {
this.llcNodes.push({node: node, type: lowLevelCallTypes.CALL})
} else if (isLowLevelCallcodeInst(node)) {
this.llcNodes.push({node: node, type: lowLevelCallTypes.CALLCODE})
} else if (isLowLevelDelegatecallInst(node)) {
this.llcNodes.push({node: node, type: lowLevelCallTypes.DELEGATECALL}) this.llcNodes.push({node: node, type: lowLevelCallTypes.DELEGATECALL})
} else if (isLowLevelSendInst(node)) { } else if (isLLSend(node)) {
this.llcNodes.push({node: node, type: lowLevelCallTypes.SEND})
} else if (isLowLevelSendInst050(node)) {
this.llcNodes.push({node: node, type: lowLevelCallTypes.SEND}) this.llcNodes.push({node: node, type: lowLevelCallTypes.SEND})
} else if (isLLDelegatecallInst050(node)) {
this.llcNodes.push({node: node, type: lowLevelCallTypes.DELEGATECALL})
} }
} }
...@@ -49,12 +41,6 @@ export default class lowLevelCalls implements AnalyzerModule { ...@@ -49,12 +41,6 @@ export default class lowLevelCalls implements AnalyzerModule {
morehref = 'http://solidity.readthedocs.io/en/develop/control-structures.html?#external-function-calls' morehref = 'http://solidity.readthedocs.io/en/develop/control-structures.html?#external-function-calls'
// http://solidity.readthedocs.io/en/develop/frequently-asked-questions.html?#why-is-the-low-level-function-call-less-favorable-than-instantiating-a-contract-with-a-variable-contractb-b-and-executing-its-functions-b-dosomething // http://solidity.readthedocs.io/en/develop/frequently-asked-questions.html?#why-is-the-low-level-function-call-less-favorable-than-instantiating-a-contract-with-a-variable-contractb-b-and-executing-its-functions-b-dosomething
break break
case lowLevelCallTypes.CALLCODE:
text = `use of "callcode": the use of low level "callcode" should be avoided whenever possible.
External code that is called can change the state of the calling contract and send ether from the caller's balance.
If this is wanted behaviour use the Solidity library feature if possible.`
morehref = 'http://solidity.readthedocs.io/en/develop/contracts.html#libraries'
break
case lowLevelCallTypes.DELEGATECALL: case lowLevelCallTypes.DELEGATECALL:
text = `use of "delegatecall": the use of low level "delegatecall" should be avoided whenever possible. text = `use of "delegatecall": the use of low level "delegatecall" should be avoided whenever possible.
External code that is called can change the state of the calling contract and send ether from the caller's balance. External code that is called can change the state of the calling contract and send ether from the caller's balance.
......
{ {
"argumentTypes":[ "argumentTypes": null,
"arguments":
[
{ {
"typeIdentifier": "t_rational_3_by_1", "argumentTypes": null,
"typeString": "int_const 3" "hexValue": "33",
"id": 6,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "79:1:0",
"subdenomination": null,
"typeDescriptions":
{
"typeIdentifier": "t_rational_3_by_1",
"typeString": "int_const 3"
},
"value": "3"
} }
], ],
"id": 5, "expression":
"name": "blockhash", {
"nodeType": "Identifier", "argumentTypes":
"overloadedDeclarations": [], [
"referencedDeclaration": -5, {
"src": "69:9:0", "typeIdentifier": "t_rational_3_by_1",
"typeString": "int_const 3"
}
],
"id": 5,
"name": "blockhash",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": -5,
"src": "69:9:0",
"typeDescriptions":
{
"typeIdentifier": "t_function_blockhash_view$_t_uint256_$returns$_t_bytes32_$",
"typeString": "function (uint256) view returns (bytes32)"
}
},
"id": 7,
"isConstant": false,
"isLValue": false,
"isPure": false,
"kind": "functionCall",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "69:12:0",
"tryCall": false,
"typeDescriptions": "typeDescriptions":
{ {
"typeIdentifier": "t_function_blockhash_view$_t_uint256_$returns$_t_bytes32_$", "typeIdentifier": "t_bytes32",
"typeString": "function (uint256) view returns (bytes32)" "typeString": "bytes32"
} }
} }
\ No newline at end of file
{ "argumentTypes": null,
"expression":
{ "argumentTypes": null,
"id": 109,
"name": "block",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": -4,
"src": "1507:5:0",
"typeDescriptions": { "typeIdentifier": "t_magic_block", "typeString": "block" } },
"id": 110,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "timestamp",
"nodeType": "MemberAccess",
"referencedDeclaration": null,
"src": "1507:15:0",
"typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }
\ No newline at end of file
{ "argumentTypes": null,
"id": 74,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"nodeType": "UnaryOperation",
"operator": "delete",
"prefix": true,
"src": "627:12:0",
"subExpression":
{ "argumentTypes": null,
"id": 73,
"name": "users",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4,
"src": "634:5:0",
"typeDescriptions": {
"typeIdentifier": "t_array$_t_uint256_$dyn_storage",
"typeString": "uint256[] storage ref"
}
},
"typeDescriptions": {
"typeIdentifier": "t_tuple$__$",
"typeString": "tuple()"
}
}
\ No newline at end of file
...@@ -2,7 +2,10 @@ module.exports = { ...@@ -2,7 +2,10 @@ module.exports = {
localCall: require('./localCall.json'), localCall: require('./localCall.json'),
contractDefinition: require('./contractDefinition.json'), contractDefinition: require('./contractDefinition.json'),
unaryOperation: require('./unaryOperation.json'), unaryOperation: require('./unaryOperation.json'),
blockTimestamp: require('./blockTimestamp.json'),
dynamicDeleteUnaryOp: require('./dynamicDeleteUnaryOp.json'),
nowAst: require('./nowAst.json'), nowAst: require('./nowAst.json'),
requireCall: require('./requireCall.json'),
thisLocalCall: require('./thisLocalCall.json'), thisLocalCall: require('./thisLocalCall.json'),
libCall: require('./libCall.json'), libCall: require('./libCall.json'),
externalDirect: require('./externalDirect.json'), externalDirect: require('./externalDirect.json'),
...@@ -17,6 +20,7 @@ module.exports = { ...@@ -17,6 +20,7 @@ module.exports = {
fullyQualifiedFunctionDefinition: require('./fullyQualifiedFunctionDefinition.json'), fullyQualifiedFunctionDefinition: require('./fullyQualifiedFunctionDefinition.json'),
selfdestruct: require('./selfdestruct.json'), selfdestruct: require('./selfdestruct.json'),
storageVariableNodes: require('./storageVariableNodes.json'), storageVariableNodes: require('./storageVariableNodes.json'),
abiNamespaceCallNodes: require('./abiNamespaceCallNodes.json'),
lowlevelCall: require('./lowlevelCall.json'), lowlevelCall: require('./lowlevelCall.json'),
parameterFunction: require('./parameterFunction.json'), parameterFunction: require('./parameterFunction.json'),
parameterFunctionCall: require('./parameterFunctionCall.json'), parameterFunctionCall: require('./parameterFunctionCall.json'),
......
{ {
"attributes": { "argumentTypes": null,
"argumentTypes": null, "arguments":
"isConstant": false, [
"isLValue": false, {
"isPure": false, "argumentTypes": null,
"isStructConstructorCall": false, "id": 216,
"lValueRequested": false, "name": "internalPureFunc",
"names": [ "nodeType": "Identifier",
null "overloadedDeclarations": [],
], "referencedDeclaration": 12,
"type": "uint256", "src": "1636:16:0",
"type_conversion": false "typeDescriptions":
}, {
"children": [ "typeIdentifier": "t_function_internal_pure$_t_uint256_$returns$_t_uint256_$",
{ "typeString": "function (uint256) pure returns (uint256)"
"attributes": { }
"argumentTypes": [ }
{ ],
"typeIdentifier": "t_function_internal_pure$_t_uint256_$_t_uint256_$returns$_t_uint256_$", "expression":
"typeString": "function (uint256,uint256) pure returns (uint256)" {
}, "argumentTypes":
{ [
"typeIdentifier": "t_uint256", {
"typeString": "uint256" "typeIdentifier": "t_function_internal_pure$_t_uint256_$returns$_t_uint256_$",
}, "typeString": "function (uint256) pure returns (uint256)"
{ }
"typeIdentifier": "t_uint256", ],
"typeString": "uint256" "id": 215,
} "name": "funcTakesInternalPure",
], "nodeType": "Identifier",
"overloadedDeclarations": [ "overloadedDeclarations": [],
null "referencedDeclaration": 104,
], "src": "1614:21:0",
"referencedDeclaration": 40, "typeDescriptions":
"type": "function (function (uint256,uint256) pure returns (uint256),uint256,uint256) pure returns (uint256)", {
"value": "eval" "typeIdentifier": "t_function_internal_pure$_t_function_internal_pure$_t_uint256_$returns$_t_uint256_$_$returns$_t_uint256_$",
}, "typeString": "function (function (uint256) pure returns (uint256)) pure returns (uint256)"
"id": 49, }
"name": "Identifier", },
"src": "361:4:0" "id": 217,
}, "isConstant": false,
{ "isLValue": false,
"attributes": { "isPure": false,
"argumentTypes": null, "kind": "functionCall",
"overloadedDeclarations": [ "lValueRequested": false,
null "names": [],
], "nodeType": "FunctionCall",
"referencedDeclaration": 15, "src": "1614:39:0",
"type": "function (uint256,uint256) pure returns (uint256)", "tryCall": false,
"value": "plus" "typeDescriptions":
}, {
"id": 50, "typeIdentifier": "t_uint256",
"name": "Identifier", "typeString": "uint256"
"src": "366:4:0" }
}, }
{ \ No newline at end of file
"attributes": {
"argumentTypes": null,
"overloadedDeclarations": [
null
],
"referencedDeclaration": 42,
"type": "uint256",
"value": "x"
},
"id": 51,
"name": "Identifier",
"src": "372:1:0"
},
{
"attributes": {
"argumentTypes": null,
"overloadedDeclarations": [
null
],
"referencedDeclaration": 44,
"type": "uint256",
"value": "y"
},
"id": 52,
"name": "Identifier",
"src": "375:1:0"
}
],
"id": 53,
"name": "FunctionCall",
"src": "361:16:0"
}
\ No newline at end of file
{
"argumentTypes": null,
"arguments":
[
{
"argumentTypes": null,
"commonType":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"id": 8,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftExpression":
{
"argumentTypes": null,
"expression":
{
"argumentTypes": null,
"id": 5,
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": -15,
"src": "56:3:0",
"typeDescriptions":
{
"typeIdentifier": "t_magic_message",
"typeString": "msg"
}
},
"id": 6,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "value",
"nodeType": "MemberAccess",
"referencedDeclaration": null,
"src": "56:9:0",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"nodeType": "BinaryOperation",
"operator": ">=",
"rightExpression":
{
"argumentTypes": null,
"id": 7,
"name": "_amount",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 2,
"src": "69:7:0",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"src": "56:20:0",
"typeDescriptions":
{
"typeIdentifier": "t_bool",
"typeString": "bool"
}
}
],
"expression":
{
"argumentTypes":
[
{
"typeIdentifier": "t_bool",
"typeString": "bool"
}
],
"id": 4,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations":
[
-18,
-18
],
"referencedDeclaration": -18,
"src": "48:7:0",
"typeDescriptions":
{
"typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$",
"typeString": "function (bool) pure"
}
},
"id": 9,
"isConstant": false,
"isLValue": false,
"isPure": false,
"kind": "functionCall",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "48:29:0",
"tryCall": false,
"typeDescriptions":
{
"typeIdentifier": "t_tuple$__$",
"typeString": "tuple()"
}
}
\ No newline at end of file
pragma solidity >=0.4.9 <0.6.0; pragma solidity >=0.4.9 <0.7.0;
contract arr { contract arr {
uint[] users; uint[] users;
......
...@@ -50,5 +50,9 @@ contract C { ...@@ -50,5 +50,9 @@ contract C {
if (!Set.insert(knownValues, value)) if (!Set.insert(knownValues, value))
revert(); revert();
} }
function testt() public view returns (uint) {
return block.timestamp;
}
// In this contract, we can also directly access knownValues.flags, if we want. // In this contract, we can also directly access knownValues.flags, if we want.
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment