If I want to compute the sha256 hash of some bytes, I can use solana_program::hashv::hashv
, which works fine for a small piece of data that can be hashed in one transaction. Let's say I want to hash something bigger, which I can't do in one transaction because the data is too long to fit in a tx, or hashing would exceed the compute budget, or some other limitation. Is there a way to hash part of the data in one tx and another part in a second (since sha256 is extendable)?
Add a comment
|
1 Answer
Turns out there is a easy way:
I can use solana_program::hash::extend_and_hash
and store my intermediary hash in a PDA.
Always cool to see the amount of power some of the solana standard libs pack!
-
Note for future readers: Alternatively one could also cut the data into a bunch of equally sized chunks and use a Merkle Tree to achieve the same goal in many cases, however this is much less efficient if you only care about having one hash for all your data and none of the other properties of MTs.– McBainCommented Apr 15 at 15:02