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

Method verify_block

language/move-bytecode-verifier/src/stack_usage_verifier.rs:44–70  ·  view source on GitHub ↗
(&self, block_id: BlockId, cfg: &dyn ControlFlowGraph)

Source from the content-addressed store, hash-verified

42 }
43
44 fn verify_block(&self, block_id: BlockId, cfg: &dyn ControlFlowGraph) -> PartialVMResult<()> {
45 let code = &self.code.code;
46 let mut stack_size_increment = 0;
47 let block_start = cfg.block_start(block_id);
48 for i in block_start..=cfg.block_end(block_id) {
49 let (num_pops, num_pushes) = self.instruction_effect(&code[i as usize])?;
50 // Check that the stack height is sufficient to accommodate the number
51 // of pops this instruction does
52 if stack_size_increment < num_pops {
53 return Err(
54 PartialVMError::new(StatusCode::NEGATIVE_STACK_SIZE_WITHIN_BLOCK)
55 .at_code_offset(self.current_function(), block_start),
56 );
57 }
58 stack_size_increment -= num_pops;
59 stack_size_increment += num_pushes;
60 }
61
62 if stack_size_increment == 0 {
63 Ok(())
64 } else {
65 Err(
66 PartialVMError::new(StatusCode::POSITIVE_STACK_SIZE_AT_BLOCK_END)
67 .at_code_offset(self.current_function(), block_start),
68 )
69 }
70 }
71
72 /// The effect of an instruction is a tuple where the first element
73 /// is the number of pops it does, and the second element is the number

Callers 1

verifyMethod · 0.80

Calls 5

block_startMethod · 0.80
block_endMethod · 0.80
instruction_effectMethod · 0.80
at_code_offsetMethod · 0.80
current_functionMethod · 0.45

Tested by

no test coverage detected