1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Reproduced issue 743 in test case

This contract hex does include the value `f4`, but it was compiled from a contract with no instance of `.delegatecall`. I believe `f4` in this case is part of some other value or contract address, and `ethBinToOps` has some error in how it skips pushed data.

@kumavis
This commit is contained in:
Dan Finlay 2016-10-17 14:48:25 -07:00
parent 0f0951ba54
commit 049705004f
3 changed files with 35 additions and 12 deletions

View File

@ -249,15 +249,9 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
if (txParams.to) { if (txParams.to) {
query.getCode(txParams.to, function (err, result) { query.getCode(txParams.to, function (err, result) {
if (err) return cb(err) if (err) return cb(err)
var code = ethUtil.toBuffer(result) var containsDelegateCall = this.checkForDelegateCall(result)
if (code !== '0x') { txData.containsDelegateCall = containsDelegateCall
var ops = ethBinToOps(code) cb()
var containsDelegateCall = ops.some((op) => op.name === 'DELEGATECALL')
txData.containsDelegateCall = containsDelegateCall
cb()
} else {
cb()
}
}) })
} else { } else {
cb() cb()
@ -282,6 +276,17 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
} }
} }
IdentityStore.prototype.checkForDelegateCall = function (codeHex) {
const code = ethUtil.toBuffer(codeHex)
if (code !== '0x') {
const ops = ethBinToOps(code)
const containsDelegateCall = ops.some((op) => op.name === 'DELEGATECALL')
return containsDelegateCall
} else {
return false
}
}
IdentityStore.prototype.addGasBuffer = function (gasHex) { IdentityStore.prototype.addGasBuffer = function (gasHex) {
var gas = new BN(gasHex, 16) var gas = new BN(gasHex, 16)
var buffer = new BN('100000', 10) var buffer = new BN('100000', 10)

View File

@ -0,0 +1 @@
0x606060405260e060020a60003504637bd703e8811461003157806390b98a111461005c578063f8b2cb4f1461008e575b005b6100b4600435600073f28c53067227848f8145355c455da5cfdd20e3136396e4ee3d6100da84610095565b6100c660043560243533600160a060020a03166000908152602081905260408120548290101561011f57506000610189565b6100b46004355b600160a060020a0381166000908152602081905260409020545b919050565b60408051918252519081900360200190f35b604080519115158252519081900360200190f35b60026040518360e060020a02815260040180838152602001828152602001925050506020604051808303818660325a03f4156100025750506040515191506100af9050565b33600160a060020a0390811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9291505056

View File

@ -1,10 +1,15 @@
var assert = require('assert') const assert = require('assert')
var IdentityStore = require('../../app/scripts/lib/idStore') const IdentityStore = require('../../app/scripts/lib/idStore')
var configManagerGen = require('../lib/mock-config-manager') const configManagerGen = require('../lib/mock-config-manager')
const fs = require('fs')
const path = require('path')
const ethUtil = require('ethereumjs-util') const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN const BN = ethUtil.BN
const async = require('async') const async = require('async')
const nonDelegatePath = path.join(__dirname, '..', 'lib', 'non-delegate-code.txt')
const nonDelegateCode = fs.readFileSync(nonDelegatePath).toString()
describe('IdentityStore', function() { describe('IdentityStore', function() {
describe('#createNewVault', function () { describe('#createNewVault', function () {
@ -156,4 +161,16 @@ describe('IdentityStore', function() {
assert.ok(bnResult.gt(gas), 'added more gas as buffer.') assert.ok(bnResult.gt(gas), 'added more gas as buffer.')
assert.equal(result.indexOf('0x'), 0, 'include hex prefix') assert.equal(result.indexOf('0x'), 0, 'include hex prefix')
}) })
describe('#checkForDelegateCall', function() {
const idStore = new IdentityStore({
configManager: configManagerGen(),
ethStore: {
addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
},
})
var result = idStore.checkForDelegateCall(nonDelegateCode)
assert.equal(result, false, 'no delegate call in provided code')
})
}) })