@1inch/solidity-utils 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/profileEVM.js +57 -15
- package/package.json +1 -1
package/js/profileEVM.js
CHANGED
|
@@ -1,23 +1,65 @@
|
|
|
1
1
|
const { promisify } = require('util');
|
|
2
2
|
const fs = require('fs').promises;
|
|
3
3
|
|
|
4
|
-
function _normalizeOp (
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
function _normalizeOp (ops, i) {
|
|
5
|
+
if (ops[i].op === 'STATICCALL') {
|
|
6
|
+
ops[i].gasCost = ops[i].gasCost - ops[i + 1].gas;
|
|
7
|
+
|
|
8
|
+
if (ops[i].stack.length > 8 && ops[i].stack[ops[i].stack.length - 8] === '0000000000000000000000000000000000000000000000000000000000000001') {
|
|
9
|
+
ops[i].op = 'STATICCALL-ECRECOVER';
|
|
10
|
+
} else if (ops[i].stack.length > 8 && ops[i].stack[ops[i].stack.length - 8] <= '00000000000000000000000000000000000000000000000000000000000000FF') {
|
|
11
|
+
ops[i].op = 'STATICCALL-' + ops[i].stack[ops[i].stack.length - 8].substr(62, 2);
|
|
12
12
|
} else {
|
|
13
|
-
|
|
13
|
+
ops[i].args = [
|
|
14
|
+
'0x' + ops[i].stack[ops[i].stack.length - 2].substr(24),
|
|
15
|
+
'0x' + (ops[i].memory || []).join('').substr(
|
|
16
|
+
2 * web3.utils.toBN(ops[i].stack[ops[i].stack.length - 3]).toNumber(),
|
|
17
|
+
2 * web3.utils.toBN(ops[i].stack[ops[i].stack.length - 4]).toNumber(),
|
|
18
|
+
),
|
|
19
|
+
];
|
|
20
|
+
if (ops[i].gasCost === 100) {
|
|
21
|
+
ops[i].op += '_R';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (['CALL', 'DELEGATECALL', 'CALLCODE'].indexOf(ops[i].op) !== -1) {
|
|
26
|
+
ops[i].args = [
|
|
27
|
+
'0x' + ops[i].stack[ops[i].stack.length - 2].substr(24),
|
|
28
|
+
'0x' + (ops[i].memory || []).join('').substr(
|
|
29
|
+
2 * web3.utils.toBN(ops[i].stack[ops[i].stack.length - 4]).toNumber(),
|
|
30
|
+
2 * web3.utils.toBN(ops[i].stack[ops[i].stack.length - 5]).toNumber(),
|
|
31
|
+
),
|
|
32
|
+
];
|
|
33
|
+
ops[i].gasCost = ops[i].gasCost - ops[i + 1].gas;
|
|
34
|
+
ops[i].res = ops[i + 1].stack[ops[i + 1].stack.length - 1];
|
|
35
|
+
|
|
36
|
+
if (ops[i].gasCost === 100) {
|
|
37
|
+
ops[i].op += '_R';
|
|
14
38
|
}
|
|
15
39
|
}
|
|
16
|
-
if (['
|
|
17
|
-
|
|
40
|
+
if (['RETURN', 'REVERT', 'INVALID'].indexOf(ops[i].op) !== -1) {
|
|
41
|
+
ops[i].gasCost = 3;
|
|
42
|
+
}
|
|
43
|
+
if (['SSTORE', 'SLOAD'].indexOf(ops[i].op) !== -1) {
|
|
44
|
+
ops[i].args = [
|
|
45
|
+
'0x' + ops[i].stack[ops[i].stack.length - 1],
|
|
46
|
+
];
|
|
47
|
+
if (ops[i].op === 'SSTORE') {
|
|
48
|
+
ops[i].args.push('0x' + ops[i].stack[ops[i].stack.length - 2]);
|
|
49
|
+
}
|
|
50
|
+
if (ops[i].gasCost === 100) {
|
|
51
|
+
ops[i].op += '_R';
|
|
52
|
+
}
|
|
53
|
+
if (ops[i].gasCost === 20000) {
|
|
54
|
+
ops[i].op += '_I';
|
|
55
|
+
}
|
|
56
|
+
ops[i].res = ops[i + 1].stack[ops[i + 1].stack.length - 1];
|
|
18
57
|
}
|
|
19
|
-
if ([
|
|
20
|
-
|
|
58
|
+
if (ops[i].op === 'EXTCODESIZE') {
|
|
59
|
+
ops[i].args = [
|
|
60
|
+
'0x' + ops[i].stack[ops[i].stack.length - 1].substr(24),
|
|
61
|
+
];
|
|
62
|
+
ops[i].res = ops[i + 1].stack[ops[i + 1].stack.length - 1];
|
|
21
63
|
}
|
|
22
64
|
}
|
|
23
65
|
|
|
@@ -55,9 +97,9 @@ async function gasspectEVM (txHash, options = {}, optionalTraceFile) {
|
|
|
55
97
|
const ops = trace.result.structLogs;
|
|
56
98
|
|
|
57
99
|
const traceAddress = [0, -1];
|
|
58
|
-
for (const op of ops) {
|
|
100
|
+
for (const [i, op] of ops.entries()) {
|
|
59
101
|
op.traceAddress = traceAddress.slice(0, traceAddress.length - 1);
|
|
60
|
-
_normalizeOp(
|
|
102
|
+
_normalizeOp(ops, i);
|
|
61
103
|
|
|
62
104
|
if (op.depth + 2 > traceAddress.length) {
|
|
63
105
|
traceAddress[traceAddress.length - 1] += 1;
|