MCPcopy Create free account
hub / github.com/diem/move / check_code

Method check_code

language/move-binary-format/src/check_bounds.rs:346–522  ·  view source on GitHub ↗
(
        &self,
        code_unit: &CodeUnit,
        type_parameters: &[AbilitySet],
        parameters: &Signature,
    )

Source from the content-addressed store, hash-verified

344 }
345
346 fn check_code(
347 &self,
348 code_unit: &CodeUnit,
349 type_parameters: &[AbilitySet],
350 parameters: &Signature,
351 ) -> PartialVMResult<()> {
352 check_bounds_impl(self.view.signatures(), code_unit.locals)?;
353
354 let locals = self.get_locals(code_unit)?;
355 let locals_count = locals.len() + parameters.len();
356
357 // if there are locals check that the type parameters in local signature are in bounds.
358 let type_param_count = type_parameters.len();
359 for local in locals {
360 self.check_type_parameter(local, type_param_count)?
361 }
362
363 // check bytecodes
364 let code_len = code_unit.code.len();
365 for (bytecode_offset, bytecode) in code_unit.code.iter().enumerate() {
366 use self::Bytecode::*;
367
368 match bytecode {
369 LdConst(idx) => self.check_code_unit_bounds_impl(
370 self.view.constant_pool(),
371 *idx,
372 bytecode_offset,
373 )?,
374 MutBorrowField(idx) | ImmBorrowField(idx) => self.check_code_unit_bounds_impl_opt(
375 &self.view.field_handles(),
376 *idx,
377 bytecode_offset,
378 )?,
379 MutBorrowFieldGeneric(idx) | ImmBorrowFieldGeneric(idx) => {
380 self.check_code_unit_bounds_impl_opt(
381 &self.view.field_instantiations(),
382 *idx,
383 bytecode_offset,
384 )?;
385 // check type parameters in borrow are bound to the function type parameters
386 if let Some(field_inst) = self
387 .view
388 .field_instantiations()
389 .and_then(|f| f.get(idx.into_index()))
390 {
391 if let Some(sig) = self
392 .view
393 .signatures()
394 .get(field_inst.type_parameters.into_index())
395 {
396 for ty in &sig.0 {
397 self.check_type_parameter(ty, type_param_count)?
398 }
399 }
400 }
401 }
402 Call(idx) => self.check_code_unit_bounds_impl(
403 self.view.function_handles(),

Callers 2

verify_scriptMethod · 0.80
check_function_defMethod · 0.80

Calls 15

check_bounds_implFunction · 0.85
check_type_parameterMethod · 0.80
offset_out_of_boundsMethod · 0.80
signaturesMethod · 0.45
get_localsMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45
constant_poolMethod · 0.45
field_handlesMethod · 0.45
field_instantiationsMethod · 0.45

Tested by

no test coverage detected