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

feat: program refactor #651

Merged
merged 105 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
dab8375
no alloc in recursion pv
tamirhemo May 1, 2024
c47c464
aligned borrow pv recursion
tamirhemo May 1, 2024
aceb33b
checkpoint
tamirhemo May 1, 2024
3125327
merge main
tamirhemo May 1, 2024
898e178
checkpoint
tamirhemo May 1, 2024
94634c9
hintable
tamirhemo May 1, 2024
af3be6a
checkpoint 2
tamirhemo May 1, 2024
5792d61
checkpoint
tamirhemo May 1, 2024
c8d15db
first shard
tamirhemo May 1, 2024
dd258aa
Merge remote-tracking branch 'origin/main' into tamir/program-refactor
tamirhemo May 1, 2024
0946286
digest format
tamirhemo May 1, 2024
5bf02e5
commit to public values
tamirhemo May 1, 2024
45d0ce2
reconstruct challenger
tamirhemo May 1, 2024
bff1506
map on core leaves
tamirhemo May 1, 2024
323d36a
comment out shard logic for testing
tamirhemo May 1, 2024
e93d12b
test program leaves
tamirhemo May 2, 2024
8b3c225
build and setup
tamirhemo May 2, 2024
cbf9f72
Merge remote-tracking branch 'origin/main' into tamir/program-refactor
tamirhemo May 2, 2024
c49c0d1
test map core
tamirhemo May 2, 2024
0a241ed
tendermint test
tamirhemo May 2, 2024
771cbf0
fix program
tamirhemo May 2, 2024
2c8a1ab
Merge remote-tracking branch 'origin/main' into tamir/program-refactor
tamirhemo May 2, 2024
c8d230a
challenger fix
tamirhemo May 2, 2024
1f0042b
Merge remote-tracking branch 'origin/main' into tamir/program-refactor
tamirhemo May 2, 2024
e4da130
checkpoint
tamirhemo May 2, 2024
91e01d6
checkpoint
tamirhemo May 2, 2024
d518ce2
intermeddiate
tamirhemo May 2, 2024
ab1a69a
Merge remote-tracking branch 'origin/main' into tamir/program-refactor
tamirhemo May 2, 2024
e879907
fix is_complete
tamirhemo May 2, 2024
d15e87d
completeness
tamirhemo May 2, 2024
9b2adfc
completeness assertion
tamirhemo May 2, 2024
b3b315a
try fix challenger
tamirhemo May 2, 2024
fc0b394
fix
tamirhemo May 2, 2024
d135b82
fix challenger assertions
tamirhemo May 2, 2024
251e073
fix challenger assertion
tamirhemo May 2, 2024
1d6774a
cleanuo
tamirhemo May 2, 2024
d5be08e
cleanup
tamirhemo May 2, 2024
2dfbb8e
initialize values to zero
tamirhemo May 2, 2024
f348a04
checkpoint
tamirhemo May 3, 2024
335e0c0
refactor completeness assertions
tamirhemo May 3, 2024
b51948c
reduce program
tamirhemo May 3, 2024
3346faf
hinting sp1_reduce_variables
tamirhemo May 3, 2024
e6f5a74
fmt
tamirhemo May 3, 2024
e971427
Merge remote-tracking branch 'origin/main' into tamir/program-refactor
tamirhemo May 3, 2024
e91b017
checkpoint
tamirhemo May 3, 2024
b1fe8f7
checkpoint
tamirhemo May 3, 2024
794560a
reduce tests
tamirhemo May 3, 2024
60fb4bd
is complete
tamirhemo May 3, 2024
2d64a43
reduce test
tamirhemo May 3, 2024
c5c1c59
fix machine
tamirhemo May 3, 2024
1c09e08
try machine
tamirhemo May 3, 2024
17c25bb
bug fix
tamirhemo May 3, 2024
3d4b9e9
fix tendermint test
tamirhemo May 3, 2024
95f0cac
tendermint passes
May 3, 2024
7116564
simplify
May 3, 2024
0ae1922
merge main
May 3, 2024
ce94262
some cleanup
tamirhemo May 3, 2024
0373f33
cleanup and refs
tamirhemo May 3, 2024
25272a5
root
tamirhemo May 3, 2024
99c5421
Merge remote-tracking branch 'origin/main' into tamir/program-refactor
tamirhemo May 3, 2024
096607b
checkpoint
tamirhemo May 3, 2024
fcb82ea
checkpoint
tamirhemo May 4, 2024
4745d17
compress test
tamirhemo May 4, 2024
adde13e
degree 9 machine
tamirhemo May 5, 2024
f2c7c0a
fix is_complete assertion
tamirhemo May 5, 2024
db2acb4
fix
tamirhemo May 5, 2024
23fc8f1
fix
May 5, 2024
6da70b3
compress degree 9
tamirhemo May 5, 2024
453d81e
wrap test
tamirhemo May 5, 2024
8471b86
checkpoint
tamirhemo May 5, 2024
6ad5b3a
rm print statements
tamirhemo May 5, 2024
16204e6
build programs before proving
tamirhemo May 5, 2024
2fbf97d
deferred verifier
tamirhemo May 5, 2024
9e84ab2
checkpoint
tamirhemo May 5, 2024
f24a2b9
refactor v1
tamirhemo May 5, 2024
586c48d
deferred part 1
tamirhemo May 5, 2024
e2b21c3
boom
tamirhemo May 5, 2024
92d5a17
cleanup
tamirhemo May 5, 2024
5ce6f0b
main
tamirhemo May 6, 2024
932a4aa
merge main
tamirhemo May 6, 2024
a98cb6d
commit directly
tamirhemo May 6, 2024
cf88718
features
tamirhemo May 6, 2024
6b820df
bug
tamirhemo May 6, 2024
f124c61
name
tamirhemo May 6, 2024
8754863
fib test
tamirhemo May 6, 2024
d7109f9
cleanup init
tamirhemo May 6, 2024
01408c2
merge main
tamirhemo May 6, 2024
1d94161
machine verifier
tamirhemo May 7, 2024
4d47e9d
cleanup
tamirhemo May 7, 2024
6726ab2
Merge remote-tracking branch 'origin/main' into tamir/program-refactor
tamirhemo May 7, 2024
69d1f66
Merge remote-tracking branch 'origin/main' into tamir/program-refactor
tamirhemo May 7, 2024
5b2cecf
renaming in tracing
tamirhemo May 7, 2024
f63e52f
wrap machine
tamirhemo May 7, 2024
202c718
clean
tamirhemo May 7, 2024
f208634
rename
tamirhemo May 7, 2024
7468dc5
cleanup
tamirhemo May 7, 2024
2565d19
clippy
tamirhemo May 7, 2024
2367345
compress flag
tamirhemo May 7, 2024
0088012
cleanup verifier in prover
tamirhemo May 7, 2024
f32c9a2
merged main
kevjue May 9, 2024
047b3ac
compiles
kevjue May 9, 2024
f1fe24c
e2e test changes
kevjue May 9, 2024
fd764d6
fixed lint errors
kevjue May 9, 2024
464d890
increased program fixed siz
kevjue May 9, 2024
c0b139a
next power of 2 padding for program
kevjue May 10, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/src/stark/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ impl<SC: StarkGenericConfig, A: MachineAir<Val<SC>>> Verifier<SC, A> {

let pcs = config.pcs();

assert_eq!(chips.len(), opened_values.chips.len());

let log_degrees = opened_values
.chips
.iter()
Expand Down
107 changes: 107 additions & 0 deletions prover/scripts/e2e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

use std::borrow::Borrow;

use clap::Parser;
use p3_baby_bear::BabyBear;
use sp1_core::io::SP1Stdin;
use sp1_prover::utils::{babybear_bytes_to_bn254, babybears_to_bn254, words_to_bytes};
use sp1_prover::SP1Prover;
use sp1_recursion_circuit::stark::build_wrap_circuit;
use sp1_recursion_circuit::witness::Witnessable;
use sp1_recursion_compiler::ir::Witness;
use sp1_recursion_core::air::RecursionPublicValues;
use sp1_recursion_gnark_ffi::{convert, verify, Groth16Prover};
use subtle_encoding::hex;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
#[clap(short, long)]
build_dir: String,
}

