504 using FqNative = Curve::BaseFieldNative;
505 using FrNative = Curve::ScalarFieldNative;
506 using G1Native = Curve::GroupNative;
508 using Builder = Curve::Builder;
515 const std::array<uint8_t, 32> pub_x_bytes = { 0x2f, 0x8b, 0xde, 0x4d, 0x1a, 0x07, 0x20, 0x93, 0x55, 0xb4, 0xa7,
516 0x25, 0x0a, 0x5c, 0x51, 0x28, 0xe8, 0x8b, 0x84, 0xbd, 0xdc, 0x61,
517 0x9a, 0xb7, 0xcb, 0xa8, 0xd5, 0x69, 0xb2, 0x40, 0xef, 0xe4 };
518 const std::array<uint8_t, 32> pub_y_bytes = { 0xd8, 0xac, 0x22, 0x26, 0x36, 0xe5, 0xe3, 0xd6, 0xd4, 0xdb, 0xa9,
519 0xdd, 0xa6, 0xc9, 0xc4, 0x26, 0xf7, 0x88, 0x27, 0x1b, 0xab, 0x0d,
520 0x68, 0x40, 0xdc, 0xa8, 0x7d, 0x3a, 0xa6, 0xac, 0x62, 0xd6 };
521 const std::array<uint8_t, 32> r_bytes = { 0xa8, 0x41, 0x94, 0xc3, 0x71, 0xc6, 0x7b, 0xa2, 0x59, 0x2f, 0x59,
522 0xc6, 0x20, 0xad, 0x30, 0x4c, 0xb7, 0x6d, 0x7a, 0x88, 0x25, 0x6b,
523 0xb5, 0x0d, 0xc4, 0x1c, 0x66, 0x57, 0x44, 0xbf, 0x78, 0x61 };
524 const std::array<uint8_t, 32> s_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
525 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
526 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64 };
527 const std::array<uint8_t, 32> z_bytes = { 0xb6, 0xb8, 0x18, 0x2e, 0xc7, 0x1f, 0x95, 0xd4, 0x42, 0x13, 0x3f,
528 0x21, 0x5c, 0x9e, 0x0e, 0x7b, 0x55, 0x98, 0x0e, 0xf2, 0x02, 0x07,
529 0xf7, 0xaa, 0x2a, 0xbb, 0x7a, 0x7e, 0xe9, 0x1b, 0xab, 0x1f };
531 FqNative pub_x = FqNative::serialize_from_buffer(pub_x_bytes.data());
532 FqNative pub_y = FqNative::serialize_from_buffer(pub_y_bytes.data());
533 typename G1Native::affine_element public_key_native(pub_x, pub_y);
534 ASSERT_TRUE(public_key_native.on_curve()) <<
"Public key must be on curve";
537 const std::string message_string(z_bytes.begin(), z_bytes.end());
542 bool native_verification =
543 ecdsa_verify_signature<Sha256Hasher, FqNative, FrNative, G1Native>(message_string, public_key_native, sig);
545 bool stdlib_verification;
549 const G1Stdlib public_key_ct = G1Stdlib::from_witness(&
builder, public_key_native);
551 const std::vector<uint8_t> r_vec(r_bytes.begin(), r_bytes.end());
552 const std::vector<uint8_t> s_vec(s_bytes.begin(), s_bytes.end());
556 const std::vector<uint8_t> z_vec(z_bytes.begin(), z_bytes.end());
560 stdlib::ecdsa_verify_signature<Builder, Curve, FqStdlib, FrStdlib, G1Stdlib>(
561 hashed_message_ct, public_key_ct, sig_ct);
563 stdlib_verification = signature_result.
get_value();
568 ASSERT_TRUE(circuit_valid);
572 EXPECT_FALSE(native_verification);
573 EXPECT_FALSE(stdlib_verification);
574 EXPECT_EQ(native_verification, stdlib_verification);
581 using FqNative = Curve::BaseFieldNative;
582 using FrNative = Curve::ScalarFieldNative;
583 using G1Native = Curve::GroupNative;
585 using Builder = Curve::Builder;
590 const std::array<uint8_t, 32> pub_x_bytes = { 0x79, 0x9f, 0x2a, 0xba, 0xfa, 0x27, 0x16, 0x4b, 0x09, 0x50, 0xf2,
591 0xc8, 0x82, 0xf0, 0xd1, 0x67, 0xe1, 0xd2, 0x16, 0x74, 0x87, 0xd5,
592 0x2e, 0xa7, 0x23, 0x0b, 0x5d, 0x96, 0xc2, 0xa8, 0x74, 0x00 };
593 const std::array<uint8_t, 32> pub_y_bytes = { 0xda, 0xa5, 0x79, 0xf4, 0xf1, 0x61, 0xe9, 0xdc, 0xa1, 0xa1, 0x34,
594 0x35, 0x92, 0x16, 0xb9, 0x35, 0xea, 0xd0, 0x97, 0x2d, 0x76, 0x3f,
595 0xe3, 0x33, 0xc7, 0x12, 0xee, 0x8d, 0x18, 0x4b, 0xd8, 0x11 };
596 const std::array<uint8_t, 32> r_bytes = { 0xb1, 0x99, 0xa1, 0x62, 0x72, 0x66, 0x61, 0xba, 0x23, 0x3c, 0xd6,
597 0xc6, 0x6e, 0x99, 0x0b, 0x01, 0x2e, 0x1e, 0x76, 0x04, 0xb1, 0x1f,
598 0x76, 0x19, 0x3b, 0x2a, 0xf5, 0xca, 0x36, 0xc1, 0x01, 0x76 };
599 const std::array<uint8_t, 32> s_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
600 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
601 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05 };
602 const std::array<uint8_t, 32> z_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
603 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
604 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05 };
606 const FqNative pub_x = FqNative::serialize_from_buffer(pub_x_bytes.data());
607 const FqNative pub_y = FqNative::serialize_from_buffer(pub_y_bytes.data());
608 const typename G1Native::affine_element public_key_native(pub_x, pub_y);
609 ASSERT_TRUE(public_key_native.on_curve()) <<
"Public key must be on curve";
612 const std::string message_string(z_bytes.begin(), z_bytes.end());
617 bool native_verification =
618 ecdsa_verify_signature<Sha256Hasher, FqNative, FrNative, G1Native>(message_string, public_key_native, sig);
622 const G1Stdlib public_key_ct = G1Stdlib::from_witness(&
builder, public_key_native);
624 const std::vector<uint8_t> r_vec(r_bytes.begin(), r_bytes.end());
625 const std::vector<uint8_t> s_vec(s_bytes.begin(), s_bytes.end());
629 const std::vector<uint8_t> z_vec(z_bytes.begin(), z_bytes.end());
633 stdlib::ecdsa_verify_signature<Builder, Curve, FqStdlib, FrStdlib, G1Stdlib>(
634 hashed_message_ct, public_key_ct, sig_ct);
636 bool stdlib_verification = signature_result.
get_value();
639 ASSERT_TRUE(circuit_valid);
641 EXPECT_EQ(native_verification, stdlib_verification);
648 using FqNative = Curve::BaseFieldNative;
649 using G1Native = Curve::GroupNative;
651 using Builder = Curve::Builder;
656 const std::array<uint8_t, 32> pub_x_bytes = { 0xbd, 0xae, 0xdd, 0xff, 0x80, 0x69, 0x8b, 0xd0, 0xb5, 0xdb, 0x79,
657 0x10, 0xe1, 0xc6, 0x56, 0x9d, 0xc3, 0x4e, 0x77, 0x3b, 0xda, 0x69,
658 0x5e, 0x61, 0x5c, 0x87, 0xf5, 0x4e, 0x6a, 0x70, 0x7e, 0xd6 };
659 const std::array<uint8_t, 32> pub_y_bytes = { 0xc1, 0xb3, 0x69, 0x9c, 0x7e, 0xea, 0x97, 0xbe, 0x5e, 0x52, 0x3d,
660 0x47, 0x5c, 0x5f, 0x72, 0x00, 0x97, 0x2c, 0x61, 0x23, 0xf2, 0xcd,
661 0x3d, 0x59, 0x33, 0x54, 0xe7, 0x4d, 0x35, 0xd1, 0x85, 0x11 };
662 const std::array<uint8_t, 32> r_bytes = { 0x4d, 0xc6, 0x6f, 0x06, 0x26, 0x12, 0x5d, 0x49, 0xb5, 0xa7, 0x7d,
663 0x36, 0xc3, 0xf9, 0x7e, 0x9b, 0xb8, 0x29, 0x48, 0xf2, 0xbd, 0xdc,
664 0xf8, 0x43, 0xe5, 0xee, 0x13, 0x3c, 0xc8, 0x96, 0xf1, 0xd8 };
665 const std::array<uint8_t, 32> s_bytes = { 0x52, 0x59, 0x33, 0x34, 0x92, 0xf6, 0x68, 0x42, 0x1a, 0xe0, 0x63,
666 0x3f, 0x2d, 0x16, 0x92, 0x4b, 0x9f, 0x3b, 0xe9, 0x36, 0xee, 0xd3,
667 0xf1, 0x96, 0x28, 0x6e, 0x0a, 0x57, 0x5d, 0xe2, 0x9f, 0xb7 };
668 const std::array<uint8_t, 32> z_bytes = { 0x93, 0xd5, 0x0c, 0x3d, 0xd6, 0xd6, 0xc3, 0xf7, 0xf7, 0x55, 0x0e,
669 0x69, 0x76, 0x40, 0x2b, 0x89, 0xaa, 0xf2, 0xd6, 0x8a, 0x7a, 0x94,
670 0x80, 0x44, 0x69, 0xaa, 0x69, 0x03, 0x15, 0xb8, 0x64, 0x31 };
672 const FqNative pub_x = FqNative::serialize_from_buffer(pub_x_bytes.data());
673 const FqNative pub_y = FqNative::serialize_from_buffer(pub_y_bytes.data());
674 const typename G1Native::affine_element public_key_native(pub_x, pub_y);
675 ASSERT_TRUE(public_key_native.on_curve()) <<
"Public key must be on curve";
678 const G1Stdlib public_key_ct = G1Stdlib::from_witness(&
builder, public_key_native);
680 const std::vector<uint8_t> r_vec(r_bytes.begin(), r_bytes.end());
681 const std::vector<uint8_t> s_vec(s_bytes.begin(), s_bytes.end());
685 const std::vector<uint8_t> z_vec(z_bytes.begin(), z_bytes.end());
689 stdlib::ecdsa_verify_signature<Builder, Curve, FqStdlib, FrStdlib, G1Stdlib>(
690 hashed_message_ct, public_key_ct, sig_ct);
693 EXPECT_TRUE(signature_result.
get_value());
696 ASSERT_TRUE(circuit_valid);
707 using Builder = Curve::Builder;
708 using FqNative = Curve::BaseFieldNative;
709 using FrNative = Curve::ScalarFieldNative;
710 using G1Native = Curve::GroupNative;
717 const FrNative d(
"0xd67abee717b3fc725adf59e2cc8cd916435c348b277dd814a34e3ceb279436c2");
718 const G1Native::affine_element Q = G1Native::one * d;
722 for (uint64_t seed = 1; seed < 100; ++seed) {
724 const G1Native::affine_element R(G1Native::one * k);
726 if (r != FrNative::zero() &&
uint256_t(r) < half_n_plus_one) {
730 ASSERT_NE(r, FrNative::zero());
731 ASSERT_LT(
uint256_t(r), half_n_plus_one);
734 const FrNative s = r;
735 const FrNative z = r * (k - d);
736 const FrNative s_inv = s.invert();
737 ASSERT_EQ(r * s_inv, FrNative::one());
741 const FrNative u1 = z * s_inv;
742 const FrNative u2 = r * s_inv;
743 const G1Native::affine_element R_native(G1Native::one * u1 + G1Native::element(Q) * u2);
744 ASSERT_FALSE(R_native.is_point_at_infinity());
745 EXPECT_EQ(FrNative(
uint256_t(R_native.x)), r);
749 G1Stdlib public_key_ct = G1Stdlib::from_witness(&
builder, Q);
751 std::array<uint8_t, 32> r_bytes;
752 std::array<uint8_t, 32> s_bytes;
753 std::array<uint8_t, 32> z_bytes;
754 FrNative::serialize_to_buffer(r, r_bytes.data());
755 FrNative::serialize_to_buffer(s, s_bytes.data());
756 FqNative::serialize_to_buffer(FqNative(
uint256_t(z)), z_bytes.data());
758 const std::vector<uint8_t> r_vec(r_bytes.begin(), r_bytes.end());
759 const std::vector<uint8_t> s_vec(s_bytes.begin(), s_bytes.end());
760 const std::vector<uint8_t> z_vec(z_bytes.begin(), z_bytes.end());
765 bool_t
result = stdlib::ecdsa_verify_signature<Builder, Curve, FqStdlib, FrStdlib, G1Stdlib>(
766 hashed_message, public_key_ct, sig_ct);
767 EXPECT_FALSE(
result.get_value()) <<
"circuit must reject honest u₂ ≡ 1";