Git Product home page Git Product logo

pyevmasm's Introduction

pyevmasm

Build Status

PyPI version Slack Status

pyevmasm is an assembler and disassembler library for the Ethereum Virtual Machine (EVM). It includes a commandline utility and a Python API.

CLI Examples with evmasm

evmasm is a commandline utility that uses pyevmasm to assemble or disassemble EVM:

usage: evmasm [-h] (-a | -d | -t) [-bi] [-bo] [-i [INPUT]] [-o [OUTPUT]] [-f FORK]

pyevmasm the EVM assembler and disassembler

optional arguments:
  -h, --help            show this help message and exit
  -a, --assemble        Assemble EVM instructions to opcodes
  -d, --disassemble     Disassemble EVM to opcodes
  -t, --print-opcode-table
                        List supported EVM opcodes
  -bi, --binary-input   Binary input mode (-d only)
  -bo, --binary-output  Binary output mode (-a only)
  -i [INPUT], --input [INPUT]
                        Input file, default=stdin
  -o [OUTPUT], --output [OUTPUT]
                        Output file, default=stdout
  -f FORK, --fork FORK  Fork, default: byzantium. Possible: frontier,
                        homestead, tangerine_whistle, spurious_dragon,
                        byzantium, constantinople, serenity. Also an unsigned
                        block number is accepted to select the fork.

Disassembling the preamble of compiled contract:

$ echo -n "608060405260043610603f57600035" | evmasm -d
00000000: PUSH1 0x80
00000002: PUSH1 0x40
00000004: MSTORE
00000005: PUSH1 0x4
00000007: CALLDATASIZE
00000008: LT
00000009: PUSH1 0x3f
0000000b: JUMPI
0000000c: PUSH1 0x0
0000000e: CALLDATALOAD

Python API Examples

>>> from pyevmasm import instruction_tables, disassemble_hex, disassemble_all, assemble_hex
>>> instruction_table = instruction_tables['byzantium']
>>> instruction_table[20]
Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0)
>>> instruction_table['EQ']
Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0)
>>> instrs = list(disassemble_all(binascii.unhexlify('608060405260043610603f57600035')))
>>> instrs.insert(1, instruction_table['JUMPI'])
>>> a = assemble_hex(instrs)
>>> a
'0x60805760405260043610603f57600035'
>>> print(disassemble_hex(a))
PUSH1 0x80
JUMPI
PUSH1 0x40
MSTORE
...
>>> assemble_hex('PUSH1 0x40\nMSTORE\n')
'0x604052'

Installation

Python >=2.7 or Python >=3.3 is required.

Install the latest stable version using pip:

pip install pyevmasm

Or, install the library from source:

git clone https://github.com/trailofbits/pyevmasm
cd pyevmasm
python setup.py install --user

Documentation

https://pyevmasm.readthedocs.io

New issues, feature requests, and contributions are welcome. Join us in #ethereum channel on the Empire Hacking Slack to discuss Ethereum security tool development.

pyevmasm's People

Contributors

0xalpharush avatar 0xphaze avatar computerality avatar cryptomental avatar defunctio avatar dependabot[bot] avatar dguido avatar disconnect3d avatar el15066 avatar esultanik avatar f0rki avatar feliam avatar georgiypetrov avatar ggrieco-tob avatar montyly avatar nveloso avatar offlinemark avatar oldsj avatar woodruffw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyevmasm's Issues

Help text recommends ambiguous flag

The helpful "input is binary?" text should be updated to recommend -bi

[I] (py3) vagrant ubuntu-bionic /v/m/541 ❯ cat QuickFuzz.78967239524.88.5513551461481047294.38.evm.txt |evmasm -d
Input is binary? try using -b.
[I] (py3) vagrant ubuntu-bionic /v/m/541 ❯ cat QuickFuzz.78967239524.88.5513551461481047294.38.evm.txt |evmasm -b -d
usage: evmasm [-h] (-a | -d | -t) [-bi] [-bo] [-i [INPUT]] [-o [OUTPUT]]
evmasm: error: ambiguous option: -b could match -bi, -bo

