@nomicfoundation/edr 0.12.0-next.1 → 0.12.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +196 -64
- package/index.js +4 -1
- package/package.json +26 -21
- package/src/account.rs +6 -5
- package/src/block.rs +1 -1
- package/src/call_override.rs +1 -1
- package/src/cast.rs +1 -1
- package/src/chains/generic.rs +27 -20
- package/src/chains/l1.rs +84 -78
- package/src/chains/op.rs +50 -51
- package/src/config.rs +166 -9
- package/src/context.rs +96 -89
- package/src/contract_decoder.rs +57 -0
- package/src/debug_trace.rs +2 -0
- package/src/gas_report.rs +92 -0
- package/src/lib.rs +4 -1
- package/src/log.rs +2 -2
- package/src/logger.rs +4 -2
- package/src/mock/time.rs +134 -0
- package/src/mock.rs +4 -1
- package/src/precompile.rs +1 -1
- package/src/provider/response.rs +4 -4
- package/src/provider.rs +51 -4
- package/src/result.rs +35 -80
- package/src/serde.rs +1 -1
- package/src/solidity_tests/config.rs +80 -12
- package/src/solidity_tests/l1.rs +7 -7
- package/src/solidity_tests/op.rs +5 -5
- package/src/solidity_tests/runner.rs +1 -1
- package/src/solidity_tests/test_results.rs +70 -41
- package/src/solidity_tests.rs +1 -1
- package/src/trace/debug.rs +29 -26
- package/src/trace/exit.rs +9 -8
- package/src/trace/return_data.rs +19 -7
- package/src/trace/solidity_stack_trace.rs +56 -28
- package/src/trace.rs +6 -5
- package/src/ts/solidity_tests.ts +46 -0
- package/src/withdrawal.rs +5 -5
- package/Cargo.toml +0 -92
- package/build.rs +0 -3
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
use std::collections::HashMap;
|
|
2
|
+
|
|
3
|
+
use napi::bindgen_prelude::BigInt;
|
|
4
|
+
use napi_derive::napi;
|
|
5
|
+
|
|
6
|
+
#[napi(object)]
|
|
7
|
+
pub struct GasReport {
|
|
8
|
+
pub contracts: HashMap<String, ContractGasReport>,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
#[napi(object)]
|
|
12
|
+
pub struct ContractGasReport {
|
|
13
|
+
pub deployments: Vec<DeploymentGasReport>,
|
|
14
|
+
pub functions: HashMap<String, Vec<FunctionGasReport>>,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#[napi]
|
|
18
|
+
pub enum GasReportExecutionStatus {
|
|
19
|
+
Success,
|
|
20
|
+
Revert,
|
|
21
|
+
Halt,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#[napi(object)]
|
|
25
|
+
pub struct DeploymentGasReport {
|
|
26
|
+
pub gas: BigInt,
|
|
27
|
+
pub size: BigInt,
|
|
28
|
+
pub status: GasReportExecutionStatus,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
#[napi(object)]
|
|
32
|
+
pub struct FunctionGasReport {
|
|
33
|
+
pub gas: BigInt,
|
|
34
|
+
pub status: GasReportExecutionStatus,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
impl From<edr_gas_report::GasReport> for GasReport {
|
|
38
|
+
fn from(value: edr_gas_report::GasReport) -> Self {
|
|
39
|
+
Self {
|
|
40
|
+
contracts: value
|
|
41
|
+
.into_inner()
|
|
42
|
+
.into_iter()
|
|
43
|
+
.map(|(k, v)| (k, v.into()))
|
|
44
|
+
.collect(),
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
impl From<edr_gas_report::ContractGasReport> for ContractGasReport {
|
|
50
|
+
fn from(value: edr_gas_report::ContractGasReport) -> Self {
|
|
51
|
+
Self {
|
|
52
|
+
deployments: value.deployments.into_iter().map(Into::into).collect(),
|
|
53
|
+
functions: value
|
|
54
|
+
.functions
|
|
55
|
+
.into_iter()
|
|
56
|
+
.map(|(k, v)| {
|
|
57
|
+
let function_reports = v.into_iter().map(FunctionGasReport::from).collect();
|
|
58
|
+
(k, function_reports)
|
|
59
|
+
})
|
|
60
|
+
.collect(),
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
impl From<edr_gas_report::GasReportExecutionStatus> for GasReportExecutionStatus {
|
|
66
|
+
fn from(value: edr_gas_report::GasReportExecutionStatus) -> Self {
|
|
67
|
+
match value {
|
|
68
|
+
edr_gas_report::GasReportExecutionStatus::Success => Self::Success,
|
|
69
|
+
edr_gas_report::GasReportExecutionStatus::Revert => Self::Revert,
|
|
70
|
+
edr_gas_report::GasReportExecutionStatus::Halt => Self::Halt,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
impl From<edr_gas_report::DeploymentGasReport> for DeploymentGasReport {
|
|
76
|
+
fn from(value: edr_gas_report::DeploymentGasReport) -> Self {
|
|
77
|
+
Self {
|
|
78
|
+
gas: BigInt::from(value.gas),
|
|
79
|
+
size: BigInt::from(value.size),
|
|
80
|
+
status: value.status.into(),
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
impl From<edr_gas_report::FunctionGasReport> for FunctionGasReport {
|
|
86
|
+
fn from(value: edr_gas_report::FunctionGasReport) -> Self {
|
|
87
|
+
Self {
|
|
88
|
+
gas: BigInt::from(value.gas),
|
|
89
|
+
status: value.status.into(),
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/lib.rs
CHANGED
|
@@ -17,7 +17,10 @@ pub mod chains;
|
|
|
17
17
|
pub mod config;
|
|
18
18
|
/// Types related to an EDR N-API context.
|
|
19
19
|
pub mod context;
|
|
20
|
+
/// Types for decoding smart contract data.
|
|
21
|
+
pub mod contract_decoder;
|
|
20
22
|
mod debug_trace;
|
|
23
|
+
pub mod gas_report;
|
|
21
24
|
/// Types and functions related to code coverage instrumentation.
|
|
22
25
|
pub mod instrument;
|
|
23
26
|
/// Types for EVM execution logs.
|
|
@@ -26,7 +29,7 @@ pub mod log;
|
|
|
26
29
|
pub mod logger;
|
|
27
30
|
/// Types for mocking provider behavior.
|
|
28
31
|
#[cfg(feature = "test-mock")]
|
|
29
|
-
mod mock;
|
|
32
|
+
pub mod mock;
|
|
30
33
|
/// Types for precompiles.
|
|
31
34
|
pub mod precompile;
|
|
32
35
|
/// Types for Ethereum RPC providers.
|
package/src/log.rs
CHANGED
|
@@ -9,8 +9,8 @@ pub struct ExecutionLog {
|
|
|
9
9
|
pub data: Uint8Array,
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
impl From<&
|
|
13
|
-
fn from(value: &
|
|
12
|
+
impl From<&edr_receipt::log::ExecutionLog> for ExecutionLog {
|
|
13
|
+
fn from(value: &edr_receipt::log::ExecutionLog) -> Self {
|
|
14
14
|
let topics = value
|
|
15
15
|
.topics()
|
|
16
16
|
.iter()
|
package/src/logger.rs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
use std::sync::{mpsc::channel, Arc};
|
|
2
2
|
|
|
3
|
-
use edr_eth::Bytes;
|
|
4
3
|
use edr_napi_core::logger::LoggerError;
|
|
4
|
+
use edr_primitives::Bytes;
|
|
5
5
|
use napi::{
|
|
6
6
|
threadsafe_function::{
|
|
7
7
|
ErrorStrategy, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
|
|
@@ -65,7 +65,9 @@ impl LoggerConfig {
|
|
|
65
65
|
);
|
|
66
66
|
assert_eq!(status, Status::Ok);
|
|
67
67
|
|
|
68
|
-
receiver
|
|
68
|
+
receiver
|
|
69
|
+
.recv()
|
|
70
|
+
.expect("Receive can only fail if the channel is closed")
|
|
69
71
|
});
|
|
70
72
|
|
|
71
73
|
let mut print_line_callback: ThreadsafeFunction<_, ErrorStrategy::Fatal> = self
|
package/src/mock/time.rs
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
use std::sync::Arc;
|
|
2
|
+
|
|
3
|
+
use edr_evm::spec::RuntimeSpec;
|
|
4
|
+
use edr_evm_spec::ChainSpec;
|
|
5
|
+
use edr_generic::GenericChainSpec;
|
|
6
|
+
use edr_napi_core::logger::Logger;
|
|
7
|
+
use edr_primitives::B256;
|
|
8
|
+
use edr_rpc_spec::RpcSpec;
|
|
9
|
+
use napi::{bindgen_prelude::BigInt, tokio::runtime, Env, JsObject};
|
|
10
|
+
use napi_derive::napi;
|
|
11
|
+
|
|
12
|
+
use crate::{
|
|
13
|
+
cast::TryCast as _,
|
|
14
|
+
config::{resolve_configs, ConfigResolution, ProviderConfig},
|
|
15
|
+
contract_decoder::ContractDecoder,
|
|
16
|
+
logger::LoggerConfig,
|
|
17
|
+
provider::Provider,
|
|
18
|
+
subscription::SubscriptionConfig,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
#[napi]
|
|
22
|
+
pub struct MockTime {
|
|
23
|
+
inner: Arc<edr_provider::time::MockTime>,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#[napi]
|
|
27
|
+
impl MockTime {
|
|
28
|
+
#[doc = "Creates a new instance of `MockTime` with the current time."]
|
|
29
|
+
#[napi(factory, catch_unwind)]
|
|
30
|
+
pub fn now() -> Self {
|
|
31
|
+
Self {
|
|
32
|
+
inner: Arc::new(edr_provider::time::MockTime::now()),
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#[doc = "Adds the specified number of seconds to the current time."]
|
|
37
|
+
#[napi(catch_unwind)]
|
|
38
|
+
pub fn add_seconds(&self, seconds: BigInt) -> napi::Result<()> {
|
|
39
|
+
let seconds = seconds.try_cast()?;
|
|
40
|
+
|
|
41
|
+
self.inner.add_seconds(seconds);
|
|
42
|
+
Ok(())
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#[doc = "Creates a provider with a mock timer."]
|
|
47
|
+
#[doc = "For testing purposes."]
|
|
48
|
+
#[napi(catch_unwind, ts_return_type = "Promise<Provider>")]
|
|
49
|
+
pub fn create_provider_with_mock_timer(
|
|
50
|
+
env: Env,
|
|
51
|
+
provider_config: ProviderConfig,
|
|
52
|
+
logger_config: LoggerConfig,
|
|
53
|
+
subscription_config: SubscriptionConfig,
|
|
54
|
+
contract_decoder: &ContractDecoder,
|
|
55
|
+
time: &MockTime,
|
|
56
|
+
) -> napi::Result<JsObject> {
|
|
57
|
+
let (deferred, promise) = env.create_deferred()?;
|
|
58
|
+
|
|
59
|
+
macro_rules! try_or_reject_promise {
|
|
60
|
+
($expr:expr) => {
|
|
61
|
+
match $expr {
|
|
62
|
+
Ok(value) => value,
|
|
63
|
+
Err(error) => {
|
|
64
|
+
deferred.reject(error);
|
|
65
|
+
return Ok(promise);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let runtime = runtime::Handle::current();
|
|
72
|
+
|
|
73
|
+
let ConfigResolution {
|
|
74
|
+
logger_config,
|
|
75
|
+
provider_config,
|
|
76
|
+
subscription_callback,
|
|
77
|
+
} = try_or_reject_promise!(resolve_configs(
|
|
78
|
+
&env,
|
|
79
|
+
runtime.clone(),
|
|
80
|
+
provider_config,
|
|
81
|
+
logger_config,
|
|
82
|
+
subscription_config,
|
|
83
|
+
));
|
|
84
|
+
|
|
85
|
+
let contract_decoder = Arc::clone(contract_decoder.as_inner());
|
|
86
|
+
let timer = Arc::clone(&time.inner);
|
|
87
|
+
|
|
88
|
+
runtime.clone().spawn_blocking(move || {
|
|
89
|
+
// Using a closure to limit the scope, allowing us to use `?` for error
|
|
90
|
+
// handling. This is necessary because the result of the closure is used
|
|
91
|
+
// to resolve the deferred promise.
|
|
92
|
+
let create_provider = move || -> napi::Result<Provider> {
|
|
93
|
+
let logger = Logger::<GenericChainSpec, Arc<edr_provider::time::MockTime>>::new(
|
|
94
|
+
logger_config,
|
|
95
|
+
Arc::clone(&contract_decoder),
|
|
96
|
+
)?;
|
|
97
|
+
|
|
98
|
+
let provider_config =
|
|
99
|
+
edr_provider::ProviderConfig::<edr_chain_l1::Hardfork>::try_from(provider_config)?;
|
|
100
|
+
|
|
101
|
+
let provider =
|
|
102
|
+
edr_provider::Provider::<GenericChainSpec, Arc<edr_provider::time::MockTime>>::new(
|
|
103
|
+
runtime.clone(),
|
|
104
|
+
Box::new(logger),
|
|
105
|
+
Box::new(move |event| {
|
|
106
|
+
let event = edr_napi_core::subscription::SubscriptionEvent::new::<
|
|
107
|
+
<GenericChainSpec as RuntimeSpec>::Block,
|
|
108
|
+
<GenericChainSpec as RpcSpec>::RpcBlock<B256>,
|
|
109
|
+
<GenericChainSpec as ChainSpec>::SignedTransaction,
|
|
110
|
+
>(event);
|
|
111
|
+
|
|
112
|
+
subscription_callback.call(event);
|
|
113
|
+
}),
|
|
114
|
+
provider_config,
|
|
115
|
+
Arc::clone(&contract_decoder),
|
|
116
|
+
timer,
|
|
117
|
+
)
|
|
118
|
+
.map_err(|error| napi::Error::from_reason(error.to_string()))?;
|
|
119
|
+
|
|
120
|
+
Ok(Provider::new(
|
|
121
|
+
Arc::new(provider),
|
|
122
|
+
runtime,
|
|
123
|
+
contract_decoder,
|
|
124
|
+
#[cfg(feature = "scenarios")]
|
|
125
|
+
None,
|
|
126
|
+
))
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
let result = create_provider();
|
|
130
|
+
deferred.resolve(|_env| result);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
Ok(promise)
|
|
134
|
+
}
|
package/src/mock.rs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
pub mod time;
|
|
2
|
+
|
|
1
3
|
use std::sync::Arc;
|
|
2
4
|
|
|
5
|
+
use edr_evm_spec::EvmHaltReason;
|
|
3
6
|
use edr_napi_core::provider::SyncProvider;
|
|
4
7
|
use edr_rpc_client::jsonrpc;
|
|
5
8
|
use edr_solidity::contract_decoder::ContractDecoder;
|
|
@@ -24,7 +27,7 @@ impl SyncProvider for MockProvider {
|
|
|
24
27
|
&self,
|
|
25
28
|
_request: String,
|
|
26
29
|
_contract_decoder: Arc<ContractDecoder>,
|
|
27
|
-
) -> napi::Result<edr_napi_core::spec::Response<
|
|
30
|
+
) -> napi::Result<edr_napi_core::spec::Response<EvmHaltReason>> {
|
|
28
31
|
let response = jsonrpc::ResponseData::Success {
|
|
29
32
|
result: self.mocked_response.clone(),
|
|
30
33
|
};
|
package/src/precompile.rs
CHANGED
package/src/provider/response.rs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use
|
|
1
|
+
use edr_evm_spec::EvmHaltReason;
|
|
2
2
|
use edr_napi_core::spec::SolidityTraceData;
|
|
3
3
|
use edr_solidity::contract_decoder::NestedTraceDecoder as _;
|
|
4
4
|
use napi::Either;
|
|
@@ -11,11 +11,11 @@ use crate::{
|
|
|
11
11
|
|
|
12
12
|
#[napi]
|
|
13
13
|
pub struct Response {
|
|
14
|
-
inner: edr_napi_core::spec::Response<
|
|
14
|
+
inner: edr_napi_core::spec::Response<EvmHaltReason>,
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
impl From<edr_napi_core::spec::Response<
|
|
18
|
-
fn from(value: edr_napi_core::spec::Response<
|
|
17
|
+
impl From<edr_napi_core::spec::Response<EvmHaltReason>> for Response {
|
|
18
|
+
fn from(value: edr_napi_core::spec::Response<EvmHaltReason>) -> Self {
|
|
19
19
|
Self { inner: value }
|
|
20
20
|
}
|
|
21
21
|
}
|
package/src/provider.rs
CHANGED
|
@@ -5,18 +5,18 @@ mod response;
|
|
|
5
5
|
use std::sync::Arc;
|
|
6
6
|
|
|
7
7
|
use edr_napi_core::provider::SyncProvider;
|
|
8
|
-
use edr_solidity::
|
|
8
|
+
use edr_solidity::compiler::create_models_and_decode_bytecodes;
|
|
9
9
|
use napi::{tokio::runtime, Env, JsFunction, JsObject, Status};
|
|
10
10
|
use napi_derive::napi;
|
|
11
11
|
|
|
12
12
|
pub use self::factory::ProviderFactory;
|
|
13
13
|
use self::response::Response;
|
|
14
|
-
use crate::call_override::CallOverrideCallback;
|
|
14
|
+
use crate::{call_override::CallOverrideCallback, contract_decoder::ContractDecoder};
|
|
15
15
|
|
|
16
16
|
/// A JSON-RPC provider for Ethereum.
|
|
17
17
|
#[napi]
|
|
18
18
|
pub struct Provider {
|
|
19
|
-
contract_decoder: Arc<ContractDecoder>,
|
|
19
|
+
contract_decoder: Arc<edr_solidity::contract_decoder::ContractDecoder>,
|
|
20
20
|
provider: Arc<dyn SyncProvider>,
|
|
21
21
|
runtime: runtime::Handle,
|
|
22
22
|
#[cfg(feature = "scenarios")]
|
|
@@ -28,7 +28,7 @@ impl Provider {
|
|
|
28
28
|
pub fn new(
|
|
29
29
|
provider: Arc<dyn SyncProvider>,
|
|
30
30
|
runtime: runtime::Handle,
|
|
31
|
-
contract_decoder: Arc<ContractDecoder>,
|
|
31
|
+
contract_decoder: Arc<edr_solidity::contract_decoder::ContractDecoder>,
|
|
32
32
|
#[cfg(feature = "scenarios")] scenario_file: Option<
|
|
33
33
|
napi::tokio::sync::Mutex<napi::tokio::fs::File>,
|
|
34
34
|
>,
|
|
@@ -45,6 +45,53 @@ impl Provider {
|
|
|
45
45
|
|
|
46
46
|
#[napi]
|
|
47
47
|
impl Provider {
|
|
48
|
+
#[doc = "Adds a compilation result to the instance."]
|
|
49
|
+
#[doc = ""]
|
|
50
|
+
#[doc = "For internal use only. Support for this method may be removed in the future."]
|
|
51
|
+
#[napi(catch_unwind)]
|
|
52
|
+
pub async fn add_compilation_result(
|
|
53
|
+
&self,
|
|
54
|
+
solc_version: String,
|
|
55
|
+
compiler_input: serde_json::Value,
|
|
56
|
+
compiler_output: serde_json::Value,
|
|
57
|
+
) -> napi::Result<()> {
|
|
58
|
+
let contract_decoder = self.contract_decoder.clone();
|
|
59
|
+
|
|
60
|
+
self.runtime
|
|
61
|
+
.spawn_blocking(move || {
|
|
62
|
+
let compiler_input = serde_json::from_value(compiler_input)
|
|
63
|
+
.map_err(|error| napi::Error::from_reason(error.to_string()))?;
|
|
64
|
+
|
|
65
|
+
let compiler_output = serde_json::from_value(compiler_output)
|
|
66
|
+
.map_err(|error| napi::Error::from_reason(error.to_string()))?;
|
|
67
|
+
|
|
68
|
+
let contracts = match create_models_and_decode_bytecodes(
|
|
69
|
+
solc_version,
|
|
70
|
+
&compiler_input,
|
|
71
|
+
&compiler_output,
|
|
72
|
+
) {
|
|
73
|
+
Ok(contracts) => contracts,
|
|
74
|
+
Err(error) => {
|
|
75
|
+
return Err(napi::Error::from_reason(format!("Contract decoder failed to be updated. Please report this to help us improve Hardhat.\n{error}")));
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
for contract in contracts {
|
|
80
|
+
contract_decoder.add_contract_metadata(contract);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
Ok(())
|
|
84
|
+
})
|
|
85
|
+
.await
|
|
86
|
+
.map_err(|error| napi::Error::new(Status::GenericFailure, error.to_string()))?
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#[doc = "Retrieves the instance's contract decoder."]
|
|
90
|
+
#[napi(catch_unwind)]
|
|
91
|
+
pub fn contract_decoder(&self) -> ContractDecoder {
|
|
92
|
+
ContractDecoder::from(Arc::clone(&self.contract_decoder))
|
|
93
|
+
}
|
|
94
|
+
|
|
48
95
|
#[doc = "Handles a JSON-RPC request and returns a JSON-RPC response."]
|
|
49
96
|
#[napi(catch_unwind)]
|
|
50
97
|
pub async fn handle_request(&self, request: String) -> napi::Result<Response> {
|
package/src/result.rs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
use edr_evm::trace::AfterMessage;
|
|
2
|
+
use edr_evm_spec::EvmHaltReason;
|
|
2
3
|
use napi::{
|
|
3
4
|
bindgen_prelude::{BigInt, Either3, Uint8Array},
|
|
4
5
|
Either,
|
|
@@ -16,27 +17,24 @@ pub enum SuccessReason {
|
|
|
16
17
|
Return,
|
|
17
18
|
/// The opcode `SELFDESTRUCT` was called
|
|
18
19
|
SelfDestruct,
|
|
19
|
-
EofReturnContract,
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
impl From<
|
|
23
|
-
fn from(eval:
|
|
22
|
+
impl From<edr_evm::result::SuccessReason> for SuccessReason {
|
|
23
|
+
fn from(eval: edr_evm::result::SuccessReason) -> Self {
|
|
24
24
|
match eval {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
edr_eth::result::SuccessReason::EofReturnContract => Self::EofReturnContract,
|
|
25
|
+
edr_evm::result::SuccessReason::Stop => Self::Stop,
|
|
26
|
+
edr_evm::result::SuccessReason::Return => Self::Return,
|
|
27
|
+
edr_evm::result::SuccessReason::SelfDestruct => Self::SelfDestruct,
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
impl From<SuccessReason> for
|
|
32
|
+
impl From<SuccessReason> for edr_evm::result::SuccessReason {
|
|
34
33
|
fn from(value: SuccessReason) -> Self {
|
|
35
34
|
match value {
|
|
36
35
|
SuccessReason::Stop => Self::Stop,
|
|
37
36
|
SuccessReason::Return => Self::Return,
|
|
38
37
|
SuccessReason::SelfDestruct => Self::SelfDestruct,
|
|
39
|
-
SuccessReason::EofReturnContract => Self::EofReturnContract,
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
}
|
|
@@ -100,81 +98,38 @@ pub enum ExceptionalHalt {
|
|
|
100
98
|
CreateContractStartingWithEF,
|
|
101
99
|
/// EIP-3860: Limit and meter initcode. Initcode size limit exceeded.
|
|
102
100
|
CreateInitCodeSizeLimit,
|
|
103
|
-
/// Aux data overflow, new aux data is larger tha u16 max size.
|
|
104
|
-
EofAuxDataOverflow,
|
|
105
|
-
/// Aud data is smaller then already present data size.
|
|
106
|
-
EofAuxDataTooSmall,
|
|
107
|
-
/// EOF Subroutine stack overflow
|
|
108
|
-
SubRoutineStackOverflow,
|
|
109
|
-
/// Check for target address validity is only done inside subcall.
|
|
110
|
-
InvalidEXTCALLTarget,
|
|
111
101
|
}
|
|
112
102
|
|
|
113
|
-
impl From<
|
|
114
|
-
fn from(halt:
|
|
103
|
+
impl From<EvmHaltReason> for ExceptionalHalt {
|
|
104
|
+
fn from(halt: EvmHaltReason) -> Self {
|
|
115
105
|
match halt {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
edr_eth::l1::HaltReason::CreateContractStartingWithEF => {
|
|
106
|
+
EvmHaltReason::OutOfGas(..) => ExceptionalHalt::OutOfGas,
|
|
107
|
+
EvmHaltReason::OpcodeNotFound => ExceptionalHalt::OpcodeNotFound,
|
|
108
|
+
EvmHaltReason::InvalidFEOpcode => ExceptionalHalt::InvalidFEOpcode,
|
|
109
|
+
EvmHaltReason::InvalidJump => ExceptionalHalt::InvalidJump,
|
|
110
|
+
EvmHaltReason::NotActivated => ExceptionalHalt::NotActivated,
|
|
111
|
+
EvmHaltReason::StackUnderflow => ExceptionalHalt::StackUnderflow,
|
|
112
|
+
EvmHaltReason::StackOverflow => ExceptionalHalt::StackOverflow,
|
|
113
|
+
EvmHaltReason::OutOfOffset => ExceptionalHalt::OutOfOffset,
|
|
114
|
+
EvmHaltReason::CreateCollision => ExceptionalHalt::CreateCollision,
|
|
115
|
+
EvmHaltReason::PrecompileError => ExceptionalHalt::PrecompileError,
|
|
116
|
+
EvmHaltReason::NonceOverflow => ExceptionalHalt::NonceOverflow,
|
|
117
|
+
EvmHaltReason::CreateContractSizeLimit => ExceptionalHalt::CreateContractSizeLimit,
|
|
118
|
+
EvmHaltReason::CreateContractStartingWithEF => {
|
|
131
119
|
ExceptionalHalt::CreateContractStartingWithEF
|
|
132
120
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
ExceptionalHalt::SubRoutineStackOverflow
|
|
140
|
-
}
|
|
141
|
-
edr_eth::l1::HaltReason::InvalidEXTCALLTarget => ExceptionalHalt::InvalidEXTCALLTarget,
|
|
142
|
-
edr_eth::l1::HaltReason::OverflowPayment
|
|
143
|
-
| edr_eth::l1::HaltReason::StateChangeDuringStaticCall
|
|
144
|
-
| edr_eth::l1::HaltReason::CallNotAllowedInsideStatic
|
|
145
|
-
| edr_eth::l1::HaltReason::OutOfFunds
|
|
146
|
-
| edr_eth::l1::HaltReason::CallTooDeep => {
|
|
121
|
+
EvmHaltReason::CreateInitCodeSizeLimit => ExceptionalHalt::CreateInitCodeSizeLimit,
|
|
122
|
+
EvmHaltReason::OverflowPayment
|
|
123
|
+
| EvmHaltReason::StateChangeDuringStaticCall
|
|
124
|
+
| EvmHaltReason::CallNotAllowedInsideStatic
|
|
125
|
+
| EvmHaltReason::OutOfFunds
|
|
126
|
+
| EvmHaltReason::CallTooDeep => {
|
|
147
127
|
unreachable!("Internal halts that can be only found inside Inspector: {halt:?}")
|
|
148
128
|
}
|
|
149
129
|
}
|
|
150
130
|
}
|
|
151
131
|
}
|
|
152
132
|
|
|
153
|
-
impl From<ExceptionalHalt> for edr_eth::l1::HaltReason {
|
|
154
|
-
fn from(value: ExceptionalHalt) -> Self {
|
|
155
|
-
match value {
|
|
156
|
-
ExceptionalHalt::OutOfGas => Self::OutOfGas(edr_eth::l1::OutOfGasError::Basic),
|
|
157
|
-
ExceptionalHalt::OpcodeNotFound => Self::OpcodeNotFound,
|
|
158
|
-
ExceptionalHalt::InvalidFEOpcode => Self::InvalidFEOpcode,
|
|
159
|
-
ExceptionalHalt::InvalidJump => Self::InvalidJump,
|
|
160
|
-
ExceptionalHalt::NotActivated => Self::NotActivated,
|
|
161
|
-
ExceptionalHalt::StackUnderflow => Self::StackUnderflow,
|
|
162
|
-
ExceptionalHalt::StackOverflow => Self::StackOverflow,
|
|
163
|
-
ExceptionalHalt::OutOfOffset => Self::OutOfOffset,
|
|
164
|
-
ExceptionalHalt::CreateCollision => Self::CreateCollision,
|
|
165
|
-
ExceptionalHalt::PrecompileError => Self::PrecompileError,
|
|
166
|
-
ExceptionalHalt::NonceOverflow => Self::NonceOverflow,
|
|
167
|
-
ExceptionalHalt::CreateContractSizeLimit => Self::CreateContractSizeLimit,
|
|
168
|
-
ExceptionalHalt::CreateContractStartingWithEF => Self::CreateContractStartingWithEF,
|
|
169
|
-
ExceptionalHalt::CreateInitCodeSizeLimit => Self::CreateInitCodeSizeLimit,
|
|
170
|
-
ExceptionalHalt::EofAuxDataOverflow => Self::EofAuxDataOverflow,
|
|
171
|
-
ExceptionalHalt::EofAuxDataTooSmall => Self::EofAuxDataTooSmall,
|
|
172
|
-
ExceptionalHalt::SubRoutineStackOverflow => Self::SubRoutineStackOverflow,
|
|
173
|
-
ExceptionalHalt::InvalidEXTCALLTarget => Self::InvalidEXTCALLTarget,
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
133
|
/// The result when the EVM terminates due to an exceptional halt.
|
|
179
134
|
#[napi(object)]
|
|
180
135
|
pub struct HaltResult {
|
|
@@ -194,15 +149,15 @@ pub struct ExecutionResult {
|
|
|
194
149
|
pub contract_address: Option<Uint8Array>,
|
|
195
150
|
}
|
|
196
151
|
|
|
197
|
-
impl From<&AfterMessage<
|
|
198
|
-
fn from(value: &AfterMessage<
|
|
152
|
+
impl From<&AfterMessage<EvmHaltReason>> for ExecutionResult {
|
|
153
|
+
fn from(value: &AfterMessage<EvmHaltReason>) -> Self {
|
|
199
154
|
let AfterMessage {
|
|
200
155
|
execution_result,
|
|
201
156
|
contract_address,
|
|
202
157
|
} = value;
|
|
203
158
|
|
|
204
159
|
let result = match execution_result {
|
|
205
|
-
|
|
160
|
+
edr_evm::result::ExecutionResult::Success {
|
|
206
161
|
reason,
|
|
207
162
|
gas_used,
|
|
208
163
|
gas_refunded,
|
|
@@ -217,12 +172,12 @@ impl From<&AfterMessage<edr_eth::l1::HaltReason>> for ExecutionResult {
|
|
|
217
172
|
gas_refunded: BigInt::from(*gas_refunded),
|
|
218
173
|
logs,
|
|
219
174
|
output: match output {
|
|
220
|
-
|
|
175
|
+
edr_evm::result::Output::Call(return_value) => {
|
|
221
176
|
let return_value = Uint8Array::with_data_copied(return_value);
|
|
222
177
|
|
|
223
178
|
Either::A(CallOutput { return_value })
|
|
224
179
|
}
|
|
225
|
-
|
|
180
|
+
edr_evm::result::Output::Create(return_value, address) => {
|
|
226
181
|
let return_value = Uint8Array::with_data_copied(return_value);
|
|
227
182
|
|
|
228
183
|
Either::B(CreateOutput {
|
|
@@ -233,7 +188,7 @@ impl From<&AfterMessage<edr_eth::l1::HaltReason>> for ExecutionResult {
|
|
|
233
188
|
},
|
|
234
189
|
})
|
|
235
190
|
}
|
|
236
|
-
|
|
191
|
+
edr_evm::result::ExecutionResult::Revert { gas_used, output } => {
|
|
237
192
|
let output = Uint8Array::with_data_copied(output);
|
|
238
193
|
|
|
239
194
|
Either3::B(RevertResult {
|
|
@@ -241,7 +196,7 @@ impl From<&AfterMessage<edr_eth::l1::HaltReason>> for ExecutionResult {
|
|
|
241
196
|
output,
|
|
242
197
|
})
|
|
243
198
|
}
|
|
244
|
-
|
|
199
|
+
edr_evm::result::ExecutionResult::Halt { reason, gas_used } => Either3::C(HaltResult {
|
|
245
200
|
reason: ExceptionalHalt::from(*reason),
|
|
246
201
|
gas_used: BigInt::from(*gas_used),
|
|
247
202
|
}),
|
package/src/serde.rs
CHANGED