@nomicfoundation/edr 0.4.2 → 0.5.1

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 CHANGED
@@ -223,6 +223,8 @@ export interface ProviderConfig {
223
223
  chains: Array<ChainConfig>
224
224
  /** The address of the coinbase */
225
225
  coinbase: Buffer
226
+ /** Enables RIP-7212 */
227
+ enableRip7212: boolean
226
228
  /**
227
229
  * The configuration for forking a blockchain. If not provided, a local
228
230
  * blockchain will be created
@@ -260,7 +262,8 @@ export const enum SuccessReason {
260
262
  /** The opcode `RETURN` was called */
261
263
  Return = 1,
262
264
  /** The opcode `SELFDESTRUCT` was called */
263
- SelfDestruct = 2
265
+ SelfDestruct = 2,
266
+ EofReturnContract = 3
264
267
  }
265
268
  export interface CallOutput {
266
269
  /** Return value */
@@ -313,7 +316,13 @@ export const enum ExceptionalHalt {
313
316
  /** Error on created contract that begins with EF */
314
317
  CreateContractStartingWithEF = 12,
315
318
  /** EIP-3860: Limit and meter initcode. Initcode size limit exceeded. */
316
- CreateInitCodeSizeLimit = 13
319
+ CreateInitCodeSizeLimit = 13,
320
+ /** Aux data overflow, new aux data is larger tha u16 max size. */
321
+ EofAuxDataOverflow = 14,
322
+ /** Aud data is smaller then already present data size. */
323
+ EofAuxDataTooSmall = 15,
324
+ /** EOF Subroutine stack overflow */
325
+ EOFFunctionStackOverflow = 16
317
326
  }
318
327
  /** The result when the EVM terminates due to an exceptional halt. */
319
328
  export interface HaltResult {
@@ -409,7 +418,8 @@ export class Provider {
409
418
  setVerboseTracing(verboseTracing: boolean): void
410
419
  }
411
420
  export class Response {
412
- get json(): string
421
+ /** Returns the response data as a JSON string or a JSON object. */
422
+ get data(): string | any
413
423
  get solidityTrace(): RawTrace | null
414
424
  get traces(): Array<RawTrace>
415
425
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomicfoundation/edr",
3
- "version": "0.4.2",
3
+ "version": "0.5.1",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [
@@ -38,6 +38,7 @@
38
38
  "@types/node": "^18.0.0",
39
39
  "chai": "^4.3.6",
40
40
  "chai-as-promised": "^7.1.1",
41
+ "json-stream-stringify": "^3.1.4",
41
42
  "mocha": "^10.0.0",
42
43
  "ts-node": "^10.8.0",
43
44
  "typescript": "~4.5.2"
@@ -46,13 +47,13 @@
46
47
  "node": ">= 18"
47
48
  },
48
49
  "dependencies": {
49
- "@nomicfoundation/edr-darwin-arm64": "0.4.2",
50
- "@nomicfoundation/edr-darwin-x64": "0.4.2",
51
- "@nomicfoundation/edr-linux-arm64-gnu": "0.4.2",
52
- "@nomicfoundation/edr-linux-arm64-musl": "0.4.2",
53
- "@nomicfoundation/edr-linux-x64-gnu": "0.4.2",
54
- "@nomicfoundation/edr-linux-x64-musl": "0.4.2",
55
- "@nomicfoundation/edr-win32-x64-msvc": "0.4.2"
50
+ "@nomicfoundation/edr-darwin-arm64": "0.5.1",
51
+ "@nomicfoundation/edr-darwin-x64": "0.5.1",
52
+ "@nomicfoundation/edr-linux-arm64-gnu": "0.5.1",
53
+ "@nomicfoundation/edr-linux-arm64-musl": "0.5.1",
54
+ "@nomicfoundation/edr-linux-x64-gnu": "0.5.1",
55
+ "@nomicfoundation/edr-linux-x64-musl": "0.5.1",
56
+ "@nomicfoundation/edr-win32-x64-msvc": "0.5.1"
56
57
  },
57
58
  "scripts": {
58
59
  "artifacts": "napi artifacts",
@@ -63,8 +64,8 @@
63
64
  "universal": "napi universal",
64
65
  "version": "napi version",
65
66
  "pretest": "pnpm build",
66
- "test": "pnpm tsc && mocha --recursive \"test/**/*.ts\"",
67
- "testNoBuild": "pnpm tsc && mocha --recursive \"test/**/*.ts\"",
67
+ "test": "pnpm tsc && node --max-old-space-size=8192 node_modules/mocha/bin/_mocha --recursive \"test/**/*.ts\"",
68
+ "testNoBuild": "pnpm tsc && node --max-old-space-size=8192 node_modules/mocha/bin/_mocha --recursive \"test/**/*.ts\"",
68
69
  "clean": "rm -rf @nomicfoundation/edr.node"
69
70
  }
70
71
  }
@@ -100,6 +100,8 @@ pub struct ProviderConfig {
100
100
  pub chains: Vec<ChainConfig>,
101
101
  /// The address of the coinbase
102
102
  pub coinbase: Buffer,
103
+ /// Enables RIP-7212
104
+ pub enable_rip_7212: bool,
103
105
  /// The configuration for forking a blockchain. If not provided, a local
104
106
  /// blockchain will be created
105
107
  pub fork: Option<ForkConfig>,
@@ -261,6 +263,7 @@ impl TryFrom<ProviderConfig> for edr_provider::ProviderConfig {
261
263
  chain_id: value.chain_id.try_cast()?,
262
264
  chains,
263
265
  coinbase: value.coinbase.try_cast()?,
266
+ enable_rip_7212: value.enable_rip_7212,
264
267
  fork: value.fork.map(TryInto::try_into).transpose()?,
265
268
  genesis_accounts: HashMap::new(),
266
269
  hardfork: value.hardfork.into(),
package/src/provider.rs CHANGED
@@ -4,7 +4,7 @@ use std::sync::Arc;
4
4
 
5
5
  use edr_provider::{time::CurrentTime, InvalidRequestReason};
6
6
  use edr_rpc_eth::jsonrpc;
7
- use napi::{tokio::runtime, Env, JsFunction, JsObject, Status};
7
+ use napi::{tokio::runtime, Either, Env, JsFunction, JsObject, Status};
8
8
  use napi_derive::napi;
9
9
 
10
10
  use self::config::ProviderConfig;
@@ -120,9 +120,9 @@ impl Provider {
120
120
  format!("Invalid JSON `{json_request}` due to: {error}"),
121
121
  )
122
122
  })
123
- .map(|json_response| Response {
123
+ .map(|json| Response {
124
124
  solidity_trace: None,
125
- json: json_response,
125
+ data: Either::A(json),
126
126
  traces: Vec::new(),
127
127
  });
128
128
  }
@@ -168,10 +168,25 @@ impl Provider {
168
168
  let response = jsonrpc::ResponseData::from(response.map(|response| response.result));
169
169
 
170
170
  serde_json::to_string(&response)
171
- .map_err(|e| napi::Error::new(Status::GenericFailure, e.to_string()))
172
- .map(|json_response| Response {
171
+ .and_then(|json| {
172
+ // We experimentally determined that 500_000_000 was the maximum string length
173
+ // that can be returned without causing the error:
174
+ //
175
+ // > Failed to convert rust `String` into napi `string`
176
+ //
177
+ // To be safe, we're limiting string lengths to half of that.
178
+ const MAX_STRING_LENGTH: usize = 250_000_000;
179
+
180
+ if json.len() <= MAX_STRING_LENGTH {
181
+ Ok(Either::A(json))
182
+ } else {
183
+ serde_json::to_value(response).map(Either::B)
184
+ }
185
+ })
186
+ .map_err(|error| napi::Error::new(Status::GenericFailure, error.to_string()))
187
+ .map(|data| Response {
173
188
  solidity_trace,
174
- json: json_response,
189
+ data,
175
190
  traces: traces.into_iter().map(Arc::new).collect(),
176
191
  })
177
192
  }
@@ -209,7 +224,10 @@ impl Provider {
209
224
 
210
225
  #[napi]
211
226
  pub struct Response {
212
- json: String,
227
+ // N-API is known to be slow when marshalling `serde_json::Value`s, so we try to return a
228
+ // `String`. If the object is too large to be represented as a `String`, we return a `Buffer`
229
+ // instead.
230
+ data: Either<String, serde_json::Value>,
213
231
  /// When a transaction fails to execute, the provider returns a trace of the
214
232
  /// transaction.
215
233
  solidity_trace: Option<Arc<edr_evm::trace::Trace>>,
@@ -219,9 +237,10 @@ pub struct Response {
219
237
 
220
238
  #[napi]
221
239
  impl Response {
240
+ /// Returns the response data as a JSON string or a JSON object.
222
241
  #[napi(getter)]
223
- pub fn json(&self) -> String {
224
- self.json.clone()
242
+ pub fn data(&self) -> Either<String, serde_json::Value> {
243
+ self.data.clone()
225
244
  }
226
245
 
227
246
  #[napi(getter)]
package/src/result.rs CHANGED
@@ -85,7 +85,7 @@ pub struct RevertResult {
85
85
  pub enum ExceptionalHalt {
86
86
  OutOfGas,
87
87
  OpcodeNotFound,
88
- InvalidEFOpcode,
88
+ InvalidFEOpcode,
89
89
  InvalidJump,
90
90
  NotActivated,
91
91
  StackUnderflow,
@@ -113,7 +113,7 @@ impl From<edr_evm::HaltReason> for ExceptionalHalt {
113
113
  match halt {
114
114
  edr_evm::HaltReason::OutOfGas(..) => ExceptionalHalt::OutOfGas,
115
115
  edr_evm::HaltReason::OpcodeNotFound => ExceptionalHalt::OpcodeNotFound,
116
- edr_evm::HaltReason::InvalidEFOpcode => ExceptionalHalt::InvalidEFOpcode,
116
+ edr_evm::HaltReason::InvalidFEOpcode => ExceptionalHalt::InvalidFEOpcode,
117
117
  edr_evm::HaltReason::InvalidJump => ExceptionalHalt::InvalidJump,
118
118
  edr_evm::HaltReason::NotActivated => ExceptionalHalt::NotActivated,
119
119
  edr_evm::HaltReason::StackUnderflow => ExceptionalHalt::StackUnderflow,
@@ -152,7 +152,7 @@ impl From<ExceptionalHalt> for edr_evm::HaltReason {
152
152
  match value {
153
153
  ExceptionalHalt::OutOfGas => Self::OutOfGas(edr_evm::OutOfGasError::Basic),
154
154
  ExceptionalHalt::OpcodeNotFound => Self::OpcodeNotFound,
155
- ExceptionalHalt::InvalidEFOpcode => Self::InvalidEFOpcode,
155
+ ExceptionalHalt::InvalidFEOpcode => Self::InvalidFEOpcode,
156
156
  ExceptionalHalt::InvalidJump => Self::InvalidJump,
157
157
  ExceptionalHalt::NotActivated => Self::NotActivated,
158
158
  ExceptionalHalt::StackUnderflow => Self::StackUnderflow,