@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.
Files changed (2) hide show
  1. package/js/profileEVM.js +57 -15
  2. 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 (op) {
5
- if (op.op === 'STATICCALL') {
6
- if (op.stack.length > 8 && op.stack[op.stack.length - 8] === '0000000000000000000000000000000000000000000000000000000000000001') {
7
- op.gasCost = 700 + 3000;
8
- op.op = 'STATICCALL-ECRECOVER';
9
- } else if (op.stack.length > 8 && op.stack[op.stack.length - 8] <= '00000000000000000000000000000000000000000000000000000000000000FF') {
10
- op.gasCost = 700;
11
- op.op = 'STATICCALL-' + op.stack[op.stack.length - 8].substr(62, 2);
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
- op.gasCost = 700;
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 (['CALL', 'DELEGATECALL', 'CALLCODE'].indexOf(op.op) !== -1) {
17
- op.gasCost = 700;
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 (['RETURN', 'REVERT', 'INVALID'].indexOf(op.op) !== -1) {
20
- op.gasCost = 3;
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(op);
102
+ _normalizeOp(ops, i);
61
103
 
62
104
  if (op.depth + 2 > traceAddress.length) {
63
105
  traceAddress[traceAddress.length - 1] += 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1inch/solidity-utils",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",