0.0.4 โ€ข Published 3 years ago

evm-shell v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

[ ๐ŸŒ ๐Ÿ“ฉ ๐Ÿ”ฅ ]

EVM Shell

A hands-on interactive EVM repl/shell. Low-level ethereum virtual machine inspection.

๐Ÿ’พ npm install -g evm-shell

In order to understand smart contracts you have to become a smart contract. evm-shell is your entrance to this rabbithole ๐Ÿฐ๐Ÿ•ณ๏ธ.

Imagine, you wake up as a smart contract deployed at address 0xc0de00000000000000000000000000000000c0de. Your friend at account 0xbabe00000000000000000000000000000000babe is calling your contract code. You decide what to do, step-by-step, one instruction at a time. Perform arithmetic operations, manipulate the stack, memory, storage, emit events, and much more. Your code, your rules ๐Ÿ‘‘.

evm-shell

โ‡’  evm-shell
๐Ÿš€ Entering interactive EVM shell. 'help' is your friend. '[Tab]' for autocomplete.
   โ†’ chainId:      1
   โ†’ hardfork:     london
   โ†’ address:      0xc0de00000000000000000000000000000000c0de
   โ†’ value:        100
   โ†’ gasLimit:     68719476735
   โ†’ gasPrice:     0
   โ†’ caller/origin:0xbabe00000000000000000000000000000000babe/0xbabe00000000000000000000000000000000babe

๐Ÿ™Œ Bugs/Feedback โ†’ github/@tintinweb 
    โ†’ https://github.com/tintinweb/evm-shell/ | ConsenSys Diligence @ https://consensys.net/diligence/

ยป  push 1
ยป  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[pc      ]: 2
[code    ]: 0x6001
[gasUsed ]: 3
[stack   ]: ["01"] โ†—
[memory  ]:  โ†—
[storage ]: []
[logs    ]: []

ยป  push 0xfe
ยป  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[pc      ]: 4
[code    ]: 0x600160fe
[gasUsed ]: 6
[stack   ]: ["01","fe"] โ†—
[memory  ]:  โ†—
[storage ]: []
[logs    ]: []

ยป  mul
ยป  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[pc      ]: 5
[code    ]: 0x600160fe02
[gasUsed ]: 11
[stack   ]: ["fe"] โ†—
[memory  ]:  โ†—
[storage ]: []
[logs    ]: []

Hints

  • Note: This is not a simulator, we actually run your code in the amazing ethereumjs vm.
  • Note: .reset completely removes all statements. .undo removes the last statement.
  • Note: Automatically restores the state if you mess up because your instruction reverts ๐Ÿ˜‰

Usage

