Skip to content

Commit

Permalink
refactor!: expose public (re-)exports via triton_vm::prelude::*
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Jan 25, 2024
1 parent 5613f19 commit 0bb30d8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ strum = { version = "0.25", features = ["derive"] }
syn = "2.0"
test-strategy = "0.3.1"
thiserror = "1.0"
twenty-first = { git = "https://github.com/Neptune-Crypto/twenty-first", rev = "10afd069" }
twenty-first = { git = "https://github.com/Neptune-Crypto/twenty-first", rev = "a97464b8" }
unicode-width = "0.1"

[workspace.dependencies.cargo-husky]
Expand Down
7 changes: 1 addition & 6 deletions triton-vm/benches/proof_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ use twenty_first::shared_math::bfield_codec::BFieldCodec;

use triton_vm::example_programs::FIBONACCI_SEQUENCE;
use triton_vm::example_programs::VERIFY_SUDOKU;
use triton_vm::program::Program;
use triton_vm::prelude::*;
use triton_vm::proof_stream::ProofStream;
use triton_vm::prove_program;
use triton_vm::stark::Stark;
use triton_vm::stark::StarkHasher;
use triton_vm::triton_program;
use triton_vm::NonDeterminism;
use triton_vm::Proof;
use triton_vm::StarkParameters;

/// Ties together a program and its inputs.
struct ProgramAndInput {
Expand Down
5 changes: 1 addition & 4 deletions triton-vm/benches/prove_fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ use criterion::Criterion;

use triton_vm::aet::AlgebraicExecutionTrace;
use triton_vm::example_programs::FIBONACCI_SEQUENCE;
use triton_vm::prelude::*;
use triton_vm::profiler::Report;
use triton_vm::profiler::TritonProfiler;
use triton_vm::proof::Claim;
use triton_vm::stark::Stark;
use triton_vm::stark::StarkHasher;
use triton_vm::PublicInput;
use triton_vm::StarkParameters;

const FIBONACCI_INDEX: u64 = 100;

Expand Down
29 changes: 9 additions & 20 deletions triton-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
//!
//! ```
//! # use triton_vm::*;
//! # use triton_vm::prelude::*;
//! let factorial_program = triton_program!(
//! read_io 1 // n
//! push 1 // n 1
Expand All @@ -52,7 +53,7 @@
//! recurse
//! );
//! let public_input = [10];
//! let non_determinism = [].into();
//! let non_determinism = NonDeterminism::default();
//!
//! let (parameters, claim, proof) =
//! prove_program(&factorial_program, &public_input, &non_determinism).unwrap();
Expand Down Expand Up @@ -81,6 +82,7 @@
//!
//! ```
//! # use triton_vm::*;
//! # use triton_vm::prelude::*;
//! let sum_of_squares_program = triton_program!(
//! read_io 1 // n
//! call sum_of_squares_secret_in // n sum_1
Expand Down Expand Up @@ -131,7 +133,7 @@
//!
//! ```
//! # use triton_vm::*;
//! # use triton_vm::error::InstructionError;
//! # use triton_vm::prelude::*;
//! let crashing_program = triton_program!(push 2 assert halt);
//! let vm_error = crashing_program.run([].into(), [].into()).unwrap_err();
//! assert!(matches!(vm_error.source, InstructionError::AssertionFailed));
Expand All @@ -144,21 +146,10 @@
#![recursion_limit = "4096"]

pub use twenty_first;
pub use twenty_first::shared_math::b_field_element::BFieldElement;
pub use twenty_first::shared_math::tip5::Digest;
pub use twenty_first::shared_math::tip5::DIGEST_LENGTH;

use crate::error::CanonicalRepresentationError;
use crate::error::ProvingError;
pub use crate::program::NonDeterminism;
pub use crate::program::Program;
pub use crate::program::PublicInput;
pub use crate::proof::Claim;
pub use crate::proof::Proof;
pub use crate::stark::Stark;
use crate::prelude::*;
use crate::stark::StarkHasher;
pub use crate::stark::StarkParameters;

pub mod aet;
pub mod arithmetic_domain;
Expand All @@ -168,6 +159,7 @@ pub mod fri;
pub mod instruction;
pub mod op_stack;
pub mod parser;
pub mod prelude;
pub mod profiler;
pub mod program;
pub mod proof;
Expand Down Expand Up @@ -211,8 +203,7 @@ mod shared_tests;
/// [`Label`](instruction::LabelledInstruction)s, among others.
///
/// ```
/// # use triton_vm::triton_program;
/// # use triton_vm::BFieldElement;
/// # use triton_vm::prelude::*;
/// # use triton_vm::instruction::Instruction;
/// let element_0 = BFieldElement::new(0);
/// let label = "my_label";
Expand Down Expand Up @@ -292,9 +283,7 @@ macro_rules! triton_program {
/// Inserting substring of labelled instructions:
///
/// ```
/// # use triton_vm::BFieldElement;
/// # use triton_vm::triton_asm;
/// # use triton_vm::instruction::LabelledInstruction;
/// # use triton_vm::prelude::*;
/// # use triton_vm::instruction::AnInstruction::Push;
/// # use triton_vm::instruction::AnInstruction::Pop;
/// # use triton_vm::op_stack::NumberOfWords::N1;
Expand Down Expand Up @@ -432,7 +421,7 @@ macro_rules! triton_instr {
$crate::instruction::LabelledInstruction::Instruction(instruction)
}};
(push $arg:expr) => {{
let argument = $crate::BFieldElement::new($arg);
let argument = $crate::prelude::BFieldElement::new($arg);
let instruction = $crate::instruction::AnInstruction::<String>::Push(argument);
$crate::instruction::LabelledInstruction::Instruction(instruction)
}};
Expand Down
25 changes: 25 additions & 0 deletions triton-vm/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Re-exports the most commonly-needed APIs of Triton VM.
//!
//! This module is intended to be wildcard-imported, _i.e._, `use triton_vm::prelude::*;`.
pub use twenty_first;
pub use twenty_first::shared_math::b_field_element::BFieldElement;
pub use twenty_first::shared_math::bfield_codec::BFieldCodec;
pub use twenty_first::shared_math::tip5;
pub use twenty_first::shared_math::tip5::Digest;
pub use twenty_first::shared_math::tip5::Tip5;
pub use twenty_first::shared_math::x_field_element::XFieldElement;

pub use crate::error::InstructionError;
pub use crate::instruction::LabelledInstruction;
pub use crate::program::NonDeterminism;
pub use crate::program::Program;
pub use crate::program::PublicInput;
pub use crate::proof::Claim;
pub use crate::proof::Proof;
pub use crate::stark::Stark;
pub use crate::stark::StarkParameters;
pub use crate::triton_asm;
pub use crate::triton_instr;
pub use crate::triton_program;
pub use crate::vm::VMState;

0 comments on commit 0bb30d8

Please sign in to comment.