Coder Social home page Coder Social logo

ethereumjs / ethereumjs-monorepo Goto Github PK

View Code? Open in Web Editor NEW
2.5K 59.0 720.0 85.12 MB

Monorepo for the Ethereum VM TypeScript Implementation

JavaScript 1.74% Python 0.07% TypeScript 97.20% Shell 0.59% Solidity 0.01% Dockerfile 0.01% HTML 0.38%
javascript ethereum ethereumjs evm virtual-machine vm bytecode typescript monorepo

ethereumjs-monorepo's Introduction

EthereumJS Monorepo

Code Coverage Discord GitPOAP

This repository holds various protocol building blocks of the Ethereum blockchain execution layer and is managed by the Ethereum Foundation JavaScript team. There is a TypeScript implementation of the Ethereum Virtual Machine (EVM) ready to be used in Node.js or a browser environment, implementations of core structural blockchain building blocks like an Ethereum Tx, Block or Blockchain as well as a Trie (Merkle Patricia Tree) and devp2p (execution networking layer) implementation.

All libraries are bound together by the core Common library keeping track of chain specifics and hardfork changes. They are complemented by helper packages like RLP for data encoding/decoding or Util, providing helper functionalities like (byte) conversion, signatures, types and others.

Finally, the EthereumJS Execution Client (EthereumJS) has been in active development for some time now. It already serves a variety of purposes like testing, research (e.g. EIPs) and developer tooling to engage with the protocol.

Also to note: on the Ethereum Consensus side, the ChainSafe Lodestar repository complements this repository with an Ethereum Consensus Client implementation as well as various protocol implementations (like an SSZ library) developed in the context of Ethereum Consensus layer evolution.

Packages

Below you can find a list of the packages included in this repository.

package npm issues tests coverage
@ethereumjs/block NPM Package Block Issues Actions Status Code Coverage
@ethereumjs/blockchain NPM Package Blockchain Issues Actions Status Code Coverage
@ethereumjs/client NPM Package Client Issues Actions Status Code Coverage
@ethereumjs/common NPM Package Common Issues Actions Status Code Coverage
@ethereumjs/devp2p NPM Package Devp2p Issues Actions Status Code Coverage
@ethereumjs/ethash NPM Package Ethash Issues Actions Status Code Coverage
@ethereumjs/evm NPM Package EVM Issues Actions Status Code Coverage
@ethereumjs/genesis NPM Package Genesis Issues Actions Status Code Coverage
@ethereumjs/rlp NPM Package rlp Issues Actions Status Code Coverage
@ethereumjs/statemanager NPM Package StateManager Issues Actions Status Code Coverage
@ethereumjs/trie NPM Package Trie Issues Actions Status Code Coverage
@ethereumjs/tx NPM Package Tx Issues Actions Status Code Coverage
@ethereumjs/util NPM Package Util Issues Actions Status Code Coverage
@ethereumjs/verkle NPM Package VM Issues Actions Status Code Coverage
@ethereumjs/vm NPM Package VM Issues Actions Status Code Coverage
@ethereumjs/wallet NPM Package StateManager Issues Actions Status Code Coverage

Branches

The following are our currently active branches:

Branch Release Series Status  Description
master v7 Active Current release and working branch
maintenance-v6 v6 Maintenance Maintenance for v6 releases

Breaking releases are done in sync for all libraries, and release cycles are named after the @ethereumjs/vm version. In most cases PRs should be opened towards the current working branch.

To inspect code related to a specific package version, refer to the tags.

Coverage report

Detailed version can be seen on Codecov.io

Code Coverage

Package dependency relationship

 graph TD
   vm{vm}
   client{client}
   ethash --> blockchain
   ethash --> client
   devp2p --> client
   block --> client
   block --> blockchain
   block --> ethash
   block --> vm
   blockchain --> client
   blockchain --> vm
   trie --> client
   trie --> vm
   trie --> blockchain
   trie --> block
   trie --> statemanager
   common --> block
   common --> statemanager
   common --> tx
   common --> blockchain
   common --> vm
   common --> evm
   common --> client
   common --> devp2p
   common --> genesis
   evm --> vm
   evm --> client
   genesis --> client
   genesis --> statemanager
   genesis --> trie
   tx --> block
   tx --> evm
   tx --> vm
   vm --> client
   statemanager --> evm
   statemanager --> vm

To update the diagram above edit the README file and open a new PR with the changes.

Getting Started

See our monorepo documentation to get started on setting up the repository and installing dependencies. The config folder gives an overview on shared configuration and scripts between packages.

EthereumJS

See our organizational documentation for an introduction to EthereumJS as well as information on current standards and best practices. If you want to join for work or carry out improvements on the libraries, please review our contribution guidelines first.

