Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cd ..
# - Generate a hash for versioning: sha256sum bb-civc-inputs.tar.gz
# - Upload the compressed results: aws s3 cp bb-civc-inputs.tar.gz s3://aztec-ci-artifacts/protocol/bb-civc-inputs-[hash(0:8)].tar.gz
# Note: In case of the "Test suite failed to run ... Unexpected token 'with' " error, need to run: docker pull aztecprotocol/build:3.0
pinned_short_hash="dba43b65"
pinned_short_hash="869efec4"
pinned_civc_inputs_url="https://aztec-ci-artifacts.s3.us-east-2.amazonaws.com/protocol/bb-civc-inputs-${pinned_short_hash}.tar.gz"

function compress_and_upload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void create_ecdsa_k1_verify_constraints(Builder& builder,

auto new_sig = ecdsa_convert_signature(builder, input.signature);

byte_array_ct message = ecdsa_array_of_bytes_to_byte_array(builder, input.hashed_message);
byte_array_ct hashed_message = ecdsa_array_of_bytes_to_byte_array(builder, input.hashed_message);
auto pub_key_x_byte_arr = ecdsa_array_of_bytes_to_byte_array(builder, input.pub_x_indices);
auto pub_key_y_byte_arr = ecdsa_array_of_bytes_to_byte_array(builder, input.pub_y_indices);

Expand All @@ -74,16 +74,15 @@ void create_ecdsa_k1_verify_constraints(Builder& builder,
pub_key_y_byte_arr[i].assert_equal(field_ct::from_witness_index(&builder, input.pub_y_indices[i]));
}
for (size_t i = 0; i < input.hashed_message.size(); ++i) {
message[i].assert_equal(field_ct::from_witness_index(&builder, input.hashed_message[i]));
hashed_message[i].assert_equal(field_ct::from_witness_index(&builder, input.hashed_message[i]));
}

bool_ct signature_result =
stdlib::ecdsa_verify_signature_prehashed_message_noassert<Builder,
secp256k1_ct,
typename secp256k1_ct::fq_ct,
typename secp256k1_ct::bigfr_ct,
typename secp256k1_ct::g1_bigfr_ct>(
message, public_key, sig);
stdlib::ecdsa_verify_signature<Builder,
secp256k1_ct,
typename secp256k1_ct::fq_ct,
typename secp256k1_ct::bigfr_ct,
typename secp256k1_ct::g1_bigfr_ct>(hashed_message, public_key, sig);
bool_ct signature_result_normalized = signature_result.normalize();
builder.assert_equal(signature_result_normalized.witness_index, input.result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void create_ecdsa_r1_verify_constraints(Builder& builder,

auto new_sig = ecdsa_convert_signature(builder, input.signature);

byte_array_ct message = ecdsa_array_of_bytes_to_byte_array(builder, input.hashed_message);
byte_array_ct hashed_message = ecdsa_array_of_bytes_to_byte_array(builder, input.hashed_message);
auto pub_key_x_byte_arr = ecdsa_array_of_bytes_to_byte_array(builder, input.pub_x_indices);
auto pub_key_y_byte_arr = ecdsa_array_of_bytes_to_byte_array(builder, input.pub_y_indices);

Expand All @@ -72,16 +72,15 @@ void create_ecdsa_r1_verify_constraints(Builder& builder,
pub_key_y_byte_arr[i].assert_equal(field_ct::from_witness_index(&builder, input.pub_y_indices[i]));
}
for (size_t i = 0; i < input.hashed_message.size(); ++i) {
message[i].assert_equal(field_ct::from_witness_index(&builder, input.hashed_message[i]));
hashed_message[i].assert_equal(field_ct::from_witness_index(&builder, input.hashed_message[i]));
}

bool_ct signature_result =
stdlib::ecdsa_verify_signature_prehashed_message_noassert<Builder,
secp256r1_ct,
typename secp256r1_ct::fq_ct,
typename secp256r1_ct::bigfr_ct,
typename secp256r1_ct::g1_bigfr_ct>(
message, public_key, sig);
stdlib::ecdsa_verify_signature<Builder,
secp256r1_ct,
typename secp256r1_ct::fq_ct,
typename secp256r1_ct::bigfr_ct,
typename secp256r1_ct::g1_bigfr_ct>(hashed_message, public_key, sig);
bool_ct signature_result_normalized = signature_result.normalize();
builder.assert_equal(signature_result_normalized.witness_index, input.result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,22 @@ class EcdsaCircuit {
stdlib::ecdsa_signature<Builder> sig{ typename curve::byte_array_ct(&builder, rr),
typename curve::byte_array_ct(&builder, ss) };

stdlib::byte_array<Builder> hashed_message =
static_cast<stdlib::byte_array<Builder>>(stdlib::SHA256<Builder>::hash(input_buffer));

// IN CIRCUIT: verify the signature
typename curve::bool_ct signature_result = stdlib::ecdsa_verify_signature<Builder,
curve,
typename curve::fq_ct,
typename curve::bigfr_ct,
typename curve::g1_bigfr_ct>(
// input_buffer, public_key, sig);
input_buffer,
// hashed_message, public_key, sig);
hashed_message,
public_key,
sig);

// Assert the signature is true, we hash the message inside the verify sig stdlib call
bool_ct is_true = bool_ct(true);
signature_result.must_imply(is_true, "signature verification failed");
// Assert the signature is true
signature_result.assert_equal(bool_ct(true));

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,30 @@ namespace bb::stdlib {
template <typename Builder> struct ecdsa_signature {
stdlib::byte_array<Builder> r;
stdlib::byte_array<Builder> s;

Builder* get_context() const
{
if (r.get_context() != nullptr) {
return r.get_context();
}

if (s.get_context() != nullptr) {
return s.get_context();
}

return nullptr;
}
};

template <typename Builder, typename Curve, typename Fq, typename Fr, typename G1>
bool_t<Builder> ecdsa_verify_signature(const stdlib::byte_array<Builder>& message,
bool_t<Builder> ecdsa_verify_signature(const stdlib::byte_array<Builder>& hashed_message,
const G1& public_key,
const ecdsa_signature<Builder>& sig);

template <typename Builder, typename Curve, typename Fq, typename Fr, typename G1>
bool_t<Builder> ecdsa_verify_signature_prehashed_message_noassert(const stdlib::byte_array<Builder>& hashed_message,
const G1& public_key,
const ecdsa_signature<Builder>& sig);
void validate_inputs(const stdlib::byte_array<Builder>& hashed_message,
const G1& public_key,
const ecdsa_signature<Builder>& sig);

template <typename Builder> void generate_ecdsa_verification_test_circuit(Builder& builder, size_t num_iterations);

Expand Down
Loading