mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 20:39:08 +01:00
Fix tx adding code
Broken in this commit:
bc39cd7b89
Synchronous methods were added to an `async.waterfall` array.
This commit also removes the delegate call checking, since we concluded it was misinformed.
This commit is contained in:
parent
4b6b1db4f0
commit
85d5b12f8d
@ -1,7 +1,6 @@
|
|||||||
const async = require('async')
|
const async = require('async')
|
||||||
const bind = require('ap').partial
|
const bind = require('ap').partial
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const ethBinToOps = require('eth-bin-to-ops')
|
|
||||||
const EthQuery = require('eth-query')
|
const EthQuery = require('eth-query')
|
||||||
const bip39 = require('bip39')
|
const bip39 = require('bip39')
|
||||||
const Transaction = require('ethereumjs-tx')
|
const Transaction = require('ethereumjs-tx')
|
||||||
@ -369,30 +368,9 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
|
|
||||||
// calculate metadata for tx
|
// calculate metadata for tx
|
||||||
async.parallel([
|
async.parallel([
|
||||||
analyzeForDelegateCall,
|
|
||||||
analyzeGasUsage,
|
analyzeGasUsage,
|
||||||
], didComplete)
|
], didComplete)
|
||||||
|
|
||||||
// perform static analyis on the target contract code
|
|
||||||
function analyzeForDelegateCall (cb) {
|
|
||||||
if (txParams.to) {
|
|
||||||
query.getCode(txParams.to, function (err, result) {
|
|
||||||
if (err) return cb(err)
|
|
||||||
var code = ethUtil.toBuffer(result)
|
|
||||||
if (code !== '0x') {
|
|
||||||
var ops = ethBinToOps(code)
|
|
||||||
var containsDelegateCall = ops.some((op) => op.name === 'DELEGATECALL')
|
|
||||||
txData.containsDelegateCall = containsDelegateCall
|
|
||||||
cb()
|
|
||||||
} else {
|
|
||||||
cb()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
cb()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function analyzeGasUsage (cb) {
|
function analyzeGasUsage (cb) {
|
||||||
query.getBlockByNumber('latest', true, function (err, block) {
|
query.getBlockByNumber('latest', true, function (err, block) {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
@ -416,7 +394,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
query.estimateGas(txParams, cb)
|
query.estimateGas(txParams, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForGasError (txData, estimatedGasHex) {
|
function checkForGasError (txData, estimatedGasHex, cb) {
|
||||||
txData.estimatedGas = estimatedGasHex
|
txData.estimatedGas = estimatedGasHex
|
||||||
// all gas used - must be an error
|
// all gas used - must be an error
|
||||||
if (estimatedGasHex === txData.txParams.gas) {
|
if (estimatedGasHex === txData.txParams.gas) {
|
||||||
@ -425,7 +403,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTxGas (txData, blockGasLimitHex) {
|
function setTxGas (txData, blockGasLimitHex, cb) {
|
||||||
const txParams = txData.txParams
|
const txParams = txData.txParams
|
||||||
// if OOG, nothing more to do
|
// if OOG, nothing more to do
|
||||||
if (txData.simulationFails) {
|
if (txData.simulationFails) {
|
||||||
@ -443,7 +421,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
// try adding an additional gas buffer to our estimation for safety
|
// try adding an additional gas buffer to our estimation for safety
|
||||||
const estimatedGasBn = new BN(ethUtil.stripHexPrefix(txData.estimatedGas), 16)
|
const estimatedGasBn = new BN(ethUtil.stripHexPrefix(txData.estimatedGas), 16)
|
||||||
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
|
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
|
||||||
const estimationWithBuffer = self.addGasBuffer(estimatedGasBn)
|
const estimationWithBuffer = new BN(self.addGasBuffer(estimatedGasBn), 16)
|
||||||
// added gas buffer is too high
|
// added gas buffer is too high
|
||||||
if (estimationWithBuffer.gt(blockGasLimitBn)) {
|
if (estimationWithBuffer.gt(blockGasLimitBn)) {
|
||||||
txParams.gas = txData.estimatedGas
|
txParams.gas = txData.estimatedGas
|
||||||
|
@ -154,8 +154,6 @@ PTXP.render = function () {
|
|||||||
]),
|
]),
|
||||||
]), // End of Table
|
]), // End of Table
|
||||||
|
|
||||||
this.warnIfNeeded(),
|
|
||||||
|
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -201,29 +199,6 @@ PTXP.miniAccountPanelForRecipient = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should analyze if there is a DELEGATECALL opcode
|
|
||||||
// in the recipient contract, and show a warning if so.
|
|
||||||
PTXP.warnIfNeeded = function () {
|
|
||||||
const containsDelegateCall = !!this.props.txData.containsDelegateCall
|
|
||||||
|
|
||||||
if (!containsDelegateCall) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return h('span.error', {
|
|
||||||
style: {
|
|
||||||
fontFamily: 'Montserrat Light',
|
|
||||||
fontSize: '13px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
},
|
|
||||||
}, [
|
|
||||||
h('i.fa.fa-lg.fa-info-circle', { style: { margin: '5px' } }),
|
|
||||||
h('span', ' Your identity may be used in other contracts!'),
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function forwardCarrat () {
|
function forwardCarrat () {
|
||||||
return (
|
return (
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user