Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add lurk shard test #265

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ fail-fast = false
slow-timeout = { period = "300s", terminate-after = 4 }
# Retry failed tests once, marked flaky if test then passes
retries = 1

[test-groups]
limited = { max-threads = 4 }
very-limited = { max-threads = 1 }

[[profile.ci.overrides]]
filter = '(test(_shard_) | test(_e2e))'
test-group = 'very-limited'
4 changes: 2 additions & 2 deletions src/lurk/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,14 @@ pub fn u64_iszero<F>() -> FuncE<F> {
pub fn u64_equal<F: AbstractField>() -> FuncE<F> {
func!(
fn u64_equal(a, b): [1] {
let zero = 0;
let one = 1;
let a: [8] = load(a);
let b: [8] = load(b);
let diff = sub(a, b);
if diff {
let zero = 0;
return zero
}
let one = 1;
return one
}
)
Expand Down
51 changes: 47 additions & 4 deletions tests/fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
use p3_baby_bear::BabyBear;
use p3_field::AbstractField;
use sphinx_core::{
stark::{LocalProver, StarkGenericConfig, StarkMachine},
stark::{LocalProver, MachineRecord, StarkGenericConfig, StarkMachine},
utils::{BabyBearPoseidon2, SphinxCoreOpts},
};
use std::time::Instant;

use loam::{
lair::{
chipset::Chipset,
execute::{QueryRecord, Shard},
execute::{QueryRecord, Shard, ShardingConfig},
func_chip::FuncChip,
lair_chip::{build_chip_vector, LairMachineProgram},
toplevel::Toplevel,
Expand Down Expand Up @@ -87,12 +87,55 @@ fn fib_e2e() {
build_chip_vector(&lurk_main),
record.expect_public_values().len(),
);
let (pk, _) = machine.setup(&LairMachineProgram);
let (pk, vk) = machine.setup(&LairMachineProgram);
let mut challenger_p = machine.config().challenger();
let opts = SphinxCoreOpts::default();
let shard = Shard::new(&record);
machine.prove::<LocalProver<_, _>>(&pk, shard, &mut challenger_p, opts);
let proof = machine.prove::<LocalProver<_, _>>(&pk, shard.clone(), &mut challenger_p, opts);

let elapsed_time = start_time.elapsed().as_secs_f32();
println!("Total time for e2e-{arg} = {:.2} s", elapsed_time);

let mut challenger_v = machine.config().challenger();
machine
.verify(&vk, &proof, &mut challenger_v)
.expect("proof verifies");
}

#[ignore]
#[test]
fn fib_shard_e2e() {
// This is enough for ensuring two shards in the proof by default
let arg = 500000;
let (toplevel, _) = build_lurk_toplevel();
let (args, lurk_main, mut record) = setup(arg, &toplevel);
let start_time = Instant::now();

toplevel
.execute(lurk_main.func(), &args, &mut record, None)
.unwrap();
let config = BabyBearPoseidon2::new();
let machine = StarkMachine::new(
config,
build_chip_vector(&lurk_main),
record.expect_public_values().len(),
);
let (pk, vk) = machine.setup(&LairMachineProgram);
let mut challenger_p = machine.config().challenger();
let opts = SphinxCoreOpts::default();
let shard = Shard::new(&record);
let shards = shard.clone().shard(&ShardingConfig::default());
assert!(
shards.len() > 1,
"lurk_shard_test must have more than one shard"
);
let proof = machine.prove::<LocalProver<_, _>>(&pk, shard.clone(), &mut challenger_p, opts);

let elapsed_time = start_time.elapsed().as_secs_f32();
println!("Total time for e2e-{arg} = {:.2} s", elapsed_time);

let mut challenger_v = machine.config().challenger();
machine
.verify(&vk, &proof, &mut challenger_v)
.expect("proof verifies");
}