-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
// use p3_baby_bear::BabyBear; | ||
// use p3_field::AbstractField; | ||
// use sp1_core::stark::StarkGenericConfig; | ||
// use sp1_core::utils::BabyBearPoseidon2; | ||
// use sp1_recursion_compiler::prelude::*; | ||
// use sp1_recursion_core::runtime::Runtime; | ||
|
||
// #[test] | ||
// fn test_compiler_for_loops() { | ||
// let mut builder = AsmCompiler::<BabyBear>::new(); | ||
|
||
// let n_val = BabyBear::from_canonical_u32(10); | ||
// let m_val = BabyBear::from_canonical_u32(5); | ||
|
||
// let zero: Felt<_> = builder.constant(BabyBear::zero()); | ||
// let n: Felt<_> = builder.constant(n_val); | ||
// let m: Felt<_> = builder.constant(m_val); | ||
|
||
// let i_counter: Felt<_> = builder.constant(BabyBear::zero()); | ||
// let total_counter: Felt<_> = builder.constant(BabyBear::zero()); | ||
// builder.range(zero, n).for_each(|_, builder| { | ||
// builder.assign(i_counter, i_counter + BabyBear::one()); | ||
|
||
// let j_counter: Felt<_> = builder.constant(BabyBear::zero()); | ||
// builder.range(zero, m).for_each(|_, builder| { | ||
// builder.assign(total_counter, total_counter + BabyBear::one()); | ||
// builder.assign(j_counter, j_counter + BabyBear::one()); | ||
// }); | ||
// // Assert that the inner loop ran m times, in two different ways. | ||
// builder.assert_eq(j_counter, m_val); | ||
// builder.assert_eq(j_counter, m); | ||
// }); | ||
// // Assert that the outer loop ran n times, in two different ways. | ||
// builder.assert_eq(i_counter, n_val); | ||
// builder.assert_eq(i_counter, n); | ||
// // Assert that the total counter is equal to n * m, in two ways. | ||
// builder.assert_eq(total_counter, n_val * m_val); | ||
// builder.assert_eq(total_counter, n * m); | ||
|
||
// let program = builder.compile(); | ||
|
||
// type SC = BabyBearPoseidon2; | ||
// type F = <SC as StarkGenericConfig>::Val; | ||
|
||
// let mut runtime = Runtime::<F>::new(&program); | ||
// runtime.run(); | ||
// } | ||
use p3_baby_bear::BabyBear; | ||
use p3_field::AbstractField; | ||
use sp1_core::stark::StarkGenericConfig; | ||
use sp1_core::utils::BabyBearPoseidon2; | ||
use sp1_recursion_compiler::asm::VmBuilder; | ||
use sp1_recursion_compiler::prelude::*; | ||
use sp1_recursion_core::runtime::Runtime; | ||
|
||
#[test] | ||
fn test_compiler_for_loops() { | ||
let mut builder = VmBuilder::<BabyBear>::default(); | ||
|
||
let n_val = BabyBear::from_canonical_u32(10); | ||
let m_val = BabyBear::from_canonical_u32(5); | ||
|
||
let zero: Var<_> = builder.eval(BabyBear::zero()); | ||
let n: Var<_> = builder.eval(n_val); | ||
let m: Var<_> = builder.eval(m_val); | ||
|
||
let i_counter: Var<_> = builder.eval(BabyBear::zero()); | ||
let total_counter: Var<_> = builder.eval(BabyBear::zero()); | ||
builder.range(zero, n).for_each(|_, builder| { | ||
builder.assign(i_counter, i_counter + BabyBear::one()); | ||
|
||
let j_counter: Var<_> = builder.eval(BabyBear::zero()); | ||
builder.range(zero, m).for_each(|_, builder| { | ||
builder.assign(total_counter, total_counter + BabyBear::one()); | ||
builder.assign(j_counter, j_counter + BabyBear::one()); | ||
}); | ||
// Assert that the inner loop ran m times, in two different ways. | ||
builder.assert_var_eq(j_counter, m_val); | ||
builder.assert_var_eq(j_counter, m); | ||
}); | ||
// Assert that the outer loop ran n times, in two different ways. | ||
builder.assert_var_eq(i_counter, n_val); | ||
builder.assert_var_eq(i_counter, n); | ||
// Assert that the total counter is equal to n * m, in two ways. | ||
builder.assert_var_eq(total_counter, n_val * m_val); | ||
builder.assert_var_eq(total_counter, n * m); | ||
|
||
let program = builder.compile(); | ||
|
||
type SC = BabyBearPoseidon2; | ||
type F = <SC as StarkGenericConfig>::Val; | ||
|
||
let mut runtime = Runtime::<F>::new(&program); | ||
runtime.run(); | ||
} |