Basically lists all supported evm instructions. Meta-commands are dot-prefixed.

 ยป  help

  Commands:

    help [command...]         Provides help for a given command.
    exit                      Exits application.
    .show                     
    .reset                    
    .undo                     
    .config                   
    .opcodes                  
    .step [step]              
    .stack                    
    .memory                   
    .state                    
    .storage                  
    .logs                     
    .disasm                   
    .load <hexstr>            
    stop [args...]            
    add [args...]             
    mul [args...]             
    sub [args...]             
    div [args...]             
    sdiv [args...]            
    mod [args...]             
    smod [args...]            
    addmod [args...]          
    mulmod [args...]          
    exp [args...]             
    signextend [args...]      
    lt [args...]              
    gt [args...]              
    slt [args...]             
    sgt [args...]             
    eq [args...]              
    iszero [args...]          
    and [args...]             
    or [args...]              
    xor [args...]             
    not [args...]             
    byte [args...]            
    shl [args...]             
    shr [args...]             
    sar [args...]             
    sha3 [args...]            
    address [args...]         
    balance [args...]         
    origin [args...]          
    caller [args...]          
    callvalue [args...]       
    calldataload [args...]    
    calldatasize [args...]    
    calldatacopy [args...]    
    codesize [args...]        
    codecopy [args...]        
    gasprice [args...]        
    extcodesize [args...]     
    extcodecopy [args...]     
    returndatasize [args...]  
    returndatacopy [args...]  
    extcodehash [args...]     
    blockhash [args...]       
    coinbase [args...]        
    timestamp [args...]       
    number [args...]          
    difficulty [args...]      
    gaslimit [args...]        
    chainid [args...]         
    selfbalance [args...]     
    basefee [args...]         
    pop [args...]             
    mload [args...]           
    mstore [args...]          
    mstore8 [args...]         
    sload [args...]           
    sstore [args...]          
    jump [args...]            
    jumpi [args...]           
    pc [args...]              
    msize [args...]           
    gas [args...]             
    jumpdest [args...]        
    push1 [args...]           
    push2 [args...]           
    push3 [args...]           
    push4 [args...]           
    push5 [args...]           
    push6 [args...]           
    push7 [args...]           
    push8 [args...]           
    push9 [args...]           
    push10 [args...]          
    push11 [args...]          
    push12 [args...]          
    push13 [args...]          
    push14 [args...]          
    push15 [args...]          
    push16 [args...]          
    push17 [args...]          
    push18 [args...]          
    push19 [args...]          
    push20 [args...]          
    push21 [args...]          
    push22 [args...]          
    push23 [args...]          
    push24 [args...]          
    push25 [args...]          
    push26 [args...]          
    push27 [args...]          
    push28 [args...]          
    push29 [args...]          
    push30 [args...]          
    push31 [args...]          
    push32 [args...]          
    dup1 [args...]            
    dup2 [args...]            
    dup3 [args...]            
    dup4 [args...]            
    dup5 [args...]            
    dup6 [args...]            
    dup7 [args...]            
    dup8 [args...]            
    dup9 [args...]            
    dup10 [args...]           
    dup11 [args...]           
    dup12 [args...]           
    dup13 [args...]           
    dup14 [args...]           
    dup15 [args...]           
    dup16 [args...]           
    swap1 [args...]           
    swap2 [args...]           
    swap3 [args...]           
    swap4 [args...]           
    swap5 [args...]           
    swap6 [args...]           
    swap7 [args...]           
    swap8 [args...]           
    swap9 [args...]           
    swap10 [args...]          
    swap11 [args...]          
    swap12 [args...]          
    swap13 [args...]          
    swap14 [args...]          
    swap15 [args...]          
    swap16 [args...]          
    log0 [args...]            
    log1 [args...]            
    log2 [args...]            
    log3 [args...]            
    log4 [args...]            
    create [args...]          
    call [args...]            
    callcode [args...]        
    return [args...]          
    delegatecall [args...]    
    create2 [args...]         
    staticcall [args...]      
    revert [args...]          
    invalid [args...]         
    selfdestruct [args...]    
    push <args>   

Examples

Transaction vars: msg.sender, tx.origin, this etc.

ยป  caller
ยป  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[pc      ]: 1
[code    ]: 0x33
[gasUsed ]: 2
[stack   ]: ["babe00000000000000000000000000000000babe"] โ†—
[memory  ]:  โ†—
[storage ]: []
[logs    ]: []

ยป  address
ยป  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[pc      ]: 1
[code    ]: 0x30
[gasUsed ]: 2
[stack   ]: ["c0de00000000000000000000000000000000c0de"] โ†—
[memory  ]:  โ†—
[storage ]: []
[logs    ]: []

Memory manipulation

ยป  push 0x1337
ยป  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[pc      ]: 3
[code    ]: 0x611337
[gasUsed ]: 3
[stack   ]: ["1337"] โ†—
[memory  ]:  โ†—
[storage ]: []
[logs    ]: []

ยป  push 64
ยป  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[pc      ]: 5
[code    ]: 0x6113376040
[gasUsed ]: 6
[stack   ]: ["1337","40"] โ†—
[memory  ]:  โ†—
[storage ]: []
[logs    ]: []

ยป  mstore
ยป  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[pc      ]: 6
[code    ]: 0x611337604052
[gasUsed ]: 18
[stack   ]: [] โ†—
[memory  ]: 0000000000000000000000000000000000000000000000000000000000000000
            0000000000000000000000000000000000000000000000000000000000000000
            0000000000000000000000000000000000000000000000000000000000001337 โ†—
[storage ]: []
[logs    ]: []

ยป  push 64
ยป  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[pc      ]: 8
[code    ]: 0x6113376040526040
[gasUsed ]: 21
[stack   ]: ["40"] โ†—
[memory  ]: 0000000000000000000000000000000000000000000000000000000000000000
            0000000000000000000000000000000000000000000000000000000000000000
            0000000000000000000000000000000000000000000000000000000000001337 โ†—
[storage ]: []
[logs    ]: []

ยป  mload
ยป  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[pc      ]: 9
[code    ]: 0x611337604052604051
[gasUsed ]: 24
[stack   ]: ["1337"] โ†—
[memory  ]: 0000000000000000000000000000000000000000000000000000000000000000
            0000000000000000000000000000000000000000000000000000000000000000
            0000000000000000000000000000000000000000000000000000000000001337 โ†—
[storage ]: []
[logs    ]: []