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

20 contract integration tests updated

parent 2fce136c
...@@ -5,7 +5,7 @@ import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, Compilation ...@@ -5,7 +5,7 @@ import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, Compilation
export default class blockBlockhash implements AnalyzerModule { export default class blockBlockhash implements AnalyzerModule {
warningNodes: FunctionCallAstNode[] = [] warningNodes: FunctionCallAstNode[] = []
name: string = 'Block.blockhash usage: ' name: string = 'Blockhash usage: '
description: string = 'Semantics maybe unclear' description: string = 'Semantics maybe unclear'
category: ModuleCategory = category.SECURITY category: ModuleCategory = category.SECURITY
algorithm: ModuleAlgorithm = algorithm.EXACT algorithm: ModuleAlgorithm = algorithm.EXACT
...@@ -17,7 +17,7 @@ export default class blockBlockhash implements AnalyzerModule { ...@@ -17,7 +17,7 @@ export default class blockBlockhash implements AnalyzerModule {
report (compilationResults: CompilationResult): ReportObj[] { report (compilationResults: CompilationResult): ReportObj[] {
return this.warningNodes.map((item, i) => { return this.warningNodes.map((item, i) => {
return { return {
warning: `use of "block.blockhash": "block.blockhash" is used to access the last 256 block hashes. warning: `use of "blockhash": "blockhash" is used to access the last 256 block hashes.
A miner computes the block hash by "summing up" the information in the current block mined. A miner computes the block hash by "summing up" the information in the current block mined.
By "summing up" the information in a clever way a miner can try to influence the outcome of a transaction in the current block. By "summing up" the information in a clever way a miner can try to influence the outcome of a transaction in the current block.
This is especially easy if there are only a small number of equally likely outcomes.`, This is especially easy if there are only a small number of equally likely outcomes.`,
......
...@@ -78,7 +78,7 @@ export default class checksEffectsInteraction implements AnalyzerModule { ...@@ -78,7 +78,7 @@ export default class checksEffectsInteraction implements AnalyzerModule {
private isLocalCallWithStateChange (node: FunctionCallAstNode, context: Context): boolean { private isLocalCallWithStateChange (node: FunctionCallAstNode, context: Context): boolean {
if (isLocalCallGraphRelevantNode(node)) { if (isLocalCallGraphRelevantNode(node)) {
const func = resolveCallGraphSymbol(context.callGraph, getFullQualifiedFunctionCallIdent(context.currentContract.node, node)) const func = resolveCallGraphSymbol(context.callGraph, getFullQualifiedFunctionCallIdent(context.currentContract.node, node))
return !func || (func && func['changesState']) return !func || (func && func.node['changesState'])
} }
return false return false
} }
......
import { default as category } from './categories' import { default as category } from './categories'
import { default as algorithm } from './algorithmCategories' import { default as algorithm } from './algorithmCategories'
import { isTransfer } from './staticAnalysisCommon' import { isLoop, isTransfer } from './staticAnalysisCommon'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, ForStatementAstNode, WhileStatementAstNode, CommonAstNode, ExpressionStatementAstNode} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, ForStatementAstNode, WhileStatementAstNode, CommonAstNode, ExpressionStatementAstNode} from './../../types'
export default class etherTransferInLoop implements AnalyzerModule { export default class etherTransferInLoop implements AnalyzerModule {
...@@ -12,14 +12,16 @@ export default class etherTransferInLoop implements AnalyzerModule { ...@@ -12,14 +12,16 @@ export default class etherTransferInLoop implements AnalyzerModule {
visit (node: ForStatementAstNode | WhileStatementAstNode): void { visit (node: ForStatementAstNode | WhileStatementAstNode): void {
let transferNodes: ExpressionStatementAstNode[] = [] let transferNodes: ExpressionStatementAstNode[] = []
if(node.body && node.body.nodeType === 'Block') if(isLoop(node)) {
if(node.body && node.body.nodeType === 'Block')
transferNodes = node.body.statements.filter(child => ( child.nodeType === 'ExpressionStatement' && transferNodes = node.body.statements.filter(child => ( child.nodeType === 'ExpressionStatement' &&
child.expression.nodeType === 'FunctionCall' && isTransfer(child.expression.expression))) child.expression.nodeType === 'FunctionCall' && isTransfer(child.expression.expression)))
// When loop body is described without braces // When loop body is described without braces
else if(node.body && node.body.nodeType === 'ExpressionStatement' && node.body.expression.nodeType === 'FunctionCall' && isTransfer(node.body.expression.expression)) else if(node.body && node.body.nodeType === 'ExpressionStatement' && node.body.expression.nodeType === 'FunctionCall' && isTransfer(node.body.expression.expression))
transferNodes.push(node.body) transferNodes.push(node.body)
if (transferNodes.length > 0) { if (transferNodes.length > 0) {
this.relevantNodes.push(...transferNodes) this.relevantNodes.push(...transferNodes)
}
} }
} }
......
...@@ -13,7 +13,7 @@ export default class selfdestruct implements AnalyzerModule { ...@@ -13,7 +13,7 @@ export default class selfdestruct implements AnalyzerModule {
abstractAst: AbstractAst = new AbstractAst() abstractAst: AbstractAst = new AbstractAst()
visit: Function = this.abstractAst.build_visit( visit: Function = this.abstractAst.build_visit(
(node: any) => isStatement(node) || ( node.nodeType=== 'FunctionCall' && isSelfdestructCall(node.expression) ) (node: any) => isStatement(node) || (node.nodeType=== 'FunctionCall' && isSelfdestructCall(node))
) )
report: Function = this.abstractAst.build_report(this._report.bind(this)) report: Function = this.abstractAst.build_report(this._report.bind(this))
......
...@@ -438,7 +438,7 @@ function getFullQualifiedFunctionCallIdent (contract: ContractDefinitionAstNode, ...@@ -438,7 +438,7 @@ function getFullQualifiedFunctionCallIdent (contract: ContractDefinitionAstNode,
else if (isThisLocalCall(func.expression)) return getThisLocalCallContractName(func) + '.' + getThisLocalCallName(func) + '(' + getFunctionCallTypeParameterType(func) + ')' else if (isThisLocalCall(func.expression)) return getThisLocalCallContractName(func) + '.' + getThisLocalCallName(func) + '(' + getFunctionCallTypeParameterType(func) + ')'
else if (isSuperLocalCall(func.expression)) return getContractName(contract) + '.' + getSuperLocalCallName(func) + '(' + getFunctionCallTypeParameterType(func) + ')' else if (isSuperLocalCall(func.expression)) return getContractName(contract) + '.' + getSuperLocalCallName(func) + '(' + getFunctionCallTypeParameterType(func) + ')'
else if (isExternalDirectCall(func)) return getExternalDirectCallContractName(func) + '.' + getExternalDirectCallMemberName(func) + '(' + getFunctionCallTypeParameterType(func) + ')' else if (isExternalDirectCall(func)) return getExternalDirectCallContractName(func) + '.' + getExternalDirectCallMemberName(func) + '(' + getFunctionCallTypeParameterType(func) + ')'
else if (isLibraryCall(func.expression)) return getLibraryCallContractName(func.expression) + '.' + getLibraryCallMemberName(func) + '(' + getFunctionCallTypeParameterType(func) + ')' else if (isLibraryCall(func.expression)) return getLibraryCallContractName(func) + '.' + getLibraryCallMemberName(func) + '(' + getFunctionCallTypeParameterType(func) + ')'
else throw new Error('staticAnalysisCommon.js: Can not get function name from non function call node') else throw new Error('staticAnalysisCommon.js: Can not get function name from non function call node')
} }
...@@ -995,11 +995,11 @@ function isBytesLengthCheck (node: MemberAccessAstNode): boolean { ...@@ -995,11 +995,11 @@ function isBytesLengthCheck (node: MemberAccessAstNode): boolean {
* @node {ASTNode} some AstNode * @node {ASTNode} some AstNode
* @return {bool} * @return {bool}
*/ */
// function isLoop (node) { function isLoop (node) {
// return nodeType(node, exactMatch(nodeTypes.FORSTATEMENT)) || return nodeType(node, exactMatch(nodeTypes.FORSTATEMENT)) ||
// nodeType(node, exactMatch(nodeTypes.WHILESTATEMENT)) || nodeType(node, exactMatch(nodeTypes.WHILESTATEMENT)) ||
// nodeType(node, exactMatch(nodeTypes.DOWHILESTATEMENT)) nodeType(node, exactMatch(nodeTypes.DOWHILESTATEMENT))
// } }
/** /**
* True if it is a 'for' loop * True if it is a 'for' loop
...@@ -1202,7 +1202,7 @@ export { ...@@ -1202,7 +1202,7 @@ export {
isIntDivision, isIntDivision,
isStringToBytesConversion, isStringToBytesConversion,
isBytesLengthCheck, isBytesLengthCheck,
// isForLoop, isLoop,
// #################### Trivial Node Identification // #################### Trivial Node Identification
isDeleteUnaryOperation, isDeleteUnaryOperation,
......
pragma solidity >=0.4.9 <0.7.0; pragma solidity >=0.4.9 <0.6.0;
library Set { library Set {
// We define a new struct datatype that will be used to // We define a new struct datatype that will be used to
...@@ -51,8 +51,5 @@ contract C { ...@@ -51,8 +51,5 @@ contract C {
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