1

I can not reproduce hash number of these code at local neither at ubuntu or mac environment.

Can anyone tell me how to write a local code that can reproduce the hash result. Below is the code

hash value: 4036725243

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
#include <eosiolib/asset.hpp>
#include <eosiolib/crypto.h>
#include "types.hpp"// #include "eosio.token.hpp"
#include "utils.hpp"
uint8_t compute_random_roll(const std::string& seed1, const std::string& seed2) {
    size_t hash = 0;
    //hash_combine(hash, sha256_to_hex(seed1));
    //hash_combine(hash, sha1_to_hex(seed2));
    hash_combine(hash, seed1);
    hash_combine(hash, seed2);
    return hash % 100 + 1;
}

CONTRACT hello : public eosio::contract {
public:
    using contract::contract;

    ACTION act1() {

        std::string seed1 = "5ccf6c155474c5ddd1ad68b681c4a8713b4e06df11494d0cf2bd5c5e71b4d1e5";
        std::string seed2 = "b72c663881f411e2b669548b9f96dc3705cebf2e";
        std::hash<std::string> hash_fn;
        size_t hash = hash_fn(seed1);
        eosio::print("hash  = ", hash);

        eosio::print("bet  = ", compute_random_roll(seed1, seed2));

  }

  ACTION receipt(std::string debug) {
      require_auth(_self);
  }
};

EOSIO_DISPATCH( hello, (act1)(receipt))
1

I solve this problem with the help of my amazing teammates, a big thank you to them. Apparently, the reason I cannot reproduce the hash is because I used std::hash inside hash_combine function. And in different platform it may result differently. std::hash use MurmurHash2 at 32-bit platform and CityHash at 64-bit platform. And EOS node would use 32-bit one. So now I use MurmurHash2 directly and I am able to reproduce the Hash number.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.