https://github.com/trailofbits/pyevmasm/blob/66b8b46515ba43f58ce8542f318a9f5ccbf42a22/pyevmasm/__main__.py#L52

0.2.3 installed by pip is different with source code in github

pyvmasm version

0.2.3

Python version

3.7

Summary of the problem

In the source code of pyevmasm installed by pip, the pop number of CREATE2 is 3 which should be 4 actually.
This bug has been fixed in source code 2 years ago.
Thanks a lot if you can upgrade pip package.

Add list of opcodes

List all known opcodes from _table via --opcodes or --print-opcodes flag.

Detect and do not disassemble swarm hash

Currently evmasm cli tool attempts to disassemble the swarm hash appended to the contract code. It should detect the hash and display it in a nicely instead. Manticore and Rattle handle this by searching for \a1ebzzr0 and pattern match.

Add comments for assembly

It would be helpful to have an escape sequence for comments (e.g. \\, # or %) that are simply ignored during assembly.

Support previous forks instruction sets

Currently pyevmasm only supports the latest/post-Byzantium fork. Would be good to be able to accurately disassemble old code created before the most recent fork. Could be exposed by specifying which fork or by specifying a block number.

BLOCKHASH appears in disassembled code but doesn't appear in original source code.

pyvmasm version

0.2.0

Python version

3.7.4

Summary of the problem

I have bytecode for which I have access to the original source code. My goal is to look for the BLOCKHASH opcode in my code. Upon disassembling a few of the bytecodes that I have and searching for whether they contain the BLOCKHASH opcode, I noticed that some of them, when looking at the original source code, do not call the blockhash function at all. Instead, they call the block.number function. Here's an example:
The bytecode for contract 0x3bfc20f0b9afcace800d73d2191166ff16540258 is 0x606060405236156100725763ffffffff60e060020a60. However, the source code doesn't call blockhash, simply block.number:

/**
 *Submitted for verification at Etherscan.io on 2017-07-20
*/

//sol Wallet
// Multi-sig, daily-limited account proxy/wallet.
// @authors:
// Gav Wood <[email protected]>
// inheritable "property" contract that enables methods to be protected by requiring the acquiescence of either a
// single, or, crucially, each of a number of, designated owners.
// usage:
// use modifiers onlyowner (just own owned) or onlymanyowners(hash), whereby the same hash must be provided by
// some number (specified in constructor) of the set of owners (specified in the constructor, modifiable) before the
// interior is executed.

pragma solidity ^0.4.9;

contract WalletEvents {
  // EVENTS

  // this contract only has six types of events: it can accept a confirmation, in which case
  // we record owner and operation (hash) alongside it.
  event Confirmation(address owner, bytes32 operation);
  event Revoke(address owner, bytes32 operation);

  // some others are in the case of an owner changing.
  event OwnerChanged(address oldOwner, address newOwner);
  event OwnerAdded(address newOwner);
  event OwnerRemoved(address oldOwner);

  // the last one is emitted if the required signatures change
  event RequirementChanged(uint newRequirement);

  // Funds has arrived into the wallet (record how much).
  event Deposit(address _from, uint value);
  // Single transaction going out of the wallet (record who signed for it, how much, and to whom it's going).
  event SingleTransact(address owner, uint value, address to, bytes data, address created);
  // Multi-sig transaction going out of the wallet (record who signed for it last, the operation hash, how much, and to whom it's going).
  event MultiTransact(address owner, bytes32 operation, uint value, address to, bytes data, address created);
  // Confirmation still needed for a transaction.
  event ConfirmationNeeded(bytes32 operation, address initiator, uint value, address to, bytes data);
}

contract WalletAbi {
  // Revokes a prior confirmation of the given operation
  function revoke(bytes32 _operation) external;

  // Replaces an owner `_from` with another `_to`.
  function changeOwner(address _from, address _to) external;

  function addOwner(address _owner) external;

  function removeOwner(address _owner) external;

  function changeRequirement(uint _newRequired) external;

  function isOwner(address _addr) constant returns (bool);

  function hasConfirmed(bytes32 _operation, address _owner) external constant returns (bool);

  // (re)sets the daily limit. needs many of the owners to confirm. doesn't alter the amount already spent today.
  function setDailyLimit(uint _newLimit) external;

  function execute(address _to, uint _value, bytes _data) external returns (bytes32 o_hash);
  function confirm(bytes32 _h) returns (bool o_success);
}

contract WalletLibrary is WalletEvents {
  // TYPES

  // struct for the status of a pending operation.
  struct PendingState {
    uint yetNeeded;
    uint ownersDone;
    uint index;
  }

  // Transaction structure to remember details of transaction lest it need be saved for a later call.
  struct Transaction {
    address to;
    uint value;
    bytes data;
  }

  // MODIFIERS

  // simple single-sig function modifier.
  modifier onlyowner {
    if (isOwner(msg.sender))
      _;
  }
  // multi-sig function modifier: the operation must have an intrinsic hash in order
  // that later attempts can be realised as the same underlying operation and
  // thus count as confirmations.
  modifier onlymanyowners(bytes32 _operation) {
    if (confirmAndCheck(_operation))
      _;
  }

  // METHODS

  // gets called when no other function matches
  function() payable {
    // just being sent some cash?
    if (msg.value > 0)
      Deposit(msg.sender, msg.value);
  }

  // constructor is given number of sigs required to do protected "onlymanyowners" transactions
  // as well as the selection of addresses capable of confirming them.
  function initMultiowned(address[] _owners, uint _required) only_uninitialized {
    m_numOwners = _owners.length + 1;
    m_owners[1] = uint(msg.sender);
    m_ownerIndex[uint(msg.sender)] = 1;
    for (uint i = 0; i < _owners.length; ++i)
    {
      m_owners[2 + i] = uint(_owners[i]);
      m_ownerIndex[uint(_owners[i])] = 2 + i;
    }
    m_required = _required;
  }

  // Revokes a prior confirmation of the given operation
  function revoke(bytes32 _operation) external {
    uint ownerIndex = m_ownerIndex[uint(msg.sender)];
    // make sure they're an owner
    if (ownerIndex == 0) return;
    uint ownerIndexBit = 2**ownerIndex;
    var pending = m_pending[_operation];
    if (pending.ownersDone & ownerIndexBit > 0) {
      pending.yetNeeded++;
      pending.ownersDone -= ownerIndexBit;
      Revoke(msg.sender, _operation);
    }
  }

  // Replaces an owner `_from` with another `_to`.
  function changeOwner(address _from, address _to) onlymanyowners(sha3(msg.data)) external {
    if (isOwner(_to)) return;
    uint ownerIndex = m_ownerIndex[uint(_from)];
    if (ownerIndex == 0) return;

    clearPending();
    m_owners[ownerIndex] = uint(_to);
    m_ownerIndex[uint(_from)] = 0;
    m_ownerIndex[uint(_to)] = ownerIndex;
    OwnerChanged(_from, _to);
  }

  function addOwner(address _owner) onlymanyowners(sha3(msg.data)) external {
    if (isOwner(_owner)) return;

    clearPending();
    if (m_numOwners >= c_maxOwners)
      reorganizeOwners();
    if (m_numOwners >= c_maxOwners)
      return;
    m_numOwners++;
    m_owners[m_numOwners] = uint(_owner);
    m_ownerIndex[uint(_owner)] = m_numOwners;
    OwnerAdded(_owner);
  }

  function removeOwner(address _owner) onlymanyowners(sha3(msg.data)) external {
    uint ownerIndex = m_ownerIndex[uint(_owner)];
    if (ownerIndex == 0) return;
    if (m_required > m_numOwners - 1) return;

    m_owners[ownerIndex] = 0;
    m_ownerIndex[uint(_owner)] = 0;
    clearPending();
    reorganizeOwners(); //make sure m_numOwner is equal to the number of owners and always points to the optimal free slot
    OwnerRemoved(_owner);
  }

  function changeRequirement(uint _newRequired) onlymanyowners(sha3(msg.data)) external {
    if (_newRequired > m_numOwners) return;
    m_required = _newRequired;
    clearPending();
    RequirementChanged(_newRequired);
  }

  // Gets an owner by 0-indexed position (using numOwners as the count)
  function getOwner(uint ownerIndex) external constant returns (address) {
    return address(m_owners[ownerIndex + 1]);
  }

  function isOwner(address _addr) constant returns (bool) {
    return m_ownerIndex[uint(_addr)] > 0;
  }

  function hasConfirmed(bytes32 _operation, address _owner) external constant returns (bool) {
    var pending = m_pending[_operation];
    uint ownerIndex = m_ownerIndex[uint(_owner)];

    // make sure they're an owner
    if (ownerIndex == 0) return false;

    // determine the bit to set for this owner.
    uint ownerIndexBit = 2**ownerIndex;
    return !(pending.ownersDone & ownerIndexBit == 0);
  }

  // constructor - stores initial daily limit and records the present day's index.
  function initDaylimit(uint _limit) only_uninitialized {
    m_dailyLimit = _limit;
    m_lastDay = today();
  }
  // (re)sets the daily limit. needs many of the owners to confirm. doesn't alter the amount already spent today.
  function setDailyLimit(uint _newLimit) onlymanyowners(sha3(msg.data)) external {
    m_dailyLimit = _newLimit;
  }
  // resets the amount already spent today. needs many of the owners to confirm.
  function resetSpentToday() onlymanyowners(sha3(msg.data)) external {
    m_spentToday = 0;
  }

  // throw unless the contract is not yet initialized.
  modifier only_uninitialized { if (m_numOwners > 0) throw; _; }

  // constructor - just pass on the owner array to the multiowned and
  // the limit to daylimit
  function initWallet(address[] _owners, uint _required, uint _daylimit) only_uninitialized {
    initDaylimit(_daylimit);
    initMultiowned(_owners, _required);
  }

  // kills the contract sending everything to `_to`.
  function kill(address _to) onlymanyowners(sha3(msg.data)) external {
    suicide(_to);
  }

  // Outside-visible transact entry point. Executes transaction immediately if below daily spend limit.
  // If not, goes into multisig process. We provide a hash on return to allow the sender to provide
  // shortcuts for the other confirmations (allowing them to avoid replicating the _to, _value
  // and _data arguments). They still get the option of using them if they want, anyways.
  function execute(address _to, uint _value, bytes _data) external onlyowner returns (bytes32 o_hash) {
    // first, take the opportunity to check that we're under the daily limit.
    if ((_data.length == 0 && underLimit(_value)) || m_required == 1) {
      // yes - just execute the call.
      address created;
      if (_to == 0) {
        created = create(_value, _data);
      } else {
        if (!_to.call.value(_value)(_data))
          throw;
      }
      SingleTransact(msg.sender, _value, _to, _data, created);
    } else {
      // determine our operation hash.
      o_hash = sha3(msg.data, block.number);
      // store if it's new
      if (m_txs[o_hash].to == 0 && m_txs[o_hash].value == 0 && m_txs[o_hash].data.length == 0) {
        m_txs[o_hash].to = _to;
        m_txs[o_hash].value = _value;
        m_txs[o_hash].data = _data;
      }
      if (!confirm(o_hash)) {
        ConfirmationNeeded(o_hash, msg.sender, _value, _to, _data);
      }
    }
  }

  function create(uint _value, bytes _code) internal returns (address o_addr) {
    assembly {
      o_addr := create(_value, add(_code, 0x20), mload(_code))
      jumpi(invalidJumpLabel, iszero(extcodesize(o_addr)))
    }
  }

  // confirm a transaction through just the hash. we use the previous transactions map, m_txs, in order
  // to determine the body of the transaction from the hash provided.
  function confirm(bytes32 _h) onlymanyowners(_h) returns (bool o_success) {
    if (m_txs[_h].to != 0 || m_txs[_h].value != 0 || m_txs[_h].data.length != 0) {
      address created;
      if (m_txs[_h].to == 0) {
        created = create(m_txs[_h].value, m_txs[_h].data);
      } else {
        if (!m_txs[_h].to.call.value(m_txs[_h].value)(m_txs[_h].data))
          throw;
      }

      MultiTransact(msg.sender, _h, m_txs[_h].value, m_txs[_h].to, m_txs[_h].data, created);
      delete m_txs[_h];
      return true;
    }
  }

  // INTERNAL METHODS

  function confirmAndCheck(bytes32 _operation) internal returns (bool) {
    // determine what index the present sender is:
    uint ownerIndex = m_ownerIndex[uint(msg.sender)];
    // make sure they're an owner
    if (ownerIndex == 0) return;

    var pending = m_pending[_operation];
    // if we're not yet working on this operation, switch over and reset the confirmation status.
    if (pending.yetNeeded == 0) {
      // reset count of confirmations needed.
      pending.yetNeeded = m_required;
      // reset which owners have confirmed (none) - set our bitmap to 0.
      pending.ownersDone = 0;
      pending.index = m_pendingIndex.length++;
      m_pendingIndex[pending.index] = _operation;
    }
    // determine the bit to set for this owner.
    uint ownerIndexBit = 2**ownerIndex;
    // make sure we (the message sender) haven't confirmed this operation previously.
    if (pending.ownersDone & ownerIndexBit == 0) {
      Confirmation(msg.sender, _operation);
      // ok - check if count is enough to go ahead.
      if (pending.yetNeeded <= 1) {
        // enough confirmations: reset and run interior.
        delete m_pendingIndex[m_pending[_operation].index];
        delete m_pending[_operation];
        return true;
      }
      else
      {
        // not enough: record that this owner in particular confirmed.
        pending.yetNeeded--;
        pending.ownersDone |= ownerIndexBit;
      }
    }
  }

  function reorganizeOwners() private {
    uint free = 1;
    while (free < m_numOwners)
    {
      while (free < m_numOwners && m_owners[free] != 0) free++;
      while (m_numOwners > 1 && m_owners[m_numOwners] == 0) m_numOwners--;
      if (free < m_numOwners && m_owners[m_numOwners] != 0 && m_owners[free] == 0)
      {
        m_owners[free] = m_owners[m_numOwners];
        m_ownerIndex[m_owners[free]] = free;
        m_owners[m_numOwners] = 0;
      }
    }
  }

  // checks to see if there is at least `_value` left from the daily limit today. if there is, subtracts it and
  // returns true. otherwise just returns false.
  function underLimit(uint _value) internal onlyowner returns (bool) {
    // reset the spend limit if we're on a different day to last time.
    if (today() > m_lastDay) {
      m_spentToday = 0;
      m_lastDay = today();
    }
    // check to see if there's enough left - if so, subtract and return true.
    // overflow protection                    // dailyLimit check
    if (m_spentToday + _value >= m_spentToday && m_spentToday + _value <= m_dailyLimit) {
      m_spentToday += _value;
      return true;
    }
    return false;
  }

  // determines today's index.
  function today() private constant returns (uint) { return now / 1 days; }

  function clearPending() internal {
    uint length = m_pendingIndex.length;

    for (uint i = 0; i < length; ++i) {
      delete m_txs[m_pendingIndex[i]];

      if (m_pendingIndex[i] != 0)
        delete m_pending[m_pendingIndex[i]];
    }

    delete m_pendingIndex;
  }

  // FIELDS
  address constant _walletLibrary = 0xcafecafecafecafecafecafecafecafecafecafe;

  // the number of owners that must confirm the same operation before it is run.
  uint public m_required;
  // pointer used to find a free slot in m_owners
  uint public m_numOwners;

  uint public m_dailyLimit;
  uint public m_spentToday;
  uint public m_lastDay;

  // list of owners
  uint[256] m_owners;

  uint constant c_maxOwners = 250;
  // index on the list of owners to allow reverse lookup
  mapping(uint => uint) m_ownerIndex;
  // the ongoing operations.
  mapping(bytes32 => PendingState) m_pending;
  bytes32[] m_pendingIndex;

  // pending transactions we have at present.
  mapping (bytes32 => Transaction) m_txs;
}

contract Wallet is WalletEvents {

  // WALLET CONSTRUCTOR
  //   calls the `initWallet` method of the Library in this context
  function Wallet(address[] _owners, uint _required, uint _daylimit) {
    // Signature of the Wallet Library's init function
    bytes4 sig = bytes4(sha3("initWallet(address[],uint256,uint256)"));
    address target = _walletLibrary;

    // Compute the size of the call data : arrays has 2
    // 32bytes for offset and length, plus 32bytes per element ;
    // plus 2 32bytes for each uint
    uint argarraysize = (2 + _owners.length);
    uint argsize = (2 + argarraysize) * 32;

    assembly {
      // Add the signature first to memory
      mstore(0x0, sig)
      // Add the call data, which is at the end of the
      // code
      codecopy(0x4,  sub(codesize, argsize), argsize)
      // Delegate call to the library
      delegatecall(sub(gas, 10000), target, 0x0, add(argsize, 0x4), 0x0, 0x0)
    }
  }

  // METHODS

  // gets called when no other function matches
  function() payable {
    // just being sent some cash?
    if (msg.value > 0)
      Deposit(msg.sender, msg.value);
    else if (msg.data.length > 0)
      _walletLibrary.delegatecall(msg.data);
  }

  // Gets an owner by 0-indexed position (using numOwners as the count)
  function getOwner(uint ownerIndex) constant returns (address) {
    return address(m_owners[ownerIndex + 1]);
  }

  // As return statement unavailable in fallback, explicit the method here

  function hasConfirmed(bytes32 _operation, address _owner) external constant returns (bool) {
    return _walletLibrary.delegatecall(msg.data);
  }

  function isOwner(address _addr) constant returns (bool) {
    return _walletLibrary.delegatecall(msg.data);
  }

  // FIELDS
  address constant _walletLibrary = 0x863df6bfa4469f3ead0be8f9f2aae51c91a907b4;

  // the number of owners that must confirm the same operation before it is run.
  uint public m_required;
  // pointer used to find a free slot in m_owners
  uint public m_numOwners;

  uint public m_dailyLimit;
  uint public m_spentToday;
  uint public m_lastDay;

  // list of owners
  uint[256] m_owners;
}

The disassembled code returned from pyevmasm:
'PUSH1 0x60\nPUSH1 0x40\nMSTORE\nCALLDATASIZE\nISZERO\nPUSH2 0x72\nJUMPI\nPUSH4 0xffffffff\nPUSH1 0xe0\nPUSH1 0x2\nEXP\nPUSH1 0x0\nCALLDATALOAD\nDIV\nAND\nPUSH4 0x2f54bf6e\nDUP2\nEQ\nPUSH2 0x12d\nJUMPI\nDUP1\nPUSH4 0x4123cb6b\nEQ\nPUSH2 0x15d\nJUMPI\nDUP1\nPUSH4 0x52375093\nEQ\nPUSH2 0x17f\nJUMPI\nDUP1\nPUSH4 0x659010e7\nEQ\nPUSH2 0x1a1\nJUMPI\nDUP1\nPUSH4 0x746c9171\nEQ\nPUSH2 0x1c3\nJUMPI\nDUP1\nPUSH4 0xc2cf7326\nEQ\nPUSH2 0x1e5\nJUMPI\nDUP1\nPUSH4 0xc41a360a\nEQ\nPUSH2 0x218\nJUMPI\nDUP1\nPUSH4 0xf1736d86\nEQ\nPUSH2 0x247\nJUMPI\nJUMPDEST\nPUSH2 0x12b\nJUMPDEST\nPUSH1 0x0\nCALLVALUE\nGT\nISZERO\nPUSH2 0xc7\nJUMPI\nPUSH1 0x40\nDUP1\nMLOAD\nPUSH1 0x1\nPUSH1 0xa0\nPUSH1 0x2\nEXP\nSUB\nCALLER\nAND\nDUP2\nMSTORE\nCALLVALUE\nPUSH1 0x20\nDUP3\nADD\nMSTORE\nDUP2\nMLOAD\nPUSH32 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c\nSWAP3\nSWAP2\nDUP2\nSWAP1\nSUB\nSWAP1\nSWAP2\nADD\nSWAP1\nLOG1\nPUSH2 0x127\nJUMP\nJUMPDEST\nPUSH1 0x0\nCALLDATASIZE\nGT\nISZERO\nPUSH2 0x127\nJUMPI\nPUSH20 0x863df6bfa4469f3ead0be8f9f2aae51c91a907b4\nPUSH1 0x1\nPUSH1 0xa0\nPUSH1 0x2\nEXP\nSUB\nAND\nPUSH1 0x0\nCALLDATASIZE\nPUSH1 0x0\nPUSH1 0x40\nMLOAD\nPUSH1 0x20\nADD\nMSTORE\nPUSH1 0x40\nMLOAD\nDUP1\nDUP4\nDUP4\nDUP1\nDUP3\nDUP5\nCALLDATACOPY\nDUP3\nADD\nSWAP2\nPOP\nPOP\nSWAP3\nPOP\nPOP\nPOP\nPUSH1 0x20\nPUSH1 0x40\nMLOAD\nDUP1\nDUP4\nSUB\nDUP2\nDUP6\nPUSH1 0x32\nGAS\nSUB\nDELEGATECALL\nISZERO\nISZERO\nPUSH2 0x124\nJUMPI\nINVALID\nJUMPDEST\nPOP\nPOP\nJUMPDEST\nJUMPDEST\nJUMPDEST\nJUMP\nJUMPDEST\nSTOP\nJUMPDEST\nCALLVALUE\nISZERO\nPUSH2 0x135\nJUMPI\nINVALID\nJUMPDEST\nPUSH2 0x149\nPUSH1 0x1\nPUSH1 0xa0\nPUSH1 0x2\nEXP\nSUB\nPUSH1 0x4\nCALLDATALOAD\nAND\nPUSH2 0x269\nJUMP\nJUMPDEST\nPUSH1 0x40\nDUP1\nMLOAD\nSWAP2\nISZERO\nISZERO\nDUP3\nMSTORE\nMLOAD\nSWAP1\nDUP2\nSWAP1\nSUB\nPUSH1 0x20\nADD\nSWAP1\nRETURN\nJUMPDEST\nCALLVALUE\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DMOD\nSWAP1\nADDRESS\nINVALID\nDUP1\nBLOCKHASH\nSTOP\nINVALID'```

The result returned from etherscan's disassembler tool:
[1] PUSH1 0x60
[3] PUSH1 0x40
[4] MSTORE
[5] CALLDATASIZE
[6] ISZERO
[9] PUSH2 0x0072
[10] JUMPI
[15] PUSH4 0xffffffff
[17] PUSH1 0xe0
[19] PUSH1 0x02
[20] EXP
[22] PUSH1 0x 


I wonder whether this is due to the heuristics used in this library or if the block.number opcode (or some other opcode somehow calls BLOCKHASH).

assemble_hex() has confusing name

The function assemble_hex() takes a string of evm assembly and produces assembled bytecode as a hexstring. To me, this function sounds like it takes a hexstring, or something, which I found confusing. I think we should rename it.

this would be an api breaking change.

colorize evmasm output

It would be nice if the evmasm command output looked nicer by having different colors

Instruction.semantics should be renamed

I don't think .semantics is exactly the optimal name for this member of the Instruction class, i think a better name might be .mnemonic.

this would be an api breaking change.

UnknownMnemonicError MSTORE

I tried assembling a few files that I got by compiling solidity with --asm. When assembling them in pyevmasm, I'm getting pyevmasm.evmasm.UnknownMnemonicError: MSTORE(0X40,
as well as

File "/usr/lib/python3.7/site-packages/pyevmasm/evmasm.py", line 594, in assemble_all
    instr = assemble_one(line, pc=pc)
  File "/usr/lib/python3.7/site-packages/pyevmasm/evmasm.py", line 561, in assemble_one
    raise Exception("Something wrong at pc %d" % pc)
Exception: Something wrong at pc 0

Is it possible that these Mnemonics are not implemented, and if they are, how can I assemble the file?
Thanks

Tautology in README

The first line of the "Installation" section in the README seems to be a tautology:

Python >=2.7 or Python >=3.3 is required.

Is it correct to write less than instead of greater than for one of these versions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.