Im trying to implement a simple hashlock contract where I initially commit a sha256 hash of a password string and an address of the target receiver.

The contract compiles and tests work (since for tests I am using the smartpy hashing procedures). But once I deploy, I can't seem to get the reveal to work since the password string that I am passing does not result in the same hash.

How should I generate my initial hash of the string so that once the actual string is passed, the contract computes same hash?

So far I am using just a generic sha256 online generator. But I feel like smartpy sp.sha256(sp.pack()) procedure results in something I am unable to replicate outside.

What am i doing wrong? Is the issue in encoding of the sha256? What encoding does smartpy use? Can I specify what it uses? Code itself is here: Link

For example, I am trying to replicate the sp.pack("password") When i convert a string "password" into hex I get 70617373776f7264 But when I pass 70617373776f7264 into sha256 generator, I don't get the same hash as sp.sha256(sp.pack("password"))

So could someone clarify the correct procedure to replicate the steps?

2 Answers 2


You have to do the pack before compute the sha256.

If you do


It results in 0x05010000000474657374 and 0x5cedc49191ca9f6a0af917b23dd897c11b125970af57bd6c8f033edccf913e68.

If you use compute the sha256, of the first result, you obtain the second. Pay attention that sp.pack(...) is an hex value, not a string.


The sp.pack adds a prefix bytes sequence that essentially says "this is a string". You can see it by doing scenario.show(sp.pack("password")) (output in log.txt). Instead of sp.pack you want sp.utils.bytes_of_string. Putting everything together, scenario.show(sp.sha256(sp.utils.bytes_of_string("password"))) indeed prints the SHA256 of "password".

Your Answer

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