diff --git a/Cargo.toml b/Cargo.toml index f38351e8d..e35cb0fa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ rayon = "1.8" serde = { version = "1", features = ["derive"] } serde_derive = "1" serde_json = "1.0" -strum = { version = "0.25", features = ["derive"] } +strum = { version = "0.26", features = ["derive"] } syn = "2.0" test-strategy = "0.3.1" thiserror = "1.0" diff --git a/triton-tui/Cargo.toml b/triton-tui/Cargo.toml index 5324c93ef..61bee6bc9 100644 --- a/triton-tui/Cargo.toml +++ b/triton-tui/Cargo.toml @@ -40,7 +40,7 @@ tokio-util = "0.7" tracing = "0.1" tracing-error = "0.2" tracing-subscriber = { version = "0.3", features = ["env-filter", "serde"] } -triton-vm = "0.36" +triton-vm = { git = "https://github.com/TritonVM/triton-vm.git", rev = "ce8a6d3e" } tui-textarea = "0.4" [dev-dependencies] diff --git a/triton-tui/src/action.rs b/triton-tui/src/action.rs index 2be83cf68..d27d537fb 100644 --- a/triton-tui/src/action.rs +++ b/triton-tui/src/action.rs @@ -4,10 +4,9 @@ use arbitrary::Arbitrary; use itertools::Itertools; use serde::de::*; use serde::*; - use triton_vm::instruction::Instruction; use triton_vm::op_stack::NUM_OP_STACK_REGISTERS; -use triton_vm::BFieldElement; +use triton_vm::prelude::*; use crate::mode::Mode; diff --git a/triton-tui/src/components/home.rs b/triton-tui/src/components/home.rs index f07779c4d..19b592bfc 100644 --- a/triton-tui/src/components/home.rs +++ b/triton-tui/src/components/home.rs @@ -4,9 +4,8 @@ use itertools::Itertools; use ratatui::prelude::*; use ratatui::widgets::block::*; use ratatui::widgets::*; -use strum::EnumCount; use triton_vm::instruction::*; -use triton_vm::op_stack::OpStackElement; +use triton_vm::op_stack::NUM_OP_STACK_REGISTERS; use crate::action::*; use crate::element_type_hint::ElementTypeHint; @@ -136,11 +135,23 @@ impl Home { let stack_size = op_stack.len(); let title = format!(" Stack (size: {stack_size:>4}) "); let title = Title::from(title).alignment(Alignment::Left); - let num_padding_lines = (render_area.height as usize).saturating_sub(stack_size + 3); + + let border_set = symbols::border::Set { + bottom_left: symbols::line::ROUNDED.vertical_right, + ..symbols::border::ROUNDED + }; + let block = Block::default() + .padding(Padding::new(1, 1, 1, 0)) + .borders(Borders::TOP | Borders::LEFT | Borders::BOTTOM) + .border_set(border_set) + .title(title); + + let num_available_lines = block.inner(render_area).height as usize; + let num_padding_lines = num_available_lines.saturating_sub(stack_size); let mut text = vec![Line::from(""); num_padding_lines]; for (i, st) in op_stack.iter().rev().enumerate() { let stack_index_style = match i { - i if i < OpStackElement::COUNT => Style::new().bold(), + i if i < NUM_OP_STACK_REGISTERS => Style::new().bold(), _ => Style::new().dim(), }; let stack_index = Span::from(format!("{i:>3}")).set_style(stack_index_style); @@ -149,16 +160,6 @@ impl Home { let line = Line::from(vec![stack_index, separator, stack_element]); text.push(line); } - - let border_set = symbols::border::Set { - bottom_left: symbols::line::ROUNDED.vertical_right, - ..symbols::border::ROUNDED - }; - let block = Block::default() - .padding(Padding::new(1, 1, 1, 0)) - .borders(Borders::TOP | Borders::LEFT | Borders::BOTTOM) - .border_set(border_set) - .title(title); let paragraph = Paragraph::new(text).block(block).alignment(Alignment::Left); frame.render_widget(paragraph, render_area); } @@ -167,15 +168,19 @@ impl Home { if !self.show_type_hints { return; } + let block = Block::default() + .padding(Padding::new(0, 1, 1, 0)) + .borders(Borders::TOP | Borders::BOTTOM); let render_area = render_info.areas.type_hint; let type_hints = &render_info.state.type_hints.stack; + let num_available_lines = block.inner(render_area).height as usize; + let num_padding_lines = num_available_lines.saturating_sub(type_hints.len()); + let mut text = vec![Line::from(""); num_padding_lines]; + let highest_hint = type_hints.last().cloned().flatten(); let lowest_hint = type_hints.first().cloned().flatten(); - let num_padding_lines = (render_area.height as usize).saturating_sub(type_hints.len() + 3); - let mut text = vec![Line::from(""); num_padding_lines]; - text.push(ElementTypeHint::render(&highest_hint).into()); for (hint_0, hint_1, hint_2) in type_hints.iter().rev().tuple_windows() { if ElementTypeHint::is_continuous_sequence(&[hint_0, hint_1, hint_2]) { @@ -186,9 +191,6 @@ impl Home { } text.push(ElementTypeHint::render(&lowest_hint).into()); - let block = Block::default() - .padding(Padding::new(0, 1, 1, 0)) - .borders(Borders::TOP | Borders::BOTTOM); let paragraph = Paragraph::new(text).block(block).alignment(Alignment::Left); frame.render_widget(paragraph, render_area); } @@ -272,14 +274,27 @@ impl Home { let state = &render_info.state; let jump_stack = &state.vm_state.jump_stack; - let render_area = render_info.areas.call_stack; let jump_stack_depth = jump_stack.len(); let title = format!(" Calls (depth: {jump_stack_depth:>3}) "); let title = Title::from(title).alignment(Alignment::Left); - let num_padding_lines = (render_area.height as usize).saturating_sub(jump_stack_depth + 3); + let border_set = symbols::border::Set { + top_left: symbols::line::ROUNDED.horizontal_down, + bottom_left: symbols::line::ROUNDED.horizontal_up, + ..symbols::border::ROUNDED + }; + let block = Block::default() + .padding(Padding::new(1, 1, 1, 0)) + .title(title) + .borders(Borders::TOP | Borders::LEFT | Borders::BOTTOM) + .border_set(border_set); + let render_area = render_info.areas.call_stack; + + let num_available_lines = block.inner(render_area).height as usize; + let num_padding_lines = num_available_lines.saturating_sub(jump_stack_depth); let mut text = vec![Line::from(""); num_padding_lines]; + let address_width = self.address_render_width(state); for (return_address, call_address) in jump_stack.iter().rev() { let return_address = return_address.value(); @@ -292,17 +307,6 @@ impl Home { let line = Line::from(vec![addresses, separator, label]); text.push(line); } - - let border_set = symbols::border::Set { - top_left: symbols::line::ROUNDED.horizontal_down, - bottom_left: symbols::line::ROUNDED.horizontal_up, - ..symbols::border::ROUNDED - }; - let block = Block::default() - .padding(Padding::new(1, 1, 1, 0)) - .title(title) - .borders(Borders::TOP | Borders::LEFT | Borders::BOTTOM) - .border_set(border_set); let paragraph = Paragraph::new(text).block(block).alignment(Alignment::Left); frame.render_widget(paragraph, render_area); } @@ -523,8 +527,7 @@ mod tests { use proptest_arbitrary_interop::arb; use ratatui::backend::TestBackend; use test_strategy::proptest; - use triton_vm::vm::VMState; - use triton_vm::Program; + use triton_vm::prelude::*; use super::*; diff --git a/triton-tui/src/components/memory.rs b/triton-tui/src/components/memory.rs index 1b889b19f..f4ec247a6 100644 --- a/triton-tui/src/components/memory.rs +++ b/triton-tui/src/components/memory.rs @@ -7,7 +7,7 @@ use ratatui::prelude::*; use ratatui::widgets::*; use ratatui::Frame; use triton_vm::instruction::Instruction; -use triton_vm::BFieldElement; +use triton_vm::prelude::*; use tui_textarea::TextArea; use crate::action::Action; @@ -316,13 +316,11 @@ mod tests { use proptest_arbitrary_interop::arb; use ratatui::backend::TestBackend; use test_strategy::proptest; - use triton_vm::vm::VMState; - use triton_vm::BFieldElement; - use triton_vm::Program; + use triton_vm::prelude::*; use super::*; - /// Since `TextArea` is not `Arbitrary`, we need to implement `Arbitrary` for `Memory` manually. + /// Since `TextArea` is not `Arbitrary`, implement `Arbitrary` for `Memory` manually. #[derive(Debug, Clone, test_strategy::Arbitrary)] struct ArbitraryMemory { #[strategy(arb())] diff --git a/triton-tui/src/shadow_memory.rs b/triton-tui/src/shadow_memory.rs index 1b1ca46f7..38fde0c25 100644 --- a/triton-tui/src/shadow_memory.rs +++ b/triton-tui/src/shadow_memory.rs @@ -4,12 +4,10 @@ use std::iter::once; use color_eyre::eyre::bail; use color_eyre::eyre::Result; use itertools::Itertools; - use triton_vm::instruction::*; use triton_vm::op_stack::NumberOfWords::*; use triton_vm::op_stack::*; -use triton_vm::vm::VMState; -use triton_vm::BFieldElement; +use triton_vm::prelude::*; use crate::action::ExecutedInstruction; use crate::element_type_hint::ElementTypeHint; @@ -43,7 +41,7 @@ impl ShadowMemory { } fn initial_program_digest_type_hint() -> TypeHint { - let digest_length = triton_vm::Digest::default().0.len(); + let digest_length = tip5::DIGEST_LENGTH; TypeHint { type_name: Some("Digest".to_string()), variable_name: "program_digest".to_string(), @@ -209,7 +207,7 @@ impl ShadowMemory { type_name: Some("Digest".to_string()), variable_name: format!("{}_hash", hash_type_hint.variable_name), starting_index: 0, - length: triton_vm::Digest::default().0.len(), + length: Digest::default().0.len(), }; self.apply_type_hint(type_hint).unwrap(); } diff --git a/triton-tui/src/triton_vm_state.rs b/triton-tui/src/triton_vm_state.rs index 278265531..36f7c8975 100644 --- a/triton-tui/src/triton_vm_state.rs +++ b/triton-tui/src/triton_vm_state.rs @@ -8,12 +8,10 @@ use tokio::sync::mpsc::UnboundedSender; use tracing::error; use tracing::info; use tracing::warn; - use triton_vm::error::InstructionError; use triton_vm::instruction::*; use triton_vm::op_stack::NUM_OP_STACK_REGISTERS; -use triton_vm::vm::VMState; -use triton_vm::*; +use triton_vm::prelude::*; use crate::action::*; use crate::args::TuiArgs;