solidity decoder imports updated

pull/697/head
aniket-engg 4 years ago committed by Aniket
parent 2dc8d11a56
commit 4c0a741791
  1. 32
      libs/remix-debug/src/solidity-decoder/decodeInfo.ts
  2. 8
      libs/remix-debug/src/solidity-decoder/index.ts
  3. 38
      libs/remix-debug/src/solidity-decoder/internalCallTree.ts
  4. 17
      libs/remix-debug/src/solidity-decoder/solidityProxy.ts

@ -1,17 +1,17 @@
'use strict'
const AddressType = require('./types/Address')
const ArrayType = require('./types/ArrayType')
const BoolType = require('./types/Bool')
const BytesType = require('./types/DynamicByteArray')
const BytesXType = require('./types/FixedByteArray')
const EnumType = require('./types/Enum')
const StringType = require('./types/StringType')
const StructType = require('./types/Struct')
const IntType = require('./types/Int')
const UintType = require('./types/Uint')
const MappingType = require('./types/Mapping')
const util = require('./types/util')
import { Address as AddressType } from './types/Address'
import { ArrayType } from './types/ArrayType'
import { Bool as BoolType } from './types/Bool'
import { DynamicByteArray as BytesType } from './types/DynamicByteArray'
import { FixedByteArray as BytesXType } from './types/FixedByteArray'
import { Enum as EnumType } from './types/Enum'
import { StringType } from './types/StringType'
import { Struct as StructType } from './types/Struct'
import { Int as IntType } from './types/Int'
import { Uint as UintType } from './types/Uint'
import { Mapping as MappingType } from './types/Mapping'
import { extractLocation, removeLocation } from './types/util'
/**
* mapping decode the given @arg type
@ -31,7 +31,7 @@ function mapping (type, stateDefinitions, contractName) {
'keyType': keyType,
'valueType': valueType
}
return new MappingType(underlyingTypes, 'location', util.removeLocation(type))
return new MappingType(underlyingTypes, 'location', removeLocation(type))
}
/**
@ -89,7 +89,7 @@ function bool (type) {
*/
function dynamicByteArray (type, stateDefinitions, contractName, location) {
if (!location) {
location = util.extractLocation(type)
location = extractLocation(type)
}
if (location) {
return new BytesType(location)
@ -120,7 +120,7 @@ function fixedByteArray (type) {
*/
function stringType (type, stateDefinitions, contractName, location) {
if (!location) {
location = util.extractLocation(type)
location = extractLocation(type)
}
if (location) {
return new StringType(location)
@ -265,7 +265,7 @@ function getStructMembers (type, stateDefinitions, contractName, location) {
* @return {String} returns the token type (used to instanciate the right decoder) (uint[2] storage ref[2] will return 'array', uint256 will return uintX)
*/
function typeClass (fullType) {
fullType = util.removeLocation(fullType)
fullType = removeLocation(fullType)
if (fullType.lastIndexOf(']') === fullType.length - 1) {
return 'array'
}

@ -1,6 +1,6 @@
const SolidityProxy = require('./solidityProxy')
const stateDecoder = require('./stateDecoder')
const localDecoder = require('./localDecoder')
const InternalCallTree = require('./internalCallTree')
import { SolidityProxy } from './solidityProxy'
import * as stateDecoder from './stateDecoder'
import * as localDecoder from './localDecoder'
import { InternalCallTree } from './internalCallTree'
export { SolidityProxy, stateDecoder, localDecoder, InternalCallTree }

@ -1,13 +1,11 @@
'use strict'
const { AstWalker } = require('@remix-project/remix-astwalker')
const remixLib = require('@remix-project/remix-lib')
const SourceLocationTracker = require('../source/sourceLocationTracker')
const EventManager = require('../eventManager')
const decodeInfo = require('./decodeInfo')
const util = remixLib.util
const traceHelper = require('../trace/traceHelper')
const typesUtil = require('./types/util.js')
import { AstWalker } from '@remix-project/remix-astwalker'
import { util } from '@remix-project/remix-lib'
import { SourceLocationTracker } from '../source/sourceLocationTracker'
import { EventManager } from '../eventManager'
import { parseType } from './decodeInfo'
import { isContractCreation, isCallInstruction, isCreateInstruction, isJumpDestInstruction } from '../trace/traceHelper'
import { extractLocationFromAstVariable } from './types/util.js'
/**
* Tree representing internal jump into function.
@ -54,7 +52,7 @@ export class InternalCallTree {
} else {
// each recursive call to buildTree represent a new context (either call, delegatecall, internal function)
const calledAddress = traceManager.getCurrentCalledAddressAt(0)
const isCreation = traceHelper.isContractCreation(calledAddress)
const isCreation = isContractCreation(calledAddress)
buildTree(this, 0, '', true, isCreation).then((result) => {
if (result.error) {
this.event.trigger('callTreeBuildFailed', [result.error])
@ -204,12 +202,12 @@ async function buildTree (tree, step, scopeId, isExternalCall, isCreation) {
if (!sourceLocation) {
return { outStep: step, error: 'InternalCallTree - No source Location. ' + step }
}
const isCallInstruction = traceHelper.isCallInstruction(tree.traceManager.trace[step])
const isCreateInstruction = traceHelper.isCreateInstruction(tree.traceManager.trace[step])
const isCallInstrn = isCallInstruction(tree.traceManager.trace[step])
const isCreateInstrn = isCreateInstruction(tree.traceManager.trace[step])
// we are checking if we are jumping in a new CALL or in an internal function
if (isCallInstruction || sourceLocation.jump === 'i') {
if (isCallInstrn || sourceLocation.jump === 'i') {
try {
const externalCallResult = await buildTree(tree, step + 1, scopeId === '' ? subScope.toString() : scopeId + '.' + subScope, isCallInstruction, isCreateInstruction)
const externalCallResult = await buildTree(tree, step + 1, scopeId === '' ? subScope.toString() : scopeId + '.' + subScope, isCallInstrn, isCreateInstrn)
if (externalCallResult.error) {
return { outStep: step, error: 'InternalCallTree - ' + externalCallResult.error }
} else {
@ -264,12 +262,12 @@ async function includeVariableDeclaration (tree, step, sourceLocation, scopeId,
// so, either this is the direct value, or the offset in memory. That depends on the type.
if (variableDeclaration.name !== '') {
states = tree.solidityProxy.extractStatesDefinitions()
var location = typesUtil.extractLocationFromAstVariable(variableDeclaration)
var location = extractLocationFromAstVariable(variableDeclaration)
location = location === 'default' ? 'storage' : location
// we push the new local variable in our tree
tree.scopes[scopeId].locals[variableDeclaration.name] = {
name: variableDeclaration.name,
type: decodeInfo.parseType(variableDeclaration.typeDescriptions.typeString, states, contractObj.name, location),
type: parseType(variableDeclaration.typeDescriptions.typeString, states, contractObj.name, location),
stackDepth: stack.length,
sourceLocation: sourceLocation
}
@ -283,8 +281,8 @@ async function includeVariableDeclaration (tree, step, sourceLocation, scopeId,
const functionDefinition = resolveFunctionDefinition(tree, previousSourceLocation, generatedSources)
if (!functionDefinition) return
const previousIsJumpDest2 = traceHelper.isJumpDestInstruction(tree.traceManager.trace[step - 2])
const previousIsJumpDest1 = traceHelper.isJumpDestInstruction(tree.traceManager.trace[step - 1])
const previousIsJumpDest2 = isJumpDestInstruction(tree.traceManager.trace[step - 2])
const previousIsJumpDest1 = isJumpDestInstruction(tree.traceManager.trace[step - 1])
const isConstructor = functionDefinition.kind === 'constructor'
if (newLocation && (previousIsJumpDest1 || previousIsJumpDest2 || isConstructor)) {
tree.functionCallStack.push(step)
@ -376,12 +374,12 @@ function addParams (parameterList, tree, scopeId, states, contractName, sourceLo
const param = parameterList.parameters[inputParam]
const stackDepth = stackLength + (dir * stackPosition)
if (stackDepth >= 0) {
let location = typesUtil.extractLocationFromAstVariable(param)
let location = extractLocationFromAstVariable(param)
location = location === 'default' ? 'memory' : location
const attributesName = param.name === '' ? `$${inputParam}` : param.name
tree.scopes[scopeId].locals[attributesName] = {
name: attributesName,
type: decodeInfo.parseType(param.typeDescriptions.typeString, states, contractName, location),
type: parseType(param.typeDescriptions.typeString, states, contractName, location),
stackDepth: stackDepth,
sourceLocation: sourceLocation
}

@ -1,9 +1,8 @@
'use strict'
const remixLib = require('@remix-project/remix-lib')
const traceHelper = require('../trace/traceHelper')
const stateDecoder = require('./stateDecoder')
const astHelper = require('./astHelper')
const util = remixLib.util
import { util } from '@remix-project/remix-lib'
import { isContractCreation } from '../trace/traceHelper'
import { extractStateVariables } from './stateDecoder'
import { extractContractDefinitions, extractStatesDefinitions } from './astHelper'
export class SolidityProxy {
@ -65,10 +64,10 @@ export class SolidityProxy {
*/
extractStatesDefinitions () {
if (!this.cache.contractDeclarations) {
this.cache.contractDeclarations = astHelper.extractContractDefinitions(this.sources)
this.cache.contractDeclarations = extractContractDefinitions(this.sources)
}
if (!this.cache.statesDefinitions) {
this.cache.statesDefinitions = astHelper.extractStatesDefinitions(this.sources, this.cache.contractDeclarations)
this.cache.statesDefinitions = extractStatesDefinitions(this.sources, this.cache.contractDeclarations)
}
return this.cache.statesDefinitions
}
@ -81,7 +80,7 @@ export class SolidityProxy {
*/
extractStateVariables (contractName) {
if (!this.cache.stateVariablesByContractName[contractName]) {
this.cache.stateVariablesByContractName[contractName] = stateDecoder.extractStateVariables(contractName, this.sources)
this.cache.stateVariablesByContractName[contractName] = extractStateVariables(contractName, this.sources)
}
return this.cache.stateVariablesByContractName[contractName]
}
@ -127,7 +126,7 @@ export class SolidityProxy {
}
function contractObjectFromCode (contracts, code, address) {
const isCreation = traceHelper.isContractCreation(address)
const isCreation = isContractCreation(address)
for (let file in contracts) {
for (let contract in contracts[file]) {
const bytecode = isCreation ? contracts[file][contract].evm.bytecode.object : contracts[file][contract].evm.deployedBytecode.object

Loading…
Cancel
Save