@@ -4,12 +4,12 @@ This is the core of the Ethereum Virtual Machine (EVM or just VM).
4
4
5
5
NOTES:
6
6
7
- stack items are lazily duplicated.
8
- So you must never directly change a buffer from the stack,
9
- instead you should `copy` it first
7
+ 1. Stack items are lazily duplicated, so you must never directly change a buffer
8
+ from the stack, instead you should `copy` it first.
9
+
10
+ 2. Not all stack items are 32 bytes, so if the operation relies on the stack
11
+ item length then you must use `utils.pad(<item>, 32)` first.
10
12
11
- not all stack items are 32 bytes, so if the operation relies on the stack
12
- item length then you must use utils.pad(<item>, 32) first.
13
13
*/
14
14
import { Address , BN } from 'ethereumjs-util'
15
15
import { Block } from '@ethereumjs/block'
@@ -23,7 +23,7 @@ import { default as EVM, ExecResult } from './evm/evm'
23
23
*/
24
24
export interface RunCodeOpts {
25
25
/**
26
- * The [`Block`](https://github.com/ ethereumjs/ethereumjs- block) the `tx` belongs to. If omitted a blank block will be used
26
+ * The `@ ethereumjs/block` the `tx` belongs to. If omitted a default blank block will be used.
27
27
*/
28
28
block ?: Block
29
29
evm ?: EVM
@@ -71,35 +71,28 @@ export interface RunCodeOpts {
71
71
* @ignore
72
72
*/
73
73
export default function runCode ( this : VM , opts : RunCodeOpts ) : Promise < ExecResult > {
74
- if ( ! opts . block ) {
75
- opts . block = new Block ( )
76
- }
74
+ const block = opts . block ?? Block . fromBlockData ( { } , { common : this . _common } )
77
75
78
76
// Backwards compatibility
79
- if ( ! opts . txContext ) {
80
- opts . txContext = new TxContext (
81
- opts . gasPrice || new BN ( 0 ) ,
82
- opts . origin || opts . caller || Address . zero ( )
83
- )
84
- }
85
- if ( ! opts . message ) {
86
- opts . message = new Message ( {
77
+ const txContext =
78
+ opts . txContext ??
79
+ new TxContext ( opts . gasPrice ?? new BN ( 0 ) , opts . origin ?? opts . caller ?? Address . zero ( ) )
80
+
81
+ const message =
82
+ opts . message ??
83
+ new Message ( {
87
84
code : opts . code ,
88
85
data : opts . data ,
89
86
gasLimit : opts . gasLimit ,
90
- to : opts . address || Address . zero ( ) ,
87
+ to : opts . address ?? Address . zero ( ) ,
91
88
caller : opts . caller ,
92
89
value : opts . value ,
93
- depth : opts . depth || 0 ,
94
- selfdestruct : opts . selfdestruct || { } ,
95
- isStatic : opts . isStatic || false ,
90
+ depth : opts . depth ?? 0 ,
91
+ selfdestruct : opts . selfdestruct ?? { } ,
92
+ isStatic : opts . isStatic ?? false ,
96
93
} )
97
- }
98
94
99
- let evm = opts . evm
100
- if ( ! evm ) {
101
- evm = new EVM ( this , opts . txContext , opts . block )
102
- }
95
+ const evm = opts . evm ?? new EVM ( this , txContext , block )
103
96
104
- return evm . runInterpreter ( opts . message , { pc : opts . pc } )
97
+ return evm . runInterpreter ( message , { pc : opts . pc } )
105
98
}
0 commit comments