Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/fifty-eggs-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/edr": minor
---

Added `Response::traces` method with a raw trace format compatible with EthereumJS' VM. A failed create reports no `contractAddress`, unlike EthereumJS.
6 changes: 1 addition & 5 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ c-kzg = { version = "2.1.8", default-features = false, features = [
"ethereum_kzg_settings",
] }

revm-inspectors = { version = "0.42.2", features = ["serde"] }
# Temporary fork: revm-inspectors 0.42.2 with paradigmxyz/revm-inspectors#468
# applied, which adds `StackSnapshotType::Top`. That change ships in
# revm-inspectors 0.44, which needs revm 43. Drop the fork once EDR is on
# revm >= 43.
revm-inspectors = { git = "https://github.com/Wodann/revm-inspectors", branch = "feat/top-of-stack-snapshot-0.42", features = ["serde"] }
# No foundry-fork-db release supports revm 42 (0.27.0 on crates.io pins revm
# ^41; the next fork-db bump goes straight to revm 43), so a foundry-core git
# revision is used: the one Foundry v1.8.0 and v1.8.1 (the stable releases on
Expand Down
1 change: 0 additions & 1 deletion crates/edr_napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ edr_solidity_tests.workspace = true
edr_state_api.workspace = true
edr_signer.workspace = true
edr_solidity.workspace = true
edr_tracing.workspace = true
edr_utils_sync.workspace = true
k256.workspace = true
mimalloc-safe = { workspace = true, features = ["local_dynamic_tls"] }
Expand Down
149 changes: 64 additions & 85 deletions crates/edr_napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ export declare class Provider {

export declare class ProviderFactory {}

export declare class RawTrace {
get trace(): Array<TracingMessage | TracingStep | TracingMessageResult>
}

export declare class Response {
/** Returns the response data as a JSON string or a JSON object. */
get data(): string | any
Expand All @@ -108,6 +104,12 @@ export declare class Response {
* request's call itself.
*/
callTraces(): Array<CallTrace>
/**
* Returns the raw traces of executed contracts. This may contain zero or
* more traces. Uses a function instead of a getter to avoid repeated
* expensive conversions.
*/
traces(): Array<Array<TracingMessage | TracingStep | TracingMessageResult>>
}

export declare class ReturnData {
Expand Down Expand Up @@ -314,11 +316,6 @@ export declare enum CallKind {
Create = 4,
}

export interface CallOutput {
/** Return value */
returnValue: Uint8Array
}

/** The result of executing a call override. */
export interface CallOverrideResult {
result: Uint8Array
Expand Down Expand Up @@ -493,13 +490,6 @@ export interface CounterExampleSequence {
/** The instrumentation coverage library file name. */
export declare const COVERAGE_LIBRARY_FILE_NAME: string

export interface CreateOutput {
/** Return value */
returnValue: Uint8Array
/** Optionally, a 160-bit address */
address?: Uint8Array
}

export interface CustomErrorStackTraceEntry {
type: StackTraceEntryType.CUSTOM_ERROR
message: string
Expand Down Expand Up @@ -591,14 +581,6 @@ export interface ExecutionLog {
data: Uint8Array
}

/** The result of executing a transaction. */
export interface ExecutionResult {
/** The transaction result */
result: SuccessResult | RevertResult | HaltResult
/** Optional contract address if the transaction created a new contract. */
contractAddress?: Uint8Array
}

/** Represents the exit code of the EVM. */
export declare enum ExitCode {
/** Execution was successful. */
Expand Down Expand Up @@ -814,19 +796,6 @@ export declare const GENERIC_CHAIN_TYPE: string

export declare function genericChainProviderFactory(): ProviderFactory

/** The result when the EVM terminates due to an exceptional halt. */
export interface HaltResult {
/** The exceptional halt that occurred */
reason: ExceptionalHalt
/**
* Halting will spend all the gas and will thus be equal to the specified
* gas limit
*/
gasUsed: bigint
/** The logs */
logs: Array<ExecutionLog>
}

/** Configuration for a hardfork activation */
export interface HardforkActivation {
/** The condition for the hardfork activation */
Expand Down Expand Up @@ -1341,6 +1310,15 @@ export interface ObservabilityConfig {
* Defaults to `IncludeTraces.None`.
*/
includeCallTraces?: IncludeTraces
/**
* How much of the stack each step of `Response.traces()` records.
*
* This will be overridden if `Provider.setVerboseTracing(true)` is called,
* which records the full stack until it is disabled again.
*
* Defaults to `StackSnapshotType.None`.
*/
recordStack?: StackSnapshotType
}

export declare const OP_CHAIN_TYPE: string
Expand Down Expand Up @@ -1527,16 +1505,6 @@ export interface RevertErrorStackTraceEntry {
isInvalidOpcodeError: boolean
}

/** The result when the EVM terminates due to a revert. */
export interface RevertResult {
/** The amount of gas used */
gasUsed: bigint
/** The logs */
logs: Array<ExecutionLog>
/** The transaction output */
output: Uint8Array
}

/**
* Derives the secp256k1 public key of the provided secret key, returning it
* in uncompressed SEC1 form: 65 bytes, `0x04 || X || Y`.
Expand Down Expand Up @@ -1832,6 +1800,16 @@ export interface SourceReference {
range: Array<number>
}

/** How much of the stack each step of a raw trace records. */
export declare enum StackSnapshotType {
/** No stack entries. */
None = 0,
/** The full stack. */
Full = 1,
/** Only the top entry of the stack. */
Top = 2,
}

/** The stack trace result */
export interface StackTrace {
/** Enum tag for JS. */
Expand Down Expand Up @@ -1916,20 +1894,6 @@ export declare enum SuccessReason {
SelfDestruct = 2,
}

/** The result when the EVM terminates successfully. */
export interface SuccessResult {
/** The reason for termination */
reason: SuccessReason
/** The amount of gas used */
gasUsed: bigint
/** The amount of gas refunded */
gasRefunded: bigint
/** The logs */
logs: Array<ExecutionLog>
/** The transaction output */
output: CallOutput | CreateOutput
}

/**
* See [`edr_solidity_tests::result::SuiteResult`]
*
Expand Down Expand Up @@ -1982,49 +1946,64 @@ export interface TracingConfigWithBuffers {
ignoreContracts?: boolean
}

/** Matches Hardhat's `MinimalExecResult` interface. */
export interface TracingExecResult {
/** Whether execution succeeded */
readonly success: boolean
/** Gas used during execution */
readonly executionGasUsed: bigint
/** Address of the created contract. None if the create failed. */
readonly contractAddress?: Uint8Array
/** The reason for the exit (success or halt) */
readonly reason?: SuccessReason | ExceptionalHalt
/** The output data */
readonly output?: Uint8Array
}

/** Matches Hardhat's `MinimalMessage` interface. */
export interface TracingMessage {
/** Sender address */
readonly caller: Uint8Array
/** Recipient address. None if it is a Create message. */
readonly to?: Uint8Array
/** Whether it's a static call */
readonly isStaticCall: boolean
/** Transaction gas limit */
readonly gasLimit: bigint
/** Depth of the message */
readonly depth: number
/** Input data of the message */
readonly data: Uint8Array
/** Value sent in the message */
readonly value: bigint
/**
* Address of the code that is being executed. Can be different from `to`
* if a delegate call is being done.
*/
readonly codeAddress?: Uint8Array
/** Code of the contract that is being executed. */
readonly code?: Uint8Array
/** Value sent in the message */
readonly value: bigint
/** Input data of the message */
readonly data: Uint8Array
/** Transaction gas limit */
readonly gasLimit: bigint
/** Whether it's a static call */
readonly isStaticCall: boolean
}

/** Matches Hardhat's `MinimalEVMResult` interface. */
export interface TracingMessageResult {
/** Execution result */
readonly executionResult: ExecutionResult
/** The execution result */
readonly execResult: TracingExecResult
}

/** Opcode information for a tracing step. */
export interface TracingOpcode {
/** The name of the opcode */
readonly name: string
}

/** Matches Hardhat's `MinimalInterpreterStep` interface. */
export interface TracingStep {
/** The program counter */
readonly pc: number
/** Call depth */
readonly depth: number
/** The program counter */
readonly pc: bigint
/** The executed op code */
readonly opcode: string
/**
* The entries on the stack. It only contains the top element unless
* verbose tracing is enabled. The vector is empty if there are no elements
* on the stack.
*/
/** The executed opcode */
readonly opcode: TracingOpcode
/** The stack entries, as many as `ObservabilityConfig.recordStack` records. */
readonly stack: Array<bigint>
/** The memory at the step. None if verbose tracing is disabled. */
/** The memory at the step. None unless verbose tracing is enabled. */
readonly memory?: Uint8Array
}

Expand Down
2 changes: 1 addition & 1 deletion crates/edr_napi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ module.exports.Exit = nativeBinding.Exit
module.exports.Precompile = nativeBinding.Precompile
module.exports.Provider = nativeBinding.Provider
module.exports.ProviderFactory = nativeBinding.ProviderFactory
module.exports.RawTrace = nativeBinding.RawTrace
module.exports.Response = nativeBinding.Response
module.exports.ReturnData = nativeBinding.ReturnData
module.exports.SolidityTestRunnerFactory = nativeBinding.SolidityTestRunnerFactory
Expand Down Expand Up @@ -834,6 +833,7 @@ module.exports.precompileP256Verify = nativeBinding.precompileP256Verify
module.exports.printStackTrace = nativeBinding.printStackTrace
module.exports.RECEIVE_FUNCTION_NAME = nativeBinding.RECEIVE_FUNCTION_NAME
module.exports.secp256k1PublicKeyFromSecretKey = nativeBinding.secp256k1PublicKeyFromSecretKey
module.exports.StackSnapshotType = nativeBinding.StackSnapshotType
module.exports.StackTraceEntryType = nativeBinding.StackTraceEntryType
module.exports.stackTraceEntryTypeToString = nativeBinding.stackTraceEntryTypeToString
module.exports.SuccessReason = nativeBinding.SuccessReason
Expand Down
31 changes: 31 additions & 0 deletions crates/edr_napi/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,27 @@ impl TryFrom<LocalConfig> for edr_provider::config::Local {
}
}

/// How much of the stack each step of a raw trace records.
#[napi]
pub enum StackSnapshotType {
/// No stack entries.
None,
/// The full stack.
Full,
/// Only the top entry of the stack.
Top,
}

impl From<StackSnapshotType> for edr_provider::observability::StackSnapshotType {
fn from(value: StackSnapshotType) -> Self {
match value {
StackSnapshotType::None => Self::None,
StackSnapshotType::Full => Self::Full,
StackSnapshotType::Top => Self::Top,
}
}
}

/// Configuration for runtime observability.
#[napi(object)]
pub struct ObservabilityConfig<'env> {
Expand All @@ -266,6 +287,13 @@ pub struct ObservabilityConfig<'env> {
///
/// Defaults to `IncludeTraces.None`.
pub include_call_traces: Option<IncludeTraces>,
/// How much of the stack each step of `Response.traces()` records.
///
/// This will be overridden if `Provider.setVerboseTracing(true)` is called,
/// which records the full stack until it is disabled again.
///
/// Defaults to `StackSnapshotType.None`.
pub record_stack: Option<StackSnapshotType>,
}

/// Configuration for a provider.
Expand Down Expand Up @@ -670,6 +698,9 @@ impl ObservabilityConfig<'_> {
),
on_collected_coverage_fn,
on_collected_gas_report_fn,
record_stack: self
.record_stack
.map_or(default_config.record_stack, Into::into),
verbose_raw_tracing: default_config.verbose_raw_tracing,
})
}
Expand Down
Loading
Loading