From 2ea0736b51c621d8c42c57a73eda886ad9ca1a97 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 30 Jan 2018 11:03:53 +0000 Subject: [PATCH] Use lt/eq from bn.js instead of cmp --- lib/opFns.js | 10 +++++----- lib/precompiled/01-ecrecover.js | 2 +- lib/precompiled/02-sha256.js | 2 +- lib/precompiled/03-ripemd160.js | 2 +- lib/precompiled/04-identity.js | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/opFns.js b/lib/opFns.js index 46eb91315e..993cfadd59 100644 --- a/lib/opFns.js +++ b/lib/opFns.js @@ -122,19 +122,19 @@ module.exports = { }, // 0x10 range - bit ops LT: function (a, b, runState) { - return new BN(a.cmp(b) === -1 ? 1 : 0) + return new BN(a.lt(b) ? 1 : 0) }, GT: function (a, b, runState) { - return new BN(a.cmp(b) === 1 ? 1 : 0) + return new BN(a.gt(b) ? 1 : 0) }, SLT: function (a, b, runState) { - return new BN(a.fromTwos(256).cmp(b.fromTwos(256)) === -1 ? 1 : 0) + return new BN(a.fromTwos(256).lt(b.fromTwos(256)) ? 1 : 0) }, SGT: function (a, b, runState) { - return new BN(a.fromTwos(256).cmp(b.fromTwos(256)) === 1 ? 1 : 0) + return new BN(a.fromTwos(256).gt(b.fromTwos(256)) ? 1 : 0) }, EQ: function (a, b, runState) { - return new BN(a.cmp(b) === 0 ? 1 : 0) + return new BN(a.eq(b) ? 1 : 0) }, ISZERO: function (a, runState) { return new BN(a.isZero() ? 1 : 0) diff --git a/lib/precompiled/01-ecrecover.js b/lib/precompiled/01-ecrecover.js index 93d11e0d2d..444c39ed15 100644 --- a/lib/precompiled/01-ecrecover.js +++ b/lib/precompiled/01-ecrecover.js @@ -11,7 +11,7 @@ module.exports = function (opts) { results.gasUsed = new BN(fees.ecrecoverGas.v) - if (opts.gasLimit.cmp(results.gasUsed) === -1) { + if (opts.gasLimit.lt(results.gasUsed)) { results.gasUsed = opts.gasLimit results.exception = 0 // 0 means VM fail (in this case because of OOG) results.exceptionError = error.OUT_OF_GAS diff --git a/lib/precompiled/02-sha256.js b/lib/precompiled/02-sha256.js index 8980aae055..ac060f93c5 100644 --- a/lib/precompiled/02-sha256.js +++ b/lib/precompiled/02-sha256.js @@ -13,7 +13,7 @@ module.exports = function (opts) { results.gasUsed = new BN(fees.sha256Gas.v) results.gasUsed.iadd(new BN(fees.sha256WordGas.v).imuln(Math.ceil(data.length / 32))) - if (opts.gasLimit.cmp(results.gasUsed) === -1) { + if (opts.gasLimit.lt(results.gasUsed)) { results.gasUsed = opts.gasLimit results.exceptionError = error.OUT_OF_GAS results.exception = 0 // 0 means VM fail (in this case because of OOG) diff --git a/lib/precompiled/03-ripemd160.js b/lib/precompiled/03-ripemd160.js index 9093f272f5..03554cedf5 100644 --- a/lib/precompiled/03-ripemd160.js +++ b/lib/precompiled/03-ripemd160.js @@ -13,7 +13,7 @@ module.exports = function (opts) { results.gasUsed = new BN(fees.ripemd160Gas.v) results.gasUsed.iadd(new BN(fees.ripemd160WordGas.v).imuln(Math.ceil(data.length / 32))) - if (opts.gasLimit.cmp(results.gasUsed) === -1) { + if (opts.gasLimit.lt(results.gasUsed)) { results.gasUsed = opts.gasLimit results.exceptionError = error.OUT_OF_GAS results.exception = 0 // 0 means VM fail (in this case because of OOG) diff --git a/lib/precompiled/04-identity.js b/lib/precompiled/04-identity.js index 127b010cff..9328a48b93 100644 --- a/lib/precompiled/04-identity.js +++ b/lib/precompiled/04-identity.js @@ -13,7 +13,7 @@ module.exports = function (opts) { results.gasUsed = new BN(fees.identityGas.v) results.gasUsed.iadd(new BN(fees.identityWordGas.v).imuln(Math.ceil(data.length / 32))) - if (opts.gasLimit.cmp(results.gasUsed) === -1) { + if (opts.gasLimit.lt(results.gasUsed)) { results.gasUsed = opts.gasLimit results.exceptionError = error.OUT_OF_GAS results.exception = 0 // 0 means VM fail (in this case because of OOG)