Skip to content

Commit

Permalink
fix: ashlang spartan proof verification
Browse files Browse the repository at this point in the history
  • Loading branch information
chancehudson committed Oct 22, 2024
1 parent ec3a008 commit c10b789
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions mopro-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
30 changes: 15 additions & 15 deletions mopro-ffi/src/ashlang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ macro_rules! ashlang_spartan_app {
ar1cs_path: String, // path to ar1cs file
secret_inputs: Vec<String>,
) -> Result<mopro_ffi::GenerateProofResult, mopro_ffi::MoproError> {
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(),
)
Expand All @@ -23,18 +23,20 @@ macro_rules! ashlang_spartan_app {
ar1cs_path: String,
proof: Vec<u8>,
) -> Result<bool, mopro_ffi::MoproError> {
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<String>,
) -> anyhow::Result<GenerateProofResult> {
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
Expand All @@ -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<u8>) -> anyhow::Result<bool> {
ashlang::SpartanProver::verify(bincode::deserialize(&proof)?)
/// Verifies a spartan proof from an ar1cs file
pub fn verify(ar1cs_path: &str, proof: Vec<u8>) -> anyhow::Result<bool> {
let ir_source = fs::read_to_string(ar1cs_path)?;
let p = bincode::deserialize(&proof)?;
ashlang::SpartanProver::verify(&ir_source, p)
// Ok(true)
}

#[cfg(test)]
Expand All @@ -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(())
}
}

0 comments on commit c10b789

Please sign in to comment.