Hot answers tagged

18 votes
Accepted

Difference between keccak256 and sha3

from an answer to What are the key differences between the draft SHA-3 standard and the Keccak submission?: No they did not, the internals and security levels have not been changed from the ...
pageman's user avatar
  • 296
18 votes

How to calculate the assigned txHash of a transaction?

Short answer It cannot be done. Longer answer The txhash is keccak256(signedTransaction). This keccak256 function is available as a solidity function http://solidity.readthedocs.io/en/v0.4.21/units-...
Thorkil Værge's user avatar
15 votes
Accepted

Why are there no leading zeroes in ethereum block hash?

In the Ethereum blockchain, the difficulty is used to calculate a target. Here are the ethminer logs for block number 1257006: ℹ 35:02:42.89 ethminer Solution found; Submitting to http://192.168.4....
BokkyPooBah's user avatar
  • 40.3k
15 votes

What is a block hash?

The block header is the hash returned from generating a Merkle tree that is below the current difficulty target for the blocks data. What's a hash? In order to understand what the block header is ...
Anandamide's user avatar
14 votes
Accepted

trying to use web3-utils but not working

Please check your web3.js library version. In versions < 1.0 you can call web3.sha3('test'). In 1.0 it was moved to web3.utils.sha3 Another option is to use web3-utils library, in this case you ...
max taldykin's user avatar
  • 2,966
13 votes
Accepted

Why are Ethereum addresses hashes of public keys?

Indeed, ethereum's address reuse renders the "protection against an ecc public key attack" argument null. For externally owned accounts, using the public key directly would likely not result in any ...
Raghav Sood's user avatar
  • 4,040
9 votes
Accepted

What datatype should I use for an IPFS address hash?

bytes because they are more than 32 bytes. An IPFS hash: itself specifies the hash function and length of the hash in the first two bytes of the multihash. In the examples above the first two bytes ...
eth's user avatar
  • 85.4k
9 votes

Why are there no leading zeroes in ethereum block hash?

What you see in block explorers is the sha3 of the block header, not the ethash.
Yaron Welner's user avatar
9 votes

Block header hash calculation

