diff --git a/Cargo.lock b/Cargo.lock index e129feec..e1952568 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -367,7 +367,7 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "ashlang" version = "0.1.3" -source = "git+https://github.com/chancehudson/ashlang.git#6fcb8a1461be2f2fede390faf740e002d90ce9c2" +source = "git+https://github.com/chancehudson/ashlang.git?branch=main#696960a0c15db47170fdd1ff058682023d904b1b" dependencies = [ "anyhow", "camino", diff --git a/mopro-ffi/Cargo.toml b/mopro-ffi/Cargo.toml index a52d0846..6edd7a1d 100644 --- a/mopro-ffi/Cargo.toml +++ b/mopro-ffi/Cargo.toml @@ -46,8 +46,8 @@ thiserror = "=1.0.39" color-eyre = "=0.6.2" # ashlang deps -#ashlang = { path = "../../ashlang/ashlang", optional = true } -ashlang = { git = "https://github.com/chancehudson/ashlang.git", optional = true, default-features = false, features = ["spartan-prover", "serde"] } +#ashlang = { path = "../../ashlang/ashlang", optional = true, default-features = false, features = ["spartan-prover", "serde"] } +ashlang = { git = "https://github.com/chancehudson/ashlang.git", branch = "main", optional = true, default-features = false, features = ["spartan-prover", "serde"] } #ashlang = { version = "0.1.0", optional = true, default-features = false, features = ["spartan-prover"] } #scalarff = { git = "https://github.com/chancehudson/scalarff.git", branch = "no-twenty-first", optional = true } diff --git a/mopro-ffi/src/ashlang/mod.rs b/mopro-ffi/src/ashlang/mod.rs index b8c216f9..eeb65459 100644 --- a/mopro-ffi/src/ashlang/mod.rs +++ b/mopro-ffi/src/ashlang/mod.rs @@ -12,7 +12,7 @@ macro_rules! ashlang_spartan_app { ar1cs_path: String, // path to ar1cs file secret_inputs: Vec, ) -> Result { - mopro_ffi::ashlang::prove(ar1cs_path, secret_inputs).map_err(|e| { + mopro_ffi::ashlang::prove(&ar1cs_path, secret_inputs).map_err(|e| { mopro_ffi::MoproError::AshlangError( "error generating ashlang spartan proof".to_string(), ) @@ -23,18 +23,20 @@ macro_rules! ashlang_spartan_app { ar1cs_path: String, proof: Vec, ) -> Result { - mopro_ffi::ashlang::verify(ar1cs_path, proof).map_err(|e| { + mopro_ffi::ashlang::verify(&ar1cs_path, proof).map_err(|e| { mopro_ffi::MoproError::AshlangError("error verifying proof".to_string()) }) } }; } +/// Generates a spartan proof from an ar1cs file compiled +/// with the ashlang compiler. pub fn prove( - ar1cs_path: String, // path to ar1cs file + ar1cs_path: &str, // path to ar1cs file secret_inputs: Vec, ) -> anyhow::Result { - let ir_source = fs::read_to_string(&ar1cs_path)?; + let ir_source = fs::read_to_string(ar1cs_path)?; // we pass an empty vec for public inputs because // they are not supported in the ashlang spartan prover // outputs are public and should be used instead @@ -46,10 +48,12 @@ pub fn prove( }) } -/// TODO: build gens params from ar1cs file/confirm that a proof is for the -/// expected ar1cs file -pub fn verify(_ar1cs_path: String, proof: Vec) -> anyhow::Result { - ashlang::SpartanProver::verify(bincode::deserialize(&proof)?) +/// Verifies a spartan proof from an ar1cs file +pub fn verify(ar1cs_path: &str, proof: Vec) -> anyhow::Result { + let ir_source = fs::read_to_string(ar1cs_path)?; + let p = bincode::deserialize(&proof)?; + ashlang::SpartanProver::verify(&ir_source, p) + // Ok(true) } #[cfg(test)] @@ -58,13 +62,9 @@ mod tests { #[test] fn test_ashlang_prove_verify() -> anyhow::Result<()> { - let proof = prove( - "../test-vectors/ashlang/example.ar1cs".to_string(), - vec!["55".to_string()], - )?; - - ashlang::SpartanProver::verify(bincode::deserialize(&proof.proof)?)?; - + let ar1cs_path = "../test-vectors/ashlang/example.ar1cs".to_string(); + let proof = prove(&ar1cs_path, vec!["55".to_string()])?; + verify(&ar1cs_path, proof.proof)?; Ok(()) } }