Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Commit

Permalink
remove remix-lib dep from remix-analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed May 7, 2020
1 parent cae4c1d commit 3af34b2
Show file tree
Hide file tree
Showing 35 changed files with 25,802 additions and 28,384 deletions.
791 changes: 107 additions & 684 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"diff": "lerna diff",
"updated": "lerna updated",
"bootstrap": "npm run build-ts-packages; lerna bootstrap",
"bootstrap": "lerna bootstrap; npm run build-ts-packages",
"build-ts-packages": "lerna run --scope 'remix-analyzer' --scope 'remix-astwalker' --scope 'remix-solidity' --scope 'remix-tests' --scope 'remix-url-resolver' build",
"publish": "npm run build-ts-packages; lerna publish",
"release": "lerna bootstrap; lerna publish;",
Expand Down
3 changes: 1 addition & 2 deletions remix-analyzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
}
],
"dependencies": {
"remix-astwalker": "0.0.24",
"remix-lib": "0.4.29"
"remix-astwalker": "0.0.24"
},
"scripts": {
"build": "tsc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getDeclaredVariableName, getFullQuallyfiedFuncDefinitionIdent } from '.
import { default as algorithm } from './algorithmCategories'
import AbstractAst from './abstractAstView'
import { get } from 'fast-levenshtein'
import { util } from 'remix-lib'
import { escapeRegExp } from '../../util/helpers'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, ContractHLAst, FunctionHLAst, VariableDeclarationAstNode, VisitFunction, ReportFunction} from './../../types'

