3

What does solana_program::hash function return? Supposedly it returns a sha256 Hash value of argument passed, but if I check the same sha256 on a third-party algorithm - it ain't the same. And it's not even its base58 value. I'm confused. Any ideas?

Context: I need hashing for the following scenario: client sends hashed value and then after some time original value, and on-chain code should assert that they are the same after hashing the original value on-chain.

1 Answer 1

1

Looking at the src, it seems like it calls sha2::Sha256 (i believe the solana syscall version of hashv for on-chain programs is defined here, and it uses the same function)

Which 3rd party library are you using? What kind of data are you hashing? There may be various reasons for the discrepancy such as byte-endianness etc

2
  • Let's say there is a value 1: let value = &[1u8], and I want it hashed hash::hash(value). The hash function requires borrowed value / reference here apparently. The output of hash(value) in this case is 67WKXSxm4oc149PvQjdXLacKFZpK5DyYdqBwpiVydJbb, which I can't figure out where it comes from, such that I would use some library accordingly on client side.
    – krilin
    Commented Aug 23, 2022 at 13:20
  • 1
    that looks like its base58-encoded, and indeed it is. Debug and Display trait impl for Hash: docs.rs/solana-program/latest/src/solana_program/…
    – billy
    Commented Aug 24, 2022 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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