pub fn main() {
sp1_core::utils::setup_logger();
std::env::set_var("RECONSTRUCT_COMMITMENTS", "false");

let args = Args::parse();

let elf = include_bytes!("../../tests/fibonacci/elf/riscv32im-succinct-zkvm-elf");

tracing::info!("initializing prover");
let prover = SP1Prover::new();

tracing::info!("setup elf");
let (pk, vk) = prover.setup(elf);

tracing::info!("prove core");
let stdin = SP1Stdin::new();
let core_proof = prover.prove_core(&pk, &stdin);

tracing::info!("Compress");
let reduced_proof = prover.compress(&vk, core_proof, vec![]);

tracing::info!("Shrink");
let compressed_proof = prover.shrink(reduced_proof);

tracing::info!("wrap");
let wrapped_proof = prover.wrap_bn254(compressed_proof);

tracing::info!("building verifier constraints");
let constraints = tracing::info_span!("wrap circuit")
.in_scope(|| build_wrap_circuit(&prover.wrap_vk, wrapped_proof.clone()));

tracing::info!("building template witness");
let pv: &RecursionPublicValues<_> = wrapped_proof.public_values.as_slice().borrow();
let vkey_hash = babybears_to_bn254(&pv.sp1_vk_digest);
let committed_values_digest_bytes: [BabyBear; 32] = words_to_bytes(&pv.committed_value_digest)
.try_into()
.unwrap();
let committed_values_digest = babybear_bytes_to_bn254(&committed_values_digest_bytes);

let mut witness = Witness::default();
wrapped_proof.write(&mut witness);
witness.write_commited_values_digest(committed_values_digest);
witness.write_vkey_hash(vkey_hash);

tracing::info!("sanity check gnark test");
Groth16Prover::test(constraints.clone(), witness.clone());

tracing::info!("sanity check gnark build");
Groth16Prover::build(
constraints.clone(),
witness.clone(),
args.build_dir.clone().into(),
);

tracing::info!("sanity check gnark prove");
let groth16_prover = Groth16Prover::new(args.build_dir.clone().into());

tracing::info!("gnark prove");
let proof = groth16_prover.prove(witness.clone());

tracing::info!("verify gnark proof");
let verified = verify(proof.clone(), &args.build_dir.clone().into());
assert!(verified);

tracing::info!("convert gnark proof");
let solidity_proof = convert(proof.clone(), &args.build_dir.clone().into());

// tracing::info!("sanity check plonk bn254 build");
// PlonkBn254Prover::build(
// constraints.clone(),
// witness.clone(),
// args.build_dir.clone().into(),
// );

// tracing::info!("sanity check plonk bn254 prove");
// let proof = PlonkBn254Prover::prove(witness.clone(), args.build_dir.clone().into());

println!(
"{:?}",
String::from_utf8(hex::encode(proof.encoded_proof)).unwrap()
);
println!("solidity proof: {:?}", solidity_proof);
}
7 changes: 4 additions & 3 deletions prover/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Borrow;
use std::path::PathBuf;

