UNPKG

truffle-analyze

Version:

Add vulnerability and weakness analysis via the MythX

73 lines (63 loc) 1.77 kB
'use strict'; const path = require('path'); // Take truffle's build/contracts/xxx.json JSON and make it // compatible with the Mythril Platform API const truffle2MythXJSON = function(truffleJSON, toolId = 'truffle-analyze') { const { contractName, bytecode, deployedBytecode, sourceMap, deployedSourceMap, sourcePath, source, ast, compiler: { version }, } = truffleJSON; const sourcesKey = path.basename(sourcePath); return { contractName, bytecode, deployedBytecode, sourceMap, deployedSourceMap, sourceList: [ sourcePath ], sources: { [sourcesKey]: { source, ast, }, }, toolId, version, }; }; const remapMythXOutput = mythObject => { const mapped = mythObject.sourceList.map(source => ({ source, sourceType: mythObject.sourceType, sourceFormat: mythObject.sourceFormat, issues: [], })); if (mythObject.issues) { mythObject.issues.forEach(issue => { issue.locations.forEach(({ sourceMap }) => { // const sourceListIndex = sourceMap.split(':')[2]; // FIXME: Only one sourceList is supported. set to 0 mapped[0].issues.push({ swcID: issue.swcID, swcTitle: issue.swcTitle, description: issue.description, extra: issue.extra, severity: issue.severity, sourceMap, }); }); }); } return mapped; }; module.exports = { truffle2MythXJSON, remapMythXOutput, };