Skip to content

Commit

Permalink
slightly improve interface for Arithmetic Domain
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Aug 9, 2023
1 parent 21bb1ae commit c9907e2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
20 changes: 9 additions & 11 deletions triton-vm/src/arithmetic_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,8 @@ pub struct ArithmeticDomain {
}

impl ArithmeticDomain {
/// Create a new domain with the given length and offset.
pub fn of_length_with_offset(length: usize, offset: BFieldElement) -> Self {
Self {
offset,
generator: Self::generator_for_length(length as u64),
length,
}
}

/// Create a new domain with the given length. No offset is applied.
/// Create a new domain with the given length.
/// No offset is applied, but can added through [`with_offset()`](Self::with_offset).
pub fn of_length(length: usize) -> Self {
Self {
offset: BFieldElement::one(),
Expand All @@ -34,6 +26,12 @@ impl ArithmeticDomain {
}
}

/// Set the offset of the domain.
pub fn with_offset(mut self, offset: BFieldElement) -> Self {
self.offset = offset;
self
}

/// Derive a generator for a domain of the given length.
/// The domain length must be a power of 2.
pub fn generator_for_length(domain_length: u64) -> BFieldElement {
Expand Down Expand Up @@ -102,7 +100,7 @@ mod domain_tests {
for order in [4, 8, 32] {
let generator = BFieldElement::primitive_root_of_unity(order).unwrap();
let offset = BFieldElement::generator();
let b_domain = ArithmeticDomain::of_length_with_offset(order as usize, offset);
let b_domain = ArithmeticDomain::of_length(order as usize).with_offset(offset);

let expected_b_values: Vec<BFieldElement> =
(0..order).map(|i| offset * generator.mod_pow(i)).collect();
Expand Down
2 changes: 1 addition & 1 deletion triton-vm/src/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<H: AlgebraicHasher> Fri<H> {
expansion_factor: usize,
colinearity_checks_count: usize,
) -> Self {
let domain = ArithmeticDomain::of_length_with_offset(domain_length, offset);
let domain = ArithmeticDomain::of_length(domain_length).with_offset(offset);
let _hasher = PhantomData;
Self {
domain,
Expand Down
2 changes: 1 addition & 1 deletion triton-vm/src/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ impl Stark {
false => 1,
};
let domain_length = maybe_blowup_factor * roundup_npo2(max_degree as u64) as usize;
ArithmeticDomain::of_length_with_offset(domain_length, fri_domain.offset)
ArithmeticDomain::of_length(domain_length).with_offset(fri_domain.offset)
}

/// Compute the upper bound to use for the maximum degree the quotients given the length of the
Expand Down
2 changes: 1 addition & 1 deletion triton-vm/src/table/master_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ mod master_table_tests {
fn zerofiers_are_correct_test() {
let big_order = 16;
let big_offset = BFieldElement::generator();
let big_domain = ArithmeticDomain::of_length_with_offset(big_order as usize, big_offset);
let big_domain = ArithmeticDomain::of_length(big_order as usize).with_offset(big_offset);

let small_order = 8;
let small_domain = ArithmeticDomain::of_length(small_order as usize);
Expand Down

0 comments on commit c9907e2

Please sign in to comment.