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 option to use native tracer in replay #84

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions replay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ clap.workspace = true
ethers.workspace = true
eyre.workspace = true
function_name.workspace = true
hex.workspace = true
lazy_static.workspace = true
libc.workspace = true
libloading.workspace = true
Expand All @@ -25,3 +26,6 @@ rustc-host.workspace = true
serde = { version = "1.0.203", features = ["derive"] }
sneks.workspace = true
tokio.workspace = true

[dev-dependencies]
serde_json.workspace = true
24 changes: 10 additions & 14 deletions replay/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,8 @@ enum Subcommands {

#[derive(Args, Clone, Debug)]
struct ReplayArgs {
/// RPC endpoint.
#[arg(short, long, default_value = "http://localhost:8547")]
endpoint: String,
/// Tx to replay.
#[arg(short, long)]
tx: TxHash,
/// Project path.
#[arg(short, long, default_value = ".")]
project: PathBuf,
#[command(flatten)]
trace: TraceArgs,
/// Whether to use stable Rust. Note that nightly is needed to expand macros.
#[arg(short, long)]
stable_rust: bool,
Expand All @@ -76,6 +69,9 @@ struct TraceArgs {
/// Project path.
#[arg(short, long, default_value = ".")]
project: PathBuf,
/// If set, use the native tracer instead of the JavaScript one. Notice the native tracer might not be available in the node.
#[arg(short, long, default_value_t = false)]
use_native_tracer: bool,
}

fn main() -> Result<()> {
Expand Down Expand Up @@ -106,7 +102,7 @@ async fn main_impl(args: Opts) -> Result<()> {

async fn trace(args: TraceArgs) -> Result<()> {
let provider = sys::new_provider(&args.endpoint)?;
let trace = Trace::new(provider, args.tx).await?;
let trace = Trace::new(provider, args.tx, args.use_native_tracer).await?;
println!("{}", trace.json);
Ok(())
}
Expand Down Expand Up @@ -144,11 +140,11 @@ async fn replay(args: ReplayArgs) -> Result<()> {
bail!("failed to exec gdb {:?}", err);
}

let provider = sys::new_provider(&args.endpoint)?;
let trace = Trace::new(provider, args.tx).await?;
let provider = sys::new_provider(&args.trace.endpoint)?;
let trace = Trace::new(provider, args.trace.tx, args.trace.use_native_tracer).await?;

build_so(&args.project)?;
let so = find_so(&args.project)?;
build_so(&args.trace.project)?;
let so = find_so(&args.trace.project)?;

// TODO: don't assume the contract is top-level
let args_len = trace.tx.input.len();
Expand Down
30 changes: 27 additions & 3 deletions replay/src/query.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
{
"hostio": function(info) {
info.args = toHex(info.args);
info.outs = toHex(info.outs);
if (this.nests.includes(info.name)) {
info.info = this.open.pop();
Object.assign(info, this.open.pop());
info.name = info.name.substring(4) // remove evm_
}
this.open.push(info);
},
"enter": function(frame) {
let inner = [];
let name = "";
switch (frame.getType()) {
case "CALL":
name = "evm_call_contract";
break;
case "DELEGATECALL":
name = "evm_delegate_call_contract";
break;
case "STATICCALL":
name = "evm_static_call_contract";
break;
case "CREATE":
name = "evm_create1";
break;
case "CREATE2":
name = "evm_create2";
break;
case "SELFDESTRUCT":
name = "evm_self_destruct";
break;
}
this.open.push({
address: frame.getTo(),
address: toHex(frame.getTo()),
steps: inner,
name: name,
});

this.stack.push(this.open); // save where we were
this.open = inner;
},
Expand Down
Loading
Loading