interface SimilarRecord {
Expand Down Expand Up @@ -73,7 +73,7 @@ export default class similarVariableNames implements AnalyzerModule {
}

private isCommonNrSuffixVersion (varName1: string, varName2: string): boolean {
const ref: string = '^' + util.escapeRegExp(varName1.slice(0, -1)) + '[0-9]*$'
const ref: string = '^' + escapeRegExp(varName1.slice(0, -1)) + '[0-9]*$'
return varName2.match(ref) != null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FunctionDefinitionAstNode, ModifierDefinitionAstNode, ParameterListAstN
WhileStatementAstNode, VariableDeclarationAstNode, ContractDefinitionAstNode, InheritanceSpecifierAstNode,
MemberAccessAstNode, BinaryOperationAstNode, FunctionCallAstNode, ExpressionStatementAstNode, UnaryOperationAstNode,
IdentifierAstNode, IndexAccessAstNode, BlockAstNode, AssignmentAstNode, InlineAssemblyAstNode, IfStatementAstNode } from "types"
import { util } from 'remix-lib'
import { concatWithSeperator, escapeRegExp } from '../../util/helpers'

type SpecialObjDetail = {
obj: string
Expand Down Expand Up @@ -439,7 +439,7 @@ function getFullQualifiedFunctionCallIdent (contract: ContractDefinitionAstNode,
}

function getFullQuallyfiedFuncDefinitionIdent (contract: ContractDefinitionAstNode, func: FunctionDefinitionAstNode, paramTypes: any[]): string {
return getContractName(contract) + '.' + getFunctionDefinitionName(func) + '(' + util.concatWithSeperator(paramTypes, ',') + ')'
return getContractName(contract) + '.' + getFunctionDefinitionName(func) + '(' + concatWithSeperator(paramTypes, ',') + ')'
}

function getUnAssignedTopLevelBinOps (subScope: BlockAstNode | IfStatementAstNode | WhileStatementAstNode | ForStatementAstNode): ExpressionStatementAstNode[] {
Expand Down Expand Up @@ -665,7 +665,7 @@ function isConstructor (node: FunctionDefinitionAstNode): boolean {
* @return {bool}
*/
function isIntDivision (node: BinaryOperationAstNode): boolean {
return operator(node, exactMatch(util.escapeRegExp('/'))) && typeDescription(node.rightExpression, util.escapeRegExp('int'))
return operator(node, exactMatch(escapeRegExp('/'))) && typeDescription(node.rightExpression, escapeRegExp('int'))
}

/**
Expand Down Expand Up @@ -863,7 +863,7 @@ function isLowLevelCall (node: MemberAccessAstNode): boolean {
*/
function isLLSend04 (node: MemberAccessAstNode): boolean {
return isMemberAccess(node,
exactMatch(util.escapeRegExp(lowLevelCallTypes.SEND.type)),
exactMatch(escapeRegExp(lowLevelCallTypes.SEND.type)),
undefined, exactMatch(basicTypes.ADDRESS), exactMatch(lowLevelCallTypes.SEND.ident))
}

Expand All @@ -874,7 +874,7 @@ function isLLSend04 (node: MemberAccessAstNode): boolean {
*/
function isLLSend (node: MemberAccessAstNode): boolean {
return isMemberAccess(node,
exactMatch(util.escapeRegExp(lowLevelCallTypes.SEND.type)),
exactMatch(escapeRegExp(lowLevelCallTypes.SEND.type)),
undefined, exactMatch(basicTypes.PAYABLE_ADDRESS), exactMatch(lowLevelCallTypes.SEND.ident))
}

Expand All @@ -885,10 +885,10 @@ function isLLSend (node: MemberAccessAstNode): boolean {
*/
function isLLCall (node: MemberAccessAstNode): boolean {
return isMemberAccess(node,
exactMatch(util.escapeRegExp(lowLevelCallTypes.CALL.type)),
exactMatch(escapeRegExp(lowLevelCallTypes.CALL.type)),
undefined, exactMatch(basicTypes.ADDRESS), exactMatch(lowLevelCallTypes.CALL.ident)) ||
isMemberAccess(node,
exactMatch(util.escapeRegExp(lowLevelCallTypes.CALL.type)),
exactMatch(escapeRegExp(lowLevelCallTypes.CALL.type)),
undefined, exactMatch(basicTypes.PAYABLE_ADDRESS), exactMatch(lowLevelCallTypes.CALL.ident))
}

Expand All @@ -899,7 +899,7 @@ function isLLCall (node: MemberAccessAstNode): boolean {
*/
function isLLCall04 (node: MemberAccessAstNode): boolean {
return isMemberAccess(node,
exactMatch(util.escapeRegExp(lowLevelCallTypes['CALL-0.4'].type)),
exactMatch(escapeRegExp(lowLevelCallTypes['CALL-0.4'].type)),
undefined, exactMatch(basicTypes.ADDRESS), exactMatch(lowLevelCallTypes['CALL-0.4'].ident))
}

Expand All @@ -910,7 +910,7 @@ function isLLCall04 (node: MemberAccessAstNode): boolean {
*/
function isLLCallcode (node: MemberAccessAstNode): boolean {
return isMemberAccess(node,
exactMatch(util.escapeRegExp(lowLevelCallTypes.CALLCODE.type)),
exactMatch(escapeRegExp(lowLevelCallTypes.CALLCODE.type)),
undefined, exactMatch(basicTypes.ADDRESS), exactMatch(lowLevelCallTypes.CALLCODE.ident))
}

Expand All @@ -921,7 +921,7 @@ function isLLCallcode (node: MemberAccessAstNode): boolean {
*/
function isLLDelegatecall (node: MemberAccessAstNode): boolean {
return isMemberAccess(node,
exactMatch(util.escapeRegExp(lowLevelCallTypes.DELEGATECALL.type)),
exactMatch(escapeRegExp(lowLevelCallTypes.DELEGATECALL.type)),
undefined, matches(basicTypes.PAYABLE_ADDRESS, basicTypes.ADDRESS), exactMatch(lowLevelCallTypes.DELEGATECALL.ident))
}

Expand All @@ -932,7 +932,7 @@ function isLLDelegatecall (node: MemberAccessAstNode): boolean {
*/
function isLLDelegatecall04 (node: MemberAccessAstNode): boolean {
return isMemberAccess(node,
exactMatch(util.escapeRegExp(lowLevelCallTypes['DELEGATECALL-0.4'].type)),
exactMatch(escapeRegExp(lowLevelCallTypes['DELEGATECALL-0.4'].type)),
undefined, matches(basicTypes.PAYABLE_ADDRESS, basicTypes.ADDRESS), exactMatch(lowLevelCallTypes['DELEGATECALL-0.4'].ident))
}

Expand All @@ -943,12 +943,12 @@ function isLLDelegatecall04 (node: MemberAccessAstNode): boolean {
*/
function isTransfer (node: MemberAccessAstNode): boolean {
return isMemberAccess(node,
exactMatch(util.escapeRegExp(lowLevelCallTypes.TRANSFER.type)),
exactMatch(escapeRegExp(lowLevelCallTypes.TRANSFER.type)),
undefined, matches(basicTypes.ADDRESS, basicTypes.PAYABLE_ADDRESS), exactMatch(lowLevelCallTypes.TRANSFER.ident))
}

function isStringToBytesConversion (node: FunctionCallAstNode): boolean {
return isExplicitCast(node, util.escapeRegExp('string *'), util.escapeRegExp('bytes'))
return isExplicitCast(node, escapeRegExp('string *'), escapeRegExp('bytes'))
}

function isExplicitCast (node: FunctionCallAstNode, castFromType: string, castToType: string): boolean {
Expand All @@ -958,7 +958,7 @@ function isExplicitCast (node: FunctionCallAstNode, castFromType: string, castTo
}

function isBytesLengthCheck (node: MemberAccessAstNode): boolean {
return isMemberAccess(node, exactMatch(util.escapeRegExp(basicTypes.UINT)), undefined, util.escapeRegExp('bytes *'), 'length')
return isMemberAccess(node, exactMatch(escapeRegExp(basicTypes.UINT)), undefined, escapeRegExp('bytes *'), 'length')
}

/**
Expand All @@ -985,7 +985,7 @@ function isMemberAccess (node: MemberAccessAstNode, retType: string, accessor: s
}

function isSpecialVariableAccess (node: MemberAccessAstNode, varType: SpecialObjDetail): boolean {
return isMemberAccess(node, exactMatch(util.escapeRegExp(varType.type)), varType.obj, varType.obj, varType.member)
return isMemberAccess(node, exactMatch(escapeRegExp(varType.type)), varType.obj, varType.obj, varType.member)
}

// #################### Node Identification Primitives
Expand Down Expand Up @@ -1061,11 +1061,11 @@ function findFirstSubNodeLTR (node: any, type: string): any {
* @return {Boolean} isPayable
*/
function buildFunctionSignature (paramTypes: any[], returnTypes: any[], isPayable: boolean, additionalMods?: any): string {
return 'function (' + util.concatWithSeperator(paramTypes, ',') + ')' + ((isPayable) ? ' payable' : '') + ((additionalMods) ? ' ' + additionalMods : '') + ((returnTypes.length) ? ' returns (' + util.concatWithSeperator(returnTypes, ',') + ')' : '')
return 'function (' + concatWithSeperator(paramTypes, ',') + ')' + ((isPayable) ? ' payable' : '') + ((additionalMods) ? ' ' + additionalMods : '') + ((returnTypes.length) ? ' returns (' + concatWithSeperator(returnTypes, ',') + ')' : '')
}

function buildAbiSignature (funName: string, paramTypes: any[]): string {
return funName + '(' + util.concatWithSeperator(paramTypes, ',') + ')'
return funName + '(' + concatWithSeperator(paramTypes, ',') + ')'
}

const helpers = {
Expand Down
19 changes: 19 additions & 0 deletions remix-analyzer/src/util/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

export const groupBy = (arr, key) => {
return arr.reduce((sum, item) => {
const groupByVal = item[key]
const groupedItems = sum[groupByVal] || []
groupedItems.push(item)
sum[groupByVal] = groupedItems
return sum
}, {})
}

export const concatWithSeperator = (list, seperator) => {
return list.reduce((sum, item) => sum + item + seperator, '').slice(0, -seperator.length)
}

export const escapeRegExp = (str) => {
return str.replace(/[-[\]/{}()+?.\\^$|]/g, '\\$&')
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { default as test} from "tape"
import { compilerInput } from '../util/compilerHelper'
import { compilerInput } from '../../src/util/compilerHelper'
import { readFileSync } from 'fs'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { default as test} from "tape"
import { compilerInput } from '../util/compilerHelper'
import { compilerInput } from '../../src/util/compilerHelper'
import { readFileSync } from 'fs'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { default as test} from "tape"
import { readFileSync } from 'fs'
import { compilerInput } from '../util/compilerHelper'
import { compilerInput } from '../../src/util/compilerHelper'
import { join } from 'path'
import { default as StatRunner } from '../../dist/src/solidity-analyzer'
import { CompilationResult, AnalysisReportObj, AnalysisReport, AnalyzerModule } from '../../src/types'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { checksEffectsInteraction } from '../../src/solidity-analyzer/modules/'
import { install, require as requireNPMmodule } from 'npm-install-version'
install('solc@0.5.0')
const compiler = requireNPMmodule('solc@0.5.0')
import { compilerInput } from '../util/compilerHelper'
import { compilerInput } from '../../src/util/compilerHelper'
const folder: string = 'solidity-v0.5'

function compile (fileName): CompilationResult {
Expand Down
2 changes: 2 additions & 0 deletions remix-analyzer/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('./util/test')

require('./analysis/staticAnalysisCommon-test')

require('./analysis/staticAnalysisIntegration-test-0.4.24')
Expand Down
43 changes: 43 additions & 0 deletions remix-analyzer/test/util/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'
import { default as test} from "tape"
import { concatWithSeperator, escapeRegExp, groupBy } from '../../src/util/helpers'

test('util.concatWithSeperator valid output', function (t) {
t.plan(4)
t.notEqual(concatWithSeperator(['a', 'b', 'c'], ','), 'a, b, c', 'Concat with comma should not produce spaces')
t.equal(concatWithSeperator(['a', 'b', 'c'], ','), 'a,b,c', 'Concat with comma should not produce spaces')
t.equal(concatWithSeperator(['a', 'b', 'c'], ', '), 'a, b, c', 'Concat with comma space should not produce trailing comma')
t.equal(concatWithSeperator(['a', 'b', 'c'], '+'), 'a+b+c', 'Concat with plus')
})

test('util.escapeRegExp', function (t) {
t.plan(3)
const original = 'function (uint256) returns (bool)'
t.equal(escapeRegExp('abcd'), 'abcd', 'String with no regex')
t.equal(escapeRegExp(original), 'function \\(uint256\\) returns \\(bool\\)', 'function string with regex')
t.ok(new RegExp(escapeRegExp(original)).test(original), 'should still test for original string')
})

test('util.groupBy on valid input', function (t) {
t.plan(1)

const result = groupBy([
{category: 'GAS', name: 'a'},
{category: 'SEC', name: 'b'},
{category: 'GAS', name: 'c'}

], 'category')

const expectedResult = {
'GAS': [
{category: 'GAS', name: 'a'},
{category: 'GAS', name: 'c'}
],
'SEC': [
{category: 'SEC', name: 'b'}
]
}

t.deepEqual(result, expectedResult)
})

2 changes: 1 addition & 1 deletion remix-analyzer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["src", "index.ts"],
"include": ["src", "index.ts", "test/util/test.ts"],
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
Expand Down
Loading

0 comments on commit 3af34b2

Please sign in to comment.