Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to execute "builtin" ethereum functions #7

Open
armaniferrante opened this issue Jun 11, 2020 · 12 comments
Open

Add ability to execute "builtin" ethereum functions #7

armaniferrante opened this issue Jun 11, 2020 · 12 comments

Comments

@armaniferrante
Copy link
Owner

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.

@ArjunBhuptani
Copy link

If we were to implement this ourselves and PR it, how would this work?

@ArjunBhuptani
Copy link

ArjunBhuptani commented Jun 11, 2020

So all we should need to do is to implement the following I think?

call(...) {
    fn call(
    &mut self,
    _gas: &U256,
    _sender_address: &Address,
    _receive_address: &Address,
    _value: Option<U256>,
    _data: &[u8],
    _code_address: &Address,
    _call_type: CallType,
    _trap: bool,
) -> ::std::result::Result<MessageCallResult, TrapKind> {
    if _receive_address == Address::hex!("0x1") {
        let d = // do ecrecover here
        Ok(MessageCallResult::Success(*gas, ReturnData::&*d))
    } else {
        unimplemented();
    }
}

@armaniferrante
Copy link
Owner Author

armaniferrante commented Jun 11, 2020

@ArjunBhuptani that seems like a good place to start. You also need to keep track of the callstack depth and implement the depth externality--though you can probably just return a fake constant since it's only used on calls and creates.

@ArjunBhuptani
Copy link

Ah good tip, thanks!

@armaniferrante
Copy link
Owner Author

@ArjunBhuptani I updated the repo to use the latest openethereum packages, since everything moved over from paritytech to a new org. You'll want to pull the latest changes.

@LayneHaber
Copy link

Alright, so working on creating a test that will emulate this properly within our fork. Having a bit of trouble getting the regular node tests passing, are there specific instructions for running those?

@LayneHaber
Copy link

Right now the workflow is:

  1. cargo build in root and in /wasm
  2. make build in /wasm
  3. yarn install && yarn test in /examples/node

but I seem to be messing things up along the way

@LayneHaber
Copy link

I seem to be getting this error when trying to merge the browser and node packages:
sed: pkg-node/pure-evm_bg.js: No such file or directory

@LayneHaber
Copy link

Yeah, as soon as I use the imports from ../pkg-node it starts to behave

@armaniferrante
Copy link
Owner Author

armaniferrante commented Jun 12, 2020

You should only need steps 2 and 3, as listed above.

Maybe you don't have wasm-pack installed (or something else)? pkg-node shouldn't be there if the build was successful.

(To install wasm-pack, you can use the docker container with all the required deps or install it directly with this line https://github.com/armaniferrante/pure-evm/blob/master/.circleci/docker/Dockerfile#L18)

@LayneHaber
Copy link

yeah there was a different error when I didn't have wasm installed. not sure what's off with my build step quite yet, but found a workaround so i'll probably come back to that later

@ArjunBhuptani
Copy link

PR: #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants