Skip to content

Commit

Permalink
added rust tests for aggsig exchange, fixed issue with pubkey hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Jan 8, 2018
1 parent 635fee6 commit ed81188
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/modules/aggsig/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ static int secp256k1_compute_sighash_single(const secp256k1_context *ctx, secp25
unsigned char output[32];
unsigned char buf[33];
size_t buflen = sizeof(buf);

int overflow;

secp256k1_sha256 hasher;
secp256k1_sha256_initialize(&hasher);

/* Encode public nonce */
CHECK(secp256k1_ec_pubkey_serialize(ctx, buf, &buflen, pubkey, SECP256K1_EC_COMPRESSED));
secp256k1_sha256_write(&hasher, buf, sizeof(buf));

/* Remove the first encoding element, as it may differ depending on how we got here */
secp256k1_sha256_write(&hasher, buf+1, sizeof(buf-1));

/* Encode message */
secp256k1_sha256_write(&hasher, msghash32, 32);
Expand Down
10 changes: 7 additions & 3 deletions src/modules/aggsig/tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ void test_aggsig_api(void) {

/* Receiver verifies sender's Sig and signs */
CHECK(secp256k1_aggsig_verify_single(vrfy, sig, msg, &combiner_sum, &pubkeys[0], 1));

CHECK(secp256k1_aggsig_sign_single(sign, sig2, msg, seckeys[1], sec_nonces[1], &combiner_sum, &combiner_sum, seed));
/* sender verifies receiver's Sig then creates final combined sig */
CHECK(secp256k1_aggsig_verify_single(vrfy, sig2, msg, &combiner_sum, &pubkeys[1], 1));
Expand All @@ -212,12 +211,17 @@ void test_aggsig_api(void) {
pubkey_combiner[1]=&pubkeys[1];
CHECK(secp256k1_ec_pubkey_combine(ctx, &combiner_sum_2, pubkey_combiner, 2) == 1);

/* Ensure added sigs verify properly */
/* Ensure added sigs verify properly (with and without providing nonce_sum */
CHECK(secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, &combiner_sum, &combiner_sum_2, 0));
CHECK(secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, NULL, &combiner_sum_2, 0));

/* And anything else doesnt' */
CHECK(!secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, &pub_nonces[0], &combiner_sum_2, 0));
CHECK(!secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, &combiner_sum, &pub_nonces[1], 0));
CHECK(!secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, NULL, &pub_nonces[1], 0));
msg[0]=1;
msg[1]=2;
msg[2]=3;
CHECK(!secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, NULL, &combiner_sum_2, 0));

}
/*** End aggsig for Grin exchange test ***/
Expand Down

0 comments on commit ed81188

Please sign in to comment.