From a4e7ebc5919659f0e2ab0f5ff46d5fe3ad3619d2 Mon Sep 17 00:00:00 2001 From: Some Random Crypto Guy Date: Thu, 5 Mar 2026 14:10:49 +0000 Subject: [PATCH] added missing test code --- tests/block_weight/block_weight.cpp | 3 +- tests/core_tests/chaingen.cpp | 7 +- tests/data/txs/bpp_tx_e89415.bin | Bin 0 -> 1539 bytes tests/data/unsigned_monero_tx | Bin 0 -> 1753 bytes tests/data/wallet_9svHk1 | Bin 0 -> 1971 bytes tests/data/wallet_9svHk1.keys | Bin 0 -> 1271 bytes tests/unit_tests/CMakeLists.txt | 2 + tests/unit_tests/carrot_impl.cpp | 1 + tests/unit_tests/carrot_return_index.cpp | 172 +++++++++++ tests/unit_tests/carrot_sparc.cpp | 300 +++++++++++-------- tests/unit_tests/hardfork.cpp | 65 ++-- tests/unit_tests/long_term_block_weight.cpp | 3 +- tests/unit_tests/protocol_tx.cpp | 3 +- tests/unit_tests/tx_construction_helpers.cpp | 1 + tests/unit_tests/wallet_tx_builder.cpp | 1 + utils/python-rpc/framework/wallet.py | 42 --- 16 files changed, 399 insertions(+), 201 deletions(-) create mode 100644 tests/data/txs/bpp_tx_e89415.bin create mode 100644 tests/data/unsigned_monero_tx create mode 100644 tests/data/wallet_9svHk1 create mode 100644 tests/data/wallet_9svHk1.keys create mode 100644 tests/unit_tests/carrot_return_index.cpp diff --git a/tests/block_weight/block_weight.cpp b/tests/block_weight/block_weight.cpp index 17a57071c..fe16b432d 100644 --- a/tests/block_weight/block_weight.cpp +++ b/tests/block_weight/block_weight.cpp @@ -65,11 +65,12 @@ public: , const cryptonote::difficulty_type& cumulative_difficulty , const uint64_t& coins_generated , uint64_t num_rct_outs - , oracle::asset_type_counts& cum_rct_by_asset_type + , oracle::asset_type_counts_v2& cum_rct_by_asset_type , const crypto::hash& blk_hash , uint64_t slippage_total , uint64_t yield_total , uint64_t audit_total + , uint64_t token_total , const cryptonote::network_type nettype , cryptonote::yield_block_info& ybi , cryptonote::audit_block_info& abi diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index f70d99277..ae03d7a28 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -87,11 +87,12 @@ namespace const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated, uint64_t num_rct_outs, - oracle::asset_type_counts& cum_rct_by_asset_type, + oracle::asset_type_counts_v2& cum_rct_by_asset_type, const crypto::hash& blk_hash, uint64_t slippage_total, uint64_t yield_total, uint64_t audit_total, + uint64_t token_total, const cryptonote::network_type nettype, cryptonote::yield_block_info& ybi, cryptonote::audit_block_info& abi @@ -178,10 +179,10 @@ static std::unique_ptr init_blockchain(const std: const block *blk = &boost::get(ev); auto blk_hash = get_block_hash(*blk); - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::yield_block_info ybi; cryptonote::audit_block_info abi; - bdb->add_block(*blk, 1, 1, 1, 0, 0, num_rct_outs_by_asset_type, blk_hash, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + bdb->add_block(*blk, 1, 1, 1, 0, 0, num_rct_outs_by_asset_type, blk_hash, 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); } bool r = bap->blockchain.init(bdb, nettype, true, test_options, 2, nullptr); diff --git a/tests/data/txs/bpp_tx_e89415.bin b/tests/data/txs/bpp_tx_e89415.bin new file mode 100644 index 0000000000000000000000000000000000000000..38f596397b50ec27d53c58dd6234ec393eb3301e GIT binary patch literal 1539 zcmV+e2K@N~009C35SFBh8nL;(0npv90-x&}k=`+!u^rvg8|LaL^05cjVW6u8tI-7F zlmV7g_X+fd00w# z1#HUTcm|~iECH>1A-#6Max)+RdZ1hzOrCV4zO)d}a~8IUf2pPdh@LRJiHVkN#C-;9ZOXz9nRq&d5TVpfAZ( z%V=0S9bC0m0C2SSV36K+K;UQ$2gx=2A0P5#H>G2Bc!^a>#GwueQa}X%3BNhONI36N zag|ehL|HF(tNhq73pS^w_34s`^<0|A(~Klv9piUPIh-GI2J>kI;yqX(;I|cC1iFdZ z;-)WtGDEwo-BY36x9h|5Y^9lvNC*T! zeqk6~V00wVMJY*-sJO}xV1mrpN}bY_3`G?kl5C-EekOGdit*3x#i3>!eG4Z4+YoLw zribYwI?o3sakJAJgUxQOTuZ9JuN+<8m>{}y3W+FaBTJt8N(X$xd}}nUu5jk0eShKj zY0+sK7)NN3ua}*Gm9HpoT-DYNTp}ih34HTVhKF5aY)$!Bg-y|P&KeiP;NLq)$)Q10 zS2QHmxNL-XC<~{uqF=_YlAACFtZy%?6`;4RT@O5%;(h67*u!abho<({j2uAGxIB9~ zBYNpgBYsDMj)=6K_uleVPPn8_pEU>ghSax=SW^?u^N6!&YZ{AlYf0M?O4kEPJV&Q6 zA&9E>cb9#Blu1IKc{X>U_%uL5>t1xY0?<;9THS$s6E9=U=oQH#s_h5I^Ob|60`CzU zDTs7$!=WK5@!S7SAB@;(@1>Vezw6gkiwwyev=FihJ`A_qdk~4k9+S71EOjU}Xz^ny zF9FXnT4^of^V|VT^a%>7{NDmg(A(iMzD1s%=7pv|e5@0y5Hg{w`l%VGH~@sF@nt|9 zI6?;}=$}OMRSl%g{ROWR?=I>k>16;2sm)WmhNs)z^!Qp3 zXBFUZstu1QuBV6H=Y~nWYvUdVkuIsr)7zIveF-R#6M{5>fb*;#hkekmN8a;(UjCGH(X%S_bPP<^$p@VfES-Jf}0>mFgW~%X)dB4C?A$ ze6>}jR*qt7?E`l2+%bvf@H)zU93$D^ZtQGFScBI{{aAspo*XGRE1i4 zwPd>4io@V{93u$!7@kmVhz2k<}xwVioPoV_eS5|x-I{w-<5;xIG?jvni~`W zIStk}YK$Yyaaxy>&O?#gn+?zVvdQ!_njlTX%c&z8yA1ZlR!UsRznJHc9+?6qHIzhT z|A1eAIQ}^674IA2Pz`eC-=F1?v|KW3_2x#)e538dx@*{lEGGS8Ls1jx!~pGR>{=@~ zeQ$1GBBIN$-%wLoO;lqWh&dp)l^0R{%y9})UlnF+3#a6 pC6o+feSYhM{p8yy&%2Jmr-i)srzJ3%r^!M=VXg$hFH6D{WC$9A@qz#V literal 0 HcmV?d00001 diff --git a/tests/data/unsigned_monero_tx b/tests/data/unsigned_monero_tx new file mode 100644 index 0000000000000000000000000000000000000000..4e644bc450c98a5ef03a99a0cf44742346815cbd GIT binary patch literal 1753 zcmb`HX;4#F6vy9vVKE5Gz9`BARB%C~Y(s>AEE3cp2#lZvK?sn70mHs&i-@9zvI#;c zLqQ5E3Sk?<5*?6D)CwU)TrjAVrLrShjHEA=vC|J7zIbQuyg75`ADJ>oTI*c zf{f_xs!h308l32r8#}O>N2koV_GuYD?GjOk`>h2xlmUYEORFruh`V52K5z0E4&~uF zf4!1uNA_&-7>&8#C;JCHXbOO=t*1&jPyqsK-3=8g+A6p@^hFT2-;1|5^0l5MA1iv&mmoCWBvT1b z5dku#$j|bHzepY3dF#!FFusmqdAPqLw>s2)eQ|SZl;%$Rz~~(ZYHt@^(9;6A5c}OHSf_qZw9%$K&TV*Sbx2 z0_2!ec6TQODmyUQA7cJ8L;c^Loz63wg-sTRyi-PYF5v~JHY*)_yxL3p;;wrac2BoGz$z#L6tu)*rAtaxqGl`$fHAx z{whD4WQ&4xZOIpKSutmbOAlN!-#MNI$h4Juu~9_3LSVP!&Sw~ito+();_2zUmkYKQ zeIn_Mx|QO-M`@^R0Ss&*SR48**CZ@5NZMR@P(Ajf#yF{`=!$z89m{(IWqG2C$7i%s6Bh4EAiR|(}cR(VGEI8<=}aA2GDfhu}_p621r9d8uK|`7H&9# zP7{DJMhWP|t&AHaK3R#Rq)AK!CyrorBZi+&ZLIz-3!oyGiNx6jS%>xLFmM+Hz*v^NRSH{pn1SXLguujQAFSv<1qU8nf4& zedJ}4_9U^NNSIJ?X5Wcu>1-{1UI3Mp0py?AN6Y)4^{q4rAS$qpO?7J2ueXxrmU?rw z7u7}$mpV-~HUvp5#a?rn+0K0mRZxqevm2#7O4Xl(gZ~>J{%hSp@AUHE5cOZgQSywTOYS zSsXh33huSj#D^hOT`%7q4@ZS1rd?RwwIDU`VZJ%qAMZ%B%?XC@4+E7O8Al1M{m*{a z97}!u5zq2D&x|DaKL7|fH#SahQ6tYZ(x(1evn4Wb?+|eC1t+8Ta@e{@6NS=JkRXGi zhPI7-FzRYlWarIUI8c?6CWko#YRWf662sS3olY6|2)%^=vO=u{e1j!MMJB*lEI1Ee zmH?>Btonpv$)F6nrCcs&nQQf8u5bly6Bj+%o)E`_X{0fm^G*Ew_eJ<$Y@vw^*6i&yI%kR literal 0 HcmV?d00001 diff --git a/tests/data/wallet_9svHk1 b/tests/data/wallet_9svHk1 new file mode 100644 index 0000000000000000000000000000000000000000..a49b6b50ef8766f77da46798cf7c66f8418dd8a0 GIT binary patch literal 1971 zcmV;k2Tb^yopU+uqUk274^Riw0%uWL)YVSE>V+sQ)=9O}ws-Sf*{U2aazNlT8g`b+ z|EHb%(oKJ1@vZUEIcfv83(*m94}WGI>SUZ?JhF5Yq@iO;6-fEpYhP@1X$+}tJ#35T zq_2NO?F%*Rz)zK4QCVL%t*p{3;JDJiJp(5#-k}f7lTSUuYPHU)#85i<{ZQD_SM9tPgVFw1T?DdjcK=dsyudR(DSDdxv6CGgL+xF^ld1O$3l`Vo)GvNqE$ zswiLt4&EUew4TRYQRqmVy_huDIT^)SE|*W{4A(|wdnhzP?oq}lU1JFZe$`OOZCOJPETF&GWnLWyp9LT<$4Q{E(oxc})gk6sHMWk|RMC zE6vK2i>E}uc5At3cYCTauhM7%6m2M4L?Fc?)oRADGXmY;(BoDh+)8!fa2@x#>P^7T zo*TNcl#{jA9Xt}sM@4~Wveja|9JxL6NNf&x4EUuw=E;=`zSe@}7y~<9!Y&n2rGVe! z9dWV?=D^5}j8!xMhH*=)9kNSsvfFg_2C2Cw;0=mDHP`N!D$CyB)@w3n1Sk^48k67K6c|8%8OL~S~i~5q@pq$P!^#K5N*p@dBVwEncm3*_cH3M$073wKmE`dz zdSUq3ec6EQaEC7cy=XvK6OMW%bZ=G_hEgxT1QLw2z185E8bl!LBaLeovKG_O^)fAZ zvLC3rF9*3Xfs5k+RxsAK9EOvXR%@m?{DRN0-yXcc(0)d@m1Axoc<6S?0hARke2CxJ z$4cV`KmX~8If+>pc8@dOWj5eSbUw?K;EdNGPe3lL5wqt0oa5SN;|jd#S2(p4UcYBU zOCdFbwH0}O4=e}%r6Y(5T>e(?QY_SrdI;;QH{R31y4G1eG$`7LCuV5SJEhnU0<_tUT6;26LVu6Bh?{X@J~x;&5>l4Hex zTxJL?kia;mp6d%9xKi~~PDhVBfIY`sb~?}_us79Y`SNZIi*$8wdrlc-W{vRk5AP6& zqAU8VUT3oN(7c9Z`k-wpCnId8s4X4=S$tzZ1+`}yuR{nbAUbfgA>-8$J`Xt%P|F`N z?J0)F;r?XOj_LN@_p#p0TkjLuneIQ}H?Sk}YFPMGGn*W|-Ryz-lX<`!*jR|cq*zL! zdYDl9$^9eN&+W%vyzAuZfO>RabN>)YbC0P(p3B>@<{|QCnm1LSIpFW2$gd?M1jE+Dh?h_w;R`0=j%3T{aII2J=M>D z4n9&O{I_w7z|N1xtYl4r@JVpPGFZgDmL6l=gw^as$@C`(h#hOFeHtz2&DZ zV8Q0-wx3sOhR&eG0AtV_cSggc)3Kv=maMA>4DEIqwMoXH{pmgjPLCfncOZ>FnoSzP z9ui{W_>iLkJU!3y{W(`=9(a$s*rYlQt~Wc*+!0hYkf9!-j96Ao(l%gV%Q&*gGkrV% zaM_4Gj*jJ%2%wm2;+y+tWuzcQ#da``~UVF6RUJWJzok$(*AYCy+O z;@()ebi~J(EkAnYcdfr)o@6hMZ-JdcDfJfXpBQ11m!q0i{O!me(Be8B7`m=qMfO*7 zM%&D-6tjioe7DX`pgDT|l;-iJHQ^(8rP8{LYC0!83GzY&%lEMtRQGuz8vaOdc?@`nSB0avnd zgr@nRqR1I|rxqCY5)B#DOP0kT54$N9l%?k=p38M7HQ4gA;!y!$;hd)|>L_N1}Lc2d-S9;V@$`qsIMQp-zNOHRu^F)(}Z FyHv~3)xrP( literal 0 HcmV?d00001 diff --git a/tests/data/wallet_9svHk1.keys b/tests/data/wallet_9svHk1.keys new file mode 100644 index 0000000000000000000000000000000000000000..945283f001cf277d40361865268e06249c9c3100 GIT binary patch literal 1271 zcmV9~X49+L*35hlIcB16pvp{5{p}Zkg_#~O4UwOBChdsOJ zko3XT2j>Qpr9V=Puv4Lx*gYV~p13hMs;#aCC&vYU*HkO{!kW+9uvHui|` zCRSEB${KT$+e4Fwf$*k6Loh5mt9mH)nt%BOQ^FZ9tHZ+fz#vRS1hwb@>{IcJK{PP; zD9AQOPxg5(P1sl5IljA_W6^Z44Fb40<6DnNy#VG8&_m-D1d_jEj*MKg$j zA#i1T4{x836SYh=7!L91{_D&u+Ft=ffK*bV=m-LGz*qL8mC%%Ss=u-^Q80_lp8+FC ztxD!~Qx4m2FTQCRI+*N+>E88Ui-?^BBH79y_~QbW`HEa7wU!o2g%9w>zW_~Sf-C>kEvcW^~gDHVr1TK2}tsZP)T z|49#ZHAu0-?-6wLjU&G#q#Rxetx|?&Dc%SsB+9k6>@P$~!Pasw`2s`JoKBSJz|244{;T;j}G$mZZ)SL*K}eR zrP00T@a9>NV4v-ZZ0$H-Np?wey&F~^Yc40Hp<4v8h^wN>-I|m)i1QMb)1e=i^Ck^3 z6BF#++n1Q_0oiERK+%Z-X(>c)!=AEe1lk15*>bS``5DkPISr{r$@xvB(M9wuZ3br0 z+Sp@=uH#)jmxOZ(bXX^N5G}mebN>4Qj8~(#zn!(3(9BOQ1dK#^$Et!bIywc%rn5tL z-5ES}{bd3v4bh10Cg8;!Ic4DM*+Z6A->Kp(J)%D;-a;i~yP$)?IngG_cHdpGWiLk< zC8XTod?N?%q875}dhG(4qA*=!nAh(LL+IpOpsT(Rg^1Pvi(qdW{_*h~sJe&{%Jze- zw`QCCkpDlxEav4M*|q(Y%aR5bQ++`EPu2By$Xz4aV3>>dq^>H^Eaes|9 return_txs(NUM_RETURNS); + + rct::xmr_amount bob_total_sent = 0; + + // Bob returns NUM_RETURNS payments + for (uint64_t idx = 0; idx < NUM_RETURNS; ++idx) + { + // Random amount + rct::xmr_amount amount = crypto::rand() & 0xFFFFFFFF; + bob_total_sent += amount; + + crypto::secret_key k_idx; + make_sparc_return_index(s_sender_receiver_unctx, input_context, Ko, idx, k_idx); + + // Bob: K_return_final = K_return_base + k_idx * T + rct::key k_idx_T; + rct::scalarmultKey(k_idx_T, rct::pk2rct(crypto::get_T()), rct::sk2rct(k_idx)); + rct::key K_return_final = rct::addKeys(rct::pk2rct(K_return_base), k_idx_T); + + // Bob: K_r = K_return_final + K_change + return_txs[idx].K_r = rct::rct2pk(rct::addKeys(K_return_final, rct::pk2rct(K_change))); + + // Bob: return TX enote + return_txs[idx].tx_first_key_image = rct::rct2ki(rct::pkGen()); + return_txs[idx].onetime_address = rct::rct2pk(rct::pkGen()); + + // D_e + crypto::secret_key d_e; + crypto::rand(32, to_bytes(d_e)); + sc_reduce32(to_bytes(d_e)); + make_carrot_enote_ephemeral_pubkey_cryptonote(d_e, return_txs[idx].enote_ephemeral_pubkey); + + const input_context_t return_input_context = make_carrot_input_context(return_txs[idx].tx_first_key_image); + mx25519_pubkey shared_secret_unctx; + crypto::hash shared_secret; + make_carrot_uncontextualized_shared_key_sender(d_e, K_return_base, shared_secret_unctx); + make_carrot_sender_receiver_secret(shared_secret_unctx.data, return_txs[idx].enote_ephemeral_pubkey, return_input_context, shared_secret); + + // Bob encrypts the amount + return_txs[idx].amount_enc = encrypt_carrot_amount(amount, shared_secret, return_txs[idx].onetime_address); + } + + // Verify all K_r values are unique + for (size_t i = 0; i < NUM_RETURNS; ++i) + { + for (size_t j = i + 1; j < NUM_RETURNS; ++j) + { + EXPECT_NE(return_txs[i].K_r, return_txs[j].K_r) + << "K_r for return " << i << " and " << j << " should differ"; + } + } + + // Alice receives and decrypts all return payments + rct::xmr_amount alice_total_received = 0; + + for (uint64_t idx = 0; idx < NUM_RETURNS; ++idx) + { + const auto &rtx = return_txs[idx]; + + // k_idx for this return index + crypto::secret_key alice_k_idx; + make_sparc_return_index(s_sender_receiver_unctx, input_context, Ko, idx, alice_k_idx); + + // Alice: K_return = k_return * G + k_idx * T + rct::key alice_K_return_rct; + rct::addKeys2(alice_K_return_rct, rct::sk2rct(k_return_base), rct::sk2rct(alice_k_idx), rct::pk2rct(crypto::get_T())); + + // Alice computes K_r = K_return + K_change + crypto::public_key alice_K_r = rct::rct2pk(rct::addKeys(alice_K_return_rct, rct::pk2rct(K_change))); + + // Verify Alice's K_r matches what's on-chain (Bob's) + ASSERT_EQ(alice_K_r, rtx.K_r) << "K_r mismatch for idx " << idx; + + // Alice derives shared secret using k_return_base + const input_context_t return_input_context = make_carrot_input_context(rtx.tx_first_key_image); + mx25519_pubkey shared_secret_unctx; + crypto::hash shared_secret; + make_carrot_uncontextualized_shared_key_receiver(k_return_base, rtx.enote_ephemeral_pubkey, shared_secret_unctx); + make_carrot_sender_receiver_secret(shared_secret_unctx.data, rtx.enote_ephemeral_pubkey, return_input_context, shared_secret); + + // Alice decrypts the amount + rct::xmr_amount decrypted_amount = decrypt_carrot_amount(rtx.amount_enc, shared_secret, rtx.onetime_address); + + alice_total_received += decrypted_amount; + } + + // Final verification: Alice's total matches Bob's total + EXPECT_EQ(alice_total_received, bob_total_sent); +} diff --git a/tests/unit_tests/carrot_sparc.cpp b/tests/unit_tests/carrot_sparc.cpp index 993f30f10..cf4f53915 100644 --- a/tests/unit_tests/carrot_sparc.cpp +++ b/tests/unit_tests/carrot_sparc.cpp @@ -109,15 +109,16 @@ std::tuple, crypto::public_key> make_origin_ crypto::secret_key k_return; alice.s_view_balance_dev.make_internal_return_privkey(input_context, enote_proposal_out.enote.onetime_address, k_return); - // compute K_return = k_return * G - crypto::public_key return_pub; - crypto::secret_key_to_public_key(k_return, return_pub); - encrypted_return_pubkey_t K_return; - static_assert(sizeof(K_return.bytes) == sizeof(return_pub.data), "Size mismatch"); - memcpy(K_return.bytes, return_pub.data, sizeof(encrypted_return_pubkey_t)); + // compute k_idx + crypto::secret_key k_idx; + //make_sparc_return_index(input_context, enote_proposal_out.enote.onetime_address, 0, k_idx); + + // compute SPARC K_return = k_return * G + crypto::public_key K_return; + secret_key_to_public_key(k_return, K_return); - // compute K_o = K_change + K_return - crypto::public_key K_o = rct::rct2pk(rct::addKeys(rct::pk2rct(return_pub), rct::pk2rct(enote_proposal_change.enote.onetime_address))); + // compute K_r = K_change + K_return + crypto::public_key K_r = rct::rct2pk(rct::addKeys(rct::pk2rct(K_return), rct::pk2rct(enote_proposal_change.enote.onetime_address))); // calculate the shared secret mx25519_pubkey shared_secret_unctx; @@ -133,16 +134,21 @@ std::tuple, crypto::public_key> make_origin_ make_sparc_return_pubkey_encryption_mask(shared_secret_unctx.data, input_context, enote_proposal_out.enote.onetime_address, m_return); // compute return_enc - enote_proposal_out.enote.return_enc = K_return ^ m_return; + encrypted_return_pubkey_t return_pub; + static_assert(sizeof(K_return.data) == sizeof(return_pub.bytes), "Size mismatch"); + memcpy(return_pub.bytes, K_return.data, sizeof(encrypted_return_pubkey_t)); + enote_proposal_out.enote.return_enc = return_pub ^ m_return; // Return the enotes and the public return key std::vector tx_enotes{enote_proposal_change, enote_proposal_out}; - return {tx_enotes, K_o}; + return {tx_enotes, K_r}; } //---------------------------------------------------------------------------------------------------------------------- -std::tuple, crypto::public_key> make_return_tx( +std::tuple, crypto::public_key, rct::xmr_amount> make_return_tx( carrot::carrot_and_legacy_account &bob, - std::vector &origin_tx_outputs + std::vector &origin_tx_outputs, + const uint64_t idx, + const uint64_t amount ) { // [0] enote is change, [1] enote bob received const auto change_output = origin_tx_outputs[0].enote; @@ -199,23 +205,43 @@ std::tuple, crypto::public_key> make_return_ ); // Create a TX fee that needs to be deducted from the returned amount - const rct::xmr_amount txnFee = recovered_amount >> 4; - const rct::xmr_amount amount_return = recovered_amount - txnFee; + const rct::xmr_amount txnFee = amount >> 4; + const rct::xmr_amount amount_return = amount - txnFee; // compute m_return encrypted_return_pubkey_t m_return; make_sparc_return_pubkey_encryption_mask(origin_tx_shared_secret_unctx.data, input_context, received_output.onetime_address, m_return); // compute K_return from return_enc - encrypted_return_pubkey_t K_return; - K_return = received_output.return_enc ^ m_return; - crypto::public_key return_pub; - static_assert(sizeof(K_return.bytes) == sizeof(return_pub.data), "Size mismatch"); - memcpy(return_pub.data, K_return.bytes, sizeof(encrypted_return_pubkey_t)); - + encrypted_return_pubkey_t K_return_encrypted; + K_return_encrypted = received_output.return_enc ^ m_return; + crypto::public_key K_return_base; + static_assert(sizeof(K_return_encrypted.bytes) == sizeof(K_return_base.data), "Size mismatch"); + memcpy(K_return_base.data, K_return_encrypted.bytes, sizeof(encrypted_return_pubkey_t)); + /* + // k_idx + crypto::secret_key k_idx; + make_sparc_return_index(input_context, received_output.onetime_address, idx, k_idx); + + // k_idx_origin for idx=0 + crypto::secret_key k_idx_origin; + make_sparc_return_index(input_context, received_output.onetime_address, 0, k_idx_origin); + + // k_idx_diff = k_idx - k_idx_origin + crypto::secret_key k_idx_diff; + sc_sub(to_bytes(k_idx_diff), to_bytes(k_idx), to_bytes(k_idx_origin)); + + // K_return: K_return = K_return_base + k_idx_diff * T + rct::key K_return_adjusted = rct::addKeys( + rct::pk2rct(K_return_base), + rct::scalarmultKey(rct::pk2rct(crypto::get_T()), rct::sk2rct(k_idx_diff)) + ); + crypto::public_key return_pub = rct::rct2pk(K_return_adjusted); + */ + // Make a destination address for the return CarrotDestinationV1 return_destination; - make_carrot_main_address_v1(change_output.onetime_address, return_pub, return_destination); + make_carrot_main_address_v1(change_output.onetime_address, K_return_base, return_destination); // Create the return proposal, using the return address and the amount const CarrotPaymentProposalV1 proposal_return = CarrotPaymentProposalV1{ @@ -226,15 +252,17 @@ std::tuple, crypto::public_key> make_return_ RCTOutputEnoteProposal enote_proposal_return; encrypted_payment_id_t encrypted_payment_id_return; - get_output_proposal_return_v1( + get_output_proposal_paymentchannel_v1( proposal_return, tx_return_first_key_image, nullptr, // s_view_balance_dev + received_output.onetime_address, + idx, enote_proposal_return, encrypted_payment_id_return ); std::vector tx_enotes{enote_proposal_return}; - return {tx_enotes, enote_proposal_return.enote.onetime_address}; + return {tx_enotes, enote_proposal_return.enote.onetime_address, txnFee}; } //---------------------------------------------------------------------------------------------------------------------- TEST(carrot_sparc, main_address_return_payment_normal_scan_completeness) @@ -242,127 +270,157 @@ TEST(carrot_sparc, main_address_return_payment_normal_scan_completeness) // these will generate a new format carrot address. carrot::carrot_and_legacy_account alice, bob; alice.generate(); + alice.generate_subaddress_map({1,1}); bob.generate(); + bob.generate_subaddress_map({1,1}); // make origin tx Alice -> Bob CarrotDestinationV1 bob_address = bob.cryptonote_address(); auto [origin_tx_outputs, origin_return_pubkey] = make_origin_tx(alice, bob_address); - // make return tx Bob -> Alice - auto [return_tx_outputs, return_pubkey] = make_return_tx(bob, origin_tx_outputs); - const auto return_output = return_tx_outputs[0].enote; + std::vector amounts; + rct::xmr_amount expected_total = 0; + for (size_t i=0; i<100; ++i) { + amounts.push_back(rct::randXmrAmount(TREASURY_SAL1_MINT_AMOUNT)); + expected_total += amounts.back(); + } - // 1. Alice checks the "hashmap" for a known return_address - ASSERT_EQ(origin_return_pubkey, return_pubkey); + rct::xmr_amount received_total = 0, fee_total = 0; + for (size_t idx=0; idx Alice + auto [return_tx_outputs, return_pubkey, txnFee] = make_return_tx(bob, origin_tx_outputs, idx, amount); + const auto return_output = return_tx_outputs[0].enote; - // Alice should now have access to the origin TX, including the "change" and "output" enotes - const auto change_output = origin_tx_outputs[0].enote; - const auto sent_output = origin_tx_outputs[1].enote; + // 1. Alice checks the "hashmap" for a known return_address + //ASSERT_EQ(origin_return_pubkey, return_pubkey); - // 2. compute k_return' - const input_context_t input_context = make_carrot_input_context(sent_output.tx_first_key_image); - crypto::secret_key k_return; - alice.s_view_balance_dev.make_internal_return_privkey(input_context, sent_output.onetime_address, k_return); + // Alice should now have access to the origin TX, including the "change" and "output" enotes + const auto change_output = origin_tx_outputs[0].enote; + const auto sent_output = origin_tx_outputs[1].enote; + + // 2. compute k_return' + const input_context_t input_context = make_carrot_input_context(sent_output.tx_first_key_image); + crypto::secret_key k_return; + alice.s_view_balance_dev.make_internal_return_privkey(input_context, sent_output.onetime_address, k_return); + + // 6. recover the shared secret(s_sr) of return tx + // s_sr = k_return * D_e + const input_context_t input_context_return = make_carrot_input_context(return_output.tx_first_key_image); + mx25519_pubkey shared_secret_return_unctx; + crypto::hash shared_secret_return; + make_carrot_uncontextualized_shared_key_receiver(k_return, return_output.enote_ephemeral_pubkey, shared_secret_return_unctx); + + // 3. compute k_idx' + crypto::secret_key k_idx; + make_sparc_return_index(shared_secret_return_unctx.data, input_context_return, sent_output.onetime_address, idx, k_idx); + + // 4. compute SPARC K_return' = k_return' * G + k_idx' * T + rct::key K_return; + rct::addKeys2(K_return, + rct::sk2rct(k_return), + rct::sk2rct(k_idx), + rct::pk2rct(crypto::get_T())); + + // 5. compute K_r' = K_change + K_return' + crypto::public_key K_r_verify = rct::rct2pk(rct::addKeys(K_return, rct::pk2rct(change_output.onetime_address))); + ASSERT_EQ(K_r_verify, return_pubkey); + + // 7. recompute the shared secret : s^ctx_sr = H_32(s_sr, D_e, input_context) + make_carrot_sender_receiver_secret(shared_secret_return_unctx.data, + return_output.enote_ephemeral_pubkey, + input_context_return, + shared_secret_return); + + // 8. recompute the view_tag and make sure it is correct + EXPECT_TRUE(test_carrot_view_tag(shared_secret_return_unctx.data, input_context_return, K_r_verify, return_output.view_tag)); - // 3. compute K_return' = k_return * G - crypto::public_key K_return; - crypto::secret_key_to_public_key(k_return, K_return); + // 9. compute the amount encryption mask and recover the amount + rct::xmr_amount recovered_amount_return = decrypt_carrot_amount(return_output.amount_enc, shared_secret_return, return_output.onetime_address); - // 4. compute K_o' = K_return' + K_change - crypto::public_key K_o_verify = rct::rct2pk(rct::addKeys(rct::pk2rct(K_return), rct::pk2rct(change_output.onetime_address))); - ASSERT_EQ(K_o_verify, return_pubkey); + // 10. compute k_a' = H_n(s^ctx_sr, a', K^j_s', enote_type') + crypto::secret_key recovered_amount_blinding_factor_return; + make_carrot_amount_blinding_factor(shared_secret_return, + recovered_amount_return, + change_output.onetime_address, + CarrotEnoteType::PAYMENT, + recovered_amount_blinding_factor_return); - // 5. recover the shared secret(s_sr) of return tx - // s_sr = k_return * D_e - const input_context_t input_context_return = make_carrot_input_context(return_output.tx_first_key_image); - mx25519_pubkey shared_secret_return_unctx; - crypto::hash shared_secret_return; - make_carrot_uncontextualized_shared_key_receiver(k_return, return_output.enote_ephemeral_pubkey, shared_secret_return_unctx); - // s^ctx_sr = H_32(s_sr, D_e, input_context) - make_carrot_sender_receiver_secret(shared_secret_return_unctx.data, - return_output.enote_ephemeral_pubkey, - input_context_return, - shared_secret_return); + // 11. compute C_a' = k_a' G + a' H + rct::key recovered_amount_commitment_return = rct::commit(recovered_amount_return, rct::sk2rct(recovered_amount_blinding_factor_return)); - // 6. verify the view_tag - EXPECT_TRUE(test_carrot_view_tag(shared_secret_return_unctx.data, input_context_return, return_output.onetime_address, return_output.view_tag)); - - // 8. compute the amount encryption mask and recover the amount - rct::xmr_amount recovered_amount_return = decrypt_carrot_amount(return_output.amount_enc, shared_secret_return, return_output.onetime_address); + // 12. verify the commitment + ASSERT_EQ(return_output.amount_commitment, recovered_amount_commitment_return); - // 10. compute k_a' = H_n(s^ctx_sr, a', K^j_s', enote_type') - crypto::secret_key recovered_amount_blinding_factor_return; - make_carrot_amount_blinding_factor(shared_secret_return, - recovered_amount_return, - change_output.onetime_address, - CarrotEnoteType::PAYMENT, - recovered_amount_blinding_factor_return); - - // 11. compute C_a' = k_a' G + a' H - rct::key recovered_amount_commitment_return = rct::commit(recovered_amount_return, rct::sk2rct(recovered_amount_blinding_factor_return)); - - // 12. verify the commitment - ASSERT_EQ(return_output.amount_commitment, recovered_amount_commitment_return); - - // 13. compute m_pid and pid_enc - not implemented/tested since not supported in SPARC - /* - if (return_output.encrypted_payment_id) + // 13. compute m_pid and pid_enc - not implemented/tested since not supported in SPARC + /* + if (return_output.encrypted_payment_id) nominal_payment_id_out = decrypt_legacy_payment_id(*encrypted_payment_id, s_sender_receiver, onetime_address); - else + else nominal_payment_id_out = null_payment_id; - encrypted_payment_id_out =encrypt_legacy_payment_id(proposal.destination.payment_id, s_sender_receiver, output_enote_out.enote.onetime_address); - */ + encrypted_payment_id_out =encrypt_legacy_payment_id(proposal.destination.payment_id, s_sender_receiver, output_enote_out.enote.onetime_address); + */ - // 15. compute m_anchor and anchor' - janus_anchor_t recovered_anchor_return = decrypt_carrot_anchor(return_output.anchor_enc, shared_secret_return, return_output.onetime_address); + // 15. compute m_anchor and anchor' + janus_anchor_t recovered_anchor_return = decrypt_carrot_anchor(return_output.anchor_enc, shared_secret_return, return_output.onetime_address); - // 17. compute d_e' - crypto::secret_key recovered_ephemeral_privkey_return; - make_carrot_enote_ephemeral_privkey(recovered_anchor_return, input_context_return, change_output.onetime_address, null_payment_id, recovered_ephemeral_privkey_return); + // 17. compute d_e' + crypto::secret_key recovered_ephemeral_privkey_return; + make_carrot_enote_ephemeral_privkey(recovered_anchor_return, input_context_return, change_output.onetime_address, null_payment_id, recovered_ephemeral_privkey_return); - // 18. compute D_e' - mx25519_pubkey recovered_ephemeral_pubkey_return; - make_carrot_enote_ephemeral_pubkey(recovered_ephemeral_privkey_return, change_output.onetime_address, false, recovered_ephemeral_pubkey_return); + // 18. compute D_e' + mx25519_pubkey recovered_ephemeral_pubkey_return; + make_carrot_enote_ephemeral_pubkey(recovered_ephemeral_privkey_return, change_output.onetime_address, false, recovered_ephemeral_pubkey_return); - // 19. verify the enote ephemeral pubkey - ASSERT_EQ(recovered_ephemeral_pubkey_return, return_output.enote_ephemeral_pubkey); + // 19. verify the enote ephemeral pubkey + ASSERT_EQ(recovered_ephemeral_pubkey_return, return_output.enote_ephemeral_pubkey); - // Scan the change output - crypto::secret_key recovered_sender_extension_g_change; - crypto::secret_key recovered_sender_extension_t_change; - crypto::public_key recovered_address_spend_pubkey_change; - rct::xmr_amount recovered_amount_change; - crypto::secret_key recovered_amount_blinding_factor_change; - CarrotEnoteType recovered_enote_type_change; - janus_anchor_t recovered_internal_message_out_change; - crypto::public_key return_address_out; - bool is_return_out; - const bool scan_success_change = try_scan_carrot_enote_internal_receiver(change_output, - alice, - recovered_sender_extension_g_change, - recovered_sender_extension_t_change, - recovered_address_spend_pubkey_change, - recovered_amount_change, - recovered_amount_blinding_factor_change, - recovered_enote_type_change, - recovered_internal_message_out_change, - return_address_out, - is_return_out); - ASSERT_TRUE(scan_success_change); + // Scan the change output + crypto::secret_key recovered_sender_extension_g_change; + crypto::secret_key recovered_sender_extension_t_change; + crypto::public_key recovered_address_spend_pubkey_change; + rct::xmr_amount recovered_amount_change; + crypto::secret_key recovered_amount_blinding_factor_change; + CarrotEnoteType recovered_enote_type_change; + janus_anchor_t recovered_internal_message_out_change; + crypto::public_key return_address_out; + bool is_return_out; + const bool scan_success_change = try_scan_carrot_enote_internal_receiver(change_output, + alice, + recovered_sender_extension_g_change, + recovered_sender_extension_t_change, + recovered_address_spend_pubkey_change, + recovered_amount_change, + recovered_amount_blinding_factor_change, + recovered_enote_type_change, + recovered_internal_message_out_change, + return_address_out, + is_return_out); + ASSERT_TRUE(scan_success_change); - // check spendability of the change output - EXPECT_TRUE(alice.can_open_fcmp_onetime_address(alice.get_keys().m_carrot_account_address.m_spend_public_key, - recovered_sender_extension_g_change, - recovered_sender_extension_t_change, - change_output.onetime_address)); + // check spendability of the change output + EXPECT_TRUE(alice.can_open_fcmp_onetime_address(alice.get_keys().m_carrot_account_address.m_spend_public_key, + recovered_sender_extension_g_change, + recovered_sender_extension_t_change, + change_output.onetime_address)); - // check spendability of the return_payment - crypto::secret_key sum_g; - sc_add(to_bytes(sum_g), to_bytes(recovered_sender_extension_g_change), to_bytes(k_return)); - ASSERT_TRUE(alice.can_open_fcmp_onetime_address(alice.get_keys().m_carrot_account_address.m_spend_public_key, - sum_g, - recovered_sender_extension_t_change, - return_output.onetime_address)); + // check spendability of the return_payment + crypto::secret_key sum_g, sum_t; + sc_add(to_bytes(sum_g), to_bytes(recovered_sender_extension_g_change), to_bytes(k_return)); + sc_add(to_bytes(sum_t), to_bytes(recovered_sender_extension_t_change), to_bytes(k_idx)); + ASSERT_TRUE(alice.can_open_fcmp_onetime_address(alice.get_keys().m_carrot_account_address.m_spend_public_key, + sum_g, + sum_t, + return_output.onetime_address)); + + received_total += recovered_amount_return; + fee_total += txnFee; + std::cout << "Amount[" << idx << "] received " << recovered_amount_return << ", fee " << txnFee << " from total " << amount << std::endl; + } + + // Verify we received all the expected amounts + ASSERT_EQ(expected_total, received_total + fee_total); } //---------------------------------------------------------------------------------------------------------------------- TEST(carrot_sparc, get_spend_authority_proof_completeness) diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp index c19960f99..5b5d75bcd 100644 --- a/tests/unit_tests/hardfork.cpp +++ b/tests/unit_tests/hardfork.cpp @@ -53,11 +53,12 @@ public: , const cryptonote::difficulty_type& cumulative_difficulty , const uint64_t& coins_generated , uint64_t num_rct_outs - , oracle::asset_type_counts& cum_rct_by_asset_type + , oracle::asset_type_counts_v2& cum_rct_by_asset_type , const crypto::hash& blk_hash , uint64_t slippage_total , uint64_t yield_total , uint64_t audit_total + , uint64_t token_total , const cryptonote::network_type nettype , cryptonote::yield_block_info& ybi , cryptonote::audit_block_info& abi @@ -104,7 +105,7 @@ TEST(major, Only) { TestDB db; HardFork hf(db, 1, 0, 0, 0, 1, 0); // no voting - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; @@ -117,27 +118,27 @@ TEST(major, Only) ASSERT_FALSE(hf.add(mkblock(0, 2), 0)); ASSERT_FALSE(hf.add(mkblock(2, 2), 0)); ASSERT_TRUE(hf.add(mkblock(1, 2), 0)); - db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); // block height 1, only version 1 is accepted ASSERT_FALSE(hf.add(mkblock(0, 2), 1)); ASSERT_FALSE(hf.add(mkblock(2, 2), 1)); ASSERT_TRUE(hf.add(mkblock(1, 2), 1)); - db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); // block height 2, only version 2 is accepted ASSERT_FALSE(hf.add(mkblock(0, 2), 2)); ASSERT_FALSE(hf.add(mkblock(1, 2), 2)); ASSERT_FALSE(hf.add(mkblock(3, 2), 2)); ASSERT_TRUE(hf.add(mkblock(2, 2), 2)); - db.add_block(mkblock(2, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(2, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); } TEST(empty_hardforks, Success) { TestDB db; HardFork hf(db); - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; @@ -147,7 +148,7 @@ TEST(empty_hardforks, Success) ASSERT_TRUE(hf.get_state(time(NULL) + 3600*24*400) == HardFork::Ready); for (uint64_t h = 0; h <= 10; ++h) { - db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE(hf.add(db.get_block_from_height(h), h)); } ASSERT_EQ(hf.get(0), 1); @@ -173,7 +174,7 @@ TEST(check_for_height, Success) { TestDB db; HardFork hf(db, 1, 0, 0, 0, 1, 0); // no voting - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; @@ -184,14 +185,14 @@ TEST(check_for_height, Success) for (uint64_t h = 0; h <= 4; ++h) { ASSERT_TRUE(hf.check_for_height(mkblock(1, 1), h)); ASSERT_FALSE(hf.check_for_height(mkblock(2, 2), h)); // block version is too high - db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE(hf.add(db.get_block_from_height(h), h)); } for (uint64_t h = 5; h <= 10; ++h) { ASSERT_FALSE(hf.check_for_height(mkblock(1, 1), h)); // block version is too low ASSERT_TRUE(hf.check_for_height(mkblock(2, 2), h)); - db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE(hf.add(db.get_block_from_height(h), h)); } } @@ -200,7 +201,7 @@ TEST(get, next_version) { TestDB db; HardFork hf(db); - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; @@ -211,19 +212,19 @@ TEST(get, next_version) for (uint64_t h = 0; h <= 4; ++h) { ASSERT_EQ(2, hf.get_next_version()); - db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE(hf.add(db.get_block_from_height(h), h)); } for (uint64_t h = 5; h <= 9; ++h) { ASSERT_EQ(4, hf.get_next_version()); - db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE(hf.add(db.get_block_from_height(h), h)); } for (uint64_t h = 10; h <= 15; ++h) { ASSERT_EQ(4, hf.get_next_version()); - db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE(hf.add(db.get_block_from_height(h), h)); } } @@ -232,7 +233,7 @@ TEST(states, Success) { TestDB db; HardFork hf(db); - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; ASSERT_TRUE(hf.add_fork(1, 0, 0)); ASSERT_TRUE(hf.add_fork(2, BLOCKS_PER_YEAR, SECONDS_PER_YEAR)); @@ -256,7 +257,7 @@ TEST(steps_asap, Success) { TestDB db; HardFork hf(db, 1,0,1,1,1); - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; @@ -268,7 +269,7 @@ TEST(steps_asap, Success) hf.init(); for (uint64_t h = 0; h < 10; ++h) { - db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE(hf.add(db.get_block_from_height(h), h)); } @@ -288,7 +289,7 @@ TEST(steps_1, Success) { TestDB db; HardFork hf(db, 1,0,1,1,1); - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; @@ -298,7 +299,7 @@ TEST(steps_1, Success) hf.init(); for (uint64_t h = 0 ; h < 10; ++h) { - db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE(hf.add(db.get_block_from_height(h), h)); } @@ -312,7 +313,7 @@ TEST(reorganize, Same) for (int history = 1; history <= 12; ++history) { TestDB db; HardFork hf(db, 1, 0, 1, 1, history, 100); - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; @@ -326,7 +327,7 @@ TEST(reorganize, Same) // index 0 1 2 3 4 5 6 7 8 9 static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }; for (uint64_t h = 0; h < 20; ++h) { - db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE(hf.add(db.get_block_from_height(h), h)); } @@ -344,7 +345,7 @@ TEST(reorganize, Changed) { TestDB db; HardFork hf(db, 1, 0, 1, 1, 4, 100); - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; @@ -360,7 +361,7 @@ TEST(reorganize, Changed) static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }; static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9 }; for (uint64_t h = 0; h < 16; ++h) { - db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE (hf.add(db.get_block_from_height(h), h)); } @@ -380,7 +381,7 @@ TEST(reorganize, Changed) ASSERT_EQ(db.height(), 3); hf.reorganize_from_block_height(2); for (uint64_t h = 3; h < 16; ++h) { - db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); bool ret = hf.add(db.get_block_from_height(h), h); ASSERT_EQ (ret, h < 15); } @@ -393,7 +394,7 @@ TEST(reorganize, Changed) TEST(voting, threshold) { - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; for (int threshold = 87; threshold <= 88; ++threshold) { @@ -407,7 +408,7 @@ TEST(voting, threshold) for (uint64_t h = 0; h <= 8; ++h) { uint8_t v = 1 + !!(h % 8); - db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); bool ret = hf.add(db.get_block_from_height(h), h); if (h >= 8 && threshold == 87) { // for threshold 87, we reach the treshold at height 7, so from height 8, hard fork to version 2, but 8 tries to add 1 @@ -425,7 +426,7 @@ TEST(voting, threshold) TEST(voting, different_thresholds) { - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; for (int threshold = 87; threshold <= 88; ++threshold) { @@ -444,7 +445,7 @@ TEST(voting, different_thresholds) static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 }; for (uint64_t h = 0; h < sizeof(block_versions) / sizeof(block_versions[0]); ++h) { - db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); bool ret = hf.add(db.get_block_from_height(h), h); ASSERT_EQ(ret, true); } @@ -458,7 +459,7 @@ TEST(voting, info) { TestDB db; HardFork hf(db, 1, 0, 1, 1, 4, 50); // window size 4, default threshold 50% - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; cryptonote::audit_block_info abi; cryptonote::yield_block_info ybi; @@ -500,7 +501,7 @@ TEST(voting, info) ASSERT_EQ(expected_thresholds[h], threshold); ASSERT_EQ(4, voting); - db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); + db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); ASSERT_TRUE(hf.add(db.get_block_from_height(h), h)); } } @@ -563,10 +564,10 @@ TEST(reorganize, changed) #define ADD(v, h, a) \ do { \ cryptonote::block b = mkblock(hf, h, v); \ - oracle::asset_type_counts num_rct_outs_by_asset_type; \ + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; \ cryptonote::audit_block_info abi; \ cryptonote::yield_block_info ybi; \ - db.add_block(b, 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); \ + db.add_block(b, 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); \ ASSERT_##a(hf.add(b, h)); \ } while(0) #define ADD_TRUE(v, h) ADD(v, h, TRUE) diff --git a/tests/unit_tests/long_term_block_weight.cpp b/tests/unit_tests/long_term_block_weight.cpp index a4aa94acd..e09d5c2bd 100644 --- a/tests/unit_tests/long_term_block_weight.cpp +++ b/tests/unit_tests/long_term_block_weight.cpp @@ -57,11 +57,12 @@ public: , const cryptonote::difficulty_type& cumulative_difficulty , const uint64_t& coins_generated , uint64_t num_rct_outs - , oracle::asset_type_counts& cum_rct_by_asset_type + , oracle::asset_type_counts_v2& cum_rct_by_asset_type , const crypto::hash& blk_hash , uint64_t slippage_total , uint64_t yield_total , uint64_t audit_total + , uint64_t token_total , const cryptonote::network_type nettype , cryptonote::yield_block_info& ybi , cryptonote::audit_block_info& abi diff --git a/tests/unit_tests/protocol_tx.cpp b/tests/unit_tests/protocol_tx.cpp index 2fe0dfc5c..1f52af904 100644 --- a/tests/unit_tests/protocol_tx.cpp +++ b/tests/unit_tests/protocol_tx.cpp @@ -55,11 +55,12 @@ public: , const difficulty_type& cumulative_difficulty , const uint64_t& coins_generated , uint64_t num_rct_outs - , oracle::asset_type_counts& cum_rct_by_asset_type + , oracle::asset_type_counts_v2& cum_rct_by_asset_type , const crypto::hash& blk_hash , uint64_t slippage_total , uint64_t yield_total , uint64_t audit_total + , uint64_t token_total , const network_type nettype , yield_block_info& ybi , audit_block_info& abi diff --git a/tests/unit_tests/tx_construction_helpers.cpp b/tests/unit_tests/tx_construction_helpers.cpp index edfb4e75a..6e0674ca3 100644 --- a/tests/unit_tests/tx_construction_helpers.cpp +++ b/tests/unit_tests/tx_construction_helpers.cpp @@ -415,6 +415,7 @@ cryptonote::transaction construct_carrot_pruned_transaction_fake_inputs( {{0, 0}, carrot::AddressDeriveType::PreCarrot}, {}, {}, + "SAL1", tx_proposal); cryptonote::transaction tx; diff --git a/tests/unit_tests/wallet_tx_builder.cpp b/tests/unit_tests/wallet_tx_builder.cpp index 2ee1dd826..1da889755 100644 --- a/tests/unit_tests/wallet_tx_builder.cpp +++ b/tests/unit_tests/wallet_tx_builder.cpp @@ -109,6 +109,7 @@ TEST(wallet_tx_builder, input_selection_basic) top_block_index, /*allow_carrot_external_inputs_in_normal_transfers=*/true, /*allow_pre_carrot_inputs_in_normal_transfers=*/true, + /*asset_type=*/"", selected_transfer_indices ); diff --git a/utils/python-rpc/framework/wallet.py b/utils/python-rpc/framework/wallet.py index 51797493d..d78cb732f 100644 --- a/utils/python-rpc/framework/wallet.py +++ b/utils/python-rpc/framework/wallet.py @@ -1136,45 +1136,3 @@ class Wallet(object): 'id': '0' } return self.rpc.send_json_rpc_request(frozen) - - class BackgroundSyncOptions(object): - def __init__(self): - self.off = 'off' - self.reuse_password = 'reuse-wallet-password' - self.custom_password = 'custom-background-password' - background_sync_options = BackgroundSyncOptions() - - def setup_background_sync(self, background_sync_type = background_sync_options.off, wallet_password = '', background_cache_password = ''): - setup_background_sync = { - 'method': 'setup_background_sync', - 'jsonrpc': '2.0', - 'params' : { - 'background_sync_type': background_sync_type, - 'wallet_password': wallet_password, - 'background_cache_password': background_cache_password, - }, - 'id': '0' - } - return self.rpc.send_json_rpc_request(setup_background_sync) - - def start_background_sync(self): - start_background_sync = { - 'method': 'start_background_sync', - 'jsonrpc': '2.0', - 'params' : {}, - 'id': '0' - } - return self.rpc.send_json_rpc_request(start_background_sync) - - def stop_background_sync(self, wallet_password = '', seed = '', seed_offset = ''): - stop_background_sync = { - 'method': 'stop_background_sync', - 'jsonrpc': '2.0', - 'params' : { - 'wallet_password': wallet_password, - 'seed': seed, - 'seed_offset': seed_offset, - }, - 'id': '0' - } - return self.rpc.send_json_rpc_request(stop_background_sync)