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

commons, modules & test ASTs updated

parent 04dccc92
import { default as category } from './categories' import { default as category } from './categories'
import { isNowAccess, isBlockTimestampAccess } from './staticAnalysisCommon' import { isNowAccess, isBlockTimestampAccess } from './staticAnalysisCommon'
import { default as algorithm } from './algorithmCategories' import { default as algorithm } from './algorithmCategories'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, AstNodeLegacy, CompilationResult} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, AstNodeLegacy, CompilationResult, IdentifierAstNode, MemberAccessAstNode} from './../../types'
export default class blockTimestamp implements AnalyzerModule { export default class blockTimestamp implements AnalyzerModule {
warningNowNodes: AstNodeLegacy[] = [] warningNowNodes: IdentifierAstNode[] = []
warningblockTimestampNodes: AstNodeLegacy[] = [] warningblockTimestampNodes: MemberAccessAstNode[] = []
name: string = 'Block timestamp: ' name: string = 'Block timestamp: '
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
visit (node: AstNodeLegacy): void { visit (node: IdentifierAstNode | MemberAccessAstNode ): void {
if (isNowAccess(node)) this.warningNowNodes.push(node) if (node.nodeType === "Identifier" && isNowAccess(node)) this.warningNowNodes.push(node)
else if (isBlockTimestampAccess(node)) this.warningblockTimestampNodes.push(node) else if (node.nodeType === "MemberAccess" && isBlockTimestampAccess(node)) this.warningblockTimestampNodes.push(node)
} }
report (compilationResults: CompilationResult): ReportObj[] { report (compilationResults: CompilationResult): ReportObj[] {
......
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 { isDeleteFromDynamicArray, isMappingIndexAccess } from './staticAnalysisCommon' import { isDeleteFromDynamicArray, isMappingIndexAccess } from './staticAnalysisCommon'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, AstNodeLegacy, CompilationResult} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, UnaryOperationAstNode} from './../../types'
export default class deleteFromDynamicArray implements AnalyzerModule { export default class deleteFromDynamicArray implements AnalyzerModule {
relevantNodes: AstNodeLegacy[] = [] relevantNodes: UnaryOperationAstNode[] = []
name: string = 'Delete from dynamic Array: ' name: string = 'Delete from dynamic Array: '
description: string = 'Using delete on an array leaves a gap' description: string = 'Using delete on an array leaves a gap'
category: ModuleCategory = category.MISC category: ModuleCategory = category.MISC
algorithm: ModuleAlgorithm = algorithm.EXACT algorithm: ModuleAlgorithm = algorithm.EXACT
visit (node: AstNodeLegacy): void { visit (node: UnaryOperationAstNode): void {
if (isDeleteFromDynamicArray(node) && node.children && !isMappingIndexAccess(node.children[0])) this.relevantNodes.push(node) if (isDeleteFromDynamicArray(node) && !isMappingIndexAccess(node.subExpression)) this.relevantNodes.push(node)
} }
report (compilationResults: CompilationResult): ReportObj[] { report (compilationResults: CompilationResult): ReportObj[] {
......
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 { getLoopBlockStartIndex, isTransfer } from './staticAnalysisCommon' import { isTransfer } from './staticAnalysisCommon'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, AstNodeLegacy, CompilationResult, ForStatementAstNode, WhileStatementAstNode, CommonAstNode, ExpressionStatementAstNode} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, AstNodeLegacy, CompilationResult, ForStatementAstNode, WhileStatementAstNode, CommonAstNode, ExpressionStatementAstNode} from './../../types'
export default class etherTransferInLoop implements AnalyzerModule { export default class etherTransferInLoop implements AnalyzerModule {
......
import { default as category } from './categories' import { default as category } from './categories'
import { isRequireCall, isAssertCall } from './staticAnalysisCommon' import { isRequireCall, isAssertCall } from './staticAnalysisCommon'
import { default as algorithm } from './algorithmCategories' import { default as algorithm } from './algorithmCategories'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, AstNodeLegacy, CompilationResult} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, FunctionCallAstNode} from './../../types'
export default class guardConditions implements AnalyzerModule { export default class guardConditions implements AnalyzerModule {
guards: AstNodeLegacy[] = [] guards: FunctionCallAstNode[] = []
name: string = 'Guard Conditions: ' name: string = 'Guard Conditions: '
description: string = 'Use require and appropriately' description: string = 'Use require and appropriately'
category: ModuleCategory = category.MISC category: ModuleCategory = category.MISC
algorithm: ModuleAlgorithm = algorithm.EXACT algorithm: ModuleAlgorithm = algorithm.EXACT
visit (node: AstNodeLegacy): void { visit (node: FunctionCallAstNode): void {
if (isRequireCall(node) || isAssertCall(node)) this.guards.push(node) if (isRequireCall(node) || isAssertCall(node)) this.guards.push(node)
} }
......
...@@ -2,7 +2,7 @@ import { default as category } from './categories' ...@@ -2,7 +2,7 @@ import { default as category } from './categories'
import { hasFunctionBody, getFullQuallyfiedFuncDefinitionIdent, getEffectedVariableName } from './staticAnalysisCommon' import { hasFunctionBody, getFullQuallyfiedFuncDefinitionIdent, getEffectedVariableName } from './staticAnalysisCommon'
import { default as algorithm } from './algorithmCategories' import { default as algorithm } from './algorithmCategories'
import AbstractAst from './abstractAstView' import AbstractAst from './abstractAstView'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, AstNodeLegacy, CompilationResult, CommonAstNode, FunctionDefinitionAstNode} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, CommonAstNode, FunctionDefinitionAstNode} from './../../types'
export default class noReturn implements AnalyzerModule { export default class noReturn implements AnalyzerModule {
name: string = 'no return: ' name: string = 'no return: '
......
...@@ -2,7 +2,7 @@ import { default as category } from './categories' ...@@ -2,7 +2,7 @@ import { default as category } from './categories'
import { isStatement, isSelfdestructCall } from './staticAnalysisCommon' import { isStatement, isSelfdestructCall } from './staticAnalysisCommon'
import { default as algorithm } from './algorithmCategories' import { default as algorithm } from './algorithmCategories'
import AbstractAst from './abstractAstView' import AbstractAst from './abstractAstView'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, AstNodeLegacy, CompilationResult} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult} from './../../types'
export default class selfdestruct implements AnalyzerModule { export default class selfdestruct implements AnalyzerModule {
name: string = 'Selfdestruct: ' name: string = 'Selfdestruct: '
...@@ -13,8 +13,7 @@ export default class selfdestruct implements AnalyzerModule { ...@@ -13,8 +13,7 @@ export default class selfdestruct implements AnalyzerModule {
abstractAst = new AbstractAst() abstractAst = new AbstractAst()
visit = this.abstractAst.build_visit( visit = this.abstractAst.build_visit(
(node: AstNodeLegacy) => isStatement(node) || (node: any) => isStatement(node) || isSelfdestructCall(node.expression)
isSelfdestructCall(node)
) )
report = this.abstractAst.build_report(this._report.bind(this)) report = this.abstractAst.build_report(this._report.bind(this))
......
...@@ -70,7 +70,7 @@ export default class similarVariableNames implements AnalyzerModule { ...@@ -70,7 +70,7 @@ export default class similarVariableNames implements AnalyzerModule {
return varName2.match(ref) != null return varName2.match(ref) != null
} }
private getFunctionVariables (contract, func): string[] { private getFunctionVariables (contract, func) {
return contract.stateVariables.concat(func.localVariables) return contract.stateVariables.concat(func.localVariables)
} }
} }
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 { isStringToBytesConversion, isBytesLengthCheck } from './staticAnalysisCommon' import { isStringToBytesConversion, isBytesLengthCheck } from './staticAnalysisCommon'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, AstNodeLegacy, CompilationResult} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, MemberAccessAstNode, FunctionCallAstNode} from './../../types'
export default class stringBytesLength implements AnalyzerModule { export default class stringBytesLength implements AnalyzerModule {
name: string = 'String Length: ' name: string = 'String Length: '
...@@ -9,13 +9,13 @@ export default class stringBytesLength implements AnalyzerModule { ...@@ -9,13 +9,13 @@ export default class stringBytesLength implements AnalyzerModule {
category: ModuleCategory = category.MISC category: ModuleCategory = category.MISC
algorithm: ModuleAlgorithm = algorithm.EXACT algorithm: ModuleAlgorithm = algorithm.EXACT
stringToBytesConversions: AstNodeLegacy[] = [] stringToBytesConversions: FunctionCallAstNode[] = []
bytesLengthChecks: AstNodeLegacy[] = [] bytesLengthChecks: MemberAccessAstNode[] = []
visit (node: AstNodeLegacy): void { visit (node: FunctionCallAstNode | MemberAccessAstNode): void {
if (isStringToBytesConversion(node)) this.stringToBytesConversions.push(node) if (node.nodeType === "FunctionCall" && isStringToBytesConversion(node)) this.stringToBytesConversions.push(node)
else if (isBytesLengthCheck(node)) this.bytesLengthChecks.push(node) else if (node.nodeType === "MemberAccess" && isBytesLengthCheck(node)) this.bytesLengthChecks.push(node)
} }
report (compilationResults: CompilationResult): ReportObj[] { report (compilationResults: CompilationResult): ReportObj[] {
......
import { default as category } from './categories' import { default as category } from './categories'
import { isThisLocalCall } from './staticAnalysisCommon' import { isThisLocalCall } from './staticAnalysisCommon'
import { default as algorithm } from './algorithmCategories' import { default as algorithm } from './algorithmCategories'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, AstNodeLegacy, CompilationResult, MemberAccessAstNode} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, MemberAccessAstNode} from './../../types'
export default class thisLocal implements AnalyzerModule { export default class thisLocal implements AnalyzerModule {
warningNodes: MemberAccessAstNode[] = [] warningNodes: MemberAccessAstNode[] = []
......
...@@ -169,7 +169,7 @@ export interface FunctionDefinitionAstNode { ...@@ -169,7 +169,7 @@ export interface FunctionDefinitionAstNode {
overrides: OverrideSpecifierAstNode | null overrides: OverrideSpecifierAstNode | null
parameters: ParameterListAstNode parameters: ParameterListAstNode
returnParameters: ParameterListAstNode returnParameters: ParameterListAstNode
modifiers: Array<any> modifiers: Array<ModifierInvocationAstNode>
body: object | null body: object | null
implemented: boolean implemented: boolean
scope: number scope: number
...@@ -182,7 +182,7 @@ export interface VariableDeclarationAstNode { ...@@ -182,7 +182,7 @@ export interface VariableDeclarationAstNode {
nodeType: 'VariableDeclaration' nodeType: 'VariableDeclaration'
src: string src: string
name: string name: string
typeName: object typeName: ElementaryTypeNameAstNode | UserDefinedTypeNameAstNode
constant: boolean constant: boolean
stateVariable: boolean stateVariable: boolean
storageLocation: 'storage' | 'memory' | 'calldata' | 'default' storageLocation: 'storage' | 'memory' | 'calldata' | 'default'
...@@ -298,7 +298,7 @@ export interface BlockAstNode { ...@@ -298,7 +298,7 @@ export interface BlockAstNode {
id: number id: number
nodeType: 'Block' nodeType: 'Block'
src: string src: string
statements: Array<CommonAstNode> statements: Array<any>
} }
export interface PlaceholderStatementAstNode { export interface PlaceholderStatementAstNode {
...@@ -481,10 +481,12 @@ export interface NewExpressionAstNode extends ExpressionAttributes { ...@@ -481,10 +481,12 @@ export interface NewExpressionAstNode extends ExpressionAttributes {
typeName: UserDefinedTypeNameAstNode | ElementaryTypeNameAstNode typeName: UserDefinedTypeNameAstNode | ElementaryTypeNameAstNode
} }
export interface MemberAccessAstNode extends CommonAstNode, ExpressionAttributes { export interface MemberAccessAstNode extends ExpressionAttributes {
id: number
nodeType: 'MemberAccess' nodeType: 'MemberAccess'
src: string
memberName: string memberName: string
expression: object expression: any
referencedDeclaration: number | null referencedDeclaration: number | null
} }
......
{ {
"attributes": { "argumentTypes": null,
"operator": "=", "id": 5,
"type": "uint256" "isConstant": false,
}, "isLValue": false,
"children": [ "isPure": false,
{ "lValueRequested": false,
"attributes": { "leftHandSide":
"type": "uint256" {
}, "argumentTypes": null,
"children": [ "id": 3,
{ "name": "a",
"attributes": { "nodeType": "Identifier",
"type": "mapping(address => uint256)", "overloadedDeclarations": [],
"value": "c" "referencedDeclaration": 22,
}, "src": "52:1:0",
"id": 61, "typeDescriptions":
"name": "Identifier", {
"src": "873:1:0" "typeIdentifier": "t_uint256",
}, "typeString": "uint256"
{ }
"attributes": { },
"member_name": "sender", "nodeType": "Assignment",
"type": "address" "operator": "=",
}, "rightHandSide":
"children": [ {
{ "argumentTypes": null,
"attributes": { "hexValue": "31",
"type": "msg", "id": 4,
"value": "msg" "isConstant": false,
}, "isLValue": false,
"id": 62, "isPure": true,
"name": "Identifier", "kind": "number",
"src": "875:3:0" "lValueRequested": false,
} "nodeType": "Literal",
], "src": "56:5:0",
"id": 63, "subdenomination": "wei",
"name": "MemberAccess", "typeDescriptions":
"src": "875:10:0" {
} "typeIdentifier": "t_rational_1_by_1",
], "typeString": "int_const 1"
"id": 64, },
"name": "IndexAccess", "value": "1"
"src": "873:13:0" },
}, "src": "52:9:0",
{ "typeDescriptions":
"attributes": { {
"hexvalue": "30", "typeIdentifier": "t_uint256",
"subdenomination": null, "typeString": "uint256"
"token": null, }
"type": "int_const 0", }
"value": "0" \ No newline at end of file
},
"id": 65,
"name": "Literal",
"src": "889:1:0"
}
],
"id": 66,
"name": "Assignment",
"src": "873:17:0"
}
\ No newline at end of file
{ {
"attributes": { "argumentTypes":[
"member_name": "blockhash",
"type": "function (uint256) returns (bytes32)"
},
"children": [
{ {
"attributes": { "typeIdentifier": "t_rational_3_by_1",
"type": "block", "typeString": "int_const 3"
"value": "block"
},
"name": "Identifier"
} }
], ],
"name": "MemberAccess" "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)"
}
} }
\ No newline at end of file
{ {
"children": "body":
[ {
{ "id": 10,
"attributes": "nodeType": "Block",
"src": "113:2:0",
"statements": []
},
"condition":
{
"argumentTypes": null,
"expression":
{
"argumentTypes": null,
"components":
[
{ {
"argumentTypes": null, "argumentTypes": null,
"commonType": "id": 13,
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"isConstant": false, "isConstant": false,
"isLValue": false, "isLValue": false,
"isPure": false, "isPure": false,
"lValueRequested": false, "lValueRequested": false,
"operator": "<", "leftHandSide":
"type": "bool"
},
"children":
[
{ {
"attributes": "argumentTypes": null,
"id": 11,
"name": "c",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 8,
"src": "123:1:0",
"typeDescriptions":
{ {
"argumentTypes": null, "typeIdentifier": "t_struct$_S_$3_storage_ptr",
"overloadedDeclarations": "typeString": "struct C.S storage pointer"
[ }
null
],
"referencedDeclaration": 69,
"type": "uint256",
"value": "i"
},
"id": 82,
"name": "Identifier",
"src": "592:1:0"
}, },
"nodeType": "Assignment",
"operator": "=",
"rightHandSide":
{ {
"attributes": "argumentTypes": null,
"id": 12,
"name": "s",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 5,
"src": "127:1:0",
"typeDescriptions":
{ {
"argumentTypes": null, "typeIdentifier": "t_struct$_S_$3_storage",
"hexvalue": "3130", "typeString": "struct C.S storage ref"
"isConstant": false, }
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"subdenomination": null,
"token": "number",
"type": "int_const 10",
"value": "10"
},
"id": 83,
"name": "Literal",
"src": "596:2:0"
}
],
"id": 84,
"name": "BinaryOperation",
"src": "592:6:0"
},
{
"children":
[
{
"children":
[
{
"attributes":
{
"argumentTypes": null,
"isConstant": false,
"isLValue": false,
"isPure": false,
"isStructConstructorCall": false,
"lValueRequested": false,
"names":
[
null
],
"type": "uint256",
"type_conversion": false
},
"children":
[
{
"attributes":
{
"argumentTypes":
[
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
],
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"member_name": "push",
"referencedDeclaration": null,
"type": "function (uint256) returns (uint256)"
},
"children":
[
{
"attributes":
{
"argumentTypes": null,
"overloadedDeclarations":
[
null
],
"referencedDeclaration": 4,
"type": "uint256[] storage ref",
"value": "array"
},
"id": 72,
"name": "Identifier",
"src": "544:5:0"
}
],
"id": 74,
"name": "MemberAccess",
"src": "544:10:0"
},
{
"attributes":
{
"argumentTypes": null,
"overloadedDeclarations":
[
null
],
"referencedDeclaration": 69,
"type": "uint256",
"value": "i"
},
"id": 75,
"name": "Identifier",
"src": "555:1:0"
}
],
"id": 76,
"name": "FunctionCall",
"src": "544:13:0"
}
],
"id": 77,
"name": "ExpressionStatement",
"src": "544:13:0"
}, },
"src": "123:5:0",
"typeDescriptions":
{ {
"children": "typeIdentifier": "t_struct$_S_$3_storage_ptr",
[ "typeString": "struct C.S storage pointer"
{
"attributes":
{
"argumentTypes": null,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"operator": "++",
"prefix": false,
"type": "uint256"
},
"children":
[
{
"attributes":
{
"argumentTypes": null,
"overloadedDeclarations":
[
null
],
"referencedDeclaration": 69,
"type": "uint256",
"value": "i"
},
"id": 78,
"name": "Identifier",
"src": "571:1:0"
}
],
"id": 79,
"name": "UnaryOperation",
"src": "571:3:0"
}
],
"id": 80,
"name": "ExpressionStatement",
"src": "571:3:0"
} }
], }
"id": 81, ],
"name": "Block", "id": 14,
"src": "530:55:0" "isConstant": false,
"isInlineArray": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"nodeType": "TupleExpression",
"src": "122:7:0",
"typeDescriptions":
{
"typeIdentifier": "t_struct$_S_$3_storage_ptr",
"typeString": "struct C.S storage pointer"
} }
], },
"id": 85, "id": 15,
"name": "DoWhileStatement", "isConstant": false,
"src": "528:72:0" "isLValue": true,
} "isPure": false,
\ No newline at end of file "lValueRequested": false,
"memberName": "f",
"nodeType": "MemberAccess",
"referencedDeclaration": 2,
"src": "122:9:0",
"typeDescriptions":
{
"typeIdentifier": "t_bool",
"typeString": "bool"
}
},
"id": 16,
"nodeType": "DoWhileStatement",
"src": "110:23:0"
}
\ No newline at end of file
{ {
"attributes": { "body":
"constant": true, {
"name": "winnerName", "id": 6,
"payable": false, "nodeType": "Block",
"visibility": "public" "src": "42:23:0",
}, "statements":
"children": [ [
{ {
"children": [ "assignments":
], [
"name": "ParameterList" 4
}, ],
{ "declarations":
"children": [], [
"name": "ParameterList" {
}, "constant": false,
{ "id": 4,
"children": [], "name": "a",
"name": "Block" "nodeType": "VariableDeclaration",
} "overrides": null,
], "scope": 6,
"name": "FunctionDefinition" "src": "52:6:0",
} "stateVariable": false,
\ No newline at end of file "storageLocation": "default",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName":
{
"id": 3,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "52:4:0",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "internal"
}
],
"id": 5,
"initialValue": null,
"nodeType": "VariableDeclarationStatement",
"src": "52:6:0"
}
]
},
"documentation": null,
"functionSelector": "26121ff0",
"id": 7,
"implemented": true,
"kind": "function",
"modifiers": [],
"name": "f",
"nodeType": "FunctionDefinition",
"overrides": null,
"parameters":
{
"id": 1,
"nodeType": "ParameterList",
"parameters": [],
"src": "27:2:0"
},
"returnParameters":
{
"id": 2,
"nodeType": "ParameterList",
"parameters": [],
"src": "42:0:0"
},
"scope": 8,
"src": "17:48:0",
"stateMutability": "pure",
"virtual": false,
"visibility": "public"
}
\ No newline at end of file
{ {
"children": [ "arguments": null,
"baseName":
{
"contractScope": null,
"id": 19,
"name": "A",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 9,
"src": "176:1:0",
"typeDescriptions":
{ {
"attributes": { "typeIdentifier": "t_contract$_A_$9",
"name": "r" "typeString": "contract A"
},
"id": 7,
"name": "UserDefinedTypeName",
"src": "84:1:0"
} }
], },
"id": 8, "id": 20,
"name": "InheritanceSpecifier", "nodeType": "InheritanceSpecifier",
"src": "84:1:0" "src": "176:1:0"
} }
\ No newline at end of file
{ {
"children": [ "AST":
], {
"id": 21, "nodeType": "YulBlock",
"name": "InlineAssembly", "src": "148:83:0",
"src": "809:41:0" "statements":
} [
\ No newline at end of file {
"nodeType": "YulVariableDeclaration",
"src": "162:11:0",
"value":
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "172:1:0"
},
"variables":
[
{
"name": "c1",
"nodeType": "YulTypedName",
"src": "166:2:0",
"type": ""
}
]
},
{
"nodeType": "YulVariableDeclaration",
"src": "186:11:0",
"value":
{
"name": "b",
"nodeType": "YulIdentifier",
"src": "196:1:0"
},
"variables":
[
{
"name": "c2",
"nodeType": "YulTypedName",
"src": "190:2:0",
"type": ""
}
]
},
{
"nodeType": "YulVariableDeclaration",
"src": "210:11:0",
"value":
{
"name": "s",
"nodeType": "YulIdentifier",
"src": "220:1:0"
},
"variables":
[
{
"name": "c3",
"nodeType": "YulTypedName",
"src": "214:2:0",
"type": ""
}
]
}
]
},
"evmVersion": "istanbul",
"externalReferences":
[
{
"declaration": 8,
"isOffset": false,
"isSlot": false,
"src": "196:1:0",
"valueSize": 1
},
{
"declaration": 11,
"isOffset": false,
"isSlot": false,
"src": "220:1:0",
"valueSize": 1
},
{
"declaration": 5,
"isOffset": false,
"isSlot": false,
"src": "172:1:0",
"valueSize": 1
}
],
"id": 14,
"nodeType": "InlineAssembly",
"src": "139:92:0"
}
\ No newline at end of file
{ {
"attributes": { "argumentTypes": null,
"member_name": "insert", "expression":
"type": "function (struct Set.Data storage pointer,uint256) returns (bool)" {
}, "argumentTypes": null,
"children": [ "id": 33,
"name": "L",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 21,
"src": "244:1:0",
"typeDescriptions":
{ {
"attributes": { "typeIdentifier": "t_type$_t_contract$_L_$21_$",
"type": "type(library Set)", "typeString": "type(library L)"
"value": "Set"
},
"name": "Identifier"
} }
], },
"name": "MemberAccess" "id": 34,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "f",
"nodeType": "MemberAccess",
"referencedDeclaration": 6,
"src": "244:3:0",
"typeDescriptions":
{
"typeIdentifier": "t_function_delegatecall_nonpayable$_t_uint256_$returns$__$",
"typeString": "function (uint256)"
}
} }
\ No newline at end of file
{ {
"attributes": { "argumentTypes": null,
"type": "tuple()", "arguments": [],
"type_conversion": false "expression":
}, {
"children": [ "argumentTypes": [],
{ "id": 13,
"attributes": { "name": "sha3",
"type": "function (struct Ballot.Voter storage pointer)", "nodeType": "Identifier",
"value": "bli" "overloadedDeclarations": [],
}, "referencedDeclaration": 8,
"id": 37, "src": "129:4:0",
"name": "Identifier", "typeDescriptions":
"src": "540:3:0"
},
{ {
"attributes": { "typeIdentifier": "t_function_internal_pure$__$returns$_t_bool_$",
"type": "struct Ballot.Voter storage pointer", "typeString": "function () pure returns (bool)"
"value": "x"
},
"id": 38,
"name": "Identifier",
"src": "544:1:0"
} }
], },
"id": 39, "id": 14,
"name": "FunctionCall", "isConstant": false,
"src": "540:6:0" "isLValue": false,
} "isPure": false,
\ No newline at end of file "kind": "functionCall",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "129:6:0",
"tryCall": false,
"typeDescriptions":
{
"typeIdentifier": "t_bool",
"typeString": "bool"
}
}
\ No newline at end of file
{ {
"sendAst": { "name": "MemberAccess", "sendAst": {
"children": [ "argumentTypes":
{ [
"attributes": { {
"value": "d", "typeIdentifier": "t_rational_1_by_1",
"type": "address" "typeString": "int_const 1"
} }
}], ],
"attributes": { "expression":
"value": "send", {
"type": "function (uint256) returns (bool)" } "argumentTypes": null,
}, "id": 27,
"callAst": { "name": "MemberAccess", "children": [{ "name": "addr",
"attributes": { "nodeType": "Identifier",
"value": "f", "overloadedDeclarations": [],
"type": "address" "referencedDeclaration": 4,
}}], "src": "227:4:0",
"attributes": { "typeDescriptions":
"member_name": "call", {
"type": "function () payable returns (bool)" } }, "typeIdentifier": "t_address_payable",
"callcodeAst": { "typeString": "address payable"
"name": "MemberAccess", }
"children": [{ },
"attributes": { "id": 28,
"value": "f", "isConstant": false,
"type": "address" "isLValue": false,
}}], "isPure": false,
"attributes": { "lValueRequested": false,
"member_name": "callcode", "memberName": "send",
"type": "function () payable returns (bool)" } }, "nodeType": "MemberAccess",
"delegatecallAst": { "referencedDeclaration": null,
"name": "MemberAccess", "src": "227:9:0",
"children": [{ "typeDescriptions":
"attributes": { {
"value": "g", "typeIdentifier": "t_function_send_nonpayable$_t_uint256_$returns$_t_bool_$",
"type": "address" "typeString": "function (uint256) returns (bool)"
}}], }
"attributes": { },
"member_name": "delegatecall", "callAst": {
"type": "function () returns (bool)" } } "argumentTypes": null,
"expression":
{
"argumentTypes": null,
"id": 9,
"name": "a",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 6,
"src": "91:1:0",
"typeDescriptions":
{
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"id": 12,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "call",
"nodeType": "MemberAccess",
"referencedDeclaration": null,
"src": "91:6:0",
"typeDescriptions":
{
"typeIdentifier": "t_function_barecall_payable$_t_bytes_memory_ptr_$returns$_t_bool_$_t_bytes_memory_ptr_$",
"typeString": "function (bytes memory) payable returns (bool,bytes memory)"
}
},
"callcodeAst": {
"argumentTypes": [],
"expression":
{
"argumentTypes": null,
"id": 3,
"name": "test",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 10,
"src": "62:4:0",
"typeDescriptions":
{
"typeIdentifier": "t_type$_t_contract$_test_$10_$",
"typeString": "type(contract test)"
}
},
"id": 5,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "callcode",
"nodeType": "MemberAccess",
"referencedDeclaration": 9,
"src": "62:13:0",
"typeDescriptions":
{
"typeIdentifier": "t_function_internal_pure$__$returns$__$",
"typeString": "function () pure"
}
},
"delegatecallAst": {
"argumentTypes":
[
{
"typeIdentifier": "t_stringliteral_c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
"typeString": "literal_string \"\""
}
],
"expression":
{
"argumentTypes": null,
"id": 20,
"name": "addr",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4,
"src": "181:4:0",
"typeDescriptions":
{
"typeIdentifier": "t_address_payable",
"typeString": "address payable"
}
},
"id": 21,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "delegatecall",
"nodeType": "MemberAccess",
"referencedDeclaration": null,
"src": "181:17:0",
"typeDescriptions":
{
"typeIdentifier": "t_function_baredelegatecall_nonpayable$_t_bytes_memory_ptr_$returns$_t_bool_$_t_bytes_memory_ptr_$",
"typeString": "function (bytes memory) returns (bool,bytes memory)"
}
}
} }
\ No newline at end of file
{ {
"attributes": { "argumentTypes": null,
"arguments":
[
{
"argumentTypes": null, "argumentTypes": null,
"hexValue": "32",
"id": 37,
"isConstant": false, "isConstant": false,
"isLValue": false, "isLValue": false,
"isPure": false, "isPure": true,
"isStructConstructorCall": false, "kind": "number",
"lValueRequested": false, "lValueRequested": false,
"names": [ "nodeType": "Literal",
null "src": "234:1:0",
], "subdenomination": null,
"type": "uint256", "typeDescriptions":
"type_conversion": false {
"typeIdentifier": "t_rational_2_by_1",
"typeString": "int_const 2"
},
"value": "2"
}, },
"children": [ {
"argumentTypes": null,
"hexValue": "31",
"id": 38,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "240:1:0",
"subdenomination": null,
"typeDescriptions":
{ {
"attributes": { "typeIdentifier": "t_rational_1_by_1",
"argumentTypes": [ "typeString": "int_const 1"
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
],
"overloadedDeclarations": [
null
],
"referencedDeclaration": 25,
"type": "function (uint256,uint256) pure returns (uint256)",
"value": "f"
},
"id": 34,
"name": "Identifier",
"src": "267:1:0"
}, },
"value": "1"
}
],
"expression":
{
"argumentTypes":
[
{ {
"attributes": { "typeIdentifier": "t_rational_2_by_1",
"argumentTypes": null, "typeString": "int_const 2"
"overloadedDeclarations": [
null
],
"referencedDeclaration": 27,
"type": "uint256",
"value": "x"
},
"id": 35,
"name": "Identifier",
"src": "269:1:0"
}, },
{ {
"attributes": { "typeIdentifier": "t_rational_1_by_1",
"argumentTypes": null, "typeString": "int_const 1"
"overloadedDeclarations": [
null
],
"referencedDeclaration": 29,
"type": "uint256",
"value": "y"
},
"id": 36,
"name": "Identifier",
"src": "272:1:0"
} }
], ],
"id": 37, "id": 36,
"name": "FunctionCall", "name": "f",
"src": "267:7:0" "nodeType": "Identifier",
} "overloadedDeclarations":
\ No newline at end of file [
6,
14,
24
],
"referencedDeclaration": 14,
"src": "228:1:0",
"typeDescriptions":
{
"typeIdentifier": "t_function_internal_nonpayable$_t_uint256_$_t_uint256_$returns$__$",
"typeString": "function (uint256,uint256)"
}
},
"id": 39,
"isConstant": false,
"isLValue": false,
"isPure": false,
"kind": "functionCall",
"lValueRequested": false,
"names":
[
"y",
"x"
],
"nodeType": "FunctionCall",
"src": "228:15:0",
"tryCall": false,
"typeDescriptions":
{
"typeIdentifier": "t_tuple$__$",
"typeString": "tuple()"
}
}
\ No newline at end of file
{ {
"attributes": { "argumentTypes": null,
"type": "tuple()", "arguments":
"type_conversion": false [
}, {
"children": [ "argumentTypes": null,
{ "id": 6,
"attributes": { "name": "a",
"type": "function (address)", "nodeType": "Identifier",
"value": "selfdestruct" "overloadedDeclarations": [],
}, "referencedDeclaration": 2,
"name": "Identifier" "src": "77:1:0",
}, "typeDescriptions":
{ {
"attributes": { "typeIdentifier": "t_address_payable",
"type": "address", "typeString": "address payable"
"value": "a" }
}, }
"name": "Identifier" ],
} "expression":
], {
"name": "FunctionCall" "argumentTypes":
} [
\ No newline at end of file {
"typeIdentifier": "t_address_payable",
"typeString": "address payable"
}
],
"id": 5,
"name": "selfdestruct",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": -21,
"src": "64:12:0",
"typeDescriptions":
{
"typeIdentifier": "t_function_selfdestruct_nonpayable$_t_address_payable_$returns$__$",
"typeString": "function (address payable)"
}
},
"id": 7,
"isConstant": false,
"isLValue": false,
"isPure": false,
"kind": "functionCall",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "64:15:0",
"tryCall": false,
"typeDescriptions":
{
"typeIdentifier": "t_tuple$__$",
"typeString": "tuple()"
}
}
\ No newline at end of file
{ {
"attributes": { "argumentTypes": [],
"member_name": "duper", "expression":
"type": "function ()" {
}, "argumentTypes": null,
"children": [ "id": 10,
"name": "super",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": -25,
"src": "162:5:0",
"typeDescriptions":
{ {
"attributes": { "typeIdentifier": "t_super$_B_$17",
"type": "contract super a", "typeString": "contract super B"
"value": "super"
},
"name": "Identifier"
} }
], },
"name": "MemberAccess" "id": 12,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "x",
"nodeType": "MemberAccess",
"referencedDeclaration": 4,
"src": "162:7:0",
"typeDescriptions":
{
"typeIdentifier": "t_function_internal_pure$__$returns$__$",
"typeString": "function () pure"
}
} }
\ No newline at end of file
{ {
"name": "MemberAccess", "argumentTypes": null,
"children": [ { "expression":
"attributes": { {
"value": "this", "argumentTypes": null,
"type": "contract test" }, "id": 13,
"name": "Identifier" } ], "name": "this",
"attributes": { "nodeType": "Identifier",
"value": "b", "overloadedDeclarations": [],
"type": "function (bytes32,address) returns (bool)" } } "referencedDeclaration": -28,
\ No newline at end of file "src": "138:4:0",
"typeDescriptions":
{
"typeIdentifier": "t_contract$_C_$21",
"typeString": "contract C"
}
},
"id": 14,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "h",
"nodeType": "MemberAccess",
"referencedDeclaration": 4,
"src": "138:6:0",
"typeDescriptions":
{
"typeIdentifier": "t_function_external_payable$__$returns$__$",
"typeString": "function () payable external"
}
}
\ No newline at end of file
{ {
"children": "body":
[ {
"id": 13,
"nodeType": "Block",
"src": "89:27:0",
"statements":
[
{
"expression":
{
"argumentTypes": null,
"id": 9,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftHandSide":
{ {
"attributes": "argumentTypes": null,
"id": 7,
"name": "x",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4,
"src": "91:1:0",
"typeDescriptions":
{ {
"argumentTypes": null, "typeIdentifier": "t_uint256",
"commonType": "typeString": "uint256"
{ }
"typeIdentifier": "t_uint256", },
"typeString": "uint256" "nodeType": "Assignment",
}, "operator": "=",
"isConstant": false, "rightHandSide":
"isLValue": false, {
"isPure": false, "argumentTypes": null,
"lValueRequested": false, "hexValue": "31",
"operator": "<", "id": 8,
"type": "bool" "isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "95:1:0",
"subdenomination": null,
"typeDescriptions":
{
"typeIdentifier": "t_rational_1_by_1",
"typeString": "int_const 1"
}, },
"children": "value": "1"
[
{
"attributes":
{
"argumentTypes": null,
"overloadedDeclarations":
[
null
],
"referencedDeclaration": 45,
"type": "uint256",
"value": "i"
},
"id": 48,
"name": "Identifier",
"src": "372:1:0"
},
{
"attributes":
{
"argumentTypes": null,
"hexvalue": "3130",
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"subdenomination": null,
"token": "number",
"type": "int_const 10",
"value": "10"
},
"id": 49,
"name": "Literal",
"src": "376:2:0"
}
],
"id": 50,
"name": "BinaryOperation",
"src": "372:6:0"
}, },
"src": "91:5:0",
"typeDescriptions":
{ {
"children": "typeIdentifier": "t_uint256",
[ "typeString": "uint256"
{
"children":
[
{
"attributes":
{
"argumentTypes": null,
"isConstant": false,
"isLValue": false,
"isPure": false,
"isStructConstructorCall": false,
"lValueRequested": false,
"names":
[
null
],
"type": "uint256",
"type_conversion": false
},
"children":
[
{
"attributes":
{
"argumentTypes":
[
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
],
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"member_name": "push",
"referencedDeclaration": null,
"type": "function (uint256) returns (uint256)"
},
"children":
[
{
"attributes":
{
"argumentTypes": null,
"overloadedDeclarations":
[
null
],
"referencedDeclaration": 4,
"type": "uint256[] storage ref",
"value": "array"
},
"id": 51,
"name": "Identifier",
"src": "394:5:0"
}
],
"id": 53,
"name": "MemberAccess",
"src": "394:10:0"
},
{
"attributes":
{
"argumentTypes": null,
"overloadedDeclarations":
[
null
],
"referencedDeclaration": 45,
"type": "uint256",
"value": "i"
},
"id": 54,
"name": "Identifier",
"src": "405:1:0"
}
],
"id": 55,
"name": "FunctionCall",
"src": "394:13:0"
}
],
"id": 56,
"name": "ExpressionStatement",
"src": "394:13:0"
},
{
"children":
[
{
"attributes":
{
"argumentTypes": null,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"operator": "++",
"prefix": false,
"type": "uint256"
},
"children":
[
{
"attributes":
{
"argumentTypes": null,
"overloadedDeclarations":
[
null
],
"referencedDeclaration": 45,
"type": "uint256",
"value": "i"
},
"id": 57,
"name": "Identifier",
"src": "421:1:0"
}
],
"id": 58,
"name": "UnaryOperation",
"src": "421:3:0"
}
],
"id": 59,
"name": "ExpressionStatement",
"src": "421:3:0"
}
],
"id": 60,
"name": "Block",
"src": "380:55:0"
} }
], },
"id": 61, "id": 10,
"name": "WhileStatement", "nodeType": "ExpressionStatement",
"src": "365:70:0" "src": "91:5:0"
} },
\ No newline at end of file {
"id": 11,
"nodeType": "Break",
"src": "98:5:0"
},
{
"id": 12,
"nodeType": "Continue",
"src": "105:8:0"
}
]
},
"condition":
{
"argumentTypes": null,
"hexValue": "74727565",
"id": 6,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "bool",
"lValueRequested": false,
"nodeType": "Literal",
"src": "83:4:0",
"subdenomination": null,
"typeDescriptions":
{
"typeIdentifier": "t_bool",
"typeString": "bool"
},
"value": "true"
},
"id": 14,
"nodeType": "WhileStatement",
"src": "76:40:0"
}
\ No newline at end of file
pragma solidity >=0.4.9 <0.6.0; pragma solidity >=0.4.9 <0.7.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
...@@ -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 tests2() public {
this.register(10);
}
// 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