From bdc84a05ac8d98150737eed19e2be373ac89e26c Mon Sep 17 00:00:00 2001 From: Richard Meissner Date: Sun, 4 Nov 2018 00:30:52 +0100 Subject: [PATCH] Handle revert in create2 with message --- lib/opFns.js | 8 ++++++-- lib/runCall.js | 4 +--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/opFns.js b/lib/opFns.js index 4ec98558c5..06fea23350 100644 --- a/lib/opFns.js +++ b/lib/opFns.js @@ -539,7 +539,7 @@ module.exports = { outLength: new BN(0) } - // Deduct gas costs for hashingq + // Deduct gas costs for hashing subGas(runState, new BN(runState._common.param('gasPrices', 'sha3Word')).imul(length.divCeil(new BN(32)))) checkCallMemCost(runState, options, localOpts) checkOutOfGas(runState, options) @@ -1011,7 +1011,7 @@ function makeCall (runState, callOptions, localOpts, cb) { if (results.vm.return && (!results.vm.exceptionError || results.vm.exceptionError.error === ERROR.REVERT)) { memStore(runState, localOpts.outOffset, results.vm.return, new BN(0), localOpts.outLength, false) - if (results.vm.exceptionError && results.vm.exceptionError.error === ERROR.REVERT && runState.opName === 'CREATE') { + if (results.vm.exceptionError && results.vm.exceptionError.error === ERROR.REVERT && isCreateOpCode(runState.opName)) { runState.lastReturned = results.vm.return } @@ -1049,6 +1049,10 @@ function makeCall (runState, callOptions, localOpts, cb) { } } +function isCreateOpCode (opName) { + return opName === 'CREATE' || opName === 'CREATE2' +} + function getContractStorage (runState, address, key, cb) { if (runState._common.gteHardfork('constantinople')) { async.parallel({ diff --git a/lib/runCall.js b/lib/runCall.js index 76f26a4566..dd5a871b5f 100644 --- a/lib/runCall.js +++ b/lib/runCall.js @@ -5,7 +5,6 @@ const BN = ethUtil.BN const exceptions = require('./exceptions.js') const ERROR = exceptions.ERROR -const EMPTY_CODE_HASH = ethUtil.keccak256() /** * runs a CALL operation @@ -103,7 +102,7 @@ module.exports = function (opts, cb) { return } - if ((account.nonce && new BN(account.nonce) > 0) || account.codeHash.compare(EMPTY_CODE_HASH) !== 0) { + if ((account.nonce && new BN(account.nonce) > 0) || account.codeHash.compare(ethUtil.KECCAK256_NULL) !== 0) { toAccount = account code = new Buffer('fe', 'hex') // Invalid init code done() @@ -221,7 +220,6 @@ module.exports = function (opts, cb) { var totalGas = results.gasUsed if (!results.runState.vmError) { var returnFee = new BN(results.return.length * self._common.param('gasPrices', 'createData')) - totalGas = totalGas.add(returnFee) } // if not enough gas