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 ...
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: [...
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 ...
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 ...
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 ...
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 ...
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 ...
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.
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!
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
hashing × 13anchor × 7
solana-program × 5
pda × 2
publickey × 2
node.js × 2
web3.js × 2
transactions × 1
random × 1
program × 1
rust × 1
compute-budget × 1
data × 1
instructions × 1
lifetimes × 1
signing × 1
blockhash × 1
verify × 1
compute × 1
private-key × 1