From f8f6bebf09dc633082ac738df89eaf71fc1b5034 Mon Sep 17 00:00:00 2001 From: Jan Ferdinand Sauer Date: Wed, 4 Oct 2023 23:09:33 +0200 Subject: [PATCH] use `u64` as absolute addresses when converting from labels --- triton-vm/src/instruction.rs | 33 +++++++++++++++------------------ triton-vm/src/program.rs | 2 +- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/triton-vm/src/instruction.rs b/triton-vm/src/instruction.rs index 2479c9cb..bff4564c 100644 --- a/triton-vm/src/instruction.rs +++ b/triton-vm/src/instruction.rs @@ -66,7 +66,7 @@ impl LabelledInstruction { pub const fn op_stack_size_influence(&self) -> i32 { match self { LabelledInstruction::Instruction(instruction) => instruction.op_stack_size_influence(), - LabelledInstruction::Label(_) => 0, + _ => 0, } } } @@ -453,9 +453,7 @@ pub fn convert_all_labels_to_addresses(program: &[LabelledInstruction]) -> Vec HashMap { +pub(crate) fn build_label_to_address_map(program: &[LabelledInstruction]) -> HashMap { use LabelledInstruction::*; let mut label_map = HashMap::new(); @@ -469,7 +467,7 @@ pub(crate) fn build_label_to_address_map( entry.insert(instruction_pointer); } }, - Instruction(instruction) => instruction_pointer += instruction.size(), + Instruction(instruction) => instruction_pointer += instruction.size() as u64, } } label_map @@ -479,20 +477,19 @@ pub(crate) fn build_label_to_address_map( /// address as the call target. Discards all labels. fn convert_label_to_address_for_instruction( labelled_instruction: &LabelledInstruction, - label_map: &HashMap, + label_map: &HashMap, ) -> Option { - match labelled_instruction { - LabelledInstruction::Label(_) => None, - LabelledInstruction::Instruction(instruction) => { - let instruction_with_absolute_address = instruction.map_call_address(|label| { - let &absolute_address = label_map - .get(label) - .unwrap_or_else(|| panic!("Label not found: {label}")); - BFieldElement::new(absolute_address as u64) - }); - Some(instruction_with_absolute_address) - } - } + let LabelledInstruction::Instruction(instruction) = labelled_instruction else { + return None; + }; + + let instruction_with_absolute_address = instruction.map_call_address(|label| { + label_map + .get(label) + .map(|&address| BFieldElement::new(address)) + .unwrap_or_else(|| panic!("Label not found: {label}")) + }); + Some(instruction_with_absolute_address) } const fn all_instructions_without_args() -> [AnInstruction; Instruction::COUNT] { diff --git a/triton-vm/src/program.rs b/triton-vm/src/program.rs index 7fd6ac6e..909f2c98 100644 --- a/triton-vm/src/program.rs +++ b/triton-vm/src/program.rs @@ -342,7 +342,7 @@ impl Program { let mut state = VMState::new(&program, public_input, non_determinism); while !state.halting { if let Instruction::Call(address) = state.current_instruction()? { - let address = address.value() as usize; + let address = address.value(); let label = address_to_label_map[&address].to_owned(); let profile_line = ProfileLine::new(call_stack.len(), label, 0); let profile_line_number = profile.len();