diff --git a/src/vm/validated_memory_dict.rs b/src/vm/validated_memory_dict.rs index 98811d2f93..4b4a894912 100644 --- a/src/vm/validated_memory_dict.rs +++ b/src/vm/validated_memory_dict.rs @@ -5,7 +5,7 @@ use num_bigint::BigInt; use std::collections::HashMap; pub struct ValidatedMemoryDict { - memory: Memory, + pub memory: Memory, validation_rules: HashMap>, validated_addresses: Vec, } diff --git a/src/vm/vm_core.rs b/src/vm/vm_core.rs index 6c95bc6fed..6c855fe23f 100644 --- a/src/vm/vm_core.rs +++ b/src/vm/vm_core.rs @@ -21,6 +21,10 @@ struct Operands { op1: MaybeRelocatable, } +struct Rule { + func: fn(&VirtualMachine, &MaybeRelocatable, &()) -> Option, +} + pub struct VirtualMachine { run_context: RunContext, prime: BigInt, @@ -37,7 +41,7 @@ pub struct VirtualMachine { //program: ProgramBase, program_base: Option, validated_memory: ValidatedMemoryDict, - //auto_deduction: HashMap>, + //auto_deduction: HashMap>, accessesed_addresses: Vec, trace: Vec, current_step: BigInt, @@ -286,6 +290,29 @@ impl VirtualMachine { return None; } + pub fn deduce_memory_cell(&mut self, addr: MaybeRelocatable) -> Option { + match addr { + MaybeRelocatable::Int(_) => (), + MaybeRelocatable::RelocatableValue(ref addr_val) => { + match self.auto_deduction.get(&addr_val.segment_index) { + Some(rules) => { + for (rule, args) in rules.iter() { + match (rule.func)(self, &addr, args) { + Some(value) => { + self.validated_memory.memory.insert(&addr, &value); + return Some(value); + }, + None => (), + }; + } + }, + None => (), + }; + } + } + None + } + fn opcode_assertions(&self, instruction: &Instruction, operands: &Operands) { match instruction.opcode { Opcode::ASSERT_EQ => {