Skip to main content
6 votes
Accepted

Why can't I use a future blockhash for on-chain randomness?

A malicious leader can front-run your transaction by grinding the blockhash, including whatever ordered set of transactions required. It doesn't matter how in the future your blockhash is, a malicious ...
Jacob Creech's user avatar
  • 4,019
4 votes

How would one hash two different pubkeys inside an Anchor program?

In order to get a commutative function of the two seed inputs, I would just XOR the keys together. fn couple(prt1: Pubkey, prt2: Pubkey) -> Pubkey { let a1: [u8; 32] = prt1.to_bytes(); let a2: [...
AllBlooming's user avatar
  • 2,309
3 votes
Accepted

Where are the hashing utils in nodejs?

If you're referring to serialization, generally the standard for Solana & Rust is Borsh, which you can use in javascript with borsh-js. If you're referring to hashing, I would just use the crypto ...
McBain's user avatar
  • 5,384
2 votes
Accepted

How can i create hash table using PDAs?

We can create hashmaps and nested hashmaps this way On contract-side: #[account(mut)] pub user: Signer<'info>, // data for seeds from counter-account can be read from other pda-account // this ...
Mahesh Ghamaand's user avatar
2 votes

How can i create hash table using PDAs?

await PublicKey.findProgramAddress() expects a Buffer or Uint8Array, and the program's address. u8 So you could perhaps do (i have not tested it): const yourIndex = a; // a u8 number ranging from 0 ...
Sjoerd Dijkstra's user avatar
2 votes

Best way to pack data and then hash it, both in Rust and NodeJS

It is the same as solidity, you need to encode the data structure first, then only you can hash it. So once encoded to bytes you can use solana_program::keccak::hashv on the slice of bytes. To pack ...
Arowana's user avatar
  • 2,373
2 votes
Accepted

How would one hash two different pubkeys inside an Anchor program?

The seeds are already going to be hashed behind the scenes to generate the PDA, so hashing them in advance won't really buy you anything. Would sorting the pubkeys first be sufficient for your ...
trent.sol's user avatar
  • 4,585
2 votes
Accepted

How to get the SHA256 hash of some bytes on chain?

I've got the answer in Anchor Discord server. The answer is solana_program::hashv::hashv.
Yan's user avatar
  • 419
1 vote
Accepted

Compute sha256 hash of a very large input that doesn't fit in one transaction

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!
McBain's user avatar
  • 5,384
1 vote

Data Hashing vs Merkle Trees (account compression) on Solana. Which is better for compressing a large data sample?

It boils down to what your constraint is, compute or storage space, and if your data will change at any point in the future: Merkle Tree: Higher upfront compute cost, but much lower cost for ...
McBain's user avatar
  • 5,384
1 vote

What does solana_program::hash actually return?

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 ...
billy's user avatar
  • 404
1 vote

Is there a transaction instruction verification system in place to avoid verifying user-fed transaction id's in a server?

If all you care about is the movement of tokens from account to account, you can use the getTransaction API. The relevant parts of the response are these: result.meta.{pre|post}Balances – Array of ...
steveluscher's user avatar
  • 3,153

Only top scored, non community-wiki answers of a minimum length are eligible