Skip to content

Commit

Permalink
script cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rahxephon89 committed Jul 29, 2024
1 parent a7822ee commit 3a0bb8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
36 changes: 17 additions & 19 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,32 +739,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,
Expand Down Expand Up @@ -1653,7 +1651,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));
}
}
}
Expand Down
15 changes: 1 addition & 14 deletions aptos-move/aptos-vm/src/verifier/event_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3a0bb8e

Please sign in to comment.