1
1
#include " ecdsa_secp256r1.hpp"
2
- #include " ecdsa_secp256k1.hpp"
3
2
#include " barretenberg/crypto/ecdsa/ecdsa.hpp"
4
3
#include " barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp"
4
+ #include " ecdsa_secp256k1.hpp"
5
5
6
6
namespace acir_format {
7
7
8
8
using namespace proof_system ::plonk;
9
9
10
- secp256r1_ct::g1_ct ecdsa_convert_inputs (Composer * ctx, const secp256r1::g1::affine_element& input)
10
+ secp256r1_ct::g1_ct ecdsa_convert_inputs (Builder * ctx, const secp256r1::g1::affine_element& input)
11
11
{
12
12
uint256_t x_u256 (input.x );
13
13
uint256_t y_u256 (input.y );
@@ -23,20 +23,20 @@ secp256r1_ct::g1_ct ecdsa_convert_inputs(Composer* ctx, const secp256r1::g1::aff
23
23
return { x, y };
24
24
}
25
25
26
- void create_ecdsa_r1_verify_constraints (Composer& composer ,
26
+ void create_ecdsa_r1_verify_constraints (Builder& builder ,
27
27
const EcdsaSecp256r1Constraint& input,
28
28
bool has_valid_witness_assignments)
29
29
{
30
30
31
31
if (has_valid_witness_assignments == false ) {
32
- dummy_ecdsa_constraint (composer , input);
32
+ dummy_ecdsa_constraint (builder , input);
33
33
}
34
34
35
- auto new_sig = ecdsa_convert_signature (composer , input.signature );
35
+ auto new_sig = ecdsa_convert_signature (builder , input.signature );
36
36
37
- auto message = ecdsa_vector_of_bytes_to_byte_array (composer , input.hashed_message );
38
- auto pub_key_x_byte_arr = ecdsa_vector_of_bytes_to_byte_array (composer , input.pub_x_indices );
39
- auto pub_key_y_byte_arr = ecdsa_vector_of_bytes_to_byte_array (composer , input.pub_y_indices );
37
+ auto message = ecdsa_vector_of_bytes_to_byte_array (builder , input.hashed_message );
38
+ auto pub_key_x_byte_arr = ecdsa_vector_of_bytes_to_byte_array (builder , input.pub_x_indices );
39
+ auto pub_key_y_byte_arr = ecdsa_vector_of_bytes_to_byte_array (builder , input.pub_y_indices );
40
40
41
41
auto pub_key_x_fq = secp256r1_ct::fq_ct (pub_key_x_byte_arr);
42
42
auto pub_key_y_fq = secp256r1_ct::fq_ct (pub_key_y_byte_arr);
@@ -45,39 +45,39 @@ void create_ecdsa_r1_verify_constraints(Composer& composer,
45
45
std::vector<uint8_t > ss (new_sig.s .begin (), new_sig.s .end ());
46
46
uint8_t vv = new_sig.v ;
47
47
48
- stdlib::ecdsa::signature<Composer > sig{ stdlib::byte_array<Composer >(&composer , rr),
49
- stdlib::byte_array<Composer >(&composer , ss),
50
- stdlib::uint8<Composer >(&composer , vv) };
48
+ stdlib::ecdsa::signature<Builder > sig{ stdlib::byte_array<Builder >(&builder , rr),
49
+ stdlib::byte_array<Builder >(&builder , ss),
50
+ stdlib::uint8<Builder >(&builder , vv) };
51
51
52
52
pub_key_x_fq.assert_is_in_field ();
53
53
pub_key_y_fq.assert_is_in_field ();
54
54
secp256r1_ct::g1_bigfr_ct public_key = secp256r1_ct::g1_bigfr_ct (pub_key_x_fq, pub_key_y_fq);
55
55
for (size_t i = 0 ; i < 32 ; ++i) {
56
- sig.r [i].assert_equal (field_ct::from_witness_index (&composer , input.signature [i]));
57
- sig.s [i].assert_equal (field_ct::from_witness_index (&composer , input.signature [i + 32 ]));
58
- pub_key_x_byte_arr[i].assert_equal (field_ct::from_witness_index (&composer , input.pub_x_indices [i]));
59
- pub_key_y_byte_arr[i].assert_equal (field_ct::from_witness_index (&composer , input.pub_y_indices [i]));
56
+ sig.r [i].assert_equal (field_ct::from_witness_index (&builder , input.signature [i]));
57
+ sig.s [i].assert_equal (field_ct::from_witness_index (&builder , input.signature [i + 32 ]));
58
+ pub_key_x_byte_arr[i].assert_equal (field_ct::from_witness_index (&builder , input.pub_x_indices [i]));
59
+ pub_key_y_byte_arr[i].assert_equal (field_ct::from_witness_index (&builder , input.pub_y_indices [i]));
60
60
}
61
61
for (size_t i = 0 ; i < input.hashed_message .size (); ++i) {
62
- message[i].assert_equal (field_ct::from_witness_index (&composer , input.hashed_message [i]));
62
+ message[i].assert_equal (field_ct::from_witness_index (&builder , input.hashed_message [i]));
63
63
}
64
64
65
65
bool_ct signature_result =
66
- stdlib::ecdsa::verify_signature_prehashed_message_noassert<Composer ,
66
+ stdlib::ecdsa::verify_signature_prehashed_message_noassert<Builder ,
67
67
secp256r1_ct,
68
68
secp256r1_ct::fq_ct,
69
69
secp256r1_ct::bigfr_ct,
70
70
secp256r1_ct::g1_bigfr_ct>(message, public_key, sig);
71
71
bool_ct signature_result_normalized = signature_result.normalize ();
72
- composer .assert_equal (signature_result_normalized.witness_index , input.result );
72
+ builder .assert_equal (signature_result_normalized.witness_index , input.result );
73
73
}
74
74
75
75
// Add dummy constraints for ECDSA because when the verifier creates the
76
76
// constraint system, they usually use zeroes for witness values.
77
77
//
78
78
// This does not work for ECDSA as the signature, r, s and public key need
79
79
// to be valid.
80
- void dummy_ecdsa_constraint (Composer& composer , EcdsaSecp256r1Constraint const & input)
80
+ void dummy_ecdsa_constraint (Builder& builder , EcdsaSecp256r1Constraint const & input)
81
81
{
82
82
83
83
std::vector<uint32_t > pub_x_indices_;
@@ -110,11 +110,11 @@ void dummy_ecdsa_constraint(Composer& composer, EcdsaSecp256r1Constraint const&
110
110
// We don't use them in a gate, so when we call assert_equal, they will be
111
111
// replaced as if they never existed.
112
112
for (size_t i = 0 ; i < 32 ; ++i) {
113
- uint32_t m_wit = composer .add_variable (hashed_message[i]);
114
- uint32_t x_wit = composer .add_variable (pub_x_value.slice (248 - i * 8 , 256 - i * 8 ));
115
- uint32_t y_wit = composer .add_variable (pub_y_value.slice (248 - i * 8 , 256 - i * 8 ));
116
- uint32_t r_wit = composer .add_variable (signature.r [i]);
117
- uint32_t s_wit = composer .add_variable (signature.s [i]);
113
+ uint32_t m_wit = builder .add_variable (hashed_message[i]);
114
+ uint32_t x_wit = builder .add_variable (pub_x_value.slice (248 - i * 8 , 256 - i * 8 ));
115
+ uint32_t y_wit = builder .add_variable (pub_y_value.slice (248 - i * 8 , 256 - i * 8 ));
116
+ uint32_t r_wit = builder .add_variable (signature.r [i]);
117
+ uint32_t s_wit = builder .add_variable (signature.s [i]);
118
118
message_indicies_.emplace_back (m_wit);
119
119
pub_x_indices_.emplace_back (x_wit);
120
120
pub_y_indices_.emplace_back (y_wit);
@@ -124,16 +124,16 @@ void dummy_ecdsa_constraint(Composer& composer, EcdsaSecp256r1Constraint const&
124
124
125
125
// Call assert_equal(from, to) to replace the value in `to` by the value in `from`
126
126
for (size_t i = 0 ; i < input.hashed_message .size (); ++i) {
127
- composer .assert_equal (message_indicies_[i], input.hashed_message [i]);
127
+ builder .assert_equal (message_indicies_[i], input.hashed_message [i]);
128
128
}
129
129
for (size_t i = 0 ; i < input.pub_x_indices .size (); ++i) {
130
- composer .assert_equal (pub_x_indices_[i], input.pub_x_indices [i]);
130
+ builder .assert_equal (pub_x_indices_[i], input.pub_x_indices [i]);
131
131
}
132
132
for (size_t i = 0 ; i < input.pub_y_indices .size (); ++i) {
133
- composer .assert_equal (pub_y_indices_[i], input.pub_y_indices [i]);
133
+ builder .assert_equal (pub_y_indices_[i], input.pub_y_indices [i]);
134
134
}
135
135
for (size_t i = 0 ; i < input.signature .size (); ++i) {
136
- composer .assert_equal (signature_[i], input.signature [i]);
136
+ builder .assert_equal (signature_[i], input.signature [i]);
137
137
}
138
138
}
139
139
0 commit comments