diff --git a/Cargo.lock b/Cargo.lock index 01795225..a9ee8cfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,6 +129,12 @@ dependencies = [ "wasmer", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -490,8 +496,7 @@ dependencies = [ [[package]] name = "bellperson" version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c41bd83b8437856d267eb311de13dcd9bff9077cc5ba35c7ec886070dea8a45" +source = "git+https://github.com/0xEigenLabs/bellperson.git#2221b13fde4857af7d1f770a41f4233a2195b4eb" dependencies = [ "bellpepper-core", "bincode", @@ -1874,7 +1879,7 @@ dependencies = [ [[package]] name = "fields" version = "0.1.0" -source = "git+https://github.com/0xEigenLabs/eigen-zkvm.git?branch=main#562f447e026bae7aa14c19783341d9072217d76d" +source = "git+https://github.com/0xEigenLabs/eigen-zkvm.git?rev=cf405b2e2cecb8567cfd083a55936b71722276d5#cf405b2e2cecb8567cfd083a55936b71722276d5" dependencies = [ "byteorder", "franklin-crypto", @@ -2047,6 +2052,12 @@ dependencies = [ "slab", ] +[[package]] +name = "gcd" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a" + [[package]] name = "generic-array" version = "0.12.4" @@ -2239,6 +2250,11 @@ name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash 0.8.11", + "allocator-api2", + "rayon", +] [[package]] name = "hashbrown" @@ -2614,6 +2630,16 @@ version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +[[package]] +name = "libloading" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" +dependencies = [ + "cfg-if 1.0.0", + "windows-targets 0.48.5", +] + [[package]] name = "libm" version = "0.2.11" @@ -2817,6 +2843,7 @@ checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits", + "rand 0.8.5", "serde", ] @@ -2930,6 +2957,18 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" +[[package]] +name = "nums" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3c74f925fb8cfc49a8022f2afce48a0683b70f9e439885594e84c5edbf5b01" +dependencies = [ + "num-bigint 0.4.6", + "num-integer", + "num-traits", + "rand 0.8.5", +] + [[package]] name = "object" version = "0.36.5" @@ -2988,6 +3027,313 @@ version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" +[[package]] +name = "p3-air" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "p3-field", + "p3-matrix", +] + +[[package]] +name = "p3-baby-bear" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "p3-field", + "p3-mds", + "p3-monty-31", + "p3-poseidon2", + "p3-symmetric", + "rand 0.8.5", + "serde", +] + +[[package]] +name = "p3-challenger" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "p3-field", + "p3-maybe-rayon", + "p3-symmetric", + "p3-util", + "tracing", +] + +[[package]] +name = "p3-circle" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "p3-challenger", + "p3-commit", + "p3-dft", + "p3-field", + "p3-fri", + "p3-matrix", + "p3-maybe-rayon", + "p3-util", + "serde", + "tracing", +] + +[[package]] +name = "p3-commit" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "p3-challenger", + "p3-dft", + "p3-field", + "p3-matrix", + "p3-util", + "serde", +] + +[[package]] +name = "p3-dft" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-util", + "tracing", +] + +[[package]] +name = "p3-field" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "num-bigint 0.4.6", + "num-integer", + "num-traits", + "nums", + "p3-maybe-rayon", + "p3-util", + "rand 0.8.5", + "serde", + "tracing", +] + +[[package]] +name = "p3-fri" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "p3-challenger", + "p3-commit", + "p3-dft", + "p3-field", + "p3-interpolation", + "p3-matrix", + "p3-maybe-rayon", + "p3-util", + "serde", + "tracing", +] + +[[package]] +name = "p3-goldilocks" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "num-bigint 0.4.6", + "p3-dft", + "p3-field", + "p3-mds", + "p3-poseidon2", + "p3-symmetric", + "p3-util", + "rand 0.8.5", + "serde", +] + +[[package]] +name = "p3-interpolation" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "p3-field", + "p3-matrix", + "p3-util", +] + +[[package]] +name = "p3-koala-bear" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "p3-field", + "p3-mds", + "p3-monty-31", + "p3-poseidon2", + "p3-symmetric", + "rand 0.8.5", + "serde", +] + +[[package]] +name = "p3-matrix" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "p3-field", + "p3-maybe-rayon", + "p3-util", + "rand 0.8.5", + "serde", + "tracing", + "transpose", +] + +[[package]] +name = "p3-maybe-rayon" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "rayon", +] + +[[package]] +name = "p3-mds" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "p3-dft", + "p3-field", + "p3-matrix", + "p3-symmetric", + "p3-util", + "rand 0.8.5", +] + +[[package]] +name = "p3-merkle-tree" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "p3-commit", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-symmetric", + "p3-util", + "serde", + "tracing", +] + +[[package]] +name = "p3-mersenne-31" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "num-bigint 0.4.6", + "p3-dft", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-mds", + "p3-poseidon2", + "p3-symmetric", + "p3-util", + "rand 0.8.5", + "serde", +] + +[[package]] +name = "p3-monty-31" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "num-bigint 0.4.6", + "p3-dft", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-mds", + "p3-poseidon2", + "p3-symmetric", + "p3-util", + "rand 0.8.5", + "serde", + "tracing", + "transpose", +] + +[[package]] +name = "p3-poseidon" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "p3-field", + "p3-mds", + "p3-symmetric", + "rand 0.8.5", +] + +[[package]] +name = "p3-poseidon2" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "gcd", + "p3-field", + "p3-mds", + "p3-symmetric", + "rand 0.8.5", +] + +[[package]] +name = "p3-symmetric" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "p3-field", + "serde", +] + +[[package]] +name = "p3-uni-stark" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "itertools 0.13.0", + "p3-air", + "p3-challenger", + "p3-commit", + "p3-dft", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-util", + "serde", + "tracing", +] + +[[package]] +name = "p3-util" +version = "0.1.0" +source = "git+https://github.com/plonky3/Plonky3.git?rev=2192432ddf28e7359dd2c577447886463e6124f0#2192432ddf28e7359dd2c577447886463e6124f0" +dependencies = [ + "serde", +] + [[package]] name = "pairing" version = "0.23.0" @@ -3224,25 +3570,10 @@ dependencies = [ "tiny-keccak 1.5.0", ] -[[package]] -name = "powdr" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" -dependencies = [ - "powdr-ast", - "powdr-backend", - "powdr-executor", - "powdr-number", - "powdr-pil-analyzer", - "powdr-pipeline", - "powdr-riscv", - "powdr-riscv-executor", -] - [[package]] name = "powdr-airgen" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "itertools 0.13.0", "log", @@ -3253,8 +3584,8 @@ dependencies = [ [[package]] name = "powdr-analysis" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "itertools 0.13.0", "lazy_static", @@ -3267,8 +3598,8 @@ dependencies = [ [[package]] name = "powdr-asm-to-pil" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "lazy_static", "log", @@ -3280,17 +3611,20 @@ dependencies = [ ] [[package]] -name = "powdr-asm-utils" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +name = "powdr-asmopt" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ - "itertools 0.13.0", + "powdr-analysis", + "powdr-ast", + "powdr-parser", + "powdr-pilopt", ] [[package]] name = "powdr-ast" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "auto_enums", "derive_more", @@ -3305,8 +3639,8 @@ dependencies = [ [[package]] name = "powdr-backend" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "bincode", "hex", @@ -3316,31 +3650,52 @@ dependencies = [ "num-integer", "num-traits", "powdr-ast", + "powdr-backend-utils", "powdr-executor", "powdr-number", "powdr-parser", "powdr-parser-util", "powdr-pil-analyzer", "rand 0.8.5", + "rayon", "serde", "serde_json", - "starky 0.0.1 (git+https://github.com/0xEigenLabs/eigen-zkvm.git?branch=main)", + "starky 0.0.1 (git+https://github.com/0xEigenLabs/eigen-zkvm.git?rev=cf405b2e2cecb8567cfd083a55936b71722276d5)", "strum", "thiserror", ] +[[package]] +name = "powdr-backend-utils" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" +dependencies = [ + "itertools 0.13.0", + "log", + "powdr-ast", + "powdr-executor-utils", + "powdr-number", + "powdr-parser", + "powdr-pil-analyzer", +] + [[package]] name = "powdr-executor" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ + "auto_enums", "bit-vec", + "derive_more", "indicatif", "itertools 0.13.0", "lazy_static", + "libloading", "log", "num-traits", "powdr-ast", + "powdr-executor-utils", + "powdr-jit-compiler", "powdr-number", "powdr-parser-util", "powdr-pil-analyzer", @@ -3348,10 +3703,20 @@ dependencies = [ "serde", ] +[[package]] +name = "powdr-executor-utils" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" +dependencies = [ + "powdr-ast", + "powdr-number", + "serde", +] + [[package]] name = "powdr-importer" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "powdr-ast", "powdr-number", @@ -3360,23 +3725,46 @@ dependencies = [ "pretty_assertions", ] +[[package]] +name = "powdr-isa-utils" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" + +[[package]] +name = "powdr-jit-compiler" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" +dependencies = [ + "itertools 0.13.0", + "lazy_static", + "libloading", + "log", + "mktemp", + "powdr-ast", + "powdr-number", + "powdr-parser", +] + [[package]] name = "powdr-linker" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "itertools 0.13.0", + "lazy_static", + "log", "powdr-analysis", "powdr-ast", "powdr-number", "powdr-parser-util", "pretty_assertions", + "strum", ] [[package]] name = "powdr-number" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "ark-bn254", "ark-ff", @@ -3386,6 +3774,10 @@ dependencies = [ "ibig", "num-bigint 0.4.6", "num-traits", + "p3-baby-bear", + "p3-field", + "p3-koala-bear", + "p3-mersenne-31", "schemars", "serde", "serde_cbor", @@ -3394,8 +3786,8 @@ dependencies = [ [[package]] name = "powdr-parser" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "derive_more", "lalrpop", @@ -3409,8 +3801,8 @@ dependencies = [ [[package]] name = "powdr-parser-util" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "codespan-reporting 0.11.1", "lalrpop-util", @@ -3420,8 +3812,8 @@ dependencies = [ [[package]] name = "powdr-pil-analyzer" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "itertools 0.13.0", "lazy_static", @@ -3434,9 +3826,10 @@ dependencies = [ [[package]] name = "powdr-pilopt" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ + "itertools 0.13.0", "log", "powdr-ast", "powdr-number", @@ -3445,8 +3838,8 @@ dependencies = [ [[package]] name = "powdr-pipeline" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "itertools 0.13.0", "log", @@ -3455,7 +3848,7 @@ dependencies = [ "powdr-airgen", "powdr-analysis", "powdr-asm-to-pil", - "powdr-asm-utils", + "powdr-asmopt", "powdr-ast", "powdr-backend", "powdr-executor", @@ -3472,23 +3865,60 @@ dependencies = [ "walkdir", ] +[[package]] +name = "powdr-plonky3" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" +dependencies = [ + "indexmap 1.9.3", + "itertools 0.13.0", + "lazy_static", + "p3-air", + "p3-baby-bear", + "p3-challenger", + "p3-circle", + "p3-commit", + "p3-dft", + "p3-field", + "p3-fri", + "p3-goldilocks", + "p3-koala-bear", + "p3-matrix", + "p3-maybe-rayon", + "p3-mds", + "p3-merkle-tree", + "p3-mersenne-31", + "p3-monty-31", + "p3-poseidon", + "p3-poseidon2", + "p3-symmetric", + "p3-uni-stark", + "p3-util", + "powdr-ast", + "powdr-executor-utils", + "powdr-number", + "powdr-riscv-runtime", + "rand 0.8.5", + "rand_chacha 0.3.1", + "serde", + "tracing", +] + [[package]] name = "powdr-riscv" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "gimli 0.31.1", "goblin", "itertools 0.13.0", "lalrpop", - "lalrpop-util", "lazy_static", "log", - "mktemp", - "num-traits", - "powdr-asm-utils", "powdr-ast", "powdr-executor", + "powdr-isa-utils", + "powdr-linker", "powdr-number", "powdr-parser", "powdr-parser-util", @@ -3496,15 +3926,15 @@ dependencies = [ "powdr-riscv-executor", "powdr-riscv-syscalls", "raki", - "regex-syntax 0.6.29", "serde_json", + "static_assertions", "thiserror", ] [[package]] name = "powdr-riscv-executor" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "inferno 0.11.21", "itertools 0.13.0", @@ -3512,25 +3942,38 @@ dependencies = [ "log", "num-bigint 0.4.6", "num-traits", - "powdr-analysis", + "p3-field", + "p3-goldilocks", + "p3-symmetric", "powdr-ast", "powdr-executor", - "powdr-importer", "powdr-number", "powdr-parser", - "powdr-riscv-syscalls", + "powdr-plonky3", + "rayon", "rustc-demangle", ] +[[package]] +name = "powdr-riscv-runtime" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" +dependencies = [ + "getrandom 0.2.15", + "powdr-riscv-syscalls", + "serde", + "serde_cbor", +] + [[package]] name = "powdr-riscv-syscalls" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" [[package]] name = "powdr-schemas" -version = "0.1.0-alpha.2" -source = "git+https://github.com/0xEigenLabs/powdr?branch=eigen%2Fv1#d8d0c95a47af99ff0caa112f051d05a1be69f498" +version = "0.1.3" +source = "git+https://github.com/powdr-labs/powdr.git?branch=main#61510810630c5c195784f70ad68c83bd04674400" dependencies = [ "powdr-ast", "powdr-number", @@ -3893,10 +4336,11 @@ dependencies = [ "num", "num-bigint 0.3.3", "num-traits", - "powdr", "powdr-ast", + "powdr-number", "powdr-parser-util", "powdr-pil-analyzer", + "powdr-pilopt", "proptest", "serde", "serde_json", @@ -4487,12 +4931,13 @@ dependencies = [ [[package]] name = "starky" version = "0.0.1" -source = "git+https://github.com/0xEigenLabs/eigen-zkvm.git?branch=main#562f447e026bae7aa14c19783341d9072217d76d" +source = "git+https://github.com/0xEigenLabs/eigen-zkvm.git?rev=cf405b2e2cecb8567cfd083a55936b71722276d5#cf405b2e2cecb8567cfd083a55936b71722276d5" dependencies = [ "anyhow", "byteorder", "ff_ce", - "fields 0.1.0 (git+https://github.com/0xEigenLabs/eigen-zkvm.git?branch=main)", + "fields 0.1.0 (git+https://github.com/0xEigenLabs/eigen-zkvm.git?rev=cf405b2e2cecb8567cfd083a55936b71722276d5)", + "hashbrown 0.14.5", "lazy_static", "log", "num-bigint 0.4.6", @@ -4518,6 +4963,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9091b6114800a5f2141aee1d1b9d6ca3592ac062dc5decb3764ec5895a47b4eb" +[[package]] +name = "strength_reduce" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82" + [[package]] name = "string_cache" version = "0.8.7" @@ -4813,6 +5264,16 @@ dependencies = [ "once_cell", ] +[[package]] +name = "transpose" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad61aed86bc3faea4300c7aee358b4c6d0c8d6ccc36524c96e4c92ccf26e77e" +dependencies = [ + "num-integer", + "strength_reduce", +] + [[package]] name = "type_analysis" version = "2.1.9" @@ -5466,7 +5927,11 @@ dependencies = [ "itertools 0.12.1", "log", "num-traits", - "powdr", + "powdr-backend", + "powdr-executor", + "powdr-number", + "powdr-pipeline", + "powdr-riscv", "recursion", "serde_json", "starky 0.0.1", diff --git a/algebraic-gpu/Cargo.toml b/algebraic-gpu/Cargo.toml index 25efe202..3c84ca61 100644 --- a/algebraic-gpu/Cargo.toml +++ b/algebraic-gpu/Cargo.toml @@ -30,8 +30,7 @@ byteorder = "1" ff = { version = "0.13.0", features = ["derive"] } pairing = "0.23.0" -bellperson = { version = "0.26", default-features = false, features = ["groth16"] } - +bellperson = { git = "https://github.com/0xEigenLabs/bellperson.git", default-features = false, features = ["groth16"], optional = true } rand = "0.8.5" [dev-dependencies] diff --git a/fields/src/packable.rs b/fields/src/packable.rs index 6aa4e72b..9cd45582 100644 --- a/fields/src/packable.rs +++ b/fields/src/packable.rs @@ -1,9 +1,11 @@ use crate::ff::PrimeFieldRepr; use crate::packed::PackedField; -/// Points us to the default packing for a particular field. There may me multiple choices of -/// PackedField for a particular Field (e.g. every Field is also a PackedField), but this is the -/// recommended one. The recommended packing varies by target_arch and target_feature. +/// Points us to the default packing for a particular field. +/// +/// There may be multiple choices of `PackedField` for a particular `Field` +/// (e.g., every `Field` is also a `PackedField`), but this is the recommended one. +/// The recommended packing varies by `target_arch` and `target_feature`. pub trait Packable: PrimeFieldRepr { type Packing: PackedField; } diff --git a/groth16/Cargo.toml b/groth16/Cargo.toml index 76059ef0..43710dc6 100644 --- a/groth16/Cargo.toml +++ b/groth16/Cargo.toml @@ -28,7 +28,7 @@ ff = { version = "0.13.0", features = ["derive"], optional = true } pairing = { version = "0.23.0", optional = true } group = { version = "0.13.0", optional = true } blstrs = { version = "0.7.0", features = ["__private_bench"], optional = true } -bellperson = { version = "0.26", default-features = false, features = ["groth16"], optional = true } +bellperson = { git = "https://github.com/0xEigenLabs/bellperson.git", default-features = false, features = ["groth16"], optional = true } rand_new = { package = "rand", version = "0.8", features = ["getrandom"], optional = true } rand_core = { version = "0.6", optional = true } diff --git a/recursion/Cargo.toml b/recursion/Cargo.toml index 300bc02e..242dbb5f 100644 --- a/recursion/Cargo.toml +++ b/recursion/Cargo.toml @@ -30,10 +30,11 @@ fields = { path = "../fields", default-features = false } starky = { path = "../starky", default-features = false } algebraic = { path = "../algebraic", default-features = false } -powdr = { git = "https://github.com/0xEigenLabs/powdr", branch = "eigen/v1", default-features = false } -powdr-ast = { git = "https://github.com/0xEigenLabs/powdr", branch = "eigen/v1", default-features = false } -powdr-pil-analyzer = { git = "https://github.com/0xEigenLabs/powdr", branch = "eigen/v1", default-features = false } -powdr-parser-util = { git = "https://github.com/0xEigenLabs/powdr", branch = "eigen/v1", default-features = false } +powdr-ast = { git = "https://github.com/powdr-labs/powdr.git", branch = "main", package = "powdr-ast", default-features = false } +powdr-number = { git = "https://github.com/powdr-labs/powdr.git", branch = "main", package = "powdr-number", default-features = false } +powdr-pil-analyzer = { git = "https://github.com/powdr-labs/powdr.git", branch = "main", package = "powdr-pil-analyzer", default-features = false } +powdr-pilopt = { git = "https://github.com/powdr-labs/powdr.git", branch = "main", package = "powdr-pilopt", default-features = false } +powdr-parser-util = { git = "https://github.com/powdr-labs/powdr.git", branch = "main", package = "powdr-parser-util", default-features = false } #powdr = { path = "../../powdr/powdr", default-features = false } #powdr-ast = { path = "../../powdr/ast", default-features = false } @@ -45,4 +46,4 @@ env_logger = "0.10" [features] default = ["wasmer/singlepass", "starky/default"] -avx512 = ["fields/avx512", "starky/avx512", "powdr/starky-avx512"] +avx512 = ["fields/avx512", "starky/avx512"] diff --git a/recursion/src/compressor12/compressor12_pil.rs b/recursion/src/compressor12/compressor12_pil.rs index 4bdc6c7f..0b1924a0 100644 --- a/recursion/src/compressor12/compressor12_pil.rs +++ b/recursion/src/compressor12/compressor12_pil.rs @@ -52,15 +52,14 @@ pub fn render(n_bits: usize, n_publics: usize) -> String { res.push_str(&format!( r#" let N: int = 2**{n_bits}; - namespace Global(N); - pol constant L1; + pol constant L1 = [0]*; "# )); for i in (12..n_publics).step_by(12) { res.push_str(&format!( r#" - pol constant L{}; + pol constant L{} = [0]*; "#, i / 12 + 1 )); @@ -69,14 +68,36 @@ namespace Global(N); res.push_str( r#" namespace Compressor(N); - pol constant S[12]; - pol constant C[12]; - pol constant PARTIAL; - pol constant POSEIDON12; - pol constant GATE; - pol constant CMULADD; - pol constant EVPOL4; - pol constant FFT4; + pol constant S_0 = [0]*; + pol constant S_1 = [0]*; + pol constant S_2 = [0]*; + pol constant S_3 = [0]*; + pol constant S_4 = [0]*; + pol constant S_5 = [0]*; + pol constant S_6 = [0]*; + pol constant S_7 = [0]*; + pol constant S_8 = [0]*; + pol constant S_9 = [0]*; + pol constant S_10 = [0]*; + pol constant S_11 = [0]*; + pol constant C_0 = [0]*; + pol constant C_1 = [0]*; + pol constant C_2 = [0]*; + pol constant C_3 = [0]*; + pol constant C_4 = [0]*; + pol constant C_5 = [0]*; + pol constant C_6 = [0]*; + pol constant C_7 = [0]*; + pol constant C_8 = [0]*; + pol constant C_9 = [0]*; + pol constant C_10 = [0]*; + pol constant C_11 = [0]*; + pol constant PARTIAL = [0]*; + pol constant POSEIDON12 = [0]*; + pol constant GATE = [0]*; + pol constant CMULADD = [0]*; + pol constant EVPOL4 = [0]*; + pol constant FFT4 = [0]*; pol commit a[12]; "#, ); @@ -95,7 +116,7 @@ namespace Compressor(N); for i in 0..n_publics { res.push_str(&format!( r#" - Global.L{} * (a[{}] - :pub{}) = 0; + Global::L{} * (a[{}] - :pub{}) = 0; "#, i / 12 + 1, i % 12, @@ -106,24 +127,18 @@ namespace Compressor(N); // Normal plonk gate res.push_str( r#" - // Normal plonk gates - pol a01 = a[0]*a[1]; - pol g012 = C[3]*a01 + C[0]*a[0] + C[1]*a[1] + C[2]*a[2] + C[4]; - g012*GATE = 0; - - pol a34 = a[3]*a[4]; - pol g345 = C[3]*a34 + C[0]*a[3] + C[1]*a[4] + C[2]*a[5] + C[4]; - g345*GATE = 0; - - pol a67 = a[6]*a[7]; - pol g678 = C[9]*a67 + C[6]*a[6] + C[7]*a[7] + C[8]*a[8] + C[10]; - g678*GATE = 0; - - pol a910 = a[9]*a[10]; - pol g91011 = C[9]*a910 + C[6]*a[9] + C[7]*a[10] + C[8]*a[11] + C[10]; - g91011*GATE = 0; - - // POSEIDON12 GATE + pol a01 = a[0] * a[1]; + pol g012 = C_3 * a01 + C_0 * a[0] + C_1 * a[1] + C_2 * a[2] + C_4; + g012 * GATE = 0; + pol a34 = a[3] * a[4]; + pol g345 = C_3 * a34 + C_0 * a[3] + C_1 * a[4] + C_2 * a[5] + C_4; + g345 * GATE = 0; + pol a67 = a[6] * a[7]; + pol g678 = C_9 * a67 + C_6 * a[6] + C_7 * a[7] + C_8 * a[8] + C_10; + g678 * GATE = 0; + pol a910 = a[9] * a[10]; + pol g91011 = C_9 * a910 + C_6 * a[9] + C_7 * a[10] + C_8 * a[11] + C_10; + g91011 * GATE = 0; "#, ); @@ -131,7 +146,7 @@ namespace Compressor(N); for i in 0..12 { res.push_str(&format!( r#" - pol a{i}_1 = a[{i}] + C[{i}]; + pol a{i}_1 = a[{i}] + C_{i}; "# )); @@ -171,63 +186,51 @@ namespace Compressor(N); } res.push_str( r#" - POSEIDON12 * (a[ 0]' - (25*a0_R + 15*a1_R + 41*a2_R + 16*a3_R + 2*a4_R + 28*a5_R + 13*a6_R + 13*a7_R + 39*a8_R + 18*a9_R + 34*a10_R + 20*a11_R)) = 0; - POSEIDON12 * (a[ 1]' - (20*a0_R + 17*a1_R + 15*a2_R + 41*a3_R + 16*a4_R + 2*a5_R + 28*a6_R + 13*a7_R + 13*a8_R + 39*a9_R + 18*a10_R + 34*a11_R)) = 0; - POSEIDON12 * (a[ 2]' - (34*a0_R + 20*a1_R + 17*a2_R + 15*a3_R + 41*a4_R + 16*a5_R + 2*a6_R + 28*a7_R + 13*a8_R + 13*a9_R + 39*a10_R + 18*a11_R)) = 0; - POSEIDON12 * (a[ 3]' - (18*a0_R + 34*a1_R + 20*a2_R + 17*a3_R + 15*a4_R + 41*a5_R + 16*a6_R + 2*a7_R + 28*a8_R + 13*a9_R + 13*a10_R + 39*a11_R)) = 0; - POSEIDON12 * (a[ 4]' - (39*a0_R + 18*a1_R + 34*a2_R + 20*a3_R + 17*a4_R + 15*a5_R + 41*a6_R + 16*a7_R + 2*a8_R + 28*a9_R + 13*a10_R + 13*a11_R)) = 0; - POSEIDON12 * (a[ 5]' - (13*a0_R + 39*a1_R + 18*a2_R + 34*a3_R + 20*a4_R + 17*a5_R + 15*a6_R + 41*a7_R + 16*a8_R + 2*a9_R + 28*a10_R + 13*a11_R)) = 0; - POSEIDON12 * (a[ 6]' - (13*a0_R + 13*a1_R + 39*a2_R + 18*a3_R + 34*a4_R + 20*a5_R + 17*a6_R + 15*a7_R + 41*a8_R + 16*a9_R + 2*a10_R + 28*a11_R)) = 0; - POSEIDON12 * (a[ 7]' - (28*a0_R + 13*a1_R + 13*a2_R + 39*a3_R + 18*a4_R + 34*a5_R + 20*a6_R + 17*a7_R + 15*a8_R + 41*a9_R + 16*a10_R + 2*a11_R)) = 0; - POSEIDON12 * (a[ 8]' - ( 2*a0_R + 28*a1_R + 13*a2_R + 13*a3_R + 39*a4_R + 18*a5_R + 34*a6_R + 20*a7_R + 17*a8_R + 15*a9_R + 41*a10_R + 16*a11_R)) = 0; - POSEIDON12 * (a[ 9]' - (16*a0_R + 2*a1_R + 28*a2_R + 13*a3_R + 13*a4_R + 39*a5_R + 18*a6_R + 34*a7_R + 20*a8_R + 17*a9_R + 15*a10_R + 41*a11_R)) = 0; - POSEIDON12 * (a[10]' - (41*a0_R + 16*a1_R + 2*a2_R + 28*a3_R + 13*a4_R + 13*a5_R + 39*a6_R + 18*a7_R + 34*a8_R + 20*a9_R + 17*a10_R + 15*a11_R)) = 0; - POSEIDON12 * (a[11]' - (15*a0_R + 41*a1_R + 16*a2_R + 2*a3_R + 28*a4_R + 13*a5_R + 13*a6_R + 39*a7_R + 18*a8_R + 34*a9_R + 20*a10_R + 17*a11_R)) = 0; - - - // CMULADD GATE - pol ca0 = (a[0] + C[0])*C[9]; - pol ca1 = (a[1] + C[1])*C[9]; - pol ca2 = (a[2] + C[2])*C[9]; - pol ca3 = a[3] + C[3]; - pol ca4 = a[4] + C[4]; - pol ca5 = a[5] + C[5]; - pol ca6 = (a[6] + C[6])*C[10]; - pol ca7 = (a[7] + C[7])*C[10]; - pol ca8 = (a[8] + C[8])*C[10]; + POSEIDON12 * (a[0]' - (25 * a0_R + 15 * a1_R + 41 * a2_R + 16 * a3_R + 2 * a4_R + 28 * a5_R + 13 * a6_R + 13 * a7_R + 39 * a8_R + 18 * a9_R + 34 * a10_R + 20 * a11_R)) = 0; + POSEIDON12 * (a[1]' - (20 * a0_R + 17 * a1_R + 15 * a2_R + 41 * a3_R + 16 * a4_R + 2 * a5_R + 28 * a6_R + 13 * a7_R + 13 * a8_R + 39 * a9_R + 18 * a10_R + 34 * a11_R)) = 0; + POSEIDON12 * (a[2]' - (34 * a0_R + 20 * a1_R + 17 * a2_R + 15 * a3_R + 41 * a4_R + 16 * a5_R + 2 * a6_R + 28 * a7_R + 13 * a8_R + 13 * a9_R + 39 * a10_R + 18 * a11_R)) = 0; + POSEIDON12 * (a[3]' - (18 * a0_R + 34 * a1_R + 20 * a2_R + 17 * a3_R + 15 * a4_R + 41 * a5_R + 16 * a6_R + 2 * a7_R + 28 * a8_R + 13 * a9_R + 13 * a10_R + 39 * a11_R)) = 0; + POSEIDON12 * (a[4]' - (39 * a0_R + 18 * a1_R + 34 * a2_R + 20 * a3_R + 17 * a4_R + 15 * a5_R + 41 * a6_R + 16 * a7_R + 2 * a8_R + 28 * a9_R + 13 * a10_R + 13 * a11_R)) = 0; + POSEIDON12 * (a[5]' - (13 * a0_R + 39 * a1_R + 18 * a2_R + 34 * a3_R + 20 * a4_R + 17 * a5_R + 15 * a6_R + 41 * a7_R + 16 * a8_R + 2 * a9_R + 28 * a10_R + 13 * a11_R)) = 0; + POSEIDON12 * (a[6]' - (13 * a0_R + 13 * a1_R + 39 * a2_R + 18 * a3_R + 34 * a4_R + 20 * a5_R + 17 * a6_R + 15 * a7_R + 41 * a8_R + 16 * a9_R + 2 * a10_R + 28 * a11_R)) = 0; + POSEIDON12 * (a[7]' - (28 * a0_R + 13 * a1_R + 13 * a2_R + 39 * a3_R + 18 * a4_R + 34 * a5_R + 20 * a6_R + 17 * a7_R + 15 * a8_R + 41 * a9_R + 16 * a10_R + 2 * a11_R)) = 0; + POSEIDON12 * (a[8]' - (2 * a0_R + 28 * a1_R + 13 * a2_R + 13 * a3_R + 39 * a4_R + 18 * a5_R + 34 * a6_R + 20 * a7_R + 17 * a8_R + 15 * a9_R + 41 * a10_R + 16 * a11_R)) = 0; + POSEIDON12 * (a[9]' - (16 * a0_R + 2 * a1_R + 28 * a2_R + 13 * a3_R + 13 * a4_R + 39 * a5_R + 18 * a6_R + 34 * a7_R + 20 * a8_R + 17 * a9_R + 15 * a10_R + 41 * a11_R)) = 0; + POSEIDON12 * (a[10]' - (41 * a0_R + 16 * a1_R + 2 * a2_R + 28 * a3_R + 13 * a4_R + 13 * a5_R + 39 * a6_R + 18 * a7_R + 34 * a8_R + 20 * a9_R + 17 * a10_R + 15 * a11_R)) = 0; + POSEIDON12 * (a[11]' - (15 * a0_R + 41 * a1_R + 16 * a2_R + 2 * a3_R + 28 * a4_R + 13 * a5_R + 13 * a6_R + 39 * a7_R + 18 * a8_R + 34 * a9_R + 20 * a10_R + 17 * a11_R)) = 0; + pol ca0 = (a[0] + C_0) * C_9; + pol ca1 = (a[1] + C_1) * C_9; + pol ca2 = (a[2] + C_2) * C_9; + pol ca3 = a[3] + C_3; + pol ca4 = a[4] + C_4; + pol ca5 = a[5] + C_5; + pol ca6 = (a[6] + C_6) * C_10; + pol ca7 = (a[7] + C_7) * C_10; + pol ca8 = (a[8] + C_8) * C_10; pol ca9 = a[9]; pol ca10 = a[10]; pol ca11 = a[11]; - - pol cA = (ca0 + ca1) * (ca3 + ca4); - pol cB = (ca0 + ca2) * (ca3 + ca5); - pol cC = (ca1 + ca2) * (ca4 + ca5); - pol cD = ca0*ca3; - pol cE = ca1*ca4; - pol cF = ca2*ca5; - + pol cA = (ca0 + ca1) * (ca3 + ca4); + pol cB = (ca0 + ca2) * (ca3 + ca5); + pol cC = (ca1 + ca2) * (ca4 + ca5); + pol cD = ca0 * ca3; + pol cE = ca1 * ca4; + pol cF = ca2 * ca5; CMULADD * (ca9 - (cC + cD - cE - cF) - ca6) = 0; - CMULADD * (ca10 - (cA + cC - 2*cE - cD) - ca7) = 0; + CMULADD * (ca10 - (cA + cC - 2 * cE - cD) - ca7) = 0; CMULADD * (ca11 - (cB - cD + cE) - ca8) = 0; - - // FFT4 - - pol g0 = C[0]*a[0] + C[1]*a[3] + C[2]*a[6] + C[3]*a[9] + C[6]*a[0] + C[7]*a[3]; - pol g1 = C[0]*a[1] + C[1]*a[4] + C[2]*a[7] + C[3]*a[10] + C[6]*a[1] + C[7]*a[4]; - pol g2 = C[0]*a[2] + C[1]*a[5] + C[2]*a[8] + C[3]*a[11] + C[6]*a[2] + C[7]*a[5]; - - pol g3 = C[0]*a[0] - C[1]*a[3] + C[4]*a[6] - C[5]*a[9] + C[6]*a[0] - C[7]*a[3]; - pol g4 = C[0]*a[1] - C[1]*a[4] + C[4]*a[7] - C[5]*a[10] + C[6]*a[1] - C[7]*a[4]; - pol g5 = C[0]*a[2] - C[1]*a[5] + C[4]*a[8] - C[5]*a[11] + C[6]*a[2] - C[7]*a[5]; - - pol g6 = C[0]*a[0] + C[1]*a[3] - C[2]*a[6] - C[3]*a[9] + C[6]*a[6] + C[8]*a[9]; - pol g7 = C[0]*a[1] + C[1]*a[4] - C[2]*a[7] - C[3]*a[10] + C[6]*a[7] + C[8]*a[10]; - pol g8 = C[0]*a[2] + C[1]*a[5] - C[2]*a[8] - C[3]*a[11] + C[6]*a[8] + C[8]*a[11]; - - pol g9 = C[0]*a[0] - C[1]*a[3] - C[4]*a[6] + C[5]*a[9] + C[6]*a[6] - C[8]*a[9]; - pol g10 = C[0]*a[1] - C[1]*a[4] - C[4]*a[7] + C[5]*a[10] + C[6]*a[7] - C[8]*a[10]; - pol g11 = C[0]*a[2] - C[1]*a[5] - C[4]*a[8] + C[5]*a[11] + C[6]*a[8] - C[8]*a[11]; - + pol g0 = C_0 * a[0] + C_1 * a[3] + C_2 * a[6] + C_3 * a[9] + C_6 * a[0] + C_7 * a[3]; + pol g1 = C_0 * a[1] + C_1 * a[4] + C_2 * a[7] + C_3 * a[10] + C_6 * a[1] + C_7 * a[4]; + pol g2 = C_0 * a[2] + C_1 * a[5] + C_2 * a[8] + C_3 * a[11] + C_6 * a[2] + C_7 * a[5]; + pol g3 = C_0 * a[0] - C_1 * a[3] + C_4 * a[6] - C_5 * a[9] + C_6 * a[0] - C_7 * a[3]; + pol g4 = C_0 * a[1] - C_1 * a[4] + C_4 * a[7] - C_5 * a[10] + C_6 * a[1] - C_7 * a[4]; + pol g5 = C_0 * a[2] - C_1 * a[5] + C_4 * a[8] - C_5 * a[11] + C_6 * a[2] - C_7 * a[5]; + pol g6 = C_0 * a[0] + C_1 * a[3] - C_2 * a[6] - C_3 * a[9] + C_6 * a[6] + C_8 * a[9]; + pol g7 = C_0 * a[1] + C_1 * a[4] - C_2 * a[7] - C_3 * a[10] + C_6 * a[7] + C_8 * a[10]; + pol g8 = C_0 * a[2] + C_1 * a[5] - C_2 * a[8] - C_3 * a[11] + C_6 * a[8] + C_8 * a[11]; + pol g9 = C_0 * a[0] - C_1 * a[3] - C_4 * a[6] + C_5 * a[9] + C_6 * a[6] - C_8 * a[9]; + pol g10 = C_0 * a[1] - C_1 * a[4] - C_4 * a[7] + C_5 * a[10] + C_6 * a[7] - C_8 * a[10]; + pol g11 = C_0 * a[2] - C_1 * a[5] - C_4 * a[8] + C_5 * a[11] + C_6 * a[8] - C_8 * a[11]; FFT4 * (a[0]' - g0) = 0; FFT4 * (a[1]' - g1) = 0; FFT4 * (a[2]' - g2) = 0; @@ -240,7 +243,6 @@ namespace Compressor(N); FFT4 * (a[9]' - g9) = 0; FFT4 * (a[10]' - g10) = 0; FFT4 * (a[11]' - g11) = 0; - "# ); @@ -260,7 +262,7 @@ namespace Compressor(N); res.push_str( format!( r#" - pol {r0}_A = ({a0} + {a1}) * ({b0} + {b1}); + pol {r0}_A = ({a0} + {a1}) * ({b0} + {b1}); "# ) .as_str(), @@ -268,7 +270,7 @@ namespace Compressor(N); res.push_str( format!( r#" - pol {r0}_B = ({a0} + {a2}) * ({b0} + {b2}); + pol {r0}_B = ({a0} + {a2}) * ({b0} + {b2}); "# ) .as_str(), @@ -276,7 +278,7 @@ namespace Compressor(N); res.push_str( format!( r#" - pol {r0}_C = ({a1} + {a2}) * ({b1} + {b2}); + pol {r0}_C = ({a1} + {a2}) * ({b1} + {b2}); "# ) .as_str(), @@ -316,7 +318,7 @@ namespace Compressor(N); res.push_str( format!( r#" - pol {r1} = {r0}_A + {r0}_C - 2*{r0}_E - {r0}_D + {c1}; + pol {r1} = {r0}_A + {r0}_C - 2 * {r0}_E - {r0}_D + {c1}; "# ) .as_str(), @@ -354,11 +356,7 @@ namespace Compressor(N); EVPOL4 * (a[6]' - acc4_0 ) = 0; EVPOL4 * (a[7]' - acc4_1 ) = 0; EVPOL4 * (a[8]' - acc4_2 ) = 0; - - // Connection equations - [a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11]] connect - [S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], S[8], S[9], S[10], S[11]]; - + [a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11]] connect [S_0, S_1, S_2, S_3, S_4, S_5, S_6, S_7, S_8, S_9, S_10, S_11]; "#, ); diff --git a/recursion/src/pilcom.rs b/recursion/src/pilcom.rs index cef495de..60d5db05 100644 --- a/recursion/src/pilcom.rs +++ b/recursion/src/pilcom.rs @@ -1,21 +1,24 @@ //! Poring from https://github.com/powdr-labs/powdr.git. -use std::rc::Rc; +// use std::rc::Rc; mod export; mod expression_counter; pub use export::export; -use powdr::number::GoldilocksField; +use powdr_number::GoldilocksField; use starky::types::PIL; use std::path::Path; pub fn compile_pil_from_str(pil_str: &str) -> PIL { - let analyze = powdr_pil_analyzer::analyze_string::(pil_str); - export(&Rc::new(analyze)) + let analyzed_pil = powdr_pil_analyzer::analyze_string::(pil_str).unwrap(); + let analyze = powdr_pilopt::optimize(analyzed_pil); + export(&analyze) } pub fn compile_pil_from_path(pil_path: &str) -> PIL { - let analyze = powdr_pil_analyzer::analyze_file::(Path::new(pil_path)); - export(&Rc::new(analyze)) + let analyzed_pil = + powdr_pil_analyzer::analyze_file::(Path::new(pil_path)).unwrap(); + let analyze = powdr_pilopt::optimize(analyzed_pil); + export(&analyze) } #[cfg(test)] diff --git a/recursion/src/pilcom/export.rs b/recursion/src/pilcom/export.rs index 2a68f46e..178ee72d 100644 --- a/recursion/src/pilcom/export.rs +++ b/recursion/src/pilcom/export.rs @@ -1,11 +1,13 @@ -use powdr::number::FieldElement; +use num_traits::One; +use powdr_ast::parsed::SourceReference; +use powdr_number::FieldElement; use std::collections::HashMap; use std::{cmp, path::PathBuf}; use powdr_ast::analyzed::{ AlgebraicBinaryOperation, AlgebraicBinaryOperator, AlgebraicExpression as Expression, - AlgebraicUnaryOperation, AlgebraicUnaryOperator, Analyzed, IdentityKind, PolyID, - PolynomialType, StatementIdentifier, SymbolKind, + AlgebraicUnaryOperation, AlgebraicUnaryOperator, Analyzed, Identity, PolyID, PolynomialType, + StatementIdentifier, SymbolKind, }; use powdr_parser_util::SourceRef; use starky::types::{ @@ -63,15 +65,12 @@ pub fn export(analyzed: &Analyzed) -> PIL { } StatementIdentifier::PublicDeclaration(name) => { let pub_def = &analyzed.public_declarations[name]; - let pub_ref = &pub_def.polynomial; - let poly_id = pub_ref.poly_id.unwrap(); - let (_, expr) = exporter.polynomial_reference_to_json( - PolyID { - id: poly_id.id + pub_def.array_index.unwrap_or_default() as u64, - ..poly_id - }, - false, - ); + let symbol = &analyzed.definitions[&pub_def.polynomial.name].0; + let (_, poly) = symbol + .array_elements() + .nth(pub_def.array_index.unwrap_or_default()) + .unwrap(); + let (_, expr) = exporter.polynomial_reference_to_json(poly, false); let id = publics.len(); publics.push(starky::types::Public { polType: polynomial_reference_type_to_type(&expr.op).to_string(), @@ -81,11 +80,11 @@ pub fn export(analyzed: &Analyzed) -> PIL { name: name.clone(), }); } - StatementIdentifier::Identity(id) => { + StatementIdentifier::ProofItem(id) => { let identity = &analyzed.identities[*id]; // PILCOM strips the path from filenames, we do the same here for compatibility let file_name = identity - .source + .source_reference() .file_name .as_deref() .and_then(|s| { @@ -95,53 +94,54 @@ pub fn export(analyzed: &Analyzed) -> PIL { .map(String::from) }) .unwrap_or_default(); - let line = exporter.line_of_source_ref(&identity.source); - let selector_degree = if identity.kind == IdentityKind::Polynomial { - 2 - } else { - 1 - }; - let left = exporter.extract_expression_vec(&identity.left.expressions, 1); - let sel_left = - exporter.extract_expression_opt(&identity.left.selector, selector_degree); - let right = exporter.extract_expression_vec(&identity.right.expressions, 1); - let sel_right = exporter.extract_expression_opt(&identity.right.selector, 1); - match identity.kind { - IdentityKind::Polynomial => pol_identities.push(PolIdentity { - e: sel_left.unwrap(), + let line = exporter.line_of_source_ref(identity.source_reference()); + match identity { + Identity::Polynomial(identity) => pol_identities.push(PolIdentity { + e: exporter.extract_expression(&identity.expression, 2), fileName: file_name, line, }), - IdentityKind::Plookup => { + Identity::Lookup(identity) => { plookup_identities.push(PlookupIdentity { - selF: sel_left, - f: Some(left), - selT: sel_right, - t: Some(right), + selF: exporter.extract_selector(&identity.left.selector, 1), + f: Some(exporter.extract_expression_vec(&identity.left.expressions, 1)), + selT: exporter.extract_selector(&identity.right.selector, 1), + t: Some( + exporter.extract_expression_vec(&identity.right.expressions, 1), + ), fileName: file_name, line, }); } - IdentityKind::Permutation => { + Identity::Permutation(identity) => { permutation_identities.push(PermutationIdentity { - selF: sel_left, - f: Some(left), - selT: sel_right, - t: Some(right), + selF: exporter.extract_selector(&identity.left.selector, 1), + f: Some(exporter.extract_expression_vec(&identity.left.expressions, 1)), + selT: exporter.extract_selector(&identity.right.selector, 1), + t: Some( + exporter.extract_expression_vec(&identity.right.expressions, 1), + ), fileName: file_name, line, }); } - IdentityKind::Connect => { + Identity::Connect(identity) => { connection_identities.push(ConnectionIdentity { - pols: Some(left), - connections: Some(right), + pols: Some(exporter.extract_expression_vec(&identity.left, 1)), + connections: Some(exporter.extract_expression_vec(&identity.right, 1)), fileName: file_name, line, }); } + Identity::PhantomLookup(..) + | Identity::PhantomPermutation(..) + | Identity::PhantomBusInteraction(..) => { + // These are not relevant for the PIL + } } } + StatementIdentifier::ProverFunction(_) + | StatementIdentifier::TraitImplementation(_) => {} } } PIL { @@ -192,10 +192,8 @@ fn polynomial_reference_type_to_type(t: &str) -> &'static str { /// Makes names compatible with estark, which sometimes require that /// there is exactly one `.` in the name. fn fixup_name(name: &str) -> String { - if name.contains('.') { - name.to_string() - } else if let Some(last) = name.rfind("::") { - format!("{}.{}", &name[..last], &name[last + 1..]) + if let Some(last) = name.rfind("::") { + format!("{}.{}", &name[..last], &name[last + 2..]) } else { panic!("Witness or intermediate column is not inside a namespace: {name}"); } @@ -273,13 +271,11 @@ impl<'a, T: FieldElement> Exporter<'a, T> { id } - fn extract_expression_opt( - &mut self, - expr: &Option>, - max_degree: u32, - ) -> Option { - expr.as_ref() - .map(|e| self.extract_expression(e, max_degree)) + fn extract_selector(&mut self, expr: &Expression, max_degree: u32) -> Option { + match expr.is_one() { + true => None, + false => Some(self.extract_expression(expr, max_degree)), + } } fn extract_expression_vec(&mut self, expr: &[Expression], max_degree: u32) -> Vec { diff --git a/recursion/src/pilcom/expression_counter.rs b/recursion/src/pilcom/expression_counter.rs index 35313bd6..06c384b1 100644 --- a/recursion/src/pilcom/expression_counter.rs +++ b/recursion/src/pilcom/expression_counter.rs @@ -1,12 +1,16 @@ use std::collections::HashMap; +use num_traits::One; use powdr_ast::analyzed::{ Analyzed, Identity, PolynomialType, PublicDeclaration, SelectedExpressions, StatementIdentifier, Symbol, SymbolKind, }; +use powdr_number::FieldElement; /// Computes expression IDs for each intermediate polynomial. -pub fn compute_intermediate_expression_ids(analyzed: &Analyzed) -> HashMap { +pub fn compute_intermediate_expression_ids( + analyzed: &Analyzed, +) -> HashMap { let mut expression_counter: usize = 0; let mut ids = HashMap::new(); for item in &analyzed.source_order { @@ -28,7 +32,9 @@ pub fn compute_intermediate_expression_ids(analyzed: &Analyzed) -> HashMap StatementIdentifier::PublicDeclaration(name) => { analyzed.public_declarations[name].expression_count() } - StatementIdentifier::Identity(id) => analyzed.identities[*id].expression_count(), + StatementIdentifier::ProofItem(id) => analyzed.identities[*id].expression_count(), + StatementIdentifier::ProverFunction(_) + | StatementIdentifier::TraitImplementation(_) => 0, } } ids @@ -39,9 +45,25 @@ trait ExpressionCounter { fn expression_count(&self) -> usize; } -impl ExpressionCounter for Identity> { +impl ExpressionCounter for Identity { fn expression_count(&self) -> usize { - self.left.expression_count() + self.right.expression_count() + match self { + Identity::Polynomial(_) => 1, + Identity::Lookup(plookup_identity) => { + plookup_identity.left.expression_count() + plookup_identity.right.expression_count() + } + Identity::Permutation(permutation_identity) => { + permutation_identity.left.expression_count() + + permutation_identity.right.expression_count() + } + Identity::Connect(connect_identity) => { + connect_identity.left.len() + connect_identity.right.len() + } + // phantom identities are not relevant in this context + Identity::PhantomLookup(..) + | Identity::PhantomPermutation(..) + | Identity::PhantomBusInteraction(..) => 0, + } } } @@ -61,8 +83,8 @@ impl ExpressionCounter for PublicDeclaration { } } -impl ExpressionCounter for SelectedExpressions { +impl ExpressionCounter for SelectedExpressions { fn expression_count(&self) -> usize { - self.selector.is_some() as usize + self.expressions.len() + (if self.selector.is_one() { 0 } else { 1 }) + self.expressions.len() } } diff --git a/starky/src/fri.rs b/starky/src/fri.rs index 428c878e..23f3bb86 100644 --- a/starky/src/fri.rs +++ b/starky/src/fri.rs @@ -1,4 +1,4 @@ -#![allow(clippy::map_all_any_identity)] +#![allow(clippy::map_identity)] use crate::constant::{MG, SHIFT, SHIFT_INV}; use crate::fft::FFT; diff --git a/zkvm/Cargo.toml b/zkvm/Cargo.toml index 3e7b65d0..ff3d501f 100644 --- a/zkvm/Cargo.toml +++ b/zkvm/Cargo.toml @@ -10,7 +10,12 @@ itertools = "0.12.0" # serialization log = "0.4.0" -powdr = { git = "https://github.com/0xEigenLabs/powdr", branch = "eigen/v1", default-features = false } +powdr-number = { git = "https://github.com/powdr-labs/powdr.git", branch = "main", package = "powdr-number", default-features = false } +powdr-backend = { git = "https://github.com/powdr-labs/powdr.git", branch = "main", package = "powdr-backend", default-features = false, features = ["estark-starky"] } +powdr-executor = { git = "https://github.com/powdr-labs/powdr.git", branch = "main", package = "powdr-executor", default-features = false } +powdr-riscv = { git = "https://github.com/powdr-labs/powdr.git", branch = "main", package = "powdr-riscv", default-features = false } +powdr-pipeline = { git = "https://github.com/powdr-labs/powdr.git", branch = "main", package = "powdr-pipeline", default-features = false, features = ["estark-starky"] } + #powdr = { path = "../../powdr/powdr", default-features = false } starky = { path = "../starky" } recursion = { path = "../recursion" } @@ -27,4 +32,4 @@ num-traits = "0.2.17" [features] default = [] -avx512 = ["starky/avx512", "recursion/avx512", "powdr/starky-avx512"] +avx512 = ["starky/avx512", "recursion/avx512", "powdr-pipeline/estark-starky-simd", "powdr-backend/estark-starky-simd"] diff --git a/zkvm/program/ark/Cargo.toml b/zkvm/program/ark/Cargo.toml new file mode 100644 index 00000000..066f960c --- /dev/null +++ b/zkvm/program/ark/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "ark" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +powdr-riscv-runtime = { git = "https://github.com/0xEigenLabs/powdr", branch = "eigen/v1" } + +bn = { version = "0.6.0", package = "substrate-bn-succinct" } +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +sha2 = { version = "0.10.8", default-features = false } +rand_core = "0.6" +rand_chacha = { version = "0.3", default-features = false } + +# arkworks +ark-bn254 = { version = "0.4.0", default-features = false, features = ["curve"] } +ark-serialize = { version = "0.4.2" } +ark-ff = { version = "0.4.2" } +ark-groth16 = { version = "0.4.0", default-features = false, features = ["r1cs"] } +ark-ec = { version = "0.4.0" } +ark-bls12-377 = { version = "0.4.0", default-features = false, features = ["curve"] } +ark-relations = { version = "0.4.0", default-features = false } +ark-std = { version = "0.4.0", default-features = false } +ark-snark = { version = "0.4.0" } + +[workspace] diff --git a/zkvm/program/ark/rust-toolchain.toml b/zkvm/program/ark/rust-toolchain.toml new file mode 100644 index 00000000..ffe8ad46 --- /dev/null +++ b/zkvm/program/ark/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly-2024-02-01" +targets = ["riscv32imac-unknown-none-elf"] +profile = "minimal" diff --git a/zkvm/program/ark/src/lib.rs b/zkvm/program/ark/src/lib.rs new file mode 100644 index 00000000..09c76ab0 --- /dev/null +++ b/zkvm/program/ark/src/lib.rs @@ -0,0 +1,195 @@ +#![no_std] + +use ark_snark::{CircuitSpecificSetupSNARK, SNARK}; +// For randomness (during paramgen and proof generation) +// use ark_std::rand::{Rng, RngCore, SeedableRng}; +use rand_chacha::ChaCha20Rng; +use rand_core::{RngCore, SeedableRng}; +use ark_ff::vec::Vec; +// For benchmarking + +// Bring in some tools for using pairing-friendly curves +// We're going to use the BLS12-377 pairing-friendly elliptic curve. +// use ark_bls12_377::{Bls12_377, Fr}; +use ark_bn254::{Bn254, Fr}; +use ark_ff::Field; +use ark_std::test_rng; + +// We'll use these interfaces to construct our circuit. +use ark_relations::{ + lc, ns, + r1cs::{ConstraintSynthesizer, ConstraintSystemRef, SynthesisError, Variable}, +}; + +const MIMC_ROUNDS: usize = 322; + +/// This is an implementation of MiMC, specifically a +/// variant named `LongsightF322p3` for BLS12-377. +/// See http://eprint.iacr.org/2016/492 for more +/// information about this construction. +/// +/// ``` +/// function LongsightF322p3(xL ⦂ Fp, xR ⦂ Fp) { +/// for i from 0 up to 321 { +/// xL, xR := xR + (xL + Ci)^3, xL +/// } +/// return xL +/// } +/// ``` +fn mimc(mut xl: F, mut xr: F, constants: &[F]) -> F { + assert_eq!(constants.len(), MIMC_ROUNDS); + + for i in 0..MIMC_ROUNDS { + let mut tmp1 = xl; + tmp1.add_assign(&constants[i]); + let mut tmp2 = tmp1; + tmp2.square_in_place(); + tmp2.mul_assign(&tmp1); + tmp2.add_assign(&xr); + xr = xl; + xl = tmp2; + } + + xl +} + +/// This is our demo circuit for proving knowledge of the +/// preimage of a MiMC hash invocation. +struct MiMCDemo<'a, F: Field> { + xl: Option, + xr: Option, + constants: &'a [F], +} + +/// Our demo circuit implements this `Circuit` trait which +/// is used during paramgen and proving in order to +/// synthesize the constraint system. +impl<'a, F: Field> ConstraintSynthesizer for MiMCDemo<'a, F> { + fn generate_constraints(self, cs: ConstraintSystemRef) -> Result<(), SynthesisError> { + assert_eq!(self.constants.len(), MIMC_ROUNDS); + + // Allocate the first component of the preimage. + let mut xl_value = self.xl; + let mut xl = + cs.new_witness_variable(|| xl_value.ok_or(SynthesisError::AssignmentMissing))?; + + // Allocate the second component of the preimage. + let mut xr_value = self.xr; + let mut xr = + cs.new_witness_variable(|| xr_value.ok_or(SynthesisError::AssignmentMissing))?; + + for i in 0..MIMC_ROUNDS { + // xL, xR := xR + (xL + Ci)^3, xL + let ns = ns!(cs, "round"); + let cs = ns.cs(); + + // tmp = (xL + Ci)^2 + let tmp_value = xl_value.map(|mut e| { + e.add_assign(&self.constants[i]); + e.square_in_place(); + e + }); + let tmp = + cs.new_witness_variable(|| tmp_value.ok_or(SynthesisError::AssignmentMissing))?; + + cs.enforce_constraint( + lc!() + xl + (self.constants[i], Variable::One), + lc!() + xl + (self.constants[i], Variable::One), + lc!() + tmp, + )?; + + // new_xL = xR + (xL + Ci)^3 + // new_xL = xR + tmp * (xL + Ci) + // new_xL - xR = tmp * (xL + Ci) + let new_xl_value = xl_value.map(|mut e| { + e.add_assign(&self.constants[i]); + e.mul_assign(&tmp_value.unwrap()); + e.add_assign(&xr_value.unwrap()); + e + }); + + let new_xl = if i == (MIMC_ROUNDS - 1) { + // This is the last round, xL is our image and so + // we allocate a public input. + cs.new_input_variable(|| new_xl_value.ok_or(SynthesisError::AssignmentMissing))? + } else { + cs.new_witness_variable(|| new_xl_value.ok_or(SynthesisError::AssignmentMissing))? + }; + + cs.enforce_constraint( + lc!() + tmp, + lc!() + xl + (self.constants[i], Variable::One), + lc!() + new_xl - xr, + )?; + + // xR = xL + xr = xl; + xr_value = xl_value; + + // xL = new_xL + xl = new_xl; + xl_value = new_xl_value; + } + + Ok(()) + } +} + +#[no_mangle] +fn main() { + use ark_groth16::Groth16; + use rand_chacha::ChaCha20Rng; + use rand_core::{RngCore, SeedableRng}; + use ark_ff::Field; + use core::time::Duration; + + // Initialize the random number generator + let mut rng = ChaCha20Rng::from_seed([0u8; 32]); + + // Generate the MiMC round constants as finite field elements + let constants = (0..MIMC_ROUNDS) + .map(|_| Fr::from(rng.next_u64())) + .collect::>(); + + // Create parameters for our circuit + let (pk, vk) = { + let c = MiMCDemo:: { + xl: None, + xr: None, + constants: &constants, + }; + + Groth16::::setup(c, &mut rng).unwrap() + }; + + // Prepare the verification key (for proof verification) + let pvk = Groth16::::process_vk(&vk).unwrap(); + + // Benchmark constants + const SAMPLES: u32 = 50; + + let mut total_proving = Duration::ZERO; + let mut total_verifying = Duration::ZERO; + + for _ in 0..SAMPLES { + // Generate a random preimage and compute the image + let xl = Fr::from(rng.next_u64()); + let xr = Fr::from(rng.next_u64()); + let image = mimc(xl, xr, &constants); + + { + // Create an instance of our circuit (with the witness) + let c = MiMCDemo { + xl: Some(xl), + xr: Some(xr), + constants: &constants, + }; + + // Create a Groth16 proof with our parameters + let proof = Groth16::::prove(&pk, c, &mut rng).unwrap(); + assert!( + Groth16::::verify_with_processed_vk(&pvk, &[image], &proof).unwrap() + ); + } + } +} diff --git a/zkvm/program/keccak/Cargo.toml b/zkvm/program/keccak/Cargo.toml new file mode 100644 index 00000000..ceb1b8e9 --- /dev/null +++ b/zkvm/program/keccak/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "keccak" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tiny-keccak = { version = "2.0.2", features = ["keccak"] } +powdr-riscv-runtime = { path = "../../../../riscv-runtime" } + +[workspace] diff --git a/zkvm/program/keccak/src/main.rs b/zkvm/program/keccak/src/main.rs new file mode 100644 index 00000000..3286e796 --- /dev/null +++ b/zkvm/program/keccak/src/main.rs @@ -0,0 +1,25 @@ +#![no_main] +#![no_std] + +extern crate powdr_riscv_runtime; +use tiny_keccak::{Hasher, Keccak}; + +#[no_mangle] +pub fn main() { + let inputs = [b"Solidity", b"Powdrrrr"]; + let mut output = [0u8; 32]; + let mut hasher = Keccak::v256(); + for input in inputs.into_iter().cycle().take(100) { + hasher.update(input); + } + hasher.finalize(&mut output); + + assert_eq!( + output, + [ + 0xb2, 0x60, 0x1c, 0x72, 0x12, 0xd8, 0x26, 0x0d, 0xa4, 0x6d, 0xde, 0x19, 0x8d, 0x50, + 0xa7, 0xe4, 0x67, 0x1f, 0xc1, 0xbb, 0x8f, 0xf2, 0xd1, 0x72, 0x5a, 0x8d, 0xa1, 0x08, + 0x11, 0xb5, 0x81, 0x69 + ], + ); +} diff --git a/zkvm/src/lib.rs b/zkvm/src/lib.rs index cb943e78..cd0fe03d 100644 --- a/zkvm/src/lib.rs +++ b/zkvm/src/lib.rs @@ -1,415 +1,405 @@ use anyhow::Result; -use powdr::backend::{ - composite::{split, CompositeProof, CompositeVerificationKey}, - BackendType, -}; -use powdr::executor::constant_evaluator::get_uniquely_sized; -use powdr::number::{DegreeType, FieldElement, GoldilocksField}; -use powdr::riscv::continuations::{rust_continuations, rust_continuations_dry_run}; -use powdr::riscv::{compile_rust, Runtime}; -use powdr::Pipeline; -use recursion::pilcom::export as pil_export; -use starky::{ - merklehash::MerkleTreeGL, - pil2circom, - stark_setup::StarkSetup, - types::{StarkStruct, Step}, -}; -use std::fs::{self, create_dir_all /*, remove_dir_all*/}; -use std::io::{BufWriter, Write}; +// use powdr_backend::{ +// composite::{split, CompositeProof, CompositeVerificationKey}, +// BackendType, +// }; +// use powdr_backend::BackendType; +// use powdr_executor::constant_evaluator::get_uniquely_sized; +use powdr_number::{CsvRenderMode, GoldilocksField, KnownField}; +use powdr_pipeline::Pipeline; +// use powdr_riscv::continuations::{rust_continuations, rust_continuations_dry_run}; +use powdr_riscv::{CompilerOptions, RuntimeLibs}; +// use recursion::pilcom::export as pil_export; +// use starky::{ +// merklehash::MerkleTreeGL, +// pil2circom, +// stark_setup::StarkSetup, +// types::{StarkStruct, Step}, +// }; +// use std::fs::{self, create_dir_all /*, remove_dir_all*/}; +// use std::io::{BufWriter, Write}; use std::path::Path; -use std::time::Instant; - -const TEST_CHANNEL: u32 = 1; - -fn generate_witness_and_prove( - mut pipeline: Pipeline, -) -> Result, Vec> { - let start = Instant::now(); - log::debug!("Generating witness..."); - pipeline.compute_witness()?; - let duration = start.elapsed(); - log::debug!("Generating witness took: {:?}", duration); - - let start = Instant::now(); - log::debug!("Proving ..."); - - pipeline = pipeline.with_backend( - BackendType::EStarkStarkyComposite, - Some("stark_gl".to_string()), - ); - pipeline.compute_proof()?; - let duration = start.elapsed(); - log::debug!("Proving took: {:?}", duration); - Ok(pipeline) -} - -fn generate_witness_and_prove_raw( - mut pipeline: Pipeline, -) -> Result<(), Vec> { - let start = Instant::now(); - log::debug!("Generating witness..."); - pipeline.compute_witness()?; - let duration = start.elapsed(); - log::debug!("Generating witness took: {:?}", duration); - - let start = Instant::now(); - log::debug!("Proving ..."); - - pipeline = pipeline.with_backend( - BackendType::EStarkStarkyComposite, - Some("stark_gl".to_string()), - ); - pipeline.compute_proof()?; - let duration = start.elapsed(); - log::debug!("Proving took: {:?}", duration); - Ok(()) -} - -fn generate_verifier( - mut pipeline: Pipeline, - output_path: &str, - task: &str, - chunk_idx: usize, -) -> Result> { - let buf = Vec::new(); - let mut vw = BufWriter::new(buf); - pipeline = pipeline.with_backend( - BackendType::EStarkStarkyComposite, - Some("stark_gl".to_string()), - ); - pipeline.export_verification_key(&mut vw).unwrap(); - - log::debug!("Init CompositeVerificationKey"); - let cvk: CompositeVerificationKey = bincode::deserialize(&vw.into_inner()?)?; - - log::debug!("Init CompositeProof"); - let proof_data = pipeline.proof().unwrap(); - let cf: CompositeProof = bincode::deserialize(proof_data)?; - - let full_pil = pipeline.optimized_pil().unwrap(); - let pils = split::split_pil((*full_pil).clone()); - - log::debug!("Generate verifier for each proof"); - let mut ids = vec![]; - for (idx, (vk, machine_proof)) in cvk - .verification_keys - .iter() - .zip(cf.proofs.into_iter()) - .enumerate() - { - if vk.is_none() { - continue; - } - let pil = pils.get(&machine_proof.machine).unwrap(); - let proof_file = Path::new(output_path).join(format!( - "{}_chunk_{}_submachine_{}.json", - task, chunk_idx, idx - )); - - log::debug!("Running proof generation to {:?}...", proof_file); - fs::write(proof_file, machine_proof.proof)?; - - let verifier_file = Path::new(output_path).join(format!( - "{}_chunk_{}_submachine_{}.circom", - task, chunk_idx, idx - )); - log::debug!( - "Running circom verifier generation to {:?}...", - verifier_file - ); - let mut writer = fs::File::create(verifier_file)?; - - let vk_data = vk.as_ref().unwrap().get(&machine_proof.size).unwrap(); - let mut setup: StarkSetup = serde_json::from_slice(vk_data)?; - log::debug!("Load StarkSetup, size={}", machine_proof.size); - - // FIXME: get the sub machine PIL - //let pil = pipeline.optimized_pil().unwrap(); - //let degree = pil.degree(); - let fixed_cols = pipeline.fixed_cols().unwrap(); - let degree = get_uniquely_sized(&fixed_cols) - .unwrap() - .iter() - .find(|(col, _)| col == "main.STEP") - .unwrap() - .1 - .len() as u64; - - assert!(degree > 1); - let n_bits = (DegreeType::BITS - (degree - 1).leading_zeros()) as usize; - let n_bits_ext = n_bits + 1; - - let steps = (2..=n_bits_ext) - .rev() - .step_by(4) - .map(|b| Step { nBits: b }) - .collect(); - - let params = StarkStruct { - nBits: n_bits, - nBitsExt: n_bits_ext, - nQueries: 2, - verificationHashType: "GL".to_owned(), - steps, - }; - - // generate circom - let opt = pil2circom::StarkOption { - enable_input: false, - verkey_input: false, - skip_main: true, - agg_stage: false, - }; - if !setup.starkinfo.qs.is_empty() { - let pil_json = pil_export::(pil); - let str_ver = pil2circom::pil2circom( - &pil_json, - &setup.const_root, - ¶ms, - &mut setup.starkinfo, - &mut setup.program, - &opt, - ) - .unwrap(); - writer.write_fmt(format_args!("{}", str_ver))?; - } - ids.push(idx); - } - Ok(ids) -} - -pub fn zkvm_execute_and_prove(task: &str, suite_json: String, output_path: &str) -> Result<()> { - log::debug!("Compiling Rust..."); - let force_overwrite = true; - let with_bootloader = true; - let (asm_file_path, asm_contents) = compile_rust::( - &format!("program/{task}"), +// use std::time::Instant; + +// const TEST_CHANNEL: u32 = 1; + +// fn generate_witness_and_prove( +// mut pipeline: Pipeline, +// ) -> Result, Vec> { +// let start = Instant::now(); +// log::debug!("Generating witness..."); +// pipeline.compute_witness()?; +// let duration = start.elapsed(); +// log::debug!("Generating witness took: {:?}", duration); + +// let start = Instant::now(); +// log::debug!("Proving ..."); + +// pipeline = pipeline.with_backend( +// BackendType::EStarkStarkyComposite, +// Some("stark_gl".to_string()), +// ); +// pipeline.compute_proof()?; +// let duration = start.elapsed(); +// log::debug!("Proving took: {:?}", duration); +// Ok(pipeline) +// } + +// fn generate_witness_and_prove_raw( +// mut pipeline: Pipeline, +// ) -> Result<(), Vec> { +// let start = Instant::now(); +// log::debug!("Generating witness..."); +// pipeline.compute_witness()?; +// let duration = start.elapsed(); +// log::debug!("Generating witness took: {:?}", duration); + +// let start = Instant::now(); +// log::debug!("Proving ..."); + +// pipeline = pipeline.with_backend( +// BackendType::EStarkStarkyComposite, +// Some("stark_gl".to_string()), +// ); +// pipeline.compute_proof()?; +// let duration = start.elapsed(); +// log::debug!("Proving took: {:?}", duration); +// Ok(()) +// } + +// fn generate_verifier( +// mut pipeline: Pipeline, +// output_path: &str, +// task: &str, +// chunk_idx: usize, +// ) -> Result> { +// let buf = Vec::new(); +// let mut vw = BufWriter::new(buf); +// pipeline = pipeline.with_backend( +// BackendType::EStarkStarkyComposite, +// Some("stark_gl".to_string()), +// ); +// pipeline.export_verification_key(&mut vw).unwrap(); + +// log::debug!("Init CompositeVerificationKey"); +// let cvk: CompositeVerificationKey = bincode::deserialize(&vw.into_inner()?)?; + +// log::debug!("Init CompositeProof"); +// let proof_data = pipeline.proof().unwrap(); +// let cf: CompositeProof = bincode::deserialize(proof_data)?; + +// let full_pil = pipeline.optimized_pil().unwrap(); +// let pils = split::split_pil((*full_pil).clone()); + +// log::debug!("Generate verifier for each proof"); +// let mut ids = vec![]; +// for (idx, (vk, machine_proof)) in cvk +// .verification_keys +// .iter() +// .zip(cf.proofs.into_iter()) +// .enumerate() +// { +// if vk.is_none() { +// continue; +// } +// let pil = pils.get(&machine_proof.machine).unwrap(); +// let proof_file = Path::new(output_path).join(format!( +// "{}_chunk_{}_submachine_{}.json", +// task, chunk_idx, idx +// )); + +// log::debug!("Running proof generation to {:?}...", proof_file); +// fs::write(proof_file, machine_proof.proof)?; + +// let verifier_file = Path::new(output_path).join(format!( +// "{}_chunk_{}_submachine_{}.circom", +// task, chunk_idx, idx +// )); +// log::debug!( +// "Running circom verifier generation to {:?}...", +// verifier_file +// ); +// let mut writer = fs::File::create(verifier_file)?; + +// let vk_data = vk.as_ref().unwrap().get(&machine_proof.size).unwrap(); +// let mut setup: StarkSetup = serde_json::from_slice(vk_data)?; +// log::debug!("Load StarkSetup, size={}", machine_proof.size); + +// // FIXME: get the sub machine PIL +// //let pil = pipeline.optimized_pil().unwrap(); +// //let degree = pil.degree(); +// let fixed_cols = pipeline.fixed_cols().unwrap(); +// let degree = get_uniquely_sized(&fixed_cols) +// .unwrap() +// .iter() +// .find(|(col, _)| col == "main.STEP") +// .unwrap() +// .1 +// .len() as u64; + +// assert!(degree > 1); +// let n_bits = (DegreeType::BITS - (degree - 1).leading_zeros()) as usize; +// let n_bits_ext = n_bits + 1; + +// let steps = (2..=n_bits_ext) +// .rev() +// .step_by(4) +// .map(|b| Step { nBits: b }) +// .collect(); + +// let params = StarkStruct { +// nBits: n_bits, +// nBitsExt: n_bits_ext, +// nQueries: 2, +// verificationHashType: "GL".to_owned(), +// steps, +// }; + +// // generate circom +// let opt = pil2circom::StarkOption { +// enable_input: false, +// verkey_input: false, +// skip_main: true, +// agg_stage: false, +// }; +// if !setup.starkinfo.qs.is_empty() { +// let pil_json = pil_export::(pil); +// let str_ver = pil2circom::pil2circom( +// &pil_json, +// &setup.const_root, +// ¶ms, +// &mut setup.starkinfo, +// &mut setup.program, +// &opt, +// ) +// .unwrap(); +// writer.write_fmt(format_args!("{}", str_ver))?; +// } +// ids.push(idx); +// } +// Ok(ids) +// } + +pub fn zkvm_execute_and_prove(task: &str, _suite_json: String, output_path: &str) -> Result<()> { + // log::debug!("Compiling Rust..."); + // let force_overwrite = true; + // // let with_bootloader = true; + // let options = CompilerOptions::new(KnownField::GoldilocksField, RuntimeLibs::new(), true); + // let (asm_file_path, asm_contents) = compile_rust( + // &format!("program/{task}"), + // options, + // Path::new(output_path), + // force_overwrite, + // None + // ) + // .ok_or_else(|| vec!["could not compile rust".to_string()]) + // .unwrap(); + + // let mut pipeline = Pipeline::::default() + // .with_output(output_path.into(), true) + // .with_backend(powdr_backend::BackendType::EStarkStarkyComposite, None) + // .with_witness_csv_settings(true, false, CsvRenderMode::Hex) + // .from_asm_string(asm_contents.clone(), Some(asm_file_path.clone())); + // // .with_prover_inputs(Default::default()) + // // .add_data(TEST_CHANNEL, &suite_json); + + // // log::debug!("Computing fixed columns..."); + // // let start = Instant::now(); + + // pipeline.compute_fixed_cols().unwrap(); + + // // let duration = start.elapsed(); + // // log::debug!("Computing fixed columns took: {:?}", duration); + // pipeline.compute_witness().unwrap(); + + let executable = powdr_riscv::compile_rust_crate_to_riscv( + &format!("program/{task}/Cargo.toml"), Path::new(output_path), - force_overwrite, - &Runtime::base().with_poseidon(), - false, - with_bootloader, - ) - .ok_or_else(|| vec!["could not compile rust".to_string()]) - .unwrap(); - - let mut pipeline = Pipeline::::default() - .with_output(output_path.into(), true) - .from_asm_string(asm_contents.clone(), Some(asm_file_path.clone())) - .with_prover_inputs(Default::default()) - .add_data(TEST_CHANNEL, &suite_json); - - log::debug!("Computing fixed columns..."); - let start = Instant::now(); - - pipeline.compute_fixed_cols().unwrap(); - - let duration = start.elapsed(); - log::debug!("Computing fixed columns took: {:?}", duration); - - /* - log::debug!("Running powdr-riscv executor in fast mode..."); - let start = Instant::now(); - - let (trace, _mem) = powdr::riscv_executor::execute::( - &asm_contents, - powdr::riscv_executor::MemoryState::new(), - pipeline.data_callback().unwrap(), - &default_input(&[]), - powdr::riscv_executor::ExecMode::Fast, + None, ); - let duration = start.elapsed(); - log::debug!("Fast executor took: {:?}", duration); - log::debug!("Trace length: {}", trace.len); - */ - - log::debug!("Running powdr-riscv executor in trace mode for continuations..."); - let start = Instant::now(); - - let bootloader_inputs = rust_continuations_dry_run(&mut pipeline, Default::default()); - - let duration = start.elapsed(); - log::debug!("Trace executor took: {:?}", duration); - - log::debug!("Running witness generation..."); - let start = Instant::now(); - rust_continuations(pipeline, generate_witness_and_prove_raw, bootloader_inputs).unwrap(); - - let duration = start.elapsed(); - log::debug!("Witness generation took: {:?}", duration); - - Ok(()) -} - -pub fn zkvm_generate_chunks( - workspace: &str, - suite_json: &String, - output_path: &str, -) -> Result, u64)>> { - log::debug!("Compiling Rust..."); - let force_overwrite = true; - let with_bootloader = true; - let (asm_file_path, asm_contents) = compile_rust::( - workspace, - Path::new(output_path), - force_overwrite, - &Runtime::base().with_poseidon(), - false, - with_bootloader, - ) - .ok_or_else(|| vec!["could not compile rust".to_string()]) - .unwrap(); + // compile + let options = CompilerOptions::new(KnownField::GoldilocksField, RuntimeLibs::new(), false); + let asm = powdr_riscv::elf::translate(&executable, options); + let _file_name = format!("{task}.asm"); let mut pipeline = Pipeline::::default() .with_output(output_path.into(), true) - .from_asm_string(asm_contents.clone(), Some(asm_file_path.clone())) - .with_prover_inputs(Default::default()) - .add_data(TEST_CHANNEL, suite_json); - - log::debug!("Running powdr-riscv executor in fast mode..."); - pipeline.compute_fixed_cols().unwrap(); - - /* - let (trace, _mem) = powdr::riscv_executor::execute::( - &asm_contents, - powdr::riscv_executor::MemoryState::new(), - pipeline.data_callback().unwrap(), - &default_input(&[]), - powdr::riscv_executor::ExecMode::Fast, - ); + .with_backend(powdr_backend::BackendType::EStarkStarkyComposite, None) + .with_witness_csv_settings(true, false, CsvRenderMode::Hex) + .from_asm_string(asm, Some("{output_path}/{_file_name}".into())); + pipeline.compute_witness().unwrap(); - log::debug!("Trace length: {}", trace.len); - */ - log::debug!("Running powdr-riscv executor in trace mode for continuations..."); - let start = Instant::now(); - - let bootloader_inputs = rust_continuations_dry_run(&mut pipeline, Default::default()); - - let duration = start.elapsed(); - log::debug!( - "Trace executor took: {:?}, input size: {:?}", - duration, - bootloader_inputs.len() - ); - - Ok(bootloader_inputs) -} - -pub fn zkvm_prove_only( - task: &str, - suite_json: &String, - bootloader_input: Vec, - start_of_shutdown_routine: u64, - i: usize, - output_path: &str, -) -> Result> { - log::debug!("Compiling Rust..."); - let asm_file_path = Path::new(output_path).join(format!("{}.asm", task)); - - let pipeline = Pipeline::::default() - .with_output(output_path.into(), true) - .from_asm_file(asm_file_path.clone()) - .with_prover_inputs(Default::default()) - .add_data(TEST_CHANNEL, suite_json); - - log::debug!("Running witness generation and proof computation..."); - let start = Instant::now(); - - //TODO: if we clone it, we lost the information gained from this function - let pipeline = rust_continuation( - task, - pipeline, - generate_witness_and_prove, - bootloader_input, - start_of_shutdown_routine, - i, - ) - .unwrap(); - - let ids = generate_verifier(pipeline, output_path, task, i)?; - - let duration = start.elapsed(); - log::debug!( - "Witness generation and proof computation took: {:?}", - duration - ); - - Ok(ids) + Ok(()) } -pub fn rust_continuation( - task: &str, - mut pipeline: Pipeline, - pipeline_callback: PipelineCallback, - bootloader_inputs: Vec, - start_of_shutdown_routine: u64, - i: usize, -) -> Result, E> -where - PipelineCallback: Fn(Pipeline) -> Result, E>, -{ - let fixed_cols = pipeline.compute_fixed_cols().unwrap(); - - // Advance the pipeline to the optimized PIL stage, so that it doesn't need to be computed - // in every chunk. - pipeline.compute_optimized_pil().unwrap(); - - let length = get_uniquely_sized(&fixed_cols) - .unwrap() - .iter() - .find(|(col, _)| col == "main.STEP") - .unwrap() - .1 - .len() as u64; - - let name = format!("{}_chunk_{}", task, i); - log::debug!("\nRunning chunk {} in {}...", i + 1, name); - - // we used to do - //let pipeline = pipeline.with_name(name); - - // now we should do - let parent_path = pipeline.output_dir().as_ref().unwrap(); - let chunk_dir = parent_path.join(name); - //remove_dir_all(&chunk_dir).unwrap(); - create_dir_all(&chunk_dir).unwrap(); - let pipeline = pipeline.with_output(chunk_dir, true); - - let jump_to_shutdown_routine = (0..length) - .map(|i| (i == start_of_shutdown_routine - 1).into()) - .collect(); - - let pipeline = pipeline.add_external_witness_values(vec![ - ( - "main_bootloader_inputs.value".to_string(), - bootloader_inputs, - ), - ( - "main.jump_to_shutdown_routine".to_string(), - jump_to_shutdown_routine, - ), - ]); - pipeline_callback(pipeline) -} +// pub fn zkvm_generate_chunks( +// workspace: &str, +// suite_json: &String, +// output_path: &str, +// ) -> Result, u64)>> { +// log::debug!("Compiling Rust..."); +// let force_overwrite = true; +// let with_bootloader = true; +// let (asm_file_path, asm_contents) = compile_rust::( +// workspace, +// Path::new(output_path), +// force_overwrite, +// &Runtime::base().with_poseidon(), +// false, +// with_bootloader, +// ) +// .ok_or_else(|| vec!["could not compile rust".to_string()]) +// .unwrap(); + +// let mut pipeline = Pipeline::::default() +// .with_output(output_path.into(), true) +// .from_asm_string(asm_contents.clone(), Some(asm_file_path.clone())) +// .with_prover_inputs(Default::default()) +// .add_data(TEST_CHANNEL, suite_json); + +// log::debug!("Running powdr-riscv executor in fast mode..."); +// pipeline.compute_fixed_cols().unwrap(); + +// /* +// let (trace, _mem) = powdr::riscv_executor::execute::( +// &asm_contents, +// powdr::riscv_executor::MemoryState::new(), +// pipeline.data_callback().unwrap(), +// &default_input(&[]), +// powdr::riscv_executor::ExecMode::Fast, +// ); + +// log::debug!("Trace length: {}", trace.len); +// */ +// log::debug!("Running powdr-riscv executor in trace mode for continuations..."); +// let start = Instant::now(); + +// let bootloader_inputs = rust_continuations_dry_run(&mut pipeline, Default::default()); + +// let duration = start.elapsed(); +// log::debug!( +// "Trace executor took: {:?}, input size: {:?}", +// duration, +// bootloader_inputs.len() +// ); + +// Ok(bootloader_inputs) +// } + +// pub fn zkvm_prove_only( +// task: &str, +// suite_json: &String, +// bootloader_input: Vec, +// start_of_shutdown_routine: u64, +// i: usize, +// output_path: &str, +// ) -> Result> { +// log::debug!("Compiling Rust..."); +// let asm_file_path = Path::new(output_path).join(format!("{}.asm", task)); + +// let pipeline = Pipeline::::default() +// .with_output(output_path.into(), true) +// .from_asm_file(asm_file_path.clone()) +// .with_prover_inputs(Default::default()) +// .add_data(TEST_CHANNEL, suite_json); + +// log::debug!("Running witness generation and proof computation..."); +// let start = Instant::now(); + +// //TODO: if we clone it, we lost the information gained from this function +// let pipeline = rust_continuation( +// task, +// pipeline, +// generate_witness_and_prove, +// bootloader_input, +// start_of_shutdown_routine, +// i, +// ) +// .unwrap(); + +// let ids = generate_verifier(pipeline, output_path, task, i)?; + +// let duration = start.elapsed(); +// log::debug!( +// "Witness generation and proof computation took: {:?}", +// duration +// ); + +// Ok(ids) +// } + +// pub fn rust_continuation( +// task: &str, +// mut pipeline: Pipeline, +// pipeline_callback: PipelineCallback, +// bootloader_inputs: Vec, +// start_of_shutdown_routine: u64, +// i: usize, +// ) -> Result, E> +// where +// PipelineCallback: Fn(Pipeline) -> Result, E>, +// { +// let fixed_cols = pipeline.compute_fixed_cols().unwrap(); + +// // Advance the pipeline to the optimized PIL stage, so that it doesn't need to be computed +// // in every chunk. +// pipeline.compute_optimized_pil().unwrap(); + +// let length = get_uniquely_sized(&fixed_cols) +// .unwrap() +// .iter() +// .find(|(col, _)| col == "main.STEP") +// .unwrap() +// .1 +// .len() as u64; + +// let name = format!("{}_chunk_{}", task, i); +// log::debug!("\nRunning chunk {} in {}...", i + 1, name); + +// // we used to do +// //let pipeline = pipeline.with_name(name); + +// // now we should do +// let parent_path = pipeline.output_dir().as_ref().unwrap(); +// let chunk_dir = parent_path.join(name); +// //remove_dir_all(&chunk_dir).unwrap(); +// create_dir_all(&chunk_dir).unwrap(); +// let pipeline = pipeline.with_output(chunk_dir, true); + +// let jump_to_shutdown_routine = (0..length) +// .map(|i| (i == start_of_shutdown_routine - 1).into()) +// .collect(); + +// let pipeline = pipeline.add_external_witness_values(vec![ +// ( +// "main_bootloader_inputs.value".to_string(), +// bootloader_inputs, +// ), +// ( +// "main.jump_to_shutdown_routine".to_string(), +// jump_to_shutdown_routine, +// ), +// ]); +// pipeline_callback(pipeline) +// } #[cfg(test)] mod tests { use super::*; - use num_traits::identities::Zero; - use std::io::{Read, Write}; + // use num_traits::identities::Zero; + // use std::io::{Read, Write}; // RUST_MIN_STACK=2073741821 RUST_LOG=debug nohup cargo test --release test_zkvm_prove -- --nocapture & - #[test] - #[ignore] - fn test_zkvm_prove() { - env_logger::try_init().unwrap_or_default(); - let test_file = "test-vectors/reth.block.json"; - let suite_json = fs::read_to_string(test_file).unwrap(); + // #[test] + // #[ignore] + // fn test_zkvm_prove() { + // env_logger::try_init().unwrap_or_default(); + // let test_file = "test-vectors/reth.block.json"; + // let suite_json = fs::read_to_string(test_file).unwrap(); - zkvm_execute_and_prove("evm", suite_json, "/tmp/test_evm").unwrap(); - } + // zkvm_execute_and_prove("evm", suite_json, "/tmp/test_evm").unwrap(); + // } #[test] fn test_zkvm_lr_prove() { @@ -417,61 +407,74 @@ mod tests { zkvm_execute_and_prove("lr", "".to_string(), "/tmp/test_lr").unwrap(); } + #[test] + fn test_zkvm_keccak_prove() { + env_logger::try_init().unwrap_or_default(); + zkvm_execute_and_prove("keccak", "".to_string(), "/tmp/test_keccak").unwrap(); + } + #[test] #[ignore] - fn test_zkvm_lr_execute_then_prove() { + fn test_zkvm_ark_prove() { env_logger::try_init().unwrap_or_default(); - let test_file = "test-vectors/reth.block.json"; - let suite_json = fs::read_to_string(test_file).unwrap(); - - let task = "evm"; - let output_path = "/tmp/test_evm"; - let workspace = format!("program/{}", task); - let bootloader_inputs = - zkvm_generate_chunks(workspace.as_str(), &suite_json, output_path).unwrap(); - // save the chunks - let bi_files: Vec<_> = (0..bootloader_inputs.len()) - .map(|i| Path::new(output_path).join(format!("{task}_chunks_{i}.data"))) - .collect(); - bootloader_inputs - .iter() - .zip(&bi_files) - .for_each(|(data, filename)| { - let mut f = fs::File::create(filename).unwrap(); - // write the start_of_shutdown_routine - f.write_all(&data.1.to_le_bytes()).unwrap(); - for d in &data.0 { - f.write_all(&d.to_bytes_le()[0..8]).unwrap(); - } - }); - - // load each chunk, generate witness and prove - bi_files.iter().enumerate().for_each(|(i, filename)| { - let mut f = fs::File::open(filename).unwrap(); - let metadata = fs::metadata(filename).unwrap(); - let file_size = metadata.len() as usize; - assert!(file_size % 8 == 0); - // read the start_of_shutdown_routine - let mut buffer = [0u8; 8]; - f.read_exact(&mut buffer).unwrap(); - let start_of_shutdown_routine: u64 = u64::from_le_bytes(buffer); - let file_size = file_size - 8; - let mut buffer = vec![0; file_size]; - f.read_exact(&mut buffer).unwrap(); - let mut bi = vec![GoldilocksField::zero(); file_size / 8]; - bi.iter_mut().zip(buffer.chunks(8)).for_each(|(out, bin)| { - *out = GoldilocksField::from_bytes_le(bin); - }); - - zkvm_prove_only( - task, - &suite_json, - bi, - start_of_shutdown_routine, - i, - output_path, - ) - .unwrap(); - }); + zkvm_execute_and_prove("ark", "".to_string(), "/tmp/test_ark").unwrap(); } + + // #[test] + // #[ignore] + // fn test_zkvm_lr_execute_then_prove() { + // env_logger::try_init().unwrap_or_default(); + // let test_file = "test-vectors/reth.block.json"; + // let suite_json = fs::read_to_string(test_file).unwrap(); + + // let task = "evm"; + // let output_path = "/tmp/test_evm"; + // let workspace = format!("program/{}", task); + // let bootloader_inputs = + // zkvm_generate_chunks(workspace.as_str(), &suite_json, output_path).unwrap(); + // // save the chunks + // let bi_files: Vec<_> = (0..bootloader_inputs.len()) + // .map(|i| Path::new(output_path).join(format!("{task}_chunks_{i}.data"))) + // .collect(); + // bootloader_inputs + // .iter() + // .zip(&bi_files) + // .for_each(|(data, filename)| { + // let mut f = fs::File::create(filename).unwrap(); + // // write the start_of_shutdown_routine + // f.write_all(&data.1.to_le_bytes()).unwrap(); + // for d in &data.0 { + // f.write_all(&d.to_bytes_le()[0..8]).unwrap(); + // } + // }); + + // // load each chunk, generate witness and prove + // bi_files.iter().enumerate().for_each(|(i, filename)| { + // let mut f = fs::File::open(filename).unwrap(); + // let metadata = fs::metadata(filename).unwrap(); + // let file_size = metadata.len() as usize; + // assert!(file_size % 8 == 0); + // // read the start_of_shutdown_routine + // let mut buffer = [0u8; 8]; + // f.read_exact(&mut buffer).unwrap(); + // let start_of_shutdown_routine: u64 = u64::from_le_bytes(buffer); + // let file_size = file_size - 8; + // let mut buffer = vec![0; file_size]; + // f.read_exact(&mut buffer).unwrap(); + // let mut bi = vec![GoldilocksField::zero(); file_size / 8]; + // bi.iter_mut().zip(buffer.chunks(8)).for_each(|(out, bin)| { + // *out = GoldilocksField::from_bytes_le(bin); + // }); + + // zkvm_prove_only( + // task, + // &suite_json, + // bi, + // start_of_shutdown_routine, + // i, + // output_path, + // ) + // .unwrap(); + // }); + // } }