@feelyourprotocol/vm 8141.0.0

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 (115) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +583 -0
  3. package/dist/cjs/bloom/index.d.ts +29 -0
  4. package/dist/cjs/bloom/index.d.ts.map +1 -0
  5. package/dist/cjs/bloom/index.js +76 -0
  6. package/dist/cjs/bloom/index.js.map +1 -0
  7. package/dist/cjs/buildBlock.d.ts +118 -0
  8. package/dist/cjs/buildBlock.d.ts.map +1 -0
  9. package/dist/cjs/buildBlock.js +363 -0
  10. package/dist/cjs/buildBlock.js.map +1 -0
  11. package/dist/cjs/constructors.d.ts +9 -0
  12. package/dist/cjs/constructors.d.ts.map +1 -0
  13. package/dist/cjs/constructors.js +75 -0
  14. package/dist/cjs/constructors.js.map +1 -0
  15. package/dist/cjs/emitEVMProfile.d.ts +9 -0
  16. package/dist/cjs/emitEVMProfile.d.ts.map +1 -0
  17. package/dist/cjs/emitEVMProfile.js +130 -0
  18. package/dist/cjs/emitEVMProfile.js.map +1 -0
  19. package/dist/cjs/index.d.ts +11 -0
  20. package/dist/cjs/index.d.ts.map +1 -0
  21. package/dist/cjs/index.js +36 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/cjs/package.json +3 -0
  24. package/dist/cjs/params.d.ts +3 -0
  25. package/dist/cjs/params.d.ts.map +1 -0
  26. package/dist/cjs/params.js +105 -0
  27. package/dist/cjs/params.js.map +1 -0
  28. package/dist/cjs/requests.d.ts +11 -0
  29. package/dist/cjs/requests.d.ts.map +1 -0
  30. package/dist/cjs/requests.js +208 -0
  31. package/dist/cjs/requests.js.map +1 -0
  32. package/dist/cjs/runBlock.d.ts +35 -0
  33. package/dist/cjs/runBlock.d.ts.map +1 -0
  34. package/dist/cjs/runBlock.js +797 -0
  35. package/dist/cjs/runBlock.js.map +1 -0
  36. package/dist/cjs/runFrameTx.d.ts +18 -0
  37. package/dist/cjs/runFrameTx.d.ts.map +1 -0
  38. package/dist/cjs/runFrameTx.js +313 -0
  39. package/dist/cjs/runFrameTx.js.map +1 -0
  40. package/dist/cjs/runTx.d.ts +18 -0
  41. package/dist/cjs/runTx.d.ts.map +1 -0
  42. package/dist/cjs/runTx.js +900 -0
  43. package/dist/cjs/runTx.js.map +1 -0
  44. package/dist/cjs/types.d.ts +452 -0
  45. package/dist/cjs/types.d.ts.map +1 -0
  46. package/dist/cjs/types.js +3 -0
  47. package/dist/cjs/types.js.map +1 -0
  48. package/dist/cjs/vm.d.ts +75 -0
  49. package/dist/cjs/vm.d.ts.map +1 -0
  50. package/dist/cjs/vm.js +111 -0
  51. package/dist/cjs/vm.js.map +1 -0
  52. package/dist/esm/bloom/index.d.ts +29 -0
  53. package/dist/esm/bloom/index.d.ts.map +1 -0
  54. package/dist/esm/bloom/index.js +72 -0
  55. package/dist/esm/bloom/index.js.map +1 -0
  56. package/dist/esm/buildBlock.d.ts +118 -0
  57. package/dist/esm/buildBlock.d.ts.map +1 -0
  58. package/dist/esm/buildBlock.js +358 -0
  59. package/dist/esm/buildBlock.js.map +1 -0
  60. package/dist/esm/constructors.d.ts +9 -0
  61. package/dist/esm/constructors.d.ts.map +1 -0
  62. package/dist/esm/constructors.js +72 -0
  63. package/dist/esm/constructors.js.map +1 -0
  64. package/dist/esm/emitEVMProfile.d.ts +9 -0
  65. package/dist/esm/emitEVMProfile.d.ts.map +1 -0
  66. package/dist/esm/emitEVMProfile.js +127 -0
  67. package/dist/esm/emitEVMProfile.js.map +1 -0
  68. package/dist/esm/index.d.ts +11 -0
  69. package/dist/esm/index.d.ts.map +1 -0
  70. package/dist/esm/index.js +11 -0
  71. package/dist/esm/index.js.map +1 -0
  72. package/dist/esm/package.json +3 -0
  73. package/dist/esm/params.d.ts +3 -0
  74. package/dist/esm/params.d.ts.map +1 -0
  75. package/dist/esm/params.js +102 -0
  76. package/dist/esm/params.js.map +1 -0
  77. package/dist/esm/requests.d.ts +11 -0
  78. package/dist/esm/requests.d.ts.map +1 -0
  79. package/dist/esm/requests.js +204 -0
  80. package/dist/esm/requests.js.map +1 -0
  81. package/dist/esm/runBlock.d.ts +35 -0
  82. package/dist/esm/runBlock.d.ts.map +1 -0
  83. package/dist/esm/runBlock.js +790 -0
  84. package/dist/esm/runBlock.js.map +1 -0
  85. package/dist/esm/runFrameTx.d.ts +18 -0
  86. package/dist/esm/runFrameTx.d.ts.map +1 -0
  87. package/dist/esm/runFrameTx.js +310 -0
  88. package/dist/esm/runFrameTx.js.map +1 -0
  89. package/dist/esm/runTx.d.ts +18 -0
  90. package/dist/esm/runTx.d.ts.map +1 -0
  91. package/dist/esm/runTx.js +896 -0
  92. package/dist/esm/runTx.js.map +1 -0
  93. package/dist/esm/types.d.ts +452 -0
  94. package/dist/esm/types.d.ts.map +1 -0
  95. package/dist/esm/types.js +2 -0
  96. package/dist/esm/types.js.map +1 -0
  97. package/dist/esm/vm.d.ts +75 -0
  98. package/dist/esm/vm.d.ts.map +1 -0
  99. package/dist/esm/vm.js +107 -0
  100. package/dist/esm/vm.js.map +1 -0
  101. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
  102. package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
  103. package/package.json +117 -0
  104. package/src/bloom/index.ts +83 -0
  105. package/src/buildBlock.ts +470 -0
  106. package/src/constructors.ts +91 -0
  107. package/src/emitEVMProfile.ts +151 -0
  108. package/src/index.ts +10 -0
  109. package/src/params.ts +104 -0
  110. package/src/requests.ts +293 -0
  111. package/src/runBlock.ts +1022 -0
  112. package/src/runFrameTx.ts +411 -0
  113. package/src/runTx.ts +1203 -0
  114. package/src/types.ts +511 -0
  115. package/src/vm.ts +147 -0
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createVM = createVM;
4
+ const common_1 = require("@feelyourprotocol/common");
5
+ const evm_1 = require("@feelyourprotocol/evm");
6
+ const statemanager_1 = require("@feelyourprotocol/statemanager");
7
+ const util_1 = require("@feelyourprotocol/util");
8
+ const vm_ts_1 = require("./vm.js");
9
+ /**
10
+ * VM async constructor. Creates engine instance and initializes it.
11
+ *
12
+ * @param opts VM engine constructor options
13
+ */
14
+ async function createVM(opts = {}) {
15
+ // Save if a `StateManager` was passed (for activatePrecompiles)
16
+ const didPassStateManager = opts.stateManager !== undefined;
17
+ // Add common, SM, blockchain, EVM here
18
+ if (opts.common === undefined) {
19
+ opts.common = new common_1.Common({ chain: common_1.Mainnet });
20
+ }
21
+ if (opts.stateManager === undefined) {
22
+ opts.stateManager = new statemanager_1.MerkleStateManager({
23
+ common: opts.common,
24
+ });
25
+ }
26
+ if (opts.blockchain === undefined) {
27
+ opts.blockchain = new evm_1.EVMMockBlockchain();
28
+ }
29
+ if (opts.profilerOpts !== undefined) {
30
+ const profilerOpts = opts.profilerOpts;
31
+ if (profilerOpts.reportAfterBlock === true && profilerOpts.reportAfterTx === true) {
32
+ throw (0, util_1.EthereumJSErrorWithoutCode)('Cannot have `reportProfilerAfterBlock` and `reportProfilerAfterTx` set to `true` at the same time');
33
+ }
34
+ }
35
+ if (opts.evm !== undefined && opts.evmOpts !== undefined) {
36
+ throw (0, util_1.EthereumJSErrorWithoutCode)('the evm and evmOpts options cannot be used in conjunction');
37
+ }
38
+ if (opts.evm === undefined) {
39
+ let enableProfiler = false;
40
+ if (opts.profilerOpts?.reportAfterBlock === true || opts.profilerOpts?.reportAfterTx === true) {
41
+ enableProfiler = true;
42
+ }
43
+ const evmOpts = opts.evmOpts ?? {};
44
+ opts.evm = await (0, evm_1.createEVM)({
45
+ common: opts.common,
46
+ stateManager: opts.stateManager,
47
+ blockchain: opts.blockchain,
48
+ profiler: {
49
+ enabled: enableProfiler,
50
+ },
51
+ ...evmOpts,
52
+ });
53
+ }
54
+ if (opts.activatePrecompiles === true && !didPassStateManager) {
55
+ await opts.evm.journal.checkpoint();
56
+ // put 1 wei in each of the precompiles in order to make the accounts non-empty and thus not have them deduct `callNewAccount` gas.
57
+ for (const [addressStr] of (0, evm_1.getActivePrecompiles)(opts.common)) {
58
+ const address = new util_1.Address((0, util_1.unprefixedHexToBytes)(addressStr));
59
+ let account = await opts.evm.stateManager.getAccount(address);
60
+ // Only do this if it is not overridden in genesis
61
+ // Note: in the case that custom genesis has storage fields, this is preserved
62
+ if (account === undefined) {
63
+ account = new util_1.Account();
64
+ const newAccount = (0, util_1.createAccount)({
65
+ balance: 1,
66
+ storageRoot: account.storageRoot,
67
+ });
68
+ await opts.evm.stateManager.putAccount(address, newAccount);
69
+ }
70
+ }
71
+ await opts.evm.journal.commit();
72
+ }
73
+ return new vm_ts_1.VM(opts);
74
+ }
75
+ //# sourceMappingURL=constructors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constructors.js","sourceRoot":"","sources":["../../src/constructors.ts"],"names":[],"mappings":";;AAoBA,4BAsEC;AA1FD,+CAAoD;AACpD,yCAAoF;AACpF,2DAA6D;AAC7D,2CAMyB;AAEzB,mCAA4B;AAI5B;;;;GAIG;AACI,KAAK,UAAU,QAAQ,CAAC,OAAe,EAAE;IAC9C,gEAAgE;IAChE,MAAM,mBAAmB,GAAG,IAAI,CAAC,YAAY,KAAK,SAAS,CAAA;IAE3D,uCAAuC;IACvC,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,KAAK,EAAE,gBAAO,EAAE,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,IAAI,iCAAkB,CAAC;YACzC,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,IAAI,uBAAiB,EAAE,CAAA;IAC3C,CAAC;IAED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AC,EAAE,CAAC;YAC7D,MAAM,OAAO,GAAG,IAAI,cAAO,CAAC,IAAA,2BAAoB,EAAC,UAAU,CAAC,CAAC,CAAA;YAC7D,IAAI,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;YAC7D,kDAAkD;YAClD,8EAA8E;YAC9E,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,OAAO,GAAG,IAAI,cAAO,EAAE,CAAA;gBACvB,MAAM,UAAU,GAAG,IAAA,oBAAa,EAAC;oBAC/B,OAAO,EAAE,CAAC;oBACV,WAAW,EAAE,OAAO,CAAC,WAAW;iBACjC,CAAC,CAAA;gBACF,MAAM,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;YAC7D,CAAC;QACH,CAAC;QACD,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,CAAA;IACjC,CAAC;IAED,OAAO,IAAI,UAAE,CAAC,IAAI,CAAC,CAAA;AACrB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { EVMPerformanceLogOutput } from '@feelyourprotocol/evm';
2
+ /**
3
+ * Emit EVM profile logs
4
+ * @param logs
5
+ * @param profileTitle
6
+ * @hidden
7
+ */
8
+ export declare function emitEVMProfile(logs: EVMPerformanceLogOutput[], profileTitle: string): void;
9
+ //# sourceMappingURL=emitEVMProfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitEVMProfile.d.ts","sourceRoot":"","sources":["../../src/emitEVMProfile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAE9D;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,uBAAuB,EAAE,EAAE,YAAY,EAAE,MAAM,QA8InF"}
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitEVMProfile = emitEVMProfile;
4
+ /**
5
+ * Emit EVM profile logs
6
+ * @param logs
7
+ * @param profileTitle
8
+ * @hidden
9
+ */
10
+ function emitEVMProfile(logs, profileTitle) {
11
+ if (logs.length === 0) {
12
+ return;
13
+ }
14
+ // Track total calls / time (ms) / gas
15
+ let calls = 0;
16
+ let totalMs = 0;
17
+ let totalGas = 0;
18
+ // Order of columns to report (see `EVMPerformanceLogOutput` type)
19
+ const colOrder = [
20
+ 'tag',
21
+ 'calls',
22
+ 'avgTimePerCall',
23
+ 'totalTime',
24
+ 'staticGasUsed',
25
+ 'dynamicGasUsed',
26
+ 'gasUsed',
27
+ 'staticGas',
28
+ 'millionGasPerSecond',
29
+ 'blocksPerSlot',
30
+ ];
31
+ // The name of this column to report (saves space)
32
+ const colNames = [
33
+ 'tag',
34
+ 'calls',
35
+ 'ms/call',
36
+ 'total (ms)',
37
+ 'sgas',
38
+ 'dgas',
39
+ 'total (s+d)',
40
+ 'static fee',
41
+ 'Mgas/s',
42
+ 'BpS',
43
+ ];
44
+ // Special padStr method which inserts whitespace left and right
45
+ // This ensures that there is at least one whitespace between the columns (denoted by pipe `|` chars)
46
+ function padStr(str, leftpad) {
47
+ return ' ' + str.toString().padStart(leftpad, ' ') + ' ';
48
+ }
49
+ // Returns the string length of this column. Used to calculate how big the header / footer should be
50
+ function strLen(str) {
51
+ return padStr(str, 0).length - 2;
52
+ }
53
+ // Step one: calculate the length of each column
54
+ const colLength = [];
55
+ for (const entry of logs) {
56
+ let ins = 0;
57
+ colLength[ins] = Math.max(colLength[ins] ?? 0, strLen(colNames[ins]));
58
+ for (const key of colOrder) {
59
+ if (entry[key] !== undefined) {
60
+ // If entry is available, max out the current column length (this will be the longest string of this column)
61
+ colLength[ins] = Math.max(colLength[ins] ?? 0, strLen(entry[key]));
62
+ ins++;
63
+ // In this switch statement update the total calls / time / gas used
64
+ switch (key) {
65
+ case 'calls':
66
+ calls += entry[key];
67
+ break;
68
+ case 'totalTime':
69
+ totalMs += entry[key];
70
+ break;
71
+ case 'gasUsed':
72
+ totalGas += entry[key];
73
+ break;
74
+ }
75
+ }
76
+ }
77
+ }
78
+ // Ensure that the column names also fit on the column length
79
+ for (const i in colLength) {
80
+ colLength[i] = Math.max(colLength[i] ?? 0, strLen(colNames[i]));
81
+ }
82
+ // Calculate the total header length
83
+ // This is done by summing all columns together, plus adding three extra chars per column (two whitespace, one pipe)
84
+ // Remove the final pipe character since this is included in the header string (so subtract one)
85
+ const headerLength = colLength.reduce((pv, cv) => pv + cv, 0) + colLength.length * 3 - 1;
86
+ const blockGasLimit = 30000000; // Block gas limit
87
+ const slotTime = 12000; // Time in milliseconds (!) per slot
88
+ // Normalize constant to check if execution time is above one block per slot (>=1) or not (<1)
89
+ const bpsNormalizer = blockGasLimit / slotTime;
90
+ const avgGas = totalGas / totalMs; // Gas per millisecond
91
+ const mGasSAvg = Math.round(avgGas) / 1e3;
92
+ const bpSAvg = Math.round((avgGas / bpsNormalizer) * 1e3) / 1e3;
93
+ // Write the profile title
94
+ // eslint-disable-next-line
95
+ console.log('+== ' + profileTitle + ' ==+');
96
+ // Write the summary of this profile
97
+ // eslint-disable-next-line
98
+ console.log(`+== Calls: ${calls}, Total time: ${Math.round(totalMs * 1e3) / 1e3}ms, Total gas: ${totalGas}, MGas/s: ${mGasSAvg}, Blocks per Slot (BpS): ${bpSAvg} ==+`);
99
+ // Generate and write the header
100
+ const header = '|' + '-'.repeat(headerLength) + '|';
101
+ // eslint-disable-next-line
102
+ console.log(header);
103
+ // Write the columns
104
+ let str = '';
105
+ for (const i in colLength) {
106
+ str += '|' + padStr(colNames[i], colLength[i]);
107
+ }
108
+ str += '|';
109
+ // eslint-disable-next-line
110
+ console.log(str);
111
+ // Write each profile entry
112
+ for (const entry of logs) {
113
+ let str = '';
114
+ let i = 0;
115
+ for (const key of colOrder) {
116
+ if (entry[key] !== undefined) {
117
+ str += '|' + padStr(entry[key], colLength[i]);
118
+ i++;
119
+ }
120
+ }
121
+ str += '|';
122
+ // eslint-disable-next-line
123
+ console.log(str);
124
+ }
125
+ // Finally, write the footer
126
+ const footer = '+' + '-'.repeat(headerLength) + '+';
127
+ // eslint-disable-next-line
128
+ console.log(footer);
129
+ }
130
+ //# sourceMappingURL=emitEVMProfile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitEVMProfile.js","sourceRoot":"","sources":["../../src/emitEVMProfile.ts"],"names":[],"mappings":";;AAQA,wCA8IC;AApJD;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,IAA+B,EAAE,YAAoB;IAClF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAM;IACR,CAAC;IAED,sCAAsC;IAEtC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,IAAI,QAAQ,GAAG,CAAC,CAAA;IAEhB,kEAAkE;IAElE,MAAM,QAAQ,GAAsC;QAClD,KAAK;QACL,OAAO;QACP,gBAAgB;QAChB,WAAW;QACX,eAAe;QACf,gBAAgB;QAChB,SAAS;QACT,WAAW;QACX,qBAAqB;QACrB,eAAe;KAChB,CAAA;IAED,kDAAkD;IAClD,MAAM,QAAQ,GAAG;QACf,KAAK;QACL,OAAO;QACP,SAAS;QACT,YAAY;QACZ,MAAM;QACN,MAAM;QACN,aAAa;QACb,YAAY;QACZ,QAAQ;QACR,KAAK;KACN,CAAA;IAED,gEAAgE;IAChE,qGAAqG;IACrG,SAAS,MAAM,CAAC,GAAoB,EAAE,OAAe;QACnD,OAAO,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,GAAG,CAAA;IAC1D,CAAC;IACD,oGAAoG;IACpG,SAAS,MAAM,CAAC,GAAoB;QAClC,OAAO,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;IACl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CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IAChD,CAAC;IACD,GAAG,IAAI,GAAG,CAAA;IAEV,2BAA2B;IAC3B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAEhB,2BAA2B;IAC3B,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,IAAI,GAAG,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAC3B,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC7B,GAAG,IAAI,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAE,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;gBAC9C,CAAC,EAAE,CAAA;YACL,CAAC;QACH,CAAC;QACD,GAAG,IAAI,GAAG,CAAA;QACV,2BAA2B;QAC3B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAClB,CAAC;IAED,4BAA4B;IAC5B,MAAM,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,GAAG,CAAA;IACnD,2BAA2B;IAC3B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACrB,CAAC"}
@@ -0,0 +1,11 @@
1
+ export { Bloom } from './bloom/index.ts';
2
+ export { BlockBuilder, BuildStatus } from './buildBlock.ts';
3
+ export { buildBlock } from './buildBlock.ts';
4
+ export * from './constructors.ts';
5
+ export * from './params.ts';
6
+ export { encodeReceipt } from './runBlock.ts';
7
+ export { runBlock } from './runBlock.ts';
8
+ export { runTx } from './runTx.ts';
9
+ export * from './types.ts';
10
+ export { VM } from './vm.ts';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.VM = exports.runTx = exports.runBlock = exports.encodeReceipt = exports.buildBlock = exports.BuildStatus = exports.BlockBuilder = exports.Bloom = void 0;
18
+ var index_ts_1 = require("./bloom/index.js");
19
+ Object.defineProperty(exports, "Bloom", { enumerable: true, get: function () { return index_ts_1.Bloom; } });
20
+ var buildBlock_ts_1 = require("./buildBlock.js");
21
+ Object.defineProperty(exports, "BlockBuilder", { enumerable: true, get: function () { return buildBlock_ts_1.BlockBuilder; } });
22
+ Object.defineProperty(exports, "BuildStatus", { enumerable: true, get: function () { return buildBlock_ts_1.BuildStatus; } });
23
+ var buildBlock_ts_2 = require("./buildBlock.js");
24
+ Object.defineProperty(exports, "buildBlock", { enumerable: true, get: function () { return buildBlock_ts_2.buildBlock; } });
25
+ __exportStar(require("./constructors.js"), exports);
26
+ __exportStar(require("./params.js"), exports);
27
+ var runBlock_ts_1 = require("./runBlock.js");
28
+ Object.defineProperty(exports, "encodeReceipt", { enumerable: true, get: function () { return runBlock_ts_1.encodeReceipt; } });
29
+ var runBlock_ts_2 = require("./runBlock.js");
30
+ Object.defineProperty(exports, "runBlock", { enumerable: true, get: function () { return runBlock_ts_2.runBlock; } });
31
+ var runTx_ts_1 = require("./runTx.js");
32
+ Object.defineProperty(exports, "runTx", { enumerable: true, get: function () { return runTx_ts_1.runTx; } });
33
+ __exportStar(require("./types.js"), exports);
34
+ var vm_ts_1 = require("./vm.js");
35
+ Object.defineProperty(exports, "VM", { enumerable: true, get: function () { return vm_ts_1.VM; } });
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAAwC;AAA/B,iGAAA,KAAK,OAAA;AACd,iDAA2D;AAAlD,6GAAA,YAAY,OAAA;AAAE,4GAAA,WAAW,OAAA;AAClC,iDAA4C;AAAnC,2GAAA,UAAU,OAAA;AACnB,oDAAiC;AACjC,8CAA2B;AAC3B,6CAA6C;AAApC,4GAAA,aAAa,OAAA;AACtB,6CAAwC;AAA/B,uGAAA,QAAQ,OAAA;AACjB,uCAAkC;AAAzB,iGAAA,KAAK,OAAA;AACd,6CAA0B;AAC1B,iCAA4B;AAAnB,2FAAA,EAAE,OAAA"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,3 @@
1
+ import type { ParamsDict } from '@feelyourprotocol/common';
2
+ export declare const paramsVM: ParamsDict;
3
+ //# sourceMappingURL=params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAGpD,eAAO,MAAM,QAAQ,EAAE,UAoGtB,CAAA"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.paramsVM = void 0;
4
+ const util_1 = require("@feelyourprotocol/util");
5
+ exports.paramsVM = {
6
+ /**
7
+ * Frontier/Chainstart
8
+ */
9
+ 1: {
10
+ // gasConfig
11
+ maxRefundQuotient: 2, // Maximum refund quotient; max tx refund is min(tx.gasUsed/maxRefundQuotient, tx.gasRefund)
12
+ blobGasPerBlob: 0,
13
+ maxBlobGasPerBlock: 0,
14
+ targetBlobGasPerBlock: 0,
15
+ // pow
16
+ minerReward: '5000000000000000000', // the amount a miner get rewarded for mining a block
17
+ },
18
+ /**
19
+ . * Byzantium HF Meta EIP
20
+ . */
21
+ 609: {
22
+ // pow
23
+ minerReward: '3000000000000000000', // the amount a miner get rewarded for mining a block
24
+ },
25
+ /**
26
+ . * Constantinople HF Meta EIP
27
+ . */
28
+ 1013: {
29
+ // pow
30
+ minerReward: '2000000000000000000', // The amount a miner gets rewarded for mining a block
31
+ },
32
+ /**
33
+ . * Fee market change for ETH 1.0 chain
34
+ . */
35
+ 1559: {
36
+ // gasConfig
37
+ elasticityMultiplier: 2, // Maximum block gas target elasticity
38
+ initialBaseFee: 1000000000, // Initial base fee on first EIP1559 block
39
+ },
40
+ /**
41
+ * Save historical block hashes in state (Verkle related usage, UNSTABLE)
42
+ */
43
+ 2935: {
44
+ // config
45
+ historyStorageAddress: '0x0000F90827F1C53A10CB7A02335B175320002935', // The address where the historical blockhashes are stored
46
+ historyServeWindow: 8191, // The amount of blocks to be served by the historical blockhash contract
47
+ systemAddress: util_1.SYSTEM_ADDRESS, // The system address
48
+ },
49
+ /**
50
+ . * Reduction in refunds
51
+ . */
52
+ 3529: {
53
+ // gasConfig
54
+ maxRefundQuotient: 5, // Maximum refund quotient; max tx refund is min(tx.gasUsed/maxRefundQuotient, tx.gasRefund)
55
+ },
56
+ /**
57
+ . * Shard Blob Transactions
58
+ . */
59
+ 4844: {
60
+ // gasConfig
61
+ targetBlobGasPerBlock: 393216, // The target blob gas consumed per block
62
+ blobGasPerBlob: 131072, // The base fee for blob gas per blob
63
+ maxBlobGasPerBlock: 786432, // The max blob gas allowable per block
64
+ blobGasPriceUpdateFraction: 3338477, // The denominator used in the exponential when calculating a blob gas price
65
+ // gasPrices
66
+ minBlobGas: 1, // The minimum fee per blob gas
67
+ },
68
+ /**
69
+ . * Beacon block root in the EVM
70
+ . */
71
+ 4788: {
72
+ // config
73
+ historicalRootsLength: 8191, // The modulo parameter of the beaconroot ring buffer in the beaconroot stateful precompile
74
+ },
75
+ /**
76
+ * Execution layer triggerable withdrawals (experimental)
77
+ */
78
+ 7002: {
79
+ // config
80
+ systemAddress: util_1.SYSTEM_ADDRESS, // The system address to perform operations on the withdrawal requests predeploy address
81
+ // See: https://github.com/ethereum/EIPs/pull/8934/files
82
+ withdrawalRequestPredeployAddress: '0x00000961EF480EB55E80D19AD83579A64C007002', // Address of the validator excess address
83
+ systemCallGasLimit: 30000000, // EIP-7002 system call gas limit
84
+ },
85
+ /**
86
+ * Increase the MAX_EFFECTIVE_BALANCE -> Execution layer triggered consolidations (experimental)
87
+ */
88
+ 7251: {
89
+ // config
90
+ systemAddress: util_1.SYSTEM_ADDRESS, // The system address to perform operations on the consolidation requests predeploy address
91
+ // See: https://github.com/ethereum/EIPs/pull/8934/files
92
+ consolidationRequestPredeployAddress: '0x0000BBDDC7CE488642FB579F8B00F3A590007251', // Address of the consolidations contract
93
+ systemCallGasLimit: 30000000, // EIP-7251 system call gas limit
94
+ },
95
+ /**
96
+ . * Shard Blob Transactions
97
+ . */
98
+ 7691: {
99
+ // gasConfig
100
+ targetBlobGasPerBlock: 786432, // The target blob gas consumed per block
101
+ maxBlobGasPerBlock: 1179648, // The max blob gas allowable per block
102
+ blobGasPriceUpdateFraction: 5007716, // The denominator used in the exponential when calculating a blob gas price
103
+ },
104
+ };
105
+ //# sourceMappingURL=params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/params.ts"],"names":[],"mappings":";;;AACA,2CAAiD;AAEpC,QAAA,QAAQ,GAAe;IAClC;;OAEG;IACH,CAAC,EAAE;QACD,YAAY;QACZ,iBAAiB,EAAE,CAAC,EAAE,4FAA4F;QAClH,cAAc,EAAE,CAAC;QACjB,kBAAkB,EAAE,CAAC;QACrB,qBAAqB,EAAE,CAAC;QACxB,MAAM;QACN,WAAW,EAAE,qBAAqB,EAAE,qDAAqD;KAC1F;IACD;;OAEG;IACH,GAAG,EAAE;QACH,MAAM;QACN,WAAW,EAAE,qBAAqB,EAAE,qDAAqD;KAC1F;IACD;;OAEG;IACH,IAAI,EAAE;QACJ,MAAM;QACN,WAAW,EAAE,qBAAqB,EAAE,sDAAsD;KAC3F;IACD;;OAEG;IACH,IAAI,EAAE;QACJ,YAAY;QACZ,oBAAoB,EAAE,CAAC,EAAE,sCAAsC;QAC/D,cAAc,EAAE,UAAU,EAAE,0CAA0C;KACvE;IACD;;OAEG;IACH,IAAI,EAAE;QACJ,SAAS;QACT,qBAAqB,EAAE,4CAA4C,EAAE,0DAA0D;QAC/H,kBAAkB,EAAE,IAAI,EAAE,yEAAyE;QACnG,aAAa,EAAE,qBAAc,EAAE,qBAAqB;KACrD;IACD;;OAEG;IACH,IAAI,EAAE;QACJ,YAAY;QACZ,iBAAiB,EAAE,CAAC,EAAE,4FAA4F;KACnH;IACD;;OAEG;IACH,IAAI,EAAE;QACJ,YAAY;QACZ,qBAAqB,EAAE,MAAM,EAAE,yCAAyC;QACxE,cAAc,EAAE,MAAM,EAAE,qCAAqC;QAC7D,kBAAkB,EAAE,MAAM,EAAE,uCAAuC;QACnE,0BAA0B,EAAE,OAAO,EAAE,4EAA4E;QACjH,YAAY;QACZ,UAAU,EAAE,CAAC,EAAE,+BAA+B;KAC/C;IACD;;OAEG;IACH,IAAI,EAAE;QACJ,SAAS;QACT,qBAAqB,EAAE,IAAI,EAAE,2FAA2F;KACzH;IACD;;OAEG;IACH,IAAI,EAAE;QACJ,SAAS;QACT,aAAa,EAAE,qBAAc,EAAE,wFAAwF;QACvH,wDAAwD;QACxD,iCAAiC,EAAE,4CAA4C,EAAE,0CAA0C;QAC3H,kBAAkB,EAAE,QAAU,EAAE,iCAAiC;KAClE;IAED;;OAEG;IACH,IAAI,EAAE;QACJ,SAAS;QACT,aAAa,EAAE,qBAAc,EAAE,2FAA2F;QAC1H,wDAAwD;QACxD,oCAAoC,EAAE,4CAA4C,EAAE,yCAAyC;QAC7H,kBAAkB,EAAE,QAAU,EAAE,iCAAiC;KAClE;IACD;;OAEG;IACH,IAAI,EAAE;QACJ,YAAY;QACZ,qBAAqB,EAAE,MAAM,EAAE,yCAAyC;QACxE,kBAAkB,EAAE,OAAO,EAAE,uCAAuC;QACpE,0BAA0B,EAAE,OAAO,EAAE,4EAA4E;KAClH;CACF,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { CLRequest, CLRequestType } from '@feelyourprotocol/util';
2
+ import type { RunTxResult } from './types.ts';
3
+ import type { VM } from './vm.ts';
4
+ /**
5
+ * This helper method generates a list of all CL requests that can be included in a pending block
6
+ * @param vm VM instance (used in deriving partial withdrawal requests)
7
+ * @param txResults (used in deriving deposit requests)
8
+ * @returns a list of CL requests in ascending order by type
9
+ */
10
+ export declare const accumulateRequests: (vm: VM, txResults: RunTxResult[]) => Promise<CLRequest<CLRequestType>[]>;
11
+ //# sourceMappingURL=requests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../src/requests.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,SAAS,EACT,aAAa,EASd,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAwDjC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC7B,IAAI,EAAE,EACN,WAAW,WAAW,EAAE,KACvB,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,CAyBpC,CAAA"}
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.accumulateRequests = void 0;
4
+ const common_1 = require("@feelyourprotocol/common");
5
+ const util_1 = require("@feelyourprotocol/util");
6
+ const DEPOSIT_TOPIC = '0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5';
7
+ const PUBKEY_OFFSET = BigInt(160);
8
+ const WITHDRAWAL_CREDENTIALS_OFFSET = BigInt(256);
9
+ const AMOUNT_OFFSET = BigInt(320);
10
+ const SIGNATURE_OFFSET = BigInt(384);
11
+ const INDEX_OFFSET = BigInt(512);
12
+ const PUBKEY_SIZE = BigInt(48);
13
+ const WITHDRAWAL_CREDENTIALS_SIZE = BigInt(32);
14
+ const AMOUNT_SIZE = BigInt(8);
15
+ const SIGNATURE_SIZE = BigInt(96);
16
+ const INDEX_SIZE = BigInt(8);
17
+ const LOG_SIZE = 576;
18
+ const LOG_LAYOUT_MISMATCH = 'invalid deposit log: unsupported data layout';
19
+ function cloneSystemAccessEntry(vm, systemAddressHex) {
20
+ const access = vm.evm.blockLevelAccessList?.accesses[systemAddressHex];
21
+ if (access === undefined) {
22
+ return undefined;
23
+ }
24
+ const storageChanges = {};
25
+ for (const [slot, changes] of Object.entries(access.storageChanges)) {
26
+ storageChanges[slot] = changes.map(([index, value]) => [index, value]);
27
+ }
28
+ return {
29
+ nonceChanges: new Map(access.nonceChanges),
30
+ balanceChanges: new Map(access.balanceChanges),
31
+ codeChanges: access.codeChanges.map(([index, code]) => [index, code]),
32
+ storageChanges,
33
+ storageReads: new Set(access.storageReads),
34
+ };
35
+ }
36
+ function restoreSystemAccessEntry(vm, systemAddressHex, snapshot) {
37
+ const bal = vm.evm.blockLevelAccessList;
38
+ if (bal === undefined) {
39
+ return;
40
+ }
41
+ if (snapshot === undefined) {
42
+ delete bal.accesses[systemAddressHex];
43
+ return;
44
+ }
45
+ bal.accesses[systemAddressHex] = snapshot;
46
+ }
47
+ /**
48
+ * This helper method generates a list of all CL requests that can be included in a pending block
49
+ * @param vm VM instance (used in deriving partial withdrawal requests)
50
+ * @param txResults (used in deriving deposit requests)
51
+ * @returns a list of CL requests in ascending order by type
52
+ */
53
+ const accumulateRequests = async (vm, txResults) => {
54
+ const requests = [];
55
+ const common = vm.common;
56
+ if (common.isActivatedEIP(6110)) {
57
+ const depositContractAddress = vm.common['_chainParams'].depositContractAddress ?? common_1.Mainnet.depositContractAddress;
58
+ if (depositContractAddress === undefined)
59
+ throw (0, util_1.EthereumJSErrorWithoutCode)('deposit contract address required with EIP 6110');
60
+ const depositsRequest = accumulateDepositsRequest(depositContractAddress, txResults);
61
+ requests.push(depositsRequest);
62
+ }
63
+ if (common.isActivatedEIP(7002)) {
64
+ const withdrawalsRequest = await accumulateWithdrawalsRequest(vm);
65
+ requests.push(withdrawalsRequest);
66
+ }
67
+ if (common.isActivatedEIP(7251)) {
68
+ const consolidationsRequest = await accumulateConsolidationsRequest(vm);
69
+ requests.push(consolidationsRequest);
70
+ }
71
+ // requests are already type byte ordered by construction
72
+ return requests;
73
+ };
74
+ exports.accumulateRequests = accumulateRequests;
75
+ const accumulateWithdrawalsRequest = async (vm) => {
76
+ // Partial withdrawals logic
77
+ const addressBytes = (0, util_1.setLengthLeft)((0, util_1.bigIntToBytes)(vm.common.param('withdrawalRequestPredeployAddress')), 20);
78
+ const withdrawalsAddress = (0, util_1.createAddressFromString)((0, util_1.bytesToHex)(addressBytes));
79
+ const systemAddressBytes = (0, util_1.bigIntToAddressBytes)(vm.common.param('systemAddress'));
80
+ const systemAddress = (0, util_1.createAddressFromString)((0, util_1.bytesToHex)(systemAddressBytes));
81
+ const systemAccount = await vm.stateManager.getAccount(systemAddress);
82
+ const originalAccount = await vm.stateManager.getAccount(withdrawalsAddress);
83
+ if (originalAccount === undefined) {
84
+ return new util_1.CLRequest(util_1.CLRequestType.Withdrawal, new Uint8Array());
85
+ }
86
+ const systemAddressHex = systemAddress.toString();
87
+ const balSnapshot = cloneSystemAccessEntry(vm, systemAddressHex);
88
+ const results = await vm.evm.runCall({
89
+ caller: systemAddress,
90
+ gasLimit: vm.common.param('systemCallGasLimit'),
91
+ to: withdrawalsAddress,
92
+ });
93
+ restoreSystemAccessEntry(vm, systemAddressHex, balSnapshot);
94
+ if (systemAccount === undefined) {
95
+ await vm.stateManager.deleteAccount(systemAddress);
96
+ }
97
+ else {
98
+ await vm.stateManager.putAccount(systemAddress, systemAccount);
99
+ }
100
+ const resultsBytes = results.execResult.returnValue;
101
+ return new util_1.CLRequest(util_1.CLRequestType.Withdrawal, resultsBytes);
102
+ };
103
+ const accumulateConsolidationsRequest = async (vm) => {
104
+ // Partial withdrawals logic
105
+ const addressBytes = (0, util_1.setLengthLeft)((0, util_1.bigIntToBytes)(vm.common.param('consolidationRequestPredeployAddress')), 20);
106
+ const consolidationsAddress = (0, util_1.createAddressFromString)((0, util_1.bytesToHex)(addressBytes));
107
+ const systemAddressBytes = (0, util_1.bigIntToAddressBytes)(vm.common.param('systemAddress'));
108
+ const systemAddress = (0, util_1.createAddressFromString)((0, util_1.bytesToHex)(systemAddressBytes));
109
+ const systemAccount = await vm.stateManager.getAccount(systemAddress);
110
+ const originalAccount = await vm.stateManager.getAccount(consolidationsAddress);
111
+ if (originalAccount === undefined) {
112
+ return new util_1.CLRequest(util_1.CLRequestType.Consolidation, new Uint8Array(0));
113
+ }
114
+ const systemAddressHex = systemAddress.toString();
115
+ const balSnapshot = cloneSystemAccessEntry(vm, systemAddressHex);
116
+ const results = await vm.evm.runCall({
117
+ caller: systemAddress,
118
+ gasLimit: vm.common.param('systemCallGasLimit'),
119
+ to: consolidationsAddress,
120
+ });
121
+ restoreSystemAccessEntry(vm, systemAddressHex, balSnapshot);
122
+ if (systemAccount === undefined) {
123
+ await vm.stateManager.deleteAccount(systemAddress);
124
+ }
125
+ else {
126
+ await vm.stateManager.putAccount(systemAddress, systemAccount);
127
+ }
128
+ const resultsBytes = results.execResult.returnValue;
129
+ return new util_1.CLRequest(util_1.CLRequestType.Consolidation, resultsBytes);
130
+ };
131
+ const accumulateDepositsRequest = (depositContractAddress, txResults) => {
132
+ let resultsBytes = new Uint8Array(0);
133
+ const depositContractAddressLowerCase = depositContractAddress.toLowerCase();
134
+ for (const [_, tx] of txResults.entries()) {
135
+ for (let i = 0; i < tx.receipt.logs.length; i++) {
136
+ const log = tx.receipt.logs[i];
137
+ const [address, topics, data] = log;
138
+ if (topics.length > 0 &&
139
+ (0, util_1.bytesToHex)(topics[0]) === DEPOSIT_TOPIC &&
140
+ depositContractAddressLowerCase === (0, util_1.bytesToHex)(address).toLowerCase()) {
141
+ const { pubkey, withdrawalCredentials, amount, signature, index } = parseDepositLog(data);
142
+ const depositRequestBytes = (0, util_1.concatBytes)(pubkey, withdrawalCredentials, amount, signature, index);
143
+ resultsBytes = (0, util_1.concatBytes)(resultsBytes, depositRequestBytes);
144
+ }
145
+ }
146
+ }
147
+ return new util_1.CLRequest(util_1.CLRequestType.Deposit, resultsBytes);
148
+ };
149
+ function parseDepositLog(requestData) {
150
+ if (requestData.length !== LOG_SIZE) {
151
+ throw (0, util_1.EthereumJSErrorWithoutCode)(LOG_LAYOUT_MISMATCH);
152
+ }
153
+ // Extracts validator pubkey, withdrawal credential, deposit amount, signature,
154
+ // and validator index from Deposit Event log.
155
+ // The event fields are non-indexed so contained in one byte array (log[2]) so parsing is as follows:
156
+ // 1. Read the first 32 bytes to get the starting position of the first field.
157
+ // 2. Continue reading the byte array in 32 byte increments to get all the field starting positions
158
+ // 3. Read 32 bytes starting with the first field position to get the size of the first field
159
+ // 4. Read the bytes from first field position + 32 + the size of the first field to get the first field value
160
+ // 5. Repeat steps 3-4 for each field
161
+ const pubKeyIdxBigInt = (0, util_1.bytesToBigInt)(requestData.slice(0, 32));
162
+ const withdrawalCreditsIdxBigInt = (0, util_1.bytesToBigInt)(requestData.slice(32, 64));
163
+ const amountIdxBigInt = (0, util_1.bytesToBigInt)(requestData.slice(64, 96));
164
+ const sigIdxBigInt = (0, util_1.bytesToBigInt)(requestData.slice(96, 128));
165
+ const indexIdxBigInt = (0, util_1.bytesToBigInt)(requestData.slice(128, 160));
166
+ if (pubKeyIdxBigInt !== PUBKEY_OFFSET ||
167
+ withdrawalCreditsIdxBigInt !== WITHDRAWAL_CREDENTIALS_OFFSET ||
168
+ amountIdxBigInt !== AMOUNT_OFFSET ||
169
+ sigIdxBigInt !== SIGNATURE_OFFSET ||
170
+ indexIdxBigInt !== INDEX_OFFSET) {
171
+ throw (0, util_1.EthereumJSErrorWithoutCode)(LOG_LAYOUT_MISMATCH);
172
+ }
173
+ const pubKeyIdx = Number(pubKeyIdxBigInt);
174
+ const withdrawalCreditsIdx = Number(withdrawalCreditsIdxBigInt);
175
+ const amountIdx = Number(amountIdxBigInt);
176
+ const sigIdx = Number(sigIdxBigInt);
177
+ const indexIdx = Number(indexIdxBigInt);
178
+ const pubKeySizeBigInt = (0, util_1.bytesToBigInt)(requestData.slice(pubKeyIdx, pubKeyIdx + 32));
179
+ const withdrawalCreditsSizeBigInt = (0, util_1.bytesToBigInt)(requestData.slice(withdrawalCreditsIdx, withdrawalCreditsIdx + 32));
180
+ const amountSizeBigInt = (0, util_1.bytesToBigInt)(requestData.slice(amountIdx, amountIdx + 32));
181
+ const sigSizeBigInt = (0, util_1.bytesToBigInt)(requestData.slice(sigIdx, sigIdx + 32));
182
+ const indexSizeBigInt = (0, util_1.bytesToBigInt)(requestData.slice(indexIdx, indexIdx + 32));
183
+ if (pubKeySizeBigInt !== PUBKEY_SIZE ||
184
+ withdrawalCreditsSizeBigInt !== WITHDRAWAL_CREDENTIALS_SIZE ||
185
+ amountSizeBigInt !== AMOUNT_SIZE ||
186
+ sigSizeBigInt !== SIGNATURE_SIZE ||
187
+ indexSizeBigInt !== INDEX_SIZE) {
188
+ throw (0, util_1.EthereumJSErrorWithoutCode)(LOG_LAYOUT_MISMATCH);
189
+ }
190
+ const pubKeySize = Number(pubKeySizeBigInt);
191
+ const withdrawalCreditsSize = Number(withdrawalCreditsSizeBigInt);
192
+ const amountSize = Number(amountSizeBigInt);
193
+ const sigSize = Number(sigSizeBigInt);
194
+ const indexSize = Number(indexSizeBigInt);
195
+ const pubkey = requestData.slice(pubKeyIdx + 32, pubKeyIdx + 32 + pubKeySize);
196
+ const withdrawalCredentials = requestData.slice(withdrawalCreditsIdx + 32, withdrawalCreditsIdx + 32 + withdrawalCreditsSize);
197
+ const amount = requestData.slice(amountIdx + 32, amountIdx + 32 + amountSize);
198
+ const signature = requestData.slice(sigIdx + 32, sigIdx + 32 + sigSize);
199
+ const index = requestData.slice(indexIdx + 32, indexIdx + 32 + indexSize);
200
+ return {
201
+ pubkey,
202
+ withdrawalCredentials,
203
+ amount,
204
+ signature,
205
+ index,
206
+ };
207
+ }
208
+ //# sourceMappingURL=requests.js.map