Skip to content

feat(cast): run arbitrary bytecode#1020

Closed
refcell wants to merge 5 commits intofoundry-rs:revmfrom
refcell:ab/cast_run
Closed

feat(cast): run arbitrary bytecode#1020
refcell wants to merge 5 commits intofoundry-rs:revmfrom
refcell:ab/cast_run

Conversation

@refcell
Copy link
Contributor

@refcell refcell commented Mar 22, 2022

Overview

This PR finishes the work in #945

Motivation & Solution

This PR introduces a new subcommand for cast: run that executes arbitrary bytecode similar to hevm exec.

Checklist

  • Parse Bytecode
  • Parse Calldata
  • Setup executor with bytecode
  • Prettify raw call result
  • Unit Tests
  • CLI Docs

@refcell refcell changed the title ⚙️ cast run subcommand feat(cast): run arbitrary bytecode Mar 22, 2022
@refcell refcell marked this pull request as draft March 22, 2022 19:40
@refcell refcell mentioned this pull request Mar 22, 2022
3 tasks
@refcell refcell marked this pull request as ready for review March 22, 2022 21:32
Comment on lines +56 to +57
let bytecode_vec = self.bytecode.strip_prefix("0x").unwrap_or(&self.bytecode);
let parsed_bytecode = Bytes::from(hex::decode(bytecode_vec)?);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should work as well

Suggested change
let bytecode_vec = self.bytecode.strip_prefix("0x").unwrap_or(&self.bytecode);
let parsed_bytecode = Bytes::from(hex::decode(bytecode_vec)?);
let bytecode_vec:Bytes = self.bytecode.parse()?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks :)

Comment on lines +49 to +60
macro_rules! casttest {
($test:ident, $fun:expr) => {
$crate::casttest!($test, $crate::ethers_solc::PathStyle::Dapptools, $fun);
};
($test:ident, $style:expr, $fun:expr) => {
#[test]
fn $test() {
let (prj, cmd) = $crate::util::setup_cast(stringify!($test), $style);
$fun(prj, cmd);
}
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@refcell
Copy link
Contributor Author

refcell commented Mar 22, 2022

Right now, cast run deploys bytecode through the program setup and executes a raw call with the provided calldata - essentially it's forge run but against bytecode (rather than solidity contracts).

Open Questions

cc: @gakonst @onbjerg @mattsse
Should cast run emulate hevm exec, that takes the bytecode as the program bytecode and executes against that (as shown below)?

Screenshot from 2022-03-22 16-49-42


Currently, there is a stark difference between the outputs of `cast run` and `hevm exec` as shown below: ![Screenshot from 2022-03-22 16-51-30](https://user-images.githubusercontent.com/21288394/159595428-52d2abbc-a4a7-4b12-ac5d-f1ba170f9e2b.png)

@gakonst gakonst deleted the branch foundry-rs:revm March 23, 2022 19:51
@gakonst gakonst closed this Mar 23, 2022
@onbjerg
Copy link
Member

onbjerg commented Mar 23, 2022

I think this was auto-closed - rebase on top of master (which now includes revm changes) and re-open 😄

@gakonst
Copy link
Member

gakonst commented Mar 23, 2022

oops my bad - sorry @abigger87

@refcell
Copy link
Contributor Author

refcell commented Mar 23, 2022

haha no worries!

@tynes
Copy link
Contributor

tynes commented Apr 12, 2022

Any plans to reopen this one?

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

Successfully merging this pull request may close these issues.

5 participants