CVE-2024-21629: Insufficient Information (NVD-CWE-noinfo)
value: Rust EVM is an Ethereum Virtual Machine interpreter. In `rust-evm`, a feature called `record_external_operation` was introduced, allowing library users to record custom gas changes. This feature can have some bogus interactions with the call stack. In particular, during finalization of a `CREATE` or `CREATE2`, in the case that the substack execution happens successfully, `rust-evm` will first commit the substate, and then call `record_external_operation(Write(out_code.len()))`. If `record_external_operation` later fails, this error is returned to the parent call stack, instead of `Succeeded`. Yet, the substate commitment already happened. This causes smart contracts able to commit state changes, when the parent caller contract receives zero address (which usually indicates that the execution has failed). This issue only impacts library users with custom `record_external_operation` that returns errors. The issue is patched in release 0.41.1. No known workarounds are available.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
CVSS v3 base score: 7.5
Published: 2024-01-02T22:15Z
Repository: https://github.com/rust-ethereum/evm
Language: Rust
Files changed: Cargo.toml, src/executor/stack/executor.rs
Commit date: 2023-12-17 22:30:03 +0100
Commit message: Fix cleanup_create order and release v0.41.1 (#264)


Diff: diff --git a/Cargo.toml b/Cargo.toml
index c867e3f..478598c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,8 +1,8 @@
 [package]
 name = "evm"
-version = "0.41.0"
+version = "0.41.1"
 license = "Apache-2.0"
 authors = ["Wei Tang <hi@that.world>", "Parity Technologies <admin@parity.io>"]
 description = "SputnikVM - a Portable Blockchain Virtual Machine"
 repository = "https://github.com/sorpaas/rust-evm"
 keywords = ["no_std", "ethereum"]
diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs
index e35bae1..95b3e17 100644
--- a/src/executor/stack/executor.rs
+++ b/src/executor/stack/executor.rs
@@ -1007,16 +1007,18 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
 					.metadata_mut()
 					.gasometer
 					.record_deposit(out.len())
 				{
 					Ok(()) => {
-						let exit_result = self.exit_substate(StackExitKind::Succeeded);
 						if let Err(e) = self.record_external_operation(
 							crate::ExternalOperation::Write(U256::from(out.len())),
 						) {
+							self.state.metadata_mut().gasometer.fail();
+							let _ = self.exit_substate(StackExitKind::Failed);
 							return (e.into(), None, Vec::new());
 						}
+						let exit_result = self.exit_substate(StackExitKind::Succeeded);
 						self.state.set_code(address, out);
 						if let Err(e) = exit_result {
 							return (e.into(), None, Vec::new());
 						}
 						(ExitReason::Succeed(s), Some(address), Vec::new())

Vulnerable code: version = "0.41.0"
						let exit_result = self.exit_substate(StackExitKind::Succeeded);
Fixed code: version = "0.41.1"
							self.state.metadata_mut().gasometer.fail();
							let _ = self.exit_substate(StackExitKind::Failed);
						let exit_result = self.exit_substate(StackExitKind::Succeeded);