Below are the steps to calculate blockHash, given a blockNumber: Step1. eth.getBlock(400000) Output:{ difficulty: '6022643743806', extraData: '0xd583010202844765746885676f312e35856c696e7578', ...
AnuragP's user avatar
  • 431
9 votes

How to use ethers keccak256?

With ethers.js v5 you can use: const { ethers, utils } = require("ethers"); const labelhash = utils.keccak256(utils.toUtf8Bytes("example")) This is documented here.
Thomas Clowes's user avatar
8 votes

keccak3 in SOLIDITY and in WEB3 different hashes for an address type field

web3.sha3() takes an encoding parameter to specify that you are passing in a hex address: address_string = '0x5b2063246f2191f18f2675cedb8b28102e957458'; web3.sha3(address_string, {encoding: 'hex'}); ...
carver's user avatar
  • 6,371
8 votes

block-header hash verification

Below are the steps to calculate blockHash, given a blockNumber: Step1. eth.getBlock(400000) Output:{ difficulty: '6022643743806', extraData: '0xd583010202844765746885676f312e35856c696e7578', ...
AnuragP's user avatar
  • 431
8 votes
Accepted

How to use ethers keccak256?

Let's look at the function definition for keccak256: export function keccak256(data: BytesLike): string { return '0x' + sha3.keccak_256(arrayify(data)); } The input is not a string - it's a ...
Paul Razvan Berg's user avatar
7 votes
Accepted

Does a mining reward transaction have a hash?

There are no inputs and outputs in Ethereum, just state changes and balances. Therefore, mining rewards don't have a transaction hash since they are not a transaction. Each block contains the miner'...
Tjaden Hess's user avatar
  • 36.9k
7 votes
Accepted

How does keccak256 concatenate values inside a Solidity smart contract?

The arguments are expressed as bytes, left-padded with zeroes to the maximum length of the data type you've passed in, and concatenated without any kind of delimiter. In Python, given two hex-encoded ...
Edmund Edgar's user avatar
  • 16.9k
7 votes

Difference between keccak256 and sha3

Keccak and sha-3 are not the same. In 2007, U.S. National Institute of Standard and Technology (NIST) initiated a competition about SHA-3. In 2012, Keccak team won the competition. From then on, ...
Yilmaz's user avatar
  • 1,560
7 votes
Accepted

Distribution of KECCAK-256 hash values

I came across this paper that looks at using Keccak-256 (the original one that Ethereum uses, not SHA3) as a PRNG. It subjects the output of the hash to a large number of tests of randomness and it ...
benjaminion's user avatar
  • 9,217
7 votes

Can we use block hash as verifiable randomness for the off-chain lottery?

we want to use the block hash of some block in the future as a seed for the random generator. I think using a future block hash is generally considered "safe". (This article discusses using ...
Richard Horrocks's user avatar
6 votes
Accepted

Build a hash from a string and a number uint256 on Solidity

Another correction (2019-05-17): In modern Solidity version you can no longer pass multiple arguments to keccak256. It now only takes one argument of type bytes. You can still hash multiple values ...
Jesbus's user avatar
  • 10.4k
6 votes

How to calculate the assigned txHash of a transaction?

According to geth source code (file core/types/transactions) and this medium post the hash of a transaction is given by the keccak 256-bit hashing of the rlp encoding of all fields of a transaction, ...
Briomkez's user avatar
  • 1,894
6 votes
Accepted

How to generate the full list of function selectors for a contract?

Maybe you can use the online Ethereum IDE (Remix): Paste the whole code of the address you posted. Select the same compiler version: v0.4.25+commit.59dbf8f1. Select the contract by name: ...
alberto's user avatar
  • 3,323
6 votes
Accepted

Solidity's keccak256 hash doesn't match WEB3 keccak hash

The abi.encode function encode its parameters for a contract call using Solidity's ABI specs. For fixed size types like uintXXX, bool, address, it's quite easy, just pad them to 32 bytes; for dynamic ...
Ismael's user avatar
  • 30.5k
5 votes
Accepted

How to compare hash of two structures?

The return value of sha256 is bytes32. So use bytes32 a = sha256(...) and do the same for b. This will fix the compiler errors and a == b will work. But currently you cannot pass a struct to ...
eth's user avatar
  • 85.4k
5 votes

Does Ethereum use Ethash or KECCAK-256 (an alias to SHA3) as hash function?

A hash function is different to a proof-of-work algorithm. Much of the effort in following a proof-of-work algorithm involves making hashes, but they're distinct things. Ethash is the proof-of-work ...
Edmund Edgar's user avatar
  • 16.9k
5 votes
Accepted

Price of storing a hash SHA3 in Ethereum and Bitcoin

In Bitcoin, you can store 80 bytes in one transaction with OP_RETURN. SHA-3(256) has a size of 32 bytes and can be stored in one transaction. The fee for the OP_RETURN transaction is 0.0001 BTC. By ...
Igor Barinov's user avatar
  • 2,138
5 votes
Accepted

Is it possible to have a mapping with a hash as key?

Yes, hash was an old type that's been replaced with bytes32. You can call keccak256(data1, data2, ...) and use that as a key. Prior discussion on hash.
eth's user avatar
  • 85.4k
5 votes
Accepted

How to decode txn_hash from contract function call via Python web3.py, w3.eth.sendRawTransaction

Use hex(). txnHash = w3.eth.sendRawTransaction(signed.rawTransaction) print('txnHash: '+ str(txnHash)) txnHashHex = txnHash.hex() print('txnHash.hex(): '+ txnHashHex) Output in terminal: txnHash: b'\...
Russo's user avatar
  • 1,764
5 votes
Accepted

Compare structs and arrays with keccak256 in order to save gas

Yes there is! As keccak256 in Solidity yieds a bytes32 value, you could just compare the outcomes using ==. An example: pragma solidity 0.4.24; contract KeccakCompare { struct Example { ...
Henk's user avatar
  • 4,266
5 votes

How to generate the full list of function selectors for a contract?

For every function, you want to calculate keccak256(signature) (try https://emn178.github.io/online-tools/keccak_256.html) signature is a concatenation of function's name and parameters' types in ...
Oleg Kondrakhanov's user avatar
5 votes
Accepted

How to get the type of transaction (Send/Receive/Approve/Swap) and the ERC20 tokens involved in that transaction?

First, you are not querying the right endpoint. If you want to fetch ERC-20 events, you must do the following query : https://api.etherscan.io/api?module=account&action=tokentx&address=...
Xavier59's user avatar
  • 532

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