Skip to content

Commit

Permalink
Handle revert in create2 with message
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeissner committed Nov 4, 2018
1 parent a402acc commit 6a2c9e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/opFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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({
Expand Down
4 changes: 1 addition & 3 deletions lib/runCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6a2c9e2

Please sign in to comment.