-
Notifications
You must be signed in to change notification settings - Fork 16
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
Change edr_napi::provider::Response::solidity_trace
to return a stack trace
#734
Conversation
🦋 Changeset detectedLatest commit: ee22667 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@agostbiro I pushed the changes to run the stack traces tests using the new
This will stop at the first failure. The test that is failing runs this bytecode:
with calldata |
* wip: make tracing config a provider argument * Patch Hardhat to pass tracing config to provider --------- Co-authored-by: Franco Victorio <[email protected]>
This function has to match the latest tested solc version in the stack traces tests.
Is there an issue to track follow-up work? |
Added in 52b4958 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM!
There are some small things that I pointed out; which might need to be fixed before merging.
@@ -330,6 +337,9 @@ impl<LoggerErrorT: Debug, TimerT: Clone + TimeSinceEpoch> ProviderData<LoggerErr | |||
self.subscriber_callback.clone(), | |||
self.call_override.clone(), | |||
config, | |||
// `hardhat_reset` doesn't discard contract metadata added with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're doing an overhaul of hardhat_reset
for HH3, should we reconsider the design of this too?
cc: @fvictorio
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good question. I think we might want to remove hardhat_reset
in HH3.
let retained_indices: HashSet<_> = stacktrace | ||
.iter() | ||
.enumerate() | ||
.filter(|(idx, frame)| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you use filter_map
instead of splitting it into two iterators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure tbh. I moved this code without changes from edr_napi
and I'd rather not change it now as @fvictorio has been doing manual testing.
) -> Vec<Instruction> { | ||
let source_maps = uncompress_sourcemaps(compressed_sourcemaps); | ||
if print_debug { | ||
println!("num source_maps: {:?}", source_maps.len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these prints intended to remain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch thanks! I fixed it by force pushing as we probably want to merge this while retaining the commit history as it's a big PR and it'd help with debugging later if needed.
@@ -198,6 +204,10 @@ pub fn decode_instructions( | |||
location, | |||
}; | |||
|
|||
if bytes_index == 22249 { | |||
println!("instruction {:?}", instruction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a remnant from debugging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -207,6 +217,11 @@ pub fn decode_instructions( | |||
add_unmapped_instructions(&mut instructions, bytecode); | |||
} | |||
|
|||
if print_debug { | |||
println!("instructions length: {:?}", instructions.len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this leftover from debugging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
serde = { version = "1.0.158", default-features = false, features = ["std"] } | ||
serde_json = { version = "1.0.89", features = ["preserve_order"] } | ||
strum = { version = "0.26.0", features = ["derive"] } | ||
thiserror = "1.0.58" | ||
semver = "1.0.23" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: alphabetical (cargo add
) ordering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ee22667
For the record, I didn't do an in-depth review of all code changes that were moved from |
f1f3d59
to
4adac6b
Compare
The goal of this PR is to port Solidity stack trace generation to pure Rust and without NAPI dependencies. Doing this also necessitated porting
hardhat_addCompilationResult
to EDR from Hardhat.Most of the additions
edr_solidity
come from movingedr_napi
code there and stripping the NAPI dependencies. As the stack trace error inference involves complex heuristics, this code was originally ported verbatim from JS which lead to non-idiomatic Rust code. I originally wanted to clean it up as part of moving inference code fromedr_napi
toedr_solidity
, but I only managed to do it partially due to running out of time, so much of it remains unidiomatic Rust code. I'd ask to exclude this aspect from review.I think these are the important changes in
edr_solidity
that need review:Bytecode
is renamed toContractMetadata
,VmTrace
is renamed toNestedTrace
(to differentiate from flat traces fromedr_evm
) andVmTraceDecoder
is renamed toContractDecoder
.NestedTracer
that has interior mutability, but it's converted to a nested trace type without interior mutability when returned fromNestedTracer
. This way the risk of panics from interior mutability is confined to thenested_tracer
module.Arc<RwLock>
in build model types instead ofRc<RefCell>
. This was necessary, because the EDR provider holds on to those types now to supporthardhat_addCompilationResult
, so they need to beSend
. We don't really need to write to the types held byArc<RwLock>
outside theedr_solidity
crate, but it took too long to remove that so I gave up on it as part of this PR.Besides
edr_solidity
, on the Rust side changes to the provider inedr_provider
andedr_napi
would be important to review I think.Hardhat companion PR: NomicFoundation/hardhat#6085