License

Most packages are MPL-2.0 licensed, see package folder for the respective license.

ethereumjs-monorepo's People

Contributors

acolytec3 avatar alcuadrado avatar axic avatar cdetrio avatar cgewecke avatar chikeichan avatar danjm avatar dryajov avatar emersonmacro avatar evertonfraga avatar fanatid avatar faustbrian avatar g11tech avatar gabrocheleau avatar greenkeeper[bot] avatar holgerd77 avatar jochem-brouwer avatar jwasinger avatar krzkaczor avatar kumavis avatar paulmillr avatar rumkin avatar ryanio avatar s1na avatar scorbajio avatar scottypoi avatar vpulim avatar wanderer avatar whymarrh avatar youfoundron 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  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

ethereumjs-monorepo's Issues

runCode swallows errors

runCode does not distinguish between legit errors (stack underflow) and catastrophic errors (state read failure).

I had a bug in my overridden vm.stateManager._lookupStorageTrie method that threw an error.

This error was swallowed and the vm continued as if nothing was wrong until the stateRoot did not match

StateManager - storage and rlp encoding [breaking]

Background:

Raw storage values are RLP encoded when being put into the storageTree. This does not achieve anything as values can only be hex strings. It exists for historical reasons, and cannot be easily removed as if affects the stateRoot.

Motivation:

The StateManager has mostly been private, but as we solidify the api surface, more people would like to take advantage of its abstractions. Currently the necessary RLP encoding and decoding happens externally to the StateManager contractStorage api. When checking data in the state trie for debugging , tests, RPC implementations, its really easy to forget this strange antiquity.

Suggested Change:

Hide this complexity in the StateManager contractStorage api. This would be a breaking change.

Affected APIs:

stateManager.getContractStorage(address, key, cb)
stateManager.putContractStorage(address, key, value, cb)

current example:
stateManager.getContractStorage(address, key, function (err, value) {
  var loaded = rlp.decode(value)
  cb(err, loaded)
})
example after proposed change:
stateManager.getContractStorage(address, key, cb)

operations remove 00 prefix from addresses which leads to crashes.

I discovered this first in ethereumjs-vm 1.4 and could reproduce it in 2.0. Strangely this bug is system specific - it lead to a crash on Ubuntu but succeeded on OS X.

The error happens on a deployment of contract A which deploys another contract B. Code was compiled with solidity 0.4.3

At some Point the stack look like the following:

0 0x00b68db15676a4024a0b2cfe93c41c10c2323c44  <- B's address after deployment
1 0x01
...

Here the operation MUL is performed which produces the stack:

0 0xb68db15676a4024a0b2cfe93c41c10c2323c44
...

Note that the new address misses its 00 prefix which later leads to an error.

Error: Number can only safely store up to 53 bits

Getting this while running the tests on a fresh clone.

OSX Yosemite
Node v6.3.0

# [bcInvalidRLPTest] BLOCK_gasLimit_TooLarge
ok 186 correct pre stateRoot
/Users/aakilfernandes/projects/safemarket/ethereumjs-vm/node_modules/bn.js/lib/bn.js:6
    if (!val) throw new Error(msg || 'Assertion failed');
              ^

Error: Number can only safely store up to 53 bits
    at assert (/Users/aakilfernandes/projects/safemarket/ethereumjs-vm/node_modules/bn.js/lib/bn.js:6:21)
    at BN.toNumber (/Users/aakilfernandes/projects/safemarket/ethereumjs-vm/node_modules/bn.js/lib/bn.js:506:7)
    at Object.exports.bufferToInt (/Users/aakilfernandes/projects/safemarket/ethereumjs-vm/node_modules/ethereumjs-block/node_modules/ethereumjs-util/index.js:199:40)
    at BlockHeader.validateGasLimit (/Users/aakilfernandes/projects/safemarket/ethereumjs-vm/node_modules/ethereumjs-block/header.js:146:26)
    at /Users/aakilfernandes/projects/safemarket/ethereumjs-vm/node_modules/ethereumjs-block/header.js:196:15
    at /Users/aakilfernandes/projects/safemarket/ethereumjs-vm/node_modules/ethereumjs-blockchain/index.js:326:7
    at /Users/aakilfernandes/projects/safemarket/ethereumjs-vm/node_modules/levelup/lib/levelup.js:230:7
    at Immediate.callNext (/Users/aakilfernandes/projects/safemarket/ethereumjs-vm/node_modules/memdown/memdown.js:173:5)
    at runCallback (timers.js:566:20)
    at tryOnImmediate (timers.js:546:5)
npm ERR! Test failed.  See above for more details.

StateManager Should be public

It would be nice to expose the StateManager publically. And split it into its own module. What should the API be?

