diff --git a/aptos-move/aptos-vm/src/aptos_vm.rs b/aptos-move/aptos-vm/src/aptos_vm.rs index 53215a698e364..9e71e607eef7e 100644 --- a/aptos-move/aptos-vm/src/aptos_vm.rs +++ b/aptos-move/aptos-vm/src/aptos_vm.rs @@ -726,32 +726,30 @@ impl AptosVM { let func = session.load_script(script.code(), script.ty_args())?; + let compiled_script = match CompiledScript::deserialize_with_config( + script.code(), + self.deserializer_config(), + ) { + Ok(script) => script, + Err(err) => { + let msg = format!("[VM] deserializer for script returned error: {:?}", err); + let partial_err = PartialVMError::new(StatusCode::CODE_DESERIALIZATION_ERROR) + .with_message(msg) + .finish(Location::Script); + return Err(partial_err.into_vm_status()); + }, + }; + // Check that unstable bytecode cannot be executed on mainnet if self .features() .is_enabled(FeatureFlag::REJECT_UNSTABLE_BYTECODE_FOR_SCRIPT) { - let script = match CompiledScript::deserialize_with_config( - script.code(), - self.deserializer_config(), - ) { - Ok(script) => script, - Err(err) => { - let msg = format!("[VM] deserializer for script returned error: {:?}", err); - return Err(VMStatus::error( - StatusCode::CODE_DESERIALIZATION_ERROR, - Some(msg), - )); - }, - }; - self.reject_unstable_bytecode_for_script(&script)?; + self.reject_unstable_bytecode_for_script(&compiled_script)?; } // TODO(Gerardo): consolidate the extended validation to verifier. - verifier::event_validation::verify_no_event_emission_in_script( - script.code(), - self.deserializer_config(), - )?; + verifier::event_validation::verify_no_event_emission_in_compiled_script(&compiled_script)?; let args = verifier::transaction_arg_validation::validate_combine_signer_and_txn_args( session, @@ -1641,7 +1639,7 @@ impl AptosVM { if metadata.unstable { return Err(PartialVMError::new(StatusCode::UNSTABLE_BYTECODE_REJECTED) .with_message("script marked unstable cannot be run on mainnet".to_string()) - .finish(Location::Undefined)); + .finish(Location::Script)); } } } diff --git a/aptos-move/aptos-vm/src/verifier/event_validation.rs b/aptos-move/aptos-vm/src/verifier/event_validation.rs index 6b1e2fb1e10e8..761a94bb2652d 100644 --- a/aptos-move/aptos-vm/src/verifier/event_validation.rs +++ b/aptos-move/aptos-vm/src/verifier/event_validation.rs @@ -5,7 +5,6 @@ use crate::move_vm_ext::SessionExt; use aptos_framework::RuntimeModuleMetadataV1; use move_binary_format::{ access::{ModuleAccess, ScriptAccess}, - deserializer::DeserializerConfig, errors::{Location, PartialVMError, VMError, VMResult}, file_format::{ Bytecode, CompiledScript, @@ -151,19 +150,7 @@ pub(crate) fn extract_event_metadata( Ok(event_structs) } -pub(crate) fn verify_no_event_emission_in_script( - script_code: &[u8], - config: &DeserializerConfig, -) -> VMResult<()> { - let script = match CompiledScript::deserialize_with_config(script_code, config) { - Ok(script) => script, - Err(err) => { - let msg = format!("[VM] deserializer for script returned error: {:?}", err); - return Err(PartialVMError::new(StatusCode::CODE_DESERIALIZATION_ERROR) - .with_message(msg) - .finish(Location::Script)); - }, - }; +pub(crate) fn verify_no_event_emission_in_compiled_script(script: &CompiledScript) -> VMResult<()> { for bc in &script.code().code { if let Bytecode::CallGeneric(index) = bc { let func_instantiation = &script.function_instantiation_at(*index);