Skip to content

Commit ea5a6d7

Browse files
authored
refactor(l1): system contract errors (#2844)
**Motivation** Add specific error variants for system contract errors `SystemContractEmpty` & `SystemContractCallFailed`. <!-- Why does this pull request exist? What are its goals? --> **Description** * Add error variants `SystemContractEmpty` & `SystemContractCallFailed` * (Misc) minor change to error message <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Allows us to better map errors on execution-spec-tests
1 parent 03d3437 commit ea5a6d7

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

crates/vm/backends/levm/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,15 @@ impl LEVM {
363363
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7002.md
364364
let account = db.get_account(*WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS)?;
365365
if !account.has_code() {
366-
return Err(EvmError::Custom("BlockException.SYSTEM_CONTRACT_EMPTY: WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS has no code after deployment".to_string()));
366+
return Err(EvmError::SystemContractEmpty(
367+
"WITHDRAWAL_REQUEST_PREDEPLOY".to_string(),
368+
));
367369
}
368370

369371
match report.result {
370372
TxResult::Success => Ok(report),
371373
// EIP-7002 specifies that a failed system call invalidates the entire block.
372-
TxResult::Revert(vm_error) => Err(EvmError::Custom(format!(
374+
TxResult::Revert(vm_error) => Err(EvmError::SystemContractCallFailed(format!(
373375
"REVERT when reading withdrawal requests with error: {:?}. According to EIP-7002, the revert of this system call invalidates the block.",
374376
vm_error
375377
))),
@@ -392,13 +394,15 @@ impl LEVM {
392394
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7251.md
393395
let acc = db.get_account(*CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS)?;
394396
if !acc.has_code() {
395-
return Err(EvmError::Custom("BlockException.SYSTEM_CONTRACT_EMPTY: CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS has no code after deployment".to_string()));
397+
return Err(EvmError::SystemContractEmpty(
398+
"CONSOLIDATION_REQUEST_PREDEPLOY".to_string(),
399+
));
396400
}
397401

398402
match report.result {
399403
TxResult::Success => Ok(report),
400404
// EIP-7251 specifies that a failed system call invalidates the entire block.
401-
TxResult::Revert(vm_error) => Err(EvmError::Custom(format!(
405+
TxResult::Revert(vm_error) => Err(EvmError::SystemContractCallFailed(format!(
402406
"REVERT when dequeuing consolidation requests with error: {:?}. According to EIP-7251, the revert of this system call invalidates the block.",
403407
vm_error
404408
))),

crates/vm/backends/revm/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ impl REVM {
216216
let account_info =
217217
Self::system_contract_account_info(*WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, state)?;
218218
if account_info.is_empty_code_hash() {
219-
return Err(EvmError::Custom("BlockException.SYSTEM_CONTRACT_EMPTY: WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS has no code after deployment".to_string()));
219+
return Err(EvmError::SystemContractEmpty(
220+
"WITHDRAWAL_REQUEST_PREDEPLOY".to_string(),
221+
));
220222
}
221223

222224
match tx_result {
@@ -229,11 +231,11 @@ impl REVM {
229231
// EIP-7002 specifies that a failed system call invalidates the entire block.
230232
ExecutionResult::Halt { reason, gas_used } => {
231233
let err_str = format!("Transaction HALT when calling WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS with reason: {reason} and with used gas: {gas_used}");
232-
Err(EvmError::Custom(err_str))
234+
Err(EvmError::SystemContractCallFailed(err_str))
233235
}
234236
ExecutionResult::Revert { gas_used, output } => {
235237
let err_str = format!("Transaction REVERT when calling WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS with output: {:?} and with used gas: {gas_used}", output);
236-
Err(EvmError::Custom(err_str))
238+
Err(EvmError::SystemContractCallFailed(err_str))
237239
}
238240
}
239241
}
@@ -255,7 +257,9 @@ impl REVM {
255257
let account_info =
256258
Self::system_contract_account_info(*CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS, state)?;
257259
if account_info.is_empty_code_hash() {
258-
return Err(EvmError::Custom("BlockException.SYSTEM_CONTRACT_EMPTY: CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS has no code after deployment".to_string()));
260+
return Err(EvmError::SystemContractEmpty(
261+
"CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS".to_string(),
262+
));
259263
}
260264

261265
match tx_result {
@@ -268,11 +272,11 @@ impl REVM {
268272
// EIP-7251 specifies that a failed system call invalidates the entire block.
269273
ExecutionResult::Halt { reason, gas_used } => {
270274
let err_str = format!("Transaction HALT when calling CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS with reason: {reason} and with used gas: {gas_used}");
271-
Err(EvmError::Custom(err_str))
275+
Err(EvmError::SystemContractCallFailed(err_str))
272276
}
273277
ExecutionResult::Revert { gas_used, output } => {
274278
let err_str = format!("Transaction REVERT when calling CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS with output: {:?} and with used gas: {gas_used}", output);
275-
Err(EvmError::Custom(err_str))
279+
Err(EvmError::SystemContractCallFailed(err_str))
276280
}
277281
}
278282
}

crates/vm/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ pub enum EvmError {
2828
LevmDatabaseError(#[from] DatabaseError),
2929
#[error("Invalid deposit request layout")]
3030
InvalidDepositRequest,
31+
#[error("System contract: {0} has no code after deployment")]
32+
SystemContractEmpty(String),
33+
#[error("System call failed: {0}")]
34+
SystemContractCallFailed(String),
3135
}
3236

3337
#[derive(Debug, Error)]

crates/vm/levm/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub enum TxValidationError {
9494
NonceMismatch { expected: u64, actual: u64 },
9595
#[error("Initcode size exceeded")]
9696
InitcodeSizeExceeded,
97-
#[error("Priority fee greater than max fee per gas")]
97+
#[error("Priority fee is greater than max fee per gas")]
9898
PriorityGreaterThanMaxFeePerGas,
9999
#[error("Intrinsic gas too low")]
100100
IntrinsicGasTooLow,

0 commit comments

Comments
 (0)