diff --git a/Cargo.toml b/Cargo.toml index 59f3aa8cfd..023a595ffb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,7 @@ halo2curves = { version = "0.6.0", features = ["bits", "derive_serde"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] memmap = { version = "0.5.10", package = "memmap2" } -pasta-msm = { workspace = true } +grumpkin-msm = { workspace = true } proptest = { workspace = true } proptest-derive = { workspace = true } rand = "0.8.5" @@ -93,8 +93,9 @@ default = [] opencl = ["neptune/opencl", "nova/opencl"] cuda = ["neptune/cuda", "nova/cuda"] # compile without ISA extensions -portable = ["pasta-msm/portable", "nova/portable"] +portable = ["grumpkin-msm/portable", "nova/portable"] flamegraph = ["pprof/flamegraph", "pprof/criterion"] +preallocate = ["nova/preallocate"] [dev-dependencies] assert_cmd = "2.0.12" @@ -129,12 +130,12 @@ clap = "4.3.17" ff = "0.13" metrics = "0.21.1" neptune = { git = "https://github.com/lurk-lab/neptune", branch = "dev", features = ["abomonation"] } -nova = { git = "https://github.com/lurk-lab/arecibo", branch = "dev", package = "arecibo" } +nova = { git = "https://github.com/lurk-lab/arecibo", branch = "cache-witnesses", package = "arecibo" } once_cell = "1.18.0" pairing = { version = "0.23" } pasta_curves = { git = "https://github.com/lurk-lab/pasta_curves", branch = "dev" } -pasta-msm = { git = "https://github.com/lurk-lab/pasta-msm", branch = "dev" } -grumpkin-msm = { git = "https://github.com/lurk-lab/grumpkin-msm", branch = "dev" } +# pasta-msm = { git = "https://github.com/lurk-lab/pasta-msm", branch = "dev" } +grumpkin-msm = { git = "https://github.com/lurk-lab/grumpkin-msm", branch = "preallocate-msm" } proptest = "1.2.0" proptest-derive = "0.3" rand = "0.8" diff --git a/benches/analysis.md b/benches/analysis.md new file mode 100644 index 0000000000..033ed341c9 --- /dev/null +++ b/benches/analysis.md @@ -0,0 +1,506 @@ +commit witness +zeros: 1753383, scalars: 7941351 +preallocated time: 554.640897ms + +zeros: 4626, scalars: 10337 +preallocated time: 15.656604ms + +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 537.213809ms + +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 110.77414ms + +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 531.170838ms + +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 305.753391ms + +====================================================== + +commit witness +zeros: 1753383, scalars: 7941351 +preallocated time: 552.262088ms +zeros: 4626, scalars: 10337 +preallocated time: 13.171766ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 647.082µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 531.499733ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 110.701757ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 11.141974ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 34.712595ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 537.894677ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 306.710084ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 24.136214ms, scalars: 10337 + +commit witness +zeros: 1753383, scalars: 7941351 +preallocated time: 553.466052ms +zeros: 4626, scalars: 10337 +preallocated time: 13.719035ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 537.144µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 532.191561ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 107.233701ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 13.259707ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 13.014947ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 535.212197ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 326.414325ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 17.846628ms, scalars: 10337 + +commit witness +zeros: 1753383, scalars: 7941351 +preallocated time: 551.893777ms +zeros: 4626, scalars: 10337 +preallocated time: 10.133065ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 527.422µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 526.639577ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 108.346503ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 19.249117ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 31.217796ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 552.974791ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 306.954051ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 10.900701ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 547.146775ms +zeros: 4626, scalars: 10337 +preallocated time: 10.972027ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 477.018µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 535.831212ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 102.295341ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 9.164998ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 9.622795ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 532.395989ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 308.30945ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 30.13831ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 547.873012ms +zeros: 4626, scalars: 10337 +preallocated time: 11.926605ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 737.339µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 527.621874ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 110.785852ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 11.110117ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 10.217758ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 545.130387ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 292.238581ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 8.920837ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 542.420713ms +zeros: 4626, scalars: 10337 +preallocated time: 8.252185ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 791.279µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 532.628355ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 110.47265ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 9.112954ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 9.043526ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 534.666342ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 307.865844ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 11.170338ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 547.190364ms +zeros: 4626, scalars: 10337 +preallocated time: 10.676852ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 679.8µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 525.669625ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 101.719155ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 20.618228ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 11.14338ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 532.392684ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 294.538733ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 12.950479ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 547.256475ms +zeros: 4626, scalars: 10337 +preallocated time: 8.614403ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 1.318005ms, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 526.626976ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 103.100505ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 18.929633ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 7.558563ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 546.034999ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 309.376636ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 9.601227ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 559.779428ms +zeros: 4626, scalars: 10337 +preallocated time: 8.525373ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 884.16µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 532.348227ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 103.450288ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 9.453543ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 13.454527ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 526.638987ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 299.373208ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 13.954433ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 543.976147ms +zeros: 4626, scalars: 10337 +preallocated time: 9.917411ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 364.387µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 529.302474ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 100.981668ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 8.861711ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 9.630107ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 533.489117ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 294.904586ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 11.221538ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 554.002653ms +zeros: 4626, scalars: 10337 +preallocated time: 8.639996ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 1.084154ms, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 532.052199ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 108.69379ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 13.018952ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 7.155583ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 547.25418ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 304.965712ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 14.281396ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 551.848184ms +zeros: 4626, scalars: 10337 +preallocated time: 9.402069ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 1.173167ms, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 535.063997ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 102.983597ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 9.903441ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 10.078324ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 534.381464ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 296.718115ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 12.308884ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 545.558422ms +zeros: 4626, scalars: 10337 +preallocated time: 11.910673ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 490.473µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 529.961081ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 102.287863ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 8.928636ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 9.449481ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 536.95697ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 317.174853ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 15.31332ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 551.083934ms +zeros: 4626, scalars: 10337 +preallocated time: 12.905685ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 1.044175ms, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 532.500644ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 102.265975ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 9.047787ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 10.318061ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 533.644946ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 295.237962ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 18.177865ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 546.220056ms +zeros: 4626, scalars: 10337 +preallocated time: 10.190864ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 434.365µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 535.792618ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 104.581246ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 9.287871ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 8.826614ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 549.69789ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 309.221815ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 19.676354ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 550.937326ms +zeros: 4626, scalars: 10337 +preallocated time: 12.688268ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 694.546µs, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 537.418385ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 104.443619ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 13.931047ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 10.113483ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 548.013126ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 296.356046ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 7.791162ms, scalars: 10337 +zeros: 1753383, scalars: 7941351 +preallocated time: 556.718518ms +zeros: 4626, scalars: 10337 +preallocated time: 15.707729ms +commit T +zeros: 10357, scalars: 10357 +preallocated time: 1.090265ms, scalars: 10357 +commit witness +zeros: 1757881, scalars: 7941351 +preallocated time: 531.11216ms, scalars: 7941351 +commit T +zeros: 6752860, scalars: 9699051 +preallocated time: 104.643477ms, scalars: 9699051 +commit witness +zeros: 3440, scalars: 10337 +preallocated time: 15.47811ms, scalars: 10337 +commit T +zeros: 4321, scalars: 10357 +preallocated time: 9.693771ms, scalars: 10357 +commit witness +zeros: 1757207, scalars: 7941351 +preallocated time: 532.136405ms, scalars: 7941351 +commit T +zeros: 5966166, scalars: 9699051 +preallocated time: 312.006991ms, scalars: 9699051 +commit witness +zeros: 3426, scalars: 10337 +preallocated time: 9.123387ms, scalars: 10337 diff --git a/benches/fibonacci.rs b/benches/fibonacci.rs index 9eee2d4125..79458b5954 100644 --- a/benches/fibonacci.rs +++ b/benches/fibonacci.rs @@ -120,6 +120,7 @@ fn fibonacci_prove( b.iter_batched( || frames, |frames| { + eprintln!("\n=======================================\n"); let result = prover.prove(&pp, frames, &store); let _ = black_box(result); }, @@ -141,7 +142,7 @@ fn fibonacci_benchmark(c: &mut Criterion) { tracing::debug!("{:?}", lurk::config::LURK_CONFIG); let reduction_counts = rc_env().unwrap_or_else(|_| vec![100]); - let batch_sizes = [100, 200]; + let batch_sizes = [500]; for reduction_count in reduction_counts.iter() { let mut group: BenchmarkGroup<'_, _> = diff --git a/benches/stderr.log b/benches/stderr.log new file mode 100644 index 0000000000..3e28e6d31e --- /dev/null +++ b/benches/stderr.log @@ -0,0 +1,208 @@ + Blocking waiting for file lock on package cache + Blocking waiting for file lock on package cache + Blocking waiting for file lock on package cache + Compiling arecibo v0.2.0 (https://github.com/lurk-lab/arecibo?branch=preallocate-msm#6876c069) + Compiling lurk v0.3.1 (/home/paperspace/lurk-lab/lurk-rs) + Finished bench [optimized] target(s) in 1m 26s +Gnuplot not found, using plotters backend +Benchmarking LEM Fibonacci Prove - rc = 900/fib/num-500-cc9de142be3f4829d09c4e27771207965eef9a79-2024-01-11 +Benchmarking LEM Fibonacci Prove - rc = 900/fib/num-500-cc9de142be3f4829d09c4e27771207965eef9a79-2024-01-11: Warming up for 3.0000 s + +======================================= + +zeros, scalars, time: 1753383, 7941351, 847.267975ms +zeros, scalars, time: 4626, 10337, 18.9483ms +commit T: zeros, scalars, time: 10357, 10357, 505.101µs +zeros, scalars, time: 1757881, 7941351, 548.476278ms +commit T: zeros, scalars, time: 6752860, 9699051, 159.193017ms +zeros, scalars, time: 3440, 10337, 13.257333ms +commit T: zeros, scalars, time: 4321, 10357, 11.43605ms +zeros, scalars, time: 1757207, 7941351, 554.064449ms +commit T: zeros, scalars, time: 5966166, 9699051, 329.453026ms +zeros, scalars, time: 3426, 10337, 12.656345ms +commit T: zeros, scalars, time: 3212, 10357, 15.037615ms +zeros, scalars, time: 1757312, 7941351, 552.643811ms +commit T: zeros, scalars, time: 5341906, 9699051, 366.211021ms +zeros, scalars, time: 3445, 10337, 13.096732ms + +Warning: Unable to complete 10 samples in 120.0s. You may wish to increase target time to 133.4s. +Benchmarking LEM Fibonacci Prove - rc = 900/fib/num-500-cc9de142be3f4829d09c4e27771207965eef9a79-2024-01-11: Collecting 10 samples in estimated 133.43 s (10 iterations) + +======================================= + +zeros, scalars, time: 1753383, 7941351, 559.733825ms +zeros, scalars, time: 4626, 10337, 9.158439ms +commit T: zeros, scalars, time: 10357, 10357, 527.173µs +zeros, scalars, time: 1757881, 7941351, 552.398933ms +commit T: zeros, scalars, time: 6752860, 9699051, 151.258935ms +zeros, scalars, time: 3440, 10337, 11.264345ms +commit T: zeros, scalars, time: 4321, 10357, 16.699649ms +zeros, scalars, time: 1757207, 7941351, 555.784256ms +commit T: zeros, scalars, time: 5966166, 9699051, 341.349577ms +zeros, scalars, time: 3426, 10337, 22.523756ms +commit T: zeros, scalars, time: 3212, 10357, 12.282814ms +zeros, scalars, time: 1757312, 7941351, 556.916798ms +commit T: zeros, scalars, time: 5341906, 9699051, 356.455873ms +zeros, scalars, time: 3445, 10337, 14.381925ms + +======================================= + +zeros, scalars, time: 1753383, 7941351, 559.482651ms +zeros, scalars, time: 4626, 10337, 8.33881ms +commit T: zeros, scalars, time: 10357, 10357, 511.954µs +zeros, scalars, time: 1757881, 7941351, 556.780422ms +commit T: zeros, scalars, time: 6752860, 9699051, 156.812372ms +zeros, scalars, time: 3440, 10337, 16.870737ms +commit T: zeros, scalars, time: 4321, 10357, 10.731183ms +zeros, scalars, time: 1757207, 7941351, 542.007872ms +commit T: zeros, scalars, time: 5966166, 9699051, 335.988562ms +zeros, scalars, time: 3426, 10337, 7.690977ms +commit T: zeros, scalars, time: 3212, 10357, 16.840075ms +zeros, scalars, time: 1757312, 7941351, 550.016943ms +commit T: zeros, scalars, time: 5341906, 9699051, 356.570987ms +zeros, scalars, time: 3445, 10337, 11.335363ms + +======================================= + +zeros, scalars, time: 1753383, 7941351, 546.645273ms +zeros, scalars, time: 4626, 10337, 16.397215ms +commit T: zeros, scalars, time: 10357, 10357, 645.827µs +zeros, scalars, time: 1757881, 7941351, 554.671033ms +commit T: zeros, scalars, time: 6752860, 9699051, 148.005848ms +zeros, scalars, time: 3440, 10337, 11.370989ms +commit T: zeros, scalars, time: 4321, 10357, 9.323651ms +zeros, scalars, time: 1757207, 7941351, 547.293595ms +commit T: zeros, scalars, time: 5966166, 9699051, 344.175223ms +zeros, scalars, time: 3426, 10337, 14.81722ms +commit T: zeros, scalars, time: 3212, 10357, 9.651791ms +zeros, scalars, time: 1757312, 7941351, 546.401347ms +commit T: zeros, scalars, time: 5341906, 9699051, 343.450722ms +zeros, scalars, time: 3445, 10337, 11.25213ms + +======================================= + +zeros, scalars, time: 1753383, 7941351, 544.661655ms +zeros, scalars, time: 4626, 10337, 11.541149ms +commit T: zeros, scalars, time: 10357, 10357, 688.291µs +zeros, scalars, time: 1757881, 7941351, 543.333908ms +commit T: zeros, scalars, time: 6752860, 9699051, 161.214169ms +zeros, scalars, time: 3440, 10337, 14.271439ms +commit T: zeros, scalars, time: 4321, 10357, 9.727561ms +zeros, scalars, time: 1757207, 7941351, 550.146788ms +commit T: zeros, scalars, time: 5966166, 9699051, 323.54532ms +zeros, scalars, time: 3426, 10337, 27.002386ms +commit T: zeros, scalars, time: 3212, 10357, 13.820435ms +zeros, scalars, time: 1757312, 7941351, 544.117215ms +commit T: zeros, scalars, time: 5341906, 9699051, 356.109591ms +zeros, scalars, time: 3445, 10337, 9.279578ms + +======================================= + +zeros, scalars, time: 1753383, 7941351, 558.446133ms +zeros, scalars, time: 4626, 10337, 12.357464ms +commit T: zeros, scalars, time: 10357, 10357, 1.322616ms +zeros, scalars, time: 1757881, 7941351, 548.780802ms +commit T: zeros, scalars, time: 6752860, 9699051, 150.386332ms +zeros, scalars, time: 3440, 10337, 9.07248ms +commit T: zeros, scalars, time: 4321, 10357, 7.780242ms +zeros, scalars, time: 1757207, 7941351, 559.290401ms +commit T: zeros, scalars, time: 5966166, 9699051, 317.419659ms +zeros, scalars, time: 3426, 10337, 8.984643ms +commit T: zeros, scalars, time: 3212, 10357, 14.446419ms +zeros, scalars, time: 1757312, 7941351, 545.47734ms +commit T: zeros, scalars, time: 5341906, 9699051, 341.77525ms +zeros, scalars, time: 3445, 10337, 27.513862ms + +======================================= + +zeros, scalars, time: 1753383, 7941351, 551.266476ms +zeros, scalars, time: 4626, 10337, 20.828792ms +commit T: zeros, scalars, time: 10357, 10357, 526.157µs +zeros, scalars, time: 1757881, 7941351, 544.676505ms +commit T: zeros, scalars, time: 6752860, 9699051, 148.925532ms +zeros, scalars, time: 3440, 10337, 15.76487ms +commit T: zeros, scalars, time: 4321, 10357, 10.00217ms +zeros, scalars, time: 1757207, 7941351, 547.212751ms +commit T: zeros, scalars, time: 5966166, 9699051, 332.192887ms +zeros, scalars, time: 3426, 10337, 18.542847ms +commit T: zeros, scalars, time: 3212, 10357, 10.399446ms +zeros, scalars, time: 1757312, 7941351, 549.220526ms +commit T: zeros, scalars, time: 5341906, 9699051, 344.96839ms +zeros, scalars, time: 3445, 10337, 8.422461ms + +======================================= + +zeros, scalars, time: 1753383, 7941351, 553.025686ms +zeros, scalars, time: 4626, 10337, 8.019595ms +commit T: zeros, scalars, time: 10357, 10357, 407.011µs +zeros, scalars, time: 1757881, 7941351, 546.494072ms +commit T: zeros, scalars, time: 6752860, 9699051, 150.078863ms +zeros, scalars, time: 3440, 10337, 8.715238ms +commit T: zeros, scalars, time: 4321, 10357, 13.39994ms +zeros, scalars, time: 1757207, 7941351, 562.275316ms +commit T: zeros, scalars, time: 5966166, 9699051, 331.559419ms +zeros, scalars, time: 3426, 10337, 11.71239ms +commit T: zeros, scalars, time: 3212, 10357, 9.708633ms +zeros, scalars, time: 1757312, 7941351, 548.473271ms +commit T: zeros, scalars, time: 5341906, 9699051, 344.412262ms +zeros, scalars, time: 3445, 10337, 17.173492ms + +======================================= + +zeros, scalars, time: 1753383, 7941351, 559.244907ms +zeros, scalars, time: 4626, 10337, 21.367655ms +commit T: zeros, scalars, time: 10357, 10357, 1.383944ms +zeros, scalars, time: 1757881, 7941351, 548.028159ms +commit T: zeros, scalars, time: 6752860, 9699051, 155.876229ms +zeros, scalars, time: 3440, 10337, 15.385934ms +commit T: zeros, scalars, time: 4321, 10357, 9.65398ms +zeros, scalars, time: 1757207, 7941351, 551.845287ms +commit T: zeros, scalars, time: 5966166, 9699051, 324.000783ms +zeros, scalars, time: 3426, 10337, 10.05272ms +commit T: zeros, scalars, time: 3212, 10357, 12.700196ms +zeros, scalars, time: 1757312, 7941351, 551.272907ms +commit T: zeros, scalars, time: 5341906, 9699051, 354.742771ms +zeros, scalars, time: 3445, 10337, 20.844368ms + +======================================= + +zeros, scalars, time: 1753383, 7941351, 552.279427ms +zeros, scalars, time: 4626, 10337, 8.186424ms +commit T: zeros, scalars, time: 10357, 10357, 526.139µs +zeros, scalars, time: 1757881, 7941351, 549.376525ms +commit T: zeros, scalars, time: 6752860, 9699051, 150.726917ms +zeros, scalars, time: 3440, 10337, 16.232103ms +commit T: zeros, scalars, time: 4321, 10357, 10.420238ms +zeros, scalars, time: 1757207, 7941351, 554.918165ms +commit T: zeros, scalars, time: 5966166, 9699051, 336.273993ms +zeros, scalars, time: 3426, 10337, 14.18858ms +commit T: zeros, scalars, time: 3212, 10357, 10.984965ms +zeros, scalars, time: 1757312, 7941351, 549.806303ms +commit T: zeros, scalars, time: 5341906, 9699051, 345.2704ms +zeros, scalars, time: 3445, 10337, 9.161598ms + +======================================= + +zeros, scalars, time: 1753383, 7941351, 553.780753ms +zeros, scalars, time: 4626, 10337, 8.334434ms +commit T: zeros, scalars, time: 10357, 10357, 1.278199ms +zeros, scalars, time: 1757881, 7941351, 550.897325ms +commit T: zeros, scalars, time: 6752860, 9699051, 154.014332ms +zeros, scalars, time: 3440, 10337, 11.95373ms +commit T: zeros, scalars, time: 4321, 10357, 8.790347ms +zeros, scalars, time: 1757207, 7941351, 551.386466ms +commit T: zeros, scalars, time: 5966166, 9699051, 329.657843ms +zeros, scalars, time: 3426, 10337, 15.606529ms +commit T: zeros, scalars, time: 3212, 10357, 18.218441ms +zeros, scalars, time: 1757312, 7941351, 552.540141ms +commit T: zeros, scalars, time: 5341906, 9699051, 364.02185ms +zeros, scalars, time: 3445, 10337, 11.646848ms +Benchmarking LEM Fibonacci Prove - rc = 900/fib/num-500-cc9de142be3f4829d09c4e27771207965eef9a79-2024-01-11: Analyzing +LEM Fibonacci Prove - rc = 900/fib/num-500-cc9de142be3f4829d09c4e27771207965eef9a79-2024-01-11 + time: [11.277 s 11.381 s 11.501 s] + thrpt: [313.01 elem/s 316.31 elem/s 319.23 elem/s] + change: + time: [-8.4128% -6.7674% -4.7092%] (p = 0.00 < 0.05) + thrpt: [+4.9419% +7.2586% +9.1856%] + Change within noise threshold. + diff --git a/examples/fibonacci.rs b/examples/fibonacci.rs new file mode 100644 index 0000000000..3890fa5384 --- /dev/null +++ b/examples/fibonacci.rs @@ -0,0 +1,119 @@ +use std::{cell::RefCell, rc::Rc, sync::Arc}; + +use anyhow::anyhow; + +use pasta_curves::pallas; + +use lurk::{ + eval::lang::{Coproc, Lang}, + field::LurkField, + lem::{eval::evaluate, pointers::Ptr, store::Store}, + proof::Prover, + proof::{nova::NovaProver, RecursiveSNARKTrait}, + public_parameters::{ + instance::{Instance, Kind}, + public_params, + }, + state::State, +}; + +use tracing_subscriber::{fmt, prelude::*, EnvFilter, Registry}; +use tracing_texray::TeXRayLayer; + +fn fib(store: &Store, state: Rc>, _a: u64) -> Ptr { + let program = r#" +(letrec ((next (lambda (a b) (next b (+ a b)))) + (fib (next 0 1))) + (fib)) +"#; + + store.read(state, program).unwrap() +} + +// The env output in the `fib_frame`th frame of the above, infinite Fibonacci computation will contain a binding of the +// nth Fibonacci number to `a`. +// means of computing it.] +fn fib_frame(n: usize) -> usize { + 11 + 16 * n +} + +// Set the limit so the last step will be filled exactly, since Lurk currently only pads terminal/error continuations. +fn fib_limit(n: usize, rc: usize) -> usize { + let frame = fib_frame(n); + rc * (frame / rc + usize::from(frame % rc != 0)) +} + +#[derive(Clone, Debug, Copy)] +struct ProveParams { + fib_n: usize, + rc: usize, +} + +fn rc_env() -> anyhow::Result> { + std::env::var("LURK_RC") + .map_err(|e| anyhow!("Reduction count env var isn't set: {e}")) + .and_then(|rc| { + let vec: anyhow::Result> = rc + .split(',') + .map(|rc| { + rc.parse::() + .map_err(|e| anyhow!("Failed to parse RC: {e}")) + }) + .collect(); + vec + }) +} + +fn fibonacci_prove(prove_params: ProveParams, state: &Rc>) { + let limit = fib_limit(prove_params.fib_n, prove_params.rc); + let lang_pallas = Lang::>::new(); + let lang_rc = Arc::new(lang_pallas.clone()); + + // use cached public params + let instance = Instance::new( + prove_params.rc, + lang_rc.clone(), + true, + Kind::NovaPublicParams, + ); + let pp = public_params(&instance).unwrap(); + + let store = Store::default(); + + let ptr = fib::(&store, state.clone(), prove_params.fib_n as u64); + let prover = NovaProver::new(prove_params.rc, lang_rc.clone()); + + let frames = &evaluate::>(None, ptr, &store, limit) + .unwrap(); + let (proof, z0, zi, _num_steps) = tracing_texray::examine(tracing::info_span!("bang!")) + .in_scope(|| prover.prove(&pp, frames, &store).unwrap()); + + let res = proof.verify(&pp, &z0, &zi).unwrap(); + assert!(res); +} + +/// RUST_LOG=info LURK_RC=900 LURK_PERF=max-parallel-simple cargo run --release --example fibonacci --features "cuda" +fn main() { + let subscriber = Registry::default() + .with(fmt::layer().pretty()) + .with(EnvFilter::from_default_env()) + .with(TeXRayLayer::new().width(120)); + tracing::subscriber::set_global_default(subscriber).unwrap(); + + let rcs = rc_env().unwrap_or_else(|_| vec![100]); + let batch_sizes = [500]; + + let state = State::init_lurk_state().rccell(); + + for rc in rcs.iter() { + for fib_n in batch_sizes.iter() { + let prove_params = ProveParams { + fib_n: *fib_n, + rc: *rc, + }; + fibonacci_prove(prove_params, &state); + } + } + + println!("success"); +} \ No newline at end of file diff --git a/src/proof/mod.rs b/src/proof/mod.rs index d1daa03861..78039d0f27 100644 --- a/src/proof/mod.rs +++ b/src/proof/mod.rs @@ -100,7 +100,7 @@ where /// Generate the recursive SNARK, encoded in `ProveOutput` fn prove_recursively( - pp: &Self::PublicParams, + pp: &'a Self::PublicParams, z0: &[F], steps: Vec>, store: &'a Store, @@ -174,7 +174,7 @@ pub trait Prover<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> { /// Generate a proof from a sequence of frames fn prove( &self, - pp: &Self::PublicParams, + pp: &'a Self::PublicParams, frames: &[Frame], store: &'a Store, ) -> Result<(Self::RecursiveSnark, Vec, Vec, usize), ProofError> { @@ -205,7 +205,7 @@ pub trait Prover<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> { /// Evaluate an expression with an environment and then generate the corresponding proof fn evaluate_and_prove( &self, - pp: &Self::PublicParams, + pp: &'a Self::PublicParams, expr: Ptr, env: Ptr, store: &'a Store, diff --git a/src/proof/nova.rs b/src/proof/nova.rs index 9ed1b39a79..2dc79f742d 100644 --- a/src/proof/nova.rs +++ b/src/proof/nova.rs @@ -159,7 +159,7 @@ where /// A proof for the intermediate steps of a recursive computation along with /// the number of steps used for verification Recursive( - Box, E2, C1LEM<'a, F, C>, C2>>, + Box, E2, C1LEM<'a, F, C>, C2>>, usize, PhantomData<&'a C>, ), @@ -234,7 +234,7 @@ where #[tracing::instrument(skip_all, name = "nova::prove_recursively")] fn prove_recursively( - pp: &PublicParams>, + pp: &'a PublicParams>, z0: &[F], steps: Vec>, store: &'a Store, @@ -257,7 +257,7 @@ where tracing::debug!("steps.len: {num_steps}"); // produce a recursive SNARK - let mut recursive_snark: Option, E2, C1LEM<'a, F, C>, C2>> = + let mut recursive_snark: Option, E2, C1LEM<'a, F, C>, C2>> = None; // the shadowing here is voluntary diff --git a/src/proof/supernova.rs b/src/proof/supernova.rs index 1e0decc608..ac9613d4a4 100644 --- a/src/proof/supernova.rs +++ b/src/proof/supernova.rs @@ -134,7 +134,7 @@ where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, { /// A proof for the intermediate steps of a recursive computation - Recursive(Box, E2>>), + Recursive(Box, E2>>), /// A proof for the final step of a recursive computation Compressed( Box, E2, C1LEM<'a, F, C>, C2, SS1, SS2>>, @@ -177,14 +177,14 @@ where #[tracing::instrument(skip_all, name = "supernova::prove_recursively")] fn prove_recursively( - pp: &PublicParams>, + pp: &'a PublicParams>, z0: &[F], steps: Vec>, store: &'a Store, _reduction_count: usize, _lang: Arc>, ) -> Result { - let mut recursive_snark_option: Option, E2>> = None; + let mut recursive_snark_option: Option, E2>> = None; let z0_primary = z0; let z0_secondary = Self::z0_secondary(); diff --git a/stderr.log b/stderr.log new file mode 100644 index 0000000000..929f36c086 --- /dev/null +++ b/stderr.log @@ -0,0 +1 @@ +error: No justfile found