armaniferrante / pure-evm Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU General Public License v3.0
License: GNU General Public License v3.0
When returning memory types, the returndatasize payload is prepended to the return value. In such cases, one must chop it off before returning from pure_evm.exec()
.
I'll get to this soon, but the workaround for now is to just chop it off the first 64 bytes of the return data for such types. For example, see https://github.com/armaniferrante/pure-evm/blob/master/wasm/examples/node/ttt.js#L14.
This shouldn't affect fixed-sized (not in memory) primitive types like u256, for example, https://github.com/armaniferrante/pure-evm/blob/master/wasm/examples/node/index.js#L16.
All javascript tests are just ad hoc js scripts with assertions. Use something proper like mocha/jest.
Currently only running node examples.
Builtin functions like sha256
and recover
execute as cross contract calls to fixed account addresses on Ethereum.
Currently, pure-evm doesn't allow any cross contract calls whatsoever.
It might be desireable to special case "builtin" functions as requested by #6.
Trying to use this package to run view
functions, and running into some strange issues.
When I try to call execute
with the bytecode retrieved from eth_getCode
(the runtime/deployed bytecode), I get a rust panic error:
RuntimeError: unreachable
at __rust_start_panic (wasm-function[330]:0x3a810)
at rust_panic (wasm-function[213]:0x39f81)
313 |
314 | // Execute on the raw bytes.
> 315 | const output = pure_evm.exec(
| ^
316 | Uint8Array.from(Buffer.from(bytecode.replace("0x", ""), "hex")),
317 | encodedData,
318 | );
at std::panicking::rust_panic_with_hook::h5e7c2dc110ae79d4 (wasm-function[95]:0x36e5a)
at std::panicking::begin_panic::h6da1813f9eea9b6a (wasm-function[200]:0x39c59)
at <pure_evm::pure_ext::PureExt as vm::ext::Ext>::depth::he3b3a85b57bdb8e8 (wasm-function[273]:0x3a540)
at evm::interpreter::Interpreter<Cost>::exec_instruction::h8137cbc088506585 (wasm-function[1]:0xc988)
at <evm::interpreter::Interpreter<Cost> as vm::Exec>::exec::h41e00997af783aac (wasm-function[5]:0x1df67)
at pure_evm::exec::h1eb45dc630e9c525 (wasm-function[10]:0x24982)
at exec (wasm-function[92]:0x36a29)
at Object.module.exports.exec (../../node_modules/pure-evm/pure-evm_main.js:38:22)
at AppInstance.computeStateTransition (src/models/app-instance.ts:315:31)
at runMicrotasks (<anonymous>)
Interestingly enough, when using the init/creation bytecode, the error disappears and the output of the execute
function once converted to a hex string is the same as the deployed bytecode returned from eth_getCode
. Any idea on what might be causing these errors?
Here is a code snippet (running in node env, not browser):
const appArtifact = require(`@connext/contracts/artifacts/${pureAppName}.json`);
const iface = new Interface(appArtifact.abi);
// applyAction is a view function, using solidity 0.6
const data = iface.encodeFunctionData("applyAction", [
this.encodedLatestState,
this.encodeAction(action),
]);
const encodedData = Uint8Array.from(Buffer.from(data.replace("0x", ""), "hex"));
const bytecode = await provider.send("eth_getCode", [this.appDefinition, "latest"]);
// Works IFF using init bytecode, but returns deployed bytecode hex string. Fails otherwise.
const output = pure_evm.exec(
Uint8Array.from(Buffer.from(bytecode.replace("0x", ""), "hex")),
encodedData,
);
// Taken from the ttt test
const bytes = defaultAbiCoder.decode(["bytes"], output)[0];
const computedNextState = defaultAbiCoder.decode([this.abiEncodings.stateEncoding], bytes)[0];
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.