Skip to content

Commit dd48770

Browse files
authored
Merge branch 'master' into rename-trie-to-mpt
2 parents 83e7b01 + a983867 commit dd48770

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/vm/lib/evm/eei.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,10 @@ export default class EEI {
566566
this._lastReturned = results.execResult.returnValue
567567
}
568568

569-
if (!results.execResult.exceptionError) {
569+
if (
570+
!results.execResult.exceptionError ||
571+
results.execResult.exceptionError.error === ERROR.CODESTORE_OUT_OF_GAS
572+
) {
570573
Object.assign(this._result.selfdestruct, selfdestruct)
571574
// update stateRoot on current contract
572575
const account = await this._state.getAccount(this._env.address)

packages/vm/lib/evm/evm.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ export default class EVM {
341341
allowedCodeSize = false
342342
}
343343
// If enough gas and allowed code size
344+
let CodestoreOOG = false
344345
if (
345346
totalGas.lte(message.gasLimit) &&
346347
(this._vm._allowUnlimitedContractSize || allowedCodeSize)
@@ -355,8 +356,8 @@ export default class EVM {
355356
debug(`Not enough gas or code size not allowed (Frontier)`)
356357
if (totalGas.sub(returnFee).lte(message.gasLimit)) {
357358
// we cannot pay the code deposit fee (but the deposit code actually did run)
358-
//result = { ...result, ...COOGResult(totalGas.sub(returnFee)) }
359-
result.gasUsed = totalGas.sub(returnFee)
359+
result = { ...result, ...COOGResult(totalGas.sub(returnFee)) }
360+
CodestoreOOG = true
360361
} else {
361362
result = { ...result, ...OOGResult(message.gasLimit) }
362363
}
@@ -367,6 +368,17 @@ export default class EVM {
367368
if (!result.exceptionError && result.returnValue && result.returnValue.toString() !== '') {
368369
await this._state.putContractCode(message.to, result.returnValue)
369370
debug(`Code saved on new contract creation`)
371+
} else if (CodestoreOOG) {
372+
// This only happens at Frontier. But, let's do a sanity check;
373+
if (!this._vm._common.gteHardfork('homestead')) {
374+
// Pre-Homestead behavior; put an empty contract.
375+
// This contract would be considered "DEAD" in later hard forks.
376+
// It is thus an unecessary default item, which we have to save to dik
377+
// It does change the state root, but it only wastes storage.
378+
//await this._state.putContractCode(message.to, result.returnValue)
379+
const account = await this._state.getAccount(message.to)
380+
await this._state.putAccount(message.to, account)
381+
}
370382
}
371383

372384
return {

0 commit comments

Comments
 (0)