@@ -341,6 +341,7 @@ export default class EVM {
341
341
allowedCodeSize = false
342
342
}
343
343
// If enough gas and allowed code size
344
+ let CodestoreOOG = false
344
345
if (
345
346
totalGas . lte ( message . gasLimit ) &&
346
347
( this . _vm . _allowUnlimitedContractSize || allowedCodeSize )
@@ -355,8 +356,8 @@ export default class EVM {
355
356
debug ( `Not enough gas or code size not allowed (Frontier)` )
356
357
if ( totalGas . sub ( returnFee ) . lte ( message . gasLimit ) ) {
357
358
// 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
360
361
} else {
361
362
result = { ...result , ...OOGResult ( message . gasLimit ) }
362
363
}
@@ -367,6 +368,17 @@ export default class EVM {
367
368
if ( ! result . exceptionError && result . returnValue && result . returnValue . toString ( ) !== '' ) {
368
369
await this . _state . putContractCode ( message . to , result . returnValue )
369
370
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
+ }
370
382
}
371
383
372
384
return {
0 commit comments