@@ -6,7 +6,7 @@ import Common from 'ethereumjs-common'
6
6
import PStateManager from '../state/promisified'
7
7
import { VmError , ERROR } from '../exceptions'
8
8
import Message from './message'
9
- import EVM from './evm'
9
+ import EVM , { EVMResult } from './evm'
10
10
const promisify = require ( 'util.promisify' )
11
11
12
12
/**
@@ -460,34 +460,35 @@ export default class EEI {
460
460
461
461
const results = await this . _evm . executeMessage ( msg )
462
462
463
- if ( results . vm . logs ) {
464
- this . _result . logs = this . _result . logs . concat ( results . vm . logs )
463
+ if ( results . execResult . logs ) {
464
+ this . _result . logs = this . _result . logs . concat ( results . execResult . logs )
465
465
}
466
466
467
467
// add gasRefund
468
- if ( results . vm . gasRefund ) {
469
- this . _result . gasRefund = this . _result . gasRefund . add ( results . vm . gasRefund )
468
+ if ( results . execResult . gasRefund ) {
469
+ this . _result . gasRefund = this . _result . gasRefund . add ( results . execResult . gasRefund )
470
470
}
471
471
472
472
// this should always be safe
473
473
this . useGas ( results . gasUsed )
474
474
475
475
// Set return value
476
476
if (
477
- results . vm . return &&
478
- ( ! results . vm . exceptionError || ( results . vm . exceptionError as VmError ) . error === ERROR . REVERT )
477
+ results . execResult . returnValue &&
478
+ ( ! results . execResult . exceptionError ||
479
+ results . execResult . exceptionError . error === ERROR . REVERT )
479
480
) {
480
- this . _lastReturned = results . vm . return
481
+ this . _lastReturned = results . execResult . returnValue
481
482
}
482
483
483
- if ( ! results . vm . exceptionError ) {
484
+ if ( ! results . execResult . exceptionError ) {
484
485
Object . assign ( this . _result . selfdestruct , selfdestruct )
485
486
// update stateRoot on current contract
486
487
const account = await this . _state . getAccount ( this . _env . address )
487
488
this . _env . contract = account
488
489
}
489
490
490
- return new BN ( results . vm . exception )
491
+ return this . _getReturnCode ( results )
491
492
}
492
493
493
494
/**
@@ -521,27 +522,27 @@ export default class EEI {
521
522
522
523
const results = await this . _evm . executeMessage ( msg )
523
524
524
- if ( results . vm . logs ) {
525
- this . _result . logs = this . _result . logs . concat ( results . vm . logs )
525
+ if ( results . execResult . logs ) {
526
+ this . _result . logs = this . _result . logs . concat ( results . execResult . logs )
526
527
}
527
528
528
529
// add gasRefund
529
- if ( results . vm . gasRefund ) {
530
- this . _result . gasRefund = this . _result . gasRefund . add ( results . vm . gasRefund )
530
+ if ( results . execResult . gasRefund ) {
531
+ this . _result . gasRefund = this . _result . gasRefund . add ( results . execResult . gasRefund )
531
532
}
532
533
533
534
// this should always be safe
534
535
this . useGas ( results . gasUsed )
535
536
536
537
// Set return buffer in case revert happened
537
538
if (
538
- results . vm . exceptionError &&
539
- ( results . vm . exceptionError as VmError ) . error === ERROR . REVERT
539
+ results . execResult . exceptionError &&
540
+ results . execResult . exceptionError . error === ERROR . REVERT
540
541
) {
541
- this . _lastReturned = results . vm . return
542
+ this . _lastReturned = results . execResult . returnValue
542
543
}
543
544
544
- if ( ! results . vm . exceptionError ) {
545
+ if ( ! results . execResult . exceptionError ) {
545
546
Object . assign ( this . _result . selfdestruct , selfdestruct )
546
547
// update stateRoot on current contract
547
548
const account = await this . _state . getAccount ( this . _env . address )
@@ -552,7 +553,7 @@ export default class EEI {
552
553
}
553
554
}
554
555
555
- return new BN ( results . vm . exception )
556
+ return this . _getReturnCode ( results )
556
557
}
557
558
558
559
/**
@@ -570,6 +571,16 @@ export default class EEI {
570
571
async isAccountEmpty ( address : Buffer ) : Promise < boolean > {
571
572
return this . _state . accountIsEmpty ( address )
572
573
}
574
+
575
+ private _getReturnCode ( results : EVMResult ) {
576
+ // This preserves the previous logic, but seems to contradict the EEI spec
577
+ // https://github.com/ewasm/design/blob/38eeded28765f3e193e12881ea72a6ab807a3371/eth_interface.md
578
+ if ( results . execResult . exceptionError ) {
579
+ return new BN ( 0 )
580
+ } else {
581
+ return new BN ( 1 )
582
+ }
583
+ }
573
584
}
574
585
575
586
function trap ( err : ERROR ) {
0 commit comments