Skip to content

Commit

Permalink
Merge pull request #20 from lambdaclass/opcode-assertions
Browse files Browse the repository at this point in the history
Add opcode_assertions
  • Loading branch information
unbalancedparentheses authored May 10, 2022
2 parents ca5822f + efeda38 commit ed62ece
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/vm/vm_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,47 @@ impl VirtualMachine {
};
return None;
}

fn opcode_assertions(&self, instruction: &Instruction, operands: &Operands) {
match instruction.opcode {
Opcode::ASSERT_EQ => {
match &operands.res {
None => panic!("Res.UNCONSTRAINED cannot be used with Opcode.ASSERT_EQ"),
Some(res) => {
if let (MaybeRelocatable::Int(res_num), MaybeRelocatable::Int(dst_num)) =
(res, &operands.dst)
{
if res_num != dst_num {
panic!(
"An ASSERT_EQ instruction failed: {} != {}",
res_num, dst_num
);
};
};
}
};
}
Opcode::CALL => {
if let (MaybeRelocatable::Int(op0_num), MaybeRelocatable::Int(run_pc)) =
(&operands.op0, &self.run_context.pc)
{
let return_pc = run_pc + bigint!(instruction.size());
if op0_num != &return_pc {
panic!("Call failed to write return-pc (inconsistent op0): {} != {}. Did you forget to increment ap?", op0_num, return_pc);
};
};

if let (MaybeRelocatable::Int(return_fp), MaybeRelocatable::Int(dst_num)) =
(&self.run_context.fp, &operands.dst)
{
if dst_num != return_fp {
panic!("Call failed to write return-fp (inconsistent dst): fp->{} != dst->{}. Did you forget to increment ap?",dst_num,dst_num);
};
};
}
_ => {}
}
}
}

#[derive(Debug, PartialEq)]
Expand Down

0 comments on commit ed62ece

Please sign in to comment.