runCode callback exception attr doc is wrong

This is what runCode.js looks like now:

exception: err ? 0 : 1

It seems to me that this logic is backwards, and should be

exception: err ? 1 : 0

But I'm also not sure why it isn't a boolean, as the documentation says it should be.

exception: !!err

44d096a fixed this and closed #48, but then it got reverted. I can't tell why.

Contact?

Sorry for this inappropriate issue, but is there a way to contact you @wanderer? Can't find an e-mail address . It's business talk.

tests fail on 64 bit ubuntu 14.04

andreas@AndreasLT:~/WebstormProjects/ethereumjs-vm$ npm test

> [email protected] test /home/andreas/WebstormProjects/ethereumjs-vm
> ./tests/tester -a

TAP version 13
# executable test
not ok 1  assert.js:89 throw new assert.AssertionError({ ^ 
  ---
    operator: fail
    at: Socket.<anonymous> (/home/andreas/WebstormProjects/ethereumjs-vm/tests/tester.js:11:7)
  ...
not ok 2 AssertionError: false == true at Object.exports.pubToAddress.exports.publicToAddress (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/ethereumjs-util/index.js:307:3) at Transaction.getSenderAddress (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/ethereumjs-tx/index.js:154:18) at Object.defineProperty.get (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/ethereumjs-tx/index.js:97:25) at populateCache (/home/andreas/WebstormProjects/ethereumjs-vm/lib/runTx.js:72:20) at /home/andreas/WebstormProjects/ethereumjs-vm/node_modules/async/lib/async.js:718:13 at iterate (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/async/lib/async.js:262:13) at async.forEachOfSeries.async.eachOfSeries (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/async/lib/async.js:281:9) at _parallel (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/async/lib/async.js:717:9) at Object.async.series (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/async/lib/async.js:739:9) at VM.module.exports [as runTx] (/home/andreas/WebstormProjects/ethereumjs-vm/lib/runTx.js:39:9) 
  ---
    operator: fail
    at: Socket.<anonymous> (/home/andreas/WebstormProjects/ethereumjs-vm/tests/tester.js:11:7)
  ...
# test the cache api
# should have the correct value in the cache 

assert.js:89
  throw new assert.AssertionError({
  ^
AssertionError: false == true
    at Object.exports.pubToAddress.exports.publicToAddress (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/ethereumjs-util/index.js:307:3)
    at Transaction.getSenderAddress (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/ethereumjs-tx/index.js:154:18)
    at Object.defineProperty.get (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/ethereumjs-tx/index.js:97:25)
    at populateCache (/home/andreas/WebstormProjects/ethereumjs-vm/lib/runTx.js:72:20)
    at /home/andreas/WebstormProjects/ethereumjs-vm/node_modules/async/lib/async.js:718:13
    at iterate (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/async/lib/async.js:262:13)
    at async.forEachOfSeries.async.eachOfSeries (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/async/lib/async.js:281:9)
    at _parallel (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/async/lib/async.js:717:9)
    at Object.async.series (/home/andreas/WebstormProjects/ethereumjs-vm/node_modules/async/lib/async.js:739:9)
    at VM.module.exports [as runTx] (/home/andreas/WebstormProjects/ethereumjs-vm/lib/runTx.js:39:9)
npm ERR! Test failed.  See above for more details.

Just pulled repo and ran 'npm install'

mainnet block 0x01331e causes stateTrie crash

/Users/kumavis/dev/node-blockchain-server/node_modules/merkle-patricia-tree/baseTrie.js:359
  var lastNode = stack.pop()
                      ^

TypeError: Cannot read property 'pop' of undefined
    at SecureTrie.Trie._updateNode (/Users/kumavis/dev/node-blockchain-server/node_modules/merkle-patricia-tree/baseTrie.js:359:23)
    at /Users/kumavis/dev/node-blockchain-server/node_modules/merkle-patricia-tree/baseTrie.js:106:16
    at /Users/kumavis/dev/node-blockchain-server/node_modules/merkle-patricia-tree/baseTrie.js:442:14
    at processNode (/Users/kumavis/dev/node-blockchain-server/node_modules/merkle-patricia-tree/baseTrie.js:447:23)
    at /Users/kumavis/dev/node-blockchain-server/node_modules/merkle-patricia-tree/baseTrie.js:438:5
    at /Users/kumavis/dev/node-blockchain-server/node_modules/merkle-patricia-tree/baseTrie.js:179:7
    at /Users/kumavis/dev/node-blockchain-server/node_modules/merkle-patricia-tree/util.js:75:7
    at /Users/kumavis/dev/node-blockchain-server/node_modules/async/lib/async.js:52:16
    at /Users/kumavis/dev/node-blockchain-server/node_modules/async/lib/async.js:269:32
    at /Users/kumavis/dev/node-blockchain-server/node_modules/async/lib/async.js:44:16

Expose constructors

The newest version of ethereumjs-vm seems to have changes the api such that Account, Trie, Transaction etc are not publicly accessable meaning that users of the browserified version in ./dist need to re-require those libs to interact with the vm.

Could these be re-exposed?

fullexample.js: self._trie.get is not a function

Just trying to run fullexample.js, getting self._trie.get is not a function.

Full stack trace:

TypeError: self._trie.get is not a function
    at Cache._lookupAccount (/home/jeremy/Development/vm-test/node_modules/ethereumjs-vm/lib/cache.js:41:14)
    at /home/jeremy/Development/vm-test/node_modules/ethereumjs-vm/lib/cache.js:74:10
    at /home/jeremy/Development/vm-test/node_modules/ethereumjs-vm/node_modules/async/lib/async.js:181:20
    at iterate (/home/jeremy/Development/vm-test/node_modules/ethereumjs-vm/node_modules/async/lib/async.js:262:13)
    at Object.async.forEachOfSeries.async.eachOfSeries (/home/jeremy/Development/vm-test/node_modules/ethereumjs-vm/node_modules/async/lib/async.js:281:9)
    at Object.async.forEachSeries.async.eachSeries (/home/jeremy/Development/vm-test/node_modules/ethereumjs-vm/node_modules/async/lib/async.js:214:22)
    at Cache.warm (/home/jeremy/Development/vm-test/node_modules/ethereumjs-vm/lib/cache.js:72:9)
    at StateManager.proto.warmCache (/home/jeremy/Development/vm-test/node_modules/ethereumjs-vm/lib/stateManager.js:260:14)
    at populateCache (/home/jeremy/Development/vm-test/node_modules/ethereumjs-vm/lib/runTx.js:85:23)
    at /home/jeremy/Development/vm-test/node_modules/ethereumjs-vm/node_modules/async/lib/async.js:718:13

I have these dependencies in my package.json

  "dependencies": {
    "async": "^2.0.1",
    "ethereumjs-account": "^2.0.4",
    "ethereumjs-tx": "^1.1.2",
    "ethereumjs-util": "^4.5.0",
    "ethereumjs-vm": "^1.4.1",
    "merkle-patricia-tree": "^2.1.2",
    "rlp": "^2.0.0"
  }

using

node v6.5.0
npm 3.10.6

Performance in Browser

from wanderer/node-ethereum/issues/16

contract c {
    uint[] data;
    function f() {
        for (uint x = 0; x < 1000 ; x++)
            data[data.length++] = x;
    }
}

run inside the browser will stall it (inluding all other tabs) for several minutes. Changing the loop into an infinite loop (and providing 3000000 gas) will make it even worse and crash most of the browsers.
It would be good to know whether this also happens for node.

bin tests

In the Readme it says

if you want to just run the Blockchain tests run ./bin/tester -b if you want to just run the VM tests run ./bin/tester -v if you want to just run the State tests run ./bin/tester -s

Are those tests moved? Or are they just gone

Supporting eth_call - should runCall be a public method?

runCall seems to be the most appropriate way to simulate an eth_call because it still performs value transfer but skips nonce and balance checking. it is not currently covered in the readme. here is a discussion with tim on it

tim [9:53 AM] 
@kumavis: @wanderer Is there any way to skip the balance check when calling `vm.runTx()`? I’m currently using `runTx` to simulate `eth_call` within the testrpc: I’m checkpointing the state trie, calling `runTx`, then reverting. Unfortunately, when an `eth_call` is made from an account with a zero balance, `runTx` fails - and since `eth_call` is supposed to be free, in my context it shouldn’t fail. Is there any way around this?

[9:53] 
Wondering if I should be calling `vm.runCall` instead. I forget why I’m not.

kumavis [9:55 AM] 
@tim yeah i realized this a couple weeks back

[9:55] 
its a fundamental flaw of eth call that hasnt been discussed

tim [9:56 AM] 
Would calling `vm.runCall` fix it?

kumavis [9:56 AM] 
mmmm… maybe?

tim [9:56 AM] 
Looks like `vm.runCall`’s params are quite different.

[9:56] 
But it worth trying.

kumavis [9:56 AM] 
we could also just create an option to skip the balance check

[9:56] 
but more importantly: what is the ‘correct’ behaviour(edited)

[9:57] 
or simply, what does geth do : P

tim [9:57 AM] 
kumavis: I ​*believe*​ the correct behavior is to let the call run since `eth_call` doesn’t change state. But I technically haven’t tried it on geth, as far as I can remember anyway.

[9:57] 
Right.

[9:58] 
I can probably try it easily though.

kumavis [9:58 AM] 
problem with geth at least accessing it from the rpc, is that you dont know what happened

tim [9:58 AM] 
What do you mean?

kumavis [9:58 AM] 
you just get a result

tim [9:58 AM] 
Ah, right.

kumavis [9:58 AM] 
OOG? other error? idk just “0x"

new messages
tim [9:58 AM] 
Ya, makes sense.

[9:59] 
Which is why the testrpc is nice - it exposes that.

[9:59] 
Although there’s no reason why geth can’t, come to think of it.

[9:59] 
Will try geth, brb

kumavis [10:03 AM] 
@tim seems like geth is okay with it

tim [10:03 AM] 
Oh sweet, you did my work for me. Was still setting things up.

[10:03] 
Ya, that’s what I thought.

kumavis [10:03 AM] 
yeah was trying to think of the fastest way..

[10:03] 
`curl -d '{"jsonrpc":"2.0","method":"eth_call","params": [{"from":"0x0000","to":"0x3","data":"0x1234"}], "id":1}' -X POST https://rawrpc.metamask.io | jsonogram`

[10:04] 
i went with sending junk to precompiled contracts

[10:04] 
hah, except the null adress actualyl has a lot of funds

[10:04] 
yeah still works

tim [10:05 AM] 
kumavis: that’s a random `to` though. Is that even a valid request?

kumavis [10:05 AM] 
yeah geth left-pads the params

[10:05] 
its a precompiled contract

tim [10:06 AM] 
Ah, right.

[10:06] 
Okay, well then.

[10:06] 
I’ll try figuring out how to run `vm.runCall` and see if that works.

kumavis [10:06 AM] 
https://github.com/ethereumjs/ethereumjs-vm/blob/ee76631dbc77f8d587ed6435aafde3187aa28a5d/lib/index.js#L38

GitHub
ethereumjs/ethereumjs-vm
ethereumjs-vm - the ethereum VM implemented in JS

tim [10:06 AM] 
I’d rather try to get runCall working that skip the check.

[10:06] 
Only because there’s no reason to add that feature if it already exists.

[10:07] 
But It’s entirely possible I don’t understand the purpose of runCall within the context of ethereumjs-vm

kumavis [10:08 AM] 
this could use more detail, but does make it look like runTx is not necesary https://github.com/ethereumjs/ethereumjs-vm#internal-structure

GitHub
ethereumjs/ethereumjs-vm
ethereumjs-vm - the ethereum VM implemented in JS

tim [10:09 AM] 
Or maybe runCode is what I need?

[10:10] 
Oooh, if I use runCode I have to get the code first.

[10:10] 
Let’s hope getCode() works how it should. :simple_smile:

kumavis [10:10 AM] 
you want runCall

[10:11] 
b/c you want to transfer the value

tim [10:11 AM] 
kumavis?

kumavis [10:11 AM] 
`The opFns for CREATE, CALL, and CALLCODE call back up to runCall.`(edited)

[10:11] 
you shouldnt start lower than runCall

tim [10:12 AM] 
runCall’s not a first class citizen in the readme.

[10:12] 
Also, what do you mean by transferring the value?

kumavis [10:12 AM] 
new Tx({ value: 12 })

[10:12] 
sweet sweet ether baby

[10:13] 
> runCall’s not a first class citizen in the readme
yeah thats an issue

tim [10:13 AM] 
kumavis: But that does nothing in the context of `eth_call` - at least, the state shouldn’t change in the end.

kumavis [10:13 AM] 
i think it should be public

[10:13] 
@tim no but that state may be part of the run

tim [10:13 AM] 
Hmm, good point.

kumavis [10:13 AM] 
the contract can query balances and all that

[10:14] 
the value transfer happens first

Remove support for node 0.11/0.12

Because of the dependency of ethereumjs-tx, Travis fails on those two versions. -tx has removed support for 0.11/0.12 so it makes sense to do the same here?

Note: removing support means removing it from Travis and adding a note into the README.

Fix travis for `testVM`

The test takes > 45mins, which is the hard cut-off time limit on Travis.

Solutions/workarounds:
a) disable it on Travis - at the same time simpler VM tests should be added
b) split up into shorter tests

Issue with `vm.stateManager.getContractCode()`

Blockchain.prototype.getCode = function(address, callback) {
  var self = this;
  address = new Buffer(utils.stripHexPrefix(address));
  this.vm.stateManager.getContractCode(address, function(err, result) {
    console.log(err, result);

    if (err != null) {
      callback(err);
    } else {
      callback(null, self.toHex(result));
    }
  });
}
Blockchain.prototype.processTransaction = function(from, rawTx, callback) {
  var self = this;

  var block = this.pendingBlock;
  var address = new Buffer(utils.stripHexPrefix(from), "hex");
  var privateKey = new Buffer(this.accounts[from].secretKey, 'hex');

  this.stateTrie.get(address, function(err, val) {
    var account = new Account(val);

    // If the user specified a nonce, use that instead.
    if (rawTx.nonce == null) {
      rawTx.nonce = self.toHex(account.nonce);
    }

    var tx = new Transaction(rawTx);

    tx.sign(privateKey);

    var tx_hash = self.toHex(tx.hash());

    // Add the transaction to the block.
    block.transactions.push(tx);

    self.vm.runBlock({
      block: block,
      generate: true
    }, function(err, results) {
      if (err) {
        callback(err);
        return;
      }

      if (results.error != null) {
        callback(new Error("VM error: " + results.error));
        return;
      }

      var receipt = results.receipts[0];
      var result = results.results[0];

      if (result.vm.exception != 1) {
        callback(new Error("VM Exception while executing transaction: " + result.vm.exceptionError));
        return;
      }

      var logs = [];

      for (var i = 0; i < receipt.logs.length; i++) {
        var log = receipt.logs[i];
        var address = self.toHex(log[0]);
        var topics = []

        for (var j = 0; j < log[1].length; j++) {
          topics.push(self.toHex(log[1][j]));
        }

        var data = self.toHex(log[2]);

        logs.push({
          logIndex: self.toHex(i),
          transactionIndex: "0x0",
          transactionHash: tx_hash,
          blockHash: self.toHex(block.hash()),
          blockNumber: self.toHex(block.header.number),
          address: address,
          data: data,
          topics: topics,
          type: "mined"
        });
      }

      var tx_result = {
        tx: tx,
        block_number: self.toHex(block.header.number),
        block: block,
        stateRoot: self.toHex(receipt.stateRoot),
        gasUsed: self.toHex(receipt.gasUsed),
        bitvector: self.toHex(receipt.bitvector),
        logs: logs,
        createdAddress: result.createdAddress != null ? self.toHex(result.createdAddress) : null,
        bloom: result.bloom,
        amountSpent: result.amountSpent
      };

      self.transactions[tx_hash] = tx_result;

      console.log("");

      if (tx_result.createdAddress != null) {
        console.log("  Contract created: " + tx_result.createdAddress);
        self.contracts[tx_result.createdAddress] = rawTx.data;
      }

      console.log("  Gas usage: " + utils.bufferToInt(self.toHex(tx_result.gasUsed)));
      console.log("");

      self.mine();

      callback(null, tx_hash);
    });
  });
};

Account looses its code

Hey,

I have another problem with runCode(). Account created with runCode() looses his code after calling from another contract. Here's the example https://github.com/asinyagin/ethereumjs-test/tree/runCode. it prints:

cd2a3d9f938e13cd947ec05abc7fe734df8dd826: 
0000000000000000000000000000000000000000: 
084f6a99003dae6d3906664fdbf43dd09930d0e3: 
77045e71a7a2c50903d88e564cd72fab11e82051: 60606040526008565b00

But account 084f...d0e3 should have code. If you comment out line https://github.com/asinyagin/ethereumjs-test/blob/runCode/app.js#L43 , the account will have its code.

Throwing after contract suicide does not revert suicide

In its simplest form, create a contract with a function that suicides and then throws. Call the function. Note that the contract is no longer accessible.

Parity seems to behave the way the yellow paper describes, but the following code does not:

contract Client{
    Server public s  = new Server();
    function doit(){
        s.homicide();
        throw;
    }
}
contract Server{ 
    bool public alive = true;
    function homicide(){
        Suicide();
        suicide(msg.sender);
        
    }
    event Suicide();
}

See also https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.6+commit.2dabbdf0.js&optimize=undefined&gist=9a48bde651631bff7591817811610070

Cache.flush: Cannot read property 'modified' of undefined

Cache.flush (invoked by runCode) throws:

/home/test/evm/node_modules/ethereumjs-vm/lib/cache.js:89
    if (it.value.modified) {
          ^

TypeError: Cannot read property 'modified' of undefined
    at /home/test/evm/node_modules/ethereumjs-vm/lib/cache.js:89:33
    at Object.async.whilst (/home/test/evm/node_modules/ethereumjs-vm/node_modules/async/lib/async.js:792:13)
    at Cache.flush (/home/test/evm/node_modules/ethereumjs-vm/lib/cache.js:86:9)
    at parseVmResults (/home/test/evm/node_modules/ethereumjs-vm/lib/runCode.js:234:31)
    at /home/test/evm/node_modules/ethereumjs-vm/node_modules/async/lib/async.js:789:30
    at /home/test/evm/node_modules/ethereumjs-vm/node_modules/async/lib/async.js:167:37
    at processImmediate [as _immediateCallback] (timers.js:383:17)

Of course, just adding "it.value &&" as precondition in the if prevents the error, but I'm not sure if it breaks something else...

Bug in MSTORE8?

  MSTORE8: function (offset, byte, runState) {
    offset = utils.bufferToInt(offset)
    // grab the last byte
    byte = byte.slice(byte.length - 1)
    memStore(runState, offset, byte, 0, 1)
  }

From https://github.com/ethereumjs/ethereumjs-vm/blob/master/lib/opFns.js#L776:

function memStore (runState, offset, val, valOffset, length, skipSubMem) {
...
  for (var i = 0; i < length; i++) {
    runState.memory[offset + i] = val[valOffset + i]
  }

As length=0, no memory would be stored?

Update: sorry, confused the number of arguments

Created account has no code

Hey,

I want to create a new contract without running a transaction, i have the following code for it:

function runCode(cb) {
  var account = new Account();

  vm.runCode({
    code: account2.code,
    data: account2.code,
    account: account,
    gasLimit: 3141592,
    address: account2.address,
    caller: account1.address
  }, function(err, result) {
    if (err) return cb(err);
    account.setCode(vm.trie, result.return, function(err) {
      if (err) cb(err);
      else vm.trie.put(account2.address, account.serialize(), cb);
    });
  });
}

The account has code right after saving, but after next transaction it looses its code. Looks like that happens only if the account has a constructor with storage changing. Here's the full example https://github.com/asinyagin/ethereumjs-test/blob/runCode/app.js . If you comment out the line https://github.com/asinyagin/ethereumjs-test/blob/runCode/app.js#L43 , you'll see that account had code before runTx().

Am I doing something wrong?

Falsely says sender account has 0?

Hi. Not entirely sure where to post this, but I assume it's a vm error.

I updated testrpc to contain the latest version of ethereumjs-vm (2.0.1) in order to get around these issues I started encountering wrt invalid jumps (trufflesuite/ganache-cli-archive#196, #88).

However, now I get this error. I verified that all accounts have funds in them. So not sure where the issue is coming from. Either testrpc isn't passing the right address through OR the vm is screwing up here?

Error: Error: sender doesn't have enough funds to send tx. The upfront cost is: 471238800000000000 and the senders account only has: 0
    at runCall (/Users/simondlr/.nvm/versions/node/v6.9.1/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/lib/runTx.js:97:10)

Any help?

missing merkle-patricia-tree dep?

╭─kumavis@xyzs-MacBook-Pro  ~/dev/blockapps-vm   
╰─$ browserify index.js -o bundle.js
Error: Cannot find module 'merkle-patricia-tree' from '/Users/kumavis/dev/node_modules/ethereumjs-vm/lib'
    at /Users/kumavis/.nvm/versions/node/v0.12.7/lib/node_modules/browserify/node_modules/resolve/lib/async.js:46:17
    at process (/Users/kumavis/.nvm/versions/node/v0.12.7/lib/node_modules/browserify/node_modules/resolve/lib/async.js:173:43)
    at ondir (/Users/kumavis/.nvm/versions/node/v0.12.7/lib/node_modules/browserify/node_modules/resolve/lib/async.js:188:17)
    at load (/Users/kumavis/.nvm/versions/node/v0.12.7/lib/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
    at onex (/Users/kumavis/.nvm/versions/node/v0.12.7/lib/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
    at /Users/kumavis/.nvm/versions/node/v0.12.7/lib/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:95:15)

Example returns an Integer exception

I ran this code:

    var VM = require('ethereumjs-vm');

    //create a new VM instance
    var vm = new VM();
    var code = '7f4e616d65526567000000000000000000000000000000000000000000000000003055307f4e616d6552656700000000000000000000000000000000000000000000000000557f436f6e666967000000000000000000000000000000000000000000000000000073661005d2720d855f1d9976f88bb10c1a3398c77f5573661005d2720d855f1d9976f88bb10c1a3398c77f7f436f6e6669670000000000000000000000000000000000000000000000000000553360455560df806100c56000396000f3007f726567697374657200000000000000000000000000000000000000000000000060003514156053576020355415603257005b335415603e5760003354555b6020353360006000a233602035556020353355005b60007f756e72656769737465720000000000000000000000000000000000000000000060003514156082575033545b1560995733335460006000a2600033545560003355005b60007f6b696c6c00000000000000000000000000000000000000000000000000000000600035141560cb575060455433145b1560d25733ff5b6000355460005260206000f3';
    //code needs to be a buffer
    code = new Buffer(code, 'hex');

    vm.runCode({
      code: code,
      gasLimit: new Buffer('ffffffff', 'hex') 
    }, function(err, results) {
      console.log(typeof results.exception, results.exception, 'returned: ' + results.return.toString('hex'));
    });

and got this result:

number 1 returned: 7f726567697374657200000000000000000000000000000000000000000000000060003514156053576020355415603257005b335415603e5760003354555b6020353360006000a233602035556020353355005b60007f756e72656769737465720000000000000000000000000000000000000000000060003514156082575033545b1560995733335460006000a2600033545560003355005b60007f6b696c6c00000000000000000000000000000000000000000000000000000000600035141560cb575060455433145b1560d25733ff5b6000355460005260206000f3

why is results.exception === 1? shouldn't it be a boolean type? can someone please explain this example to me and how it works? I'm new to eth and want to use this VM as a simple state machine.

runCall invoked twice for DELEGATECALL

"When calling a contract function that calls into a library, the Ether sent in the transaction is spent multiple times."

This issue was originally started on testrpc: trufflesuite/ganache-cli-archive#122 as reported by @graup.

I have narrowed down the issue to runCall being invoked twice. It runs once as part of runBlock > runTx > runCall and once as part of DELEGATECALL > makeCall > runCall.

I assume that the problem is in DELEGATECALL since that is doing the library function invocation (the reproducible element). Not knowing more about ethereumjs-vm internals, I am unsure whether DELEGATECALL needs to simply remove the makeCall invocation or if a subset of makeCall/runCall functionality must be removed. Would like to get input from @tcoulter or someone with more understanding of the codebase before proceeding. Cheers!

`Error: trying to commit when not checkpointed` on runBlock

Hey,

I've updated ethereumjs libs and now I'm getting the error:

/home/user/ethereum-sandbox/node_modules/merkle-patricia-tree/checkpoint-interface.js:57
      throw new Error('trying to commit when not checkpointed')
            ^
Error: trying to commit when not checkpointed
    at /home/user/ethereum-sandbox/node_modules/merkle-patricia-tree/checkpoint-interface.js:57:13
    at Object.item.task (/home/user/ethereum-sandbox/node_modules/merkle-patricia-tree/node_modules/semaphore/lib/semaphore.js:24:29)
    at Object.semaphore.take (/home/user/ethereum-sandbox/node_modules/merkle-patricia-tree/node_modules/semaphore/lib/semaphore.js:31:9)
    at Trie.commit (/home/user/ethereum-sandbox/node_modules/merkle-patricia-tree/checkpoint-interface.js:48:12)
    at /home/user/ethereum-sandbox/node_modules/ethereumjs-vm/lib/runTx.js:149:16
    at /home/user/ethereum-sandbox/node_modules/async/lib/async.js:187:20
    at /home/user/ethereum-sandbox/node_modules/async/lib/async.js:239:13
    at _arrayEach (/home/user/ethereum-sandbox/node_modules/async/lib/async.js:91:13)
    at _each (/home/user/ethereum-sandbox/node_modules/async/lib/async.js:82:13)
    at Object.async.forEachOf.async.eachOf (/home/user/ethereum-sandbox/node_modules/async/lib/async.js:238:9)

With that code:

      async.series([
        this.vm.runBlock.bind(this.vm, {
          blockchain: this.blockchain,
          block: block,
          generate: true
        }),
        this.blockchain.putBlock.bind(this.blockchain, block)
      ], (function(err, results) {

I can't figure out why. Can you help me with this?

Speed optim: store bn.js instances as stack elements

Currently the stack elements are Buffer instances and all the logic/arithmetic functions convert them back and forth between Buffer & bn.js.

It should be much faster keeping them as a bn.js instance once pushed by PUSH* and only converting to Buffer when needed.

steams, hooks or events?

What is the best way to get interesting info out of the VM? First of all what do we want to get? Off the top of my head

  • Per step info for the VM
  • The results for each TX. was the tx successful? did it create a new contract? ect...
  • The results for each Block. was the block successful? what are the Receipts? what are the results from the tx's in the block

The options I can think of are events, hooks and steams.

events

events would be something like on("Step" | "tx" | "block" )

pros

  • are nice because multiple parties can subscribe to them.

cons

  • you can't pause the vm.
  • its hard to make events work across the network

hooks

Hooks are vm.onTx = function(data, done){}, vm.onBlock and vm.onStep

Pros

  • very minimalist
  • can pause the VM

Cons

  • only can be defined once!

streams

Streams look like vm.createTraceStream(), vm.createTxStream, vm.createBlockStream

NOTE currently createTraceStream is built on top of the runStep hook. If i continued to build out stream I would probably implement them on hooks.

Pros

  • should work nicely with networks.
  • standard format

Cons

  • can't pause the VM.

Currently

we have
onTx, AfterTx , onStep, and createTraceStream.

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.