Skip to content

Commit

Permalink
fix: Correctly handle optional solc output in the tracing engine (#665)
Browse files Browse the repository at this point in the history
* fix: Gracefully handle a call trace with no jump dests

This specifically does what Hardhat did, which is throwing a new Error.

The error can be found in https://github.com/ProjectOpenSea/seaport,
if we execute:
```
npx hardhat test --no-compile --config ./hardhat.config.ts --grep 'Reverts when attempting to execute transfers on a conduit when not called from a channel'
```

* fix: Handle optional settings in solc Standard JSON output

* Add a changeset
  • Loading branch information
Xanewok authored Sep 16, 2024
1 parent 2e5ff9d commit bb3808b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-dogs-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/edr": patch
---

Handle optional solc settings better in the tracing engine
8 changes: 7 additions & 1 deletion crates/edr_napi/src/trace/error_inferrer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,14 @@ impl ErrorInferrer {
return Ok(entry);
}

// This function is only called after we jumped into the initial function in
// call traces, so there should always be at least a function jumpdest.
let trace = match trace {
Either::A(_call) => unreachable!("This shouldn't happen: a call trace has no functionJumpdest but has already jumped into a function"),
Either::A(_call) => return Err(
napi::Error::new(
napi::Status::GenericFailure,
"This shouldn't happen: a call trace has no functionJumpdest but has already jumped into a function"
)),
Either::B(create) => create,
};

Expand Down
12 changes: 7 additions & 5 deletions crates/edr_solidity/src/artifacts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Represents artifacts of the Solidity compiler input and output in the
//! Standard JSON format.
//!
//! See <https://docs.soliditylang.org/en/latest/using-the-compiler.html#compiler-input-and-output-json-description>.
#![allow(missing_docs)]

use std::collections::HashMap;
Expand Down Expand Up @@ -37,7 +39,7 @@ pub struct Source {
pub struct CompilerInput {
pub language: String,
pub sources: HashMap<String, Source>,
pub settings: CompilerSettings,
pub settings: Option<CompilerSettings>,
}

/// Additional settings like the optimizer, metadata, etc.
Expand All @@ -46,7 +48,7 @@ pub struct CompilerInput {
pub struct CompilerSettings {
#[serde(rename = "viaIR")]
via_ir: Option<bool>,
optimizer: OptimizerSettings,
optimizer: Option<OptimizerSettings>,
metadata: Option<MetadataSettings>,
output_selection: HashMap<String, HashMap<String, Vec<String>>>,
evm_version: Option<String>,
Expand All @@ -66,21 +68,21 @@ pub struct OptimizerSettings {
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OptimizerDetails {
yul_details: YulDetails,
yul_details: Option<YulDetails>,
}

/// Yul-specific optimizer details.
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct YulDetails {
optimizer_steps: String,
optimizer_steps: Option<String>,
}

/// Specifies the metadata settings.
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MetadataSettings {
use_literal_content: bool,
use_literal_content: Option<bool>,
}

/// The main output of the Solidity compiler.
Expand Down

0 comments on commit bb3808b

Please sign in to comment.