integrate simple rct api

This commit is contained in:
moneromooo-monero 2016-07-10 12:57:22 +01:00
parent 1e8d37e7d8
commit a4d4d6194b
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
11 changed files with 400 additions and 188 deletions

View file

@ -127,7 +127,10 @@ bool gen_rct_tx_validation_base::generate_with(std::vector<test_event_entry>& ev
cryptonote::keypair in_ephemeral;
crypto::key_image ki;
cryptonote::generate_key_image_helper(miner_accounts[n].get_keys(), tx_pub_key, o, in_ephemeral, ki);
rct::decodeRct(rct_txes[n].rct_signatures, rct::sk2rct(in_ephemeral.sec), o, rct_tx_masks[o+n*4]);
if (rct_txes[n].rct_signatures.simple)
rct::decodeRctSimple(rct_txes[n].rct_signatures, rct::sk2rct(in_ephemeral.sec), o, rct_tx_masks[o+n*4]);
else
rct::decodeRct(rct_txes[n].rct_signatures, rct::sk2rct(in_ephemeral.sec), o, rct_tx_masks[o+n*4]);
}
CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk_txes[n], blk_last, miner_account,

View file

@ -187,7 +187,7 @@ TEST(ringct, range_proofs)
destinations.push_back(Pk);
//compute rct data with mixin 500
rctSig s = genRct(sc, pc, destinations, amounts, rct::zero(), 3);
rctSig s = genRct(rct::zero(), sc, pc, destinations, amounts, 3);
//verify rct data
ASSERT_TRUE(verRct(s));
@ -204,7 +204,7 @@ TEST(ringct, range_proofs)
//compute rct data with mixin 500
s = genRct(sc, pc, destinations, amounts, rct::zero(), 3);
s = genRct(rct::zero(), sc, pc, destinations, amounts, 3);
//verify rct data
ASSERT_FALSE(verRct(s));
@ -248,7 +248,7 @@ TEST(ringct, range_proofs_with_fee)
destinations.push_back(Pk);
//compute rct data with mixin 500
rctSig s = genRct(sc, pc, destinations, amounts, rct::zero(), 3);
rctSig s = genRct(rct::zero(), sc, pc, destinations, amounts, 3);
//verify rct data
ASSERT_TRUE(verRct(s));
@ -265,7 +265,7 @@ TEST(ringct, range_proofs_with_fee)
//compute rct data with mixin 500
s = genRct(sc, pc, destinations, amounts, rct::zero(), 3);
s = genRct(rct::zero(), sc, pc, destinations, amounts, 3);
//verify rct data
ASSERT_FALSE(verRct(s));
@ -274,6 +274,60 @@ TEST(ringct, range_proofs_with_fee)
ASSERT_TRUE(decodeRct(s, Sk, 1));
}
TEST(ringct, simple)
{
ctkeyV sc, pc;
ctkey sctmp, pctmp;
//this vector corresponds to output amounts
vector<xmr_amount>outamounts;
//this vector corresponds to input amounts
vector<xmr_amount>inamounts;
//this keyV corresponds to destination pubkeys
keyV destinations;
//add fake input 3000
//the sc is secret data
//pc is public data
tie(sctmp, pctmp) = ctskpkGen(3000);
sc.push_back(sctmp);
pc.push_back(pctmp);
inamounts.push_back(3000);
//add fake input 3000
//the sc is secret data
//pc is public data
tie(sctmp, pctmp) = ctskpkGen(3000);
sc.push_back(sctmp);
pc.push_back(pctmp);
inamounts.push_back(3000);
//add output 5000
outamounts.push_back(5000);
//add the corresponding destination pubkey
key Sk, Pk;
skpkGen(Sk, Pk);
destinations.push_back(Pk);
//add output 999
outamounts.push_back(999);
//add the corresponding destination pubkey
skpkGen(Sk, Pk);
destinations.push_back(Pk);
key message = skGen(); //real message later (hash of txn..)
//compute sig with mixin 2
xmr_amount txnfee = 1;
rctSig s = genRctSimple(message, sc, pc, destinations,inamounts, outamounts, txnfee, 2);
//verify ring ct signature
ASSERT_TRUE(verRctSimple(s));
//decode received amount corresponding to output pubkey index 1
ASSERT_TRUE(decodeRctSimple(s, Sk, 1));
}
static rct::rctSig make_sample_rct_sig(int n_inputs, const uint64_t input_amounts[], int n_outputs, const uint64_t output_amounts[], bool last_is_fee)
{
ctkeyV sc, pc;
@ -295,7 +349,7 @@ static rct::rctSig make_sample_rct_sig(int n_inputs, const uint64_t input_amount
destinations.push_back(Pk);
}
return genRct(sc, pc, destinations, amounts, rct::zero(), 3);;
return genRct(rct::zero(), sc, pc, destinations, amounts, 3);;
}
static bool range_proof_test(bool expected_valid,

View file

@ -565,7 +565,7 @@ TEST(Serialization, serializes_ringct_types)
rct::skpkGen(Sk, Pk);
destinations.push_back(Pk);
//compute rct data with mixin 500
s0 = rct::genRct(sc, pc, destinations, amounts, rct::zero(), 3);
s0 = rct::genRct(rct::zero(), sc, pc, destinations, amounts, 3);
mg0 = s0.MG;
ASSERT_TRUE(serialization::dump_binary(mg0, blob));
@ -588,6 +588,7 @@ TEST(Serialization, serializes_ringct_types)
ASSERT_TRUE(serialization::dump_binary(s0, blob));
ASSERT_TRUE(serialization::parse_binary(blob, s1));
ASSERT_TRUE(s0.simple == s1.simple);
ASSERT_TRUE(s0.rangeSigs.size() == s1.rangeSigs.size());
for (size_t n = 0; n < s0.rangeSigs.size(); ++n)
{