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
48 changes: 37 additions & 11 deletions crates/context/interface/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ pub enum ExecutionResult<HaltReasonTy = HaltReason> {
Revert {
/// Gas accounting for the transaction.
gas: ResultGas,
/// Logs emitted before the revert.
logs: Vec<Log>,
/// Output of the transaction.
output: Bytes,
},
Expand All @@ -299,6 +301,8 @@ pub enum ExecutionResult<HaltReasonTy = HaltReason> {
/// For standard EVM halts, gas used typically equals the gas limit.
/// Some system- or L2-specific halts may intentionally report less gas used.
gas: ResultGas,
/// Logs emitted before the halt.
logs: Vec<Log>,
},
}

Expand Down Expand Up @@ -329,10 +333,11 @@ impl<HaltReasonTy> ExecutionResult<HaltReasonTy> {
logs,
output,
},
Self::Revert { gas, output } => ExecutionResult::Revert { gas, output },
Self::Halt { reason, gas } => ExecutionResult::Halt {
Self::Revert { gas, logs, output } => ExecutionResult::Revert { gas, logs, output },
Self::Halt { reason, gas, logs } => ExecutionResult::Halt {
reason: op(reason),
gas,
logs,
},
}
}
Expand Down Expand Up @@ -373,19 +378,21 @@ impl<HaltReasonTy> ExecutionResult<HaltReasonTy> {
}
}

/// Returns the logs if execution is successful, or an empty list otherwise.
/// Returns the logs emitted during execution.
pub fn logs(&self) -> &[Log] {
match self {
Self::Success { logs, .. } => logs.as_slice(),
_ => &[],
Self::Success { logs, .. } | Self::Revert { logs, .. } | Self::Halt { logs, .. } => {
logs.as_slice()
}
}
}

/// Consumes [`self`] and returns the logs if execution is successful, or an empty list otherwise.
/// Consumes [`self`] and returns the logs emitted during execution.
pub fn into_logs(self) -> Vec<Log> {
match self {
Self::Success { logs, .. } => logs,
_ => Vec::new(),
Self::Success { logs, .. } | Self::Revert { logs, .. } | Self::Halt { logs, .. } => {
logs
}
}
}

