diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-06-22 04:50:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-22 04:50:30 +0800 |
commit | c7159b2be443ff3cc123472afbce9b443cdee2d5 (patch) | |
tree | b5c4949af009b301ce13539a8080eb60ccb4e2d6 /packages | |
parent | 2d98193c832958844579e1c44d2771f5b11b6dbf (diff) | |
parent | 4cf331067bfa2a99ea39551f9fb2ad330b1c3fb7 (diff) | |
download | dexon-0x-contracts-c7159b2be443ff3cc123472afbce9b443cdee2d5.tar dexon-0x-contracts-c7159b2be443ff3cc123472afbce9b443cdee2d5.tar.gz dexon-0x-contracts-c7159b2be443ff3cc123472afbce9b443cdee2d5.tar.bz2 dexon-0x-contracts-c7159b2be443ff3cc123472afbce9b443cdee2d5.tar.lz dexon-0x-contracts-c7159b2be443ff3cc123472afbce9b443cdee2d5.tar.xz dexon-0x-contracts-c7159b2be443ff3cc123472afbce9b443cdee2d5.tar.zst dexon-0x-contracts-c7159b2be443ff3cc123472afbce9b443cdee2d5.zip |
Merge pull request #747 from 0xProject/fix/sol-cov-bugs
Fix some bugs in sol-cov
Diffstat (limited to 'packages')
-rw-r--r-- | packages/sol-cov/src/revert_trace_subprovider.ts | 18 | ||||
-rw-r--r-- | packages/sol-cov/src/utils.ts | 12 |
2 files changed, 23 insertions, 7 deletions
diff --git a/packages/sol-cov/src/revert_trace_subprovider.ts b/packages/sol-cov/src/revert_trace_subprovider.ts index fb2215eaa..fed305bd3 100644 --- a/packages/sol-cov/src/revert_trace_subprovider.ts +++ b/packages/sol-cov/src/revert_trace_subprovider.ts @@ -75,6 +75,7 @@ export class RevertTraceSubprovider extends TraceCollectionSubprovider { } const bytecodeHex = stripHexPrefix(bytecode); const sourceMap = isContractCreation ? contractData.sourceMap : contractData.sourceMapRuntime; + const pcToSourceRange = parseSourceMap( contractData.sourceCodes, sourceMap, @@ -88,16 +89,19 @@ export class RevertTraceSubprovider extends TraceCollectionSubprovider { // actually happens in assembly). In that case, we want to keep // searching backwards by decrementing the pc until we find a // mapped source range. - while (_.isUndefined(sourceRange)) { + while (_.isUndefined(sourceRange) && pc > 0) { sourceRange = pcToSourceRange[pc]; pc -= 1; - if (pc <= 0) { - this._logger.warn( - `could not find matching sourceRange for structLog: ${evmCallStackEntry.structLog}`, - ); - continue; - } } + if (_.isUndefined(sourceRange)) { + this._logger.warn( + `could not find matching sourceRange for structLog: ${JSON.stringify( + _.omit(evmCallStackEntry.structLog, 'stack'), + )}`, + ); + continue; + } + const fileIndex = contractData.sources.indexOf(sourceRange.fileName); const sourceSnippet = getSourceRangeSnippet(sourceRange, contractData.sourceCodes[fileIndex]); if (sourceSnippet !== null) { diff --git a/packages/sol-cov/src/utils.ts b/packages/sol-cov/src/utils.ts index d31696636..b696bd463 100644 --- a/packages/sol-cov/src/utils.ts +++ b/packages/sol-cov/src/utils.ts @@ -5,6 +5,10 @@ import * as _ from 'lodash'; import { ContractData, LineColumn, SingleFileSourceRange } from './types'; +// This is the minimum length of valid contract bytecode. The Solidity compiler +// metadata is 86 bytes. If you add the '0x' prefix, we get 88. +const MIN_CONTRACT_BYTECODE_LENGTH = 88; + export const utils = { compareLineColumn(lhs: LineColumn, rhs: LineColumn): number { return lhs.line !== rhs.line ? lhs.line - rhs.line : lhs.column - rhs.column; @@ -38,7 +42,15 @@ export const utils = { } const contractData = _.find(contractsData, contractDataCandidate => { const bytecodeRegex = utils.bytecodeToBytecodeRegex(contractDataCandidate.bytecode); + // If the bytecode is less than the minimum length, we are probably + // dealing with an interface. This isn't what we're looking for. + if (bytecodeRegex.length < MIN_CONTRACT_BYTECODE_LENGTH) { + return false; + } const runtimeBytecodeRegex = utils.bytecodeToBytecodeRegex(contractDataCandidate.runtimeBytecode); + if (runtimeBytecodeRegex.length < MIN_CONTRACT_BYTECODE_LENGTH) { + return false; + } // We use that function to find by bytecode or runtimeBytecode. Those are quasi-random strings so // collisions are practically impossible and it allows us to reuse that code return !_.isNull(bytecode.match(bytecodeRegex)) || !_.isNull(bytecode.match(runtimeBytecodeRegex)); |