use p3_baby_bear::BabyBear;
Expand Down Expand Up @@ -44,7 +45,7 @@ pub fn build_constraints_and_witness(
let constraints = tracing::info_span!("wrap circuit")
.in_scope(|| build_wrap_circuit(template_vk, template_proof.clone()));

let pv = RecursionPublicValues::from_vec(template_proof.public_values.clone());
let pv: &RecursionPublicValues<BabyBear> = template_proof.public_values.as_slice().borrow();
let vkey_hash = babybears_to_bn254(&pv.sp1_vk_digest);
let committed_values_digest_bytes: [BabyBear; 32] = words_to_bytes(&pv.committed_value_digest)
.try_into()
Expand Down Expand Up @@ -80,10 +81,10 @@ pub fn dummy_proof() -> (StarkVerifyingKey<OuterSC>, ShardProof<OuterSC>) {
let compressed_proof = prover.compress(&vk, core_proof, vec![]);

tracing::info!("shrink");
let shrink_proof = prover.shrink(&vk, compressed_proof);
let shrink_proof = prover.shrink(compressed_proof);

tracing::info!("wrap");
let wrapped_proof = prover.wrap_bn254(&vk, shrink_proof);
let wrapped_proof = prover.wrap_bn254(shrink_proof);

(prover.wrap_vk, wrapped_proof.proof)
}
Expand Down
Loading
Loading