Closed HeNanYuanWeitao closed 5 years ago
I modify my code: std::string to_hex(const char d, uint32_t s) { std::string r; const char to_hex = "0123456789abcdef"; uint8_t c = (uint8_t)d; for (uint32_t i = 0; i < s; ++i) (r += to_hex[(c[i] >> 4)]) += to_hex[(c[i] & 0x0f)]; return r; } eosio::print("seed: ", to_hex((char*)activebets_itr->seed.hash, sizeof(activebets_itr->seed.hash)).c_str(), "\n"); And then it can print the seed: warn 2019-04-01T07:36:27.953 thread-0 wabt.hpp:613 translate_one ] misaligned const reference 427693 error 2019-04-01T07:36:27.954 thread-0 http_plugin.cpp:585 handle_exception ] FC Exception encountered while processing chain.push_transaction 427694 debug 2019-04-01T07:36:27.954 thread-0 http_plugin.cpp:586 handle_exception ] Exception Details: 3230001 crypto_api_exception: Crypto API Exception 427695 Error expected key different than recovered key 427696 {} 427697 thread-0 wasm_interface.cpp:705 assert_recover_key 427698 pending console output: public key: 0002c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cf 427699 sig: 001f4291539c1067c1e2dc1fc71083cb2d8ab24149e82367a62d67bc47f8dd0829960c93e45a9cda5c405425e65a92dd5e1853f02320400c386f2a4ebfc29ecb15b1 427700 seed: 699daf496f8c558a53002db60c1e731acbc7d4071c439d57411a952bd6b17ef1 427701 bet_id: 7366431540318193527 427702 {"console":"public key: 0002c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cf\nsig: 001f4291539c1067c1e2dc1fc71083cb2d8ab24149e82367a62d67bc47f8dd0829960c93e45a9cd a5c405425e65a92dd5e1853f02320400c386f2a4ebfc29ecb15b1\nseed: 699daf496f8c558a53002db60c1e731acbc7d4071c439d57411a952bd6b17ef1\nbet_id: 7366431540318193527"}
It will be seen by encode with base58 about the public key and the signature, I will try it. But why assert_recover_key throw that exception if the public key and signature is correct.
I get the hex number:"02C0DED2BC1F1305FB0FAAC5E6C03EE3A1924234985427B6167CA569D13DF435CFEB05F9D2" by decode the public:"6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", it is different with the result by my code: eosio::print("public key: ", to_hex((char*)rand_signing_key.data, sizeof(rand_signing_key.data)).c_str(), "\n"); 427698 pending console output: public key: 0002c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cf I get table randkeys: vm:~/eosio.cdt$ cleos get table eosbetcasino eosbetcasino randkeys { "rows": [{ "id": 1, "key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" } ], "more": false } I don't know why!!
I use eosjs-ecc to signature better's seed:699daf496f8c558a53002db60c1e731acbc7d4071c439d57411a952bd6b17ef1, with the private key: "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3", then I get the signature:"SIG_K1_K3xttLEcS1nFx9gDiHLT47AV6U4m9A3wyugHk5wVXpU8uPJgbuucqjSyp5z3iq4mUe66A2sGpQr46DBkVAYwU4Co7rSQR2", but an error has occurred when I call the interface "assert_recover_key " to verfify: " Error 3230001: Crypto API Exception". This is the log: // warn 2019-04-01T02:23:05.288 thread-0 wabt.hpp:613 translate_one ] misaligned const reference 390035 error 2019-04-01T02:23:05.288 thread-0 http_plugin.cpp:585 handle_exception ] FC Exception encountered while processing chain.push_transaction 390036 debug 2019-04-01T02:23:05.288 thread-0 http_plugin.cpp:586 handle_exception ] Exception Details: 3230001 crypto_api_exception: Crypto API Exception 390037 Error expected key different than recovered key 390038 {} 390039 thread-0 wasm_interface.cpp:705 assert_recover_key 390040 pending console output: public key: 390041 sig: 390042 seed: i<9d>?Io<8c>U<8a>S 390043 bet_id: 7366431540318193527 390044 {"console":"public key: \nsig: \nseed: i<9d>?Io<8c>U<8a>S\nbet_id: 7366431540318193527"} 390045 thread-0 apply_context.cpp:72 exec_one // you can see that only bet_id can print to console, I don't know why!!! the code of signature as follow: let signature = ecc.sign(res.rows[0].seed, '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3') console.log("seed: " + res.rows[0].seed) console.log("signature: " + signature)
let verified = ecc.verify(signature, res.rows[0].seed, 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV','utf8',false) console.log("verified: " + verified) and the log is: seed: 699daf496f8c558a53002db60c1e731acbc7d4071c439d57411a952bd6b17ef1 signature: SIG_K1_K3xttLEcS1nFx9gDiHLT47AV6U4m9A3wyugHk5wVXpU8uPJgbuucqjSyp5z3iq4mUe66A2sGpQr46DBkVAYwU4Co7rSQR2 verified:true
Who can help me!!! My smart contract as follow: /*****/
include
include
include
include <eosiolib/eosio.hpp>
include <eosiolib/time.hpp>
include <eosiolib/asset.hpp>
include <eosiolib/contract.hpp>
include <eosiolib/types.hpp>
include <eosiolib/transaction.hpp>
include <eosiolib/crypto.h>
include <boost/algorithm/string.hpp>
include
using eosio::asset; using eosio::permission_level; using eosio::action; using eosio::print; using eosio::name; using eosio::unpack_action_data; using eosio::symbol_type; using eosio::transaction; using eosio::time_point_sec;
class[[eosio::contract]] eosbetdice : public eosio::contract{ public: const uint32_t TWO_MINUTES = 2 * 60; const uint64_t MINBET = 1000; const uint64_t HOUSEEDGE_times10000 = 200; const uint64_t HOUSEEDGE_REF_times10000 = 150; const uint64_t REFERRER_REWARD_times10000 = 50;
private: struct[[eosio::table]] bet{ uint64_t id; account_name bettor; account_name referral; uint64_t bet_amt; uint64_t roll_under; checksum256 seed; time_point_sec bet_time;
};
define EOSIO_ABI_EX( TYPE, MEMBERS ) \
extern "C" { \ void apply( uint64_t receiver, uint64_t code, uint64_t action ) { \ auto self = receiver; \ if( code == self || code == N(eosio.token)) { \ if( action == N(transfer)){ \ eosio_assert( code == N(eosio.token), "Must transfer SYS"); \ } \ TYPE thiscontract( self ); \ switch( action ) { \ EOSIO_API( TYPE, MEMBERS ) \ } \ / does not allow destructor of thiscontract to run: eosio_exit(0); / \ } \ } \ }
EOSIO_ABI_EX(eosbetdice, (initcontract) (newrandkey) (resolvebet) (refundbet) (transfer) (betreceipt) (suspendbet) (deletelog) ) /*****/