40 const std::string& value_label,
41 const std::string& max_value_label) {
43 "The " + value_label +
" is bigger than " + max_value_label +
". This will produce an unsatisfied circuit.";
44 if (
value >= max_value) {
49 auto check_is_not_zero = [](
const uint512_t&
value,
const std::string& label) {
50 std::string msg =
"The " + label +
" is equal to zero. This will produce an unsatisfied circuit.";
58 check_smaller_than(hash_value,
Fr::modulus,
"hash of the message",
"order of the elliptic curve");
61 if (!public_key.get_value().on_curve()) {
62 info(
"The public key is not a point on the elliptic curve. This will produce an unsatisfied circuit.");
67 check_smaller_than(r_value,
Fr::modulus,
"r component of the signature",
"order of the elliptic curve");
68 check_is_not_zero(r_value,
"r component of the signature");
72 check_smaller_than(s_value, (
Fr::modulus + 1) / 2,
"s component of the signature",
"order of the elliptic curve");
73 check_is_not_zero(s_value,
"s component of the signature");
129 const G1& public_key,
133 validate_inputs<Builder, Curve, Fq, Fr>(hashed_message, public_key, sig);
136 bool message_is_not_constant = hashed_message.
get_context() !=
nullptr;
137 bool public_key_is_not_constant = public_key.get_context() !=
nullptr;
138 bool sig_is_not_constant = sig.
get_context() !=
nullptr;
139 BB_ASSERT_EQ(message_is_not_constant || public_key_is_not_constant || sig_is_not_constant,
141 "At least one of the inputs should be non-constant.");
144 if (message_is_not_constant) {
146 }
else if (public_key_is_not_constant) {
147 ctx = public_key.get_context();
148 }
else if (sig_is_not_constant) {
152 "At least one of the inputs passed should be non-constant. Assert failed to catch this condition.");
160 Fr z(hashed_message);
161 z.assert_is_in_field();
164 public_key.validate_on_curve();
168 r.assert_is_in_field();
177 Fr u1 = z.div_without_denominator_check(s);
178 Fr u2 = r.div_without_denominator_check(s);
182 result = G1::secp256k1_ecdsa_mul(public_key, u1, u2);
184 result = G1::batch_mul({ G1::one(ctx), public_key }, { u1, u2 });
188 if (result.get_value().is_point_at_infinity()) {
189 info(
"The result of the batch multiplication is the point at infinity. This will produce an unsatisfied "
197 result.x.self_reduce();
200 Fr result_x_mod_r = Fr::unsafe_construct_from_limbs(result.x.binary_basis_limbs[0].element,
201 result.x.binary_basis_limbs[1].element,
202 result.x.binary_basis_limbs[2].element,
203 result.x.binary_basis_limbs[3].element);
205 for (
size_t idx = 0; idx < 4; idx++) {
206 result_x_mod_r.binary_basis_limbs[idx].maximum_value = result.x.binary_basis_limbs[idx].maximum_value;
214 info(
"Signature verification succeeded.");
216 info(
"Signature verification failed");
219 return is_signature_valid;
234 using FrNative =
typename Curve::fr;
235 using FqNative =
typename Curve::fq;
236 using G1Native =
typename Curve::g1;
239 using Fr =
typename Curve::bigfr_ct;
240 using Fq =
typename Curve::fq_ct;
241 using G1 =
typename Curve::g1_bigfr_ct;
243 std::string message_string =
"Instructions unclear, ask again later.";
246 for (
size_t i = 0; i < num_iterations; i++) {
252 crypto::ecdsa_construct_signature<crypto::Sha256Hasher, FqNative, FrNative, G1Native>(message_string,
255 bool native_verification = crypto::ecdsa_verify_signature<crypto::Sha256Hasher, FqNative, FrNative, G1Native>(
256 message_string, account.
public_key, signature);
257 BB_ASSERT_EQ(native_verification,
true,
"Native ECDSA verification failed while generating test circuit.");
259 std::vector<uint8_t> rr(signature.
r.begin(), signature.
r.end());
260 std::vector<uint8_t> ss(signature.
s.begin(), signature.
s.end());
274 stdlib::ecdsa_verify_signature<Builder, Curve, Fq, Fr, G1>(hashed_message, public_key, sig);
bool_t< Builder > ecdsa_verify_signature(const stdlib::byte_array< Builder > &hashed_message, const G1 &public_key, const ecdsa_signature< Builder > &sig)
Verify ECDSA signature. Returns bool_t(true/false) depending on whether the signature is valid or not...
void validate_inputs(const stdlib::byte_array< Builder > &hashed_message, const G1 &public_key, const ecdsa_signature< Builder > &sig)
Validate the inputs used by the verification function and return messages if they produce an invalid ...