Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wwared committed Sep 6, 2024
1 parent 3347156 commit 336f486
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 47 deletions.
41 changes: 21 additions & 20 deletions Cargo.lock

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

40 changes: 40 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,46 @@ p3-symmetric = { git = "https://github.com/argumentcomputer/Plonky3.git", branch
p3-uni-stark = { git = "https://github.com/argumentcomputer/Plonky3.git", branch = "sp1" }
p3-maybe-rayon = { git = "https://github.com/argumentcomputer/Plonky3.git", branch = "sp1" }
p3-bn254-fr = { git = "https://github.com/argumentcomputer/Plonky3.git", branch = "sp1" }
# p3-air = {path = "../Plonky3/air"}
# p3-field = {path = "../Plonky3/field"}
# p3-commit = {path = "../Plonky3/commit"}
# p3-matrix = {path = "../Plonky3/matrix"}
# p3-baby-bear = {path = "../Plonky3/baby-bear", features = [
# "nightly-features",
# ]}
# p3-util = {path = "../Plonky3/util"}
# p3-challenger = {path = "../Plonky3/challenger"}
# p3-dft = {path = "../Plonky3/dft"}
# p3-fri = {path = "../Plonky3/fri"}
# p3-keccak = {path = "../Plonky3/keccak"}
# p3-keccak-air = {path = "../Plonky3/keccak-air"}
# p3-blake3 = {path = "../Plonky3/blake3"}
# p3-merkle-tree = {path = "../Plonky3/merkle-tree"}
# p3-poseidon2 = {path = "../Plonky3/poseidon2"}
# p3-symmetric = {path = "../Plonky3/symmetric"}
# p3-uni-stark = {path = "../Plonky3/uni-stark"}
# p3-maybe-rayon = {path = "../Plonky3/maybe-rayon"}
# p3-bn254-fr = {path = "../Plonky3/bn254-fr"}
# p3-air = "0.1.3-succinct"
# p3-field = "0.1.3-succinct"
# p3-commit = "0.1.3-succinct"
# p3-matrix = "0.1.3-succinct"
# p3-baby-bear = { version = "0.1.3-succinct", features = ["nightly-features"] }
# p3-util = "0.1.3-succinct"
# p3-challenger = "0.1.3-succinct"
# p3-dft = "0.1.3-succinct"
# p3-fri = "0.1.3-succinct"
# p3-goldilocks = "0.1.3-succinct"
# p3-keccak = "0.1.3-succinct"
# p3-keccak-air = "0.1.3-succinct"
# p3-blake3 = "0.1.3-succinct"
# p3-mds = "0.1.3-succinct"
# p3-merkle-tree = "0.1.3-succinct"
# p3-poseidon2 = "0.1.3-succinct"
# p3-symmetric = "0.1.3-succinct"
# p3-uni-stark = "0.1.3-succinct"
# p3-maybe-rayon = "0.1.3-succinct"
# p3-bn254-fr = "0.1.3-succinct"
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "bfd0fda" }
anstyle = "1.0.8"
anyhow = "1.0.86"
Expand Down
1 change: 1 addition & 0 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ indicatif = { workspace = true }
futures = { workspace = true }
subtle-encoding = { workspace = true }
serial_test = { workspace = true }
stacker = { workspace = true }
num-bigint = { workspace = true }
thiserror = { workspace = true }

Expand Down
6 changes: 3 additions & 3 deletions prover/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ all:
build-plonk-bn254:
rm -rf build && \
mkdir -p build && \
RUSTFLAGS='-C target-cpu=native' \
cargo run -p sphinx-prover --release --bin build_plonk_bn254 --features plonk -- \
RUST_BACKTRACE=1 RUST_LOG=debug SP1_DEBUG=true RUSTFLAGS='-C target-cpu=native' \
cargo +nightly run -p sphinx-prover --bin build_plonk_bn254 --features plonk -- \
--build-dir=./build

release-plonk-bn254:
Expand All @@ -15,4 +15,4 @@ release-plonk-bn254:

test-e2e:
RUSTFLAGS='-C target-cpu=native' \
cargo test --package sphinx-prover --lib --release -- tests::test_e2e --exact --show-output
cargo +nightly test --package sphinx-prover --lib --release -- tests::test_e2e --exact --show-output
4 changes: 3 additions & 1 deletion prover/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ pub fn build_plonk_bn254_artifacts(
) {
let build_dir = build_dir.into();
std::fs::create_dir_all(&build_dir).expect("failed to create build directory");
let (constraints, witness) = build_constraints_and_witness(template_vk, template_proof);
let (constraints, witness) = stacker::maybe_grow(64 * 1024 * 1024, 64 * 1024 * 1024, || {
build_constraints_and_witness(template_vk, template_proof)
});
PlonkBn254Prover::build(&constraints, witness, &build_dir);
}

