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 https://github.com/armaniferrante/pure-evm/issues/6.
If we were to implement this ourselves and PR it, how would this work?
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();
}
}
@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.
Ah good tip, thanks!
@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.
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?
Right now the workflow is:
cargo buildin root and in/wasmmake buildin/wasmyarn install && yarn testin/examples/node
but I seem to be messing things up along the way
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
Yeah, as soon as I use the imports from ../pkg-node it starts to behave
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)
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
PR: #13