Expand Down Expand Up @@ -422,15 +429,32 @@ impl<HaltReasonTy: fmt::Display> fmt::Display for ExecutionResult<HaltReasonTy>
}
write!(f, ", {output}")
}
Self::Revert { gas, output } => {
Self::Revert { gas, logs, output } => {
write!(f, "Revert: {gas}")?;
if !logs.is_empty() {
write!(
f,
", {} log{}",
logs.len(),
if logs.len() == 1 { "" } else { "s" }
)?;
}
if !output.is_empty() {
write!(f, ", {} bytes output", output.len())?;
}
Ok(())
}
Self::Halt { reason, gas } => {
write!(f, "Halted: {reason} ({gas})")
Self::Halt { reason, gas, logs } => {
write!(f, "Halted: {reason} ({gas})")?;
if !logs.is_empty() {
write!(
f,
", {} log{}",
logs.len(),
if logs.len() == 1 { "" } else { "s" }
)?;
}
Ok(())
}
}
}
Expand Down Expand Up @@ -1071,6 +1095,7 @@ mod tests {

let result: ExecutionResult<HaltReason> = ExecutionResult::Revert {
gas: ResultGas::new(100000, 100000, 0, 0, 0),
logs: vec![],
output: Bytes::from(vec![1, 2, 3, 4]),
};
assert_eq!(
Expand All @@ -1081,6 +1106,7 @@ mod tests {
let result: ExecutionResult<HaltReason> = ExecutionResult::Halt {
reason: HaltReason::OutOfGas(OutOfGasError::Basic),
gas: ResultGas::new(1000000, 1000000, 0, 0, 0),
logs: vec![],
};
assert_eq!(
result.to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/ee-tests/src/op_revm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ fn test_halted_deposit_tx() {
0,
0,
),
logs: vec![],
}
);
assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 0,
"limit": 16777216
},
"logs": [],
"reason": "FailedDeposit"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 21000,
"limit": 21375
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bls12-381 g1 add input length error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 21000,
"limit": 21374
},
"logs": [],
"reason": {
"Base": {
"OutOfGas": "Precompile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 23544,
"limit": 35560
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bls12-381 g1 msm input length error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 23560,
"limit": 35559
},
"logs": [],
"reason": {
"Base": {
"OutOfGas": "Precompile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 23560,
"limit": 35560
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bls12-381 fp 64 top bytes of input are not zero"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 21000,
"limit": 21600
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bls12-381 g2 add input length error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 21000,
"limit": 21599
},
"logs": [],
"reason": {
"Base": {
"OutOfGas": "Precompile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 25592,
"limit": 48108
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bls12-381 g2 msm input length error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 25608,
"limit": 48107
},
"logs": [],
"reason": {
"Base": {
"OutOfGas": "Precompile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 25608,
"limit": 48108
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bls12-381 fp 64 top bytes of input are not zero"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 23032,
"limit": 46848
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bls12-381 map fp2 to g2 input length error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 23048,
"limit": 46847
},
"logs": [],
"reason": {
"Base": {
"OutOfGas": "Precompile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 22008,
"limit": 27524
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bls12-381 map fp to g1 input length error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 22024,
"limit": 27523
},
"logs": [],
"reason": {
"Base": {
"OutOfGas": "Precompile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 27128,
"limit": 97444
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bls12-381 pairing input length error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 27144,
"limit": 97443
},
"logs": [],
"reason": {
"Base": {
"OutOfGas": "Precompile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 27144,
"limit": 97444
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bls12-381 fp 64 top bytes of input are not zero"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 1824024,
"limit": 1824024
},
"logs": [],
"reason": {
"Base": {
"OutOfGas": "Precompile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 1824024,
"limit": 1824024
},
"logs": [],
"reason": {
"Base": {
"PrecompileErrorWithContext": "bn254 invalid pair length"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"intrinsic_gas": 21000,
"limit": 24449
},
"logs": [],
"reason": {
"Base": {
"OutOfGas": "Precompile"
Expand Down
3 changes: 3 additions & 0 deletions crates/handler/src/post_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub fn output<CTX: ContextTr<Journal: JournalTr>, HALTREASON: HaltReasonTr>(
},
SuccessOrHalt::Revert => ExecutionResult::Revert {
gas: result_gas,
logs,
output: output.into_data(),
},
SuccessOrHalt::Halt(reason) => {
Expand All @@ -127,12 +128,14 @@ pub fn output<CTX: ContextTr<Journal: JournalTr>, HALTREASON: HaltReasonTr>(
return ExecutionResult::Halt {
reason: HALTREASON::from(HaltReason::PrecompileErrorWithContext(message)),
gas: result_gas,
logs,
};
}
}
ExecutionResult::Halt {
reason,
gas: result_gas,
logs,
}
}
// Only two internal return flags.
Expand Down
3 changes: 2 additions & 1 deletion crates/op-revm/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use revm::{
interpreter::{interpreter::EthInterpreter, interpreter_action::FrameInit, Gas},
primitives::{hardfork::SpecId, U256},
};
use std::boxed::Box;
use std::{boxed::Box, vec::Vec};

/// Optimism handler extends the [`Handler`] with Optimism specific logic.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -424,6 +424,7 @@ where
output = Ok(ExecutionResult::Halt {
reason: OpHaltReason::FailedDeposit,
gas: ResultGas::new(gas_limit, gas_used, 0, 0, 0),
logs: Vec::new(),
})
}

Expand Down
12 changes: 6 additions & 6 deletions examples/custom_precompile_journal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ fn main() -> anyhow::Result<()> {
let value = U256::from_be_slice(data);
println!(" 📖 Initial storage value: {value}");
}
Ok(revm::context::result::ExecutionResult::Revert { output, gas }) => {
Ok(revm::context::result::ExecutionResult::Revert { output, gas, .. }) => {
println!(
" ❌ Reverted! Gas used: {}, Output: {output:?}",
gas.used()
);
}
Ok(revm::context::result::ExecutionResult::Halt { reason, gas }) => {
Ok(revm::context::result::ExecutionResult::Halt { reason, gas, .. }) => {
println!(" 🛑 Halted! Reason: {reason:?}, Gas used: {}", gas.used());
}
Err(e) => {
Expand Down Expand Up @@ -121,13 +121,13 @@ fn main() -> anyhow::Result<()> {
println!(" 📝 Value 42 written to storage");
println!(" 💰 1 wei transferred from precompile to caller as reward");
}
Ok(revm::context::result::ExecutionResult::Revert { output, gas }) => {
Ok(revm::context::result::ExecutionResult::Revert { output, gas, .. }) => {
println!(
" ❌ Reverted! Gas used: {}, Output: {output:?}",
gas.used()
);
}
Ok(revm::context::result::ExecutionResult::Halt { reason, gas }) => {
Ok(revm::context::result::ExecutionResult::Halt { reason, gas, .. }) => {
println!(" 🛑 Halted! Reason: {reason:?}, Gas used: {}", gas.used());
}
Err(e) => {
Expand Down Expand Up @@ -161,13 +161,13 @@ fn main() -> anyhow::Result<()> {
println!(" ⚠️ Unexpected value in storage");
}
}
Ok(revm::context::result::ExecutionResult::Revert { output, gas }) => {
Ok(revm::context::result::ExecutionResult::Revert { output, gas, .. }) => {
println!(
" ❌ Reverted! Gas used: {}, Output: {output:?}",
gas.used()
);
}
Ok(revm::context::result::ExecutionResult::Halt { reason, gas }) => {
Ok(revm::context::result::ExecutionResult::Halt { reason, gas, .. }) => {
println!(" 🛑 Halted! Reason: {reason:?}, Gas used: {}", gas.used());
}
Err(e) => {
Expand Down
Loading