solidity decoder imports updated

pull/5370/head
aniket-engg 4 years ago committed by Aniket
parent ff5f4a22b9
commit 0399445a79
  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' 'use strict'
const AddressType = require('./types/Address') import { Address as AddressType } from './types/Address'
const ArrayType = require('./types/ArrayType') import { ArrayType } from './types/ArrayType'
const BoolType = require('./types/Bool') import { Bool as BoolType } from './types/Bool'
const BytesType = require('./types/DynamicByteArray') import { DynamicByteArray as BytesType } from './types/DynamicByteArray'
const BytesXType = require('./types/FixedByteArray') import { FixedByteArray as BytesXType } from './types/FixedByteArray'
const EnumType = require('./types/Enum') import { Enum as EnumType } from './types/Enum'
const StringType = require('./types/StringType') import { StringType } from './types/StringType'
const StructType = require('./types/Struct') import { Struct as StructType } from './types/Struct'
const IntType = require('./types/Int') import { Int as IntType } from './types/Int'
const UintType = require('./types/Uint') import { Uint as UintType } from './types/Uint'
const MappingType = require('./types/Mapping') import { Mapping as MappingType } from './types/Mapping'
const util = require('./types/util') import { extractLocation, removeLocation } from './types/util'
/** /**
* mapping decode the given @arg type * mapping decode the given @arg type
@ -31,7 +31,7 @@ function mapping (type, stateDefinitions, contractName) {
'keyType': keyType, 'keyType': keyType,
'valueType': valueType '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) { function dynamicByteArray (type, stateDefinitions, contractName, location) {
if (!location) { if (!location) {
location = util.extractLocation(type) location = extractLocation(type)
} }
if (location) { if (location) {
return new BytesType(location) return new BytesType(location)
@ -120,7 +120,7 @@ function fixedByteArray (type) {
*/ */
function stringType (type, stateDefinitions, contractName, location) { function stringType (type, stateDefinitions, contractName, location) {
if (!location) { if (!location) {
location = util.extractLocation(type) location = extractLocation(type)
} }
if (location) { if (location) {
return new StringType(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) * @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) { function typeClass (fullType) {
fullType = util.removeLocation(fullType) fullType = removeLocation(fullType)
if (fullType.lastIndexOf(']') === fullType.length - 1) { if (fullType.lastIndexOf(']') === fullType.length - 1) {
return 'array' return 'array'
} }

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

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

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

Loading…
Cancel
Save