Skip to content

Commit f001de8

Browse files
authored
Merge pull request #1533 from MetaMask/i1528-gasLimitLow
Convert gasLimit to not use muln in BN
2 parents bcc550d + 82cbfaa commit f001de8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/scripts/lib/tx-utils.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = class txProviderUtils {
3030

3131
setBlockGasLimit (txMeta, blockGasLimitHex, cb) {
3232
const blockGasLimitBN = hexToBn(blockGasLimitHex)
33-
const saferGasLimitBN = blockGasLimitBN.muln(0.95)
33+
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20)
3434
txMeta.blockGasLimit = bnToHex(saferGasLimitBN)
3535
cb()
3636
return
@@ -43,7 +43,7 @@ module.exports = class txProviderUtils {
4343
// if not, fallback to block gasLimit
4444
if (!txMeta.gasLimitSpecified) {
4545
const blockGasLimitBN = hexToBn(blockGasLimitHex)
46-
const saferGasLimitBN = blockGasLimitBN.muln(0.95)
46+
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20)
4747
txParams.gas = bnToHex(saferGasLimitBN)
4848
}
4949
// run tx, see if it will OOG
@@ -143,3 +143,9 @@ function bnToHex (inputBn) {
143143
function hexToBn (inputHex) {
144144
return new BN(ethUtil.stripHexPrefix(inputHex), 16)
145145
}
146+
147+
function BnMultiplyByFraction (targetBN, numerator, denominator) {
148+
const numBN = new BN(numerator)
149+
const denomBN = new BN(denominator)
150+
return targetBN.mul(numBN).div(denomBN)
151+
}

0 commit comments

Comments
 (0)