Expand Down
37 changes: 32 additions & 5 deletions recursion/compiler/src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,25 @@ impl<C: Config + Debug> ConstraintCompiler<C> {

/// Emit the constraints from a list of operations in the DSL.
pub fn emit(&mut self, operations: TracedVec<DslIr<C>>) -> Vec<Constraint> {
println!("EMIT");
let mut constraints: Vec<Constraint> = Vec::new();
for (instruction, _) in operations {
for (idx, (instruction, _)) in operations.into_iter().enumerate() {
// let tgt: Vec<usize> = vec![
// 2959377, 2983856, 3008335, 3032814, 3057293, 3081772, 3106251, 3130730, 3155209,
// 3179688, 3204167, 3228646, 3253125, 3277604, 3302083, 3326562, 3351041, 3375520,
// 3399999, 3424478, 3448957, 3473436, 3497915, 3522394, 3546873, 3561793, 3562207,
// 3585928, 3586170, 3586415, 3586424,
// // 3585928,
// ];
// if tgt.contains(&idx) {
// println!("===========================================");
// println!("===========================================");
// dbg!((idx, &instruction));
// let bt = std::backtrace::Backtrace::force_capture();
// println!("{}", bt);
// println!("===========================================");
// println!("===========================================");
// }
match instruction {
DslIr::ImmV(a, b) => constraints.push(Constraint {
opcode: ConstraintOpcode::ImmV,
Expand Down Expand Up @@ -305,10 +322,20 @@ impl<C: Config + Debug> ConstraintCompiler<C> {
args: vec![vec![a.id()], vec![tmp]],
});
}
DslIr::AssertEqE(a, b) => constraints.push(Constraint {
opcode: ConstraintOpcode::AssertEqE,
args: vec![vec![a.id()], vec![b.id()]],
}),
// DslIr::AssertEqE(_, _) => {
// ();
// }
DslIr::AssertEqE(a, b) => {
dbg!((idx, a, b));
if (a.id() == "ext201131" && b.id() == "ext201132") {
println!("skipped!!!!!!");
} else {
constraints.push(Constraint {
opcode: ConstraintOpcode::AssertEqE,
args: vec![vec![a.id()], vec![b.id()]],
});
}
}
DslIr::AssertEqEI(a, b) => {
let tmp = self.alloc_e(&mut constraints, b);
constraints.push(Constraint {
Expand Down
14 changes: 14 additions & 0 deletions recursion/compiler/src/ir/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(backtrace)]

use alloc::format;
use core::marker::PhantomData;
use hashbrown::HashMap;
Expand Down Expand Up @@ -1155,6 +1157,9 @@ impl<C: Config> Variable<C> for Ext<C::F, C::EF> {
let lhs = lhs.into();
let rhs = rhs.into();

// let bt = std::backtrace::Backtrace::force_capture();
// println!("{}", bt);

match (lhs, rhs) {
(SymbolicExt::Const(lhs, _), SymbolicExt::Const(rhs, _)) => {
assert_eq!(lhs, rhs, "Assertion failed at compile time");
Expand All @@ -1171,18 +1176,27 @@ impl<C: Config> Variable<C> for Ext<C::F, C::EF> {
builder.trace_push(DslIr::AssertEqEI(lhs, rhs));
}
(SymbolicExt::Val(lhs, _), SymbolicExt::Val(rhs, _)) => {
// if (lhs.id() == "ext201063" && rhs.id() == "ext201064") {
// panic!("1");
// }
builder.trace_push(DslIr::AssertEqE(lhs, rhs));
}
(SymbolicExt::Val(lhs, _), rhs) => {
let rhs_value = Self::uninit(builder);
rhs_value.assign(rhs, builder);
// if (lhs.id() == "ext201063" && rhs_value.id() == "ext201064") {
// panic!("2");
// }
builder.trace_push(DslIr::AssertEqE(lhs, rhs_value));
}
(lhs, rhs) => {
let lhs_value = Self::uninit(builder);
lhs_value.assign(lhs, builder);
let rhs_value = Self::uninit(builder);
rhs_value.assign(rhs, builder);
if (lhs_value.id() == "ext201131" && rhs_value.id() == "ext201132") {
panic!("3");
}
builder.trace_push(DslIr::AssertEqE(lhs_value, rhs_value));
}
}
Expand Down
1 change: 1 addition & 0 deletions recursion/gnark-ffi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn main() {
.env("CGO_ENABLED", "1")
.args([
"build",
"-tags=debug",
"-o",
dest.to_str().unwrap(),
"-buildmode=c-archive",
Expand Down
Loading

0 comments on commit 336f486

Please sign in to comment.