Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed May 19, 2024
1 parent 94fa251 commit c99826f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
35 changes: 11 additions & 24 deletions acvm-repo/acvm_js/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ pub async fn execute_circuit(
) -> Result<JsWitnessMap, Error> {
console_error_panic_hook::set_once();

let mut witness_stack = execute_program_with_native_type_return(
program,
initial_witness,
&foreign_call_handler,
)
.await?;
let mut witness_stack =
execute_program_with_native_type_return(program, initial_witness, &foreign_call_handler)
.await?;
let witness_map =
witness_stack.pop().expect("Should have at least one witness on the stack").witness;
Ok(witness_map.into())
Expand Down Expand Up @@ -111,12 +108,9 @@ pub async fn execute_circuit_with_black_box_solver(
) -> Result<JsWitnessMap, Error> {
console_error_panic_hook::set_once();

let mut witness_stack = execute_program_with_native_type_return(
program,
initial_witness,
&foreign_call_handler,
)
.await?;
let mut witness_stack =
execute_program_with_native_type_return(program, initial_witness, &foreign_call_handler)
.await?;
let witness_map =
witness_stack.pop().expect("Should have at least one witness on the stack").witness;
Ok(witness_map.into())
Expand All @@ -143,12 +137,9 @@ pub async fn execute_program_with_black_box_solver(
initial_witness: JsWitnessMap,
foreign_call_executor: &ForeignCallHandler,
) -> Result<JsWitnessStack, Error> {
let witness_stack = execute_program_with_native_type_return(
program,
initial_witness,
foreign_call_executor,
)
.await?;
let witness_stack =
execute_program_with_native_type_return(program, initial_witness, foreign_call_executor)
.await?;

Ok(witness_stack.into())
}
Expand All @@ -164,12 +155,8 @@ async fn execute_program_with_native_type_return(
None,
None))?;

execute_program_with_native_program_and_return(
&program,
initial_witness,
foreign_call_executor,
)
.await
execute_program_with_native_program_and_return(&program, initial_witness, foreign_call_executor)
.await
}

async fn execute_program_with_native_program_and_return(
Expand Down
10 changes: 7 additions & 3 deletions acvm-repo/bn254_blackbox_solver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use ark_ec::AffineRepr;
pub use embedded_curve_ops::{embedded_curve_add, multi_scalar_mul};
pub use poseidon2::poseidon2_permutation;


#[derive(Default)]
pub struct Bn254BlackBoxSolver;

Expand All @@ -30,8 +29,13 @@ impl BlackBoxFunctionSolver for Bn254BlackBoxSolver {
let sig_s: [u8; 32] = signature[0..32].try_into().unwrap();
let sig_e: [u8; 32] = signature[32..64].try_into().unwrap();

Ok(schnorr::verify_signature(public_key_x.into_repr(),
public_key_y.into_repr(), sig_s, sig_e, message))
Ok(schnorr::verify_signature(
public_key_x.into_repr(),
public_key_y.into_repr(),
sig_s,
sig_e,
message,
))
}

fn pedersen_commitment(
Expand Down
15 changes: 10 additions & 5 deletions acvm-repo/bn254_blackbox_solver/src/schnorr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ark_ec::{
short_weierstrass::{Affine, SWCurveConfig},
AffineRepr, CurveConfig, CurveGroup,
};
use ark_ff::{PrimeField, Zero, BigInteger};
use ark_ff::{BigInteger, PrimeField, Zero};
use grumpkin::{Fq, GrumpkinParameters};

pub(crate) fn verify_signature(
Expand All @@ -15,13 +15,18 @@ pub(crate) fn verify_signature(
) -> bool {
let pub_key = Affine::<GrumpkinParameters>::new_unchecked(pub_key_x, pub_key_y);

// TODO: Check for correct subgroup isn't done in Barretenberg, is it necessary?
if !pub_key.is_on_curve() || !pub_key.is_in_correct_subgroup_assuming_on_curve() || pub_key.is_zero() {
// TODO: Check for correct subgroup isn't done in Barretenberg, is it necessary?
if !pub_key.is_on_curve()
|| !pub_key.is_in_correct_subgroup_assuming_on_curve()
|| pub_key.is_zero()
{
return false;
}

let sig_s = <GrumpkinParameters as CurveConfig>::ScalarField::from_be_bytes_mod_order(&sig_s_bytes);
let sig_e = <GrumpkinParameters as CurveConfig>::ScalarField::from_be_bytes_mod_order(&sig_e_bytes);
let sig_s =
<GrumpkinParameters as CurveConfig>::ScalarField::from_be_bytes_mod_order(&sig_s_bytes);
let sig_e =
<GrumpkinParameters as CurveConfig>::ScalarField::from_be_bytes_mod_order(&sig_e_bytes);

if sig_s.is_zero() || sig_e.is_zero() {
return false;
Expand Down

0 comments on commit c99826f

Please sign in to comment.