aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-05-23 04:21:44 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-05-23 06:27:17 +0800
commit06be580d2cbe7e3543d8c4deeb4d1c22b325e6a7 (patch)
tree0d18ddae918a3369bd83d84d3688063bc67e9549 /packages/sol-cov
parent6540343f456004549077f708f0d43533488fb4e4 (diff)
downloaddexon-sol-tools-06be580d2cbe7e3543d8c4deeb4d1c22b325e6a7.tar
dexon-sol-tools-06be580d2cbe7e3543d8c4deeb4d1c22b325e6a7.tar.gz
dexon-sol-tools-06be580d2cbe7e3543d8c4deeb4d1c22b325e6a7.tar.bz2
dexon-sol-tools-06be580d2cbe7e3543d8c4deeb4d1c22b325e6a7.tar.lz
dexon-sol-tools-06be580d2cbe7e3543d8c4deeb4d1c22b325e6a7.tar.xz
dexon-sol-tools-06be580d2cbe7e3543d8c4deeb4d1c22b325e6a7.tar.zst
dexon-sol-tools-06be580d2cbe7e3543d8c4deeb4d1c22b325e6a7.zip
Fix a bug in CALL-like opcode handling
Diffstat (limited to 'packages/sol-cov')
-rw-r--r--packages/sol-cov/src/trace.ts24
1 files changed, 17 insertions, 7 deletions
diff --git a/packages/sol-cov/src/trace.ts b/packages/sol-cov/src/trace.ts
index 81c8bb0ff..feebaaab5 100644
--- a/packages/sol-cov/src/trace.ts
+++ b/packages/sol-cov/src/trace.ts
@@ -13,7 +13,8 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
let currentTraceSegment = [];
const callStack = [startAddress];
// tslint:disable-next-line:prefer-for-of
- for (const structLog of structLogs) {
+ for (let i = 0; i < structLogs.length; i++) {
+ const structLog = structLogs[i];
if (structLog.depth !== callStack.length - 1) {
throw new Error("Malformed trace. trace depth doesn't match call stack depth");
}
@@ -26,13 +27,22 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
const currentAddress = _.last(callStack) as string;
const jumpAddressOffset = structLog.op === OpCode.DelegateCall ? 4 : 2;
const newAddress = addressUtils.padZeros(
- new BigNumber(addHexPrefix(structLog.stack[jumpAddressOffset])).toString(16),
+ new BigNumber(addHexPrefix(structLog.stack[structLog.stack.length - jumpAddressOffset])).toString(16),
);
- callStack.push(newAddress);
- traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
- currentTraceSegment,
- );
- currentTraceSegment = [];
+ if (structLog === _.last(structLogs)) {
+ throw new Error('CALL-like opcode can not be the last one');
+ }
+ // Sometimes calls don't change the execution context (current address). When we do a transfer to an
+ // externally owned account - it does the call and immidiately returns because there is no fallback
+ // function. We manually check if the call depth had changed to handle that case.
+ const nextStructLog = structLogs[i + 1];
+ if (nextStructLog.depth !== structLog.depth) {
+ callStack.push(newAddress);
+ traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
+ currentTraceSegment,
+ );
+ currentTraceSegment = [];
+ }
} else if (
_.includes([OpCode.Return, OpCode.Stop, OpCode.Revert, OpCode.Invalid, OpCode.SelfDestruct], structLog.op)
) {