Git Product home page Git Product logo

pure-evm's People

Contributors

armaniferrante avatar dependabot[bot] avatar snario avatar

Stargazers

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

Watchers

 avatar

pure-evm's Issues

Returndatasize is given with return value

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.

Add ability to execute "builtin" ethereum functions

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.

Deployed bytecode error

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];

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.