diff --git a/js/src/evm/memory.js b/js/src/evm/memory.js index 847fa17..a8adac4 100644 --- a/js/src/evm/memory.js +++ b/js/src/evm/memory.js @@ -20,15 +20,15 @@ export default class Memory { const res = new Array(32).fill([-1, 0, undefined]) for (let i = offset; i < offset + 32; i++) { - const idx = i - offset; + const idx = i - offset for (const [off, seq, val] of this._data) { if (seq > res[idx][0] && i >= off && i < off + val.length) { - res[idx] = [seq, val[i-off], val] + res[idx] = [seq, val[i - off], val] } } } - const ret = new Uint8Array(res.map((v) => v[1])); - const used = new Set(res.map((v) => v[2])); + const ret = new Uint8Array(res.map((v) => v[1])) + const used = new Set(res.map((v) => v[2])) return [ret, used] } } diff --git a/js/src/evm/stack.js b/js/src/evm/stack.js index 93a853a..6181239 100644 --- a/js/src/evm/stack.js +++ b/js/src/evm/stack.js @@ -34,7 +34,7 @@ export default class Stack { } push_uint(val) { - this.push(bigIntToUint8Array(val)); + this.push(bigIntToUint8Array(val)) } pop_uint() { diff --git a/js/src/evm/vm.js b/js/src/evm/vm.js index 287332c..2268ae0 100644 --- a/js/src/evm/vm.js +++ b/js/src/evm/vm.js @@ -200,8 +200,8 @@ export default class Vm { let s1 = this.stack.pop_uint() // unsigned to signed - s0 = s0 <= E255M1 ? s0 : (s0 - E256) - s1 = s1 <= E255M1 ? s1 : (s1 - E256) + s0 = s0 <= E255M1 ? s0 : s0 - E256 + s1 = s1 <= E255M1 ? s1 : s1 - E256 let res switch (op) { case Op.SLT: diff --git a/js/src/index.js b/js/src/index.js index a7b8d8a..9ccdbe6 100644 --- a/js/src/index.js +++ b/js/src/index.js @@ -1,2 +1,2 @@ -export {functionSelectors} from './selectors.js' -export {functionArguments} from './arguments.js' +export { functionSelectors } from './selectors.js' +export { functionArguments } from './arguments.js' diff --git a/js/src/utils.js b/js/src/utils.js index 8afb7d0..c36b78e 100644 --- a/js/src/utils.js +++ b/js/src/utils.js @@ -2,11 +2,12 @@ export function hexToUint8Array(str) { if (str.startsWith('0x')) { str = str.slice(2) if (str.length % 2 !== 0) { - str = '0' + str; + str = '0' + str } } - if (typeof Buffer !== 'undefined') { // fast path for nodejs: - return Buffer.from(str, 'hex'); + if (typeof Buffer !== 'undefined') { + // fast path for nodejs: + return Buffer.from(str, 'hex') } const arr = new Uint8Array(str.length / 2) for (let i = 0, p = 0; i < str.length; i += 2, p += 1) { @@ -16,16 +17,16 @@ export function hexToUint8Array(str) { } export function uint8ArrayToBigInt(arr) { - return arr.reduce((acc, b) => acc * 256n + BigInt(b), 0n) + return arr.reduce((acc, b) => acc * 256n + BigInt(b), 0n) } -export function bigIntToUint8Array(val, n=32) { - const r = new Uint8Array(n); - while(n > 0) { - r[--n] = Number(val & 255n); - val >>= 8n; +export function bigIntToUint8Array(val, n = 32) { + const r = new Uint8Array(n) + while (n > 0) { + r[--n] = Number(val & 255n) + val >>= 8n } - return r; + return r } export function toBigInt(v) {