Skip to content

Commit

Permalink
Fix ecdsa private input
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Jan 11, 2024
1 parent 93ee579 commit a0f2eb7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions vm/src/vm/runners/builtin_runner/signature.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::air_private_input::{PrivateInput, PrivateInputSignature, SignatureInput};
use crate::math_utils::div_mod;
use crate::stdlib::{cell::RefCell, collections::HashMap, prelude::*, rc::Rc};

use crate::types::errors::math_errors::MathError;
Expand All @@ -19,16 +20,16 @@ use crate::{
},
};
use lazy_static::lazy_static;
use num_bigint::{BigInt, Sign};
use num_integer::div_ceil;
use num_traits::{Num, One};
use starknet_crypto::{verify, FieldElement, Signature};
use starknet_types_core::felt::NonZeroFelt;

lazy_static! {
static ref EC_ORDER: NonZeroFelt = Felt252::from_dec_str(
"3618502788666131213697322783095070105526743751716087489154079457884512865583"
static ref EC_ORDER: BigInt = BigInt::from_str_radix(
"3618502788666131213697322783095070105526743751716087489154079457884512865583",
10
)
.unwrap()
.try_into()
.unwrap();
}

Expand Down Expand Up @@ -256,9 +257,14 @@ impl SignatureBuiltinRunner {
msg: *msg,
signature_input: SignatureInput {
r: Felt252::from_bytes_be(&signature.r.to_bytes_be()),
w: Felt252::from_bytes_be(&signature.r.to_bytes_be())
.mod_inverse(&EC_ORDER)
w: Felt252::from(
&div_mod(
&BigInt::one(),
&BigInt::from_bytes_be(Sign::Plus, &signature.s.to_bytes_be()),
&EC_ORDER,
)
.unwrap_or_default(),
),
},
}))
}
Expand Down

0 comments on commit a0f2eb7

Please sign in to comment.