ethereumjs / ethereumjs-monorepo Goto Github PK
View Code? Open in Web Editor NEWMonorepo for the Ethereum VM TypeScript Implementation
Monorepo for the Ethereum VM TypeScript Implementation
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.
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.
According to the YP during contract creation the balance should be taken from the previous state (if it existed) plus the endowment.
Currently ethereumjs-vm won't keep the balance.
go-ethereum implements it properly: https://github.com/ethereum/go-ethereum/blob/c541b38fb36587d23c60f5e2f2b9b3c8700ec489/core/state/statedb.go#L283
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.
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.
Investigate how https://github.com/gpujs/gpu.js could speed up ethereumjs-vm. Good find @wanderer
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.
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.
Hide this complexity in the StateManager contractStorage api. This would be a breaking change.
stateManager.getContractStorage(address, key, cb)
stateManager.putContractStorage(address, key, value, cb)
stateManager.getContractStorage(address, key, function (err, value) {
var loaded = rlp.decode(value)
cb(err, loaded)
})
stateManager.getContractStorage(address, key, cb)
Hey,
I've found another problem: ethereumjs doesn't create a contract. I think the problem is in contract's code, because the same source code with different contract's code works well.
Here's an example: https://github.com/asinyagin/ethereumjs-test/blob/master/app.js
It shows 2 account at the end, but there should be 3 accounts.
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.
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
Having some issues that I think are related to the saynchronous nature of the vm, so I was wondering what the reasoning was. It might shed some light on my issue. Thanks!
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.
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);
});
});
};
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?
See ethereum/EIPs#150.
Instead of stopping execution, it just returns a gasUsed > gasLimit
.
I see this in browser-solidity, which calls runTx
.
@kumavis did you had such an issue?
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
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?
Hey,
I can't figure out how to get a receipt of transaction in the block that is executed by runBlock()
. block.transactionReceipt
from docs is undefined and block.header.receiptTrie
is an empty trie. Here's the full code of my test https://github.com/asinyagin/ethereumjs-test/blob/receipt-test/app.js.
I use this fix to turn off block validation ethereumjs/ethereumjs-blockchain#2
ie using genesis state etc? looks like it just loads allocations (address => balance) etc
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();
}
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
The options I can think of are events, hooks and steams.
events would be something like on("Step" | "tx" | "block" )
pros
cons
Hooks are vm.onTx = function(data, done){}
, vm.onBlock
and vm.onStep
Pros
Cons
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
Cons
we have
onTx
, AfterTx
, onStep
, and createTraceStream
.
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?
It looks like the account nonce is not rolled back correctly when there is an e.g. out of gas exception.
See trufflesuite/ganache-cli-archive#33 for a repro
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...
@wanderer @kumavis @tcoulter can you please have a look at the branches and delete the unneeded ones: https://github.com/ethereumjs/ethereumjs-vm/branches ?
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
"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!
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.
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
tx.from has been removed
its still used all over the vm
e.g. https://github.com/ethereumjs/ethereumjs-vm/blob/master/lib/runTx.js
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
Hi,
As I see, runBlock()
gives wrong gasUsed
while runTx()
uses correct number of gas. Here's how to reproduce it: https://github.com/asinyagin/ethereumjs-test/blob/master/app.js . The app prints:
root@982421ef3b07:~/ethereumjs-test# node app.js
tx: 5a24e
block: 05254e
Right now homestead (e.g. support for DELEGATECALL
) is turned on based the block number. Would it make sense having that as an option in runCode/runTx?
Would make supporting delegatecall in browser-solidity
easy: chriseth/browser-solidity#119
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.
no error is thrown -- these errors can be simple typos, makes it hard to debug
vm.on('afterBlock', function(block){
// typo or other accidentally error
throw new Error()
})
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'
When setup
is called I'm getting an error thrown at:
assert(pubKey.length === 64)
called by:
var address = utils.pubToAddress(new Buffer(publicKey, 'hex'))
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.
It would be nice to expose the StateManager publically. And split it into its own module. What should the API be?
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
npm published version is out of date :)
only uses self.stateManager.blockchain
, ignores optional arg
https://github.com/ethereumjs/ethereumjs-vm/blob/master/lib/runBlockchain.js#L13-L17
╭─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)
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?
/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
this could prolly just be a vm util
https://github.com/ethereumjs/bin-to-ops
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.