diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-23 06:14:07 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-23 06:27:18 +0800 |
commit | 6e0aef5f2bd8cd3ca9086abf4794028feac5ae9b (patch) | |
tree | 334b2d718487ca5fca6bb3c9c08abe25ef898517 | |
parent | 127b3e7d60aa5b5256d3d77aecf5efb239649957 (diff) | |
download | dexon-sol-tools-6e0aef5f2bd8cd3ca9086abf4794028feac5ae9b.tar dexon-sol-tools-6e0aef5f2bd8cd3ca9086abf4794028feac5ae9b.tar.gz dexon-sol-tools-6e0aef5f2bd8cd3ca9086abf4794028feac5ae9b.tar.bz2 dexon-sol-tools-6e0aef5f2bd8cd3ca9086abf4794028feac5ae9b.tar.lz dexon-sol-tools-6e0aef5f2bd8cd3ca9086abf4794028feac5ae9b.tar.xz dexon-sol-tools-6e0aef5f2bd8cd3ca9086abf4794028feac5ae9b.tar.zst dexon-sol-tools-6e0aef5f2bd8cd3ca9086abf4794028feac5ae9b.zip |
Fix depth tracking in a tracer
-rw-r--r-- | packages/sol-cov/src/trace.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/packages/sol-cov/src/trace.ts b/packages/sol-cov/src/trace.ts index 389bd8309..28fc7d004 100644 --- a/packages/sol-cov/src/trace.ts +++ b/packages/sol-cov/src/trace.ts @@ -25,7 +25,7 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress if (_.includes([OpCode.CallCode, OpCode.StaticCall, OpCode.Call, OpCode.DelegateCall], structLog.op)) { const currentAddress = _.last(callStack) as string; - const jumpAddressOffset = structLog.op === OpCode.DelegateCall ? 4 : 2; + const jumpAddressOffset = 1; const newAddress = addressUtils.padZeros( new BigNumber(addHexPrefix(structLog.stack[structLog.stack.length - jumpAddressOffset - 1])).toString( 16, @@ -65,6 +65,21 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress "Detected a contract created from within another contract. Sol-cov currently doesn't support that scenario. We'll just skip that trace", ); return traceByContractAddress; + } else { + if (structLog !== _.last(structLogs)) { + const nextStructLog = structLogs[i + 1]; + if (nextStructLog.depth === structLog.depth) { + continue; + } else if (nextStructLog.depth === structLog.depth - 1) { + const currentAddress = callStack.pop() as string; + traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat( + currentTraceSegment, + ); + currentTraceSegment = []; + } else { + throw new Error('Shit broke'); + } + } } } if (callStack.length !== 0) { |