Skip to content

Commit

Permalink
script cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rahxephon89 committed Jul 23, 2024
1 parent 97b10bb commit 48ccde9
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 @@ -726,32 +726,30 @@ impl AptosVM {

let func = session.load_script(script.code(), script.ty_args())?;

let compiled_script = match CompiledScript::deserialize_with_config(

Check warning on line 729 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L729

Added line #L729 was not covered by tests
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 warning on line 739 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L732-L739

Added lines #L732 - L739 were not covered by tests
},
};

// Check that unstable bytecode cannot be executed on mainnet
if self
.features()
.is_enabled(FeatureFlag::REJECT_UNSTABLE_BYTECODE_FOR_SCRIPT)

Check warning on line 746 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L744-L746

Added lines #L744 - L746 were not covered by tests
{
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)?;
}

Check warning on line 749 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L748-L749

Added lines #L748 - L749 were not covered by tests

// 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)?;

Check warning on line 752 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L752

Added line #L752 was not covered by tests

let args = verifier::transaction_arg_validation::validate_combine_signer_and_txn_args(
session,
Expand Down Expand Up @@ -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));
}
}
}
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<()> {

Check warning on line 153 in aptos-move/aptos-vm/src/verifier/event_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/verifier/event_validation.rs#L153

Added line #L153 was not covered by tests
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 48ccde9

Please sign in to comment.